Esempio n. 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     using (SqlConnection connection = DBUtils.GetDBconnection()) //Вносим значения логина, пароля и имейла в БД
     {
         if (textBox1.Text == "")                                 //проверка, чтобы поле не было пустым
         {
             MessageBox.Show("Enter login");
             return;
         }
         if (textBox2.Text == "")//проверка, чтобы поле не было пустым
         {
             MessageBox.Show("Enter login");
             return;
         }
         if (textBox3.Text == "")//проверка, чтобы поле не было пустым
         {
             MessageBox.Show("Enter login");
             return;
         }
         if (textBox3.Text.Length < 8)//проверка длины пароля
         {
             MessageBox.Show("Password is too short (min - 8 signs)");
             return;
         }
         if (CheckUserLogin())
         {
             return;
         }
         if (CheckUserEmail())
         {
             return;
         }
         int dogSignInt = 0;                            //количество знаков @ в имейле
         for (int i = 0; i < textBox2.Text.Length; i++) //цикл проверки наличия @ в поле для ввода почты
         {
             if (textBox2.Text[i] == '@')
             {
                 dogSignInt++;
             }
         }
         if (dogSignInt != 1)
         {
             MessageBox.Show("Invalid E-mail");                 //если в посте нет @, то выводит, что почта невалидна
         }
         connection.Open();
         string     sqlExpression = "INSERT INTO Customer (Username,Email,Pass) VALUES ('" + textBox1.Text + "', '" + textBox2.Text + "', '" + textBox3.Text + "')";
         SqlCommand command       = new SqlCommand(sqlExpression, connection);
         command.ExecuteNonQuery();
         Personal_acc_customer perAcc = new Personal_acc_customer(this, textBox1.Text);
         perAcc.Show();
         this.Hide();
         connection.Close();
     }
 }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (SqlConnection conn = DBUtils.GetDBconnection())
            {
                string         username = "";
                DataTable      table2   = new DataTable();      //создаем вторую таблицу
                SqlDataAdapter adapter2 = new SqlDataAdapter(); //создаем второй адаптер
                DataTable      table    = new DataTable();      //создаем таблицу
                SqlDataAdapter adapter  = new SqlDataAdapter(); //создаем адаптер
                conn.Open();
                string     sqlExpression  = "SELECT * FROM Customer WHERE Email = '" + textBox2.Text + "' AND Pass = '******' ";
                string     sqlExpression2 = "SELECT Username FROM Customer WHERE Email = '" + textBox2.Text + "' AND Pass = '******' ";
                SqlCommand command        = new SqlCommand(sqlExpression, conn);
                SqlCommand command2       = new SqlCommand(sqlExpression2, conn);
                command.ExecuteNonQuery();
                command2.ExecuteNonQuery();
                adapter.SelectCommand  = command;
                adapter2.SelectCommand = command2;
                adapter.Fill(table);
                adapter2.Fill(table2);
                foreach (DataRow row in table2.Rows)
                {
                    // получаем все ячейки строки
                    var cells = row.ItemArray;
                    foreach (object cell in cells)
                    {
                        username = cell.ToString();
                    }
                }

                if (table.Rows.Count > 0)//проверяем, есть ли в таблице данные
                {
                    Personal_acc_customer perAcc = new Personal_acc_customer(this, username);
                    perAcc.Show();
                    this.Close();
                    conn.Close();
                }
                else
                {
                    MessageBox.Show("Invalid E-mail or Password");
                    conn.Close();
                }
            }
        }