コード例 #1
0
 private void Yes_Click(object sender, EventArgs e)
 {
     if (comboBox2.Text != "" && comboBox7.Text != "")
     {
         Search.CountryA    = comboBox7.Text;
         Search.CityA       = comboBox6.Text;
         Search.Airport     = comboBox9.Text;
         Search.CountryB    = comboBox2.Text;
         Search.CityB       = comboBox3.Text;
         Search.HotelB      = comboBox1.Text;
         Search.NightsA     = int.Parse(textBox1.Text);
         Search.NightsB     = int.Parse(textBox2.Text);
         Search.CountPeople = int.Parse(textBox3.Text);
         Search.DateA       = dateTimePicker1.Value;
         Search.DateB       = dateTimePicker2.Value;
         Search.GetUpdate();
         Close();
     }
     else
     {
         MyMessageBox mmb = new MyMessageBox(Search.Form, "Ошибка", "Введите значение для стран", "ОК", "", "ОК", "");
         mmb.Show();
     }
 }
コード例 #2
0
 private void Yes_Click(object sender, EventArgs e)
 {
     if (label4.Text == "Add Hotel")
     {
         if (comboBox1.Text != "" && comboBox2.Text != "" && comboBox3.Text != "")
         {
             c.Open();
             string          sql     = $"SELECT ID FROM City WHERE Name = '{comboBox3.Text}'";
             MySqlCommand    command = new MySqlCommand(sql, c);
             MySqlDataReader reader  = command.ExecuteReader();
             reader.Read();
             int id = Convert.ToInt32(reader[0]);
             c.Close();
             string SQL = $"INSERT INTO Hotel (ID, IdCity, name, stars, food) VALUES('{ID}','{id}','{textBox0.Text}', '{int.Parse(textBox1.Text)}','{comboBox1.Text.Split(' ')[0]}')";
             c.Open();
             MySqlCommand com = new MySqlCommand(SQL, c);
             com.ExecuteNonQuery();
             string          sql0     = "SELECT Hotel.Name, Hotel.Stars, Hotel.Food, City.Name, Country.Name, Hotel.ID FROM Hotel, City, Country WHERE Hotel.IdCity = City.ID AND City.IdCountry = Country.ID";
             MySqlCommand    command0 = new MySqlCommand(sql0, c);
             MySqlDataReader reader0  = command0.ExecuteReader();
             Hotels          ag       = (Hotels)Form.State;
             f.CreateDataGridView(ag.dataGridView1, reader0);
             c.Close();
             Close();
         }
         else
         {
             MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Введите значение", "ОК", "", "ОК", "");
             mmb.Show();
         }
     }
     else
     {
         if (comboBox1.Text != "" && comboBox2.Text != "" && comboBox3.Text != "")
         {
             c.Open();
             string          sql     = $"SELECT ID FROM City WHERE Name = '{comboBox3.Text}'";
             MySqlCommand    command = new MySqlCommand(sql, c);
             MySqlDataReader reader  = command.ExecuteReader();
             reader.Read();
             int id = Convert.ToInt32(reader[0]);
             c.Close();
             string SQL = $"UPDATE Hotel SET IdCity='{id}', name='{textBox0.Text}', stars='{int.Parse(textBox1.Text)}', food='{comboBox1.Text.Split(' ')[0]}' WHERE ID={ID}";
             c.Open();
             MySqlCommand com = new MySqlCommand(SQL, c);
             com.ExecuteNonQuery();
             string          sql0     = "SELECT Hotel.Name, Hotel.Stars, Hotel.Food, City.Name, Country.Name, Hotel.ID FROM Hotel, City, Country WHERE Hotel.IdCity = City.ID AND City.IdCountry = Country.ID";
             MySqlCommand    command0 = new MySqlCommand(sql0, c);
             MySqlDataReader reader0  = command0.ExecuteReader();
             Hotels          ag       = (Hotels)Form.State;
             f.CreateDataGridView(ag.dataGridView1, reader0);
             c.Close();
             Close();
         }
         else
         {
             MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Введите значение", "ОК", "", "ОК", "");
             mmb.Show();
         }
     }
 }
