Пример #1
0
        /// <summary>
        /// Resets default for not nullable columns to empty string if it is null. Just to get behavior
        /// more like Query Browser.
        /// </summary>
        /// <param name="connection">The DataConnectionWrapper to be used for enumeration.</param>
        /// <param name="table">Table with data to post process.</param>>
        protected override void PostProcessData(DataConnectionWrapper connection, DataTable table)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            // Call to base
            base.PostProcessData(connection, table);

            // Do not process table whithout rows
            if (table.Rows == null)
            {
                return;
            }

            // Reset default value for each not nullable column to empty string if
            // it is null
            foreach (DataRow column in table.Rows)
            {
                if (DataInterpreter.GetSqlBool(column, Attributes.Nullable).IsFalse &&
                    !DataInterpreter.IsNotNull(column, Attributes.Default))
                {
                    DataInterpreter.SetValueIfChanged(column, Attributes.Default, String.Empty);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Fills available values for index comboboxes
        /// </summary>
        private void FillComboboxes()
        {
            // Fill index kind combobox
            indexKindSelect.Tag = Index.IndexKind;
            FillCombobox(indexKindSelect, Document.GetSupportedIndexKinds());

            // If indexes are not supported at all, disable add button
            bool enabled = indexKindSelect.Items.Count > 0;

            addButton.Enabled = enabled;

            // If selected index is primary key, add it to the list of available kinds and select
            if (DataInterpreter.CompareInvariant(SelectedIndexName, IndexDescriptor.PRIMARY))
            {
                indexKindSelect.Items.Add(IndexDescriptor.PRIMARY);
                indexKindSelect.SelectedItem = IndexDescriptor.PRIMARY;
            }


            // Fill index types
            indexTypeSelect.Tag = Index.IndexType;
            FillCombobox(indexTypeSelect, Document.GetSupportedIndexTypes());

            // Disable combobox if only one type is supported
            indexTypeSelect.Enabled = indexTypeSelect.Items.Count > 1;
        }
Пример #3
0
        /// <summary>
        /// Creates new stored function identifier template without name part.
        /// </summary>
        /// <param name="hierarchy">Server explorer facade object to be used for Server Explorer hierarchy interaction.</param>
        /// <param name="typeName">Object type name to create identifier.</param>
        /// <returns>Returns new stored function identifier template without name part.</returns>
        protected override object[] CreateNewIDBase(ServerExplorerFacade hierarchy, string typeName)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }

            // Only stored procedures are supported
            if (!DataInterpreter.CompareInvariant(typeName, StoredProcDescriptor.TypeName))
            {
                throw new NotSupportedException(String.Format(
                                                    CultureInfo.CurrentCulture,
                                                    Resources.Error_ObjectTypeNotSupported,
                                                    typeName));
            }

            // Get default schema
            string schema = hierarchy.Connection.Schema;

            Debug.Assert(!String.IsNullOrEmpty(schema), "Failed to retrive schema name!");
            if (schema == null)
            {
                return(null);
            }

            return(new object[] { null, schema, null });
        }
Пример #4
0
        /// <summary>
        /// Fills details view with data for selected foreign key.
        /// </summary>
        private void FillSelectedKeyView()
        {
            // If selected key is empty, reset view and exit
            if (SelectedKey == null)
            {
                ResetSelectedKeyView();
                return;
            }

            // Lock selected key updates
            lockUpdate = true;

            // Enable key settings
            keySettingsGroup.Enabled = true;

            // Fill key name
            keyNameText.DataSource = SelectedKey;

            // Select referenced table
            refTableSelect.SelectedValue = DataInterpreter.GetStringNotNull(SelectedKey, ForeignKey.ReferencedTableName);

            // Attache referenced column column to the datasource
            AttachReferencedColumnColumn();

            // Attach grid view to filtered datasource
            AttachForeignKeyColumns();

            // Select proper actions
            onDeleteSelect.SelectedItem = SelectedKey[ForeignKey.OnDelete];
            onUpdateSelect.SelectedItem = SelectedKey[ForeignKey.OnUpdate];


            // Unlock selected key updates
            lockUpdate = false;
        }
