コード例 #1
0
        private void snabbloginAdminToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DatabaseHandler db           = new DatabaseHandler();
            Employee        defaultAdmin = db.LoadEmployee("ADM10001");
            Form            main         = new AdminWindowForm(defaultAdmin);

            main.Show();
            this.Hide();
        }
コード例 #2
0
        private void loginBtn_Click(object sender, EventArgs e)
        {
            DatabaseHandler db = new DatabaseHandler();

            string username = usernameTxtBox.Text;
            string password = passwordTxtBox.Text;

            if (Regex.IsMatch(username, @"^\d{2}[01]\d[0-3]\d[-]\d{4}$"))
            {
                isPatient = true;
                System.Diagnostics.Debug.WriteLine("isPatient = true");
            }
            else
            {
                isPatient = false;
                System.Diagnostics.Debug.WriteLine("isPatient = false");
            }

            if (!db.UserExists(username))
            {
                errorProvider.SetError(usernameTxtBox, "Användarnamn finns ej");
                //warningLbl.Text = "Användare finns ej.";
                //warningLbl.Visible = true;
                return;
            }
            else
            {
                errorProvider.SetError(usernameTxtBox, "");
                user               = db.LoadUser(username, isPatient);
                warningLbl.Text    = "";
                warningLbl.Visible = false;
            }


            if (!user.PasswordIsCorrect(password))
            {
                errorProvider.SetError(passwordTxtBox, "Lösenord och Användarnamn matchar ej!");
                //warningLbl.Text = "Felaktigt Användarnamn/Lösenord";
                //warningLbl.Visible = true;
                return;
            }
            else
            {
                if (isPatient)
                {
                    errorProvider.SetError(passwordTxtBox, "");
                    Patient userPatient = db.LoadPatient(username);
                    Form    patView     = new PatientViewForm(userPatient);
                    patView.Show();
                    this.Hide();
                }
                else
                {
                    errorProvider.SetError(passwordTxtBox, "");
                    Employee userEmployee = db.LoadEmployee(user.Identifier);
                    Form     main;
                    if (userEmployee.Position == "IT-Admin")
                    {
                        main = new AdminWindowForm(userEmployee);
                    }
                    else
                    {
                        main = new MainWindow(userEmployee);
                    }

                    main.Show();
                    this.Hide();
                }
            }
        }