Esempio n. 1
0
        private void TextBoxLogin_TextChanged(object sender, EventArgs e)
        {
            Class.HashMD5 HMD5     = new Class.HashMD5();
            string        LoginMD5 = HMD5.GetHashString(textBoxLogin.Text); //хеширование логина

            string       checkLogin    = "******" + LoginMD5 + "'";
            MySqlCommand cmdCheckLogin = new MySqlCommand(checkLogin, connect);

            connect.Open();
            cmdCheckLogin.Prepare();
            int countLogin = Convert.ToInt32(cmdCheckLogin.ExecuteScalar());

            if (countLogin == 0 && textBoxLogin.Text != "")
            {
                labelErrorLogin.Show();
                labelErrorLogin.ForeColor  = Color.FromArgb(12, 165, 47);
                labelErrorLogin.Text       = "Ок";
                buttonRegistration.Enabled = true;
                connect.Close();
            }
            else
            {
                buttonRegistration.Enabled = false;
                labelErrorLogin.Text       = "Логин занят";
                labelErrorLogin.ForeColor  = Color.FromArgb(128, 0, 0);
                connect.Close();
            }
        }
Esempio n. 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            connect.Open();
            Class.HashMD5 HMD5     = new Class.HashMD5();
            string        LoginMD5 = HMD5.GetHashString(Settings.Default["Login"].ToString());


            string       Dday      = "SELECT Day FROM ditetimepicker";
            string       Mmonth    = "SELECT Month FROM ditetimepicker";
            MySqlCommand cmdDday   = new MySqlCommand(Dday, connect);
            MySqlCommand cmdMmonth = new MySqlCommand(Mmonth, connect);

            int DdayInt   = Convert.ToInt32(cmdDday.ExecuteScalar());
            int MmonthInt = Convert.ToInt32(cmdMmonth.ExecuteScalar());

            DateTime Now  = DateTime.Now;
            int      Year = Now.Year;

            DateTime dt = new DateTime(Year, MmonthInt, DdayInt);

            TimeSpan TimeRemaining = dt - DateTime.Now;

            label11.Text = TimeRemaining.Days + " дней";

            connect.Close();
        }
Esempio n. 3
0
        private void Hello_Load(object sender, EventArgs e)
        {
            Class.HashMD5 HMD5     = new Class.HashMD5();
            string        LoginMD5 = HMD5.GetHashString(Settings.Default["Login"].ToString());

            string checkUser  = "******" + LoginMD5 + "';";
            string checkAdmin = "SELECT count(*) FROM admin WHERE Login = '******';";

            connect.Open();

            MySqlCommand cmdCheckUser  = new MySqlCommand(checkUser, connect);
            MySqlCommand cmdCheckAdmin = new MySqlCommand(checkAdmin, connect);

            cmdCheckUser.Prepare();
            cmdCheckAdmin.Prepare();

            int countUser  = Convert.ToInt32(cmdCheckUser.ExecuteScalar());
            int countAdmin = Convert.ToInt32(cmdCheckAdmin.ExecuteScalar());

            if (countUser == 1)
            {
                string       FIOuser    = "******" + LoginMD5 + "';";
                MySqlCommand cmdFIOuser = new MySqlCommand(FIOuser, connect);   //юзер
                cmdFIOuser.Parameters.AddWithValue("@Login", labelname.Text);
                MySqlDataReader reader = cmdFIOuser.ExecuteReader();
                while (reader.Read())
                {
                    labelname.Text = reader["Surname"].ToString() + " " + reader["Name"].ToString() + " " + reader["Middlename"].ToString();
                    Settings.Default["Surname"]    = reader["Surname"].ToString();
                    Settings.Default["Name"]       = reader["Name"].ToString();
                    Settings.Default["Middlename"] = reader["Middlename"].ToString();
                    Settings.Default.Save();
                }
                reader.Close();
            }

            if (countAdmin == 1)
            {
                string       FIOadmin    = "SELECT Surname, Name, Middlename FROM admin WHERE Login = '******';";
                MySqlCommand cmdFIOadmin = new MySqlCommand(FIOadmin, connect);
                cmdFIOadmin.Parameters.AddWithValue("@Login", labelname.Text);
                MySqlDataReader reader = cmdFIOadmin.ExecuteReader();
                while (reader.Read())
                {
                    labelname.Text = reader["Surname"].ToString() + " " + reader["Name"].ToString() + " " + reader["Middlename"].ToString();
                    Settings.Default["Surname"]    = reader["Surname"].ToString();
                    Settings.Default["Name"]       = reader["Name"].ToString();
                    Settings.Default["Middlename"] = reader["Middlename"].ToString();
                    Settings.Default.Save();
                }
                reader.Close();
            }
            connect.Close();
        }