Пример #5
0
        /// <summary>
        /// Handles referenced table changes and sets correct data source for
        /// the refernced column column
        /// </summary>
        /// <param name="sender">Sender of the event.</param>
        /// <param name="e">Detailed information about event.</param>
        private void OnReferencedTableChanged(object sender, EventArgs e)
        {
            // If update is loked, exit
            if (lockUpdate)
            {
                return;
            }

            // Reset foreign key columns
            DataView view = foreigKeyColumns.DataSource as DataView;

            if (view != null)
            {
                for (int i = view.Count - 1; i >= 0; i--)
                {
                    view.Delete(i);
                }
            }

            // Set new referenced table
            if (SelectedKey != null)
            {
                DataInterpreter.SetValueIfChanged(SelectedKey, ForeignKey.ReferencedTableName, ReferencedTable);
            }

            AttachReferencedColumnColumn();
        }
Пример #6
0
        /// <summary>
        /// Creates a new user defined function identifier template
        /// </summary>
        /// <param name="hierarchy">A server explorer facade object to interact with
        /// Server Explorer hierarchy</param>
        /// <param name="typeName">An object type name to create</param>
        /// <returns>Returns a new user defined function identifier template</returns>
        protected override object[] CreateNewIDBase(ServerExplorerFacade hierarchy, string typeName)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }

            // Checking a type name
            if (!DataInterpreter.CompareInvariant(typeName, UdfDescriptor.TypeName))
            {
                throw new NotSupportedException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Resources.Error_ObjectTypeNotSupported,
                              typeName)
                          );
            }

            // Get a default schema
            string schema = hierarchy.Connection.Schema;

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

            return(new object[] { null, null });
        }
Пример #7
0
        /// <summary>
        /// Handles mouse movements and makes checkboxes hot.
        /// </summary>
        /// <param name="e">Makes checkboses hot.</param>
        protected override void OnMouseMove(DataGridViewCellMouseEventArgs e)
        {
            if (this.DataGridView == null || e == null || e.RowIndex < 0 ||
                e.RowIndex >= this.DataGridView.RowCount)
            {
                return;
            }

            // Get hot flag name
            string hotFlag = GetHotFlagName(e.Location, e.RowIndex);

            // Skip if nothing changed
            if (DataInterpreter.CompareInvariant(hotItem, hotFlag))
            {
                base.OnMouseMove(e);
                return;
            }

            // Store old hot item
            string oldHotItem = hotItem;

            // Store new hot item
            hotItem = hotFlag;

            // Invalidate old hot item, if any
            InvalidateItem(e.ColumnIndex, e.RowIndex, oldHotItem);

            // Invalidate new hot item, if any
            InvalidateItem(e.ColumnIndex, e.RowIndex, hotItem);
        }
Пример #8
0
        /// <summary>
        /// Returns CREATE DATABASE statement for given schema.
        /// </summary>
        /// <param name="connection">Connection to use to execute query.</param>
        /// <param name="schema">DataRow with information about schema.</param>
        /// <returns>Returns CREATE DATABASE statement for given schema.</returns>
        private string GetCreateDatabase(DataConnectionWrapper connection, DataRow schema)
        {
            // Extract schema and table name
            string schemaName = DataInterpreter.GetString(schema, Attributes.Schema);

            if (String.IsNullOrEmpty(schemaName))
            {
                Debug.Fail("Unable to get schema name");
                return(String.Empty);
            }

            // Build SHOW CREATE DATABASE
            StringBuilder query = new StringBuilder();

            query.Append("SHOW CREATE DATABASE ");
            QueryBuilder.WriteIdentifier(schemaName, query);

            // Execute query and check result table
            DataTable createDatabase = connection.ExecuteSelectTable(query.ToString());

            if (createDatabase == null || createDatabase.Rows.Count <= 0)
            {
                Debug.Fail("Failed to read CREATE TABLE query!");
                return(String.Empty);
            }

            // Extract result
            string result = DataInterpreter.GetString(createDatabase.Rows[0], "Create Database");

            // Dispose table and exit
            createDatabase.Dispose();
            return(result);
        }
Пример #9
0
        /// <summary>
        /// Builds supported flags list for the given column datatype.
        /// </summary>
        /// <param name="dataType">Column datatype.</param>
        private void BuildFlags(int rowIndex)
        {
            DataRow column   = GetColumnRow(rowIndex);
            string  dataType = column != null?DataInterpreter.GetStringNotNull(column, Column.MySqlType) : String.Empty;

            flags.Clear();

            // If numeric, add UNSIGNED and ZEROFILL
            if (Parser.SupportUnsignedAndZerofill(dataType))
            {
                AddNumericFlags();
            }

            // If supports BINARY, add it
            if (Parser.SupportBinary(dataType))
            {
                AddBinaryFlag();
            }

            // If supports ASCII and UNICODE, add them
            if (Parser.SupportAsciiAndUnicode(dataType))
            {
                AddAsciiAndUnicode();
            }

            // Fill flags with data
            FillFlags(column);
        }
