Esempio n. 1
0
        private void button_delete_Click(object sender, EventArgs e)
        {
            // проверка, что категория была выбрана
            if (dataGrid_results.SelectedRows.Count < 1)
            {
                MessageBox.Show("Выберите компанию для изменения", "Ошибка удаления", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            // получим id категории
            int id = Convert.ToInt32(dataGrid_results.SelectedRows[0].Cells[0].Value);

            // Открываем подключение
            if (!MainWindow.open_connection(ref conn_B))
            {
                return;                                             // используются функции из родительской формы !
            }
            // Sql-запрос c параметром
            NpgsqlCommand command = new NpgsqlCommand("select * from initial.delete_companies_B(:id)", conn_B);

            command.Parameters.AddWithValue("id", id);
            if (!AddCategory.executeNonQuery(command, conn_B))
            {
                return;                                                // попробуем произвести вставку
            }
            conn_B.Close();                                            // закроем соединение
            button_refresh_Click(null, null);                          // обновим таблицу компаний
        }
Esempio n. 2
0
        /// <summary>
        /// Изменение компании
        /// </summary>
        private void button_update_Click(object sender, EventArgs e)
        {
            // проверка на пустую строку
            if (string.IsNullOrWhiteSpace(textBox_name.Text) || string.IsNullOrWhiteSpace(textBox_address.Text) || string.IsNullOrWhiteSpace(textBox_bankAccounts.Text) ||
                string.IsNullOrWhiteSpace(textBox_phone.Text) || string.IsNullOrWhiteSpace(textBox_fullName.Text))
            {
                MessageBox.Show("Не все поля заполнены", "Ошибка добавления", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            // проверка, выбран ли элемент в comboBox
            if (comboBox_countries.Items.Count == 0)
            {
                MessageBox.Show("Не выбрана страна", "Ошибка добавления", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            int country_id;

            try
            {
                country_id = Convert.ToInt32(comboBox_countries.SelectedValue);
            }
            catch (Exception)
            {
                MessageBox.Show("Не выбрана страна", "Ошибка добавления", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            // проверка, что компания была выбрана
            if (dataGrid_results.SelectedRows.Count < 1)
            {
                MessageBox.Show("Выберите компанию для изменения", "Ошибка изменения", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            // получим id компании
            int id = Convert.ToInt32(dataGrid_results.SelectedRows[0].Cells[0].Value);

            // Открываем подключение
            if (!MainWindow.open_connection(ref conn_B))
            {
                return;                                             // используются функции из родительской формы !
            }
            // Sql-запрос c параметром
            NpgsqlCommand command =
                new NpgsqlCommand("select * from initial.update_companies_B(:id, :name, :country_id, :head_full_name, :phone, :address, :bank_details)", conn_B);

            command.Parameters.AddWithValue("id", id);
            command.Parameters.AddWithValue("name", textBox_name.Text);
            command.Parameters.AddWithValue("country_id", country_id);
            command.Parameters.AddWithValue("head_full_name", textBox_fullName.Text);
            command.Parameters.AddWithValue("phone", textBox_phone.Text);
            command.Parameters.AddWithValue("address", textBox_address.Text);
            command.Parameters.AddWithValue("bank_details", textBox_bankAccounts.Text);
            if (!AddCategory.executeNonQuery(command, conn_B))
            {
                return;                                               // попробуем произвести вставку
            }
            conn_B.Close();                                           // закроем соединение
            button_refresh_Click(null, null);                         // обновим таблицу категорий
        }
Esempio n. 3
0
        /// <summary>
        /// Изменим клиента по ID
        /// </summary>
        private void button_update_Click(object sender, EventArgs e)
        {
            // проверка на пустую строку
            if (string.IsNullOrWhiteSpace(textBox_surname.Text) || string.IsNullOrWhiteSpace(textBox_name.Text) || string.IsNullOrWhiteSpace(textBox_patronymic.Text) ||
                string.IsNullOrWhiteSpace(textBox_phone.Text) || string.IsNullOrWhiteSpace(textBox_email.Text) || string.IsNullOrWhiteSpace(textBox_series.Text) ||
                string.IsNullOrWhiteSpace(textBox_number.Text) || string.IsNullOrWhiteSpace(textBox_issuedBy.Text) || string.IsNullOrWhiteSpace(textBox_address.Text))
            {
                MessageBox.Show("Не все поля заполнены", "Ошибка добавления", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            // проверка, что категория была выбрана
            if (dataGrid_results.SelectedRows.Count < 1)
            {
                MessageBox.Show("Выберите категорию для изменения", "Ошибка изменения", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            // получим id категории
            int id = Convert.ToInt32(dataGrid_results.SelectedRows[0].Cells[0].Value);

            // Открываем подключение
            if (!MainWindow.open_connection(ref conn_B))
            {
                return;                                             // используются функции из родительской формы !
            }
            // Sql-запрос c параметром
            NpgsqlCommand command =
                new NpgsqlCommand("select * from initial.update_clients_B(:id, :surname,:name,:patronymic,:birthday,:phone,:email,:address,:series,:number,:issueDate,:issuedBy)", conn_B);

            command.Parameters.AddWithValue("id", id);
            command.Parameters.AddWithValue("surname", textBox_surname.Text);
            command.Parameters.AddWithValue("name", textBox_name.Text);
            command.Parameters.AddWithValue("patronymic", textBox_patronymic.Text);
            command.Parameters.AddWithValue("birthday", dateTime_birthday.Value);
            command.Parameters.AddWithValue("phone", textBox_phone.Text);
            command.Parameters.AddWithValue("email", textBox_email.Text);
            command.Parameters.AddWithValue("address", textBox_address.Text);
            command.Parameters.AddWithValue("series", textBox_series.Text);
            command.Parameters.AddWithValue("number", textBox_number.Text);
            command.Parameters.AddWithValue("issueDate", dateTime_issueDate.Value);
            command.Parameters.AddWithValue("issuedBy", textBox_issuedBy.Text);
            if (!AddCategory.executeNonQuery(command, conn_B))
            {
                return;                                                 // попробуем произвести вставку
            }
            conn_B.Close();                                             // закроем соединение
            //button_refresh_Click(null, null);                         // обновим таблицу категорий
        }
Esempio n. 4
0
 /// <summary>
 /// конструктор
 /// </summary>
 public MainWindow()
 {
     InitializeComponent();
     // Создадим набор данных для 8 запроса
     dataSetQuery8 = new DataSet();
     dataSetQuery9 = new DataSet();
     // Очищаем набор данных
     dataSetQuery8.Clear();
     dataSetQuery9.Clear();
     // задаим строки подключения
     conn_A          = new NpgsqlConnection("server=students.ami.nstu.ru; database=risbd4; user Id=risbd4_ext; password=ris14bd4_ext");
     conn_B          = new NpgsqlConnection("server=localhost; database=postgres; user Id=test; password=test");
     formAddCategory = new AddCategory(conn_B);
     formAddClient   = new AddClient(conn_A, conn_B);
     formAddCompany  = new AddCompany(conn_A, conn_B);
     formAddGoods    = new AddGoods(conn_A, conn_B);
     // formAddCategory.Show();
 }