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;
            }
        }
        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();
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Exists table.
        /// </summary>
        /// <remarks>
        /// Ranaya, 26/05/2017.
        /// </remarks>
        /// <exception cref="TableException">
        /// Thrown when a Table error condition occurs.
        /// </exception>
        /// <param name="pStrTableName">
        /// Name of the string table.
        /// </param>
        /// <returns>
        /// True if it succeeds, false if it fails.
        /// </returns>

        private bool ExistsTable(string pStrTableName)
        {
            UserTablesMD lObjUserTable = null;

            try
            {
                lObjUserTable = (UserTablesMD)DIApplication.Company.GetBusinessObject(BoObjectTypes.oUserTables);
                return(lObjUserTable.GetByKey(pStrTableName));
            }
            catch (Exception e)
            {
                throw new TableException(e.Message, e);
            }
            finally
            {
                MemoryUtility.ReleaseComObject(lObjUserTable);
            }
        }
Exemplo n.º 5
0
        internal static void removeTable(UserTablesMD ut, string name, SAPbouiCOM.Application app,
                                         SAPbobsCOM.Company company)
        {
            int    ret;
            string errMsg;

            if (ut.GetByKey(name))
            {
                ret = ut.Remove();
                if (ret != 0)
                {
                    company.GetLastError(out ret, out errMsg);
                    app.SetStatusBarMessage("Error removing table " + name, SAPbouiCOM.BoMessageTime.bmt_Short, true);
                    throw new Exception(errMsg);
                }
                app.StatusBar.SetSystemMessage("Removed table " + name,
                                               SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
            }
        }
        /// <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));
        }
Exemplo n.º 7
0
        public void removeUserTable(string tableName)
        {
            int          err       = 0;
            string       errMsg    = "";
            UserTablesMD userTable = null;

            try
            {
                userTable = ((UserTablesMD)(oConnection.Company.GetBusinessObject(BoObjectTypes.oUserTables)));

                System.Runtime.InteropServices.Marshal.ReleaseComObject(userTable);
                System.GC.Collect();

                userTable = ((UserTablesMD)(oConnection.Company.GetBusinessObject(BoObjectTypes.oUserTables)));
                userTable.GetByKey(tableName);

                if (userTable.Remove() == 0)
                {
                    logMessage = "Tabela de Usuário " + tableName + " removida.";
                    logger.log(logMessage, Logger.LogType.INFO);
                }
                else
                {
                    oConnection.Company.GetLastError(out err, out errMsg);
                    logMessage = "Erro ao remover Tabela de Usuário: '"
                                 + tableName + "': " + errMsg + " : " + err;
                    logger.log(logMessage, Logger.LogType.ERROR, null, false);
                }
            }
            catch (Exception e)
            {
                oConnection.Company.GetLastError(out err, out errMsg);
                logMessage = "Erro ao remover Tabela de Usuário: '"
                             + tableName + "': " + errMsg + " : " + err + " : " + e.Message;
                logger.log(logMessage, Logger.LogType.ERROR, e);
                SB1ControlException.SB1ControlException.Save(e);
            }
        }
Exemplo n.º 8
0
 internal static void removeTable(UserTablesMD ut, string name, SAPbouiCOM.Application app,
                                 SAPbobsCOM.Company company)
 {
     int ret;
     string errMsg;
     if (ut.GetByKey(name))
     {
         ret = ut.Remove();
         if (ret != 0)
         {
             company.GetLastError(out ret, out errMsg);
             app.SetStatusBarMessage("Error removing table " + name, SAPbouiCOM.BoMessageTime.bmt_Short, true);
             throw new Exception(errMsg);
         }
         app.StatusBar.SetSystemMessage("Removed table " + name,
             SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
     }
 }
Exemplo n.º 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();
            }
        }