Пример #10
0
        /// <summary>
        /// Handles click on the cell content an switch checkboxes.
        /// </summary>
        /// <param name="e">Information on the event.</param>
        protected override void OnClick(DataGridViewCellEventArgs e)
        {
            if (this.DataGridView == null || e == null || e.RowIndex < 0 ||
                e.RowIndex >= this.DataGridView.RowCount)
            {
                return;
            }

            if (String.IsNullOrEmpty(hotItem) || !checkboxes.ContainsKey(hotItem))
            {
                return;
            }

            // Switch flag
            flags[hotItem] = !flags[hotItem];

            // If column row not empty, change it value
            DataRow column = GetColumnRow(e.RowIndex);

            if (column != null)
            {
                DataInterpreter.SetValueIfChanged(
                    column,
                    hotItem,
                    flags[hotItem] ? DataInterpreter.True : DataInterpreter.False);
            }

            // Notify grid about changes
            NotifyDataGridViewOfValueChange();
        }
Пример #11
0
        /// <summary>
        /// Returns DataTable with description of table's columns.
        /// </summary>
        /// <param name="connection">Connection object to use for queries.</param>
        /// <param name="restrictions">Restrictions on table and propably on column.</param>
        /// <param name="sort">Sort string to use.</param>
        /// <returns>Returns DataTable with description of table's columns.</returns>
        private DataTable ReadColumnsForTable(DataConnectionWrapper connection, object[] restrictions, string sort)
        {
            // Execute base method
            DataTable result = base.ReadTable(connection, restrictions, sort);

            // hackity, hack, hack.  We are just doing this so we can avoid having to rewrite a ton
            // of code to use a data reader to work around the server stupid binary issues.
            result = ConvertTableIfNecessary(result);

            // If result is null, exit
            if (result == null)
            {
                return(null);
            }


            // Extract table name
            string table = restrictions[2] as string;

            // For legacy version rename columns
            RenameColumn("Field", Attributes.Name, result);
            RenameColumn("Type", Attributes.ColumnType, result);
            RenameColumn("Null", Attributes.Nullable, result);
            RenameColumn("Key", Attributes.ColumnKey, result);
            RenameColumn("Default", Attributes.Default, result);
            RenameColumn("Extra", Attributes.Extra, result);

            // Calculate schema name
            string schema;

            if (restrictions.Length >= 2 && !String.IsNullOrEmpty(restrictions[1] as string))
            {
                schema = restrictions[1] as string;
            }
            else
            {
                schema = connection.Schema;
            }

            // Add catalog, schema and type column
            result.Columns.Add(Attributes.Schema, typeof(string));
            result.Columns.Add(Attributes.Table, typeof(string));

            // Set schema and table name for each row
            foreach (DataRow column in result.Rows)
            {
                DataInterpreter.SetValueIfChanged(column, Attributes.Schema, schema);
                DataInterpreter.SetValueIfChanged(column, Attributes.Table, table);
                // Empty value in IS_NULABLE column means NO
                if (!DataInterpreter.IsNotEmptyString(column, Attributes.Nullable))
                {
                    DataInterpreter.SetValueIfChanged(column, Attributes.Nullable, DataInterpreter.False);
                }
            }

            // Finaly, return result
            return(result);
        }
