Пример #1
0
        public void LoginFunction()
        {
            string username  = txtUsername.Text;
            string password  = txtPassword.Text;
            string AuditInfo = "Logged into the System";

            if (username != "" && password != "")
            {
                if (rdoAdmin.Checked == true)
                {
                    int UserType = 1;
                    int auth     = obj.Admin_Auth(username, password, UserType);
                    try
                    {
                        if (auth == 1)
                        {
                            ap = new AdminPanel();
                            SetValueForText1 = txtUsername.Text;
                            UserTypeLogin    = 1;
                            EmpID            = sb.GetEmpID(username);
                            Ab.InsertAudit(SetValueForText1, AuditInfo);
                            ap.Show();
                            Hide();
                        }
                        else
                        {
                            switch (MessageBox.Show("Authentication Failed? try again",
                                                    "Login Failed",
                                                    MessageBoxButtons.YesNo,
                                                    MessageBoxIcon.Question))
                            {
                            case DialogResult.Yes:
                                this.Hide();
                                LoginForm form = new LoginForm();
                                form.Show();
                                break;

                            case DialogResult.No:
                                Application.Exit();
                                break;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
                else if (rdoManager.Checked == true)
                {
                    int UserType = 2;
                    int auth     = obj.Manager_Auth(username, password, UserType);
                    try
                    {
                        if (auth == 1)
                        {
                            Management_Profile mp = new Management_Profile();
                            SetValueForText1 = txtUsername.Text;
                            UserTypeLogin    = 2;
                            EmpID            = sb.GetEmpID(username);
                            Ab.InsertAudit(SetValueForText1, AuditInfo);
                            mp.Show();
                            Hide();
                        }
                        else
                        {
                            switch (MessageBox.Show("Authentication Failed? try again",
                                                    "Login Failed",
                                                    MessageBoxButtons.YesNo,
                                                    MessageBoxIcon.Question))
                            {
                            case DialogResult.Yes:
                                this.Hide();
                                LoginForm form = new LoginForm();
                                form.Show();
                                break;

                            case DialogResult.No:
                                Application.Exit();
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else if (rdoStaff.Checked == true)
                {
                    int UserType = 3;
                    int auth     = obj.Staff_Auth(username, password, UserType);
                    try
                    {
                        if (auth == 1)
                        {
                            sp = new StaffProfile();
                            SetValueForText1 = txtUsername.Text;
                            EmpID            = sb.GetEmpID(username);
                            UserTypeLogin    = 3;
                            Ab.InsertAudit(SetValueForText1, AuditInfo);
                            sp.Show();
                            Hide();
                        }
                        else
                        {
                            switch (MessageBox.Show("Authentication Failed? try again",
                                                    "Login Failed",
                                                    MessageBoxButtons.YesNo,
                                                    MessageBoxIcon.Question))
                            {
                            case DialogResult.Yes:
                                Hide();
                                LoginForm form = new LoginForm();
                                form.Show();
                                break;

                            case DialogResult.No:
                                Application.Exit();
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }

            else
            {
                try
                {
                    switch (MessageBox.Show("Username &/or Password cannot be Empty",
                                            "Login Failed",
                                            MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Question))
                    {
                    case DialogResult.Yes:
                        Hide();
                        LoginForm form = new LoginForm();
                        form.Show();
                        break;

                    case DialogResult.No:
                        Application.Exit();
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }