示例#1
0
        public void Visit(CreateColumnCommand command)
        {
            var columnCreator = _app.BusinessObjects.GetBusinessObject <UserFieldsMD>(BoObjectTypes.oUserFields);

            try {
                columnCreator.TableName    = command.TableName;
                columnCreator.Name         = command.Name;
                columnCreator.Description  = command.Description;
                columnCreator.Type         = command.ColumnType;
                columnCreator.SubType      = command.SubType;
                columnCreator.Mandatory    = YesNo(command.IsMandatory);
                columnCreator.LinkedTable  = command.LinkedTable;
                columnCreator.EditSize     = command.Length;
                columnCreator.DefaultValue = command.DefaultValue;
                foreach (var val in command.ValidValues)
                {
                    columnCreator.ValidValues.Value       = val.Key;
                    columnCreator.ValidValues.Description = val.Value;
                    columnCreator.ValidValues.Add();
                }
                var created = columnCreator.Add();
                if (created != 0)
                {
                    string error = _app.BusinessObjects.GetLastErrorDescription();
                    throw new B1CoreException(string.Format("Error: {0} - campo: {1}", error, command.Name));
                }
            }
            finally {
                _app.BusinessObjects.ReleaseObject(columnCreator);
            }
        }
        public CreateTableCommand Column(string columnName, string columnDescription, Action <CreateColumnCommand> column)
        {
            var command = new CreateColumnCommand(Name, columnName, columnDescription);

            if (column != null)
            {
                column(command);
            }
            TableCommands.Add(command);
            NeedIndex(command);
            return(this);
        }
        public CreateTableCommand Column(string columnName, string columnDescription, BoFieldTypes dbType, Action <CreateColumnCommand> column = null)
        {
            var command = new CreateColumnCommand(Name, columnName, columnDescription);

            command.WithType(dbType);
            if (column != null)
            {
                column(command);
            }
            TableCommands.Add(command);
            NeedIndex(command);
            return(this);
        }
        public CreateTableCommand Alpha(string columnName, string columnDescription, int length, Action <CreateColumnCommand> column = null)
        {
            var command = new CreateColumnCommand(Name, columnName, columnDescription);

            command.WithType(BoFieldTypes.db_Alpha);
            command.WithLength(length);
            if (column != null)
            {
                column(command);
            }
            TableCommands.Add(command);
            NeedIndex(command);
            return(this);
        }
        public AlterTableCommand Date(string columnName, string columnDescription, Action <CreateColumnCommand> column = null)
        {
            var command = new CreateColumnCommand(Name, columnName, columnDescription);

            command
            .WithType(BoFieldTypes.db_Date)
            .WithLength(0);
            if (column != null)
            {
                column(command);
            }
            TableCommands.Add(command);
            NeedIndex(command);
            return(this);
        }
        public CreateTableCommand Integer(string columnName, string columnDescription, Action <CreateColumnCommand> column = null)
        {
            var command = new CreateColumnCommand(Name, columnName, columnDescription);

            command
            .WithType(BoFieldTypes.db_Numeric)
            .WithSubType(BoFldSubTypes.st_None)
            .WithLength(11);
            if (column != null)
            {
                column(command);
            }
            TableCommands.Add(command);
            NeedIndex(command);
            return(this);
        }
        public CreateTableCommand Percent(string columnName, string columnDescription, Action <CreateColumnCommand> column = null)
        {
            var command = new CreateColumnCommand(Name, columnName, columnDescription);

            command
            .WithType(BoFieldTypes.db_Float)
            .WithSubType(BoFldSubTypes.st_Percentage)
            .WithLength(0)
            .WithDefault("0");
            if (column != null)
            {
                column(command);
            }
            TableCommands.Add(command);
            NeedIndex(command);
            return(this);
        }
        public CreateTableCommand ValidValues(string columnName, string columnDescription, Dictionary <string, string> values, Action <CreateColumnCommand> column = null)
        {
            var command = new CreateColumnCommand(Name, columnName, columnDescription);

            command
            .WithType(BoFieldTypes.db_Alpha)
            .WithLength(30);
            foreach (var val in values)
            {
                command.AddValidValue(val.Key, val.Value);
            }
            if (column != null)
            {
                column(command);
            }
            TableCommands.Add(command);
            NeedIndex(command);
            return(this);
        }
 public void NeedIndex(CreateColumnCommand command)
 {
     if (command.IsIndex)
     {
         bool hasIndex = true;
         CreateIndexCommand indexCommand = null;
         if (!IndexCommands.TryGetValue(command.IndexName, out indexCommand))
         {
             indexCommand = new CreateIndexCommand(Name, command.IndexName);
             hasIndex     = false;
         }
         indexCommand.AddField(command.Name);
         if (command.IsUnique)
         {
             indexCommand.Unique();
         }
         if (!hasIndex)
         {
             IndexCommands.Add(indexCommand.IndexName, indexCommand);
         }
     }
 }