public static string CreateTable(string tableName, string tableDescription, BoUTBTableType tableType)
        {
            try
            {
                UserTablesMD oUTables = (UserTablesMD)Company.GetBusinessObject(BoObjectTypes.oUserTables);

                if (oUTables.GetByKey(tableName) == false)
                {
                    oUTables.TableName        = tableName;
                    oUTables.TableDescription = tableDescription;
                    oUTables.TableType        = tableType;
                    int ret = oUTables.Add();

                    return(ret == 0 ? "" : Company.GetLastErrorDescription());
                }

                System.Runtime.InteropServices.Marshal.ReleaseComObject(oUTables);
                return(string.Empty);
            }
            catch (Exception e)
            {
                return($"exeption : {e.Message} sap error : {Company.GetLastErrorDescription()}");
            }
            finally
            {
                GC.Collect();
            }
        }
        private void Create()
        {
            UserTablesMD table = _comp.GetBusinessObject(BoObjectTypes.oUserTables);

            if (table.GetByKey(TABLE_NAME))
            {
                table = null;
                MessageBox.Show("Tabela já criada: " + TABLE_NAME);
            }
            else
            {
                table.TableName        = TABLE_NAME;
                table.TableDescription = "List de Tarefas";
                table.Add();

                if (_comp.GetLastErrorCode() < 0)
                {
                    MessageBox.Show(_comp.GetLastErrorDescription());
                }
                else
                {
                    MessageBox.Show("Tabela: " + TABLE_NAME + " criada com sucesso!");
                }

                Marshal.ReleaseComObject(table);
                GC.Collect();
                table = null;
            }
        }
Example #3
0
        /// <summary>
        /// Initializes the table.
        /// </summary>
        /// <remarks>
        /// Ranaya, 26/05/2017.
        /// </remarks>
        /// <param name="pObjTable">
        /// The object table.
        /// </param>

        private void InitializeTable(T pObjTable)
        {
            UserTablesMD lObjUserTable = pObjTable.GetUserTable();

            try
            {
                if (!ExistsTable(lObjUserTable.TableName))
                {
                    HandleException.Table(lObjUserTable.Add());
                }
            }
            finally
            {
                MemoryUtility.ReleaseComObject(lObjUserTable);
            }
        }
Example #4
0
        public void AddUserTable(Company oCompany, string Name, string Description, BoUTBTableType Type)
        {
            try
            {
                int    lErrCode = 0;
                string lErrStr  = string.Empty;
                string LastMsg  = string.Empty;

                UserTablesMD oUserTablesMD = null;

                oUserTablesMD = (UserTablesMD)oCompany.GetBusinessObject(BoObjectTypes.oUserTables);

                System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD);
                oUserTablesMD = null;
                GC.Collect();
                oUserTablesMD = (UserTablesMD)oCompany.GetBusinessObject(BoObjectTypes.oUserTables);
                lErrCode      = 0;

                if (oUserTablesMD.GetByKey(Name) == false)
                {
                    oUserTablesMD.TableName        = Name;
                    oUserTablesMD.TableDescription = Description;
                    oUserTablesMD.TableType        = Type;

                    if ((lErrCode = oUserTablesMD.Add()) != 0)
                    {
                        oCompany.GetLastError(out lErrCode, out lErrStr);
                        throw new Exception("Falha! \nDescricao B1: " + lErrStr + "\nCodigo Erro B1: " + lErrCode.ToString());
                    }

                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD);
                    oUserTablesMD = null;
                    GC.Collect();

                    if (lErrCode != 0 && lErrCode != -2035)
                    {
                        oCompany.GetLastError(out lErrCode, out lErrStr);
                        throw new Exception("Falha! \nDescricao B1: " + lErrStr + "\nCodigo Erro B1: " + lErrCode.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao criar tabela de usuário: " + ex.Message);
            }
        }
Example #5
0
        public void Execute()
        {
            var result = table.Add();

            if (result != 0)
            {
                var errorArgs = new AddUserTableErrorEventArgs
                {
                    TableName        = table.TableName,
                    ErrorCode        = company.GetLastErrorCode(),
                    ErrorDescription = company.GetLastErrorDescription()
                };

                Error(this, errorArgs);
            }

            Marshal.ReleaseComObject(table);
        }
Example #6
0
        /// <summary>
        /// Adds the UserTable to the current company Database.
        /// </summary>
        /// <param name="company">SAPbobsCOM.Company we are connected to.</param>
        /// <returns>Return value from the SDK action UserTablesMD.Add().</returns>
        public int Add(Company company)
        {
            UserTablesMD userTables = null;
            int          ret        = -1;

            //System.GC.Collect();
            //System.GC.WaitForPendingFinalizers();

            try
            {
                userTables                  = (UserTablesMD)company.GetBusinessObject(BoObjectTypes.oUserTables);
                userTables.TableName        = Name.Substring(1);                // remove @
                userTables.TableType        = Type;
                userTables.TableDescription = Description;

                ret = userTables.Add();

#if     DEBUG
                if (ret != 0)
                {
                    int    errcode;
                    string errmsg;
                    company.GetLastError(out errcode, out errmsg);
                    System.Console.Out.WriteLine("Table " + Name + " : " + errmsg);
                }
#endif
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                // clean DI object
                System.Runtime.InteropServices.Marshal.ReleaseComObject(userTables);
                userTables = null;
                //System.GC.Collect();
                //System.GC.WaitForPendingFinalizers();
            }
            return(ret);
        }
        /// <summary>
        /// Create UDT (tableName of UserTables will allways become UPPERCASE in HANA)
        /// </summary>
        /// <param name="tableName">Table name eg: NS_MyTable (in UPPERCASE is recommended)</param>
        /// <param name="tableDescription"></param>
        /// <param name="tableType"></param>
        /// <returns>Success</returns>
        public static UserDefinedTable CreateTable(string tableName, string tableDescription, BoUTBTableType tableType = BoUTBTableType.bott_NoObject)
        {
            UserTablesMD userTablesMd = null;

            try
            {
                userTablesMd = SboApp.Company.GetBusinessObject(BoObjectTypes.oUserTables) as UserTablesMD;

                if (userTablesMd == null)
                {
                    throw new NullReferenceException("Failed to get UserTablesMD object");
                }

                if (!userTablesMd.GetByKey(tableName))
                {
                    userTablesMd.TableName        = tableName;
                    userTablesMd.TableDescription = tableDescription;
                    userTablesMd.TableType        = tableType;
                    ErrorHelper.HandleErrorWithException(
                        userTablesMd.Add(),
                        $"Could not create UDT {tableName}");
                }
            }
            catch (Exception ex)
            {
                SboApp.Logger.Error($"UDT Create Error: {ex.Message}", ex);
                throw;
            }
            finally
            {
                if (userTablesMd != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(userTablesMd);
                }
                userTablesMd = null;
                GC.Collect();
            }

            return(new UserDefinedTable("@" + tableName));
        }
Example #8
0
        /// <summary>
        /// Cria a tabela dentro do SAP Business One
        /// </summary>
        /// <param name="oCmp">Objeto da conexão do SAP que receberá essa tabela</param>
        /// <param name="oUserTb"></param>
        public static void CriarTabela(Company oCmp, Tabela oUserTb)
        {
            ValidarTabela(oUserTb);

            UserTablesMD oTbMd = (UserTablesMD)oCmp.GetBusinessObject(BoObjectTypes.oUserTables);

            oTbMd.TableName        = oUserTb.TableName;
            oTbMd.TableDescription = oUserTb.Description;
            oTbMd.TableType        = oUserTb.TipoTabela;
            oTbMd.Archivable       = oUserTb.Arquivavel;

            int res = oTbMd.Add();

            System.Runtime.InteropServices.Marshal.ReleaseComObject(oTbMd);
            oTbMd = null;
            GC.Collect();

            if (res != 0)
            {
                throw new Exception(oCmp.GetLastErrorDescription());
            }
        }
Example #9
0
        //Cria tabela de usuario
        public void CreateTable(string tableName, string tableDescr, BoUTBTableType tableType)
        {
            int          err           = 0;
            string       errMsg        = "";
            UserTablesMD oUserTablesMD = null;

            try
            {
                oUserTablesMD = ((UserTablesMD)(oConnection.Company.GetBusinessObject(BoObjectTypes.oUserTables)));
                System.GC.Collect();

                //Verifica se a tabela já existe
                if (oUserTablesMD.GetByKey(tableName))
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD);
                    System.GC.Collect();
                }
                else
                {
                    if (tableName.Length >= 20)
                    {
                        throw new Exception("Nome de tabela maior que 19 caracteres: " + tableName + " Len: " + tableName.Length);
                    }
                    if (tableDescr.Length >= 30)
                    {
                        throw new Exception("Descrição de tabela maior que 29 caracteres: " + tableDescr + " Len: " + tableDescr.Length);
                    }

                    oUserTablesMD.TableName        = tableName;
                    oUserTablesMD.TableDescription = tableDescr;
                    oUserTablesMD.TableType        = tableType;


                    //mostra msg
                    logMessage = "Criando Tabela de Usuário: '" + tableName;
                    logger.log(logMessage, Logger.LogType.INFO);


                    if (oUserTablesMD.Add() != 0)
                    {
                        oConnection.Company.GetLastError(out err, out errMsg);
                        logMessage = "Erro ao criar Tabela de Usuário: '"
                                     + tableName + "': " + errMsg + " : " + err;
                        logger.log(logMessage, Logger.LogType.ERROR, null, false);
                    }

                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD);
                    oUserTablesMD = null;
                    System.GC.Collect();
                }
            }
            catch (Exception e)
            {
                oConnection.Company.GetLastError(out err, out errMsg);
                logMessage = "Erro ao criar Tabela de Usuário: '" + tableName + "': " + errMsg + " : " + err;
                logger.log(logMessage, Logger.LogType.ERROR, e);

                //SB1ControlException.SB1ControlException.Save(e);
                if (oUserTablesMD != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD);
                }
                oUserTablesMD = null;
                System.GC.Collect();
                if (oUserTablesMD != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD);
                }
                oUserTablesMD = null;
                System.GC.Collect();
            }
        }