//подія збереження даних
        private void btnSave_Click(object sender, EventArgs e)
        {
            //перевірка, що всі поля заповнені
            if (CheckField() != false)
            {
                if (btnAddEnabled) //якщо обране додавання нового рядка
                {
                    //команда додавання в таблицю бази даних
                    command = new SQLiteCommand("INSERT INTO Department VALUES (@Id, NULL, @NameUA, @NameEN, @ReceptNum, @Fio)", Program.conn);
                    //додавання параметрів
                    command.Parameters.Add(new SQLiteParameter("@Id", 1));
                    command.Parameters.Add(new SQLiteParameter("@NameUA", textBox1.Text));
                    command.Parameters.Add(new SQLiteParameter("@NameEN", textBox2.Text));
                    command.Parameters.Add(new SQLiteParameter("@ReceptNum", textBox3.Text));
                    command.Parameters.Add(new SQLiteParameter("@Fio", textBox4.Text));
                    //виконання запиту
                    SQLiteViewInTable.AddDataInBD(command);
                    //оновлення виводу таблиці
                    FrmSettingDepart_Load(sender, e);
                    //активація та деактивація кнопок
                    btnAddEnabled  = false;
                    btnAdd.Enabled = true;
                    //повідомлення про успішну операцію
                    MessageBox.Show("Дані збережено!", "Увага!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (btnUpdate) //якщо обране редагування поточного рядка
                {
                    //додавання в таблицю бази даних
                    command = new SQLiteCommand("UPDATE Department SET NameUA = @NameUA, NameEN = @NameEN, ReceptNumb = @ReceptNumb, Fio = @Fio WHERE idDepartment = @id", Program.conn);
                    //додавання параметрів
                    command.Parameters.Add(new SQLiteParameter("@Id", dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex].Cells[1].Value));
                    command.Parameters.Add(new SQLiteParameter("@NameUA", textBox1.Text));
                    command.Parameters.Add(new SQLiteParameter("@NameEN", textBox2.Text));
                    command.Parameters.Add(new SQLiteParameter("@ReceptNumb", textBox3.Text));
                    command.Parameters.Add(new SQLiteParameter("@Fio", textBox4.Text));
                    //виконання запиту
                    SQLiteViewInTable.UpdateDateInBD(command);
                    //оновлення виводу таблиці
                    FrmSettingDepart_Load(sender, e);
                    //активація та деактивація кнопок
                    btnUpdate         = false;
                    btnChange.Enabled = true;
                    //повідомлення про успішну операцію
                    MessageBox.Show("Дані збережено!", "Увага!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                TextBoxDeActive();//декативація полів вводу
                //активація та деактивація кнопок
                btnSave.Enabled   = false;
                btnCancel.Enabled = false;
                btnAdd.Enabled    = true;
                btnDelete.Enabled = true;
                btnChange.Enabled = true;
            }
        }
        //збереження даних в базі
        private void btnSaveData_Click(object sender, EventArgs e)
        {
            //перевірка введення даних
            if (!CheckField())
            {
                return;
            }

            if (btnAddEnabled) //якщо кнопка додати
            {
                //додавання в таблицю бази даних
                command = new SQLiteCommand("INSERT INTO Subject VALUES (NULL, @idSpec, @semester, @NameUA, @NameEN, @Size)", Program.conn);
                //команда пошуку коду спеціалізації
                SQLiteCommand command2 = new SQLiteCommand("SELECT id_specialization FROM specialization WHERE name_ua_spec = @name", Program.conn);
                //доадвання параметру
                command2.Parameters.Add(new SQLiteParameter("@name", comboBox3.Text));
                dataReader = command2.ExecuteReader(); //виконаня команди

                int idSpec = 0;                        //код спеціалізації
                while (dataReader.Read())
                {
                    idSpec = Convert.ToInt32(dataReader[0]);//знайдений код спеціалізації
                }
                //доадвання параметру
                command.Parameters.Add(new SQLiteParameter("@idSpec", idSpec));
                command.Parameters.Add(new SQLiteParameter("@semester", numericSemester.Value));
                command.Parameters.Add(new SQLiteParameter("@NameUA", textBox2.Text));
                command.Parameters.Add(new SQLiteParameter("@NameEN", textBox3.Text));
                command.Parameters.Add(new SQLiteParameter("@Size", textBox5.Text));
                //виконання запиту
                SQLiteViewInTable.AddDataInBD(command);
                //оновлення виводу таблиці
                View(comboBox3, activeRbtn, Convert.ToInt32(numericSemester.Value));
                //Активація та деактивація потрібних кнопок
                btnAddEnabled     = false;
                btnChange.Enabled = true;
                btnDelete.Enabled = true;
                btnAdd.Enabled    = true;
                //повідомлення про успіх
                MessageBox.Show("Дані збережено!", "Увага!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (btnUpdate) //якщо натиснута кнопку редагувати
            {
                //знаходження коду спеціальності
                SQLiteCommand command2 = new SQLiteCommand("SELECT id_specialization FROM specialization WHERE name_ua_spec = @name", Program.conn);
                //доадвання параметру
                command2.Parameters.Add(new SQLiteParameter("@name", comboBox3.Text));
                dataReader = command2.ExecuteReader(); //виконаня команди

                int idSpec = 0;                        //код спеціалізації
                while (dataReader.Read())
                {
                    idSpec = Convert.ToInt32(dataReader[0]);//знайдений код спеціалізації
                }

                //додавання в таблицю бази даних
                command = new SQLiteCommand("UPDATE Subject SET id_specialization = @idSpec, SemesterNum = @semester, NameUA = @nameUA," +
                                            " NameEN = @nameEN, OverSize = @size WHERE idSubject = @idSubjectd", Program.conn);
                //доадвання параметру
                command.Parameters.Add(new SQLiteParameter("@idSpec", idSpec));
                command.Parameters.Add(new SQLiteParameter("@semester", numericSemester.Value));
                command.Parameters.Add(new SQLiteParameter("@nameUA", textBox2.Text));
                command.Parameters.Add(new SQLiteParameter("@nameEN", textBox3.Text));
                command.Parameters.Add(new SQLiteParameter("@size", textBox5.Text));
                command.Parameters.Add(new SQLiteParameter("@idSubjectd", idSubjectd));
                //виконання запиту
                SQLiteViewInTable.UpdateDateInBD(command);
                //оновлення виводу таблиці
                View(comboBox3, activeRbtn, Convert.ToInt32(numericSemester.Value));
                //Активація та деактивація потрібних кнопок
                btnUpdate         = false;
                btnChange.Enabled = true;
                btnDelete.Enabled = true;
                btnAdd.Enabled    = true;
                //повідомлення про успіх
                MessageBox.Show("Дані збережено!", "Увага!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            if (handlerAttached == false)
            {
                numericSemester.ValueChanged += numericSemester_ValueChanged;
                handlerAttached = true;
            }
            btnSaveData.Enabled = false;
            FieldDeActive();
            btnCancel.Enabled = false;
        }
Exemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (CheckField() != false) // перевірка вводу в поля
            {
                if (btnAddEnabled)     //якщо додавання рядка
                {
                    //додавання в таблицю бази даних
                    command = new SQLiteCommand("INSERT INTO User VALUES (NULL, @fio, @login, @pass, @admin)", Program.conn);
                    //додавання параметрів
                    command.Parameters.Add(new SQLiteParameter("@fio", textBox1.Text));
                    command.Parameters.Add(new SQLiteParameter("@login", textBox2.Text));
                    command.Parameters.Add(new SQLiteParameter("@pass", textBox3.Text));
                    if (checkBox1.Checked)
                    {
                        command.Parameters.Add(new SQLiteParameter("@admin", "+"));
                    }
                    else
                    {
                        command.Parameters.Add(new SQLiteParameter("@admin", "-"));
                    }
                    //виконання запиту
                    SQLiteViewInTable.AddDataInBD(command);
                    //оновлення виводу таблиці
                    FrmSettingUser_Load(sender, e);

                    btnAddEnabled  = false;
                    btnAdd.Enabled = true;
                    //повідомлення про успіх
                    MessageBox.Show("Дані збережено!", "Увага!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (btnUpdate)
                {
                    //додавання в таблицю бази даних
                    command = new SQLiteCommand("UPDATE User SET fio = @fio, login = @login, password = @pass, rang = @admin WHERE idUser = @id", Program.conn);
                    //додавання параметрів
                    command.Parameters.Add(new SQLiteParameter("@Id", dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex].Cells[0].Value));
                    command.Parameters.Add(new SQLiteParameter("@fio", textBox1.Text));
                    command.Parameters.Add(new SQLiteParameter("@login", textBox2.Text));
                    command.Parameters.Add(new SQLiteParameter("@pass", textBox3.Text));
                    if (checkBox1.Checked)
                    {
                        command.Parameters.Add(new SQLiteParameter("@admin", "+"));
                    }
                    else
                    {
                        command.Parameters.Add(new SQLiteParameter("@admin", "-"));
                    }
                    //виконання запиту
                    SQLiteViewInTable.UpdateDateInBD(command);
                    //оновлення виводу таблиці
                    FrmSettingUser_Load(sender, e);

                    btnUpdate         = false;
                    btnChange.Enabled = true;
                    //повідомлення про успіх
                    MessageBox.Show("Дані збережено!", "Увага!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                TextBoxDeActive(); //деактивація полів вводу
                //активація та деактивація потрібних кнопок
                btnSave.Enabled   = false;
                btnCancel.Enabled = false;
                btnAdd.Enabled    = true;
                btnDelete.Enabled = true;
                btnChange.Enabled = true;
            }
        }
        //збереження даних
        private void btnSave_Click(object sender, EventArgs e)
        {
            //перевірка введених даних
            if (!CheckField())
            {
                return;
            }

            //додавання нового рядка
            if (btnAddEnabled)
            {
                //команда пошуку коду спеціалізації
                SQLiteCommand command3 = new SQLiteCommand("SELECT id_specialization FROM specialization WHERE id_specialization = @id", Program.conn);
                //додавання параметру
                command3.Parameters.Add(new SQLiteParameter("@id", tbKey.Text));
                dataReader = command3.ExecuteReader(); //виконання команди

                if (dataReader.HasRows)                //перевірка існування рядкуів
                {
                    //повідомлення про дублікат спеціалізацій
                    MessageBox.Show("Спеціалізація з введеним кодом вже існує!", "Увага!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                //додавання в таблицю бази даних
                command1 = new SQLiteCommand("INSERT INTO specialization VALUES (NULL, @id_specialization, @name_ua_spec, @name_en_spec, @id_specialty)", Program.conn);
                //пошук коду спеціальності
                SQLiteCommand command2 = new SQLiteCommand("SELECT idSpecialty FROM Specialty WHERE NameUA = @name", Program.conn);
                //додавання параметру
                command2.Parameters.Add(new SQLiteParameter("@name", cbSpec.Text));
                dataReader = command2.ExecuteReader(); //виконання команди

                int id = 0;                            //код спеціальності
                while (dataReader.Read())
                {
                    id = Convert.ToInt32(dataReader[0]); //знайдений код спеціальності
                }
                //Додавання параметрів
                command1.Parameters.Add(new SQLiteParameter("@id_specialization", tbKey.Text));
                command1.Parameters.Add(new SQLiteParameter("@id_specialty", id));
                command1.Parameters.Add(new SQLiteParameter("@name_ua_spec", tbNameUA.Text));
                command1.Parameters.Add(new SQLiteParameter("@name_en_spec", tbNameEN.Text));
                //виконання запиту
                SQLiteViewInTable.AddDataInBD(command1);
                //оновлення виводу таблиці
                ViewData();
                //активація та деактивація потрібних кнопок
                btnAddEnabled     = false;
                btnChange.Enabled = true;
                btnDelete.Enabled = true;
                btnAdd.Enabled    = true;
                //повідомлення про успіх
                MessageBox.Show("Дані збережено!", "Увага!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (btnUpdate) //оновлення данних
            {
                //поточний код запису
                string id_row = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString();

                //команда пошуку спеціалізації
                SQLiteCommand command3 = new SQLiteCommand("SELECT id_specialization, id FROM specialization WHERE id_specialization = @id_spec", Program.conn);
                //Додавання параметрів
                command3.Parameters.Add(new SQLiteParameter("@id_spec", tbKey.Text));
                dataReader = command3.ExecuteReader(); //виконання запиту
                if (dataReader.HasRows)
                {
                    while (dataReader.Read())
                    {
                        if (dataReader[1].ToString() != id_row)
                        {
                            //повідомлення про дублікат спеціалізації
                            MessageBox.Show($"Помилка! Існує інша спеціалізація з кодом {dataReader[0].ToString()}.", "Увага!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                }

                //знаходження коду спеціальності
                SQLiteCommand command2 = new SQLiteCommand("SELECT idSpecialty FROM Specialty WHERE NameUA = @name", Program.conn);
                //Додавання параметрів
                command2.Parameters.Add(new SQLiteParameter("@name", cbSpec.Text));
                dataReader = command2.ExecuteReader(); //виконання запиту

                int id = 0;                            //код спеціальності
                while (dataReader.Read())
                {
                    id = Convert.ToInt32(dataReader[0]); //знайдений код спеціальності
                }

                //додавання в таблицю бази даних
                command1 = new SQLiteCommand("UPDATE specialization SET id_specialization = @id_specialization, id_specialty = @id_specialty," +
                                             " name_ua_spec = @name_ua_spec, name_en_spec = @name_en_spec WHERE id = @id_row", Program.conn);
                //Додавання параметрів
                command1.Parameters.Add(new SQLiteParameter("@id_specialization", tbKey.Text));
                command1.Parameters.Add(new SQLiteParameter("@id_specialty", id));
                command1.Parameters.Add(new SQLiteParameter("@name_ua_spec", tbNameUA.Text));
                command1.Parameters.Add(new SQLiteParameter("@name_en_spec", tbNameEN.Text));
                command1.Parameters.Add(new SQLiteParameter("@id_row", id_row));

                //виконання запиту
                SQLiteViewInTable.UpdateDateInBD(command1);
                //оновлення виводу таблиці
                ViewData();
                //активація та деактивація потрібних кнопок
                btnUpdate         = false;
                btnChange.Enabled = true;
                btnDelete.Enabled = true;
                btnAdd.Enabled    = true;
                //повідомлення про успіх
                MessageBox.Show("Дані збережено!", "Увага!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            btnSave.Enabled = false;
            FieldDeActive(); //деактивація полів вводу
            btnCancel.Enabled = false;
        }
Exemplo n.º 5
0
        //додавання даних
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (CheckField() != false) //перевірка правильності введення даних
            {
                if (btnAddEnabled)     //якщо натистута кнопка додати
                {
                    //команда додавання в таблицю бази даних
                    command = new SQLiteCommand("INSERT INTO Specialty VALUES (NULL, @id, @idDepart, @NameUA, @NameEN)", Program.conn);
                    //комада пошуку коду відділення
                    SQLiteCommand command2 = new SQLiteCommand("SELECT idDepartment FROM Department WHERE NameUA = @name", Program.conn);
                    //додавання параметру
                    command2.Parameters.Add(new SQLiteParameter("@name", cmbxDepart.Text));
                    dataReader = command2.ExecuteReader(); //виконання запиту

                    int id = 0;                            //код за замовчуванням
                    while (dataReader.Read())
                    {
                        id = Convert.ToInt32(dataReader[0]); //отримання коду відділення з БД
                    }
                    //додавання параметрів
                    command.Parameters.Add(new SQLiteParameter("@id", textBox1.Text));
                    command.Parameters.Add(new SQLiteParameter("@idDepart", id));
                    command.Parameters.Add(new SQLiteParameter("@NameUA", textBox2.Text));
                    command.Parameters.Add(new SQLiteParameter("@NameEN", textBox3.Text));
                    //виконання запиту
                    SQLiteViewInTable.AddDataInBD(command);
                    //оновлення виводу таблиці
                    cmbxDepart_SelectedIndexChanged(sender, e);
                    //зміна прапорця додавання
                    btnAddEnabled = false;
                    //повідомлення про виконання додавання
                    MessageBox.Show("Дані збережено!", "Увага!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (btnUpdate) // якщо натиснута кнопка редагувати
                {
                    try
                    {
                        //комада пошуку коду відділення
                        SQLiteCommand command2 = new SQLiteCommand("SELECT idDepartment FROM Department WHERE NameUA = @name", Program.conn);
                        //додавання параметру
                        command2.Parameters.Add(new SQLiteParameter("@name", cmbxDepart.Text));
                        dataReader = command2.ExecuteReader(); //виконання запиту

                        int idDepartment = 0;                  //код за замовчуванням
                        while (dataReader.Read())
                        {
                            idDepartment = Convert.ToInt32(dataReader[0]);//отримання коду відділення з БД
                        }

                        //додавання в таблицю бази даних
                        command = new SQLiteCommand("UPDATE Specialty SET idSpecialty = @idSpec, idDepartament = @idDepart, NameUA = @nameUA," +
                                                    " NameEN = @nameEN WHERE id_row = @idCurrent", Program.conn);
                        //додавання параметрів
                        command.Parameters.Add(new SQLiteParameter("@idSpec", textBox1.Text));
                        command.Parameters.Add(new SQLiteParameter("@idDepart", idDepartment));
                        command.Parameters.Add(new SQLiteParameter("@nameUA", textBox2.Text));
                        command.Parameters.Add(new SQLiteParameter("@nameEN", textBox3.Text));
                        command.Parameters.Add(new SQLiteParameter("@idCurrent", dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex].Cells[0].Value));

                        //виконання запиту
                        SQLiteViewInTable.UpdateDateInBD(command);

                        //якщо відділення змінювалось
                        if (updateDepart == true)
                        {
                            btnSaveUpdateDepartForSpec();
                            updateDepart = false; //деацтивація прапорця редагування
                        }
                        //змінаподії для випадаючого списку
                        cmbxDepart.SelectedIndexChanged -= cmbxDepart_IndexChangedForUpdate;
                        cmbxDepart.SelectedIndexChanged += cmbxDepart_SelectedIndexChanged;

                        //оновлення виводу таблиці
                        cmbxDepart_SelectedIndexChanged(sender, e);
                    } //повідомення про помилку
                    catch { MessageBox.Show("Cпеціальність з кодом " + textBox1.Text + " вже існує!"); return; }

                    btnUpdate = false;
                    //повідомлення про успіх
                    MessageBox.Show("Дані збережено!", "Увага!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                //активація та деактивація потрібних кнопок
                btnSave.Enabled   = false;
                btnCancel.Enabled = false;
                btnAdd.Enabled    = true;
                btnChange.Enabled = true;
                btnDelete.Enabled = true;
                FieldDeActive();//деактивація полів
            }
        }