예제 #1
0
        /// <summary>
        /// Adds the UDO object into the current company Database.
        /// </summary>
        /// <param name="company">SAPbobsCOM.Company we are connected to.</param>
        /// <returns>Return value of the UserObjectsMD.Add() call.</returns>
        public int Add(Company company)
        {
            UserObjectsMD udo = (UserObjectsMD)
                                company.GetBusinessObject(BoObjectTypes.oUserObjectsMD);

            udo.Code       = Code;
            udo.Name       = Name;
            udo.TableName  = Table;
            udo.ObjectType = Type;

            foreach (string child in Children)
            {
                udo.ChildTables.TableName = child;
                udo.ChildTables.Add();
            }

            // Services Definition
            udo.CanFind = CanFind;
            if (CanFind == BoYesNoEnum.tYES)
            {
                for (int i = 0; i < FindColumnsAlias.GetLength(0); i++)
                {
                    udo.FindColumns.ColumnAlias       = FindColumnsAlias[i];
                    udo.FindColumns.ColumnDescription = FindColumnsDesc[i];
                    udo.FindColumns.Add();
                }
            }
            udo.CanDelete       = CanDelete;
            udo.CanCancel       = CanCancel;
            udo.CanClose        = CanClose;
            udo.ManageSeries    = ManageSeries;
            udo.CanYearTransfer = CanYearTransfer;
            udo.CanLog          = CanLog;
            udo.LogTableName    = LogTableName;

            int ret = udo.Add();

#if     DEBUG
            if (ret != 0)
            {
                int    errcode;
                string errmsg;
                company.GetLastError(out errcode, out errmsg);
                System.Console.Out.WriteLine("UDO " + Name + " : " + errmsg);
            }
#endif

            // clean DI object
            System.Runtime.InteropServices.Marshal.ReleaseComObject(udo);
            udo = null;
            //System.GC.Collect();
            //System.GC.WaitForPendingFinalizers();

            return(ret);
        }
예제 #2
0
파일: ObjectDAO.cs 프로젝트: xavl369/UGRS
        /// <summary> Initializes the object. </summary>
        /// <remarks> Ranaya, 26/05/2017. </remarks>
        /// <param name="pObjObject"> The object object. </param>

        private void InitializeObject(IObject pObjObject)
        {
            UserObjectsMD lObjUserObject = pObjObject.GetUserObject();

            try
            {
                if (!ExistsObject(lObjUserObject.Code))
                {
                    HandleException.Object(lObjUserObject.Add());
                }
            }
            finally
            {
                MemoryUtility.ReleaseComObject(lObjUserObject);
            }
        }
예제 #3
0
        public void Execute()
        {
            var result = userObjectMd.Add();

            if (result != 0)
            {
                var errorArgs = new AddUserObjectErrorEventArgs
                {
                    TableName        = userObjectMd.TableName,
                    ObjectName       = userObjectMd.Name,
                    ErrorCode        = company.GetLastErrorCode(),
                    ErrorDescription = company.GetLastErrorDescription()
                };

                OnError(this, errorArgs);
            }

            Marshal.ReleaseComObject(userObjectMd);
        }