Esempio n. 4
0
        private void Button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                connect.Open();
                string       checkAdmin    = "SELECT count(*) FROM Admin WHERE Login = '******';"; //юзер
                MySqlCommand cmdcheckAdmin = new MySqlCommand(checkAdmin, connect);
                int          countAdmin    = Convert.ToInt32(cmdcheckAdmin.ExecuteScalar());

                if (countAdmin == 1)
                {
                    if (textBox1.Text != Settings.Default["Password"].ToString())
                    {
                        string       updatePassword    = "******" + textBox1.Text + "' WHERE Login = '******'";
                        MySqlCommand cmdupdatePassword = new MySqlCommand(updatePassword, connect);
                        cmdupdatePassword.ExecuteNonQuery();
                        labelPassword.Text = textBox1.Text;
                        connect.Close();
                    }
                    else
                    {
                        MessageBox.Show("Пароли совпадают, введите новый пароль");
                        connect.Close();
                    }
                }
                else
                {
                    Class.HashMD5 HMD5        = new Class.HashMD5();
                    string        LoginMD5    = HMD5.GetHashString(Settings.Default["Login"].ToString());
                    string        PasswordMD5 = HMD5.GetHashString(textBox1.Text);

                    if (textBox1.Text != PasswordMD5)
                    {
                        string       updatePassword    = "******" + PasswordMD5 + "' WHERE Login = '******'";
                        MySqlCommand cmdupdatePassword = new MySqlCommand(updatePassword, connect);
                        cmdupdatePassword.ExecuteNonQuery();
                        labelPassword.Text = textBox1.Text;
                        connect.Close();
                    }
                    else
                    {
                        MessageBox.Show("Пароли совпадают, введите новый пароль");
                        connect.Close();
                    }
                }
            }
        }
