Example #1
0
        // LogIn Function
        private void Button1_Click(object sender, EventArgs e)
        {
            //Sql Conenction:
            SqlConnection cnn = new SqlConnection(Program.DB_ConnectionString_Users());

            cnn.Open();

            //Select statement to retrieve if the user is Admin or not:
            SqlCommand   command0 = new SqlCommand("Select Rights from Users where Username = @use  and Password = @pas", cnn);
            SqlParameter use      = new SqlParameter();
            SqlParameter pas      = new SqlParameter();

            use.ParameterName = "@use";
            pas.ParameterName = "@pas";
            command0.Parameters.AddWithValue("@use", (textBox1.Text));
            command0.Parameters.AddWithValue("@pas", (textBox2.Text));

            //SqlDataReader:
            SqlDataReader da = command0.ExecuteReader();

            while (da.Read())
            {
                myString = da.GetInt32(0).ToString();
            }
            if ((textBox1.Text == "") && (textBox2.Text == ""))
            {
                MessageBox.Show("Username & password fields cannot be empty.");
            }
            else if (textBox1.Text == "")
            {
                MessageBox.Show("Please enter your username.");
            }
            else if (textBox2.Text == "")
            {
                MessageBox.Show("Please enter your password.");
            }
            //============================================
            else if ((myString == "0") || (myString == "1"))
            {
                Home y = new Home();
                this.Hide();
                y.ShowDialog();
                this.Close();

                // Go back to Home from the BookingSeatsScreen method:
                using (var form2 = y)
                {
                    if (form2.ShowDialog() == DialogResult.OK)
                    {
                        y.Hide();
                    }
                }
            }
            //============================================
            else
            {
                MessageBox.Show("Wrong credentials.");
            }

            //Close the connection and dispose of the commands:
            command0.Dispose();
            cnn.Close();
        }
Example #2
0
        // LogIn Function
        private void Button1_Click(object sender, EventArgs e)
        {
            //to do: custom error messageBoxes
            //to do: connection to the users db
            //to do: add logo icon on the top left corner
            //to do: this.Close after Home is opened (not only this.hide)

            string        connetionString;
            SqlConnection cnn;

            connetionString = @"Data Source =DESKTOP-CJRBB7E; Initial Catalog = UsersDB; Integrated Security = True";
            cnn             = new SqlConnection(connetionString);
            cnn.Open();

            SqlCommand command;
            //SqlDataReader dataReader;
            String       sql;
            SqlParameter use = new SqlParameter();
            SqlParameter pas = new SqlParameter();

            use.ParameterName = "@use";
            pas.ParameterName = "@pas";



            sql = "Select Rights from Users where Username=@use  and Password=@pas";


            command = new SqlCommand(sql, cnn);
            command.Parameters.AddWithValue("@use", (textBox1.Text));
            command.Parameters.AddWithValue("@pas", (textBox2.Text));
            SqlDataReader da = command.ExecuteReader();

            var myString = "";

            while (da.Read())
            {
                myString = da.GetInt32(0).ToString();

                if ((textBox1.Text == "") && (textBox2.Text == ""))
                {
                    MessageBox.Show("Username & password fields cannot be empty.");
                }
                else if (textBox1.Text == "")
                {
                    MessageBox.Show("Please enter your username.");
                }
                else if (textBox2.Text == "")
                {
                    MessageBox.Show("Please enter your password.");
                }
                //============================================
                else if ((myString == "0") || (myString == "1"))
                {
                    if (myString == "0")
                    {
                        MessageBox.Show("User");
                    }
                    else if (myString == "1")
                    {
                        MessageBox.Show("Admin");
                    }
                    Home y = new Home();
                    y.Show();
                    this.Hide();
                }
                //============================================
                else
                {
                    MessageBox.Show("Wrong credentials.");
                }
            }
        }