Пример #12
0
        /// <summary>
        /// Reads table with Database Objects which satisfy given restriction. Base implementation
        /// uses direct SQL query to the INFORMATION_SCHEMA.
        /// </summary>
        /// <param name="connection">The DataConnectionWrapper to be used for enumeration.</param>
        /// <param name="restrictions">The restrictions to be putted on the retrieved objects set.</param>
        /// <param name="sort">Sort expresion to append after ORDER BY clause.</param>
        /// <returns>Returns table with Database Objects which satisfy given restriction.</returns>
        protected override DataTable ReadTable(DataConnectionWrapper connection, object[] restrictions, string sort)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            // Extract server version
            Version serverVersion = connection.ServerVersion;

            // For latest version just return base result
            if (serverVersion == null || serverVersion.Major >= 5)
            {
                return(base.ReadTable(connection, restrictions, sort));
            }


            // Temporary table to store result
            DataTable merged = new DataTable();

            // Enumerate all tables
            DataTable tables = TableDescriptor.Enumerate(connection, restrictions);

            // If there is now tables, return empty table with columns
            if (tables == null || tables.Rows == null || tables.Rows.Count <= 0)
            {
                return(merged);
            }

            // Calculate column restrriction
            object column = restrictions != null && restrictions.Length >= 4 ? restrictions[3] : null;

            // Enumerate columns for each table
            foreach (DataRow tableRow in tables.Rows)
            {
                // Enumerate columns
                DataTable columns = ReadColumnsForTable(
                    connection,
                    new object[] {
                    null,
                    DataInterpreter.GetString(tableRow, TableDescriptor.Attributes.Schema),
                    DataInterpreter.GetString(tableRow, TableDescriptor.Attributes.Name),
                    column
                },
                    sort);

                // Merge results if any
                if (columns != null)
                {
                    merged.Merge(columns);
                }
            }

            // Return results
            return(merged);
        }
