Exemple #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.username = tbUsername.Text;
            Properties.Settings.Default.password = tbPassword.Text;

            Properties.Settings.Default.Save();

            MySqlConnection connection;

            Common.CommonSettings.connectionString = ConfigurationManager.ConnectionStrings["MySqlConnection"].ConnectionString;

            using (connection = new MySqlConnection(connectionString))
            {
                try
                {
                    connection.Open();

                    DBRetrieve retrieve = new DBRetrieve();

                    bool UserExist = retrieve.DoesUserExist(tbUsername.Text, tbPassword.Text);

                    if (UserExist)
                    {
                        userType             = checkUserType(tbUsername.Text);
                        user                 = retrieve.GetEmployeeByUsername(tbUsername.Text);
                        SessionSettings.user = user;

                        switch (userType)
                        {
                        case UserType.UNKNOWN:
                            MessageBox.Show("User unknown!", "Connection unsuccesfull", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.Show();
                            return;

                        case UserType.Administrator:
                            //MessageBox.Show("Succesfully connected to database!", "Connection succesfull", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            AdminMainForm a = new AdminMainForm(user);
                            a.Show();
                            this.Hide();
                            break;

                        case UserType.RegularUser:
                            //MessageBox.Show("Succesfully connected to database!", "Connection succesfull", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            UserMainForm u = new UserMainForm(user);
                            u.Show();
                            //this.Close();
                            break;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Invalid username/password. Please try again.", "Connection unsuccesfull", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Show();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Exemple #2
0
 public AddProject(AdminMainForm main)
 {
     InitializeComponent();
     this.main = main;
 }