private void ShowColumnSelector(DatabaseObjectType databaseObjectType, IEnumerable <IndexColumn> values, bool columnIsReadonly) { frmColumSelect columnSelect = new frmColumSelect() { ColumnIsReadOnly = columnIsReadonly }; IEnumerable <TableColumnDesingerInfo> columns = this.ucColumns.GetColumns().Where(item => !string.IsNullOrEmpty(item.Name)); List <IndexColumn> columnInfos = new List <IndexColumn>(); foreach (TableColumnDesingerInfo column in columns) { if (databaseObjectType == DatabaseObjectType.TableIndex) { if (!string.IsNullOrEmpty(column.DataType) && string.IsNullOrEmpty(column.ExtraPropertyInfo?.Expression)) { DataTypeSpecification dataTypeSpec = DataTypeManager.GetDataTypeSpecification(this.displayInfo.DatabaseType, column.DataType); if (dataTypeSpec != null && !dataTypeSpec.IndexForbidden) { columnInfos.Add(new IndexColumn() { ColumnName = column.Name }); } } } } columnSelect.InitControls(columnInfos, this.displayInfo.DatabaseType == DatabaseType.SqlServer); columnSelect.LoadColumns(values); if (columnSelect.ShowDialog() == DialogResult.OK) { if (databaseObjectType == DatabaseObjectType.TableIndex) { this.ucIndexes.SetRowColumns(columnSelect.SelectedColumns); } } }
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); }
public static void SetColumnLength(DatabaseType databaseType, TableColumn column, string length) { string dataType = column.DataType; DataTypeSpecification dataTypeSpec = DataTypeManager.GetDataTypeSpecification(databaseType, dataType); if (!string.IsNullOrEmpty(dataTypeSpec.MapTo)) { column.DataType = dataTypeSpec.MapTo; return; } string args = dataTypeSpec.Args; if (string.IsNullOrEmpty(args)) { return; } string[] argsNames = args.Split(','); string[] lengthItems = length?.Split(','); int i = 0; foreach (string argName in argsNames) { if (lengthItems == null || i > lengthItems.Length - 1) { continue; } string lengthItem = lengthItems[i]; if (argName == "length") { bool isChar = DataTypeHelper.IsCharType(dataType); if (isChar) { if (dataTypeSpec.AllowMax && lengthItem.ToLower() == "max") { column.MaxLength = -1; } else { column.MaxLength = long.Parse(lengthItem) * (DataTypeHelper.StartWithN(dataType) ? 2 : 1); } } else { column.MaxLength = long.Parse(lengthItem); } } else if (argName == "precision" || argName == "dayScale") { column.Precision = int.Parse(lengthItem); } else if (argName == "scale") { column.Scale = int.Parse(lengthItem); } i++; } }