Esempio n. 1
0
        private void button5_Click(object sender, EventArgs e)
        {
            DatabaseHandler dh  = new DatabaseHandler();
            SqlDataReader   sdr = dh.read("select * from User");

            while (sdr.Read())
            {
                if (textBox1.Text == sdr[0].ToString() && textBox2.Text == sdr[1].ToString())
                {
                    if (sdr[4].ToString() == "A")
                    {
                        // For administrator
                        AdministratorMenu am = new AdministratorMenu();
                        am.Show();
                    }
                    else if (sdr[4].ToString() == "C")
                    {
                        // For coordinator
                        CoordinatorMenu cm = new CoordinatorMenu();
                        cm.Show();
                    }
                    else if (sdr[4].ToString() == "R")
                    {
                        // For runner
                        RunnerMenu rm = new RunnerMenu();
                        rm.Show();
                    }
                    this.Close();
                }
            }
        }
Esempio n. 2
0
        private void btnlogin_Click(object sender, EventArgs e)
        {
            if (grpverify.Visible == true)
            {
                string vcode = tbverify.Text;
                if (vcode.ToLower() != code.ToLower())
                {
                    MessageBox.Show("CAPTCHA ERROR");
                    tbemail.Text  = "";
                    tbpswd.Text   = "";
                    tbverify.Text = "";
                }
            }
            string email = tbemail.Text;
            string pswd  = tbpswd.Text;
            string sql   = string.Format("select RoleId from Users where Email='{0}' and Password='******'", email, pswd);
            object role  = SqlHelper.ExecuteScalar(sql, null);

            if (role != null)
            {
                //验证通过
                if ((int)role == 1)
                {
                    //office user
                    OfficeUserMenu frmouser = new OfficeUserMenu();
                    this.Hide();
                    frmouser.Show();
                }
                else
                {
                    //admin
                    AdministratorMenu frmadmin = new AdministratorMenu();
                    this.Hide();
                    frmadmin.Show();
                }
                if (ckbautologin.Checked)
                {
                    FileStream fs = new FileStream("autoLogin.xml", FileMode.Create);
                    //filemode.create:if file already exists, it will be overwritten.
                    XmlSerializer xs   = new XmlSerializer(typeof(OfficeUser));
                    OfficeUser    user = new OfficeUser();
                    user.Email    = email;
                    user.Password = pswd;
                    user.Lastdate = DateTime.Now.ToString();
                    xs.Serialize(fs, user);
                    fs.Close();
                }
            }
            else
            {
                tbemail.Text  = "";
                tbpswd.Text   = "";
                tbverify.Text = "";
                verify_count++;
                VerifyUpdate();
                string msg = "Validation failed.";
                if (verify_count > 2)
                {
                    grpverify.Visible = true;
                    msg += "please enter the validation code and try again.";
                }
                MessageBox.Show(msg);
            }
        }