public static void CreateUDO(string tableName, SAPbobsCOM.BoUDOObjType objtype)
        {
            SAPbobsCOM.UserObjectsMD oUdtMD = null /* TODO Change to default(_) if this is not a reference type */; // ‘
            string errmsg = "";

            try
            {
                SAPbobsCOM.Company SBO_Company = Conexion.oCompany;

                oUdtMD = (SAPbobsCOM.UserObjectsMD)SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD);
                if (oUdtMD.GetByKey(tableName) == false)
                {
                    oUdtMD.Code      = tableName;
                    oUdtMD.Name      = tableName;
                    oUdtMD.TableName = tableName;

                    oUdtMD.ObjectType = objtype;

                    oUdtMD.CanCancel            = SAPbobsCOM.BoYesNoEnum.tNO;
                    oUdtMD.CanClose             = SAPbobsCOM.BoYesNoEnum.tNO;
                    oUdtMD.CanDelete            = SAPbobsCOM.BoYesNoEnum.tNO;
                    oUdtMD.CanFind              = SAPbobsCOM.BoYesNoEnum.tNO;
                    oUdtMD.CanLog               = SAPbobsCOM.BoYesNoEnum.tNO;
                    oUdtMD.ManageSeries         = SAPbobsCOM.BoYesNoEnum.tNO;
                    oUdtMD.CanCreateDefaultForm = SAPbobsCOM.BoYesNoEnum.tNO;
                    oUdtMD.CanYearTransfer      = SAPbobsCOM.BoYesNoEnum.tNO;
                    oUdtMD.EnableEnhancedForm   = SAPbobsCOM.BoYesNoEnum.tYES;
                    oUdtMD.MenuItem             = SAPbobsCOM.BoYesNoEnum.tNO;
                    oUdtMD.UseUniqueFormType    = SAPbobsCOM.BoYesNoEnum.tNO;
                    oUdtMD.Position             = 1;
                    oUdtMD.FatherMenuID         = 2048;
                    //oUdtMD.LogTableName = "";
                    if (objtype == SAPbobsCOM.BoUDOObjType.boud_MasterData)
                    {
                        oUdtMD.FormColumns.FormColumnAlias = "Code";
                        oUdtMD.FormColumns.Add();
                    }
                    else
                    {
                        oUdtMD.FormColumns.FormColumnAlias = "DocEntry";
                        oUdtMD.FormColumns.Add();
                    }

                    int lRetCode;
                    lRetCode = oUdtMD.Add();

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

                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oUdtMD);
                    oUdtMD = null /* TODO Change to default(_) if this is not a reference type */;
                    GC.Collect();
                    errmsg = "";
                }
                else
                {
                    errmsg = "";
                }
            }
            catch (Exception)
            {
            }
        }
        public static string CreateUdo(string udoCode, string udoDescription, string headerTable, string chidlTable, int position, int fatherMenuId)
        {
            SAPbobsCOM.UserObjectsMD udo = (SAPbobsCOM.UserObjectsMD)DiManager.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD);
            bool updateFlag = udo.GetByKey(udoCode);

            udo.Code                  = udoCode;
            udo.Name                  = udoDescription;
            udo.ObjectType            = BoUDOObjType.boud_Document;
            udo.TableName             = headerTable;
            udo.ChildTables.TableName = chidlTable;
            udo.ChildTables.Add();


            udo.CanCancel            = BoYesNoEnum.tNO;
            udo.CanClose             = BoYesNoEnum.tYES;
            udo.CanDelete            = BoYesNoEnum.tNO;
            udo.CanFind              = BoYesNoEnum.tYES;
            udo.MenuCaption          = udoDescription;
            udo.CanCreateDefaultForm = BoYesNoEnum.tYES;
            udo.EnableEnhancedForm   = BoYesNoEnum.tYES;
            udo.MenuItem             = BoYesNoEnum.tYES;
            udo.Position             = position;
            udo.FatherMenuID         = fatherMenuId;
            udo.MenuUID              = udoCode;

            udo.FormColumns.FormColumnAlias       = "DocEntry";
            udo.FormColumns.FormColumnDescription = "DocEntry";
            udo.FormColumns.Add();



            return(updateFlag ? udo.Update() != 0 ? Company.GetLastErrorDescription() : string.Empty : udo.Add() != 0 ? Company.GetLastErrorDescription() : string.Empty);
        }
