示例#1
0
        private void regButton_Click(object sender, RoutedEventArgs e)
        {
            string prmAlert = "Введите: \n";
            if (NameField.Text == "Имя")
            {
                prmAlert += "\tимя, \n";
            }
            if (SurnameField.Text == "Фамилия")
            {
                prmAlert += "\tфамилию, \n";
            }
            if (PhoneField.Text == "Номер телефона")
            {
                prmAlert += "\tномер телефона, \n";
            }
            if (CardField.Text == "Номер карты")
            {
                prmAlert += "\tномер карты, \n";
            }
            if (StreetField.Text == "Улица")
            {
                prmAlert += "\tулицу, \n";
            }
            if (EmailField.Text == "Почта")
            {
                prmAlert += "\tпочту, \n";
            }
            if (PassField.Password == "Пароль")
            {
                prmAlert += "\tпароль. \n";
            }
            if (CityField.Text == "Город")
            {
                prmAlert += "\tгород, \n";
                MessageBox.Show(prmAlert);
                return;
            }

            if (isUserExists()) { return; }

            DataBase db = new DataBase();
            MySqlCommand command = new MySqlCommand("INSERT INTO `users` (`email`, `pass`, `name`, `surname`, `phone`, `card`, `city`, `street`) " +
                "VALUES (@email, @pass, @name, @surname, @phone, @card, @city, @street)", db.getConnection());
            command.Parameters.Add("@email", MySqlDbType.VarChar).Value = EmailField.Text;
            command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = PassField.Password;
            command.Parameters.Add("@name", MySqlDbType.VarChar).Value = NameField.Text;
            command.Parameters.Add("@surname", MySqlDbType.VarChar).Value = SurnameField.Text;
            command.Parameters.Add("@phone", MySqlDbType.Int64).Value = PhoneField.Text;
            command.Parameters.Add("@card", MySqlDbType.Int64).Value = CardField.Text;
            command.Parameters.Add("@city", MySqlDbType.VarChar).Value = CityField.Text;
            command.Parameters.Add("@street", MySqlDbType.VarChar).Value = StreetField.Text;

            db.openConnection();
            if (command.ExecuteNonQuery() == 1)
            {
                MessageBox.Show("Аккаунт был успешно создан!");
                Hide();
                MainWindow mw5 = new MainWindow();
                mw5.Show();
            }
            else
            {
                MessageBox.Show("Аккаунт не был создан.");
            }

            db.closeConnection();
        }
示例#2
0
        private void loginButton_Click(object sender, RoutedEventArgs e)
        {
            string userEmail = emailTextBox.Text;
            string userPass  = passwordTextBox.Password.ToString();

            DataBase         db      = new DataBase();
            DataTable        table   = new DataTable();
            MySqlDataAdapter adapter = new MySqlDataAdapter();

            MySqlCommand command = new MySqlCommand("SELECT * FROM `users` WHERE `email` = @uE AND `pass` = @uP", db.getConnection());

            command.Parameters.Add("@uE", MySqlDbType.VarChar).Value = userEmail;
            command.Parameters.Add("@uP", MySqlDbType.VarChar).Value = userPass;

            adapter.SelectCommand = command;
            adapter.Fill(table);
            if (table.Rows.Count > 0)
            {
                string          connStr    = "server=localhost;port=3306;username=root;password=;database=e-shop";
                string          sql        = "SELECT * FROM `users` WHERE `email` = @uE AND `pass` = @uP";
                MySqlConnection connection = new MySqlConnection(connStr);
                MySqlCommand    sqlCom     = new MySqlCommand(sql, connection);
                sqlCom.Parameters.Add("@uE", MySqlDbType.VarChar).Value = userEmail;
                sqlCom.Parameters.Add("@uP", MySqlDbType.VarChar).Value = userPass;
                connection.Open();
                sqlCom.ExecuteNonQuery();
                MySqlDataAdapter dataAdapter = new MySqlDataAdapter(sqlCom);
                DataTable        dt          = new DataTable();
                dataAdapter.Fill(dt);

                var myData = dt.Select();

                for (int i = 0; i < myData.Length; i++)
                {
                    for (int j = 0; j < myData[i].ItemArray.Length; j++)
                    {
                        switch (j)
                        {
                        case 0: customer.Id = Convert.ToInt32(myData[i].ItemArray[j]); break;

                        case 1: customer.Email = myData[i].ItemArray[j].ToString(); break;

                        case 2: customer.Password = myData[i].ItemArray[j].ToString(); break;

                        case 3: customer.Name = myData[i].ItemArray[j].ToString(); break;

                        case 4: customer.Surname = myData[i].ItemArray[j].ToString(); break;

                        case 5: customer.Phone = myData[i].ItemArray[j].ToString(); break;

                        case 6: customer.Card = myData[i].ItemArray[j].ToString(); break;

                        case 7: customer.City = myData[i].ItemArray[j].ToString(); break;

                        case 8: customer.Street = myData[i].ItemArray[j].ToString(); break;
                        }
                    }
                }
                Random rnd = new Random();
                orderNumber = rnd.Next(10000, 99999);
                this.Hide();
                MainWindow mw = new MainWindow();
                mw.Show();
            }
            else
            {
                MessageBox.Show("Логин или пароль был введен неверно!");
            }
        }
示例#3
0
        public bool isUserExists()
        {
            DataBase db = new DataBase();
            DataTable table = new DataTable();
            MySqlDataAdapter adapter = new MySqlDataAdapter();
            MySqlCommand command = new MySqlCommand("SELECT * FROM `users` WHERE `email` = @uE", db.getConnection());
            command.Parameters.Add("@uE", MySqlDbType.VarChar).Value = EmailField.Text;

            adapter.SelectCommand = command;
            adapter.Fill(table);

            if (table.Rows.Count > 0)
            {
                MessageBox.Show("Аккаунт с такой почтой уже зарегистрирован.");
                return true;
            }
            else
            {
                return false;
            }
        }