Ejemplo n.º 1
0
        //go back main_menu
        private void main_menu_Click(object sender, EventArgs e)
        {
            this.Hide();
            Main_Menu mn = new Main_Menu();

            mn.Show();
        }
Ejemplo n.º 2
0
        //Login
        private void button_OK_Click(object sender, EventArgs e)
        {
            if (textusername.Text.Trim().Length == 0)
            {
                MessageBox.Show("Please Enter User Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textusername.Focus();
                return;
            }
            if (textpassword.Text.Trim().Length == 0)
            {
                MessageBox.Show("Please Enter Password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textpassword.Focus();
                return;
            }
            try
            {
                connection.Open();
                OleDbCommand command = new OleDbCommand();
                command.Connection = connection;
                string query = "SELECT User_Id,Pword FROM Admin WHERE User_Id = @system AND Pword = @admin";
                command.CommandText = query;



                OleDbParameter uName     = new OleDbParameter("@system", OleDbType.VarChar);
                OleDbParameter uPassword = new OleDbParameter("@admin", OleDbType.VarChar);
                uName.Value     = textusername.Text;
                admin           = textusername.Text;
                uPassword.Value = textpassword.Text;
                command.Parameters.Add(uName);
                command.Parameters.Add(uPassword);
                OleDbDataReader myReader = command.ExecuteReader(CommandBehavior.CloseConnection);

                if (myReader.Read() == true)
                {
                    this.Hide();
                    Main_Menu menu = new Main_Menu();
                    menu.Show();
                }


                else
                {
                    MessageBox.Show("Login is Failed...Try again !", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    textusername.Clear();
                    textpassword.Clear();
                    textusername.Focus();
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }