示例#1
0
文件: Utils.cs 项目: Eisai/pragmasql
        public static DataTypeWrap GetDataTypeDefaults(string typeName)
        {
            DataTypeWrap dType = new DataTypeWrap();
            string       type  = !String.IsNullOrEmpty(typeName) ? typeName.ToLowerInvariant() : String.Empty;

            switch (type)
            {
            case "char":
            case "nchar":
                dType.Width = "10";
                break;

            case "binary":
            case "nvarchar":
            case "varbinary":
            case "varchar":
                dType.Width = "50";
                break;

            case "decimal":
            case "numeric":
                dType.Precision = "18";
                dType.Scale     = "0";
                break;

            default:
                break;
            }
            return(dType);
        }
示例#2
0
文件: Utils.cs 项目: Eisai/pragmasql
        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);
        }
示例#3
0
        private DataTypeWrap GetDataTypeInfo(string typeName)
        {
            DataRow row = _tblTypes.Rows.Find(typeName);

            if (row == null)
            {
                return(null);
            }

            DataTypeWrap result = new DataTypeWrap();

            result.Name      = (string)row["name"];
            result.Width     = Utils.IsDbValueValid(row["length"]) ? ((short)row["length"]).ToString() : String.Empty;
            result.Precision = Utils.IsDbValueValid(row["prec"]) ? ((short)row["prec"]).ToString() : String.Empty;
            result.Scale     = Utils.IsDbValueValid(row["scale"]) ? ((byte)row["scale"]).ToString() : String.Empty;

            return(result);
        }
示例#4
0
        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
        }
示例#5
0
        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;
                }
            }
        }