コード例 #3
0
 private void Yes_Click(object sender, EventArgs e)
 {
     if (Yes.Text != "Изменить")
     {
         if (!label9.Visible && !label1.Visible && textBox0.Text != "" && textBox1.Text != "")
         {
             c.Open();
             string          sql     = "SELECT Login FROM Account";
             MySqlCommand    command = new MySqlCommand(sql, c);
             MySqlDataReader reader  = command.ExecuteReader();
             bool            t       = true;
             while (reader.Read())
             {
                 if (reader[0].ToString() == textBox0.Text)
                 {
                     t = false;
                 }
             }
             c.Close();
             if (t)
             {
                 c.Open();
                 int i = 0;
                 if (comboBox1.Text == "Администратор")
                 {
                     i = 1;
                 }
                 string       SQL = $"INSERT INTO Account (login, password, isAdmin) VALUES ('{textBox0.Text}', '{textBox1.Text}','{i}')";
                 MySqlCommand com = new MySqlCommand(SQL, c);
                 com.ExecuteNonQuery();
                 string          sqll     = "SELECT login FROM Account WHERE isAdmin=0 AND login NOT IN (SELECT login FROM agency)";
                 MySqlCommand    commandd = new MySqlCommand(sqll, c);
                 MySqlDataReader readerr  = commandd.ExecuteReader();
                 AT.comboBox1.Items.Clear();
                 while (readerr.Read())
                 {
                     AT.comboBox1.Items.Add(readerr[0].ToString());
                 }
                 AT.comboBox1.SelectedItem = textBox0.Text;
                 c.Close();
                 Close();
             }
             else
             {
                 MyMessageBox mmb = new MyMessageBox(AT.Form, "Ошибка", "Пользователь с таким логином уже существует", "ОК", "", "ОК", "");
                 mmb.Show();
                 c.Close();
             }
         }
     }
     else if (!label9.Visible && !label1.Visible)
     {
         if (textBox2.Text == "Турагентство")
         {
             string newlog = textBox0.Text;
             if (newlog != user.Login)
             {
                 c.Open();
                 string          sql     = "SELECT Login FROM Account";
                 MySqlCommand    command = new MySqlCommand(sql, c);
                 MySqlDataReader reader  = command.ExecuteReader();
                 bool            t       = true;
                 while (reader.Read())
                 {
                     if (reader[0].ToString() == newlog)
                     {
                         t = false;
                     }
                 }
                 c.Close();
                 if (t)
                 {
                     c.Open();
                     string       SQL = $"INSERT INTO Account (login, password, isAdmin) VALUES ('{textBox0.Text}', '{textBox1.Text}','0')";
                     MySqlCommand com = new MySqlCommand(SQL, c);
                     com.ExecuteNonQuery();
                     string       sql00 = $"INSERT INTO Account (login, password, isAdmin) VALUES ('current1308', 'current1308','0')";
                     MySqlCommand com00 = new MySqlCommand(sql00, c);
                     com00.ExecuteNonQuery();
                     string       sql0 = $"INSERT INTO Agency (login, director, name, dateLicense, comission) VALUES ('current1308', 'current1308','current1308',STR_TO_DATE('2000-01-01','%Y-%m-%d'),10)";
                     MySqlCommand com0 = new MySqlCommand(sql0, c);
                     com0.ExecuteNonQuery();
                     string       sql2 = $"UPDATE Voucher SET Login = '******' WHERE Login = '******'";
                     MySqlCommand com2 = new MySqlCommand(sql2, c);
                     com2.ExecuteNonQuery();
                     string       sql1 = $"UPDATE Agency SET Login = '******'WHERE Login = '******'";
                     MySqlCommand com1 = new MySqlCommand(sql1, c);
                     com1.ExecuteNonQuery();
                     string       sql3 = $"UPDATE Voucher SET Login = '******' WHERE Login = '******'";
                     MySqlCommand com3 = new MySqlCommand(sql3, c);
                     com3.ExecuteNonQuery();
                     string       SQL3 = $"DELETE FROM Account WHERE Login = '******' ";
                     MySqlCommand Com3 = new MySqlCommand(SQL3, c);
                     Com3.ExecuteNonQuery();
                     string       SQL4 = $"DELETE FROM Agency WHERE Login = '******' ";
                     MySqlCommand Com4 = new MySqlCommand(SQL4, c);
                     Com4.ExecuteNonQuery();
                     string       SQL5 = $"DELETE FROM Account WHERE Login = '******' ";
                     MySqlCommand Com5 = new MySqlCommand(SQL5, c);
                     Com5.ExecuteNonQuery();
                     c.Close();
                     if (AT.Form.State.GetType() == typeof(Accounts))
                     {
                         Accounts a = (Accounts)AT.Form.State;
                         c.Open();
                         string          sql7     = "SELECT Agency.Name, Account.Login, Account.Password FROM Agency, Account WHERE Account.Login = Agency.Login UNION SELECT '-', Account.Login, Account.Password FROM Account WHERE Account.Login NOT IN(SELECT Login From Agency) AND Account.IsAdmin = 0";
                         MySqlCommand    command0 = new MySqlCommand(sql7, c);
                         MySqlDataReader reader0  = command0.ExecuteReader();
                         f.CreateDataGridView(a.dataGridView1, reader0);
                         c.Close();
                         c.Open();
                         string          sql8     = "SELECT Login, Password FROM Account WHERE IsAdmin = 1";
                         MySqlCommand    command1 = new MySqlCommand(sql8, c);
                         MySqlDataReader reader1  = command1.ExecuteReader();
                         f.CreateDataGridView(a.dataGridView2, reader1);
                         c.Close();
                         a.dataGridView1.ClearSelection();
                         a.dataGridView2.ClearSelection();
                     }
                     Close();
                 }
                 else
                 {
                     MyMessageBox mmb = new MyMessageBox(AT.Form, "Ошибка", "Пользователь с данным логином уже существует", "ОК", "", "ОК", "");
                     mmb.Show();
                 }
             }
             else
             {
                 c.Open();
                 string       sql     = $"UPDATE Account SET Password='******' WHERE Login='******'";
                 MySqlCommand command = new MySqlCommand(sql, c);
                 command.ExecuteNonQuery();
                 c.Close();
                 if (AT.Form.State.GetType() == typeof(Accounts))
                 {
                     Accounts a = (Accounts)AT.Form.State;
                     c.Open();
                     string          sql0     = "SELECT Agency.Name, Account.Login, Account.Password FROM Agency, Account WHERE Account.Login = Agency.Login UNION SELECT '-', Account.Login, Account.Password FROM Account WHERE Account.Login NOT IN(SELECT Login From Agency) AND Account.IsAdmin = 0";
                     MySqlCommand    command0 = new MySqlCommand(sql0, c);
                     MySqlDataReader reader0  = command0.ExecuteReader();
                     f.CreateDataGridView(a.dataGridView1, reader0);
                     c.Close();
                     c.Open();
                     string          sql1     = "SELECT Login, Password FROM Account WHERE IsAdmin = 1";
                     MySqlCommand    command1 = new MySqlCommand(sql1, c);
                     MySqlDataReader reader1  = command1.ExecuteReader();
                     f.CreateDataGridView(a.dataGridView2, reader1);
                     c.Close();
                     a.dataGridView1.ClearSelection();
                     a.dataGridView2.ClearSelection();
                 }
                 Close();
             }
         }
         else
         {
             string newlog = textBox0.Text;
             if (newlog != user.Login)
             {
                 c.Open();
                 string          sql     = "SELECT Login FROM Account";
                 MySqlCommand    command = new MySqlCommand(sql, c);
                 MySqlDataReader reader  = command.ExecuteReader();
                 bool            t       = true;
                 while (reader.Read())
                 {
                     if (reader[0].ToString() == newlog)
                     {
                         t = false;
                     }
                 }
                 c.Close();
                 if (t)
                 {
                     c.Open();
                     string       sql1     = $"UPDATE Account SET Password='******', Login = '******' WHERE Login='******'";
                     MySqlCommand command1 = new MySqlCommand(sql1, c);
                     command1.ExecuteNonQuery();
                     c.Close();
                     if (AT.Form.State.GetType() == typeof(Accounts))
                     {
                         Accounts a = (Accounts)AT.Form.State;
                         c.Open();
                         string          sql0     = "SELECT Agency.Name, Account.Login, Account.Password FROM Agency, Account WHERE Account.Login = Agency.Login UNION SELECT '-', Account.Login, Account.Password FROM Account WHERE Account.Login NOT IN(SELECT Login From Agency) AND Account.IsAdmin = 0";
                         MySqlCommand    command0 = new MySqlCommand(sql0, c);
                         MySqlDataReader reader0  = command0.ExecuteReader();
                         f.CreateDataGridView(a.dataGridView1, reader0);
                         c.Close();
                         c.Open();
                         string          sql10     = "SELECT Login, Password FROM Account WHERE IsAdmin = 1";
                         MySqlCommand    command10 = new MySqlCommand(sql10, c);
                         MySqlDataReader reader1   = command10.ExecuteReader();
                         f.CreateDataGridView(a.dataGridView2, reader1);
                         c.Close();
                         a.dataGridView1.ClearSelection();
                         a.dataGridView2.ClearSelection();
                     }
                     Close();
                 }
                 else
                 {
                     MyMessageBox mmb = new MyMessageBox(AT.Form, "Ошибка", "Пользователь с данным логином уже существует", "ОК", "", "ОК", "");
                     mmb.Show();
                 }
             }
             else
             {
                 c.Open();
                 string       sql     = $"UPDATE Account SET Password='******' WHERE Login='******'";
                 MySqlCommand command = new MySqlCommand(sql, c);
                 command.ExecuteNonQuery();
                 c.Close();
                 if (AT.Form.State.GetType() == typeof(Accounts))
                 {
                     Accounts a = (Accounts)AT.Form.State;
                     c.Open();
                     string          sql0     = "SELECT Agency.Name, Account.Login, Account.Password FROM Agency, Account WHERE Account.Login = Agency.Login UNION SELECT '-', Account.Login, Account.Password FROM Account WHERE Account.Login NOT IN(SELECT Login From Agency) AND Account.IsAdmin = 0";
                     MySqlCommand    command0 = new MySqlCommand(sql0, c);
                     MySqlDataReader reader0  = command0.ExecuteReader();
                     f.CreateDataGridView(a.dataGridView1, reader0);
                     c.Close();
                     c.Open();
                     string          sql1     = "SELECT Login, Password FROM Account WHERE IsAdmin = 1";
                     MySqlCommand    command1 = new MySqlCommand(sql1, c);
                     MySqlDataReader reader1  = command1.ExecuteReader();
                     f.CreateDataGridView(a.dataGridView2, reader1);
                     c.Close();
                     a.dataGridView1.ClearSelection();
                     a.dataGridView2.ClearSelection();
                 }
                 Close();
             }
         }
     }
 }
コード例 #4
0
        private void ButtonHome2_Click(object sender, EventArgs e)
        {
            string name = "";

            try
            {
                Panel p = (Panel)sender;
                name = f.GetNameOfButton(p);
            }
            catch { }
            try
            {
                Label l = (Label)sender;
                name = l.Text;
            }
            catch { }
            try
            {
                PictureBox pb = (PictureBox)sender;
                name = f.GetNameOfButton(panel2, pb);
            }
            catch { }
            if (name == "Удалить")
            {
                if (State.GetType() == typeof(Agencies))
                {
                    Agencies     cur     = (Agencies)State;
                    MyMessageBox message = new MyMessageBox(this, "Предупреждение", $"Вы хотите удалить это турагенство ({cur.dataGridView1.SelectedRows.Count}), его аккаунт и все путевки?", "Да", "Нет", "Удаление_Агентства_Да", "Выход_Нет");
                    message.Show();
                }
                if (State.GetType() == typeof(OneHotel))
                {
                    OneHotel     cur     = (OneHotel)State;
                    MyMessageBox message = new MyMessageBox(this, "Предупреждение", $"Вы хотите удалить этот тип номера ({cur.dataGridView1.SelectedRows.Count})?", "Да", "Нет", "Удаление_Номера_Да", "Выход_Нет");
                    message.Show();
                }
                if (State.GetType() == typeof(OneVoucher))
                {
                    OneVoucher   cur     = (OneVoucher)State;
                    MyMessageBox message = new MyMessageBox(this, "Предупреждение", $"Вы хотите удалить эту составляющую путевки?", "Да", "Нет", "Удаление_Человека_Полета_Да", "Выход_Нет");
                    message.Show();
                }
                if (State.GetType() == typeof(Vouchers))
                {
                    Vouchers     cur     = (Vouchers)State;
                    MyMessageBox message = new MyMessageBox(this, "Предупреждение", $"Вы хотите удалить эту путевку ({cur.dataGridView1.SelectedRows.Count})?", "Да", "Нет", "Удаление_Путевки_Да", "Выход_Нет");
                    message.Show();
                }
                if (State.GetType() == typeof(Hotels))
                {
                    Hotels       cur     = (Hotels)State;
                    MyMessageBox message = new MyMessageBox(this, "Предупреждение", $"Вы хотите удалить этот отель ({cur.dataGridView1.SelectedRows.Count}) и все его путевки?", "Да", "Нет", "Удаление_Отеля_Да", "Выход_Нет");
                    message.Show();
                }
                if (State.GetType() == typeof(Routes))
                {
                    Routes       cur     = (Routes)State;
                    MyMessageBox message = new MyMessageBox(this, "Предупреждение", $"Вы хотите удалить этот рейс ({cur.dataGridView1.SelectedRows.Count}) и отменить все путевки по нем?", "Да", "Нет", "Удаление_Рейса_Да", "Выход_Нет");
                    message.Show();
                }
                if (State.GetType() == typeof(Accounts))
                {
                    Accounts cur = (Accounts)State;
                    int      i   = cur.dataGridView1.SelectedRows.Count;
                    i = Math.Max(i, cur.dataGridView2.SelectedRows.Count);
                    string str = $"Вы хотите удалить этот аккаунт ({i}), его тураегнтство и все путевки?";
                    if (cur.dataGridView2.SelectedRows.Count != 0)
                    {
                        str = $"Вы хотите удалить этот аккаунт ({i})?";
                    }
                    MyMessageBox message = new MyMessageBox(this, "Предупреждение", str, "Да", "Нет", "Удаление_Аккаунта_Да", "Выход_Нет");
                    message.Show();
                }
            }
            if (name == "Изменить")
            {
                if (State.GetType() == typeof(Agencies))
                {
                    Agencies      cur = (Agencies)State;
                    AddTouragency at  = new AddTouragency(this);
                    at.label4.Text          = "Edit Touragency";
                    at.Yes.Text             = "Изменить";
                    at.textBox0.Text        = cur.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                    at.comboBox1.Visible    = false;
                    at.textBox2.Visible     = true;
                    at.label8.Visible       = false;
                    at.textBox2.Text        = cur.dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                    at.textBox1.Text        = cur.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                    at.dateTimePicker1.Text = cur.dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                    at.textBox3.Text        = cur.dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
                    at.Show();
                }
                if (State.GetType() == typeof(Vouchers))
                {
                    DataGridViewRow cur = ((Vouchers)State).dataGridView1.SelectedRows[0];
                    AddVoucher      at  = new AddVoucher(this);
                    at.label4.Text            = "Edit Voucher";
                    at.Yes.Text               = "Изменить";
                    at.textBox2.Text          = cur.Cells[0].Value.ToString();
                    at.comboBox5.SelectedItem = cur.Cells[5].Value.ToString();
                    at.dateTimePicker1.Value  = Convert.ToDateTime(cur.Cells[3].Value.ToString());
                    c.Open();
                    string sql = $"SELECT Agency.Name, a.Name, aa.Name, Airport.Code, Airport.Name, h.Name, hh.Name" +
                                 $", Hotel.Name, Room.TypeRoom, Voucher.NumNights " +
                                 "FROM Agency, Country a, Country h, City aa, City hh, Airport, Hotel, Room, voucher " +
                                 $"WHERE Voucher.ID = '{cur.Cells[0].Value.ToString()}' AND Voucher.idTypeRoom = Room.ID AND Voucher.CodeAirport = Airport.Code " +
                                 "AND Airport.idCity = aa.ID AND aa.idCountry = a.ID AND Room.idHotel = Hotel.ID AND Hotel.idCity = hh.ID " +
                                 "AND hh.idCountry = h.ID AND Voucher.Login = Agency.Login";
                    MySqlCommand    command1 = new MySqlCommand(sql, c);
                    MySqlDataReader reader1  = command1.ExecuteReader();
                    reader1.Read();
                    at.comboBox8.SelectedItem = reader1[0].ToString();
                    at.comboBox7.SelectedItem = reader1[1].ToString();
                    at.comboBox6.SelectedItem = reader1[2].ToString();
                    at.comboBox9.SelectedItem = reader1[3].ToString() + $" ({reader1[4].ToString()})";
                    at.comboBox2.SelectedItem = reader1[5].ToString();
                    at.comboBox3.SelectedItem = reader1[6].ToString();
                    at.comboBox1.SelectedItem = reader1[7].ToString();
                    at.comboBox4.SelectedItem = reader1[8].ToString();
                    at.textBox1.Text          = reader1[9].ToString();
                    c.Close();
                    at.Show();
                }
                if (State.GetType() == typeof(OneHotel))
                {
                    OneHotel cur = (OneHotel)State;
                    AddRoom  at  = new AddRoom(this);
                    at.label4.Text   = "Edit Room";
                    at.Yes.Text      = "Изменить";
                    at.textBox1.Text = cur.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                    at.textBox2.Text = cur.dataGridView1.SelectedRows[0].Cells[2].Value.ToString().Split(' ')[0];
                    at.textBox3.Text = cur.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                    at.Show();
                }
                if (State.GetType() == typeof(Routes))
                {
                    AddRoute at = new AddRoute(this, false);
                    at.Show();
                }
                if (State.GetType() == typeof(Accounts))
                {
                    Accounts cur = (Accounts)State;
                    string   p   = "";
                    if (cur.dataGridView1.SelectedRows.Count != 0)
                    {
                        p = cur.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                    }
                    else
                    {
                        p = cur.dataGridView2.SelectedRows[0].Cells[0].Value.ToString();
                    }
                    AddAccount at = new AddAccount(new AddTouragency(this), new User(p));
                    at.label4.Text = "Edit Account";
                    at.Yes.Text    = "Изменить";
                    if (cur.dataGridView1.SelectedRows.Count != 0)
                    {
                        at.textBox0.Text     = cur.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                        at.comboBox1.Visible = false;
                        at.textBox2.Visible  = true;
                        at.textBox1.Text     = cur.dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                        at.Show();
                    }
                    else
                    {
                        at.textBox0.Text     = cur.dataGridView2.SelectedRows[0].Cells[0].Value.ToString();
                        at.comboBox1.Visible = false;
                        at.textBox2.Visible  = true;
                        at.textBox2.Text     = "Администратор";
                        at.textBox1.Text     = cur.dataGridView2.SelectedRows[0].Cells[1].Value.ToString();
                        at.Show();
                    }
                }
                if (State.GetType() == typeof(Hotels))
                {
                    Hotels   cur = (Hotels)State;
                    AddHotel at  = new AddHotel(this);
                    at.label4.Text   = "Edit Hotel";
                    at.Yes.Text      = "Изменить";
                    at.textBox0.Text = cur.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                    at.textBox1.Text = cur.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                    string str = cur.dataGridView1.SelectedRows[0].Cells[2].Value.ToString();

                    switch (str)
                    {
                    case "RO":
                        str = "RO - Room Only";
                        break;

                    case "BB":
                        str = "BB - Bed & Breakfast";
                        break;

                    case "HB":
                        str = "HB - Half Board";
                        break;

                    case "FB":
                        str = "FB - Full Board";
                        break;

                    case "AI":
                        str = "AI - All Inclusive";
                        break;

                    case "UAI":
                        str = "UAI - Ultra All Inclusive";
                        break;
                    }
                    at.comboBox1.Text         = str;
                    at.comboBox2.SelectedItem = cur.dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
                    at.comboBox3.SelectedItem = cur.dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                    at.ID = int.Parse(cur.dataGridView1.SelectedRows[0].Cells[5].Value.ToString());
                    at.Show();
                }
            }
            if (name == "Добавить")
            {
                if (State.GetType() == typeof(Agencies))
                {
                    Agencies      cur = (Agencies)State;
                    AddTouragency at  = new AddTouragency(this);

                    at.Show();
                }
                if (State.GetType() == typeof(OneHotel))
                {
                    OneHotel cur = (OneHotel)State;
                    AddRoom  at  = new AddRoom(this);

                    at.Show();
                }
                if (State.GetType() == typeof(Accounts))
                {
                    Accounts   acc = (Accounts)State;
                    AddAccount aa  = new AddAccount(new AddTouragency(this));
                    aa.Show();
                }
                if (State.GetType() == typeof(Hotels))
                {
                    Hotels   acc = (Hotels)State;
                    AddHotel aa  = new AddHotel(this);
                    aa.Show();
                }
                if (State.GetType() == typeof(Routes))
                {
                    Routes   acc = (Routes)State;
                    AddRoute aa  = new AddRoute(this);
                    aa.Show();
                }
                if (State.GetType() == typeof(Vouchers))
                {
                    AddVoucher aa = new AddVoucher(this);
                    aa.Show();
                }
            }
            if (name == "Фильтр")
            {
                if (State.GetType() == typeof(Agencies))
                {
                    string SQL1 = "SELECT Max(comission) FROM Agency";
                    string SQL2 = "SELECT Min(comission) FROM Agency";
                    string SQL3 = "SELECT Max(dateLicense) FROM Agency";
                    string SQL4 = "SELECT Min(dateLicense) FROM Agency";
                    int    maxc = 0;
                    c.Open();
                    MySqlCommand    command = new MySqlCommand(SQL1, c);
                    MySqlDataReader reader  = command.ExecuteReader();
                    while (reader.Read())
                    {
                        maxc = Convert.ToInt32(reader[0]);
                    }
                    c.Close();
                    Agencies     cur    = (Agencies)State;
                    FilterAgency filter = new FilterAgency(this);
                    int          minc   = 0;
                    c.Open();
                    MySqlCommand    command1 = new MySqlCommand(SQL2, c);
                    MySqlDataReader reader1  = command1.ExecuteReader();
                    while (reader1.Read())
                    {
                        minc = Convert.ToInt32(reader1[0]);
                    }
                    c.Close();
                    DateTime maxd = new DateTime();
                    c.Open();
                    MySqlCommand    command2 = new MySqlCommand(SQL3, c);
                    MySqlDataReader reader2  = command2.ExecuteReader();
                    while (reader2.Read())
                    {
                        maxd = Convert.ToDateTime(reader2[0]);
                    }
                    c.Close();
                    DateTime mind = new DateTime();
                    c.Open();
                    MySqlCommand    command3 = new MySqlCommand(SQL4, c);
                    MySqlDataReader reader3  = command3.ExecuteReader();
                    while (reader3.Read())
                    {
                        mind = Convert.ToDateTime(reader3[0]);
                    }
                    c.Close();
                    filter.textBox3.Text         = minc.ToString();
                    filter.textBox4.Text         = maxc.ToString();
                    filter.dateTimePicker1.Value = mind;
                    filter.dateTimePicker2.Value = maxd;
                    filter.Show();
                }
                if (State.GetType() == typeof(Hotels))
                {
                    Hotels   acc = (Hotels)State;
                    AddHotel aa  = new AddHotel(this);
                    aa.label4.Text     = "Filter";
                    aa.Yes.Visible     = false;
                    aa.No.Visible      = false;
                    aa.button1.Visible = true;
                    aa.label7.Visible  = false;
                    aa.label8.Visible  = false;
                    aa.Show();
                }
                if (State.GetType() == typeof(Routes))
                {
                    Routes      acc = (Routes)State;
                    FilterRoute aa  = new FilterRoute(this);
                    aa.label4.Text = "Filter";


                    aa.Show();
                }
            }
            if (name == "Выполнить")
            {
                if (State.GetType() == typeof(SQLQuery))
                {
                    SQLQuery sq = (SQLQuery)State;
                    c.Open();
                    MySqlCommand    command = new MySqlCommand(sq.richTextBox1.Text, c);
                    MySqlDataReader reader  = command.ExecuteReader();
                    sq.dataGridView1.Rows.Clear();
                    sq.dataGridView1.Columns.Clear();
                    for (int i = 0; i < reader.VisibleFieldCount; i++)
                    {
                        DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
                        column.Name       = "column" + i;
                        column.HeaderText = reader.GetName(i);
                        column.Width      = (sq.dataGridView1.Width - 35) / reader.VisibleFieldCount;
                        sq.dataGridView1.Columns.Add(column);
                    }
                    while (reader.Read())
                    {
                        int num = sq.dataGridView1.Rows.Add();
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            sq.dataGridView1.Rows[num].Cells[i].Value = reader[i];
                            if (reader[i].GetType() == typeof(DateTime))
                            {
                                DateTime dt = Convert.ToDateTime(reader[i]);
                                if (dt.Hour == 0 && dt.Minute == 0 && dt.Second == 0)
                                {
                                    sq.dataGridView1.Rows[num].Cells[i].Value = dt.ToShortDateString();
                                }
                            }
                        }
                    }
                    c.Close();
                }
            }
            if (name == "Очистить")
            {
                if (State.GetType() == typeof(SQLQuery))
                {
                    SQLQuery sq = (SQLQuery)State;
                    sq.richTextBox1.Text            = "SELECT";
                    sq.richTextBox1.SelectionStart  = 6;
                    sq.richTextBox1.SelectionLength = 0;
                }
            }
            if (name == "Справка")
            {
                if (State.GetType() == typeof(SQLQuery))
                {
                    Help h = new Help();
                    h.Show();
                }
            }
            if (name == "Просмотр")
            {
                if (State.GetType() == typeof(Hotels))
                {
                    Hotels h = (Hotels)State;
                    Controls.Remove(State);
                    OneHotel ag = new OneHotel(this, new Hotel(Convert.ToInt32(h.dataGridView1.SelectedRows[0].Cells[5].Value)));
                    State = ag;
                    this.Controls.Add(ag);
                    ag.Location = new Point(panel3.Location.X + panel3.Size.Width, panel3.Location.Y + panel3.Size.Height + PanelForm.Size.Height);
                    ag.Visible  = true;
                    ag.Show();
                }
                if (State.GetType() == typeof(Agencies))
                {
                    Agencies h = (Agencies)State;
                    Controls.Remove(State);
                    OneAgency ag = new OneAgency(this, new Touragency(h.dataGridView1.SelectedRows[0].Cells[2].Value.ToString()));
                    State = ag;
                    this.Controls.Add(ag);
                    ag.Location = new Point(panel3.Location.X + panel3.Size.Width, panel3.Location.Y + panel3.Size.Height + PanelForm.Size.Height);
                    ag.Visible  = true;
                    ag.Show();
                }
                if (State.GetType() == typeof(Vouchers))
                {
                    Vouchers   h  = (Vouchers)State;
                    OneVoucher ag = new OneVoucher(this);
                    Controls.Remove(State);

                    State = ag;
                    this.Controls.Add(ag);
                    ag.Location = new Point(panel3.Location.X + panel3.Size.Width, panel3.Location.Y + panel3.Size.Height + PanelForm.Size.Height);
                    ag.Visible  = true;
                    ag.Show();
                }
            }
            if (name == "Обновить")
            {
                if (State.GetType() == typeof(Routes))
                {
                    UpdateRoutes u = new UpdateRoutes();
                    u.Show();
                }
                if (State.GetType() == typeof(Agencies))
                {
                    UpdateRoutes u = new UpdateRoutes(this, 1);
                    u.Show();
                }
            }
            if (name == "Отчет")
            {
                if (State.GetType() == typeof(OneAgency))
                {
                    OneAgency a        = (OneAgency)State;
                    var       document = new iTextSharp.text.Document();
                    using (var writer = PdfWriter.GetInstance(document, new FileStream("ReportTourAgency.pdf", FileMode.Create)))
                    {
                        document.Open();

                        BaseFont             baseFont = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                        iTextSharp.text.Font font     = new iTextSharp.text.Font(baseFont, 20, 0);


                        document.Add(new Paragraph($"{a.label1.Text}", new iTextSharp.text.Font(baseFont, 30, 0)));
                        document.Add(new Paragraph($"         ", new iTextSharp.text.Font(baseFont, 10, 0)));
                        iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;

                        cb.MoveTo(30, 745);
                        cb.LineTo(560, 745);
                        cb.Stroke();

                        document.Add(new Paragraph($"{a.label2.Text}", font));
                        document.Add(new Paragraph($"{a.label4.Text}", font));
                        document.Add(new Paragraph($"{a.label3.Text}", font));
                        document.Add(new Paragraph($"{a.label6.Text}", font));
                        document.Add(new Paragraph($"         ", new iTextSharp.text.Font(baseFont, 3, 0)));
                        DataGridView d    = a.dataGridView1;
                        int          sum  = 0;
                        int          suma = 0;
                        int          sumb = 0;
                        for (int i = 0; i < d.Rows.Count; i++)
                        {
                            if (d.Rows[i].Cells[4].Value.ToString() == "Выполнено" || d.Rows[i].Cells[4].Value.ToString() == "В процессе" || d.Rows[i].Cells[4].Value.ToString() == "Оплачено")
                            {
                                if (DateTime.Now <= Convert.ToDateTime(d.Rows[i].Cells[2].Value.ToString()).AddYears(1))
                                {
                                    if (DateTime.Now <= Convert.ToDateTime(d.Rows[i].Cells[2].Value.ToString()).AddMonths(1))
                                    {
                                        sumb += Convert.ToInt32(d.Rows[i].Cells[3].Value);
                                    }
                                    suma += Convert.ToInt32(d.Rows[i].Cells[3].Value);
                                }
                                sum += Convert.ToInt32(d.Rows[i].Cells[3].Value);
                            }
                        }
                        document.Add(new Paragraph($"Прибыль от турагентства за все время: {sum}$", font));
                        document.Add(new Paragraph($"Прибыль от турагентства за месяц: {sumb}$", font));
                        document.Add(new Paragraph($"Прибыль от турагентства за год: {suma}$", font));

                        bool t = false;
                        for (int i = 0; i < d.Rows.Count; i++)
                        {
                            if (d.Rows[i].Cells[4].Value.ToString() == "Забронировано")
                            {
                                if (!t)
                                {
                                    document.Add(new Paragraph($"К оплате:", font));
                                    t = true;
                                }
                                document.Add(new Paragraph($"    Путевка №{d.Rows[i].Cells[0].Value.ToString()} - {d.Rows[i].Cells[3].Value.ToString()}$ ", font));
                            }
                        }
                        document.Add(new Paragraph($" ", font));
                        document.Add(new Paragraph($" ", font));

                        document.Add(new Paragraph("Дата создания отчета: " + DateTime.Now.ToString(), new iTextSharp.text.Font(baseFont, 10, 0)));
                        document.Close();
                        writer.Close();
                        ReportPDF r = new ReportPDF(true);
                    }
                }
                if (State.GetType() == typeof(OneVoucher))
                {
                    OneVoucher a        = (OneVoucher)State;
                    var        document = new Document();
                    using (var writer = PdfWriter.GetInstance(document, new FileStream("ReportVoucher.pdf", FileMode.Create)))
                    {
                        document.Open();

                        BaseFont             baseFont = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                        iTextSharp.text.Font font     = new iTextSharp.text.Font(baseFont, 20, 0);


                        document.Add(new Paragraph($"{a.label1.Text}", new iTextSharp.text.Font(baseFont, 30, 0)));
                        document.Add(new Paragraph($"         ", new iTextSharp.text.Font(baseFont, 10, 0)));
                        iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;

                        cb.MoveTo(30, 745);
                        cb.LineTo(560, 745);
                        cb.Stroke();

                        document.Add(new Paragraph($"{a.label4.Text}", font));
                        document.Add(new Paragraph($"{a.label6.Text}", font));
                        document.Add(new Paragraph($"{a.label3.Text}", font));
                        document.Add(new Paragraph($"{a.label8.Text}", font));
                        document.Add(new Paragraph($"{a.label7.Text}", font));
                        document.Add(new Paragraph($"{a.label2.Text}", font));
                        document.Add(new Paragraph($"Перелеты: ", font));
                        document.Add(new Paragraph($"            ", font));
                        PdfPTable table = new PdfPTable(4);
                        for (int g = 0; g < 4; g++)
                        {
                            table.AddCell(new Paragraph($"{a.dataGridView2.Columns[g].HeaderText}", new iTextSharp.text.Font(baseFont, 10, 0)));
                        }
                        for (int g = 0; g < a.dataGridView2.Rows.Count; g++)
                        {
                            for (int s = 0; s < a.dataGridView2.Rows[g].Cells.Count - 1; s++)
                            {
                                table.AddCell(new Paragraph($"{a.dataGridView2.Rows[g].Cells[s].Value.ToString()}", new iTextSharp.text.Font(baseFont, 10, 0)));
                            }
                        }
                        document.Add(table);
                        document.Add(new Paragraph($"Люди: ", font));
                        document.Add(new Paragraph($"            ", font));
                        PdfPTable table1 = new PdfPTable(6);
                        for (int g = 0; g < 6; g++)
                        {
                            table1.AddCell(new Paragraph($"{a.dataGridView1.Columns[g].HeaderText}", new iTextSharp.text.Font(baseFont, 10, 0)));
                        }
                        for (int g = 0; g < a.dataGridView1.Rows.Count; g++)
                        {
                            for (int s = 0; s < a.dataGridView1.Rows[g].Cells.Count; s++)
                            {
                                table1.AddCell(new Paragraph($"{a.dataGridView1.Rows[g].Cells[s].Value.ToString()}", new iTextSharp.text.Font(baseFont, 10, 0)));
                            }
                        }
                        document.Add(table1);
                        document.Add(new Paragraph($" ", font));
                        document.Add(new Paragraph($" ", font));

                        document.Add(new Paragraph("Дата создания отчета: " + DateTime.Now.ToString(), new iTextSharp.text.Font(baseFont, 10, 0)));

                        document.Close();
                        writer.Close();
                        ReportPDF r = new ReportPDF(false);
                    }
                }
            }
        }