예제 #4
0
        public void addUDO(Company oCompany, string sObjeto, string sCode, string sName, string sTableName, BoUDOObjType TipoObjeto,
                           BoYesNoEnum CanFind, BoYesNoEnum CanDelete, BoYesNoEnum CanCancel, BoYesNoEnum CanYearTransfer, BoYesNoEnum CanLog,
                           string sLogTableName)
        {
            UserObjectsMD oUserObjectMD = null;

            oUserObjectMD = (UserObjectsMD)oCompany.GetBusinessObject(BoObjectTypes.oUserObjectsMD);

            int    lRetVal;
            string lErrMsg = string.Empty;

            System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserObjectMD);
            oUserObjectMD = null;
            GC.Collect();
            oUserObjectMD = (UserObjectsMD)oCompany.GetBusinessObject(BoObjectTypes.oUserObjectsMD);

            if (oUserObjectMD.GetByKey(sObjeto) == false)
            {
                oUserObjectMD.Code      = sCode;
                oUserObjectMD.Name      = sName;
                oUserObjectMD.TableName = sTableName;

                oUserObjectMD.ObjectType = TipoObjeto;

                oUserObjectMD.CanFind         = CanFind;
                oUserObjectMD.CanDelete       = CanDelete;
                oUserObjectMD.CanCancel       = CanCancel;
                oUserObjectMD.CanYearTransfer = CanYearTransfer;
                oUserObjectMD.CanLog          = CanLog;
                oUserObjectMD.LogTableName    = sLogTableName;

                lRetVal = oUserObjectMD.Add();

                if (lRetVal != 0)
                {
                    oCompany.GetLastError(out lRetVal, out lErrMsg);
                }
            }

            System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserObjectMD);
            oUserObjectMD = null;
            GC.Collect();
        }
        public void MakeFieldsSearchable(string tableInitial)
        {
            Log.AppendFormat("Liberando campos para pesquisa");

            Recordset rs  = (Recordset)(SBOApp.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset));
            string    sql = "SELECT * FROM CUFD WHERE TableID LIKE '{0}%'";

            rs.DoQuery(String.Format(sql, tableInitial));
            string        tableName     = String.Empty;
            UserObjectsMD userObjectsMD = (UserObjectsMD)SBOApp.Company.GetBusinessObject(BoObjectTypes.oUserObjectsMD);

            while (!rs.EoF)
            {
                if (tableName != rs.Fields.Item("TableID").Value.ToString())
                {
                    tableName = rs.Fields.Item("TableID").Value.ToString();
                }

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

                bool bUpdate = userObjectsMD.GetByKey(tableName);

                userObjectsMD.FindColumns.ColumnAlias       = rs.Fields.Item("AliasID").Value.ToString();
                userObjectsMD.FindColumns.ColumnDescription = rs.Fields.Item("Descr").Value.ToString();
                userObjectsMD.FindColumns.Add();

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

                this.ValidateAction();

                Marshal.ReleaseComObject(userObjectsMD);
                userObjectsMD = null;
            }
        }
        public static void CriarObjeto(Company oCmp, Objeto objeto)
        {
            UserObjectsMD oUdo = (UserObjectsMD)oCmp.GetBusinessObject(BoObjectTypes.oUserObjectsMD);

            oUdo.Code            = objeto.Codigo;
            oUdo.Name            = objeto.Name;
            oUdo.ObjectType      = objeto.Tipo;
            oUdo.TableName       = objeto.NomeTabela;
            oUdo.CanFind         = objeto.CanFind;
            oUdo.CanDelete       = objeto.CanDelete;
            oUdo.CanCancel       = objeto.CanCancel;
            oUdo.CanLog          = objeto.CanLog;
            oUdo.ManageSeries    = objeto.MngSeries;
            oUdo.CanYearTransfer = objeto.CanYrTransf;

            foreach (Campo campo in objeto.Campos)
            {
                oUdo.FindColumns.ColumnAlias       = campo.Name;
                oUdo.FindColumns.ColumnDescription = campo.Description;
                oUdo.FindColumns.Add();
            }

            if (objeto.TabelaFilhas != null)
            {
                foreach (Tabela tabela in objeto.TabelaFilhas)
                {
                    oUdo.ChildTables.TableName = tabela.TableName;
                    oUdo.ChildTables.Add();
                }
            }

            int a = oUdo.Add();

            System.Runtime.InteropServices.Marshal.ReleaseComObject(oUdo);
            oUdo = null;
            GC.Collect();
            if (a != 0)
            {
                throw new Exception(oCmp.GetLastErrorDescription());
            }
        }
