hola buenas tardes estoy creando una app en C# que interactua con los metadatos pero al momento de tratar de eliminar me marca
Error al eliminar campo: La cadena de entrada no tiene el formato correcto.
al revisar noto que el valor que esta tomando es el de el nombre de la tabla ideas sobre como lo soluciono
public List GetFieldsForTable(string tableName)
{
List fields = new List();
string cufdTableName = "@" + tableName;
string query = $"SELECT \"TableID\",\"AliasID\" FROM \"CUFD\" WHERE \"TableID\" = '{cufdTableName}'";
_recordset.DoQuery(query);
if (_recordset.RecordCount == 0)
throw new Exception($"No se obtuvieron registros de campos para la tabla '{tableName}'");
_recordset.MoveFirst();
for (int index = 0; index < _recordset.RecordCount; index++)
{
string fieldName = Convert.ToString(_recordset.Fields.Item("AliasID").Value);
fields.Add(fieldName);
_recordset.MoveNext();
}
return fields;
}
public Dictionary<string, string> ShowDataFields(string fieldName, string tableName)
{
Dictionary<string, string> values = new Dictionary<string, string>();
string cufdTableName = "@" + tableName;
string query = $"SELECT \"FieldID\" FROM \"CUFD\" WHERE \"AliasID\" = '{fieldName}' AND \"TableID\" = '{cufdTableName}'";
_recordset.DoQuery(query);
if (_recordset.RecordCount == 0)
throw new Exception($"No se obtuvieron registros de Campos para '{fieldName}' en la tabla '{tableName}'");
_recordset.MoveFirst();
if (_recordset.RecordCount > 0)
{
string fieldID = Convert.ToString(_recordset.Fields.Item("FieldID").Value);
SAPbobsCOM.UserFieldsMD userFields = SBOClient.Instance.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);
try
{
userFields.GetByKey(cufdTableName, int.Parse(fieldID));
values.Add("FieldID", fieldID);
values.Add("FieldName", userFields.Name);
values.Add("FieldDesc", userFields.Description);
values.Add("FieldSize", Convert.ToString(userFields.EditSize));
var fieldType = userFields.Type;
var fieldSubtype = userFields.SubType;
switch (fieldType)
{
case SAPbobsCOM.BoFieldTypes.db_Alpha:
switch (fieldSubtype)
{
case SAPbobsCOM.BoFldSubTypes.st_None:
values.Add("FieldType", "Alfanumérico");
values.Add("FieldSubtype", "Regular");
break;
case SAPbobsCOM.BoFldSubTypes.st_Address:
values.Add("FieldType", "Alfanumérico");
values.Add("FieldSubtype", "Direccion");
break;
case SAPbobsCOM.BoFldSubTypes.st_Phone:
values.Add("FieldType", "Alfanumérico");
values.Add("FieldSubtype", "Telefono");
break;
case SAPbobsCOM.BoFldSubTypes.st_Image:
values.Add("FieldType", "General");
values.Add("FieldSubtype", "Imagen");
break;
case SAPbobsCOM.BoFldSubTypes.st_Checkbox:
values.Add("FieldType", "Alfanumerico");
values.Add("FieldSubtype", "Casilla de verificación");
break;
}
break;
case SAPbobsCOM.BoFieldTypes.db_Date:
switch (fieldSubtype)
{
case SAPbobsCOM.BoFldSubTypes.st_None:
values.Add("FieldType", "Fecha/Hora");
values.Add("Fyeldtype", "Fecha");
break;
case SAPbobsCOM.BoFldSubTypes.st_Time:
values.Add("FieldType", "Fecha/Hora");
values.Add("Fyeldtype", "Hora");
break;
}
break;
case SAPbobsCOM.BoFieldTypes.db_Float:
switch (fieldSubtype)
{
case SAPbobsCOM.BoFldSubTypes.st_Rate:
values.Add("FieldType", "Unidades y totales");
values.Add("FieldSubtype", "Tasa");
break;
case SAPbobsCOM.BoFldSubTypes.st_Sum:
values.Add("FieldType", "Unidades y totales");
values.Add("FieldSubtype", "Suma");
break;
case SAPbobsCOM.BoFldSubTypes.st_Price:
values.Add("FieldType", "Unidades y totales");
values.Add("FieldSubtype", "Precio");
break;
case SAPbobsCOM.BoFldSubTypes.st_Quantity:
values.Add("FieldType", "Unidades y totales");
values.Add("FieldSubtype", "Cantidad");
break;
case SAPbobsCOM.BoFldSubTypes.st_Percentage:
values.Add("FieldType", "Unidades y totales");
values.Add("FieldSubtype", "Porcentaje");
break;
case SAPbobsCOM.BoFldSubTypes.st_Measurement:
values.Add("FieldType", "Unidades y totales");
values.Add("FieldSubtype", "Medición");
break;
}
break;
case SAPbobsCOM.BoFieldTypes.db_Memo:
values.Add("FieldType", "Alfanumérico");
values.Add("FieldSubtype", "Texto");
break;
case SAPbobsCOM.BoFieldTypes.db_Numeric:
values.Add("FieldType", "Numérico");
values.Add("FieldSubtype", "Ninguno");
break;
}
StringBuilder validValuesString = new StringBuilder();
for (int i = 0; i < userFields.ValidValues.Count; i++)
{
userFields.ValidValues.SetCurrentLine(i);
string value = userFields.ValidValues.Value;
string description = userFields.ValidValues.Description;
validValuesString.AppendLine($"{value}:{description}");
}
values.Add("FieldValidValues", validValuesString.ToString());
}
catch (Exception ex)
{
throw ex;
}
finally
{
Marshal.ReleaseComObject(userFields);
userFields = null;
GC.Collect();
_recordset = SBOClient.Instance.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
}
}
return values;
}
public void DeleteField(string tableName, string fieldID)
{
SAPbobsCOM.UserFieldsMD userFields = SBOClient.Instance.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);
Marshal.ReleaseComObject(_recordset);
_recordset = null;
GC.Collect();
try
{
userFields.GetByKey(@tableName, int.Parse(fieldID));
int status = userFields.Remove();
if (status != 0)
{
SBOClient.Instance.Company.GetLastError(out int errCode, out string errMsg);
throw new Exception($"Error al eliminar el campo '{fieldID}' de la tabla '{tableName}': {errCode} - {errMsg}");
}
SBOClient.Instance.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables).Refresh();
}
catch (Exception ex)
{
throw new Exception($"Error al eliminar el campo '{fieldID}' de la tabla '{tableName}': {ex.Message}");
}
finally
{
Marshal.ReleaseComObject(userFields);
userFields = null;
_recordset = SBOClient.Instance.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
}
}