Пример #3
0
        internal static int AddUdo(Tabelas tabela)
        {
            int intRetCode = -1;

            SAPbobsCOM.UserObjectsMD oUserObjectMD = null;

            oUserObjectMD                      = ((SAPbobsCOM.UserObjectsMD)(B1AppDomain.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD)));
            oUserObjectMD.CanCancel            = tabela.Udos.Cancel;
            oUserObjectMD.CanClose             = tabela.Udos.Close;
            oUserObjectMD.CanCreateDefaultForm = tabela.Udos.CreateDefaultForm;
            oUserObjectMD.EnableEnhancedForm   = tabela.Udos.EnableEnhancedform;
            if (tabela.Udos.CreateDefaultForm == SAPbobsCOM.BoYesNoEnum.tYES)
            {
                if (tabela.Udos.ObjectType != BoUDOObjType.boud_Document)
                {
                    oUserObjectMD.FormColumns.FormColumnAlias       = "Code";
                    oUserObjectMD.FormColumns.FormColumnDescription = "Code";
                }
                else
                {
                    oUserObjectMD.FormColumns.FormColumnAlias       = "DocEntry";
                    oUserObjectMD.FormColumns.FormColumnDescription = "DocEntry";
                }

                int voltaCampos = 1;
                foreach (Campos campo in tabela.Campos)
                {
                    oUserObjectMD.FormColumns.Add();
                    oUserObjectMD.FormColumns.SetCurrentLine(voltaCampos);
                    oUserObjectMD.FormColumns.FormColumnAlias       = "U_" + campo.NomeCampo;
                    oUserObjectMD.FormColumns.FormColumnDescription = campo.DescricaoCampo;
                    oUserObjectMD.FormColumns.Editable  = BoYesNoEnum.tYES;
                    oUserObjectMD.FormColumns.SonNumber = 0;
                    voltaCampos++;
                }
            }

            oUserObjectMD.CanDelete = tabela.Udos.Delete;
            oUserObjectMD.CanFind   = tabela.Udos.Find;
            if (tabela.Udos.Find == SAPbobsCOM.BoYesNoEnum.tYES)
            {
                if (tabela.Udos.ObjectType != BoUDOObjType.boud_Document)
                {
                    oUserObjectMD.FindColumns.ColumnAlias       = "Code";
                    oUserObjectMD.FindColumns.ColumnDescription = "Code";
                    oUserObjectMD.FindColumns.Add();
                    oUserObjectMD.FindColumns.ColumnAlias       = "Name";
                    oUserObjectMD.FindColumns.ColumnDescription = "Name";
                }
                else
                {
                    oUserObjectMD.FindColumns.ColumnAlias       = "DocEntry";
                    oUserObjectMD.FindColumns.ColumnDescription = "DocEntry";
                    oUserObjectMD.FindColumns.ColumnAlias       = "DocNum";
                    oUserObjectMD.FindColumns.ColumnDescription = "DocNum";
                }

                int voltaFind = 1;
                foreach (Campos campo in tabela.Campos)
                {
                    oUserObjectMD.FindColumns.Add();
                    oUserObjectMD.FindColumns.SetCurrentLine(voltaFind);
                    oUserObjectMD.FindColumns.ColumnAlias       = "U_" + campo.NomeCampo;
                    oUserObjectMD.FindColumns.ColumnDescription = campo.DescricaoCampo;
                    voltaFind++;
                }
            }


            oUserObjectMD.CanYearTransfer = tabela.Udos.YearTransfer;
            oUserObjectMD.Code            = tabela.Udos.Code;
            oUserObjectMD.ManageSeries    = tabela.Udos.ManageSeries;
            oUserObjectMD.Name            = tabela.Udos.Name;
            oUserObjectMD.ObjectType      = tabela.Udos.ObjectType;
            oUserObjectMD.TableName       = tabela.Udos.TableName;

            int numerofilho = 1;

            if (tabela.Udos.Filhos != null)
            {
                foreach (UdoFilhos listaUdo in tabela.Udos.Filhos)
                {
                    if (numerofilho > 1)
                    {
                        oUserObjectMD.ChildTables.Add();
                    }

                    oUserObjectMD.ChildTables.TableName  = listaUdo.TableName;
                    oUserObjectMD.ChildTables.ObjectName = listaUdo.TableName;


                    if (tabela.Udos.EnableEnhancedform == BoYesNoEnum.tNO)
                    {
                        foreach (Tabelas tabelaFilho in B1AppDomain.DicionarioTabelasCampos.Where(p => p.Value.NomeTabela == listaUdo.TableName).Select(p => p.Value))
                        {
                            int voltaFilhos = 1;
                            foreach (Campos campo in tabelaFilho.Campos)
                            {
                                oUserObjectMD.FormColumns.Add();
                                oUserObjectMD.FormColumns.SetCurrentLine(voltaFilhos);
                                oUserObjectMD.FormColumns.FormColumnAlias       = "U_" + campo.NomeCampo;
                                oUserObjectMD.FormColumns.FormColumnDescription = campo.DescricaoCampo;
                                oUserObjectMD.FormColumns.Editable  = BoYesNoEnum.tYES;
                                oUserObjectMD.FormColumns.SonNumber = numerofilho;
                                voltaFilhos++;
                            }
                        }
                    }
                    else
                    {
                        foreach (Tabelas tabelaFilho in B1AppDomain.DicionarioTabelasCampos.Where(p => p.Value.NomeTabela == listaUdo.TableName).Select(p => p.Value))
                        {
                            int voltaNovo = 0;
                            foreach (Campos campo in tabelaFilho.Campos)
                            {
                                if (voltaNovo > 0)
                                {
                                    oUserObjectMD.EnhancedFormColumns.Add();
                                }

                                oUserObjectMD.EnhancedFormColumns.SetCurrentLine(voltaNovo);
                                oUserObjectMD.EnhancedFormColumns.ColumnAlias       = "U_" + campo.NomeCampo;
                                oUserObjectMD.EnhancedFormColumns.ColumnDescription = campo.DescricaoCampo;
                                oUserObjectMD.EnhancedFormColumns.Editable          = BoYesNoEnum.tYES;
                                oUserObjectMD.EnhancedFormColumns.ColumnIsUsed      = BoYesNoEnum.tYES;
                                oUserObjectMD.EnhancedFormColumns.ChildNumber       = numerofilho;
                                voltaNovo++;
                            }
                        }
                    }

                    numerofilho++;
                }
            }



            oUserObjectMD.RebuildEnhancedForm = tabela.Udos.RebuildEnhancedForm;

            oUserObjectMD.FormSRF = tabela.Udos.Formulario;

            intRetCode = oUserObjectMD.Add();

            //mata objeto para reutilizar senao trava
            Marshal.FinalReleaseComObject(oUserObjectMD);
            oUserObjectMD = null;
            GC.Collect();


            //verifica e retorna erro
            if (intRetCode != 0 && intRetCode != -2035)
            {
                // B1Exception.throwException("MetaData.CriaCampos: ", new Exception(B1AppDomain.Company.GetLastErrorDescription()));
            }
            else if (intRetCode == 0)
            {
                controleUdo = true;
            }
            //else if(intRetCode == 0)
            //{
            //    oUserObjectMD = ((SAPbobsCOM.UserObjectsMD)(B1AppDomain.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD)));
            //    if(oUserObjectMD.GetByKey(tabela.Udos.Code))
            //    {
            //        oUserObjectMD.RebuildEnhancedForm = BoYesNoEnum.tNO;
            //        oUserObjectMD.FormSRF = tabela.Udos.Formulario;
            //        oUserObjectMD.Update();

            //    }

            //    //mata objeto para reutilizar senao trava
            //    Marshal.FinalReleaseComObject(oUserObjectMD);
            //    oUserObjectMD = null;
            //    GC.Collect();

            //}

            return(intRetCode);
        }
