コード例 #1
0
ファイル: B1_UI.cs プロジェクト: Fun33/code
    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;
    }
コード例 #2
0
        private void InitializeRiseCommissionField()
        {
            SAPbobsCOM.UserFieldsMD lObjUserField = (SAPbobsCOM.UserFieldsMD)DIApplication.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);
            try
            {
                if (!ExistsUFD("@UG_TBL_MQ_RISE", "HasCommission"))
                {
                    lObjUserField.TableName               = "@UG_TBL_MQ_RISE";
                    lObjUserField.Name                    = "HasCommission";
                    lObjUserField.Description             = "Comisión";
                    lObjUserField.Type                    = SAPbobsCOM.BoFieldTypes.db_Alpha;
                    lObjUserField.SubType                 = SAPbobsCOM.BoFldSubTypes.st_None;
                    lObjUserField.Size                    = 1;
                    lObjUserField.EditSize                = 1;
                    lObjUserField.ValidValues.Value       = "Y";
                    lObjUserField.ValidValues.Description = "Si";
                    lObjUserField.ValidValues.Add();
                    lObjUserField.ValidValues.Value       = "N";
                    lObjUserField.ValidValues.Description = "No";
                    lObjUserField.ValidValues.Add();
                    lObjUserField.DefaultValue = "N";

                    lObjUserField.Add();
                }
            }
            finally
            {
                MemoryUtility.ReleaseComObject(lObjUserField);
            }
        }
コード例 #3
0
 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
     }
 }
コード例 #4
0
ファイル: tablas.cs プロジェクト: esteban1991/colaboradores
        public static string CreateUDT(string tableName, string tableDesc, SAPbobsCOM.BoUTBTableType tableType)
        {
            oApp     = (SAPbouiCOM.Application)Application.SBO_Application;
            oCompany = (SAPbobsCOM.Company)oApp.Company.GetDICompany();
            SAPbobsCOM.UserTablesMD oUdtMD = null;
            SAPbobsCOM.UserFieldsMD oUdtCA = null;
            tableName = "Prueba";
            try
            {
                oUdtMD = (SAPbobsCOM.UserTablesMD)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables);
                if (oUdtMD.GetByKey(tableName) == false)
                {
                    oUdtMD.TableName        = tableName;
                    oUdtMD.TableDescription = tableName;
                    oUdtMD.TableType        = tableType;



                    // oUdtCA.Mandatory = "tYes";

                    int lRetCode;
                    lRetCode = oUdtMD.Add();
                    oUdtCA.Add();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oUdtMD);
                    oUdtMD = null;
                    GC.Collect();
                    if ((lRetCode != 0))
                    {
                        if ((lRetCode == -2035))
                        {
                            return("-2035");
                        }

                        return(oCompany.GetLastErrorDescription());
                    }


                    return("");
                }
                else
                {
                    return("");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
コード例 #5
0
        /// <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();
                }
            }
        }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
        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;
                }
            }
        }
コード例 #8
0
        public static SAPbobsCOM.UserFieldsMD AddValidValues(this SAPbobsCOM.UserFieldsMD oUserFieldsMd, List <SapFramework.BaseDados.ValoresValidos> valores)
        {
            if (valores != null)
            {
                int volta = 1;

                foreach (ValoresValidos valor in valores)
                {
                    oUserFieldsMd.ValidValues.Value       = valor.Valor;
                    oUserFieldsMd.ValidValues.Description = valor.Descricao;
                    if (volta <= valores.Count)
                    {
                        oUserFieldsMd.ValidValues.Add();
                    }
                    volta++;
                }
            }
            return(oUserFieldsMd);
        }
