示例#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 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();
     }
 }
示例#3
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();
            }
        }
示例#4
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);
            }
        }
示例#6
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;
            }
        }
示例#7
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("");
                }
            }
示例#8
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);
            }
        }
示例#9
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
     }
 }