Esempio n. 1
0
        private static bool CheckUDOExists(String udoName)
        {
            SAPbobsCOM.UserObjectsMD oUdtMD = null;
            bool blnFlag = false;

            try
            {
                oUdtMD = AddOnUtilities.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD);

                if (oUdtMD.GetByKey(udoName))
                {
                    blnFlag = true;
                }
            }
            catch (Exception ex)
            {
                blnFlag = false;
                AddOnUtilities.MsgBoxWrapper(ex.Message + " " + ex.StackTrace);
            }
            finally
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oUdtMD);
                oUdtMD = null;
                GC.Collect();
            }

            return(blnFlag);
        }
Esempio n. 2
0
        public static SAPbobsCOM.GeneralData GetUdoObject(string udoName, string keyName, string keyValue)
        {
            SAPbobsCOM.GeneralService    oClassSubjectsGeneralService;
            SAPbobsCOM.GeneralData       oClassSubjectsHeaderGeneralData;
            SAPbobsCOM.GeneralDataParams oClassSubjectGeneralCollectionParams;
            try
            {
                DiCompany.StartTransaction();

                SAPbobsCOM.UserObjectsMD UserObjectMD = (SAPbobsCOM.UserObjectsMD)DiCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD);

                oClassSubjectsGeneralService    = (SAPbobsCOM.GeneralService)DiCompany.GetCompanyService().GetGeneralService(udoName);
                oClassSubjectsHeaderGeneralData = (SAPbobsCOM.GeneralData)oClassSubjectsGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralData);

                oClassSubjectGeneralCollectionParams = (SAPbobsCOM.GeneralDataParams)oClassSubjectsGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams);
                oClassSubjectGeneralCollectionParams.SetProperty(keyName, keyValue);

                oClassSubjectsHeaderGeneralData = oClassSubjectsGeneralService.GetByParams(oClassSubjectGeneralCollectionParams);

                if (DiCompany.InTransaction)
                {
                    DiCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                }
                return(oClassSubjectsHeaderGeneralData);
            }
            catch (Exception Ex)
            {
                Application.SBO_Application.SetStatusBarMessage(Ex.Message, SAPbouiCOM.BoMessageTime.bmt_Medium, true);
                return(null);
            }
        }
Esempio n. 3
0
        private static void LoadUserObjectMDFromXmlFile(string xmlFileName)
        {
            SAPbobsCOM.UserObjectsMD userObjectsMD = 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;

                userObjectsMD = ((SAPbobsCOM.UserObjectsMD)(sbo_company.GetBusinessObjectFromXML(xmlFileName, Convert.ToInt32(iCounter))));
                lErrCode      = userObjectsMD.Add();

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

                GC.Collect();
            }
        }
