-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathMainForm.cs
More file actions
60 lines (59 loc) · 2.48 KB
/
Copy pathMainForm.cs
File metadata and controls
60 lines (59 loc) · 2.48 KB
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
using BusinessObjectsLibrary.BusinessObjects;
using DevExpress.ExpressApp.ApplicationBuilder;
using DevExpress.XtraEditors;
using System.Configuration;
namespace WindowsFormsApplication {
public partial class MainForm : DevExpress.XtraBars.Ribbon.RibbonForm {
IMiddleTierClient<ApplicationDbContext> middleTierClient;
public MainForm() {
InitializeComponent();
}
private void CreateMiddleTierClient(string userName, string password) {
middleTierClient?.Dispose();
middleTierClient = new MiddleTierClientBuilder<ApplicationDbContext>()
.UseServer(ConfigurationManager.AppSettings["MiddleTierServerEndpoint"])
.ConfigureOptions(t => t.WaitForMiddleTierServerReady())
.UsePasswordAuthentication(userName, password)
.Build();
}
private void MainForm_Load(object sender, EventArgs e) {
ShowLoginForm();
}
private void LogoutButtonItem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
foreach(Form form in MdiChildren) {
form.Close();
}
Hide();
string userName = (middleTierClient != null) ? middleTierClient.Security.UserName : "User";
ShowLoginForm(userName);
}
private void ShowLoginForm(string userName = "User") {
using (LoginForm loginForm = new LoginForm(userName)) {
while (true) {
DialogResult dialogResult = loginForm.ShowDialog();
if (dialogResult == DialogResult.OK) {
try {
CreateMiddleTierClient(loginForm.UserName, loginForm.Password);
}
catch (Exception ex) {
XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
continue;
}
CreateListForm();
Show();
}
else {
Close();
}
break;
}
}
}
private void CreateListForm() {
EmployeeListForm employeeForm = new EmployeeListForm(middleTierClient);
employeeForm.MdiParent = this;
employeeForm.WindowState = FormWindowState.Maximized;
employeeForm.Show();
}
}
}