Пример #1
0
        //
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int paswint = textBoxPass2.Text.Length;
                // Regex reg1 = new Regex("/^ (?=.*[a - z])(?=.*[A - Z])(?=.*[0 - 9])(?=.*[!@#\$%\^&\*\[\]"\';:_\-<>\., =\+\/\\]).{8,}$/u");
                //   Regex reg2 = new Regex();
                bool Reg = true;

                //критерии к паролю
                if (textBoxPass2.Text != textBoxPass.Text)
                {
                    MessageBox.Show("Пароли не совпадают");
                    return;
                }
                if (paswint < 6)
                {
                    MessageBox.Show("Пароль должен быть не менее 6 символов");
                }

                /*      foreach(Control c in Controls)
                 *    {
                 *        if (c is TextBox)
                 *        {
                 *            if (c.Text == "")
                 *            {
                 *
                 *            }
                 *        }
                 *    }
                 */
                //Выводит красные поля
                if (textBoxName.Text == "")
                {
                    labelRed1.Visible = true; Reg = false;
                }
                if (textBoxFamilia.Text == "")
                {
                    labelRed2.Visible = true; Reg = false;
                }
                if (textBoxLogin.Text == "")
                {
                    labelRed3.Visible = true; Reg = false;
                }
                if (textBoxPass.Text == "")
                {
                    labelRed4.Visible = true; Reg = false;
                }
                if (textBoxPass2.Text == "")
                {
                    labelRed5.Visible = true; Reg = false;
                }

                //Connect to BD
                //Повторы login'a
                using (SqlConnection connect2 = new SqlConnection(Program.conString))
                {
                    connect2.Open();
                    string        sqlExp2 = string.Format("SELECT*FROM USERS WHERE login='******' and password='******' ", textBoxLogin.Text, textBoxPass.Text);
                    SqlCommand    cmd2    = new SqlCommand(sqlExp2, connect2);
                    SqlDataReader reader  = cmd2.ExecuteReader();
                    if (reader.HasRows) // проверка есть ли данные
                    {
                        reader.Read();  // читаем строку
                        if ((string)reader["login"] == textBoxLogin.Text)
                        {
                            MessageBox.Show("Пользователь с таким логином уже существует"); return;
                        }
                    }
                    reader.Close();
                }


                using (SqlConnection connect = new SqlConnection(Program.conString))
                {
                    connect.Open();
                    string     sqlExp = string.Format("INSERT INTO Users(login, password, lastName, firstName) VALUES ('{0}', '{1}', '{2}', '{3}') ", textBoxLogin.Text, textBoxPass.Text, textBoxFamilia.Text, textBoxName.Text);
                    SqlCommand cmd    = new SqlCommand(sqlExp, connect);
                    int        b      = cmd.ExecuteNonQuery();
                    //Вывод MessageBox'a
                    MessageBox.Show(textBoxName.Text + textBoxFamilia.Text + " , вы успешно зарегистрированы в системе");
                    Registration rg = new Registration();
                    rg.Close();
                }
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); return; }
        }