Example #1
0
        /// <summary>
        /// Method for creating UDT
        /// </summary>
        /// <param name="udtName"></param>
        /// <param name="udtDesc"></param>
        /// <param name="udtType"></param>
        public void Create(string udtName, string udtDesc, SAPbobsCOM.BoUTBTableType udtType)
        {
            SAPbobsCOM.UserTablesMD oUDTMD = null;
            try
            {
                oUDTMD                  = (SAPbobsCOM.UserTablesMD)PublicVariable.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables);
                oUDTMD.TableName        = udtName;
                oUDTMD.TableDescription = udtDesc;
                oUDTMD.TableType        = udtType;

                PublicVariable.lRetCode = oUDTMD.Add();
            }
            catch (Exception ex)
            {
                PublicVariable.oApplication.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
            }
            finally
            {
                if (oUDTMD != null)
                {
                    Marshal.FinalReleaseComObject(oUDTMD);
                    oUDTMD = null;
                    GC.Collect();
                }
            }
        }
        public static bool CheckTableExists(string TableName)
        {
            SAPbobsCOM.Company SBO_Company = Conexion.oCompany;

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

            try
            {
                TableName = TableName.Replace("@", "");
                oUdtMD    = (SAPbobsCOM.UserTablesMD)SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables);

                if (oUdtMD.GetByKey(TableName))
                {
                    ret = true;
                }
                else
                {
                    ret = false;
                }
            }
            catch (Exception ex)
            {
                ret = false;
            }
            finally
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oUdtMD);
                oUdtMD = null /* TODO Change to default(_) if this is not a reference type */;
                GC.Collect();
            }

            return(ret);
        }
 public void AddTables(string strTab, string strDesc, SAPbobsCOM.BoUTBTableType nType)
 {
     GC.Collect();
     SAPbobsCOM.UserTablesMD oUserTablesMD = null;
     try
     {
         oUserTablesMD = null;
         oUserTablesMD = ____bobCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables);
         // Adding Table
         if (!oUserTablesMD.GetByKey(strTab))
         {
             oUserTablesMD.TableName        = strTab;
             oUserTablesMD.TableDescription = strDesc;
             oUserTablesMD.TableType        = nType;
             if (oUserTablesMD.Add() != 0)
             {
                 throw new Exception(____bobCompany.GetLastErrorDescription());
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD);
         oUserTablesMD = null;
         GC.WaitForPendingFinalizers();
         GC.Collect();
     }
 }
Example #4
0
        private static void LoadUserTablesMDFromXmlFile(string xmlFileName)
        {
            GC.Collect();

            SAPbobsCOM.UserTablesMD userTablesMD = null;

            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;

                userTablesMD = ((SAPbobsCOM.UserTablesMD)(sbo_company.GetBusinessObjectFromXML(xmlFileName, Convert.ToInt32(iCounter))));
                lErrCode     = userTablesMD.Add();

                if (lErrCode != 0 && lErrCode != -2035 && lErrCode != -1120)
                {
                    sbo_application.StatusBar.SetText($"UDT {userTablesMD.TableName} not created | {sbo_company.GetLastErrorDescription()}", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                }
                if (lErrCode == 0)
                {
                    sbo_application.StatusBar.SetText($"UDT {userTablesMD.TableName} created", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
                }

                GC.Collect();
            }
        }
Example #5
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;
            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);
            }
        }
        public static string CreateUDT(string tableName, string tableDesc, SAPbobsCOM.BoUTBTableType tableType)
        {
            SAPbobsCOM.Company SBO_Company = Conexion.oCompany;

            //get company service
            if (!SBO_Company.Connected)
            {
                Conexion.Conectar_Aplicacion();
            }

            SAPbobsCOM.UserTablesMD oUdtMD = null /* TODO Change to default(_) if this is not a reference type */;
            try
            {
                oUdtMD = (SAPbobsCOM.UserTablesMD)SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables);
                if (oUdtMD.GetByKey(tableName) == false)
                {
                    oUdtMD.TableName        = tableName;
                    oUdtMD.TableDescription = tableDesc;
                    oUdtMD.TableType        = tableType;
                    int lRetCode;
                    lRetCode = oUdtMD.Add();

                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oUdtMD);
                    oUdtMD = null /* TODO Change to default(_) if this is not a reference type */;
                    GC.Collect();

                    if ((lRetCode != 0))
                    {
                        if ((lRetCode == -2035))
                        {
                            return("-2035");
                        }
                        return(SBO_Company.GetLastErrorDescription());
                    }

                    return("");
                }
                else
                {
                    return("");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Example #7
0
        private bool CreaTablaMD(string NombTabla, string DescTabla, SAPbobsCOM.BoUTBTableType tipoTabla)
        {
            SAPbobsCOM.UserTablesMD oUserTablesMD = null;
            try
            {
                oUserTablesMD = null;
                oUserTablesMD = (SAPbobsCOM.UserTablesMD)Conexion.company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables);
                if (!oUserTablesMD.GetByKey(NombTabla))
                {
                    oUserTablesMD.TableName        = NombTabla;
                    oUserTablesMD.TableDescription = DescTabla;
                    oUserTablesMD.TableType        = tipoTabla;

                    m_iErrCode = oUserTablesMD.Add();
                    if (m_iErrCode != 0)
                    {
                        Conexion.company.GetLastError(out m_iErrCode, out m_sErrMsg);
                        StatusMessageError("Error al crear  tabla: " + NombTabla);
                        return(false);
                    }
                    else
                    {
                        StatusMessageSuccess("Se ha creado la tabla: " + NombTabla);
                    }

                    LiberarObjetoGenerico(oUserTablesMD);
                    oUserTablesMD = null;
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                StatusMessageError("Error: EstructuraDatos.cs > CreaTablaMD():" + ex.Message);
                return(false);
            }
            finally
            {
                LiberarObjetoGenerico(oUserTablesMD);
                oUserTablesMD = null;
            }
        }
Example #8
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("");
                }
            }
