Ejemplo n.º 1
0
        private void Yes_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text != "" && comboBox3.Text != "" && textBox0.Text != "")
            {
                if (textBox1.Text.Length == 3)
                {
                    string sql1 = $"SELECT Airport.Code FROM Airport WHERE Airport.Code = '{textBox1.Text}'";
                    c.Open();
                    MySqlCommand    com1    = new MySqlCommand(sql1, c);
                    MySqlDataReader reader1 = com1.ExecuteReader();
                    bool            t1      = true;
                    while (reader1.Read())
                    {
                        t1 = false;
                    }
                    c.Close();
                    string sql2 = $"SELECT Airport.Code FROM Airport WHERE Airport.Name = '{textBox0.Text}'";
                    c.Open();
                    MySqlCommand    com2    = new MySqlCommand(sql2, c);
                    MySqlDataReader reader2 = com2.ExecuteReader();
                    bool            t2      = true;
                    while (reader2.Read())
                    {
                        t2 = false;
                    }
                    c.Close();
                    if (t2)
                    {
                        if (t1)
                        {
                            string SQL = $"INSERT INTO Airport(Code, idCity, Name) VALUES ('{textBox1.Text}',(SELECT ID FROM City WHERE City.Name = '{comboBox3.Text}'),'{textBox0.Text}')";
                            c.Open();
                            MySqlCommand com = new MySqlCommand(SQL, c);
                            com.ExecuteNonQuery();
                            c.Close();
                            string SQL10 = $"UPDATE City SET idCityWithNearestAirport = ID WHERE City.Name = '{comboBox3.Text}'";
                            c.Open();
                            MySqlCommand com10 = new MySqlCommand(SQL10, c);
                            com10.ExecuteNonQuery();
                            c.Close();

                            Close();
                        }
                        else
                        {
                            MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Аэропорт с таким кодом уже существует", "ОК", "", "ОК", "");
                            mmb.Show();
                        }
                    }
                    else
                    {
                        MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Аэропорт с таким названием уже существует", "ОК", "", "ОК", "");
                        mmb.Show();
                    }
                }
                else
                {
                    MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Код должен  состоять из трех букв", "ОК", "", "ОК", "");
                    mmb.Show();
                }
            }
            else
            {
                MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Введите значение", "ОК", "", "ОК", "");
                mmb.Show();
            }
        }
Ejemplo n.º 2
0
        private void Yes_Click(object sender, EventArgs e)
        {
            if (comboBox3.Text != "" && comboBox2.Text != "" && comboBox1.Text != "" && textBox0.Text != "")
            {
                c.Open();
                string          sql1     = $"SELECT City.Name FROM Country, City WHERE City.IdCountry = Country.ID AND Country.Name = '{comboBox2.Text}' AND City.Name='{textBox0.Text}'";
                MySqlCommand    command1 = new MySqlCommand(sql1, c);
                MySqlDataReader reader1  = command1.ExecuteReader();
                bool            t        = true;
                while (reader1.Read())
                {
                    t = false;
                }
                c.Close();
                if (t)
                {
                    c.Open();
                    string          sql2     = $"SELECT Country.ID FROM Country WHERE Country.Name = '{comboBox1.Text}'";
                    MySqlCommand    command2 = new MySqlCommand(sql2, c);
                    MySqlDataReader reader2  = command2.ExecuteReader();
                    int             idc      = 0;
                    while (reader2.Read())
                    {
                        idc = Convert.ToInt32(reader2[0]);
                    }
                    c.Close();
                    c.Open();
                    string          sql3     = $"SELECT ID FROM City WHERE IdCountry='{idc}' AND Name ='{comboBox3.Text}'";
                    MySqlCommand    command3 = new MySqlCommand(sql3, c);
                    MySqlDataReader reader3  = command3.ExecuteReader();
                    int             idcity   = 0;
                    while (reader3.Read())
                    {
                        idcity = Convert.ToInt32(reader3[0]);
                    }
                    c.Close();
                    if (idcity == 0)
                    {
                        idcity = ID;
                    }
                    string SQL = $"INSERT INTO City (ID, Name, IdCountry, IdCityWithNearestAirport) VALUES('{ID}','{textBox0.Text}','{idc}','{idcity}')";
                    c.Open();
                    MySqlCommand com = new MySqlCommand(SQL, c);
                    com.ExecuteNonQuery();
                    c.Close();
                    c.Open();
                    string          sql     = $"SELECT City.Name, Country.Name FROM City, Country WHERE Country.ID={idc} AND City.IdCountry=Country.ID ";
                    MySqlCommand    command = new MySqlCommand(sql, c);
                    MySqlDataReader reader  = command.ExecuteReader();
                    Form.comboBox3.Items.Clear();
                    while (reader.Read())
                    {
                        Form.comboBox3.Items.Add(reader[0].ToString());
                    }
                    c.Close();
                    Form.comboBox2.SelectedItem = comboBox2.Text;
                    Form.comboBox3.SelectedItem = textBox0.Text;
                    if (Form.FromAddAirport)
                    {
                        Form.addairport.comboBox1.Items.Clear();
                        c.Open();
                        string          sql10     = "SELECT Name FROM Country ";
                        MySqlCommand    command10 = new MySqlCommand(sql10, c);
                        MySqlDataReader reader10  = command10.ExecuteReader();
                        while (reader10.Read())
                        {
                            Form.addairport.comboBox1.Items.Add(reader10[0].ToString());
                        }
                        c.Close();
                        Form.addairport.comboBox1.SelectedItem = comboBox1.Text;
                        Form.addairport.comboBox3.SelectedItem = comboBox3.Text;
                    }

                    Close();
                }
                else
                {
                    MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Город в этой стране с таким названием уже существует", "ОК", "", "ОК", "");
                    mmb.Show();
                }
            }
            else
            {
                MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Введите значение", "ОК", "", "ОК", "");
                mmb.Show();
            }
        }