Пример #13
0
 /// <summary>
 /// Returns true if given engine has status.
 /// </summary>
 /// <param name="engine">Engine name to check.</param>
 /// <returns>Returns true if given engine has status.</returns>
 private bool HasStatus(string engine)
 {
     foreach (string candidate in HasStatusList)
     {
         if (DataInterpreter.CompareInvariant(engine, candidate))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #14
0
 /// <summary>
 /// Set state of each flag to checked or unchecked.
 /// </summary>
 private void FillFlags(DataRow column)
 {
     string[] keys = new string[flags.Count];
     flags.Keys.CopyTo(keys, 0);
     // Set checking sate for all items
     foreach (string key in keys)
     {
         // Item is checked depending on the value in the data row
         flags[key] = column != null && DataInterpreter.GetSqlBool(column, key).IsTrue;
     }
 }
Пример #15
0
        /// <summary>
        /// Extracts information about all availabel character sets and collations from
        /// the DataTable.
        /// </summary>
        /// <param name="table">DataTable object with data</param>
        private void FillCharSetsAndCollations(DataTable table)
        {
            // Iterate through all collations
            foreach (DataRow row in table.Rows)
            {
                // Extract collation and character set name
                string collation = DataInterpreter.GetString(row, CollationName);
                string charSet   = DataInterpreter.GetString(row, CharSetName);

                // Validate names
                if (String.IsNullOrEmpty(collation) ||
                    String.IsNullOrEmpty(charSet))
                {
                    Debug.Fail("Empty collation or character set name!");
                    continue;
                }

                // Add character set to list if not already there
                if (!characterSetsList.Contains(charSet))
                {
                    characterSetsList.Add(charSet);
                }

                // Add collation to list
                Debug.Assert(!collationsList.Contains(collation), "Dublicate collation name founded!");
                if (!collationsList.Contains(collation))
                {
                    collationsList.Add(collation);
                }

                // Create entry in the collationsForCharacterSet dictionary
                if (!collationsForCharacterSetDictionary.ContainsKey(charSet) || collationsForCharacterSetDictionary[charSet] == null)
                {
                    collationsForCharacterSetDictionary[charSet] = new List <string>();
                }
                List <string> collForCharSet = collationsForCharacterSetDictionary[charSet];

                // Add new collation for character set
                Debug.Assert(collForCharSet != null &&
                             !collForCharSet.Contains(collation),
                             "Empty collation list or dublicate collation!");
                if (!collForCharSet.Contains(collation))
                {
                    collForCharSet.Add(collation);
                }

                // If collation is default, add it to the defaultCollations dictionary
                if (DataInterpreter.GetSqlBool(row, IsDefault))
                {
                    Debug.Assert(!defaultCollationsDictionary.ContainsKey(charSet), "Default collation already defined!");
                    defaultCollationsDictionary[charSet] = collation;
                }
            }
        }
Пример #16
0
 /// <summary>
 /// Initializes text property with new name form datasource if any.
 /// </summary>
 private void RefreshText()
 {
     if (DataSource == null || String.IsNullOrEmpty(AttributeName))
     {
         Text = String.Empty;
     }
     else
     {
         Text = DataInterpreter.GetStringNotNull(DataSource, AttributeName);
     }
 }
Пример #17
0
        /// <summary>
        /// Reads information about default character set and collation for schema.
        /// </summary>
        private void ReadDefaulCharacterSetAndCollationForSchema()
        {
            // Read schema aditional information
            DataTable table = RootDescriptor.Enumerate(this, null);

            // Exctract default character set and collation names
            if (table != null && table.Rows.Count > 0 &&
                table.Columns.Contains(RootDescriptor.Attributes.DefaultCharset) &&
                table.Columns.Contains(RootDescriptor.Attributes.DefaultCollation))
            {
                defaultCharacterSetVal = DataInterpreter.GetString(table.Rows[0], RootDescriptor.Attributes.DefaultCharset);
                defaultCollationVal    = DataInterpreter.GetString(table.Rows[0], RootDescriptor.Attributes.DefaultCollation);
            }
        }
Пример #18
0
        /// <summary>
        /// Returns string with CREATE TABLE sql for the table which owns this index.
        /// </summary>
        /// <param name="connection">Connection to use to execute query.</param>
        /// <param name="row">DataRow with information about index.</param>
        /// <returns>Returns string with CREATE TABLE sql for this table.</returns>
        private static string GetCreateTableQuery(DataConnectionWrapper connection, DataRow row)
        {
            // Extract schema and table name
            string schemaName = DataInterpreter.GetString(row, Attributes.Schema);
            string tableName  = DataInterpreter.GetString(row, Attributes.Table);

            if (String.IsNullOrEmpty(schemaName) || String.IsNullOrEmpty(tableName))
            {
                Debug.Fail("Unable to get table or schema name");
                return(String.Empty);
            }

            return(TableDescriptor.GetCreateTableQuery(connection, schemaName, tableName));
        }
Пример #19
0
        /// <summary>
        /// Fetches data from the results of the SHOW INDEX FROM query to the
        /// DataTable with database objects descriptions.
        /// </summary>
        /// <param name="restrictions">Restricton to apply to the read objects.</param>
        /// <param name="table">DataRow with table descriptions for which indexes are enumerated.</param>
        /// <param name="indexes">DataTable with results of the SHOW INDEX FROM.</param>
        /// <param name="result">DataTable to fill with data.</param>
        protected virtual void FetchData(object[] restrictions, DataRow table, DataTable indexes, DataTable result)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            if (indexes == null)
            {
                throw new ArgumentNullException("indexes");
            }
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            // Iterate through results of SHOW INDEX FROM
            foreach (DataRow index in indexes.Rows)
            {
                // Only first columns should be considered
                if (DataInterpreter.GetInt(index, SeqInIndex) != 1)
                {
                    continue;
                }

                // Apply restrictions on the index name, if any
                if (!CheckIndexName(restrictions, index))
                {
                    continue;
                }

                // Create new index row
                DataRow row = result.NewRow();

                // Fill row with data
                DataInterpreter.SetValueIfChanged(row, Attributes.Database, null);
                DataInterpreter.SetValueIfChanged(row, Attributes.Schema, table[TableDescriptor.Attributes.Schema]);
                DataInterpreter.SetValueIfChanged(row, Attributes.Table, index[Table]);
                DataInterpreter.SetValueIfChanged(row, Attributes.Name, index[KeyName]);
                DataInterpreter.SetValueIfChanged(row, Attributes.Unique,
                                                  DataInterpreter.GetInt(index, NonUnique) == 0 ?
                                                  DataInterpreter.True : DataInterpreter.False);
                DataInterpreter.SetValueIfChanged(row, Attributes.Primary,
                                                  DataInterpreter.CompareInvariant(DataInterpreter.GetStringNotNull(index, KeyName), PRIMARY) ?
                                                  DataInterpreter.True : DataInterpreter.False);
                DataInterpreter.SetValueIfChanged(row, Attributes.IndexType, index[IndexType]);

                // Add filled index row to the results table
                result.Rows.Add(row);
            }
        }
Пример #20
0
        /// <summary>
        /// Attaches index columns table to datasource
        /// </summary>
        private void AttachIndexColumns()
        {
            DataView view = indexColumns.DataSource is DataView ? indexColumns.DataSource as DataView : new DataView(IndexColumns);

            if (view.Table != IndexColumns)
            {
                view.Table = IndexColumns;
            }

            view.RowFilter = DataInterpreter.BuildFilter(IndexColumn.Index, SelectedIndexName);
            view.Sort      = IndexColumn.Ordinal;

            indexColumns.DataSource = view;
        }
Пример #21
0
 protected void ReadScaleData()
 {
     DisposeSerialPort();
     mSerialPort = new SerialPort
     {
         BaudRate = mCurrScale.baudRate,
         PortName = mCurrScale.com,
         DataBits = mCurrScale.dataByte,
         StopBits = StopBits.One,
         Parity   = Parity.None,
     };
     //设置当前显示控制的解释器。
     mScaleDataInterpreter = DataInterpreter.GetDataInterpreter(mCurrScale.brandType, mSerialPort);
 }
Пример #22
0
        /// <summary>
        /// Attaches foreign jey columns table to datasource
        /// </summary>
        private void AttachForeignKeyColumns()
        {
            DataView view = foreigKeyColumns.DataSource is DataView
                ? foreigKeyColumns.DataSource as DataView : new DataView(ForeignKeysColumns);

            if (view.Table != ForeignKeysColumns)
            {
                view.Table = ForeignKeysColumns;
            }

            view.RowFilter = DataInterpreter.BuildFilter(ForeignKeyColumn.ForeignKeyName, SelectedKeyName);

            foreigKeyColumns.DataSource = view;
        }
Пример #23
0
        /// <summary>
        /// Fills details view with data for selected index
        /// </summary>
        private void FillSelectedIndexView()
        {
            // If selected index is empty, reset view and exit
            if (SelectedIndex == null)
            {
                ResetSelectedIndexView();
                return;
            }

            // Lock selected index updates
            lockUpdate = true;

            // Fill comboboxes
            FillComboboxes();

            // Fill index name
            indexNameText.DataSource = SelectedIndex;

            // If index is primary, need to disable combo-boxes and text boxes
            bool enable = !DataInterpreter.CompareInvariant(SelectedIndexName, IndexDescriptor.PRIMARY);

            indexNameText.Enabled   = enable;
            indexKindSelect.Enabled = enable;
            indexTypeSelect.Enabled = indexTypeSelect.Enabled && enable;

            // If not enabled, there is no value for index kind to select and we should add it
            if (!enable && !indexKindSelect.Items.Contains(IndexDescriptor.PRIMARY))
            {
                indexKindSelect.Items.Add(IndexDescriptor.PRIMARY);
            }
            // In other case PRIMARY is not allowed
            else if (indexKindSelect.Items.Contains(IndexDescriptor.PRIMARY))
            {
                indexKindSelect.Items.Remove(IndexDescriptor.PRIMARY);
            }

            // Enable index settings
            indexSettingsGroup.Enabled = true;

            // Attach grid view to filtered datasource
            AttachIndexColumns();

            // Select index kind and type
            indexKindSelect.SelectedItem = SelectedIndex[Index.IndexKind];
            indexTypeSelect.SelectedItem = SelectedIndex[Index.IndexType];

            // Unlock selected index updates
            lockUpdate = false;
        }
Пример #24
0
        /// <summary>
        /// Validates a cell of the columns grid
        /// </summary>
        private void OnCellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            // Checking only column names
            if (e.ColumnIndex != columnNameColumn.Index)
            {
                return;
            }

            // Getting a cell value
            DataGridViewCell cell      = columnsDataGrid[e.ColumnIndex, e.RowIndex];
            string           cellValue = cell.EditedFormattedValue as string;

            // A column name can't be empty
            if (string.IsNullOrEmpty(cellValue))
            {
                e.Cancel = true;
                string errorMessage = String.Format(Resources.Error_EmptyColumnName, Document.Name);
                UIHelper.ShowError(errorMessage);
                isValid = false;
                return;
            }

            // Checking if this cell name duplicates another column name
            foreach (DataGridViewRow row in columnsDataGrid.Rows)
            {
                // Skip current row
                if (row.Index == e.RowIndex)
                {
                    continue;
                }

                // Extract column name
                string columnName = row.Cells[e.ColumnIndex].Value as string;
                if (string.IsNullOrEmpty(columnName))
                {
                    continue;
                }


                if (DataInterpreter.CompareInvariant(cellValue, columnName))
                {
                    e.Cancel = true;
                    string errorMessage = String.Format(Resources.Error_DuplicateColumnName, cellValue);
                    UIHelper.ShowError(errorMessage);
                    isValid = false;
                    return;
                }
            }
        }