예제 #7
0
        private void CreateUDO(string udoName, string udoCode, BoUDOObjType udoType, string headerTableName, List <String> childTables, BoYesNoEnum isMenuItem, string menuCaption, int fatherMenuId, int menuPosition, BoYesNoEnum canCancel = BoYesNoEnum.tYES, BoYesNoEnum canClose = BoYesNoEnum.tNO, BoYesNoEnum canCreateDefaultForm = BoYesNoEnum.tYES, BoYesNoEnum canDelete = BoYesNoEnum.tYES, BoYesNoEnum canFind = BoYesNoEnum.tYES, BoYesNoEnum canLog = BoYesNoEnum.tYES, BoYesNoEnum canYearTransfer = BoYesNoEnum.tNO)
        {
            try
            {
                if (!(AddOnUtilities.UDOExist(udoName)))
                {
                    UserObjectsMD UDO = (UserObjectsMD)AddOnUtilities.oCompany.GetBusinessObject(BoObjectTypes.oUserObjectsMD);

                    //Set Services
                    // TODO: use optional params for properties below
                    UDO.CanCancel            = canCancel;
                    UDO.CanClose             = canClose;
                    UDO.CanCreateDefaultForm = canCreateDefaultForm;
                    UDO.CanDelete            = canDelete;
                    UDO.CanFind         = canFind;
                    UDO.CanLog          = canLog;
                    UDO.CanYearTransfer = canYearTransfer;

                    UDO.TableName             = headerTableName;
                    UDO.FormColumns.SonNumber = childTables.Count;
                    UDO.EnableEnhancedForm    = BoYesNoEnum.tYES; // To show Header Line Style
                    UDO.Code       = udoCode;
                    UDO.Name       = udoName;
                    UDO.ObjectType = udoType;

                    //Display columns
                    UDO.FormColumns.FormColumnAlias       = "Code";
                    UDO.FormColumns.FormColumnDescription = "Code";
                    UDO.FormColumns.Editable = BoYesNoEnum.tYES;
                    UDO.FormColumns.Add();

                    UDO.FormColumns.FormColumnAlias       = "U_User";
                    UDO.FormColumns.FormColumnDescription = "User";
                    UDO.FormColumns.Editable = BoYesNoEnum.tYES;
                    UDO.FormColumns.Add();

                    //UDO.FormColumns.FormColumnAlias = "U_Dimension1";
                    //UDO.FormColumns.FormColumnDescription = "Dimension 1";
                    //UDO.FormColumns.Add();

                    //UDO.FormColumns.FormColumnAlias = "U_Dimension2";
                    //UDO.FormColumns.FormColumnDescription = "Dimension 2";
                    //UDO.FormColumns.Add();

                    //Columns to be used in find mode
                    UDO.FindColumns.ColumnAlias       = "Code";
                    UDO.FindColumns.ColumnDescription = "Code";
                    UDO.FindColumns.Add();

                    UDO.FindColumns.ColumnAlias       = "U_User";
                    UDO.FindColumns.ColumnDescription = "User";
                    UDO.FindColumns.Add();

                    // Set UDO to have a menu
                    UDO.MenuItem    = isMenuItem;
                    UDO.MenuCaption = menuCaption;
                    // Set father and gnment of menu item.
                    UDO.FatherMenuID = fatherMenuId;
                    UDO.Position     = 1;
                    // Set UDO menu UID
                    UDO.MenuUID = "UserDimension";

                    //Link with child tables.
                    foreach (var childTable in childTables)
                    {
                        UDO.ChildTables.TableName = childTable;
                        UDO.ChildTables.Add();
                    }

                    int RetCode = UDO.Add();
                    if (RetCode != 0)
                    {
                        string errMsg = AddOnUtilities.oCompany.GetLastErrorDescription();
                        MessageBox.Show("Failed to add UDO");
                    }
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(UDO);
                }
            }
            catch (Exception ex)
            {
                AddOnUtilities.MsgBoxWrapper(ex.Message + " " + ex.StackTrace);
                SAPbouiCOM.EventForm e = null;
            }
        }