private void EditRoleForm_Load(object sender, EventArgs e) { using (var session = new Session1Entities()) { var query = session.Offices.Select(o => new { o.ID, o.Title }); var result = query.ToList(); comboBoxOffice.DisplayMember = "Title"; comboBoxOffice.ValueMember = "ID"; comboBoxOffice.DataSource = result; } adminMain = (AdminMainForm)Owner; var row = adminMain.dataGridView.CurrentCell.OwningRow; textBoxEmailAddress.Text = row.Cells["EmailAddress"].Value.ToString(); textBoxFirstName.Text = row.Cells["Name"].Value.ToString(); textBoxLastName.Text = row.Cells["LastName"].Value.ToString(); comboBoxOffice.Text = row.Cells["Office"].Value.ToString(); if (row.Cells["UserRole"].Value.ToString() == "Administrator") { radioButtonAdministrator.Checked = true; } else { radioButtonUser.Checked = true; } }
private void AddUserForm_Load(object sender, EventArgs e) { adminMainForm = (AdminMainForm)Owner; using (var session = new Session1Entities()) { var query = session.Offices.Select(o => new { o.ID, o.Title }); var result = query.ToList(); comboBoxOffice.DisplayMember = "Title"; comboBoxOffice.ValueMember = "ID"; comboBoxOffice.DataSource = result; } }
private void buttonLogin_Click(object sender, EventArgs e) { string username = textBoxUsername.Text; string password = textBoxPassword.Text; password = Hash.MakeMd5(password); using (var session = new Session1Entities()) { var query = session.Users.Where(u => u.Email == username && u.Password == password); var result = query.FirstOrDefault(); if (result != null) { if (result.Active == true) { // Login Success // Administrator = 1, User = 2 if (result.RoleID == 1) { var admin = new AdminMainForm(); // So that if AdminMainForm closed, LoginForm will open again Hide(); admin.ShowDialog(); Show(); } else { var user = new UserMainForm($"{result.FirstName} {result.LastName}", result.ID); // So that if UserMainForm closed, LoginForm will open again Hide(); var timeNow = DateTime.Now.TimeOfDay; session.Activities.Add(new Activity { UserID = result.ID, Date = DateTime.Now.Date, LoginTime = new TimeSpan(timeNow.Hours, timeNow.Minutes, timeNow.Seconds) }); session.SaveChanges(); user.ShowDialog(); Show(); } ClearFields.ClearTextBoxes(this); failedLoginAttempt = 0; } else { MessageBox.Show("User suspended by Administrator!"); failedLoginAttempt++; CheckLoginAttempt(); } } else { // Login Failed MessageBox.Show("Wrong Username or Password!"); failedLoginAttempt++; CheckLoginAttempt(); } } }