コード例 #5
0
        private void ButtonHome1_Click(object sender, EventArgs e)
        {
            string name = "";

            try
            {
                Panel p = (Panel)sender;
                name = f.GetNameOfButton(p);
            }
            catch { }
            try
            {
                Label l = (Label)sender;
                name = l.Text;
            }
            catch { }
            try
            {
                PictureBox pb = (PictureBox)sender;
                name = f.GetNameOfButton(panel1, pb);
            }
            catch { }
            if (name != "")
            {
                if (name != "Выход")
                {
                    for (int i = 0; i < panel1.Controls.Count; i++)
                    {
                        if (panel1.Controls[i].GetType() == typeof(Panel))
                        {
                            for (int j = 0; j < panel1.Controls[i].Controls.Count; j++)
                            {
                                if (panel1.Controls[i].Controls[j].GetType() == typeof(Panel))
                                {
                                    panel1.Controls[i].Controls[j].Visible = false;
                                }
                            }
                        }
                    }
                }
                if (name == "Турагентства")
                {
                    Controls.Remove(State);
                    Agencies ag = new Agencies(this);
                    State = ag;
                    this.Controls.Add(ag);
                    ag.Location = new Point(panel3.Location.X + panel3.Size.Width, panel3.Location.Y + panel3.Size.Height + PanelForm.Size.Height);
                    ag.Visible  = true;
                    ag.Show();
                    panel4.Visible = true;
                }
                if (name == "Турагентство")
                {
                    Controls.Remove(State);

                    OneAgency ag = new OneAgency(this, new Touragency(User.Login));
                    State = ag;
                    this.Controls.Add(ag);
                    ag.Location = new Point(panel3.Location.X + panel3.Size.Width, panel3.Location.Y + panel3.Size.Height + PanelForm.Size.Height);
                    ag.Visible  = true;
                    ag.Show();
                    panel4.Visible = true;
                }
                if (name == "SQL запросы")
                {
                    Controls.Remove(State);
                    SQLQuery sq = new SQLQuery(this);
                    State = sq;
                    this.Controls.Add(sq);
                    sq.Location = new Point(panel3.Location.X + panel3.Size.Width, panel3.Location.Y + panel3.Size.Height + PanelForm.Size.Height);
                    sq.Visible  = true;
                    sq.Show();
                    panel17.Visible = true;
                }
                if (name == "Отели")
                {
                    Controls.Remove(State);
                    Hotels a = new Hotels(this);
                    State = a;
                    this.Controls.Add(a);
                    a.Location = new Point(panel3.Location.X + panel3.Size.Width, panel3.Location.Y + panel3.Size.Height + PanelForm.Size.Height);
                    a.Visible  = true;
                    a.Show();
                    panel14.Visible = true;
                }
                if (name == "Авиарейсы")
                {
                    Controls.Remove(State);
                    Routes a = new Routes(this);
                    State = a;
                    this.Controls.Add(a);
                    a.Location = new Point(panel3.Location.X + panel3.Size.Width, panel3.Location.Y + panel3.Size.Height + PanelForm.Size.Height);
                    a.Visible  = true;
                    a.Show();
                    panel15.Visible = true;
                }
                if (name == "Аккаунты")
                {
                    Controls.Remove(State);
                    Accounts a = new Accounts(this);
                    State = a;
                    this.Controls.Add(a);
                    a.Location = new Point(panel3.Location.X + panel3.Size.Width, panel3.Location.Y + panel3.Size.Height + PanelForm.Size.Height);
                    a.Visible  = true;
                    a.Show();
                    panel16.Visible = true;
                }
                if (name == "Путевки")
                {
                    Controls.Remove(State);
                    Vouchers a = new Vouchers(this);
                    State = a;
                    this.Controls.Add(a);
                    a.Location = new Point(panel3.Location.X + panel3.Size.Width, panel3.Location.Y + panel3.Size.Height + PanelForm.Size.Height);
                    a.Visible  = true;
                    a.Show();
                    panel12.Visible = true;
                }
                if (name == "Поиск")
                {
                    Controls.Remove(State);
                    SearchVouchers a = new SearchVouchers(this);
                    State = a;

                    this.Controls.Add(a);
                    a.BringToFront();
                    a.Location = new Point(panel3.Location.X + panel3.Size.Width, panel3.Location.Y + panel3.Size.Height + PanelForm.Size.Height - 84);
                    a.Visible  = true;
                    a.Show();
                    panel13.Visible = true;
                }
                if (name == "Выход")
                {
                    MyMessageBox message = new MyMessageBox(this, "Предупреждение", "Выйти из аккаунта?", "Да", "Нет", "Выход_Да", "Выход_Нет");
                    message.Show();
                }
            }
        }