Esempio n. 5
0
        private void ButtonToComeIn_Click(object sender, EventArgs e)
        {
            counter++;

            Class.HashMD5 HMD5        = new Class.HashMD5();
            string        LoginMD5    = HMD5.GetHashString(textBox1.Text);
            string        PasswordMD5 = HMD5.GetHashString(textBox2.Text);

            if (radioButtonUser.Checked == true) //юзер
            {
                connect.Open();

                string       checkUser    = "******" + LoginMD5 + "' AND Password='******'"; //юзер
                MySqlCommand cmdcheckUser = new MySqlCommand(checkUser, connect);                                                          //юзер
                int          countUser    = Convert.ToInt32(cmdcheckUser.ExecuteScalar());

                //string checkUser = "******" + LoginMD5 + "' AND Password='******'"; //юзер
                //MySqlCommand cmdcheckUser = new MySqlCommand(checkUser, connect);     //юзер
                //int countUser = Convert.ToInt32(cmdcheckUser.ExecuteScalar());

                if (text1 == textBoxCap.Text)
                {
                    if (textBox1.Text != "" && textBox2.Text != "")
                    {
                        if (countUser == 1)
                        {
                            Settings.Default["Login"]    = textBox1.Text;
                            Settings.Default["Password"] = textBox2.Text;
                            Settings.Default.Save();
                            Hello hello = new Hello();
                            this.Hide();
                            hello.ShowDialog();
                        }
                        else if (counter >= 3) // лимит превышен
                        {
                            textBox1.Enabled       = false;
                            textBox2.Enabled       = false;
                            buttonToComeIn.Enabled = false;
                        }
                        else
                        {
                            MessageBox.Show("Неверно введён логин/пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Не все поля введены", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Введите капчу");
                }
                connect.Close();
            }

            if (radioButtonAdmin.Checked == true) //админ
            {
                connect.Open();
                string       checkAdmin    = "SELECT count(*) FROM Admin WHERE Login='******'"; //админ
                MySqlCommand cmdcheckAdmin = new MySqlCommand(checkAdmin, connect);                            //админ
                int          countAdmin    = Convert.ToInt32(cmdcheckAdmin.ExecuteScalar());

                if (textBox1.Text != "" && textBox2.Text != "")
                {
                    if (countAdmin == 1)
                    {
                        Settings.Default["Login"]    = textBox1.Text;
                        Settings.Default["Password"] = textBox2.Text;
                        Settings.Default.Save();
                        Hello hello = new Hello();
                        this.Hide();
                        hello.ShowDialog();
                    }
                    else if (counter >= 3) // лимит превышен
                    {
                        textBox1.Enabled       = false;
                        textBox2.Enabled       = false;
                        buttonToComeIn.Enabled = false;
                    }
                    else
                    {
                        MessageBox.Show("Неверно введён логин/пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("Не все поля введены", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                connect.Close();
            }
        }
Esempio n. 6
0
        private void Buttoncapt_Click(object sender, EventArgs e)
        {
            var name    = Settings.Default["Name"].ToString();
            var surname = Settings.Default["Surname"].ToString();

            Class.HashMD5 HMD5     = new Class.HashMD5();
            string        LoginMD5 = HMD5.GetHashString(Settings.Default["Login"].ToString());

            connect.Open();
            string       numberPassUser    = "******" + LoginMD5 + "';";
            MySqlCommand cmdNumberPassUser = new MySqlCommand(numberPassUser, connect);
            object       numberPassUserObj = cmdNumberPassUser.ExecuteScalar();
            var          doc = Convert.ToString(numberPassUserObj);

            var chars       = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
            var stringChars = new char[5];

            for (int i = 0; i < stringChars.Length; i++)
            {
                stringChars[i] = chars[rnd.Next(chars.Length)];
            }
            var numberBooking = new String(stringChars);
            var dateNow       = DateTime.Now;

            var h = rnd.Next(0, 23);
            var m = rnd.Next(0, 59);

            var dateDeparture      = dateTimePicker1.Value.ToString("dd.MM.yyyy");
            var dateArrival        = dateTimePicker2.Value.ToString("dd.MM.yyyy");;
            var dateClockDeparture = dateTimePicker1.Value.ToString("hh:mm");
            var dateClockArrival   = $"{h}:{m}";

            var          countrydepart  = comboBox1.SelectedItem.ToString().TrimStart();
            var          countryArrival = comboBox2.SelectedItem.ToString().TrimStart();
            string       rndAirplane    = "SELECT NameAircraft FROM Aircraft WHERE IDAircraft = " + rnd.Next(1, 8) + ";";
            MySqlCommand cmdRndAirplane = new MySqlCommand(rndAirplane, connect);
            object       rndAirplaneObj = cmdRndAirplane.ExecuteScalar();

            connect.Close();
            var Aircraft  = Convert.ToString(rndAirplaneObj);
            var priceT    = rnd.Next(7000, 10000);
            var priceTF   = rnd.Next(4000, 5000);
            var priceMain = priceT + priceTF;

            this.TopMost = false;
            var wordApp = new Word.Application();

            wordApp.Visible = false;
            try
            {
                var wordDocument = wordApp.Documents.Open(TemplateFileName);
                ReplaceWordStub("{name}", name, wordDocument);
                ReplaceWordStub("{surname}", surname, wordDocument);
                ReplaceWordStub("{doc}", doc, wordDocument);
                ReplaceWordStub("{numberBooking}", numberBooking, wordDocument);
                ReplaceWordStub("{numberBooking}", numberBooking, wordDocument);
                ReplaceWordStub("{dateNow}", dateNow.ToString(), wordDocument);
                int iT = Convert.ToInt32(Settings.Default["iTicket"]);
                ++iT;
                Settings.Default["iTicket"] = iT.ToString();
                Settings.Default.Save();

                ReplaceWordStub("{dateDeparture}", dateDeparture, wordDocument);
                ReplaceWordStub("{countrydepart}", countrydepart, wordDocument);
                ReplaceWordStub("{dateClockDeparture}", dateClockDeparture, wordDocument);

                ReplaceWordStub("{dateArrival}", Convert.ToString(dateArrival), wordDocument);
                ReplaceWordStub("{countryArrival}", countryArrival, wordDocument);
                ReplaceWordStub("{dateClockArrival}", dateClockArrival, wordDocument);

                ReplaceWordStub("{Aircraft}", Aircraft, wordDocument);
                ReplaceWordStub("{priceT}", Convert.ToString(priceT), wordDocument);
                ReplaceWordStub("{priceTF}", Convert.ToString(priceTF), wordDocument);
                ReplaceWordStub("{priceMain}", Convert.ToString(priceMain), wordDocument);

                if (Convert.ToInt32(Settings.Default["iTicket"]) <= 9)
                {
                    Settings.Default["numTicket"] = "00000" + Settings.Default["iTicket"].ToString();
                    var numTicket = Settings.Default["numTicket"].ToString();
                    connect.Open();
                    string addUser = "******" +
                                     "VALUES('" + numTicket + "', '" + numberBooking + "', '" + dateNow + "', '" + name + "', '" + surname + "', '" + Aircraft + "', '" + dateDeparture + "', '" + dateArrival + "', '" + countrydepart + "', '" + countryArrival + "', '" + priceMain + "');";
                    MySqlCommand cmdAddUser = new MySqlCommand(addUser, connect);
                    cmdAddUser.ExecuteNonQuery();
                    connect.Close();
                    ReplaceWordStub("{numTicket}", numTicket, wordDocument);
                }
                if (Convert.ToInt32(Settings.Default["iTicket"]) >= 10 && Convert.ToInt32(Settings.Default["iTicket"]) <= 99)
                {
                    Settings.Default["numTicket"] = "0000" + Settings.Default["iTicket"].ToString();
                    var numTicket = Settings.Default["numTicket"].ToString();
                    connect.Open();
                    string addUser = "******" +
                                     "VALUES('" + numTicket + "', '" + numberBooking + "', '" + dateNow + "', '" + name + "', '" + surname + "', '" + Aircraft + "', '" + dateDeparture + "', '" + dateArrival + "', '" + countrydepart + "', '" + countryArrival + "', '" + priceMain + "');";
                    MySqlCommand cmdAddUser = new MySqlCommand(addUser, connect);
                    cmdAddUser.ExecuteNonQuery();
                    connect.Close();
                    ReplaceWordStub("{numTicket}", numTicket, wordDocument);
                }
                if (Convert.ToInt32(Settings.Default["iTicket"]) >= 100 && Convert.ToInt32(Settings.Default["iTicket"]) <= 999)
                {
                    Settings.Default["numTicket"] = "000" + Settings.Default["iTicket"].ToString();
                    var numTicket = Settings.Default["numTicket"].ToString();
                    connect.Open();
                    string addUser = "******" +
                                     "VALUES('" + numTicket + "', '" + numberBooking + "', '" + dateNow + "', '" + name + "', '" + surname + "', '" + Aircraft + "', '" + dateDeparture + "', '" + dateArrival + "', '" + countrydepart + "', '" + countryArrival + "', '" + priceMain + "');";
                    MySqlCommand cmdAddUser = new MySqlCommand(addUser, connect);
                    cmdAddUser.ExecuteNonQuery();
                    connect.Close();
                    ReplaceWordStub("{numTicket}", numTicket, wordDocument);
                }
                if (Convert.ToInt32(Settings.Default["iTicket"]) >= 1000 && Convert.ToInt32(Settings.Default["iTicket"]) <= 9999)
                {
                    Settings.Default["numTicket"] = "00" + Settings.Default["iTicket"].ToString();
                    var numTicket = Settings.Default["numTicket"].ToString();
                    connect.Open();
                    string addUser = "******" +
                                     "VALUES('" + numTicket + "', '" + numberBooking + "', '" + dateNow + "', '" + name + "', '" + surname + "', '" + Aircraft + "', '" + dateDeparture + "', '" + dateArrival + "', '" + countrydepart + "', '" + countryArrival + "', '" + priceMain + "');";
                    MySqlCommand cmdAddUser = new MySqlCommand(addUser, connect);
                    cmdAddUser.ExecuteNonQuery();
                    connect.Close();
                    ReplaceWordStub("{numTicket}", numTicket, wordDocument);
                }
                if (Convert.ToInt32(Settings.Default["iTicket"]) >= 10000 && Convert.ToInt32(Settings.Default["iTicket"]) <= 99999)
                {
                    Settings.Default["numTicket"] = "0" + Settings.Default["iTicket"].ToString();
                    var numTicket = Settings.Default["numTicket"].ToString();
                    connect.Open();
                    string addUser = "******" +
                                     "VALUES('" + numTicket + "', '" + numberBooking + "', '" + dateNow + "', '" + name + "', '" + surname + "', '" + Aircraft + "', '" + dateDeparture + "', '" + dateArrival + "', '" + countrydepart + "', '" + countryArrival + "', '" + priceMain + "');";
                    MySqlCommand cmdAddUser = new MySqlCommand(addUser, connect);
                    cmdAddUser.ExecuteNonQuery();
                    connect.Close();
                    ReplaceWordStub("{numTicket}", numTicket, wordDocument);
                }
                if (Convert.ToInt32(Settings.Default["iTicket"]) >= 100000 && Convert.ToInt32(Settings.Default["iTicket"]) <= 999999)
                {
                    Settings.Default["numTicket"] = Settings.Default["iTicket"].ToString();
                    var numTicket = Settings.Default["numTicket"].ToString();
                    connect.Open();
                    string addUser = "******" +
                                     "VALUES('" + numTicket + "', '" + numberBooking + "', '" + dateNow + "', '" + name + "', '" + surname + "', '" + Aircraft + "', '" + dateDeparture + "', '" + dateArrival + "', '" + countrydepart + "', '" + countryArrival + "', '" + priceMain + "');";
                    MySqlCommand cmdAddUser = new MySqlCommand(addUser, connect);
                    cmdAddUser.ExecuteNonQuery();
                    connect.Close();
                    ReplaceWordStub("{numTicket}", numTicket, wordDocument);
                }

                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter   = "Word Documents (*.docx)|*.docx|All files (*.*)|*.*";
                sfd.FileName = surname + name + "AirTicket.docx";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    wordDocument.SaveAs(sfd.FileName);
                    MessageBox.Show("Успешно!");

                    PrintDialog printDialog = new PrintDialog();
                    if (printDialog.ShowDialog() == DialogResult.OK)
                    {
                        wordDocument.PrintPreview();
                    }
                }
                wordDocument.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Произошла ошибка: " + ex.Message);
                connect.Close();
            }
            finally
            {
                wordApp.Quit();
                connect.Close();
            }
        }
Esempio n. 7
0
        private void ProfileF()
        {
            textBoxSurname.Hide();
            textBoxName.Hide();
            textBoxMiddlename.Hide();
            textBoxPhone.Hide();
            textBoxEmail.Hide();
            buttonSave.Hide();
            panel5.Hide();

            string          myConnectionString = "Database = AirTO; Data Source = localhost; User Id=root; charset= utf8; Password ="******"Login"].ToString());

            string       checkUser    = "******" + LoginMD5 + "';";
            MySqlCommand cmdcheckUser = new MySqlCommand(checkUser, connect);
            int          countUser    = Convert.ToInt32(cmdcheckUser.ExecuteScalar());

            if (countUser == 1)
            {
                string       query          = "SELECT * FROM User ORDER BY IDUser";
                string       countryNumUser = "******" + LoginMD5 + "';";
                MySqlCommand cmdcountryNum  = new MySqlCommand(countryNumUser, connect);
                object       countryObjUser = cmdcountryNum.ExecuteScalar();
                int          country        = Convert.ToInt32(countryObjUser);

                string       countryNumCountrys    = "SELECT Namecountry FROM Countrys WHERE IDCountry = " + country + ";";
                MySqlCommand cmdcountryNumCountrys = new MySqlCommand(countryNumCountrys, connect);
                object       countryObj            = cmdcountryNumCountrys.ExecuteScalar();
                string       countryString         = Convert.ToString(countryObj);

                string       MWNumUser    = "******" + LoginMD5 + "';";
                MySqlCommand cmdMWNumUser = new MySqlCommand(MWNumUser, connect);
                object       MWObjUser    = cmdMWNumUser.ExecuteScalar();
                int          MWInt        = Convert.ToInt32(MWObjUser);

                string       MWNumGender    = "SELECT Gendername FROM Gender WHERE IDGender = " + MWInt + ";";
                MySqlCommand cmdMWNumGender = new MySqlCommand(MWNumGender, connect);
                object       GenderObj      = cmdMWNumGender.ExecuteScalar();
                string       GenderString   = Convert.ToString(GenderObj);

                MySqlCommand    command = new MySqlCommand(query, connect);
                MySqlDataReader reader  = command.ExecuteReader();
                List <string[]> data    = new List <string[]>();
                while (reader.Read())
                {
                    data.Add(new string[12]);

                    data[data.Count - 1][1]  = reader[3].ToString();     //фамилия
                    data[data.Count - 1][2]  = reader[4].ToString();     //имя
                    data[data.Count - 1][3]  = reader[5].ToString();     //отчество
                    data[data.Count - 1][4]  = reader[6].ToString();     //телефон
                    data[data.Count - 1][5]  = reader[7].ToString();     //почта
                    data[data.Count - 1][7]  = reader[9].ToString();     //дата рождения
                    data[data.Count - 1][10] = reader[12].ToString();    //страна
                }
                reader.Close();
                connect.Close();
                // где 1 и 1 - это номер столбца и строки
                foreach (string[] s in data)
                {
                    dataGridView1.Rows.Add(s);
                }
                dataGridView1[0, 0].Value = Settings.Default["Login"].ToString();
                dataGridView1[6, 0].Value = GenderString;
                dataGridView1[8, 0].Value = countryString;
                labelPassword.Text        = "Пароль: " + Settings.Default["Password"].ToString();
            }
            else
            {
                string       checkAdmin    = "SELECT count(*) FROM Admin WHERE Login = '******';"; //юзер
                MySqlCommand cmdcheckAdmin = new MySqlCommand(checkAdmin, connect);
                int          countAdmin    = Convert.ToInt32(cmdcheckAdmin.ExecuteScalar());

                if (countAdmin == 1)
                {
                    string       query           = "SELECT * FROM Admin ORDER BY IDAdmin";
                    string       countryNumAdmin = "SELECT IDCountry FROM Admin WHERE Login ='******';";
                    MySqlCommand cmdcountryNum   = new MySqlCommand(countryNumAdmin, connect);
                    object       countryObjAdmin = cmdcountryNum.ExecuteScalar();
                    int          country         = Convert.ToInt32(countryObjAdmin);

                    string       countryNumCountrys    = "SELECT Namecountry FROM Countrys WHERE IDCountry = " + country + ";";
                    MySqlCommand cmdcountryNumCountrys = new MySqlCommand(countryNumCountrys, connect);
                    object       countryObj            = cmdcountryNumCountrys.ExecuteScalar();
                    string       countryString         = Convert.ToString(countryObj);

                    string       MWNumAdmin    = "SELECT IDGender FROM Admin WHERE Login ='******';";
                    MySqlCommand cmdMWNumAdmin = new MySqlCommand(MWNumAdmin, connect);
                    object       MWObjAdmin    = cmdMWNumAdmin.ExecuteScalar();
                    int          MWInt         = Convert.ToInt32(MWObjAdmin);

                    string       MWNumGender    = "SELECT Gendername FROM Gender WHERE IDGender = " + MWInt + ";";
                    MySqlCommand cmdMWNumGender = new MySqlCommand(MWNumGender, connect);
                    object       GenderObj      = cmdMWNumGender.ExecuteScalar();
                    string       GenderString   = Convert.ToString(GenderObj);

                    MySqlCommand    command = new MySqlCommand(query, connect);
                    MySqlDataReader reader  = command.ExecuteReader();
                    List <string[]> data    = new List <string[]>();
                    while (reader.Read())
                    {
                        data.Add(new string[9]);

                        data[data.Count - 1][0] = reader[1].ToString();      //логин
                        data[data.Count - 1][1] = reader[3].ToString();      //фамилия
                        data[data.Count - 1][2] = reader[4].ToString();      //имя
                        data[data.Count - 1][3] = reader[5].ToString();      //отчество
                        data[data.Count - 1][4] = reader[6].ToString();      //телефон
                        data[data.Count - 1][5] = reader[7].ToString();      //почта
                        data[data.Count - 1][7] = reader[9].ToString();      //дата рождения
                    }
                    reader.Close();
                    connect.Close();
                    // где 1 и 1 - это номер столбца и строки
                    foreach (string[] s in data)
                    {
                        dataGridView1.Rows.Add(s);
                    }
                    dataGridView1[6, 0].Value = GenderString;
                    dataGridView1[8, 0].Value = countryString;
                    labelPassword.Text        = "Пароль: " + Settings.Default["Password"].ToString();
                }
            }
        }
Esempio n. 8
0
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            connect.Open();
            string       checkAdmin    = "SELECT count(*) FROM Admin WHERE Login = '******';";
            MySqlCommand cmdcheckAdmin = new MySqlCommand(checkAdmin, connect);
            int          countAdmin    = Convert.ToInt32(cmdcheckAdmin.ExecuteScalar());

            if (countAdmin == 1)
            {
                if (textBoxSurname.Text != "")
                {
                    dataGridView1[1, 0].Value = textBoxSurname.Text;
                    string       updateSurname    = "UPDATE Admin SET Surname = '" + textBoxSurname.Text + "' WHERE Login = '******'";
                    MySqlCommand cmdupdateSurname = new MySqlCommand(updateSurname, connect);
                    cmdupdateSurname.ExecuteNonQuery();
                }
                if (textBoxName.Text != "")
                {
                    dataGridView1[2, 0].Value = textBoxName.Text;
                    string       updateName    = "UPDATE Admin SET Name = '" + textBoxName.Text + "' WHERE Login = '******'";
                    MySqlCommand cmdupdateName = new MySqlCommand(updateName, connect);
                    cmdupdateName.ExecuteNonQuery();
                }
                if (textBoxMiddlename.Text != "")
                {
                    dataGridView1[3, 0].Value = textBoxMiddlename.Text;
                    string       updateMiddleame    = "UPDATE Admin SET Middlename = '" + textBoxMiddlename.Text + "' WHERE Login = '******'";
                    MySqlCommand cmdupdateMiddleame = new MySqlCommand(updateMiddleame, connect);
                    cmdupdateMiddleame.ExecuteNonQuery();
                }
                if (textBoxPhone.Text != "")
                {
                    dataGridView1[4, 0].Value = textBoxPhone.Text;
                    string       updatePhone    = "UPDATE Admin SET Phone = '" + textBoxPhone.Text + "' WHERE Login = '******'";
                    MySqlCommand cmdupdatePhone = new MySqlCommand(updatePhone, connect);
                    cmdupdatePhone.ExecuteNonQuery();
                }
                if (textBoxEmail.Text != "")
                {
                    dataGridView1[5, 0].Value = textBoxEmail.Text;
                    string       updateEmail    = "UPDATE Admin SET Email = '" + textBoxEmail.Text + "' WHERE Login = '******'";
                    MySqlCommand cmdupdateEmail = new MySqlCommand(updateEmail, connect);
                    cmdupdateEmail.ExecuteNonQuery();
                }
            }
            else
            {
                Class.HashMD5 HMD5     = new Class.HashMD5();
                string        LoginMD5 = HMD5.GetHashString(Settings.Default["Login"].ToString());

                string       checkUser    = "******" + LoginMD5 + "';"; //юзер
                MySqlCommand cmdcheckUser = new MySqlCommand(checkUser, connect);                          //юзер
                int          countUser    = Convert.ToInt32(cmdcheckUser.ExecuteScalar());

                if (countUser == 1)
                {
                    if (textBoxSurname.Text != "")
                    {
                        dataGridView1[1, 0].Value = textBoxSurname.Text;
                        string       updateSurname    = "UPDATE User SET Surname = '" + textBoxSurname.Text + "' WHERE Login = '******'";
                        MySqlCommand cmdupdateSurname = new MySqlCommand(updateSurname, connect);
                        cmdupdateSurname.ExecuteNonQuery();
                    }
                    if (textBoxName.Text != "")
                    {
                        dataGridView1[2, 0].Value = textBoxName.Text;
                        string       updateName    = "UPDATE User SET Name = '" + textBoxName.Text + "' WHERE Login = '******'";
                        MySqlCommand cmdupdateName = new MySqlCommand(updateName, connect);
                        cmdupdateName.ExecuteNonQuery();
                    }
                    if (textBoxMiddlename.Text != "")
                    {
                        dataGridView1[3, 0].Value = textBoxMiddlename.Text;
                        string       updateMiddleame    = "UPDATE User SET Middlename = '" + textBoxMiddlename.Text + "' WHERE Login = '******'";
                        MySqlCommand cmdupdateMiddleame = new MySqlCommand(updateMiddleame, connect);
                        cmdupdateMiddleame.ExecuteNonQuery();
                    }
                    if (textBoxPhone.Text != "")
                    {
                        dataGridView1[4, 0].Value = textBoxPhone.Text;
                        string       updatePhone    = "UPDATE User SET Phone = '" + textBoxPhone.Text + "' WHERE Login = '******'";
                        MySqlCommand cmdupdatePhone = new MySqlCommand(updatePhone, connect);
                        cmdupdatePhone.ExecuteNonQuery();
                    }
                    if (textBoxEmail.Text != "")
                    {
                        dataGridView1[5, 0].Value = textBoxEmail.Text;
                        string       updateEmail    = "UPDATE User SET Email = '" + textBoxEmail.Text + "' WHERE Login = '******'";
                        MySqlCommand cmdupdateEmail = new MySqlCommand(updateEmail, connect);
                        cmdupdateEmail.ExecuteNonQuery();
                    }
                }
            }
            connect.Close();
        }
Esempio n. 9
0
        private void ButtonRegistration_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked == false && radioButton2.Checked == false)
            {
                MessageBox.Show("Не выбран пол, выберите свой пол", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                buttonRegistration.Enabled = false;
            }

            maskedPhone.TextMaskFormat                 = MaskFormat.ExcludePromptAndLiterals;
            maskedPassportSeria.TextMaskFormat         = MaskFormat.ExcludePromptAndLiterals;
            maskedTextBoxPassportNumber.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;

            if (textBoxPassword.Text == textBoxRepeatPassword.Text && textBoxname.Text != "" && textBoxSurname.Text != "" &&
                textBoxMiddlename.Text != "" && textBoxEmail.Text != "" && textBoxLogin.Text != "" && comboBox1.Text != "Не выбрано" &&
                (!String.IsNullOrEmpty(maskedTextBoxPassportNumber.Text) || !String.IsNullOrWhiteSpace(maskedTextBoxPassportNumber.Text) &&
                 (!String.IsNullOrEmpty(maskedPassportSeria.Text) || !String.IsNullOrWhiteSpace(maskedPassportSeria.Text)) &&
                 (!String.IsNullOrEmpty(maskedPhone.Text) || !String.IsNullOrWhiteSpace(maskedPhone.Text)) && labelErrorEmail.Text == "Ок"))
            {
                if (checkBox1.Checked == true)
                {
                    Class.HashMD5 HMD5        = new Class.HashMD5();
                    string        PasswordMD5 = HMD5.GetHashString(textBoxPassword.Text); //хеширование пароля
                    string        LoginMD5    = HMD5.GetHashString(textBoxLogin.Text);    //хеширование логина

                    connect.Open();

                    if (radioButton1.Checked == true)
                    {
                        string addUser = "******" +
                                         "VALUES('" + LoginMD5 + "', '" + PasswordMD5 + "', '" + textBoxSurname.Text + "', '" + textBoxname.Text + "', '" + textBoxMiddlename.Text + "', '+7" + maskedPhone.Text + "', '" + textBoxEmail.Text + "', " + 1 + ", '" + this.dateTimePickerBirthday.Text + "', '" + maskedPassportSeria.Text + "', '" + maskedTextBoxPassportNumber.Text + "', '" + comboBox1.SelectedIndex + "');";
                        MySqlCommand cmdAddUser = new MySqlCommand(addUser, connect);

                        cmdAddUser.ExecuteNonQuery();
                        connect.Close();

                        Authorization auth = new Authorization();
                        this.Hide();
                        auth.ShowDialog();
                    }
                    if (radioButton2.Checked == true)
                    {
                        string addUser = "******" +
                                         "VALUES('" + LoginMD5 + "', '" + PasswordMD5 + "', '" + textBoxSurname.Text + "', '" + textBoxname.Text + "', '" + textBoxMiddlename.Text + "', '+7" + maskedPhone.Text + "', '" + textBoxEmail.Text + "', " + 2 + ", '" + this.dateTimePickerBirthday.Text + "', '" + maskedPassportSeria.Text + "', '" + maskedTextBoxPassportNumber.Text + "', '" + comboBox1.SelectedIndex + "');";
                        MySqlCommand cmdAddUser = new MySqlCommand(addUser, connect);

                        cmdAddUser.ExecuteNonQuery();
                        connect.Close();

                        Authorization auth = new Authorization();
                        this.Hide();
                        auth.ShowDialog();
                    }
                }
                else
                {
                    if (MessageBox.Show("Подтвердите согласие на обработку данных", "Важно", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        checkBox1.Checked = true;
                    }
                }
            }
            else
            {
                MessageBox.Show("Введены не все поля", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }