示例#1
0
文件: LoginForm.cs 项目: pyunqi/s606
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textUsername.Text))
            {
                MessageBox.Show("Username can not be empty", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                textUsername.Focus();
                return;
            }
            if (string.IsNullOrEmpty(textPassword.Text))
            {
                MessageBox.Show("Password can not be empty", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                textPassword.Focus();
                return;
            }
            if (!radioManager.Checked && !radioStaff.Checked)
            {
                MessageBox.Show("Please Choose A Role!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                using (KiwiBike4RentEntities kb4rEntites = new KiwiBike4RentEntities())
                {
                    var result = kb4rEntites.Login_Procedure(textUsername.Text, textPassword.Text, userType).SingleOrDefault();
                    if (1 == result)
                    {
                        this.Hide();
                        MessageBox.Show("Login successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        var role = from staff in kb4rEntites.STAFFs
                                   where staff.UserName == textUsername.Text
                                   select staff;

                        LoginInfo.currentUser = role.FirstOrDefault <STAFF>(); //current user is saved in global scope
                        Dashboard dashboard = new Dashboard();
                        dashboard.Show();
                    }
                    else
                    {
                        MessageBox.Show("Login Failed! Please check username or pasword!!", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            catch (ArgumentNullException ae)
            {
                Console.WriteLine("ArgumentNullException", ae.Source);
                MessageBox.Show("Paramters can not be null!!", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#2
0
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     using (KiwiBike4RentEntities kiwiBike4RentEntities = new KiwiBike4RentEntities())
     {
         var staff = from s in kiwiBike4RentEntities.STAFFs
                     where s.StaffID == LoginInfo.currentUser.StaffID
                     select s;
         staff.SingleOrDefault().Name          = txtName.Text;
         staff.SingleOrDefault().UserName      = txtUsername.Text;
         staff.SingleOrDefault().Tel           = txtTel.Text;
         staff.SingleOrDefault().ExtNumber     = txtExtNumber.Text;
         staff.SingleOrDefault().Password      = txtPassword.Text;
         staff.SingleOrDefault().Address       = txtAddress.Text;
         staff.SingleOrDefault().OfficeAddress = txtOfficeAddress.Text;
         kiwiBike4RentEntities.SaveChanges();
         LoginInfo.currentUser = (STAFF)staff.SingleOrDefault();//sync
     }
     MessageBox.Show("Profile Updated!", "Profile", MessageBoxButtons.OK, MessageBoxIcon.Information);
     this.Close();
 }