Exemple #1
0
 private void cmiChangeUser_Click(object sender, EventArgs e)
 {
     if (gvUsers.SelectedRows.Count != 1)
         return;
     Access_Users selectedUser = gvUsers.SelectedRows[0].DataBoundItem as Access_Users;
     if (selectedUser == null)
         return;
     InputPasswordLine input = new InputPasswordLine()
     {
         Text = @"Изменение пользователя",
         Label1 = {Text = @"Имя:"},
         Label2 = {Text = @"Пароль:"},
         InputLine1 = {Text = selectedUser.Description},
         InputLine2 = {Text = selectedUser.Password},
         InputLine3 = {Text = selectedUser.Password},
         InputLine4 = {Text = selectedUser.Email},
         cbIsAdmin = {Checked = selectedUser.IsAdmin},
         cbDepartments = {DataSource = _dataContext.AccEquipmentV2Entities.Departments.OrderBy(d => d.Description).ToList()}
     };
     input.cbDepartments.SelectedItem = selectedUser.Department;
     if (input.ShowDialog(this) == DialogResult.OK)
     {
         bool changed = false;
         if (input.cbDepartments.SelectedItem as Department != selectedUser.Department)
         {
             changed = true;
             selectedUser.Department = input.cbDepartments.SelectedItem as Department;
         }
         if (input.InputLine1.Text != selectedUser.Description)
         {
             changed = true;
             selectedUser.Description = input.InputLine1.Text;
         }
         if (input.InputLine2.Text != selectedUser.Password)
         {
             changed = true;
             selectedUser.Password = input.InputLine2.Text;
         }
         if (input.cbIsAdmin.Checked != selectedUser.IsAdmin)
         {
             changed = true;
             selectedUser.IsAdmin = input.cbIsAdmin.Checked;
         }
         if (input.InputLine4.Text != selectedUser.Email)
         {
             changed = true;
             selectedUser.Email = input.InputLine4.Text;
         }
         if (changed)
         {
             _dataContext.AccEquipmentV2Entities.SaveChanges();
             RefreshGrid();
         }
     }
 }
Exemple #2
0
 private void cmiCopy_Click(object sender, EventArgs e)
 {
     if (gvUsers.SelectedRows.Count != 1)
         return;
     var selectedUser = gvUsers.SelectedRows[0].DataBoundItem as Access_Users;
     if (selectedUser == null)
         return;
     InputPasswordLine input = new InputPasswordLine() { Text = @"Копирование пользователя "+selectedUser.Description + @" и его прав", Label1 = { Text = @"Имя нового пользователя:" }, Label2 = { Text = @"Пароль:" } };
     if (input.ShowDialog(this) == DialogResult.OK)
     {
         Access_Users user = new Access_Users()
         {
             Description = input.InputLine1.Text,
             Id = Guid.NewGuid(),
             Password = input.InputLine2.Text,
             IsAdmin = input.cbIsAdmin.Checked,
             DepartmentId = selectedUser.DepartmentId,
             Email = input.InputLine4.Text
         };
         foreach (var association in selectedUser.Access_Associations.Where(a=>a.AppId==AppId.Id).ToList())
         {
             Access_Associations newAssociation = new Access_Associations()
             {
                 Id = Guid.NewGuid(),
                 AppId = AppId.Id,
                 ElementId = association.ElementId,
                 UserId = user.Id,
                 RightFlags = association.RightFlags
             };
             _dataContext.AccEquipmentV2Entities.Access_Associations.Add(newAssociation);
         }
         _dataContext.AccEquipmentV2Entities.Access_Users.Add(user);
         _dataContext.AccEquipmentV2Entities.SaveChanges();
         RefreshGrid();
     }
 }
Exemple #3
0
 private void cmiAddUser_Click(object sender, EventArgs e)
 {
     InputPasswordLine input = new InputPasswordLine
     {
         Text = @"Добавление пользователя",
         Label1 = {Text = @"Имя:"},
         Label2 = {Text = @"Пароль:"},
         cbDepartments = {DataSource = _dataContext.AccEquipmentV2Entities.Departments.OrderBy(d => d.Description).ToList()}
     };
     if (input.ShowDialog(this) == DialogResult.OK)
     {
         Access_Users user = new Access_Users()
         {
             Description = input.InputLine1.Text,
             Id = Guid.NewGuid(),
             Password = input.InputLine2.Text,
             Department = input.cbDepartments.SelectedItem as Department,
             Email = input.InputLine4.Text
         };
         _dataContext.AccEquipmentV2Entities.Access_Users.Add(user);
         _dataContext.AccEquipmentV2Entities.SaveChanges();
         RefreshGrid();
     }
 }