private bool RunLogin() { bool RetVal = false; FormsAuthentication.Initialize(); string username = txtUsername.Text; string password = txtPassword.Text; var mUser = new clsSchool.StaffDB().GetByEmail(username); if (mUser != null) { if (mUser.StaffId > 0 && mUser.IsActive && mUser.Password == password) { FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, mUser.Email, DateTime.Now, DateTime.Now.AddDays(1), true, mUser.StaffId.ToString(), FormsAuthentication.FormsCookiePath); Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket))); hdfStaff.Value = mUser.StaffId.ToString(); RetVal = true; } } mUser = null; return(RetVal); }
private bool ValidateInput() { bool r = true; if (string.IsNullOrEmpty(txtFirstName.Text)) { lblError.Text = "Please enter the First Name"; lblError.Visible = true; timError.Enabled = true; r = false; return(r); } if (string.IsNullOrEmpty(txtLastName.Text)) { lblError.Text = "Please enter the Last Name"; lblError.Visible = true; timError.Enabled = true; r = false; return(r); } if (string.IsNullOrEmpty(txtPhone.Text)) { lblError.Text = "Please enter the Phone Number"; lblError.Visible = true; timError.Enabled = true; r = false; return(r); } if (string.IsNullOrEmpty(txtEmail.Text)) { lblError.Text = "Please enter the Email Address"; lblError.Visible = true; timError.Enabled = true; r = false; return(r); } if (hdfStaffId.Value.ToInt() == 0) { var mStaff = new clsSchool.StaffDB().GetByEmail(txtEmail.Text); if (mStaff != null) { lblError.Text = "This email address already exists in the system"; lblError.Visible = true; timError.Enabled = true; r = false; return(r); } } return(r); }
private void RemoveStaff(int StaffId) { var mStaff = new clsSchool.StaffDB().GetById(StaffId); if (mStaff != null) { mStaff.IsActive = false; bool ok = new clsSchool.StaffDB().Update(mStaff); } LoadGrid(); }
protected void btnSave_Click(object sender, EventArgs e) { if (!ValidateInput()) { return; } StaffId = 0; if (!string.IsNullOrEmpty(hdfStaffId.Value)) { StaffId = hdfStaffId.Value.ToInt(); } UnloadForm(StaffId); if (StaffId > 0) { bool ok = new clsSchool.StaffDB().Update(mStaffBase); if (!ok) { StaffId = -1; } } else { StaffId = new clsSchool.StaffDB().Add(mStaffBase); hdfStaffId.Value = StaffId.ToString(); } if (StaffId < 0) { // InputFailed("The database update failed, please try again."); } else { LoadGrid(); ResetForm(); } }