Пример #25
0
        /// <summary>
        /// Paints the "NULL" image in text cells containing the DBNull value
        /// </summary>
        /// <param name="e"></param>
        protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
        {
            // Filtering header cells
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }

            // Filtering non-text cells
            DataGridViewColumn column = Columns[e.ColumnIndex];

            if (column.CellType != typeof(DataGridViewTextBoxCell))
            {
                return;
            }

            // Filtering unbound cells
            DataGridViewRow row       = Rows[e.RowIndex];
            DataRowView     boundItem = row.DataBoundItem as DataRowView;

            if (boundItem == null)
            {
                return;
            }

            // Filtering cells having sources with not null values
            DataRow dr = boundItem.Row;

            if (DataInterpreter.IsNotNull(dr, column.DataPropertyName))
            {
                return;
            }

            // A field to paint and a picture
            Rectangle cell = e.CellBounds;
            Bitmap    pic  = Resources.Null;

            // Painting background
            e.PaintBackground(cell, true);

            // Painting the required index at the "LeftMiddle"
            int       x        = cell.Left + column.DefaultCellStyle.Padding.Left + 4;
            int       y        = cell.Top + (cell.Height - pic.Height) / 2;
            Rectangle picBound = new Rectangle(x, y, pic.Width, pic.Height);

            e.Graphics.DrawImageUnscaledAndClipped(pic, picBound);
            e.Handled = true;
        }
