示例#1
0
        private void createIndexButton_Click(object sender, EventArgs e)
        {
            try
            {
                Index index = new Index();
                index.Name = string.Format("{0}_Index_{1}", tableSchema.Name, tableSchema.Indexes.Count + 1);

                for (int i = 0; i < IndexDataGridView.Rows.Count - 1; i++)
                {
                    index.IndexMembers.Add(IndexDataGridView.Rows[i].Cells[0].Value.ToString());
                }

                index.Unique = uniqueCheckBox.Checked;

                tableSchema.Indexes.Add(index);
                dbContext.SchemaQuery.UpdateDatabase(database.Name);
            }
            catch (NullReferenceException exception)
            {
                MessageBox.Show("Complete all cells!\n" + exception.Message);
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
示例#2
0
        public IConcreteIndex GetIndex(Index index)
        {
            if (index.Unique)
            {
                return new UniqueIndex(databaseFileName, repository, index);
            }

            return new NonUniqueIndex(databaseFileName, repository, index);
        }
示例#3
0
 public UniqueIndex(string databaseFileName, IRepository repository, Index index)
 {
     this.databaseFileName = databaseFileName;
     this.repository = repository;
     this.index = index;
 }
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(relNameTextBox.Text.ToString()))
            {
                MessageBox.Show(Resources.ResourceManager.GetString("EmptyRelation"));
                return;
            }

            try
            {
                var association = new Association();
                association.Name = relNameTextBox.Text;
                association.Parent = parentComboBox.SelectedItem.ToString();
                association.Child = childComboBox.SelectedItem.ToString();

                for (int i = 0; i < relDataGridView.Rows.Count - 1; i++)
                {
                    association.ColumnMappings[relDataGridView.Rows[i].Cells[0].Value.ToString()] = relDataGridView.Rows[i].Cells[1].Value.ToString();
                }

                database.Associations.Add(association);

                // Add non-unique index for the association.
                Table parentTable = database.GetTable(association.Parent);
                Index index = new Index();
                index.Name = association.Name;
                index.Unique = false;

                foreach (var parentColumn in association.ColumnMappings.Keys)
                {
                    index.IndexMembers.Add(parentColumn);
                }

                parentTable.Indexes.Add(index);
            }
            catch (NullReferenceException exception)
            {
                MessageBox.Show("Complete all cells!\n" + exception.Message);
            }

            DialogResult = DialogResult.OK;
        }
        private void SaveTableButton_Click(object sender, System.EventArgs e)
        {
            //TODO: validate inputs

            var tableName = TableNameTextBox.Text.ToString();
            if (string.IsNullOrEmpty(tableName))
            {
                MessageBox.Show(Resources.ResourceManager.GetString("MissingTableName"));
                return;
            }

            var result = database.Tables.Find(t => t.Name.Equals(tableName));
            if(result != null)
            {
                MessageBox.Show(Resources.ResourceManager.GetString("TableNameTaked"));
                return;
            }

            table = new Table();
            table.Name = tableName;

            try
            {
                for (int i = 0; i < TableDataGridView.Rows.Count - 1; i++)
                {

                    Column column = new Column();
                    column.Name = TableDataGridView.Rows[i].Cells[0].Value.ToString();
                    column.Type = DataTypeConverter.ToDataType(TableDataGridView.Rows[i].Cells[1].Value.ToString());
                    column.Size = Int32.Parse(TableDataGridView.Rows[i].Cells[2].Value.ToString());
                    bool isPrimaryKey = (bool) ((DataGridViewCheckBoxCell) TableDataGridView.Rows[i].Cells[3]).FormattedValue;
                    column.Unique = (bool) ((DataGridViewCheckBoxCell) TableDataGridView.Rows[i].Cells[4]).FormattedValue;
                    column.Nullable = (bool) ((DataGridViewCheckBoxCell)TableDataGridView.Rows[i].Cells[5]).FormattedValue;

                    if (isPrimaryKey)
                    {
                        table.PrimaryKey.Add(column.Name);
                    }

                    table.Columns.Add(column);
                }

                // Create indexes for unique values.
                foreach (var column in table.Columns.Where(c => c.Unique).Select(c => c.Name))
                {
                    Index index = new Index();
                    index.Name = string.Format("{0}_Index_{1}", table.Name, table.Indexes.Count + 1);
                    index.IndexMembers.Add(column);
                    index.Unique = true;
                    table.Indexes.Add(index);
                }

                if (database.GetTable(table.Name) != null)
                {
                    Table tableToDelete = database.GetTable(table.Name);
                    dbContext.Query.DeleteTable(database, tableToDelete);
                    database.Tables.Remove(tableToDelete);
                }

                database.Tables.Add(table);
            }
            catch (NullReferenceException exception)
            {
                MessageBox.Show("Complete all cells!\n" + exception.Message);
            }

            DialogResult = DialogResult.OK;
        }