Esempio n. 1
0
        public void CreateTable(ConnectionParams cp)
        {
            try
            {
                _initializing         = true;
                this.ConnectionParams = cp;
                TableObj = new TableWrapper();

                //This is a fake column. We need to hack some unknown behaviour of the grid
                ColumnWrapper col = new ColumnWrapper();
                col.Name       = "Column";
                col.DataType   = "nchar";
                col.Width      = "10";
                col.AllowNulls = true;
                col.CollectInitialValues();

                TableObj.Columns.Add(col);

                cmbOwner.SelectedIndex = cmbOwner.FindStringExact("dbo");

                BindTableColumns();
                Mode = EditMode.New;

                RenderAdditionalColumnProperties(bsCols.Current as ColumnWrapper);
                ValidateColumns(ColumnValidationType.All);
            }
            finally
            {
                _initializing = false;
            }
        }
Esempio n. 2
0
        private void TogglePrimaryKeyOfSelectedCols( )
        {
            if (grd.SelectedRows.Count == 0)
            {
                return;
            }

            ColumnWrapper col = null;

            foreach (DataGridViewRow row in grd.SelectedRows)
            {
                bsCols.Position = row.Index;
                col             = bsCols.Current as ColumnWrapper;
                if (col == null)
                {
                    return;
                }
                col.IsPrimaryKey = !col.IsPrimaryKey;

                if (col.IsPrimaryKey && col.AllowNulls)
                {
                    col.AllowNulls = false;
                }
            }
            grd.Refresh();
        }
Esempio n. 3
0
        private void cmbDefaultBinding_TextChanged(object sender, EventArgs e)
        {
            if (_initializingColumn)
            {
                return;
            }

            ColumnWrapper col = bsCols.Current as ColumnWrapper;

            if (col == null)
            {
                return;
            }

            if (cmbDefaultBinding.SelectedIndex == -1 || cmbDefaultBinding.Items.IndexOf(cmbDefaultBinding.Text) == -1)
            {
                col.DefaultBinding = String.Empty;
                col.Default        = cmbDefaultBinding.Text;
            }
            else
            {
                col.DefaultBinding = cmbDefaultBinding.SelectedItem as string;
                col.Default        = String.Empty;
            }
        }
Esempio n. 4
0
        private void bsCols_AddingNew(object sender, AddingNewEventArgs e)
        {
            ColumnWrapper col = new ColumnWrapper();

            col.DataType   = "nchar";
            col.Width      = "10";
            col.AllowNulls = true;
            col.CollectInitialValues();
            e.NewObject = col;
        }
Esempio n. 5
0
        private void RenderAdditionalColumnProperties(ColumnWrapper col)
        {
            try
            {
                _initializingColumn    = true;
                cmbDefaultBinding.Text = String.Empty;
                if (col == null)
                {
                    SetAdditionalColumnPropError(true);
                    ClearAdditionalColumnPropertyControls(true);
                    return;
                }

                SetAdditionalColumnPropError(false);
                ClearAdditionalColumnPropertyControls(false);

                if (col.IsIdentity)
                {
                    cmbDefaultBinding.SelectedIndex = -1;
                    cmbDefaultBinding.Enabled       = false;
                }
                else
                {
                    cmbDefaultBinding.Enabled = true;
                    if (!String.IsNullOrEmpty(col.Default))
                    {
                        cmbDefaultBinding.Text = col.Default;
                    }
                    else
                    {
                        cmbDefaultBinding.SelectedIndex = cmbDefaultBinding.FindStringExact(col.DefaultBinding);
                    }
                }
                cmbRuleBinding.SelectedIndex = cmbRuleBinding.FindStringExact(col.RuleBinding);

                cmbCollation.SelectedIndex = cmbCollation.FindStringExact(col.Collation);
                txtDescription.Text        = col.Description;

                chkComputed.Checked = col.IsComputed;
                txtFormula.ReadOnly = !chkComputed.Checked;
                txtFormula.Text     = col.Formula;

                lblHeader.Text = col.Name;
            }
            finally
            {
                _initializingColumn = false;
            }
        }
Esempio n. 6
0
        private void cmbCollation_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_initializingColumn)
            {
                return;
            }

            ColumnWrapper col = bsCols.Current as ColumnWrapper;

            if (col == null)
            {
                return;
            }
            col.Collation = cmbCollation.SelectedItem as string;
        }
Esempio n. 7
0
        private void txtFormula_TextChanged(object sender, EventArgs e)
        {
            if (_initializingColumn)
            {
                return;
            }

            ColumnWrapper col = bsCols.Current as ColumnWrapper;

            if (col == null)
            {
                return;
            }

            col.Formula = txtFormula.Text;
        }
Esempio n. 8
0
        private void txtDescription_TextChanged(object sender, EventArgs e)
        {
            if (_initializingColumn)
            {
                return;
            }

            ColumnWrapper col = bsCols.Current as ColumnWrapper;

            if (col == null)
            {
                return;
            }

            col.Description = txtDescription.Text;
        }
Esempio n. 9
0
        private void ApplyAdditionalColumnProps(ColumnWrapper col)
        {
            if (cmbDefaultBinding.SelectedIndex == -1)
            {
                col.Default        = cmbDefaultBinding.Text;
                col.DefaultBinding = String.Empty;
            }
            else
            {
                col.DefaultBinding = (string)cmbDefaultBinding.SelectedItem;
                col.Default        = String.Empty;
            }
            col.RuleBinding = (string)cmbRuleBinding.SelectedItem;

            col.Collation   = cmbCollation.SelectedItem as string;
            col.Description = txtDescription.Text;

            col.IsComputed = chkComputed.Checked;
            col.Formula    = txtFormula.Text;
        }
Esempio n. 10
0
        private void grd_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            ColumnWrapper col = bsCols.Current as ColumnWrapper;

            if (col == null)
            {
                return;
            }

            if (e.ColumnIndex == colDataType.Index && col.IsIdentity)
            {
                if (!Utils.IsDataTypeValidForIdentity((string)e.FormattedValue, (string)grd.Rows[e.RowIndex].Cells[5].Value))
                {
                    MessageService.ShowWarning("Only int, smallint, tinyint and bigint data types can be used as identity columns.");
                    e.Cancel = true;
                    grd.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = col.DataType;
                }
            }
            else if (e.ColumnIndex == colAllowNull.Index)
            {
                if (col.IsPrimaryKey && ((bool)e.FormattedValue))
                {
                    MessageService.ShowWarning("Allow Null property can not be set on a column which is part of the primary key.");
                    e.Cancel = true;
                    grd.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = false;
                }
            }
            else if (e.ColumnIndex == colIdentity.Index)
            {
                if ((bool)e.FormattedValue)
                {
                    if (!Utils.IsDataTypeValidForIdentity((string)grd.Rows[e.RowIndex].Cells[2].Value, (string)grd.Rows[e.RowIndex].Cells[5].Value))
                    {
                        MessageService.ShowWarning("Only int, smallint, tinyint, bigint, numeric or decimal (with zero scale) can be used as identity columns.");
                        e.Cancel = true;
                        grd.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = false;
                    }
                }
            }
        }
Esempio n. 11
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
        }
Esempio n. 12
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;
                }
            }
        }