Пример #4
0
        public bool registerUDO(string UDOCode, string UDOName, SAPbobsCOM.BoUDOObjType UDOType, string[,] findAliasNDescription, string parentTableName, string childTable1 = "", string childTable2 = "", string childTable3 = "", string childTable4 = "", SAPbobsCOM.BoYesNoEnum LogOption = SAPbobsCOM.BoYesNoEnum.tNO, string MenuId = "", int parrentId = 0)
        {
            bool functionReturnValue = false;

            try
            {
                bool actionSuccess = false;
                SAPbobsCOM.UserObjectsMD v_udoMD = default(SAPbobsCOM.UserObjectsMD);

                functionReturnValue          = false;
                v_udoMD                      = (SAPbobsCOM.UserObjectsMD)oDiCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD);
                v_udoMD.CanCancel            = SAPbobsCOM.BoYesNoEnum.tYES;
                v_udoMD.CanClose             = SAPbobsCOM.BoYesNoEnum.tYES;
                v_udoMD.CanCreateDefaultForm = SAPbobsCOM.BoYesNoEnum.tNO;
                v_udoMD.CanDelete            = SAPbobsCOM.BoYesNoEnum.tYES;
                v_udoMD.CanFind              = SAPbobsCOM.BoYesNoEnum.tYES;
                v_udoMD.CanLog               = SAPbobsCOM.BoYesNoEnum.tNO;
                v_udoMD.CanYearTransfer      = SAPbobsCOM.BoYesNoEnum.tYES;
                v_udoMD.ManageSeries         = SAPbobsCOM.BoYesNoEnum.tYES;
                if (!string.IsNullOrEmpty(MenuId))
                {
                    v_udoMD.CanCreateDefaultForm = SAPbobsCOM.BoYesNoEnum.tYES;
                    //v_udoMD.RebuildEnhancedForm = SAPbobsCOM.BoYesNoEnum.tYES
                    v_udoMD.MenuItem = SAPbobsCOM.BoYesNoEnum.tYES;

                    v_udoMD.MenuUID     = MenuId;
                    v_udoMD.MenuCaption = UDOName;
                    // v_udoMD.EnableEnhancedForm = SAPbobsCOM.BoYesNoEnum.tYES
                    v_udoMD.FatherMenuID = parrentId;
                    v_udoMD.Position     = 2;
                }

                v_udoMD.Code      = UDOCode;
                v_udoMD.Name      = UDOName;
                v_udoMD.TableName = parentTableName;
                if (LogOption == SAPbobsCOM.BoYesNoEnum.tYES)
                {
                    v_udoMD.CanLog       = SAPbobsCOM.BoYesNoEnum.tYES;
                    v_udoMD.LogTableName = "A" + parentTableName;
                }
                v_udoMD.ObjectType = UDOType;
                for (Int16 i = 0; i <= findAliasNDescription.GetLength(0) - 1; i++)
                {
                    if (i > 0)
                    {
                        v_udoMD.FindColumns.Add();
                    }
                    v_udoMD.FindColumns.ColumnAlias       = findAliasNDescription[i, 0];
                    v_udoMD.FindColumns.ColumnDescription = findAliasNDescription[i, 1];
                }
                if (!string.IsNullOrEmpty(childTable1))
                {
                    v_udoMD.ChildTables.TableName = childTable1;
                    v_udoMD.ChildTables.Add();
                }
                if (!string.IsNullOrEmpty(childTable2))
                {
                    v_udoMD.ChildTables.TableName = childTable2;
                    v_udoMD.ChildTables.Add();
                }
                if (!string.IsNullOrEmpty(childTable3))
                {
                    v_udoMD.ChildTables.TableName = childTable3;
                    v_udoMD.ChildTables.Add();
                }
                if (!string.IsNullOrEmpty(childTable4))
                {
                    v_udoMD.ChildTables.TableName = childTable4;
                    v_udoMD.ChildTables.Add();
                }
                if (v_udoMD.Add() == 0)
                {
                    functionReturnValue = true;
                }
                else
                {
                    throw new Exception("Failed to Register UDO >" + UDOCode + ">" + UDOName + " >" + oDiCompany.GetLastErrorDescription());
                    functionReturnValue = false;
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(v_udoMD);
                v_udoMD = null;
                GC.Collect();
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to UDO Register : " + ex.Message);
            }
            finally
            {
            }
            return(functionReturnValue);
        }
        public void CreateUserObject(string ObjectName, string ObjectDesc, string TableName, SAPbobsCOM.BoUDOObjType ObjectType, bool CanLog, bool CanYearTransfer, bool CanCancel, bool CanClose, bool CanCreateDefaultForm, bool CanDelete, bool CanFind, int FatherMenuId, int menuPosition, GenericModel findColumns)
        {
            // se não preenchido um table name separado, usa o mesmo do objeto
            if (String.IsNullOrEmpty(TableName))
            {
                TableName = ObjectName;
            }

            Log.AppendFormat("Criação/Atualização do Objeto de usuário {0}", ObjectName);

            SAPbobsCOM.UserObjectsMD UserObjectsMD = (SAPbobsCOM.UserObjectsMD)SBOApp.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD);

            // Remove a arroba do usertable Name
            TableName = TableName.Replace("@", "");

            bool bUpdate = UserObjectsMD.GetByKey(ObjectName);

            UserObjectsMD.Code       = ObjectName;
            UserObjectsMD.Name       = ObjectDesc;
            UserObjectsMD.ObjectType = ObjectType;
            UserObjectsMD.TableName  = TableName;

            //UserObjectsMD.CanArchive = GetSapBoolean(CanArchive);
            UserObjectsMD.CanCancel            = GetSapBoolean(CanCancel);
            UserObjectsMD.CanClose             = GetSapBoolean(CanClose);
            UserObjectsMD.CanCreateDefaultForm = GetSapBoolean(CanCreateDefaultForm);
            UserObjectsMD.CanDelete            = GetSapBoolean(CanDelete);
            UserObjectsMD.CanFind         = GetSapBoolean(CanFind);
            UserObjectsMD.CanLog          = GetSapBoolean(CanLog);
            UserObjectsMD.CanYearTransfer = GetSapBoolean(CanYearTransfer);

            if (CanCreateDefaultForm)
            {
                UserObjectsMD.CanCreateDefaultForm = SAPbobsCOM.BoYesNoEnum.tYES;
                UserObjectsMD.CanCancel            = GetSapBoolean(CanCancel);
                UserObjectsMD.CanClose             = GetSapBoolean(CanClose);
                UserObjectsMD.CanDelete            = GetSapBoolean(CanDelete);
                UserObjectsMD.CanFind           = GetSapBoolean(CanFind);
                UserObjectsMD.ExtensionName     = "";
                UserObjectsMD.OverwriteDllfile  = SAPbobsCOM.BoYesNoEnum.tYES;
                UserObjectsMD.UseUniqueFormType = SAPbobsCOM.BoYesNoEnum.tYES;
                UserObjectsMD.ManageSeries      = SAPbobsCOM.BoYesNoEnum.tYES;

                UserObjectsMD.FormColumns.FormColumnAlias       = "Code";
                UserObjectsMD.FormColumns.FormColumnDescription = "Código";
                UserObjectsMD.FormColumns.Add();

                UserObjectsMD.FormColumns.FormColumnAlias       = "Name";
                UserObjectsMD.FormColumns.FormColumnDescription = "Descrição";
                UserObjectsMD.FormColumns.Editable = SAPbobsCOM.BoYesNoEnum.tYES;
                UserObjectsMD.FormColumns.Add();

                UserObjectsMD.FindColumns.ColumnAlias       = "Code";
                UserObjectsMD.FindColumns.ColumnDescription = "Código";
                UserObjectsMD.FindColumns.Add();

                UserObjectsMD.FindColumns.ColumnAlias       = "Name";
                UserObjectsMD.FindColumns.ColumnDescription = "Descrição";
                UserObjectsMD.FindColumns.Add();

                if (findColumns != null)
                {
                    FindColumns = findColumns;
                }

                if (FindColumns != null && FindColumns.Fields != null)
                {
                    foreach (KeyValuePair <string, object> pair in FindColumns.Fields)
                    {
                        UserObjectsMD.FindColumns.ColumnAlias       = pair.Key;
                        UserObjectsMD.FindColumns.ColumnDescription = pair.Value.ToString();
                        UserObjectsMD.FindColumns.Add();
                    }
                }

                UserObjectsMD.FatherMenuID = FatherMenuId;
                UserObjectsMD.Position     = menuPosition;
                UserObjectsMD.MenuItem     = SAPbobsCOM.BoYesNoEnum.tYES;
                UserObjectsMD.MenuUID      = ObjectName;
                UserObjectsMD.MenuCaption  = ObjectDesc;
            }

            if (bUpdate)
            {
                //CodErro = UserObjectsMD.Update();
            }
            else
            {
                CodErro = UserObjectsMD.Add();
            }

            this.ValidateAction();

            Marshal.ReleaseComObject(UserObjectsMD);
            UserObjectsMD      = null;
            FindColumns        = new GenericModel();
            FindColumns.Fields = new Dictionary <string, object>();
        }