Exemplo n.º 1
0
        }       //	checkStandardColumns

        /// <summary>
        /// Create Column in AD and DB
        /// </summary>
        /// <param name="col">Column Object</param>
        /// <param name="table">Table Object</param>
        /// <param name="alsoInDB">Also in DB</param>
        /// <returns></returns>
        private static bool CreateColumn(MColumn col, MTable table, bool alsoInDB)
        {
            //	Element
            M_Element element = M_Element.Get(col.GetCtx(), col.GetColumnName(), col.Get_TrxName());

            if (element == null)
            {
                element = new M_Element(col.GetCtx(), col.GetColumnName(), col.GetEntityType(), null);
                if (!element.Save())
                {
                    return(false);
                }
                log.Info("Created Element: " + element.GetColumnName());
            }
            //	Column Sync
            col.SetColumnName(element.GetColumnName());
            col.SetName(element.GetName());
            col.SetDescription(element.GetDescription());
            col.SetHelp(element.GetHelp());
            col.SetAD_Element_ID(element.GetAD_Element_ID());
            //

            if (!col.Save())
            {
                return(false);
            }

            //	DB
            if (!alsoInDB)
            {
                return(true);
            }
            //
            String sql     = col.GetSQLAdd(table);
            bool   success = DataBase.DB.ExecuteUpdateMultiple(sql, false, table.Get_TrxName()) >= 0;

            if (success)
            {
                log.Info("Created: " + table.GetTableName()
                         + "." + col.GetColumnName());
            }
            else
            {
                log.Warning("NOT Created: " + table.GetTableName()
                            + "." + col.GetColumnName());
            }
            return(success);
        }       //	createColumn
Exemplo n.º 2
0
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord"></param>
        /// <returns></returns>
        protected override bool BeforeSave(bool newRecord)
        {
            if (!CheckVersions(false))
            {
                return(false);
            }

            int displayType = GetAD_Reference_ID();

            //	Length
            if (DisplayType.IsLOB(displayType)) //	LOBs are 0
            {
                if (GetFieldLength() != 0)
                {
                    SetFieldLength(0);
                }
            }
            else if (GetFieldLength() == 0)
            {
                if (DisplayType.IsID(displayType))
                {
                    SetFieldLength(10);
                }
                else if (DisplayType.IsNumeric(displayType))
                {
                    SetFieldLength(14);
                }
                else if (DisplayType.IsDate(displayType))
                {
                    SetFieldLength(7);
                }
                else if (DisplayType.YesNo == displayType)
                {
                    SetFieldLength(1);
                }
                else
                {
                    log.SaveError("FillMandatory", Utility.Msg.GetElement(GetCtx(), "FieldLength"));
                    return(false);
                }
            }

            /** Views are not updateable
             * UPDATE AD_Column c
             * SET IsUpdateable='N', IsAlwaysUpdateable='N'
             * WHERE AD_Table_ID IN (SELECT AD_Table_ID FROM AD_Table WHERE IsView='Y')
             **/

            //	Virtual Column
            if (IsVirtualColumn())
            {
                if (IsMandatory())
                {
                    SetIsMandatory(false);
                }
                if (IsMandatoryUI())
                {
                    SetIsMandatoryUI(false);
                }
                if (IsUpdateable())
                {
                    SetIsUpdateable(false);
                }
            }
            //	Updateable/Mandatory
            if (IsParent() || IsKey())
            {
                SetIsUpdateable(false);
                SetIsMandatory(true);
            }
            if (IsAlwaysUpdateable() && !IsUpdateable())
            {
                SetIsAlwaysUpdateable(false);
            }
            //	Encrypted
            if (IsEncrypted())
            {
                int dt = GetAD_Reference_ID();
                if (IsKey() || IsParent() || IsStandardColumn() ||
                    IsVirtualColumn() || IsIdentifier() || IsTranslated() ||
                    DisplayType.IsLookup(dt) || DisplayType.IsLOB(dt) ||
                    "DocumentNo".ToLower().Equals(GetColumnName().ToLower()) ||
                    "Value".ToLower().Equals(GetColumnName().ToLower()) ||
                    "Name".ToLower().Equals(GetColumnName().ToLower()))
                {
                    log.Warning("Encryption not sensible - " + GetColumnName());
                    SetIsEncrypted(false);
                }
            }

            //	Sync Terminology
            if ((newRecord || Is_ValueChanged("AD_Element_ID")) &&
                GetAD_Element_ID() != 0)
            {
                _element = new M_Element(GetCtx(), GetAD_Element_ID(), Get_TrxName());
                SetColumnName(_element.GetColumnName());
                SetName(_element.GetName());
                SetDescription(_element.GetDescription());
                SetHelp(_element.GetHelp());
            }

            if (IsKey() && (newRecord || Is_ValueChanged("IsKey")))
            {
                SetConstraintType(null);
            }

            return(true);
        }