示例#1
0
        private void loginClicked(object sender, EventArgs e)
        {
            string UserName = userName.Text;
            string Password = password.Text;
            string catagory = Catagory.SelectedItem.ToString();

            if (catagory.Equals("Admin"))
            {
                dynamic AdminResult = AdminController.AuthenticateAdmin(UserName, Password);

                if (AdminResult != null)
                {
                    string welcomeName = AdminResult.Name;
                    new AdminPortal(welcomeName).Show();
                }
                else
                {
                    MessageBox.Show("User Not Valid", "Invalid Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (catagory.Equals("Customer"))
            {
                var CustomerResult = CustomerController.AuthenticateCustomer(UserName, Password);
                if (CustomerResult != null)
                {
                    string welcome = CustomerResult.Name;
                    new CustomerPortal(welcome).Show();
                }
                else
                {
                    MessageBox.Show("User Not Valid", "Invalid Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (catagory.Equals("Employee"))
            {
                var EmployeeResult = EmployeeController.AuthenticEmployee(UserName, Password);
                if (EmployeeResult != null)
                {
                    string welcome = EmployeeResult.Name;
                    new EmployeePortal(welcome).Show();
                }
                else
                {
                    MessageBox.Show("User Not Valid", "Invalid Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string Email    = email.Text.Trim();
            string Password = password.Text.Trim();

            if (admin.Checked == false && employee.Checked == false && customer.Checked == false)
            {
                MessageBox.Show("Please select a category", "Invalid Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (string.IsNullOrEmpty(Email) || string.IsNullOrEmpty(Password))
            {
                if (string.IsNullOrEmpty(Email))
                {
                    emailallert.Visible = true;
                }
                else
                {
                    emailallert.Visible = false;
                }
                if (string.IsNullOrEmpty(Password))
                {
                    passwordallert.Visible = true;
                }
                else
                {
                    passwordallert.Visible = false;
                }
                MessageBox.Show("Please enter your Information", "Invalid Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (admin.Checked == true)
                {
                    dynamic AdminResult = AdminController.AuthenticateAdmin(Email, Password);
                    if (AdminResult != null)
                    {
                        this.Hide();

                        new AdminPortal().Show();
                    }
                    else
                    {
                        MessageBox.Show("User Not Valid", "Invalid Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else if (employee.Checked == true)
                {
                    dynamic EmployeeResult = EmployeeController.AuthenticEmployee(Email, Email, Password);
                    if (EmployeeResult != null)
                    {
                        this.Hide();
                        new EmployeePortal().Show();
                    }
                    else
                    {
                        MessageBox.Show("User Not Valid", "Invalid Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else if (customer.Checked == true)
                {
                    dynamic CustomerResult = CustomerController.AuthenticateCustomer(Email, Email, Password);
                    if (CustomerResult != null)
                    {
                        this.Hide();
                        new Customer_Portal().Show();
                    }
                    else
                    {
                        MessageBox.Show("User Not Valid", "Invalid Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }