コード例 #1
0
        private void buttonLogin_Click(object sender, RoutedEventArgs e)
        {
            Boolean clear = true;

            if (string.IsNullOrWhiteSpace(this.user.Text))
            {
                MessageBox.Show("Username can't be empty");
                this.user.Focus();
                clear = false;
                return;
            }
            if (string.IsNullOrWhiteSpace(this.pass.Password))
            {
                MessageBox.Show("Password can't be empty");
                this.pass.Focus();
                clear = false;
            }


            if (clear == true)
            {
                try
                {

                    this.myConnection.Open();
                    SqlCommand getAll = new SqlCommand("SELECT *  FROM users where  userName = '******' AND userPass = '******'", myConnection);
                    SqlDataReader runit = getAll.ExecuteReader();

                    if (runit.Read() == true)
                    {
                        MessageBox.Show("Welcome " + this.user.Text);
                        this.Hide();
                        userWindow userw = new userWindow();
                        userw.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show("False Username or Password");
                        this.user.Clear();
                        this.pass.Clear();
                        this.user.Focus();
                    }


                }
                catch (SqlException d)
                {
                    MessageBox.Show(d.ToString());


                }
                finally
                {
                    this.myConnection.Close();

                }
            }
           

        }
コード例 #2
0
        private void buttonLogin_Click(object sender, RoutedEventArgs e)
        {
            Boolean clear = true;

            if (string.IsNullOrWhiteSpace(this.user.Text))
            {
                MessageBox.Show("Username can't be empty");
                this.user.Focus();
                clear = false;
                return;
            }
            if (string.IsNullOrWhiteSpace(this.pass.Password))
            {
                MessageBox.Show("Password can't be empty");
                this.pass.Focus();
                clear = false;
            }


            if (clear == true)
            {
                try
                {
                    this.myConnection.Open();
                    SqlCommand    getAll = new SqlCommand("SELECT *  FROM users where  userName = '******' AND userPass = '******'", myConnection);
                    SqlDataReader runit  = getAll.ExecuteReader();

                    if (runit.Read() == true)
                    {
                        MessageBox.Show("Welcome " + this.user.Text);
                        this.Hide();
                        userWindow userw = new userWindow();
                        userw.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show("False Username or Password");
                        this.user.Clear();
                        this.pass.Clear();
                        this.user.Focus();
                    }
                }
                catch (SqlException d)
                {
                    MessageBox.Show(d.ToString());
                }
                finally
                {
                    this.myConnection.Close();
                }
            }
        }