コード例 #6
0
        private void Yes_Click(object sender, EventArgs e)
        {
            if (Yes.Text == "Добавить")
            {
                string airport1 = "";
                string airport2 = "";
                if (comboBox4.Text != "" && comboBox1.Text != "")
                {
                    airport1 = comboBox4.Text.Substring(0, 3);
                    airport2 = comboBox1.Text.Substring(0, 3);
                }
                string airline = "";
                if (comboBox6.Text != "")
                {
                    string SQL2 = $"SELECT Airline.Code FROM Airline WHERE Airline.Name = '{comboBox6.Text}'";
                    c.Open();
                    MySqlCommand    command2 = new MySqlCommand(SQL2, c);
                    MySqlDataReader reader2  = command2.ExecuteReader();
                    reader2.Read();
                    airline = reader2[0].ToString();
                }
                c.Close();
                string num     = textBox0.Text;
                string timedep = numericUpDown2.Value.ToString() + '-' + numericUpDown1.Value.ToString();
                string timefly = numericUpDown3.Value.ToString() + '-' + numericUpDown4.Value.ToString();
                string plane   = textBox1.Text;
                string places  = textBox2.Text;
                string price   = textBox3.Text;
                string days    = "";
                if (checkBox3.Checked)
                {
                    days += "1,";
                }
                if (checkBox1.Checked)
                {
                    days += "2,";
                }
                if (checkBox2.Checked)
                {
                    days += "3,";
                }
                if (checkBox4.Checked)
                {
                    days += "4,";
                }
                if (checkBox5.Checked)
                {
                    days += "5,";
                }
                if (checkBox6.Checked)
                {
                    days += "6,";
                }
                if (checkBox7.Checked)
                {
                    days += "7,";
                }
                if (days != "")
                {
                    days = days.Substring(0, days.Length - 1);
                }
                string SQL = $"INSERT INTO Route (Price, RouteNum, CodeAirline, CodeAirportDeparture, CodeAirportArrive, Plane, NumPlace, TimeFlight, TimeDeparture, days) " +
                             $"VALUES('{price}','{num}','{airline}','{airport1}','{airport2}' ,'{plane}',{places},STR_TO_DATE('{timefly}','%H-%i'),STR_TO_DATE('{timedep}','%H-%i'),{days})";
                if (days != "" && price != "" && places != "" && plane != "" && num != "" && airline != "" && airport1 != "" && airport2 != "")
                {
                    if (airport1 != airport2)
                    {
                        string SQL3 = $"SELECT Route.RouteNum FROM Route WHERE Route.RouteNum = '{textBox0.Text}'";
                        c.Open();
                        MySqlCommand    command3 = new MySqlCommand(SQL3, c);
                        MySqlDataReader reader3  = command3.ExecuteReader();
                        int             i        = 0;
                        while (reader3.Read())
                        {
                            i++;
                        }
                        c.Close();
                        if (i == 0)
                        {
                            c.Open();
                            MySqlCommand com = new MySqlCommand(SQL, c);
                            com.ExecuteNonQuery();
                            c.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();
                }
                c.Open();
                string          sql     = "SELECT Route.RouteNum, Airline.Name , Route.CodeAirportDeparture, Route.CodeAirportArrive, Route.TimeDeparture, Route.days, Route.Price FROM Route, Airline WHERE Route.CodeAirline = Airline.Code";
                MySqlCommand    command = new MySqlCommand(sql, c);
                MySqlDataReader reader  = command.ExecuteReader();
                Routes          r       = (Routes)Form.State;
                f.CreateDataGridView(r.dataGridView1, reader);
                c.Close();
                Close();
            }
            else
            {
                string airport1 = "";
                string airport2 = "";
                if (comboBox4.Text != "" && comboBox1.Text != "")
                {
                    airport1 = comboBox4.Text.Substring(0, 3);
                    airport2 = comboBox1.Text.Substring(0, 3);
                }
                string airline = "";
                if (comboBox6.Text != "")
                {
                    string SQL2 = $"SELECT Airline.Code FROM Airline WHERE Airline.Name = '{comboBox6.Text}'";
                    c.Open();
                    MySqlCommand    command2 = new MySqlCommand(SQL2, c);
                    MySqlDataReader reader2  = command2.ExecuteReader();
                    reader2.Read();
                    airline = reader2[0].ToString();
                }
                c.Close();
                string num     = textBox0.Text;
                string timedep = numericUpDown2.Value.ToString() + '-' + numericUpDown1.Value.ToString();
                string timefly = numericUpDown3.Value.ToString() + '-' + numericUpDown4.Value.ToString();
                string plane   = textBox1.Text;
                string places  = textBox2.Text;
                string price   = textBox3.Text;
                string days    = "";
                if (checkBox3.Checked)
                {
                    days += "1,";
                }
                if (checkBox1.Checked)
                {
                    days += "2,";
                }
                if (checkBox2.Checked)
                {
                    days += "3,";
                }
                if (checkBox4.Checked)
                {
                    days += "4,";
                }
                if (checkBox5.Checked)
                {
                    days += "5,";
                }
                if (checkBox6.Checked)
                {
                    days += "6,";
                }
                if (checkBox7.Checked)
                {
                    days += "7,";
                }
                if (days != "")
                {
                    days = days.Substring(0, days.Length - 1);
                }
                string SQL = $"UPDATE Route SET Price = '{price}', CodeAirline = '{airline}'" +
                             $", CodeAirportDeparture = '{airport1}', CodeAirportArrive = '{airport2}'," +
                             $" Plane = '{plane}', NumPlace = '{places}', TimeFlight = STR_TO_DATE('{timefly}','%H-%i')" +
                             $", TimeDeparture = STR_TO_DATE('{timedep}','%H-%i'), days = '{days}' WHERE RouteNum = '{num}'";

                if (days != "" && price != "" && places != "" && plane != "" && num != "" && airline != "" && airport1 != "" && airport2 != "")
                {
                    if (airport1 != airport2)
                    {
                        c.Open();
                        MySqlCommand com = new MySqlCommand(SQL, c);
                        com.ExecuteNonQuery();
                        c.Close();
                    }
                    else
                    {
                        MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Нельзя создать рейс с одним аэропортом отбытия и прибытия", "ОК", "", "ОК", "");
                        mmb.Show();
                    }
                }
                else
                {
                    MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Введите значение", "ОК", "", "ОК", "");
                    mmb.Show();
                }
                c.Open();
                string          sql     = "SELECT Route.RouteNum, Airline.Name , Route.CodeAirportDeparture, Route.CodeAirportArrive, Route.TimeDeparture, Route.days, Route.Price FROM Route, Airline WHERE Route.CodeAirline = Airline.Code";
                MySqlCommand    command = new MySqlCommand(sql, c);
                MySqlDataReader reader  = command.ExecuteReader();
                Routes          r       = (Routes)Form.State;
                f.CreateDataGridView(r.dataGridView1, reader);
                c.Close();
                Close();
            }
        }
コード例 #7
0
        private void Yes_Click(object sender, EventArgs e)
        {
            if (Yes.Text == "Добавить")
            {
                if (textBox1.Text != "" && textBox2.Text != "")
                {
                    int idHotel = ((OneHotel)Form.State).Hotel.ID;
                    int i       = 1;
                    c.Open();
                    string          sql     = "SELECT ID FROM Room ORDER BY ID ASC";
                    MySqlCommand    command = new MySqlCommand(sql, c);
                    MySqlDataReader reader  = command.ExecuteReader();
                    while (reader.Read())
                    {
                        if (i != Convert.ToInt32(reader[0]))
                        {
                            break;
                        }
                        i++;
                    }
                    c.Close();
                    string SQL = $"INSERT INTO Room (id, idHotel, price, NumPerson, TypeRoom) VALUES('{i}', '{idHotel}', '{textBox2.Text}', '{textBox3.Text}','{textBox1.Text}')";
                    c.Open();
                    MySqlCommand com = new MySqlCommand(SQL, c);
                    com.ExecuteNonQuery();
                    c.Close();
                    c.Open();
                    string          sql1     = $"SELECT TypeRoom, NumPerson, Price, id FROM Room WHERE idHotel = {idHotel}";
                    MySqlCommand    command1 = new MySqlCommand(sql1, c);
                    MySqlDataReader reader1  = command1.ExecuteReader();
                    f.CreateDataGridView(((OneHotel)Form.State).dataGridView1, reader1);
                    c.Close();
                    Close();
                }
                else
                {
                    MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Введите значение", "ОК", "", "ОК", "");
                    mmb.Show();
                }
            }
            else
            {
                if (textBox1.Text != "" && textBox2.Text != "")
                {
                    int idHotel = ((OneHotel)Form.State).Hotel.ID;

                    string SQL = $"UPDATE Room SET TypeRoom = '{textBox1.Text}', NumPerson = '{textBox3.Text}', price = '{textBox2.Text}' WHERE ID = '{((OneHotel)Form.State).dataGridView1.SelectedRows[0].Cells[3].Value.ToString()}'";
                    c.Open();
                    MySqlCommand com = new MySqlCommand(SQL, c);
                    com.ExecuteNonQuery();
                    c.Close();
                    c.Open();
                    string          sql1     = $"SELECT TypeRoom, NumPerson, Price, id FROM Room WHERE idHotel = {idHotel}";
                    MySqlCommand    command1 = new MySqlCommand(sql1, c);
                    MySqlDataReader reader1  = command1.ExecuteReader();
                    f.CreateDataGridView(((OneHotel)Form.State).dataGridView1, reader1);
                    c.Close();
                    Close();
                }
                else
                {
                    MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Введите значение", "ОК", "", "ОК", "");
                    mmb.Show();
                }
            }
        }
コード例 #8
0
 private void Yes_Click(object sender, EventArgs e)
 {
     if (Yes.Text == "Добавить")
     {
         bool res = true;
         if (textBox0.Text.Length < 8)
         {
             res            = false;
             label9.Visible = true;
         }
         if (comboBox1.Text == "")
         {
             label10.Visible = true;
             res             = false;
         }
         if (textBox1.Text.Length < 8)
         {
             res            = false;
             label1.Visible = true;
         }
         if (Convert.ToDateTime(dateTimePicker1.Value) > DateTime.Now)
         {
             res             = false;
             label12.Visible = true;
         }
         if (res)
         {
             string SQL = $"INSERT INTO Agency (login, name, director, dateLicense, comission) VALUES('{comboBox1.Text}', '{textBox0.Text}', '{textBox1.Text}','{dateTimePicker1.Value.Year}-{dateTimePicker1.Value.Month}-{dateTimePicker1.Value.Day}','10')";
             c.Open();
             MySqlCommand com = new MySqlCommand(SQL, c);
             com.ExecuteNonQuery();
             string          sql     = "SELECT Name, Director,Login, DateLicense, Comission FROM Agency";
             MySqlCommand    command = new MySqlCommand(sql, c);
             MySqlDataReader reader  = command.ExecuteReader();
             Agencies        ag      = (Agencies)Form.State;
             f.CreateDataGridView(ag.dataGridView1, reader);
             c.Close();
             Close();
         }
     }
     if (Yes.Text == "Изменить")
     {
         bool res = true;
         if (textBox0.Text.Length < 8)
         {
             res            = false;
             label9.Visible = true;
         }
         if (textBox1.Text.Length < 8)
         {
             res            = false;
             label1.Visible = true;
         }
         if (Convert.ToDateTime(dateTimePicker1.Value) > DateTime.Now)
         {
             res             = false;
             label12.Visible = true;
         }
         if (res)
         {
             MyMessageBox mb = new MyMessageBox(this, "Предупреждение", "Изменить агентство?", "Да", "Нет", "Изменить_Агентство_Да", "Выход_Нет");
             mb.Show();
         }
     }
 }
コード例 #9
0
        private void Yes_Click(object sender, EventArgs e)
        {
            string pas  = textBox0.Text;
            string apas = textBox1.Text;
            string inn  = textBox2.Text;
            string name = textBox3.Text;
            string sur  = textBox4.Text;
            string nat  = comboBox2.Text;
            string date = dateTimePicker1.Value.ToShortDateString().Replace('.', '-');
            int    sex  = -1;

            if (comboBox1.Text == "")
            {
            }
            else
            {
                if (comboBox1.Text[0] == 'М')
                {
                    sex = 1;
                }
                if (comboBox1.Text[0] == 'Ж')
                {
                    sex = 0;
                }
            }

            if (pas != "" && apas != "" && inn != "" && name != "" && sur != "" && nat != "" && sex != -1)
            {
                c.Open();
                string          sql1     = $"SELECT ID FROM Country WHERE Name ='{nat}' ";
                MySqlCommand    command1 = new MySqlCommand(sql1, c);
                MySqlDataReader reader1  = command1.ExecuteReader();
                reader1.Read();
                int cou = Convert.ToInt32(reader1[0]);
                c.Close();
                bool t = false;
                c.Open();
                sql1     = $"SELECT Passport FROM People WHERE passport ='{pas}' ";
                command1 = new MySqlCommand(sql1, c);
                reader1  = command1.ExecuteReader();
                while (reader1.Read())
                {
                    t = true;
                }
                c.Close();
                if (t)
                {
                    c.Open();
                    string sql = $"UPDATE People SET abroadPassport='{apas}', INN = '{inn}', name = '{name}', " +
                                 $"surname ='{sur}', idNational ='{cou}', sex = '{sex}', birthday = STR_TO_DATE('{date}','%d-%m-%Y') " +
                                 $"WHERE passport={pas}";
                    MySqlCommand command = new MySqlCommand(sql, c);
                    command.ExecuteNonQuery();
                    c.Close();
                }
                else
                {
                    c.Open();
                    string sql = $"INSERT INTO People (passport, abroadPassport, inn, name, surname, sex, idNational, birthday) " +
                                 $"VALUES ('{pas}','{apas}','{inn}','{name}','{sur}','{sex}','{cou}', STR_TO_DATE('{date}','%d-%m-%Y'))";
                    MySqlCommand command = new MySqlCommand(sql, c);
                    command.ExecuteNonQuery();
                    c.Close();
                }
                c.Open();
                sql1     = $"SELECT idVoucher FROM VoucherPeople WHERE passport ='{pas}' AND idVoucher = '{ID}' ";
                command1 = new MySqlCommand(sql1, c);
                reader1  = command1.ExecuteReader();
                bool h = false;
                while (reader1.Read())
                {
                    h = true;
                }
                c.Close();
                if (!h)
                {
                    c.Open();
                    string sql = $"INSERT INTO VoucherPeople (passport, idVoucher) " +
                                 $"VALUES ('{pas}','{ID}')";
                    MySqlCommand command = new MySqlCommand(sql, c);
                    command.ExecuteNonQuery();
                    c.Close();
                }

                string sql10 = $"SELECT People.Surname, People.Name, People.Passport, People.Birthday, People.Sex, Country.Name " +
                               $"FROM People, Voucherpeople, Country " +
                               $"WHERE People.IdNational=Country.ID AND People.Passport = Voucherpeople.passport AND Voucherpeople.idVoucher ='{ID}' ";
                c.Open();
                MySqlCommand    comm10   = new MySqlCommand(sql10, c);
                MySqlDataReader reader10 = comm10.ExecuteReader();
                f.CreateDataGridView(((OneVoucher)Form.State).dataGridView1, reader10);
                c.Close();
                Close();
            }
            else
            {
                MyMessageBox mmb = new MyMessageBox(Form, "Ошибка", "Введите значение", "ОК", "", "ОК", "");
                mmb.Show();
            }
        }
コード例 #10
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();
            }
        }
コード例 #11
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();
            }
        }
コード例 #12
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();
     }
 }