Example #9
0
        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);
            }
        }
Example #10
0
 public void AddUserTable(string Name, string Description, SAPbobsCOM.BoUTBTableType Type)
 {
     try
     {
         if (!connect())
         {
             return;
         }
         //****************************************************************************
         // The UserTablesMD represents a meta-data object which allows us
         // to add\remove tables, change a table name etc.
         //****************************************************************************
         SAPbobsCOM.UserTablesMD oUserTablesMD = null;
         //****************************************************************************
         // In any meta-data operation there should be no other object "alive"
         // but the meta-data object, otherwise the operation will fail.
         // This restriction is intended to prevent a collisions
         //****************************************************************************
         // the meta-data object needs to be initialized with a
         // regular UserTables object
         oUserTablesMD = ((SAPbobsCOM.UserTablesMD)(oSetupCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)));
         //**************************************************
         // when adding user tables or fields to the SBO DB
         // use a prefix identifying your partner name space
         // this will prevent collisions between different
         // partners add-ons
         // SAP's name space prefix is "BE_"
         //**************************************************
         // set the table parameters
         oUserTablesMD.TableName        = Name;
         oUserTablesMD.TableDescription = Description;
         oUserTablesMD.TableType        = Type;
         // Add the table
         // This action add an empty table with 2 default fields
         // 'Code' and 'Name' which serve as the key
         // in order to add your own User Fields
         // see the AddUserFields.frm in this project
         // a privat, user defined, key may be added
         // see AddPrivateKey.frm in this project
         lRetCode = oUserTablesMD.Add();
         // check for errors in the process
         if (lRetCode != 0)
         {
             oSetupCompany.GetLastError(out lRetCode, out sErrMsg);
             errorLog("Add table error. Table: " + oUserTablesMD.TableName + ", " + sErrMsg);
         }
         else
         {
             errorLog("Table: " + oUserTablesMD.TableName + " was added successfully");
         }
         oUserTablesMD = null;
         GC.Collect();
     }
     catch (Exception ex)
     {
         string err = string.Format("Add Table: {0}, Exeption: {1}", Name, ex.Message);
         errorLog(err);
         if (ex.Message.IndexOf("Ref count") >= 0)
         {
             GC.Collect();
         }
     }
     finally
     {
         connect();
         GC.Collect(); // Release the handle to the table
     }
 }
Example #11
0
        private static void LoadUserTablesMDToXmlFile(string prefix)
        {
            SAPbobsCOM.UserTablesMD userTablesMD   = 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 ""TableName"" FROM OUTB WHERE ""TableName"" LIKE '{0}%'", prefix));
            }

            if (RS.RecordCount > 0)
            {
                while (!RS.EoF)
                {
                    string table = RS.Fields.Item("TableName").Value.ToString();

                    userTablesMD = (SAPbobsCOM.UserTablesMD)sbo_company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables);

                    if (userTablesMD.GetByKey(table))
                    {
                        XmlDocument documento = new XmlDocument();
                        sbo_company.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ExportImportMode;
                        documento.LoadXml(userTablesMD.GetAsXML());

                        if (documentoFinal == null)
                        {
                            documentoFinal = new XmlDocument();
                            documentoFinal.LoadXml(userTablesMD.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);
                            }
                        }
                    }
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(userTablesMD);
                    userTablesMD = null;
                    GC.Collect();

                    RS.MoveNext();
                }
            }

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

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