private static System.Type GetSystemDataType(SAPbobsCOM.BoFieldTypes pEnumFieldType) { string lStrDataType = "System"; switch (pEnumFieldType) { case SAPbobsCOM.BoFieldTypes.db_Alpha: lStrDataType += "String"; break; case SAPbobsCOM.BoFieldTypes.db_Date: lStrDataType += "DateTime"; break; case SAPbobsCOM.BoFieldTypes.db_Float: lStrDataType += "Double"; break; case SAPbobsCOM.BoFieldTypes.db_Memo: lStrDataType += "String"; break; case SAPbobsCOM.BoFieldTypes.db_Numeric: lStrDataType += "Decimal"; break; default: lStrDataType += "String"; break; } return(System.Type.GetType(lStrDataType)); }
public void addUDF(string fldTable, string fldName, string fldDesc, SAPbobsCOM.BoFieldTypes sType, int sSize) { SAPbobsCOM.UserFieldsMD oUserFieldsMD = default(SAPbobsCOM.UserFieldsMD); try { oUserFieldsMD = (SAPbobsCOM.UserFieldsMD)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields); oUserFieldsMD.TableName = fldTable; oUserFieldsMD.Name = fldName; oUserFieldsMD.Description = fldDesc; oUserFieldsMD.Type = sType; oUserFieldsMD.EditSize = sSize; iRetCode = oUserFieldsMD.Add(); //// Check for errors if (iRetCode != 0) { oCompany.GetLastError(out iRetCode, out sErrMsg); } else { //log("Field: '" & oUserFieldsMD.Name & "' was added successfuly to " & oUserFieldsMD.TableName & " Table") } } catch (Exception ex) { throw (ex); } oUserFieldsMD = null; }
public void AddTableField(string tablename, string fieldname, int size, SAPbobsCOM.BoFieldTypes type = SAPbobsCOM.BoFieldTypes.db_Alpha) { try { SAPbobsCOM.UserFieldsMD oUserFieldsMD = null; oUserFieldsMD = ((SAPbobsCOM.UserFieldsMD)(oSetupCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields))); // ************************************ // Adding "Name" field // ************************************ // Setting the Field's properties oUserFieldsMD.TableName = "@" + tablename; oUserFieldsMD.Name = fieldname; oUserFieldsMD.Description = fieldname; oUserFieldsMD.Type = type; if (type == SAPbobsCOM.BoFieldTypes.db_Alpha) { oUserFieldsMD.EditSize = size; } // Adding the Field to the Table lRetCode = oUserFieldsMD.Add(); // Check for errors if (lRetCode != 0) { if (lRetCode == -1) { errorLog(fieldname + " already added"); } else { oSetupCompany.GetLastError(out lRetCode, out sErrMsg); errorLog("Add field error. Field: '" + oUserFieldsMD.Name + "', table: " + oUserFieldsMD.TableName + ", " + sErrMsg); } } else { errorLog("Field: '" + oUserFieldsMD.Name + "' was added successfuly to " + oUserFieldsMD.TableName + " Table"); } GC.Collect(); } catch (Exception ex) { string err = string.Format("Add Table field: {0}/{1}, Exception: {2}", tablename, fieldname, ex.Message); errorLog(err); if (ex.Message.IndexOf("Ref count") >= 0) { GC.Collect(); } } finally { GC.Collect(); // Release the handle to the User Fields } }
/// <summary> /// Method for creating UDF /// </summary> /// <param name="udtName"></param> /// <param name="udfName"></param> /// <param name="udfDesc"></param> /// <param name="udfType"></param> /// <param name="udfSubType"></param> /// <param name="udfEditSize"></param> /// <param name="udfLinkTable"></param> /// <param name="validvalues"></param> /// <param name="defaultval"></param> public void Create(string udtName, string udfName, string udfDesc, SAPbobsCOM.BoFieldTypes udfType, SAPbobsCOM.BoFldSubTypes udfSubType, int udfEditSize, [Optional] string udfLinkTable, [Optional] IList <Models.ValidValues> validvalues, [Optional] string defaultval) { SAPbobsCOM.UserFieldsMD oUDFMD = null; try { oUDFMD = (SAPbobsCOM.UserFieldsMD)PublicVariable.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields); oUDFMD.TableName = udtName; oUDFMD.Name = udfName; oUDFMD.Description = udfDesc; oUDFMD.Type = udfType; oUDFMD.SubType = udfSubType; oUDFMD.EditSize = udfEditSize; oUDFMD.LinkedTable = udfLinkTable; if (validvalues != null) { foreach (var item in validvalues) { oUDFMD.ValidValues.Add(); oUDFMD.ValidValues.Value = item.Value; oUDFMD.ValidValues.Description = item.Description; } } oUDFMD.DefaultValue = defaultval; PublicVariable.lRetCode = oUDFMD.Add(); string a = PublicVariable.oCompany.GetLastErrorDescription(); GC.Collect(); //Program.oApplication.StatusBar.SetText(String.Format("UDF {0} Creation in UDT {1}", udfName, udtName), SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success); } catch (Exception ex) { PublicVariable.oApplication.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error); } finally { if (oUDFMD != null) { Marshal.FinalReleaseComObject(oUDFMD); oUDFMD = null; GC.Collect(); } } }
public static void CreateUDF(String udt, //can put business object as well String udfName, String udfDesc, SAPbobsCOM.BoFieldTypes udfType, SAPbobsCOM.BoFldSubTypes udfSubType, int udfEditSize, Dictionary <string, string> udfValidValues = null, SAPbobsCOM.BoYesNoEnum udfMandatory = SAPbobsCOM.BoYesNoEnum.tNO) { if (!CheckFieldExists(udt, udfName)) { SAPbobsCOM.UserFieldsMD oUDFMD = null; try { oUDFMD = AddOnUtilities.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields); oUDFMD.TableName = udt; oUDFMD.Name = udfName; oUDFMD.Description = udfDesc; oUDFMD.Type = udfType; oUDFMD.SubType = udfSubType; oUDFMD.EditSize = udfEditSize; oUDFMD.Mandatory = udfMandatory; //foreach(var udfValidValue in udfValidValues) //{ // oUDFMD.ValidValues.Value = udfValidValue.Key; // oUDFMD.ValidValues.Value = udfValidValue.Key; // oUDFMD.ValidValues.Add(); //} AddOnUtilities.IRetCode = oUDFMD.Add(); AddOnUtilities.DIErrorHandler(String.Format("UDF {0} Created.", udfName)); } catch (Exception ex) { AddOnUtilities.MsgBoxWrapper(ex.Message + " " + ex.StackTrace); } finally { //Important - release COM Object System.Runtime.InteropServices.Marshal.ReleaseComObject(oUDFMD); GC.Collect(); oUDFMD = null; } } }
/// <summary> /// Creates a User Defined Field if it doesn't exist. /// </summary> /// <param name="pTableName">The table where the field will be created.</param> /// <param name="pFieldName">The name of the field.</param> /// <param name="pDescription">The description (display name) of the field.</param> /// <param name="pType">The field's type</param> /// <param name="pSize">The field's size</param> /// <returns>The result obtained from adding the field, or -1 if it already exists.</returns> public static int CreateUserField(string pTableName, string pFieldName, string pDescription, SAPbobsCOM.BoFieldTypes pType, int pSize) { SAPbobsCOM.UserFieldsMD lObjUserFields = (SAPbobsCOM.UserFieldsMD)DIApplication.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields); if (!ExistsUFD(pTableName, pFieldName)) { lObjUserFields.TableName = pTableName; lObjUserFields.Name = pFieldName; lObjUserFields.Description = pDescription; lObjUserFields.Type = pType; lObjUserFields.Size = pSize; lObjUserFields.EditSize = pSize; return(lObjUserFields.Add()); } return(-1); }
/// <summary> /// A method for adding new field to B1 table /// </summary> /// <param name="name">Field Name</param> /// <param name="description">Field description</param> /// <param name="tableName">Table the field will be added to</param> /// <param name="fieldType">Field Type</param> /// <param name="size">Field size in the database</param> /// <param name="mandatory">bool: if the value is mandatory to be filled</param> public static void AddField(string name, string description, string tableName, SAPbobsCOM.BoFieldTypes fieldType, SAPbobsCOM.BoYesNoEnum mandatory, bool addedToUDT) { AddField(name, description, tableName, fieldType, null, mandatory, 0, addedToUDT); }
/// <summary> /// A method for adding new field to B1 table /// </summary> /// <param name="name">Field Name</param> /// <param name="description">Field description</param> /// <param name="tableName">Table the field will be added to</param> /// <param name="fieldType">Field Type</param> /// <param name="size">Field size in the database</param> /// <param name="mandatory">bool: if the value is mandatory to be filled</param> /// <param name="subType"></param> /// <param name="addedToUDT">If this field will be added to system table or User defined table</param> public static void AddField(string name, string description, string tableName, SAPbobsCOM.BoFieldTypes fieldType, Nullable <int> size, SAPbobsCOM.BoYesNoEnum mandatory, SAPbobsCOM.BoFldSubTypes subType, bool addedToUDT) { AddField(name, description, tableName, fieldType, size, mandatory, subType, addedToUDT, null); }
/// <summary> /// A method for adding new field to B1 table /// </summary> /// <param name="name">Field Name</param> /// <param name="description">Field description</param> /// <param name="tableName">Table the field will be added to</param> /// <param name="fieldType">Field Type</param> /// <param name="size">Field size in the database</param> /// <param name="subType"></param> /// <param name="mandatory"></param> /// <param name="addedToUDT">If this field will be added to system table or User defined table</param> /// <param name="valiedValue">The default selected value</param> /// <param name="validValues">Add the values seperated by comma "," for value and description ex:(Value,Description)</param> public static void AddField(string name, string description, string tableName, SAPbobsCOM.BoFieldTypes fieldType, Nullable <int> size, SAPbobsCOM.BoYesNoEnum mandatory, SAPbobsCOM.BoFldSubTypes subType, bool addedToUDT, string validValue, params string[] validValues) { var objUserFieldMD = B1Helper.diCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields) as SAPbobsCOM.UserFieldsMD; try { if (addedToUDT) { tableName = string.Format("@{0}", tableName); } if (!IsFieldExists(name, tableName)) { objUserFieldMD.TableName = tableName; objUserFieldMD.Name = name; objUserFieldMD.Description = description; objUserFieldMD.Type = fieldType; objUserFieldMD.Mandatory = mandatory; if (size == null || size <= 0) { size = 10; } if (fieldType != SAPbobsCOM.BoFieldTypes.db_Numeric) { objUserFieldMD.Size = (int)size; } else { objUserFieldMD.EditSize = (int)size; } objUserFieldMD.SubType = subType; if (validValue != null) { objUserFieldMD.DefaultValue = validValue; } if (validValues != null) { foreach (string s in validValues) { var valuesAttributes = s.Split(','); if (valuesAttributes.Length == 2) { objUserFieldMD.ValidValues.Description = valuesAttributes[1]; } objUserFieldMD.ValidValues.Value = valuesAttributes[0]; objUserFieldMD.ValidValues.Add(); } } if (objUserFieldMD.Add() != 0) { var error = Utilities.GetErrorMessage(); Utilities.LogException(error); } } } catch (Exception ex) { Utilities.LogException(ex); } finally { objUserFieldMD.ReleaseObject(); } }
private void CreaCampoMD(string NombreTabla, string NombreCampo, string DescCampo, SAPbobsCOM.BoFieldTypes TipoCampo, SAPbobsCOM.BoFldSubTypes SubTipo, int Tamano, SAPbobsCOM.BoYesNoEnum Obligatorio, string[] validValues, string[] validDescription, string valorPorDef, string tablaVinculada) { SAPbobsCOM.UserFieldsMD oUserFieldsMD = null; try { if (NombreTabla == null) { NombreTabla = ""; } if (NombreCampo == null) { NombreCampo = ""; } if (Tamano == 0) { Tamano = 10; } if (validValues == null) { validValues = new string[0]; } if (validDescription == null) { validDescription = new string[0]; } if (valorPorDef == null) { valorPorDef = ""; } if (tablaVinculada == null) { tablaVinculada = ""; } oUserFieldsMD = (SAPbobsCOM.UserFieldsMD)Conexion.company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields); oUserFieldsMD.TableName = NombreTabla; oUserFieldsMD.Name = NombreCampo; oUserFieldsMD.Description = DescCampo; oUserFieldsMD.Type = TipoCampo; if (TipoCampo != SAPbobsCOM.BoFieldTypes.db_Date) { oUserFieldsMD.EditSize = Tamano; } oUserFieldsMD.SubType = SubTipo; if (tablaVinculada != "") { oUserFieldsMD.LinkedTable = tablaVinculada; } else { if (validValues.Length > 0) { for (int i = 0; i <= (validValues.Length - 1); i++) { oUserFieldsMD.ValidValues.Value = validValues[i]; if (validDescription.Length > 0) { oUserFieldsMD.ValidValues.Description = validDescription[i]; } else { oUserFieldsMD.ValidValues.Description = validValues[i]; } oUserFieldsMD.ValidValues.Add(); } } oUserFieldsMD.Mandatory = Obligatorio; if (valorPorDef != "") { oUserFieldsMD.DefaultValue = valorPorDef; } } m_iErrCode = oUserFieldsMD.Add(); if (m_iErrCode != 0) { Conexion.company.GetLastError(out m_iErrCode, out m_sErrMsg); if ((m_iErrCode != -5002) && (m_iErrCode != -2035)) { StatusMessageError("Error al crear campo de usuario: " + NombreCampo + "en la tabla: " + NombreTabla + " Error: " + m_sErrMsg); } } else { StatusMessageSuccess("Se ha creado el campo de usuario: " + NombreCampo + " en la tabla: " + NombreTabla); } } catch (Exception ex) { StatusMessageError("Error: EstructuraDatos.cs > CreaCampoMD():" + ex.Message); } finally { LiberarObjetoGenerico(oUserFieldsMD); oUserFieldsMD = null; } }
public static string CreateUDF(string tableName, string fieldName, string desc, SAPbobsCOM.BoFieldTypes fieldType, int Size, string LinkTab, SAPbobsCOM.BoFldSubTypes SubType = SAPbobsCOM.BoFldSubTypes.st_None) { SAPbobsCOM.Company SBO_Company = Conexion.oCompany; //get company service if (!SBO_Company.Connected) { Conexion.Conectar_Aplicacion(); } try { SAPbobsCOM.UserFieldsMD oUserFieldsMD; oUserFieldsMD = (SAPbobsCOM.UserFieldsMD)SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields); oUserFieldsMD.TableName = tableName; oUserFieldsMD.Name = fieldName; oUserFieldsMD.Description = desc; oUserFieldsMD.Type = fieldType; if (Size != 0) { oUserFieldsMD.EditSize = Size; } oUserFieldsMD.SubType = SubType; int lRetCode; lRetCode = oUserFieldsMD.Add(); System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD); GC.Collect(); oUserFieldsMD = null /* TODO Change to default(_) if this is not a reference type */; if (lRetCode != 0) { if ((lRetCode == -2035 | lRetCode == -1120)) { return(System.Convert.ToString(lRetCode)); } return(SBO_Company.GetLastErrorDescription()); } return(""); } catch (Exception ex) { return(ex.Message); } }
public void AddFields(string tablename, string fieldName, string Description, SAPbobsCOM.BoFieldTypes datatype, SAPbobsCOM.BoFldSubTypes subdatatype, int size, ArrayList validvalue, string defaultValue, bool SetLinkTable, string LinkTable) { SAPbobsCOM.UserFieldsMD oUserFieldsMD = null; string errDesc = ""; GC.Collect(); bool ISUSERTABLE = true; bool ISFieldExist = true; GC.Collect(); try { string sqlStr1 = ""; sqlStr1 = "select * from \"OUTB\" Where \"TableName\" = '" + tablename + "'"; SAPbobsCOM.Recordset oRset1 = null; oRset1 = ____bobCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); oRset1.DoQuery(sqlStr1); if (oRset1.RecordCount > 0) { ISUSERTABLE = true; } else { ISUSERTABLE = false; } System.Runtime.InteropServices.Marshal.ReleaseComObject(oRset1); oRset1 = null; GC.Collect(); string sqlStr = ""; SAPbobsCOM.Recordset oRset = null; oRset = ____bobCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); if (ISUSERTABLE == true) { sqlStr = "select * from CUFD Where \"TableID\" = '@" + tablename + "' and \"AliasID\"= '" + fieldName + "'"; } else { sqlStr = "select * from CUFD Where \"TableID\" = '" + tablename + "' and \"AliasID\"= '" + fieldName + "'"; } oRset.DoQuery(sqlStr); if (oRset.RecordCount > 0) { ISFieldExist = true; } else { ISFieldExist = false; } System.Runtime.InteropServices.Marshal.ReleaseComObject(oRset); oRset = null; GC.Collect(); if (ISFieldExist == false) { oUserFieldsMD = null; oUserFieldsMD = ____bobCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields); oUserFieldsMD.TableName = tablename; oUserFieldsMD.Name = fieldName; oUserFieldsMD.Description = Description; oUserFieldsMD.Type = datatype; oUserFieldsMD.SubType = subdatatype; if (subdatatype.ToString() != "83") { oUserFieldsMD.Size = size; oUserFieldsMD.EditSize = size; } if (SetLinkTable == true) { if (LinkTable != "") { oUserFieldsMD.LinkedTable = LinkTable; } } else if (validvalue != null) { for (int iVal = 0; iVal <= validvalue.Count - 1; iVal++) { //oUserFieldsMD.ValidValues.Value = validvalue[iVal].ToString(); //oUserFieldsMD.ValidValues.Description = validvalue.Item(iVal).Description; //oUserFieldsMD.ValidValues.Add(); } if (defaultValue != "") { oUserFieldsMD.DefaultValue = defaultValue; oUserFieldsMD.Mandatory = SAPbobsCOM.BoYesNoEnum.tYES; } } int UDFCode = oUserFieldsMD.Add(); if (UDFCode == 0) { errDesc = "The Field " + Description + " is Added in table " + tablename + "."; __app.SetStatusBarMessage(errDesc, SAPbouiCOM.BoMessageTime.bmt_Medium, false); } if (UDFCode != 0) { errDesc = ____bobCompany.GetLastErrorDescription(); __app.SetStatusBarMessage(errDesc, SAPbouiCOM.BoMessageTime.bmt_Medium, true); } Marshal.ReleaseComObject(oUserFieldsMD); oUserFieldsMD = null; GC.Collect(); } else { } } catch (Exception ex) { errDesc = ex.Message; } finally { GC.Collect(); GC.WaitForPendingFinalizers(); } }