コード例 #9
0
        private static void LoadUserFieldMDFromXmlFile(string xmlFileName)
        {
            SAPbobsCOM.UserFieldsMD userFieldsMD = null;
            GC.Collect();

            xmlFileName = AppDomain.CurrentDomain.BaseDirectory + xmlFileName;

            int lErrCode    = 0;
            int recordCount = sbo_company.GetXMLelementCount(xmlFileName);

            for (int iCounter = 0; iCounter <= recordCount - 1; iCounter++)
            {
                sbo_company.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ExportImportMode;

                userFieldsMD = ((SAPbobsCOM.UserFieldsMD)(sbo_company.GetBusinessObjectFromXML(xmlFileName, Convert.ToInt32(iCounter))));
                lErrCode     = userFieldsMD.Add();

                if (lErrCode != 0 && lErrCode != -1120 && lErrCode != -5002)
                {
                    if (lErrCode == -2035)
                    {
                        lErrCode = userFieldsMD.Update();
                        if (lErrCode == 0)
                        {
                            sbo_application.StatusBar.SetText($"UDF {userFieldsMD.Name} updated", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
                        }
                    }
                    else
                    {
                        sbo_application.StatusBar.SetText($"UDF {userFieldsMD.Name} not created | {sbo_company.GetLastErrorDescription()}", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                    }
                }
                if (lErrCode == 0)
                {
                    sbo_application.StatusBar.SetText($"UDF {userFieldsMD.Name} created", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
                }

                GC.Collect();
            }
        }
コード例 #10
0
ファイル: SetupService.cs プロジェクト: radtek/UGRS_Full
 private void InitializeBankField()
 {
     SAPbobsCOM.UserFieldsMD lObjUserField = (SAPbobsCOM.UserFieldsMD)DIApplication.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);
     try
     {
         if (!Utils.ExistsUFD("ODSC", "FZ_ExtFormat"))
         {
             lObjUserField.TableName   = "ODSC";
             lObjUserField.Name        = "FZ_ExtFormat";
             lObjUserField.Description = "Formato Extracto Bancario";
             lObjUserField.Type        = SAPbobsCOM.BoFieldTypes.db_Alpha;
             lObjUserField.SubType     = SAPbobsCOM.BoFldSubTypes.st_None;
             lObjUserField.EditSize    = 20;
             lObjUserField.Size        = 20;
             lObjUserField.LinkedTable = "UG_FZ_BANKEXTRACTS";
             lObjUserField.Add();
         }
     }
     finally
     {
         MemoryUtility.ReleaseComObject(lObjUserField);
     }
 }
コード例 #11
0
        public static bool CheckFieldExists(string TableName, string FieldName)
        {
            SAPbobsCOM.Company SBO_Company = Conexion.oCompany;

            SAPbobsCOM.UserFieldsMD oUserFieldsMD = null /* TODO Change to default(_) if this is not a reference type */;
            bool ret = false;

            try
            {
                FieldName     = FieldName.Replace("U_", "");
                oUserFieldsMD = (SAPbobsCOM.UserFieldsMD)SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);

                int FieldID = getFieldidByName(TableName, FieldName);
                // ‘TableName = TableName.Replace(“@”, “”)
                if (oUserFieldsMD.GetByKey(TableName, FieldID))
                {
                    ret = true;
                }
                else
                {
                    ret = false;
                }
            }
            catch (Exception ex)
            {
                ret = false;
            }
            finally
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD);
                oUserFieldsMD = null /* TODO Change to default(_) if this is not a reference type */;
                GC.Collect();
            }

            return(ret);
        }
コード例 #12
0
            public static string CreateUDT(string tableName, string tableDesc, SAPbobsCOM.BoUTBTableType tableType)
            {
                oApp     = (SAPbouiCOM.Application)Application.SBO_Application;
                oCompany = (SAPbobsCOM.Company)oApp.Company.GetDICompany();
                SAPbobsCOM.UserTablesMD oUdtMD = null;
                SAPbobsCOM.UserFieldsMD oUdtCA = null;
                string VERSION = null;

                SAPbobsCOM.Recordset oRec = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);

                oRec.DoQuery(" SELECT [U_APLICACION] as 'SAP',[U_Version]  As 'Version',[U_fecha] as Fecha FROM [@VERSION]");

                oRec.MoveFirst();
                while (!oRec.EoF)
                {
                    //oCBC.ValidValues.Add(oRec.Fields.Item(0).Value.ToString(), oRec.Fields.Item(1).Value.ToString());
                    VERSION = oRec.Fields.Item("Version").Value.ToString();

                    // Extraerdequery1 = Convert.ToString(Grid2.Columns.Item("Descripción"));

                    oRec.MoveNext();
                }
                if (VERSION == "1.1")
                {
                    tableName = "@Prueba";
                    try
                    {
                        oUdtMD = (SAPbobsCOM.UserTablesMD)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables);
                        if (oUdtMD.GetByKey(tableName) == false)
                        {
                            oUdtMD.TableName        = tableName;
                            oUdtMD.TableDescription = tableName;
                            oUdtMD.TableType        = tableType;

                            // oUdtCA.Mandatory = "tYes";

                            int lRetCode;
                            lRetCode = oUdtMD.Add();
                            oUdtCA.Add();
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(oUdtMD);
                            oUdtMD = null;
                            GC.Collect();
                            if ((lRetCode != 0))
                            {
                                if ((lRetCode == -2035))
                                {
                                    return("-2035");
                                }

                                return(oCompany.GetLastErrorDescription());
                            }


                            return("exito");
                        }
                        else if (VERSION == "1.2")
                        {
                            return("");
                        }

                        else
                        {
                            return("");
                        }
                    }
                    catch (Exception ex)
                    {
                        return(ex.Message);
                    }
                }
                else
                {
                    return("");
                }
            }