Пример #26
0
        /// <summary>
        /// Sets value of given attribute in the column data row.
        /// </summary>
        /// <param name="attribute">Name of the attribute to set.</param>
        /// <param name="value">New value for the atribute</param>
        private void SetAttribute(string attribute, object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            // Validate row
            if (ColumnRow == null)
            {
                return;
            }

            // Validate attribute name
            DataInterpreter.SetValueIfChanged(ColumnRow, attribute, value);
        }
Пример #27
0
        /// <summary>
        /// Fills view with data row data.
        /// </summary>
        private void RefreshView()
        {
            // If row is empty, reset view and exit.
            if (ColumnRow == null)
            {
                ResetView();
                return;
            }

            // Disconnect from text box change event handler for default value
            // or it will reset null to empty string
            defaultValueText.TextChanged -= new EventHandler(OnTextChanged);

            // Fill text boxes.
            nameText.DataSource   = ColumnRow;
            datatypeText.Text     = DataInterpreter.GetString(ColumnRow, Column.MySqlType);
            defaultValueText.Text = DataInterpreter.GetString(ColumnRow, Column.Default);
            commentText.Text      = DataInterpreter.GetString(ColumnRow, Column.Comments);

            // Connect to text box change event handler for default value again
            defaultValueText.TextChanged += new EventHandler(OnTextChanged);


            // Fill column options.
            primaryKey.Checked    = DataInterpreter.GetSqlBool(ColumnRow, Column.IsPrimaryKey).IsTrue;
            notNull.Checked       = DataInterpreter.GetSqlBool(ColumnRow, Column.Nullable).IsFalse;
            autoIncrement.Checked = DataInterpreter.GetSqlBool(ColumnRow, Column.IsAutoIncrement).IsTrue;

            // Determine datatype and build flags set.
            string dataType = DataInterpreter.GetString(ColumnRow, Column.MySqlType);

            if (dataType == null)
            {
                dataType = String.Empty;
            }
            BuildFlags(dataType);


            // Enable or disable comboboxes
            charsetSelect.Enabled = collationSelect.Enabled = Parser.SupportCharacterSet(dataType);

            // Select caharacter set.
            SelectCharacterSet(DataInterpreter.GetString(ColumnRow, Column.CharacterSet));

            // Select collation
            SelectCollation(DataInterpreter.GetString(ColumnRow, Column.Collation));
        }
