Example #1
0
        public List <TableColumnDesingerInfo> GetColumns()
        {
            List <TableColumnDesingerInfo> columnDesingerInfos = new List <TableColumnDesingerInfo>();

            int order = 1;

            foreach (DataGridViewRow row in this.dgvColumns.Rows)
            {
                TableColumnDesingerInfo col = new TableColumnDesingerInfo()
                {
                    Order = order
                };

                string colName = row.Cells[this.colColumnName.Name].Value?.ToString();

                if (!string.IsNullOrEmpty(colName))
                {
                    TableColumnDesingerInfo tag = row.Tag as TableColumnDesingerInfo;

                    string dataType = DataGridViewHelper.GetCellStringValue(row, this.colDataType.Name);

                    col.OldName           = tag?.OldName;
                    col.Name              = colName;
                    col.DataType          = dataType;
                    col.Length            = DataGridViewHelper.GetCellStringValue(row, this.colLength.Name);
                    col.IsNullable        = DataGridViewHelper.GetCellBoolValue(row, this.colNullable.Name);
                    col.IsPrimary         = DataGridViewHelper.GetCellBoolValue(row, this.colPrimary.Name);
                    col.IsIdentity        = DataGridViewHelper.GetCellBoolValue(row, this.colIdentity.Name);
                    col.DefaultValue      = DataGridViewHelper.GetCellStringValue(row, this.colDefaultValue.Name);
                    col.Comment           = DataGridViewHelper.GetCellStringValue(row, this.colComment.Name);
                    col.ExtraPropertyInfo = tag?.ExtraPropertyInfo;

                    UserDefinedType userDefinedType = this.GetUserDefinedType(dataType);

                    if (userDefinedType != null)
                    {
                        col.IsUserDefined = true;
                        col.TypeOwner     = userDefinedType.Owner;
                    }

                    row.Tag = col;

                    columnDesingerInfos.Add(col);

                    order++;
                }
            }

            return(columnDesingerInfos);
        }
Example #2
0
        public void OnSaved()
        {
            for (int i = 0; i < this.dgvColumns.RowCount; i++)
            {
                DataGridViewRow row = this.dgvColumns.Rows[i];

                TableColumnDesingerInfo columnDesingerInfo = row.Tag as TableColumnDesingerInfo;

                if (columnDesingerInfo != null && !string.IsNullOrEmpty(columnDesingerInfo.Name))
                {
                    columnDesingerInfo.OldName = columnDesingerInfo.Name;
                }
            }
        }
Example #3
0
        public static List <TableColumnDesingerInfo> GetTableColumnDesingerInfos(DbInterpreter dbInterpreter, Table table, List <TableColumn> columns, List <TablePrimaryKey> primaryKeys)
        {
            List <TableColumnDesingerInfo> columnDesingerInfos = new List <TableColumnDesingerInfo>();
            IEnumerable <string>           dataTypes           = DataTypeManager.GetDataTypeSpecifications(dbInterpreter.DatabaseType).Select(item => item.Name);

            foreach (TableColumn column in columns)
            {
                DataTypeInfo dataTypeInfo = DataTypeHelper.GetDataTypeInfo(column.DataType);

                TableColumnDesingerInfo columnDesingerInfo = new TableColumnDesingerInfo()
                {
                    OldName   = column.Name,
                    IsPrimary = primaryKeys.Any(item => item.Columns.Any(t => t.ColumnName == column.Name)),
                    Length    = dbInterpreter.GetColumnDataLength(column)
                };

                ObjectHelper.CopyProperties(column, columnDesingerInfo);

                string dataType = column.IsUserDefined ? column.DataType : dataTypeInfo.DataType.ToLower();

                if (!dataTypes.Contains(dataType))
                {
                    dataTypeInfo = DataTypeHelper.GetSpecialDataTypeInfo(dataType);
                    dataType     = dataTypeInfo.DataType;
                    columnDesingerInfo.Length = dataTypeInfo.Args;
                }

                columnDesingerInfo.DataType = dataType;

                columnDesingerInfo.ExtraPropertyInfo = new TableColumnExtraPropertyInfo();

                if (column.IsComputed)
                {
                    columnDesingerInfo.ExtraPropertyInfo.Expression = column.ComputeExp;
                }

                if (table.IdentitySeed.HasValue)
                {
                    columnDesingerInfo.ExtraPropertyInfo.Seed      = table.IdentitySeed.Value;
                    columnDesingerInfo.ExtraPropertyInfo.Increment = table.IdentityIncrement.Value;
                }

                columnDesingerInfos.Add(columnDesingerInfo);
            }

            return(columnDesingerInfos);
        }
Example #4
0
        private void ShowColumnExtraPropertites()
        {
            var row = DataGridViewHelper.GetSelectedRow(this.dgvColumns);

            if (row != null)
            {
                TableColumnDesingerInfo column = row.Tag as TableColumnDesingerInfo;

                if (column == null)
                {
                    column  = new TableColumnDesingerInfo();
                    row.Tag = column;
                }

                TableColumnExtraPropertyInfo extralProperty = column?.ExtraPropertyInfo;

                if (extralProperty == null)
                {
                    extralProperty           = new TableColumnExtraPropertyInfo();
                    column.ExtraPropertyInfo = extralProperty;
                }

                DataGridViewCell identityCell = row.Cells[this.colIdentity.Name];

                if (!DataGridViewHelper.IsTrueValue(identityCell.Value))
                {
                    this.columnPropertites.HiddenProperties = new string[] { nameof(extralProperty.Seed), nameof(extralProperty.Increment) };
                }
                else
                {
                    this.columnPropertites.HiddenProperties = null;
                }

                this.columnPropertites.SelectedObject = extralProperty;
                this.columnPropertites.Refresh();
            }
        }
Example #5
0
        public static bool ValidateDataType(DatabaseType databaseType, TableColumnDesingerInfo columnDesingerInfo, out string message)
        {
            message = "";

            if (columnDesingerInfo.IsUserDefined)
            {
                return(true);
            }

            string columName = columnDesingerInfo.Name;
            string dataType  = columnDesingerInfo.DataType;

            DataTypeSpecification dataTypeSpec = DataTypeManager.GetDataTypeSpecification(databaseType, dataType);

            if (dataTypeSpec == null)
            {
                message = $"Invalid data type:{dataType}";
                return(false);
            }

            if (!string.IsNullOrEmpty(dataTypeSpec.Args))
            {
                string length = columnDesingerInfo?.Length?.Trim();

                if (string.IsNullOrEmpty(length) && dataTypeSpec.Optional)
                {
                    return(true);
                }

                if (dataTypeSpec.AllowMax && !string.IsNullOrEmpty(length) && length.ToLower() == "max")
                {
                    return(true);
                }

                string args = dataTypeSpec.Args;

                string[] argsNames   = args.Split(',');
                string[] lengthItems = length?.Split(',');

                if (argsNames.Length != lengthItems?.Length)
                {
                    if (argsNames.Length == 2 && lengthItems?.Length == 1)
                    {
                        lengthItems = new string[] { lengthItems[0], "0" };
                    }
                    else
                    {
                        message = $"Length is invalid for column \"{columName}\", it's format should be:{args}";
                        return(false);
                    }
                }

                int i = 0;

                foreach (string argName in argsNames)
                {
                    string lengthItem = lengthItems[i];

                    ArgumentRange?range = DataTypeManager.GetArgumentRange(dataTypeSpec, argName);

                    if (range.HasValue)
                    {
                        int lenValue;

                        if (!int.TryParse(lengthItem, out lenValue))
                        {
                            message = $"\"{lengthItem}\" is't a valid integer value";
                            return(false);
                        }

                        if (lenValue < range.Value.Min || lenValue > range.Value.Max)
                        {
                            message = $"The \"{argName}\"'s range of column \"{columName}\" should be between {range.Value.Min} and {range.Value.Max}";
                            return(false);
                        }
                    }

                    i++;
                }
            }

            return(true);
        }