Example #1
0
        static void Main()
        {
            //Notes();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            LoginForm login = new LoginForm();

            for (
                DialogResult result = login.ShowDialog();
                result != DialogResult.Cancel;
                result = login.ShowDialog()
                ) // I suppose this is a tad unconventional, but w/e
            {
                if (result == DialogResult.OK)
                {
                    Account account = AccountMapper.ReadAccountByUserPass(login.Username, login.Password);
                    if (account == null)
                    {
                        MessageBox.Show("Invalid username or password", "Login Error");
                    }
                    else if (account.StudentID == null)
                    {
                        Application.Run(new AdminForm(account.AccountID));
                    }
                    else
                    {
                        Application.Run(new StudentsReservations(account.AccountID));
                    }
                }
                else // result == DialogResult.Ignore
                {
                    if (int.TryParse(login.StudentID, out int id) &&
                        StudentMapper.ReadStudentByID(id) != null &&
                        AccountMapper.ReadAccountByUserPass(login.Username, login.Password) == null)
                    {
                        AccountMapper.CreateAccount(new Account()
                        {
                            Username  = login.Username,
                            Password  = login.Password,
                            StudentID = id
                        });
                        login.ClearInfo(true);
                    }
                    else
                    {
                        MessageBox.Show("Invalid student ID or username already taken", "Login Error");
                    }
                }
            }
        }