private void bRoleEdit_Click(object sender, EventArgs e) { FormCreateRole crRole = new FormCreateRole(); RoleRepository roleRep = new RoleRepository(); Roles role = bindingSourceUserinRoles.Current as Roles; List <BusinessUserInRoles> busUsinRol = new List <BusinessUserInRoles>(); crRole.Rolename = role.RoleName; crRole.UEForm = this; this.Visible = false; if (crRole.ShowDialog() == DialogResult.OK) { busUsinRol = DeleteUserinRoles(role); // Удаляем связи роли с пользователями roleRep.Delete(role); role = new Roles(); role.RoleName = crRole.tbRoleName.Text; roleRep.Create(role); MessageBox.Show("Role Edit"); GetRoles(); if (busUsinRol.Count > 0) { BusinessUserInRoles obj = new BusinessUserInRoles(); BusinessUserInRolesRepository brep = new BusinessUserInRolesRepository(); obj.RoleId = role.RoleId; for (int i = 0; i < busUsinRol.Count; i++) { obj.UserId = busUsinRol[i].UserId; obj.HireDate = busUsinRol[i].HireDate; brep.Create(obj); } } } }
private void GetUserRoles(object obj) { BusinessUserInRolesRepository brep = new BusinessUserInRolesRepository(); bindingSourceUserinRoles.DataSource = brep.GetAll(Convert.ToInt32(obj)); dgvUserinRoles.DataSource = bindingSourceUserinRoles; dgvUserinRoles.Columns["RoleId"].Visible = false; }
private void bDelete_Click(object sender, EventArgs e) { if (dgvUserinRoles.SelectedCells != null) { DialogResult result = MessageBox.Show("Удалить запись?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result.ToString() == "Yes") { BusinessUserInRoles obj = new BusinessUserInRoles(); obj = bindingSourceUserinRoles.Current as BusinessUserInRoles; BusinessUserInRolesRepository brep = new BusinessUserInRolesRepository(); brep.Delete(obj); GetUserRoles(cbUsers.SelectedValue, 0); } } }
private void bUserEdit_Click(object sender, EventArgs e) { FormCreateUser crUser = new FormCreateUser(); UserRepository userRep = new UserRepository(); Users user = bindingSourceUserinRoles.Current as Users; List <BusinessUserInRoles> busUsinRol = new List <BusinessUserInRoles>(); crUser.UserName = user.UserName; crUser.UserPassword = user.UserPassword; crUser.DateBirthday = user.DateBirthday; crUser.FirstName = user.FirstName; crUser.LastName = user.LastName; crUser.Telephon = user.Telephon; crUser.UEForm = this; this.Visible = false; if (crUser.ShowDialog() == DialogResult.OK) { busUsinRol = DeleteUserinRoles(user);// Удаляем связи пользователя с ролями userRep.Delete(user); user = new Users(); user.UserName = crUser.tbUserName.Text; user.UserPassword = crUser.tbUserPassword.Text; user.DateBirthday = crUser.dtpDateBirthday.Value.Date; user.FirstName = crUser.tbFirstName.Text; user.LastName = crUser.tbLastName.Text; user.Telephon = crUser.tbTelephon.Text; userRep.Create(user); MessageBox.Show("User Edit"); GetUsers(); if (busUsinRol.Count > 0) { BusinessUserInRoles obj = new BusinessUserInRoles(); BusinessUserInRolesRepository brep = new BusinessUserInRolesRepository(); obj.UserId = user.UserId; for (int i = 0; i < busUsinRol.Count; i++) { obj.RoleId = busUsinRol[i].RoleId; obj.HireDate = busUsinRol[i].HireDate; brep.Create(obj); } } } }
private void bCreate_Click(object sender, EventArgs e) { BusinessUserInRoles obj = new BusinessUserInRoles(); obj.UserId = Convert.ToInt32(cbUsers.SelectedValue); FormEditUserInRoles feuir = new FormEditUserInRoles(); feuir.UEForm = this; this.Visible = false; if (feuir.ShowDialog() == DialogResult.OK) { obj.RoleId = Convert.ToInt32(feuir.cbRoles.SelectedValue); obj.HireDate = feuir.dtpHireDate.Value.Date; BusinessUserInRolesRepository brep = new BusinessUserInRolesRepository(); brep.Create(obj); GetUserRoles(obj.UserId, 0); } }
private List <BusinessUserInRoles> DeleteUserinRoles(Roles role) // Метод для удаления связи между ролями и пользователями { List <BusinessUserInRoles> busUsinRol = new List <BusinessUserInRoles>(); int RoleId = role.RoleId; GetUserRoles(0, RoleId); BusinessUserInRoles obj = new BusinessUserInRoles(); BusinessUserInRolesRepository brep = new BusinessUserInRolesRepository(); while (bindingSourceUserinRoles.Current != null) { obj = bindingSourceUserinRoles.Current as BusinessUserInRoles; busUsinRol.Add(obj); brep.Delete(obj); GetUserRoles(0, RoleId); } return(busUsinRol); }
private void bOk_Click(object sender, EventArgs e) { UserRepository ur = new UserRepository(); BusinessUserInRolesRepository Userrep = new BusinessUserInRolesRepository(); this.DialogResult = DialogResult.OK; string password = ur.GetAll().Where(p => p.UserId == Convert.ToInt32(cbLogin.SelectedValue)).Select(p => p.UserPassword).First(); DateTime maxdt = Userrep.GetAll(Convert.ToInt32(cbLogin.SelectedValue)).Where(p => p.HireDate <= DateTime.Now).Max(p => p.HireDate); string RoleName = Userrep.GetAll(Convert.ToInt32(cbLogin.SelectedValue)).Where(p => p.HireDate == maxdt).Select(p => p.RoleName).Last(); if (RoleName == "Admin" && tbPassword.Text == password) { MainForm main = new MainForm(); main.Show(); main.AForm = this; this.Visible = false; } else if (RoleName == "Menedger" && tbPassword.Text == password) { MainForm main = new MainForm(); main.bScheduleEditing.Visible = false; main.bUsersEditing.Visible = false; main.bTicket.Location = new Point(431, 13); main.bTicket.Height = 181; main.Show(); } else if (RoleName == "User" && tbPassword.Text == password) { MainForm main = new MainForm(); main.bScheduleEditing.Visible = false; main.bUsersEditing.Visible = false; main.bTicket.Visible = false; main.bExit.Location = new Point(431, 13); main.bExit.Height = 271; main.Show(); } else { MessageBox.Show("Invalid Password"); } }