Example #1
0
        private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmAttendanceRecords FrmAR = new FrmAttendanceRecords();

            FrmAR.Show();
            this.Dispose(false);
        }
        private void btnlogin_Click(object sender, EventArgs e)
        {
            the_user_name = txtUserName.Text;
            //If the checkbox is ticked
            if (chkRememberMe.Checked)
            {
                Properties.Settings.Default.textbox  = txtUserName.Text;
                Properties.Settings.Default.textbox2 = txtPassword.Text;
                Properties.Settings.Default.combobox = comboUserType.Text;
                Properties.Settings.Default.checkbox = chkRememberMe.Checked;
                Properties.Settings.Default.Save();
            } //If the checkbox is not ticked
            else
            {
                Properties.Settings.Default.textbox  = "";
                Properties.Settings.Default.textbox2 = "";
                Properties.Settings.Default.combobox = "";
                Properties.Settings.Default.checkbox = (chkRememberMe.Checked = false);
                Properties.Settings.Default.Save();
            }
            if (txtUserName.Text == "9999999999")
            {
                MessageBox.Show("Please key in your User Name", "User Name field is empty", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (txtPassword.Text == "9999999999")
            {
                MessageBox.Show("Please key in your Password", "Password field is empty", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (comboUserType.Text == "Select User Type")
            {
                MessageBox.Show("Please select your User Type", "User Type is not selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                //Sql Adapter to run the Sql Query
                //If it is correct, the count will be 1, otherwise the count will be 0

                /*SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) From [dbo].[Login] Where UserName='******' and Password='******'and UserType='" + comboUserType.Text + "'", con);
                 * DataTable dt = new DataTable();
                 * sda.Fill(dt);*/
                //   if (dt.Rows[0][0].ToString() == "1")
                //   {

                if (comboUserType.Text == "Student")
                {
                    FrmMainForm frmp = new FrmMainForm();
                    frmp.Show();

                    if (chkRememberMe.Checked == false)
                    {
                        txtPassword.Text   = "";
                        txtUserName.Text   = "";
                        comboUserType.Text = "";
                    }
                    this.Hide();
                }
                else if (comboUserType.Text == "Teacher")
                {
                    FrmAttendanceRecords frar = new FrmAttendanceRecords();
                    frar.Show();
                    if (chkRememberMe.Checked == false)
                    {
                        txtPassword.Text   = "";
                        txtUserName.Text   = "";
                        comboUserType.Text = "";
                    }
                    this.Hide();
                }
                else if (comboUserType.Text == "Admin")
                {
                    FrmAdministratorMainPage FrmAdmin = new FrmAdministratorMainPage();
                    FrmAdmin.Show();
                    if (chkRememberMe.Checked == false)
                    {
                        txtPassword.Text   = "";
                        txtUserName.Text   = "";
                        comboUserType.Text = "";
                    }
                    this.Hide();
                }
                // }

                /*  else
                 * {
                 *    MessageBox.Show("Please Check Your UserName and Password", "Invalid username or password", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 * }*/
            }
        }