Ejemplo n.º 1
0
 private void button2_Click(object sender, RoutedEventArgs e)
 {
     InsEditWindow.Close();
 }
Ejemplo n.º 2
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                switch (tableName)
                {
                case "Conference":
                {
                    if (textBox1.Text == "" || datePicker1.SelectedDate.ToString() == "" || datePicker2.SelectedDate.ToString() == "")
                    {
                        MessageBox.Show("Заполнены не все поля");
                    }
                    else
                    {
                        dbConn.Open();
                        if ((int)Tag == 0)
                        {
                            sqlCmd = new NpgsqlCommand($"CALL INSERT_INTO_CONFERENCE('{textBox1.Text}', '{datePicker1.SelectedDate}', '{datePicker2.SelectedDate}')", dbConn);
                        }
                        else
                        {
                            sqlCmd = new NpgsqlCommand($"CALL UPDATE_CONFERENCE({currentDataRow[0]}, '{textBox1.Text}', '{datePicker1.SelectedDate}', '{datePicker2.SelectedDate}')", dbConn);
                        }
                        sqlCmd.ExecuteNonQuery();
                        InsEditWindow.Close();
                        dbConn.Close();
                    }
                    break;
                }

                case "SectionLeaders":
                {
                    if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
                    {
                        MessageBox.Show("Заполнены не все поля");
                    }
                    else
                    {
                        dbConn.Open();
                        if ((int)Tag == 0)
                        {
                            sqlCmd = new NpgsqlCommand($"CALL INSERT_INTO_SECTION_LEADER('{textBox1.Text}', '{textBox2.Text}', '{textBox3.Text}')", dbConn);
                        }
                        else
                        {
                            sqlCmd = new NpgsqlCommand($"CALL UPDATE_SECTION_LEADER({currentDataRow[0]}, '{textBox1.Text}', '{textBox2.Text}', '{textBox3.Text}')", dbConn);
                        }
                        sqlCmd.ExecuteNonQuery();
                        InsEditWindow.Close();
                        dbConn.Close();
                    }
                    break;
                }

                case "Section":
                {
                    if (textBox1.Text == "" || datePicker1.SelectedDate.ToString() == "" || datePicker2.SelectedDate.ToString() == "" || comboBox1.SelectedItem == null || comboBox2.SelectedItem == null)
                    {
                        MessageBox.Show("Заполнены не все поля");
                    }
                    else
                    {
                        dbConn.Open();
                        if ((int)Tag == 0)
                        {
                            sqlCmd = new NpgsqlCommand($"CALL INSERT_INTO_SECTION('{textBox1.Text}', '{datePicker1.SelectedDate}', '{datePicker2.SelectedDate}', '{comboBox1.SelectedValue}', '{comboBox2.SelectedValue}')", dbConn);
                        }
                        else
                        {
                            sqlCmd = new NpgsqlCommand($"CALL UPDATE_SECTION({currentDataRow[0]}, '{textBox1.Text}', '{datePicker1.SelectedDate}', '{datePicker2.SelectedDate}', '{comboBox1.SelectedValue}', '{comboBox2.SelectedValue}')", dbConn);
                        }
                        sqlCmd.ExecuteNonQuery();
                        InsEditWindow.Close();
                        dbConn.Close();
                    }
                    break;
                }

                case "Member":
                {
                    if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "")
                    {
                        MessageBox.Show("Заполнены не все поля");
                    }
                    else
                    {
                        dbConn.Open();
                        if ((int)Tag == 0)
                        {
                            sqlCmd = new NpgsqlCommand($"CALL INSERT_INTO_MEMBER('{textBox1.Text}', '{textBox2.Text}', '{textBox3.Text}', '{textBox4.Text}', '{textBox5.Text}', '{textBox6.Text}')", dbConn);
                        }
                        else
                        {
                            sqlCmd = new NpgsqlCommand($"CALL UPDATE_MEMBER({currentDataRow[0]}, '{textBox1.Text}', '{textBox2.Text}', '{textBox3.Text}', '{textBox4.Text}', '{textBox5.Text}', '{textBox6.Text}')", dbConn);
                        }
                        sqlCmd.ExecuteNonQuery();
                        InsEditWindow.Close();
                        dbConn.Close();
                    }
                    break;
                }

                case "Lecture":
                {
                    if (textBox1.Text == "" || datePicker1.SelectedDate.ToString() == "" || comboBox1.SelectedItem == null || comboBox2.SelectedItem == null)
                    {
                        MessageBox.Show("Заполнены не все поля");
                    }
                    else
                    {
                        dbConn.Open();
                        if ((int)Tag == 0)
                        {
                            sqlCmd = new NpgsqlCommand($"CALL INSERT_INTO_LECTURE('{textBox1.Text}', '{datePicker1.SelectedDate}', '{comboBox1.SelectedValue}', '{comboBox2.SelectedValue}')", dbConn);
                        }
                        else
                        {
                            sqlCmd = new NpgsqlCommand($"CALL UPDATE_LECTURE({currentDataRow[0]}, '{textBox1.Text}', '{datePicker1.SelectedDate}', '{comboBox1.SelectedValue}', '{comboBox2.SelectedValue}')", dbConn);
                        }
                        sqlCmd.ExecuteNonQuery();
                        InsEditWindow.Close();
                        dbConn.Close();
                    }
                    break;
                }
                }
            }
            catch (NpgsqlException ex)
            {
                MessageBox.Show($"Ошибка: {ex.Message}", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
            }
        }