1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Text;
|
---|
4 | using IndianHealthService.BMXNet.WinForm.Configuration;
|
---|
5 | using IndianHealthService.BMXNet.Forms;
|
---|
6 | using System.Windows.Forms;
|
---|
7 |
|
---|
8 | namespace IndianHealthService.BMXNet.WinForm.Forms
|
---|
9 | {
|
---|
10 | internal class RpmsLoginPresenter
|
---|
11 | {
|
---|
12 |
|
---|
13 | private bool _enableConnectionManagement = false;
|
---|
14 |
|
---|
15 | public bool EnableConnectionManagement
|
---|
16 | {
|
---|
17 | get { return _enableConnectionManagement; }
|
---|
18 | set { _enableConnectionManagement = value; }
|
---|
19 | }
|
---|
20 |
|
---|
21 | private RpmsLoginView _view = null;
|
---|
22 |
|
---|
23 | public RpmsLoginView View
|
---|
24 | {
|
---|
25 | get { return _view; }
|
---|
26 | set { _view = value; }
|
---|
27 | }
|
---|
28 |
|
---|
29 | private LoginProcess _model = null;
|
---|
30 |
|
---|
31 | public LoginProcess Model
|
---|
32 | {
|
---|
33 | get { return _model; }
|
---|
34 | set { _model = value; }
|
---|
35 | }
|
---|
36 |
|
---|
37 | private IWin32Window _uiOwner = null;
|
---|
38 |
|
---|
39 | public IWin32Window UiOwner
|
---|
40 | {
|
---|
41 | get { return _uiOwner; }
|
---|
42 | set { _uiOwner = value; }
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | public void Open()
|
---|
47 | {
|
---|
48 | this.UpdateConnectionSpecs();
|
---|
49 | this.View.IsSwitchServerModeEnabled = this.Model.IsSwitchServerModeEnabled;
|
---|
50 | this.View.ConnectionSpecSelected += new EventHandler(View_ConnectionSpecSelected);
|
---|
51 | // this.View.EnableUseWindowsAuthentication = this.View.ConnectionSpec == null ? false : this.View.ConnectionSpec.UseWindowsAuthentication;
|
---|
52 | this.View.Ok += new EventHandler(View_Ok);
|
---|
53 | this.View.Cancel += new EventHandler(View_Cancel);
|
---|
54 | this.View.ShowView(this.UiOwner);
|
---|
55 | }
|
---|
56 |
|
---|
57 | void View_Cancel(object sender, EventArgs e)
|
---|
58 | {
|
---|
59 | this.Model.WasLoginAttempted = false;
|
---|
60 | this.Model.Cancel=true;
|
---|
61 | this.View.CloseView();
|
---|
62 | }
|
---|
63 |
|
---|
64 | void View_Ok(object sender, EventArgs e)
|
---|
65 | {
|
---|
66 | if (this.View.ConnectionSpec == null)
|
---|
67 | {
|
---|
68 | MessageBox.Show("Selected a Connection.", "Login Failed");
|
---|
69 | }
|
---|
70 | else
|
---|
71 | {
|
---|
72 | if (this.View.AccessCode.Length == 0)
|
---|
73 | {
|
---|
74 | MessageBox.Show("Please enter an Access Code.", "Login Failed");
|
---|
75 | return;
|
---|
76 | }
|
---|
77 | if (this.View.VerifyCode.Length == 0)
|
---|
78 | {
|
---|
79 | MessageBox.Show("Please enter a Verify Code.", "Login Failed");
|
---|
80 | return;
|
---|
81 | }
|
---|
82 | this.View.ShowWait();
|
---|
83 | if (this.Model.AttemptAccessVerifyLogin(this.View.ConnectionSpec, this.View.AccessCode, this.View.VerifyCode))
|
---|
84 | {
|
---|
85 | this.View.HideWait();
|
---|
86 | this.View.CloseView();
|
---|
87 | }
|
---|
88 | else
|
---|
89 | {
|
---|
90 | this.View.HideWait();
|
---|
91 | if (this.Model.HandleLoginAttemptedFailed())
|
---|
92 | {
|
---|
93 | if (this.Model.Cancel)
|
---|
94 | {
|
---|
95 | this.View.CloseView();
|
---|
96 | return;
|
---|
97 | }
|
---|
98 | }
|
---|
99 | else
|
---|
100 | {
|
---|
101 | if (this.Model.Settings.UserSettings.Get("Debug",false) && (this.Model.FailureException != null))
|
---|
102 | {
|
---|
103 | ExceptionMessageDialog.SafeShow("Login Failed", this.Model.FailureException);
|
---|
104 | }
|
---|
105 | else
|
---|
106 | {
|
---|
107 | MessageBox.Show(this.Model.FailureMessage, "Login Failed");
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | if (this.Model.LoginAttempts >= this.Model.MaxAttempts)
|
---|
112 | {
|
---|
113 | MessageBox.Show("The application will now close.", "Login Attempts Exceeded");
|
---|
114 | this.View.CloseView();
|
---|
115 | }
|
---|
116 | else
|
---|
117 | {
|
---|
118 | this.View.ResetAccessVerifyCodes();
|
---|
119 | }
|
---|
120 | }
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | void View_ConnectionSpecSelected(object sender, EventArgs e)
|
---|
125 | {
|
---|
126 | this.View.UseWindowsAuthentication= this.View.ConnectionSpec==null ? false : this.View.ConnectionSpec.UseWindowsAuthentication;
|
---|
127 | this.View.EnableUseWindowsAuthentication = this.View.ConnectionSpec == null ? false : this.View.ConnectionSpec.UseWindowsAuthentication;
|
---|
128 |
|
---|
129 | if (this.View.ConnectionSpec != null)
|
---|
130 | {
|
---|
131 |
|
---|
132 |
|
---|
133 | if (this.View.ConnectionSpec.IsManageSpecsPlaceHolder)
|
---|
134 | {
|
---|
135 | this.ManageSpecifications();
|
---|
136 | this.UpdateConnectionSpecs();
|
---|
137 | return;
|
---|
138 | }
|
---|
139 |
|
---|
140 | //this.View.EnableUseWindowsAuthentication = this.View.ConnectionSpec.UseWindowsAuthentication;
|
---|
141 |
|
---|
142 | if (this.View.ConnectionSpec.UseWindowsAuthentication && this.Model.IsSwitchServerModeEnabled)
|
---|
143 | {
|
---|
144 | if (this.Model.PrimitiveAttemptWindowsAuthLogin(this.View.ConnectionSpec))
|
---|
145 | {
|
---|
146 | this.View.HideWait();
|
---|
147 | this.View.CloseView();
|
---|
148 | }
|
---|
149 |
|
---|
150 | }
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | private void ManageSpecifications()
|
---|
155 | {
|
---|
156 | RpmsServerConfigurationManagementDialog dialog = new RpmsServerConfigurationManagementDialog();
|
---|
157 | dialog.Settings = this.Model.Settings;
|
---|
158 | dialog.ShowDialog(this.View.UiOwner);
|
---|
159 | }
|
---|
160 |
|
---|
161 | void UpdateConnectionSpecs()
|
---|
162 | {
|
---|
163 | List<RpmsConnectionSpec> specs = new List<RpmsConnectionSpec>();
|
---|
164 |
|
---|
165 | specs.AddRange(this.Model.Settings.ConnectionSpecs);
|
---|
166 |
|
---|
167 | if (this.EnableConnectionManagement)
|
---|
168 | {
|
---|
169 | RpmsConnectionSpec manageSpec = new RpmsConnectionSpec();
|
---|
170 | manageSpec.IsManageSpecsPlaceHolder = true;
|
---|
171 | manageSpec.Name = "< Click to edit connections... >";
|
---|
172 | specs.Add(manageSpec);
|
---|
173 | }
|
---|
174 |
|
---|
175 | this.View.ConnectionSpec = null;
|
---|
176 | this.View.ConnectionSpecs = specs;
|
---|
177 | this.View.ConnectionSpec = this.Model.Settings.DefaultConnectionSpec;
|
---|
178 | }
|
---|
179 |
|
---|
180 | }
|
---|
181 | }
|
---|