private void btnOK_Click(object sender, EventArgs e)
        {
            int countError = 0;

            if (CheckError.CheckErrors(tbEmail))
            {
                countError++;
            }
            if (CheckError.CheckErrors(tbNewPassword))
            {
                countError++;
            }
            if (CheckError.CheckErrors(tbRepeatPassword))
            {
                countError++;
            }
            if (CheckError.CheckErrors(tbNewPassword, tbRepeatPassword))
            {
                countError++;
            }

            if (countError == 0)
            {
                DialogResult = DialogResult.OK;
            }
        }
Ejemplo n.º 2
0
        public static int CheckLogin(TextBox tbLogin, TextBox tbPassword, Label lblError)
        {
            SqlConnection connection = new SqlConnection();

            try
            {
                connection.ConnectionString = connectionString;

                connection.Open();

                SqlCommand command = connection.CreateCommand();
                //command.CommandText = "SELECT Name, Password, Email, Id FROM Users WHERE Name = '" + tbLogin.Text + "' AND Password = '******'";
                command.CommandText = "SELECT Name, Password FROM Users WHERE Name = '" + tbLogin.Text + "' AND Password = '******'";

                DbDataReader dataReader = command.ExecuteReader();

                if (!dataReader.HasRows)
                {
                    //CheckError.CheckErrors(tbLogin);
                    //if(lblError.Text == "")
                    //{
                    //    lblError.Text = "Ошибка логина";
                    //}
                    //CheckError.CheckErrors(tbPassword);
                    //if(lblError.Text == "")
                    //{
                    //    lblError.Text = "Ошибка пароля";
                    //}
                    //else
                    //{
                    //    lblError.Text += " и пароля";
                    //}

                    CheckError.ChangeBackColor(tbLogin);
                    CheckError.ChangeBackColor(tbPassword);
                    lblError.Text = "Ошибка логина или пароля";

                    return(-1);
                }

                while (dataReader.Read() != false)
                {
                    //string txt = dataReader["Name"].ToString() + "\n" + dataReader["Password"].ToString() + "\n" + dataReader["Email"] + "\n" + dataReader["Id"];
                    //MessageBox.Show(txt);
                }
                return(0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                connection.Close();
            }
            return(-1);
        }