Пример #28
0
        /// <summary>
        /// Returns ordinal value for the new item to be inserted at the end of the table.
        /// </summary>
        /// <returns>
        /// Returns ordinal value for the new item to be inserted at the end of the table.
        /// </returns>
        private object GetNextValue()
        {
            if (OrdinalColumn.ValueType != typeof(Int64) &&
                OrdinalColumn.ValueType != typeof(UInt64))
            {
                Debug.Fail("Unsupported ordinal column type!");
                return(Rows.Count);
            }

            // TODO: This will works only with numeric ordinal columns
            if (Rows.Count == 0)
            {
                return(0);
            }

            DataRow result = ExtractDataRow(Rows[0]);

            if (result == null)
            {
                return(Rows.Count);
            }

            // TODO: This is a hack to avoid DataGridViewError (default values are not applied
            // for the first row if all rows were deleted)
            if (!DataInterpreter.IsNotNull(result, OrdinalColumn.DataPropertyName))
            {
                Rows[0].Cells[OrdinalColumn.Index].Value = 1;
                return(Rows.Count);
            }

            foreach (DataGridViewRow candidate in Rows)
            {
                if (candidate == null)
                {
                    continue;
                }
                DataRow dataRow = ExtractDataRow(candidate);
                if (dataRow != null && DataInterpreter.IsNotNull(dataRow, OrdinalColumn.DataPropertyName) &&
                    IsLess(result, dataRow))
                {
                    result = dataRow;
                }
            }

            return(DataInterpreter.GetInt(result, OrdinalColumn.DataPropertyName).Value + 1);
        }
Пример #29
0
        /// <summary>
        /// Extracts information about all availabel table engines from the DataTable.
        /// </summary>
        /// <param name="table">DataTable object with data</param>
        private void FillTableEngines(DataTable table)
        {
            // Iterate through all engines
            foreach (DataRow engine in table.Rows)
            {
                // Extract values
                string     name        = DataInterpreter.GetString(engine, EngineDescriptor.Attributes.Name);
                SqlBoolean isSupported = DataInterpreter.GetSqlBool(engine, EngineDescriptor.Attributes.IsSupported);
                if (engine["Support"].Equals("DISABLED"))
                {
                    isSupported = false;
                }

                // Validate name
                if (String.IsNullOrEmpty(name))
                {
                    Debug.Fail("Empty engine name!");
                    continue;
                }

                // Check if engine is not supported
                if (isSupported.IsFalse)
                {
                    continue;
                }

                // Replacing MRG_MyISAM by more readable MERGE
                if (DataInterpreter.CompareInvariant(name, TableDescriptor.MRG_MyISAM))
                {
                    name = TableDescriptor.MERGE;
                }

                // Default engine founded (not YES and not NO - DEFAULT)
                if (isSupported.IsNull)
                {
                    Debug.Assert(String.IsNullOrEmpty(defaultEngineVal), "Duplicated default engine!");
                    defaultEngineVal = name;
                }

                // Add engine to collaection
                if (!enginesList.Contains(name))
                {
                    enginesList.Add(name);
                }
            }
        }
Пример #30
0
        /// <summary>
        /// Fetches data from the results of the SHOW INDEX FROM query to the
        /// DataTable with database objects descriptions.
        /// </summary>
        /// <param name="restrictions">Restricton to apply to the read objects.</param>
        /// <param name="table">DataRow with table descriptions for which indexes are enumerated.</param>
        /// <param name="indexes">DataTable with results of the SHOW INDEX FROM.</param>
        /// <param name="result">DataTable to fill with data.</param>
        protected override void FetchData(object[] restrictions, DataRow table, DataTable indexes, DataTable result)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            if (indexes == null)
            {
                throw new ArgumentNullException("indexes");
            }
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            // Iterate through results of SHOW INDEX FROM
            foreach (DataRow index in indexes.Rows)
            {
                // Check index name restriction
                if (!CheckIndexName(restrictions, index))
                {
                    continue;
                }
                // Check index column name restriction
                if (!CheckIndexColumnName(restrictions, index))
                {
                    continue;
                }

                // Create new row for index column
                DataRow row = result.NewRow();

                // Extract data
                DataInterpreter.SetValueIfChanged(row, Attributes.Database, null);
                DataInterpreter.SetValueIfChanged(row, Attributes.Schema, table[TableDescriptor.Attributes.Schema]);
                DataInterpreter.SetValueIfChanged(row, Attributes.Table, index[Table]);
                DataInterpreter.SetValueIfChanged(row, Attributes.Index, index[KeyName]);
                DataInterpreter.SetValueIfChanged(row, Attributes.Name, index[ColumnName]);
                DataInterpreter.SetValueIfChanged(row, Attributes.Ordinal, index[SeqInIndex]);
                DataInterpreter.SetValueIfChanged(row, Attributes.IndexLength, index[SubPart]);

                // Add new row to the results table
                result.Rows.Add(row);
            }
        }