Ejemplo n.º 3
0
 private void Yes_Click(object sender, EventArgs e)
 {
     if (comboBox2.Text != "" && textBox0.Text != "")
     {
         if (textBox1.Text.Length == 3)
         {
             string sql1 = $"SELECT Airline.Name FROM Airline WHERE Airline.Name = '{textBox0.Text}' ";
             c.Open();
             MySqlCommand    command1 = new MySqlCommand(sql1, c);
             MySqlDataReader reader1  = command1.ExecuteReader();
             bool            t1       = true;
             while (reader1.Read())
             {
                 t1 = false;
             }
             c.Close();
             string sql2 = $"SELECT Airline.Code FROM Airline WHERE Airline.Code = '{textBox1.Text}' ";
             c.Open();
             MySqlCommand    command2 = new MySqlCommand(sql2, c);
             MySqlDataReader reader2  = command2.ExecuteReader();
             bool            t2       = true;
             while (reader2.Read())
             {
                 t2 = false;
             }
             c.Close();
             if (t1)
             {
                 if (t2)
                 {
                     c.Open();
                     string          sql20     = $"SELECT Country.ID FROM Country WHERE Country.Name = '{comboBox2.Text}'";
                     MySqlCommand    command20 = new MySqlCommand(sql20, c);
                     MySqlDataReader reader20  = command20.ExecuteReader();
                     int             idc       = 0;
                     while (reader20.Read())
                     {
                         idc = Convert.ToInt32(reader20[0]);
                     }
                     c.Close();
                     string sql3 = $"INSERT INTO Airline (Name, code, idCountry) VALUES ('{textBox0.Text}','{textBox1.Text}','{idc}')";
                     c.Open();
                     MySqlCommand command3 = new MySqlCommand(sql3, c);
                     command3.ExecuteNonQuery();
                     c.Close();
                     Form.comboBox6.Items.Clear();
                     string SQL2 = "SELECT Airline.Name FROM Airline";
                     c.Open();
                     MySqlCommand    command100 = new MySqlCommand(SQL2, c);
                     MySqlDataReader reader100  = command100.ExecuteReader();
                     while (reader100.Read())
                     {
                         Form.comboBox6.Items.Add(reader100[0].ToString());
                     }
                     c.Close();
                     Form.comboBox6.SelectedItem = textBox0.Text;
                     Close();
                 }
                 else
                 {
                     MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Авиакомпания с таким кодом уже существует", "ОК", "", "ОК", "");
                     mmb.Show();
                 }
             }
             else
             {
                 MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Авиакомпания с таким названием уже существует", "ОК", "", "ОК", "");
                 mmb.Show();
             }
         }
         else
         {
             MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Код должен состоять из 3 букв", "ОК", "", "ОК", "");
             mmb.Show();
         }
     }
     else
     {
         MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Введите значение", "ОК", "", "ОК", "");
         mmb.Show();
     }
 }