Esempio n. 4
0
        private bool CreaUDOMD(string sCode, string sName, string sTableName, string[] sFindColumns,
                               string[] sChildTables, SAPbobsCOM.BoYesNoEnum eCanCancel, SAPbobsCOM.BoYesNoEnum eCanClose,
                               SAPbobsCOM.BoYesNoEnum eCanDelete, SAPbobsCOM.BoYesNoEnum eCanCreateDefaultForm, string[] sFormColumns,
                               SAPbobsCOM.BoYesNoEnum eCanFind, SAPbobsCOM.BoYesNoEnum eCanLog, SAPbobsCOM.BoUDOObjType eObjectType,
                               SAPbobsCOM.BoYesNoEnum eManageSeries, SAPbobsCOM.BoYesNoEnum eEnableEnhancedForm,
                               SAPbobsCOM.BoYesNoEnum eRebuildEnhancedForm, string[] sChildFormColumns)
        {
            SAPbobsCOM.UserObjectsMD oUserObjectMD = null;
            int    i_Result = 0;
            string s_Result = "";

            try
            {
                oUserObjectMD = (SAPbobsCOM.UserObjectsMD)Conexion.company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD);

                if (!oUserObjectMD.GetByKey(sCode))
                {
                    oUserObjectMD.Code                 = sCode;
                    oUserObjectMD.Name                 = sName;
                    oUserObjectMD.ObjectType           = eObjectType;
                    oUserObjectMD.TableName            = sTableName;
                    oUserObjectMD.CanCancel            = eCanCancel;
                    oUserObjectMD.CanClose             = eCanClose;
                    oUserObjectMD.CanDelete            = eCanDelete;
                    oUserObjectMD.CanCreateDefaultForm = eCanCreateDefaultForm;
                    oUserObjectMD.EnableEnhancedForm   = eEnableEnhancedForm;
                    oUserObjectMD.RebuildEnhancedForm  = eRebuildEnhancedForm;
                    oUserObjectMD.CanFind              = eCanFind;
                    oUserObjectMD.CanLog               = eCanLog;
                    oUserObjectMD.ManageSeries         = eManageSeries;

                    if (sFindColumns != null)
                    {
                        for (int i = 0; i < sFindColumns.Length; i++)
                        {
                            oUserObjectMD.FindColumns.ColumnAlias = sFindColumns[i];
                            oUserObjectMD.FindColumns.Add();
                        }
                    }
                    if (sChildTables != null)
                    {
                        for (int i = 0; i < sChildTables.Length; i++)
                        {
                            oUserObjectMD.ChildTables.TableName = sChildTables[i];
                            oUserObjectMD.ChildTables.Add();
                        }
                    }
                    if (sFormColumns != null)
                    {
                        oUserObjectMD.UseUniqueFormType = SAPbobsCOM.BoYesNoEnum.tYES;

                        for (int i = 0; i < sFormColumns.Length; i++)
                        {
                            oUserObjectMD.FormColumns.FormColumnAlias = sFormColumns[i];
                            oUserObjectMD.FormColumns.Add();
                        }
                    }
                    if (sChildFormColumns != null)
                    {
                        if (sChildTables != null)
                        {
                            for (int i = 0; i < sChildFormColumns.Length; i++)
                            {
                                oUserObjectMD.FormColumns.SonNumber       = 1;
                                oUserObjectMD.FormColumns.FormColumnAlias = sChildFormColumns[i];
                                oUserObjectMD.FormColumns.Add();
                            }
                        }
                    }

                    i_Result = oUserObjectMD.Add();

                    if (i_Result != 0)
                    {
                        Conexion.company.GetLastError(out i_Result, out s_Result);
                        StatusMessageError("Error: EstructuraDatos.cs > CreaUDOMD(): " + s_Result + ", creando el UDO " + sCode + ".");
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                StatusMessageError("Error: EstructuraDatos.cs > CreaUDOMD():" + ex.Message);
                return(false);
            }
            finally
            {
                LiberarObjetoGenerico(oUserObjectMD);
            }
        }
Esempio n. 5
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);
            }
        }
        public int RegisterObject(string Code, string Name, string ObjectType, string TableName, string ChildTableName, bool CanCancel, bool CanClose, bool CanCreateDefaultForm, bool CanDelete, bool CanFind, bool CanYearTransfer, bool ManageSeries, string FindColumns, bool defaultform, string defaultformFields, bool CanLog)
        {
            try
            {
                int    errCode;
                string errMsg = "";

                if (!____bobCompany.Connected)
                {
                    ____bobCompany.Connect();
                }
                SAPbobsCOM.UserObjectsMD UDO = ____bobCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD);

                if (UDO.GetByKey(Code) == false)
                {
                    // UDO.CanCancel = GetYesNo(CanCancel)
                    // UDO.CanClose = GetYesNo(CanClose)
                    // UDO.CanDelete = GetYesNo(CanDelete)
                    UDO.CanCancel            = GetYesNo(false);
                    UDO.CanClose             = GetYesNo(false);
                    UDO.CanDelete            = GetYesNo(CanDelete);
                    UDO.CanFind              = GetYesNo(CanFind);
                    UDO.CanCreateDefaultForm = GetYesNo(defaultform);
                    UDO.ManageSeries         = GetYesNo(ManageSeries);
                    UDO.CanLog = GetYesNo(CanLog);

                    if (UDO.CanCreateDefaultForm == SAPbobsCOM.BoYesNoEnum.tYES)
                    {
                        string[] s = defaultformFields.Split(',');
                        foreach (string o in s)
                        {
                            string[] s1 = o.Split('|');
                            if (s1.Length > 0)
                            {
                                UDO.FormColumns.FormColumnAlias = s1[0].ToString();
                            }
                            if (s1.Length > 1)
                            {
                                UDO.FormColumns.FormColumnDescription = s1[1].ToString();
                            }
                            UDO.FormColumns.Add();
                        }
                    }

                    if (UDO.CanFind == SAPbobsCOM.BoYesNoEnum.tYES)
                    {
                        if (FindColumns != "")
                        {
                            string[] s = FindColumns.Split(',');
                            // If s.Length > 1 Then
                            if (s.Length > 0)
                            {
                                foreach (string o in s)
                                {
                                    string s1 = "";
                                    if (o.ToString() == "Code" | o.ToString() == "Name" | o.ToString() == "DocNum" | o.ToString() == "DocEntry")
                                    {
                                        s1 = o.ToString();
                                    }
                                    else
                                    {
                                        s1 = "U_" + o.ToString();
                                    }
                                    UDO.FindColumns.ColumnAlias = s1;
                                    UDO.FindColumns.Add();
                                }
                            }
                        }
                    }

                    if (UDO.CanLog == SAPbobsCOM.BoYesNoEnum.tYES)
                    {
                        UDO.LogTableName = "A" + TableName;
                    }
                    UDO.Code       = Code;
                    UDO.Name       = Name;
                    UDO.ObjectType = GetUDOType(ObjectType);
                    UDO.TableName  = TableName;

                    if (ChildTableName != "")
                    {
                        string[] childTables = ChildTableName.Split(',');
                        if (childTables.Length > 0)
                        {
                            foreach (string o in childTables)
                            {
                                UDO.ChildTables.TableName = o.ToString();
                                UDO.ChildTables.Add();
                            }
                        }
                    }
                    int i = -1;
                    i = UDO.Add();

                    if (i != 0)
                    {
                        ____bobCompany.GetLastError(out errCode, out errMsg);
                        __app.MessageBox(errMsg);
                        __app.StatusBar.SetText(errMsg, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                        UDO.Update();
                        if (Marshal.IsComObject(UDO))
                        {
                            Marshal.ReleaseComObject(UDO);
                            UDO = null /* TODO Change to default(_) if this is not a reference type */;
                            GC.Collect();
                            return(errCode);
                        }
                    }
                    UDO.Update();
                    if (Marshal.IsComObject(UDO))
                    {
                        Marshal.ReleaseComObject(UDO);
                    }
                    UDO = null /* TODO Change to default(_) if this is not a reference type */;
                    // GC.WaitForPendingFinalizers();
                    GC.Collect();
                    // oProgressBar.Value = oProgressBar.Value + 1
                    return(0);
                }
                else
                {
                    __app.StatusBar.SetText("Table Already Exists......", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_None);
                }
                return(0);
            }
            catch (Exception ex)
            {
                GC.Collect();
                return(-1);
            }
        }
Esempio n. 7
0
        private static void LoadUserObjectsMDToXmlFile(string prefix)
        {
            SAPbobsCOM.UserObjectsMD userObjectsMD = 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 ""Code"" from OUDO where ""TableName"" like '{0}%'", prefix));
            }

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

                    userObjectsMD = (SAPbobsCOM.UserObjectsMD)sbo_company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD);

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

                        if (documentoFinal == null)
                        {
                            documentoFinal = new XmlDocument();
                            documentoFinal.LoadXml(userObjectsMD.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(UserObjectsFile);
                }

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