public static bool CanHaveScale(string dataType) { DataTypeProperties props = Utils.EvaluateDataTypeProps(dataType); return (((props & DataTypeProperties.None) != DataTypeProperties.None) && ( ((props & DataTypeProperties.Scale) == DataTypeProperties.Scale) || ((props & DataTypeProperties.All) == DataTypeProperties.All) )); }
public static DataTypeProperties EvaluateDataTypeProps(string typeName) { DataTypeProperties result = DataTypeProperties.None; DataTypeWrap dType = new DataTypeWrap(); string type = !String.IsNullOrEmpty(typeName) ? typeName.ToLowerInvariant() : String.Empty; switch (type) { case "bigint": case "bit": case "datetime": case "float": case "image": case "int": case "money": case "ntext": case "real": case "smalldatetime": case "smallint": case "smallmoney": case "sql_variant": case "text": case "timestamp": case "tinyint": case "uniqueidentifier": case "xml": result = DataTypeProperties.None; break; case "binary": case "char": case "nchar": case "nvarchar": case "varbinary": case "varchar": result = DataTypeProperties.Width; break; case "decimal": case "numeric": result = DataTypeProperties.Precision | DataTypeProperties.Scale; break; default: result = DataTypeProperties.None; break; } return(result); }
public static string GetDataTypeInfo(string typeName, int width, int scale, int precision) { DataTypeProperties props = EvaluateDataTypeProps(typeName); if ((props & DataTypeProperties.Width) == DataTypeProperties.Width) { return(typeName + "(" + width.ToString() + ")"); } else if ((props & (DataTypeProperties.Scale | DataTypeProperties.Precision)) == (DataTypeProperties.Scale | DataTypeProperties.Precision)) { return(typeName + "(" + precision.ToString() + "," + scale.ToString() + ")"); } else { return(typeName); } }
private void ValidateColumns(ColumnValidationType validationType) { if (grd.CurrentRow == null || grd.CurrentRow.IsNewRow) { return; } ColumnWrapper col = bsCols.Current as ColumnWrapper; int rowIndex = bsCols.Position; if (!_bindingCompleted || col == null || rowIndex < 0) { return; } bool isAll = (ColumnValidationType.All & validationType) == ColumnValidationType.All; bool isNone = (ColumnValidationType.None & validationType) == ColumnValidationType.None; if (isNone) { return; } #region 0- Collation support check if (isAll || (ColumnValidationType.Collation & validationType) == ColumnValidationType.Collation) { cmbCollation.Enabled = Utils.SupportsCollation(col.DataType); } #endregion #region 1- Check if column is a computed column. If true this overrides others if (isAll || (ColumnValidationType.Computed & validationType) == ColumnValidationType.Computed) { for (int i = 3; i <= 10; i++) { grd.Rows[rowIndex].Cells[i].ReadOnly = col.IsComputed; grd.InvalidateCell(i, rowIndex); } if (col.IsComputed) { return; } } #endregion #region 2- Data Type related checks if (isAll || (ColumnValidationType.DataType & validationType) == ColumnValidationType.DataType) { DataTypeWrap dType = Utils.GetDataTypeDefaults(col.DataType); DataTypeProperties props = Utils.EvaluateDataTypeProps(col.DataType); if ((props & DataTypeProperties.None) == DataTypeProperties.None) { grd.Rows[rowIndex].Cells[colWidth.Index].ReadOnly = true; grd.Rows[rowIndex].Cells[colPrecision.Index].ReadOnly = true; grd.Rows[rowIndex].Cells[colScale.Index].ReadOnly = true; } else if ((props & DataTypeProperties.All) == DataTypeProperties.All) { grd.Rows[rowIndex].Cells[colWidth.Index].ReadOnly = false; grd.Rows[rowIndex].Cells[colPrecision.Index].ReadOnly = false; grd.Rows[rowIndex].Cells[colScale.Index].ReadOnly = false; } else { if ((props & DataTypeProperties.Width) == DataTypeProperties.Width) { grd.Rows[rowIndex].Cells[colWidth.Index].ReadOnly = false; } else { grd.Rows[rowIndex].Cells[colWidth.Index].ReadOnly = true; } if ((props & DataTypeProperties.Precision) == DataTypeProperties.Precision) { grd.Rows[rowIndex].Cells[colPrecision.Index].ReadOnly = false; } else { grd.Rows[rowIndex].Cells[colPrecision.Index].ReadOnly = true; } if ((props & DataTypeProperties.Scale) == DataTypeProperties.Scale) { grd.Rows[rowIndex].Cells[colScale.Index].ReadOnly = false; } else { grd.Rows[rowIndex].Cells[colScale.Index].ReadOnly = true; } } grd.InvalidateCell(colWidth.Index, rowIndex); grd.InvalidateCell(colPrecision.Index, rowIndex); grd.InvalidateCell(colScale.Index, rowIndex); } #endregion #region 3- Check identity if (isAll || (ColumnValidationType.Identity & validationType) == ColumnValidationType.Identity) { grd.Rows[rowIndex].Cells[colSeed.Index].ReadOnly = !col.IsIdentity; grd.Rows[rowIndex].Cells[colIncrement.Index].ReadOnly = !col.IsIdentity; cmbDefaultBinding.Enabled = !col.IsIdentity; if (!col.IsIdentity) { grd.Rows[rowIndex].Cells[colSeed.Index].Value = String.Empty; grd.Rows[rowIndex].Cells[colIncrement.Index].Value = String.Empty; } else { object val = grd.Rows[rowIndex].Cells[colSeed.Index].Value; if (val != null && String.IsNullOrEmpty(val.ToString())) { grd.Rows[rowIndex].Cells[colSeed.Index].Value = "1"; } val = grd.Rows[rowIndex].Cells[colIncrement.Index].Value; if (val != null && String.IsNullOrEmpty(val.ToString())) { grd.Rows[rowIndex].Cells[colIncrement.Index].Value = "1"; } } grd.InvalidateCell(colSeed.Index, rowIndex); grd.InvalidateCell(colIncrement.Index, rowIndex); } #endregion }
private void ValidateDataTypeDefaults( ) { ColumnWrapper col = bsCols.Current as ColumnWrapper; if (col == null) { return; } if (col.DataType == col.OldDataType) { return; } int rowIndex = bsCols.Position; DataTypeWrap dType = Utils.GetDataTypeDefaults(col.DataType); DataTypeProperties props = Utils.EvaluateDataTypeProps(col.DataType); if ((props & DataTypeProperties.None) == DataTypeProperties.None) { grd.Rows[rowIndex].Cells[colWidth.Index].Value = String.Empty; grd.Rows[rowIndex].Cells[colPrecision.Index].Value = String.Empty; grd.Rows[rowIndex].Cells[colScale.Index].Value = String.Empty; } else if ((props & DataTypeProperties.All) == DataTypeProperties.All) { grd.Rows[rowIndex].Cells[colWidth.Index].Value = dType.Width; grd.Rows[rowIndex].Cells[colPrecision.Index].Value = dType.Precision; grd.Rows[rowIndex].Cells[colScale.Index].Value = dType.Scale; } else { if ((props & DataTypeProperties.Width) == DataTypeProperties.Width) { grd.Rows[rowIndex].Cells[colWidth.Index].Value = dType.Width; } else { grd.Rows[rowIndex].Cells[colWidth.Index].Value = String.Empty; } if ((props & DataTypeProperties.Precision) == DataTypeProperties.Precision) { grd.Rows[rowIndex].Cells[colPrecision.Index].Value = dType.Precision; } else { grd.Rows[rowIndex].Cells[colPrecision.Index].Value = String.Empty; } if ((props & DataTypeProperties.Scale) == DataTypeProperties.Scale) { grd.Rows[rowIndex].Cells[colScale.Index].Value = dType.Scale; } else { grd.Rows[rowIndex].Cells[colScale.Index].Value = String.Empty; } } }
/// <summary>Sets the type for the new column.</summary> /// <remarks>Sets the type for the new column.</remarks> public virtual HealthMarketScience.Jackcess.ColumnBuilder SetType(DataType type) { _type = type; _typeProperties = DataTypeProperties.Get(type); return(this); }
//public ColumnBuilder(string name) : this(name, null) //{ //} public ColumnBuilder(string name, DataType type) { _name = name; _type = type; _typeProperties = DataTypeProperties.Get(type); }