-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExamUserGridForm.cs
65 lines (64 loc) · 2.5 KB
/
ExamUserGridForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using ExamProj.Class;
using ExamProj.Context;
using ExamProj.Repositories;
using ExamProj.Services;
using ExamProj.Services.Interfaces;
using System;
using System.Linq;
using System.Windows.Forms;
namespace ExamProj
{
public partial class ExamUserGridForm : DevExpress.XtraEditors.XtraForm
{
public User user = new User();
private IUserServices _userServices { get; set; }
public ExamUserGridForm()
{
InitializeComponent();
_userServices = new UserServices(new Repository<User>(new ExamDbContext()));
RefreshUsers();
}
public void RefreshUsers()
{
gridControl.DataSource = _userServices.GetAllUsers().ToList();
}
private void gridControl_DoubleClick(object sender, EventArgs e)
{
if (gridView.FocusedRowHandle > -1)
{
var selectedUser = Convert.ToInt32(gridView.GetFocusedRowCellValue("ID"));
user = _userServices.GetUserByID(selectedUser);
ExamUserCRUDForm form = new ExamUserCRUDForm(user);
form.ShowDialog();
RefreshUsers();
user = new User();
}
else
MessageBox.Show("Select a user.", "Incorrect Line", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
private void newBtn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
ExamUserCRUDForm form = new ExamUserCRUDForm(user);
form.ShowDialog();
RefreshUsers();
user = new User();
}
private void deleteBtn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
DialogResult result;
if (gridView.FocusedRowHandle > -1)
{
result = MessageBox.Show("Are you sure about deleting this user?", "Delete User?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
var selectedUser = Convert.ToInt32(gridView.GetFocusedRowCellValue("ID"));
_userServices.DeleteUser(selectedUser);
RefreshUsers();
MessageBox.Show($"User {selectedUser} was deleted.", "User Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
MessageBox.Show("Select a user.", "Incorrect Line", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}