Ejemplo n.º 1
0
        public void removeUserField(string tableName, string tableField)
        {
            int          err         = 0;
            string       errMsg      = "";
            UserFieldsMD oUserFields = null;

            try
            {
                //bool exist = UserFieldsExist(tableName, tableField);
                oUserFields = ((UserFieldsMD)(oConnection.Company.GetBusinessObject(BoObjectTypes.oUserFields)));

                tableField = tableField.Replace("U_", "");

                Recordset rs = Query(
                    "SELECT FieldID FROM CUFD " +
                    "WHERE TableID = '" + tableName + "' AND AliasID = '" + tableField + "'"
                    );

                //se o campo existe, remove
                if (rs.RecordCount > 0)
                {
                    oUserFields.GetByKey(tableName, rs.Fields.Item("FieldID").Value);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rs);
                    System.GC.Collect();

                    err    = oUserFields.Remove();
                    errMsg = oConnection.Company.GetLastErrorDescription();
                    if (err == 0)
                    {
                        logger.log("Campo de Usuário " + tableField + " da tabela " +
                                   tableName + " Removido com sucesso.", Logger.LogType.WARNING);
                    }
                    else
                    {
                        logger.log("Erro ao remover Campo de Usuário " + tableField
                                   + " da tabela " + tableName + " Retorno SAP: " + err + " - " + errMsg, Logger.LogType.ERROR);
                    }
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFields);
                System.GC.Collect();
            }
            catch (Exception e)
            {
                oUserFields = null;
                System.GC.Collect();
                logger.log("Erro ao remover Campo de Usuário " + tableField
                           + " da tabela " + tableName + " Retorno SAP: " + err + " - " + errMsg, Logger.LogType.ERROR, e);

                SB1ControlException.SB1ControlException.Save(e);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Exists field.
        /// </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>
        /// <param name="pIntFieldIndex">
        /// Zero-based index of the int field.
        /// </param>
        /// <returns>
        /// True if it succeeds, false if it fails.
        /// </returns>

        private bool ExistsField(string pStrTableName, int pIntFieldIndex)
        {
            UserFieldsMD lObjUserField = null;

            try
            {
                lObjUserField = (UserFieldsMD)DIApplication.Company.GetBusinessObject(BoObjectTypes.oUserFields);
                return(lObjUserField.GetByKey(string.Format("@{0}", pStrTableName), pIntFieldIndex));
            }
            catch (Exception e)
            {
                throw new TableException(e.Message, e);
            }
            finally
            {
                MemoryUtility.ReleaseComObject(lObjUserField);
            }
        }
Ejemplo n.º 3
0
        internal static void removeField(UserFieldsMD uf, string tableName, int fieldID,
                                         SAPbouiCOM.Application app, SAPbobsCOM.Company company)
        {
            int    ret;
            string errMsg;

            if (uf.GetByKey(tableName, fieldID))
            {
                ret = uf.Remove();
                if (ret != 0)
                {
                    company.GetLastError(out ret, out errMsg);
                    app.SetStatusBarMessage(string.Format("Error removing field {0}-{1}",
                                                          tableName, fieldID), SAPbouiCOM.BoMessageTime.bmt_Short, true);
                    throw new Exception(errMsg);
                }
                app.StatusBar.SetSystemMessage(string.Format("Removed field {0}-{1}",
                                                             tableName, fieldID),
                                               SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
            }
        }
        public static void UpdateFieldSettings(string tableName, string fieldAlias, string fieldDescription, string linkedTable)
        {
            UserFieldsMD userFieldsMd = null;

            try
            {
                userFieldsMd = SboApp.Company.GetBusinessObject(BoObjectTypes.oUserFields) as UserFieldsMD;
                if (userFieldsMd == null)
                {
                    return;
                }

                var fieldId = GetFieldId(tableName, fieldAlias);
                if (fieldId == -1)
                {
                    return;
                }
                if (!userFieldsMd.GetByKey(tableName, fieldId))
                {
                    return;
                }

                bool changed = false;

                if (linkedTable != null && linkedTable.Trim('@') != userFieldsMd.LinkedTable.Trim('@'))
                {
                    if (DatabaseHelper.TableExists(linkedTable))
                    {
                        userFieldsMd.LinkedTable = linkedTable.Trim('@');
                    }
                    else
                    {
                        throw new Exception($"Linked table '{linkedTable}' could not be found");
                    }
                    changed = true;
                }

                if (userFieldsMd.Description != fieldDescription)
                {
                    userFieldsMd.Description = fieldDescription;
                    changed = true;
                }

                if (changed)
                {
                    userFieldsMd.Update();
                }
            }
            catch (Exception ex)
            {
                SboApp.Logger.Error($"Failed updating field: {ex.Message}", ex);
                throw;
            }
            finally
            {
                if (userFieldsMd != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(userFieldsMd);
                }
                userFieldsMd = null;
                GC.Collect();
            }
        }
        /// <summary>
        /// Increase UserField Size
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="fieldAlias"></param>
        /// <param name="size"></param>
        /// <param name="editSize"></param>
        /// <returns></returns>
        public static void IncreaseUserFieldSize(string tableName, string fieldAlias, int size, int editSize = 0)
        {
            UserFieldsMD userFieldsMd = null;

            try
            {
                userFieldsMd = SboApp.Company.GetBusinessObject(BoObjectTypes.oUserFields) as UserFieldsMD;
                if (userFieldsMd == null)
                {
                    return;
                }

                var fieldId = GetFieldId(tableName, fieldAlias);
                if (fieldId == -1)
                {
                    return;
                }
                if (!userFieldsMd.GetByKey(tableName, fieldId))
                {
                    return;
                }

                bool changed = false;
                if (userFieldsMd.Size < size && userFieldsMd.EditSize < editSize)
                {
                    if (editSize == 0)
                    {
                        editSize = size;
                    }
                    userFieldsMd.Size     = size;
                    userFieldsMd.EditSize = editSize;
                    changed = true;
                }
                else if (userFieldsMd.Size < size)
                {
                    userFieldsMd.Size = size;
                    changed           = true;
                }
                else if (userFieldsMd.EditSize < editSize)
                {
                    userFieldsMd.EditSize = editSize;
                    changed = true;
                }
                if (changed)
                {
                    userFieldsMd.Update();
                }
            }
            catch (Exception ex)
            {
                SboApp.Logger.Error($"Increase User Field Size Error: {ex.Message}", ex);
                throw;
            }
            finally
            {
                if (userFieldsMd != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(userFieldsMd);
                }
                userFieldsMd = null;
                GC.Collect();
            }
        }
Ejemplo n.º 6
0
 internal static void removeField(UserFieldsMD uf, string tableName, int fieldID, 
                     SAPbouiCOM.Application app, SAPbobsCOM.Company company)
 {
     int ret;
     string errMsg;
     if (uf.GetByKey(tableName, fieldID))
     {
         ret = uf.Remove();
         if (ret != 0)
         {
             company.GetLastError(out ret, out errMsg);
             app.SetStatusBarMessage(string.Format("Error removing field {0}-{1}",
                 tableName, fieldID), SAPbouiCOM.BoMessageTime.bmt_Short, true);
             throw new Exception(errMsg);
         }
         app.StatusBar.SetSystemMessage(string.Format("Removed field {0}-{1}",
             tableName, fieldID),
             SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
     }
 }