Example #1
0
//        Admin
//        Accountant
//        Receptionist
//        General Employee

        private void panel3_Click(object sender, EventArgs e)
        {
            if (UserNameTB.Text == "")
            {
                UserNameTB.BackColor = Color.DodgerBlue;
                MessageBox.Show("Username Is Required", "Empty", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                UserNameTB.Focus();
                return;
            }
            if (PassTB.Text == "")
            {
                PassTB.BackColor = Color.DodgerBlue;
                MessageBox.Show("Password Is Required", "Empty", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                PassTB.Focus();
                return;
            }



            if (comboBox1.SelectedIndex == 0)
            {
                if (AccountTypecomboBox.SelectedIndex == 0)
                {
                    //if (UserNameTB.Text == "Admin" && PassTB.Text == "Admin123")
                    //{
                    if (UserNameTB.Text.ToUpper() == "ADMIN" && PassTB.Text == "Admin123")
                    {
                        this.Hide();
                        AdminPortal Ap = new AdminPortal();
                        Ap.Show();
                    }
                    else
                    {
                        LoginMethod("Sp_AdminLogin");

                        //MessageBox.Show("Wrong User Name or Password, Try again", "Invalid User", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //UserNameTB.Focus();
                    }
                }


                else if (AccountTypecomboBox.SelectedIndex == 1)
                {
                    //Accountant

                    //if (UserNameTB.Text == "Account" && PassTB.Text == "Account123")
                    //{


                    LoginMethod("Sp_AccountantLogin");
                    //this.Hide();
                    //AccountantPortal Ap = new AccountantPortal();
                    //Ap.Show();
                    //}
                    //else
                    //{
                    //    MessageBox.Show("Invalid UserName Or PassWord");
                    //    UserNameTB.Focus();
                    //}
                }
                else if (AccountTypecomboBox.SelectedIndex == 2)
                {
                    // Receptionist

                    //if (UserNameTB.Text == "Rec" && PassTB.Text == "Rec123")
                    //{
                    LoginMethod("Sp_ReceptionistLogin");
                    //this.Hide();
                    //ReceptionestPortal Ap = new ReceptionestPortal();
                    //Ap.Show();
                    //}
                    //else
                    //{
                    //    MessageBox.Show("Invalid UserName Or PassWord");
                    //    UserNameTB.Focus();
                    //}
                }
                else if (AccountTypecomboBox.SelectedIndex == 3)
                {
                    //  General Employee

                    //if (UserNameTB.Text == "Emp" && PassTB.Text == "Emp123")
                    //{

                    LoginMethod("Sp_EmpLogin");
                    //this.Hide();
                    //GeneralEmployeePortal Ap = new GeneralEmployeePortal(UserNameTB.Text);
                    //Ap.Show();
                    //}
                    //else
                    //{
                    //    MessageBox.Show("Invalid UserName Or PassWord");
                    //    UserNameTB.Focus();
                    //}
                }

                else
                {
                    MessageBox.Show("Please Select Account Type", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    AccountTypecomboBox.Focus();
                }
            }

            else if (comboBox1.SelectedIndex == 1)
            {
                try
                {
                    LoginMethod("Sp_AccountantLogin");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #2
0
        private void LoginMethod(String Proc)
        {
            try
            {
                String        ConnString = ConfigurationManager.ConnectionStrings["PayrollConn"].ConnectionString;
                SqlConnection conn       = new SqlConnection(ConnString);
                SqlDataReader reader;

                using (conn)
                {
                    SqlCommand cmd1 = new SqlCommand(Proc, conn);
                    cmd1.CommandType = CommandType.StoredProcedure;
                    cmd1.Parameters.AddWithValue("@UserId", UserNameTB.Text);
                    cmd1.Parameters.AddWithValue("@Pass", PassTB.Text);
                    conn.Open();
                    reader = cmd1.ExecuteReader();
                    reader.Read();
                    if (reader.HasRows)
                    {
                        if (comboBox1.SelectedIndex == 0)
                        {
                            if (AccountTypecomboBox.SelectedIndex == 0)
                            {
                                this.Hide();
                                AdminPortal Ap = new AdminPortal();
                                Ap.Show();
                            }
                            else if (AccountTypecomboBox.SelectedIndex == 1)
                            {
                                this.Hide();
                                AccountantPortal Ap = new AccountantPortal();
                                Ap.Show();
                            }
                            else if (AccountTypecomboBox.SelectedIndex == 2)
                            {
                                this.Hide();
                                ReceptionestPortal Ap = new ReceptionestPortal();
                                Ap.Show();
                            }
                            else if (AccountTypecomboBox.SelectedIndex == 3)
                            {
                                this.Hide();
                                GeneralEmployeePortal Ap = new GeneralEmployeePortal(UserNameTB.Text);
                                Ap.Show();
                            }
                        }
                        else
                        {
                            System.Diagnostics.Process.Start(Application.StartupPath + @"\inventorysystem\inventorysystem\bin\Debug\inventorysystem.exe");

                            UserNameTB.Clear();
                            PassTB.Clear();
                            UserNameTB.Focus();
                            comboBox1.SelectedIndex = 0;
                        }
                    }
                    else
                    {
                        MessageBox.Show(" Wrong User Name or Password, Try again", "Invalid User", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        UserNameTB.Focus();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                UserNameTB.Focus();
            }
        }