コード例 #13
0
        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;
            }
        }
コード例 #14
0
ファイル: Operations.cs プロジェクト: andresramirez12/T1B1
        static private void insertXML(string strPath)
        {
            SAPbobsCOM.UserTablesMD  objUTMD = null;
            SAPbobsCOM.UserFieldsMD  objUFMD = null;
            SAPbobsCOM.UserObjectsMD objUOMD = null;


            try
            {
                T1.B1.MainObject.Instance.B1Company.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ExportImportMode;

                int iRes     = -1;
                int intTotal = T1.B1.MainObject.Instance.B1Company.GetXMLelementCount(strPath);
                for (int i = 0; i < intTotal; i++)
                {
                    if (T1.B1.MainObject.Instance.B1Company.GetXMLobjectType(strPath, i) == SAPbobsCOM.BoObjectTypes.oUserTables)
                    {
                        #region Create Tables
                        try
                        {
                            objUTMD = T1.B1.MainObject.Instance.B1Company.GetBusinessObjectFromXML(strPath, i);
                            if (!isTableCreated(objUTMD.TableName))
                            {
                                iRes = objUTMD.Add();
                                if (iRes != 0 && iRes != -2035)
                                {
                                    Exception er = new Exception("Could not create MD:" + objUTMD.TableName);
                                    _Logger.Error("Could not create MD " + objUTMD.TableName, er);
                                    break;
                                }
                                iRes = -1;
                            }
                            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(objUTMD);
                            objUTMD = null;
                        }
                        catch (Exception er)
                        {
                            _Logger.Error(strPath, er);
                            if (objUTMD != null)
                            {
                                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(objUTMD);
                                objUTMD = null;
                            }
                        }
                        #endregion
                    }
                    else if (T1.B1.MainObject.Instance.B1Company.GetXMLobjectType(strPath, i) == SAPbobsCOM.BoObjectTypes.oUserFields)
                    {
                        #region create Fields
                        try {
                            objUFMD = T1.B1.MainObject.Instance.B1Company.GetBusinessObjectFromXML(strPath, i);
                            if (!isFieldCreated(objUFMD.Name, objUFMD.TableName))
                            {
                                iRes = objUFMD.Add();
                                if (iRes != 0 && iRes != -2035)
                                {
                                    Exception er       = new Exception("Could not create MD:" + objUFMD.TableName + " Field:" + objUFMD.Name);
                                    string    strError = T1.B1.MainObject.Instance.B1Company.GetLastErrorDescription();
                                    _Logger.Error("Could not create MD " + objUFMD.Name, er);
                                    break;
                                }
                                iRes = -1;
                            }
                            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(objUFMD);
                            objUFMD = null;
                        }
                        catch (Exception er)
                        {
                            _Logger.Error(strPath, er);
                            if (objUFMD != null)
                            {
                                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(objUFMD);
                                objUFMD = null;
                            }
                        }
                        #endregion
                    }
                    else if (T1.B1.MainObject.Instance.B1Company.GetXMLobjectType(strPath, i) == SAPbobsCOM.BoObjectTypes.oUserObjectsMD)
                    {
                        #region Create UDOs
                        try
                        {
                            objUOMD = T1.B1.MainObject.Instance.B1Company.GetBusinessObjectFromXML(strPath, i);
                            if (!isUDOCreated(objUOMD.Name))
                            {
                                iRes = objUOMD.Add();
                                if (iRes != 0 && iRes != -2035 && iRes != -5002)
                                {
                                    Exception er = new Exception("Could not create UDO:" + objUOMD.Code + T1.B1.MainObject.Instance.B1Company.GetLastErrorDescription());
                                    _Logger.Error("Could not create UDO " + objUOMD.Name, er);
                                    break;
                                }
                                iRes = -1;
                            }
                            else
                            {
                                if (Settings._Main.updateUDOForm)
                                {
                                    string strSRF  = objUOMD.FormSRF;
                                    string strCode = objUOMD.Code;
                                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(objUOMD);
                                    objUOMD = null;

                                    objUOMD = T1.B1.MainObject.Instance.B1Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD);
                                    if (objUOMD.GetByKey(strCode))
                                    {
                                        objUOMD.FormSRF = strSRF;
                                        iRes            = objUOMD.Update();
                                        if (iRes != 0)
                                        {
                                            Exception er = new Exception("Could not update UDO:" + objUOMD.Code + T1.B1.MainObject.Instance.B1Company.GetLastErrorDescription());
                                            _Logger.Error("Could not update UDO " + objUOMD.Name, er);
                                            break;
                                        }
                                    }
                                    T1.Config.Settings._T1B1Metadata.updateUDOForm = false;
                                    T1.Config.Settings._T1B1Metadata.Write();
                                }
                            }
                            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(objUOMD);
                            objUOMD = null;
                        }
                        catch (Exception er)
                        {
                            _Logger.Error(strPath, er);
                            if (objUOMD != null)
                            {
                                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(objUOMD);
                                objUOMD = null;
                            }
                        }
                        #endregion
                    }
                }
            }
            catch (Exception er)
            {
                _Logger.Error(strPath, er);
            }
        }
