DMSSSOLogin.cs
11.6 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Configuration;
using System.Globalization;
using System.Threading;
using System.IO;
using DMSSSOUpgrade;
namespace DMSSSOAgent
{
public partial class DMSSSOLogin : Form
{
#region 变量定义
public string P_UserName = "";
public string P_Password = "";
public string P_UserID = "";
public string P_UName = "";
private Point downPoint;
#endregion
#region 构造函数
public DMSSSOLogin()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
}
#endregion
#region Functions
#region Form Load
private void DMSSSOLogin_Load(object sender, EventArgs e)
{
try
{
//判断是否有新版本
DMSSSOService.SSOServices SSOServices = new global::DMSSSOAgent.DMSSSOService.SSOServices();
object[] oSysList = SSOServices.getUpdateInfor();
if (((System.Xml.XmlNode[])(oSysList[0]))[0].Value != ConfigurationSettings.AppSettings["VersionNo"].ToString())
{
//MessageBox.Show(((System.Xml.XmlNode[])(oSysList[0]))[0].Value + " versionNo" + ConfigurationSettings.AppSettings["VersionNo"].ToString());
//判断是否必须更新版本 1→是 0→否
if (((System.Xml.XmlNode[])(oSysList[4]))[0].Value == "1")
{
MessageBox.Show("有新版本必须更新!");
Application.Exit();
Process.Start("DMSSSOUpgrade.exe", Application.StartupPath + @"\DMSSSOUpgrade.exe");
}
else
{
if (MessageBox.Show("有新版本可更新,您是否更新!", "确认更新?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Application.Exit();
//Process.Start("DMSSSOUpgrade.exe", @"D:\Project\TNT\P-DMS SSO\Code\DMSSSO\DMSSSOUpgrade\bin\Debug\\DMSSSOUpgrade.exe");
Process.Start("DMSSSOUpgrade.exe",Application.StartupPath+ @"\DMSSSOUpgrade.exe");
}
}
}
GetDDLLanguageText();
ApplyResource();
string sProcessesName = ConfigurationSettings.AppSettings["ProcessesName"].ToString().Trim();
if (Process.GetProcessesByName(sProcessesName).Length > 1)
{
MessageBox.Show("The process is still live.");
this.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
#endregion
#region 记录日志
/// <summary>
///
/// </summary>
/// <param name="msg"></param>
public void WriteLog()
{
try
{
string filePath = Application.StartupPath + @"\IMG\";
string FileName = filePath + "SysLog.Log";
if (!File.Exists(FileName))
{
File.Create(FileName);
}
System.IO.StreamWriter sw = System.IO.File.AppendText(FileName);
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss: ") +" Button X:"+ btnLogin.Location.X.ToString()+"Y:"+btnLogin.Location.Y.ToString());
sw.Close();
}
catch(Exception ex)
{
throw (ex);
}
}
#endregion
#region Login
private void Login()
{
if (comBoxSelectLanguage.Text == "-Select Language-")
{
MessageBox.Show("Please Select Language");
return;
}
string username = "";
username = txtUserName.Text;
string password = "";
password = txtPassword.Text;
if (username == "" || password == "") return;
try
{
DMSSSOService.SSOServices SSOservice = new global::DMSSSOAgent.DMSSSOService.SSOServices();
object[] oUserInfo = SSOservice.validateUser(username, password);
if (oUserInfo == null) return;
if (((System.Xml.XmlNode[])(oUserInfo[0]))[0].Value == "SUCCESS")
{
P_UserID = ((System.Xml.XmlNode[])(oUserInfo[1]))[0].Value;
P_UserName = ((System.Xml.XmlNode[])(oUserInfo[2]))[0].Value;
P_Password = ((System.Xml.XmlNode[])(oUserInfo[3]))[0].Value;
P_UName = ((System.Xml.XmlNode[])(oUserInfo[4]))[0].Value;
ParameterSettings.UserID = ((System.Xml.XmlNode[])(oUserInfo[1]))[0].Value;
ParameterSettings.UserName = ((System.Xml.XmlNode[])(oUserInfo[2]))[0].Value;
ParameterSettings.Password = ((System.Xml.XmlNode[])(oUserInfo[3]))[0].Value;
ParameterSettings.Name = ((System.Xml.XmlNode[])(oUserInfo[4]))[0].Value;
if (ParameterSettings.IsReLogin == false)
{
this.DialogResult = DialogResult.OK;
}
else
{
this.Hide();
ParameterSettings.IsReLogin = true;
DMSSSOAgent fm = new DMSSSOAgent();
fm.ShowDialog();
this.Close();
this.Dispose();
}
}
else if (((System.Xml.XmlNode[])(oUserInfo[0]))[0].Value == "AD_FAILED")
{
MessageBox.Show("此账号在AD里没有通过验证,请联系Helpdesk");
}
else if (((System.Xml.XmlNode[])(oUserInfo[0]))[0].Value == "DMS_FAILED")
{
MessageBox.Show("此帐号无DMS权限,有问题请联系Helpdesk");
}
else if (((System.Xml.XmlNode[])(oUserInfo[0]))[0].Value == "DMS_PROHIBIT")
{
MessageBox.Show("此账号在DMS已禁用,有问题请联系Helpdesk ");
}
else
{
MessageBox.Show("Login Failed");
}
}
catch (Exception ex)
{
MessageBox.Show("Please check the network.");
}
}
#endregion
#region System Check
private bool SystemCheck()
{
bool returnvalue = false;
return returnvalue;
}
private bool ConfigCheck()
{
bool returnvalue = false;
return returnvalue;
}
private bool RCDirectoryCheck(ref string errormsg)
{
bool returnvalue = false;
return returnvalue;
}
private bool RCFileTypeCheck(ref string errormsg)
{
bool returnvalue = false;
return returnvalue;
}
#endregion
#region Apply Resource
/// <summary>
/// 应用资源
/// ApplyResources 的第一个参数为要设置的控件
/// 第二个参数为在资源文件中的ID,默认为控件的名称
/// </summary>
private void ApplyResource()
{
//获取语言
string language = ConfigurationSettings.AppSettings["language"].ToString().Trim();
if (language == "Default")
{
ConfigurationSettings.AppSettings["language"] = "en";
}
//更改当前线程的 CultureInfo
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(ConfigurationSettings.AppSettings["language"].ToString().Trim());
//Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en");
System.ComponentModel.ComponentResourceManager res = new ComponentResourceManager(typeof(DMSSSOLogin));
res.ApplyResources(lblUserName, "lblUserName");
res.ApplyResources(lblPassword, "lblPassword");
res.ApplyResources(btnLogin, "btnLogin");
res.ApplyResources(lblLanuage, "lblLanuage");
res.ApplyResources(this, "$this");
}
#endregion
#endregion
#region Button Events
private void btnLogin_Click(object sender, EventArgs e)
{
Login();
}
private void btnMini_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
this.Dispose();
Application.Exit();
}
#endregion
#region Mouse Event
private void DMSSSOLogin_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Location = new Point(this.Location.X + e.X - downPoint.X,
this.Location.Y + e.Y - downPoint.Y);
}
}
private void DMSSSOLogin_MouseDown(object sender, MouseEventArgs e)
{
downPoint = new Point(e.X, e.Y);
}
#endregion
#region Key Event
private void txtUserName_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsLower(e.KeyChar))
{
txtUserName.SelectedText = Char.ToUpper(e.KeyChar).ToString();
e.Handled = true;
}
}
#endregion
#region Languange Event
/// <summary>
/// 获取Lanuage
/// </summary>
public void GetDDLLanguageText()
{
if (ConfigurationSettings.AppSettings["language"] == "en")
{
comBoxSelectLanguage.Text = "English";
}
else if (ConfigurationSettings.AppSettings["language"] == "zh-CHS")
{
comBoxSelectLanguage.Text = "简体中文";
}
else if (ConfigurationSettings.AppSettings["language"] == "zh-CHT")
{
comBoxSelectLanguage.Text = "繁体中文";
}
else
{
comBoxSelectLanguage.Text = "-Select Language-";
}
}
/// <summary>
/// Language 选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comBoxSelectLanguage_SelectedIndexChanged(object sender, EventArgs e)
{
string s = comBoxSelectLanguage.Text;
if (s == "English")
{
ConfigurationSettings.AppSettings["language"] = "en";
}
else if (s == "简体中文")
{
ConfigurationSettings.AppSettings["language"] = "zh-CHS";
}
else if (s == "繁体中文")
{
ConfigurationSettings.AppSettings["language"] = "zh-CHT";
}
else
{
MessageBox.Show("Please Select Language");
}
ApplyResource();
}
#endregion
}
}