示例#1
0
        private void Button1_Click(object sender, EventArgs e)
        {
            var form1 = new StudentMain();

            this.Hide();
            form1.Closed += (s, args) => this.Close();
            form1.Show();
        }
示例#2
0
        private void LoginBtn_Click(object sender, EventArgs e)
        {
            try
            {
                string username = lgUserName.Text.Trim();
                string password = lgPassword.Text.Trim();

                if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
                {
                    MessageBox.Show("Username and password are required!");
                }
                else
                {
                    loggedUser = db.Login(username, password);
                    if (loggedUser != null)
                    {
                        if (loggedUser.UserType.Equals("Admin"))
                        {
                            var form1 = new Form1();
                            this.Hide();
                            form1.Closed += (s, args) => this.Close();
                            form1.Show();
                        }
                        else if (loggedUser.UserType.Equals("Student"))
                        {
                            var form2 = new StudentMain();
                            this.Hide();
                            form2.Closed += (s, args) => this.Close();
                            form2.Show();
                        }
                        else
                        {
                            MessageBox.Show("Wrong user type");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Invalid username or password. Please enter correct match");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "Login Message Box");
            }
        }