private void RefreshGridViews()
 {
     //jeżeli wybrano tabelę to pokazuje jej zwartość
     if (cB_currentTableSelected.SelectedIndex > -1 &&
         cB_currentTableSelected.Text != "(brak)") //jeśli comboBox jest wypełniony
     {
         //odświeżanie gridView'ów
         ReadDatabase.ReadChosenTableContent(dataGridView_ReadDatabase,
                                             cB_currentTableSelected.Text);
         ReadDatabase.ReadChosenTableContent(dataGridView_modifyTable,
                                             cB_currentTableSelected.Text);
         ReadDatabase.ReadChosenTableContent(dataGridView_modifyStructure,
                                             cB_currentTableSelected.Text);
         dataGridView_modifyTable.Columns[0].ReadOnly = true;
         dataGridView_modifyTable.Columns[0].DefaultCellStyle.BackColor =
             Color.Red;
         Database.ExistingFilledRows = dataGridView_ReadDatabase.RowCount;
     }
     else
     {
         dataGridView_ReadDatabase.DataSource    = null;
         dataGridView_modifyTable.DataSource     = null;
         dataGridView_modifyStructure.DataSource = null;
     }
 }
 private void btn_chooseThisDatabase_Click(object sender, EventArgs e)
 {
     if (lB_availableDatabases.SelectedIndex > -1)
     {
         ReadDatabase.ChooseThisDatabase(lB_availableDatabases.SelectedItem.ToString());
         RefreshComboBoxes();
     }
 }
 public Form2(string tableName, string databaseName)
 {
     InitializeComponent();
     cB_columnType.SelectedIndex = 0;
     ReadDatabase.ShowExistingColumns(tableName, lB_existingColumns);
     this.tableName    = tableName;
     this.databaseName = databaseName;
     //dodawanie elementu wskazującego miejsce w kolejności istniejących kolumn
     lB_existingColumns.Items.Add("*nowa kolumna*");
     lB_existingColumns.SelectedIndex = lB_existingColumns.Items.Count - 1;
 }
 private void RefreshComboBoxes()
 {
     //odświeżanie comboBoxów
     cB_currentTableSelected.Items.Clear();
     cB_tableToDelete.Items.Clear();
     cB_tableToModify.Items.Clear();
     ReadDatabase.ShowAvailableTables(cB_currentTableSelected);
     ReadDatabase.ShowAvailableTables(cB_tableToDelete);
     ReadDatabase.ShowAvailableTables(cB_tableToModify);
     cB_currentTableSelected.SelectedIndex = 0;
     if (cB_currentTableSelected.Text == "(brak)")
     {
         tabPage_readDatabase.Enabled   = false;
         tabPage_modifyDatabase.Enabled = false;
         changeModifyStructureTabPageElementsAccessibility(false);
     }
 }
        private void btn_createColumn_Click(object sender, EventArgs e)
        {
            //sprawdzanie poprawności danych
            string wrongDataList = "";

            if (String.IsNullOrEmpty(tB_columnName.Text))
            {
                wrongDataList += "Brak nazwy kolumny." + Environment.NewLine;
            }

            if (String.IsNullOrEmpty(tB_maxDataLength.Text) && cB_columnType.Text == "VARCHAR")
            {
                wrongDataList +=
                    "Przy typie danych VARCHAR, należy podać maksymalną długość danych."
                    + Environment.NewLine;
            }
            if (!String.IsNullOrEmpty(tB_maxDataLength.Text))
            {
                int temp;
                if (!Int32.TryParse(tB_maxDataLength.Text, out temp))
                {
                    wrongDataList += "Maksymalna długość musi być liczbą całkowitą."
                                     + Environment.NewLine;
                }
            }

            if (!String.IsNullOrEmpty(tB_defaultValue.Text))
            {
                if (cB_columnType.Text == "INT")
                {
                    int temp;
                    if (!Int32.TryParse(tB_defaultValue.Text, out temp))
                    {
                        wrongDataList += "Podana wartość domyślna nie jest liczbą całkowitą."
                                         + Environment.NewLine;
                    }
                }
                else if (cB_columnType.Text == "FLOAT")
                {
                    string content = tB_defaultValue.Text;
                    int    temp;
                    if (ModifyDatabase.isNumberAndFloating(content))
                    {
                        content = content.Replace(',', '.');
                        tB_defaultValue.Text = content;
                    }
                    else if (!Int32.TryParse(tB_defaultValue.Text, out temp))
                    {
                        wrongDataList += "Podana wartość domyślna nie jest poprawną liczbą."
                                         + Environment.NewLine;
                    }
                }
            }

            //wywoływanie metody tworzącej kolumnę
            if (wrongDataList == "")
            {
                string[] options = new string[6];
                //typ danych
                options[0] = cB_columnType.Text;
                //max dł.
                if (!String.IsNullOrEmpty(tB_maxDataLength.Text))
                {
                    options[1] = tB_maxDataLength.Text;
                }
                else
                {
                    options[1] = null;
                }
                //domyślna wart.
                if (!String.IsNullOrEmpty(tB_defaultValue.Text))
                {
                    options[2] = tB_defaultValue.Text;
                }
                else
                {
                    options[2] = null;
                }
                //czy null
                options[3] = checkBox_nullAllowed.Checked.ToString();
                //czy auto inc.
                options[4] = checkBox_autoIncrement.Checked.ToString();
                //wyżej niżej
                if (lB_existingColumns.Items.Count == 1) //brak obecności inych kolumn
                {
                    options[5] = null;
                }
                else
                {
                    if (lB_existingColumns.SelectedIndex == 0) //nowa kolumna będzie pierwszą
                    {
                        options[5] = "first";
                    }
                    else
                    {
                        int index = lB_existingColumns.SelectedIndex - 1;
                        options[5] = "after " + lB_existingColumns.Items[index].ToString();
                    }
                }

                CreateDatabase.AddNewColumn(tableName, tB_columnName.Text, options);
                ReadDatabase.ChooseThisDatabase(databaseName);
                this.Close();
            }
            else
            {
                MessageBox.Show(wrongDataList, "Wprowadzono nieprawidłowe dane",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void btn_discardChanges_Click(object sender, EventArgs e)
 {
     ReadDatabase.ReadChosenTableContent(dataGridView_modifyTable,
                                         cB_currentTableSelected.Text);
 }