コード例 #15
0
        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();
            }
        }
コード例 #16
0
        private static void LoadUserFieldMDToXmlFile(string prefix)
        {
            SAPbobsCOM.UserFieldsMD userFieldsMD   = null;
            XmlDocument             documentoFinal = null;

            SAPbobsCOM.Recordset RS = (SAPbobsCOM.Recordset)sbo_company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);

            if (sbo_company.DbServerType == SAPbobsCOM.BoDataServerTypes.dst_HANADB)
            {
                RS.DoQuery(string.Format(@"select ""TableID"", ""FieldID"" from CUFD where (CUFD.""TableID"" like '@{0}%' or CUFD.""AliasID"" like '{0}%') and CUFD.""TableID"" not like 'A%'", prefix));
            }

            if (RS.RecordCount > 0)
            {
                while (!RS.EoF)
                {
                    int    fieldID = int.Parse(RS.Fields.Item("FieldID").Value.ToString());
                    string tableID = RS.Fields.Item("TableID").Value.ToString();

                    userFieldsMD = (SAPbobsCOM.UserFieldsMD)sbo_company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);

                    if (userFieldsMD.GetByKey(tableID, fieldID))
                    {
                        XmlDocument documento = new XmlDocument();
                        sbo_company.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ExportImportMode;
                        documento.LoadXml(userFieldsMD.GetAsXML());

                        if (documentoFinal == null)
                        {
                            documentoFinal = new XmlDocument();
                            documentoFinal.LoadXml(userFieldsMD.GetAsXML());
                        }
                        else
                        {
                            XmlNode nodeBO = documento.DocumentElement.FirstChild;
                            string  stringContenidoNodeBO = nodeBO.InnerXml;
                            try
                            {
                                XmlNode nuevoNodeBO = documentoFinal.CreateElement("BO");
                                nuevoNodeBO.InnerXml = stringContenidoNodeBO;

                                documentoFinal.DocumentElement.AppendChild(nuevoNodeBO);
                            }
                            catch (ArgumentException ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                            catch (InvalidOperationException ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }

                    RS.MoveNext();
                }

                if (documentoFinal != null)
                {
                    documentoFinal.Save(UserFieldsFile);
                }

                sbo_application.StatusBar.SetText("UDF export completed", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
            }
        }