94768009c6416ff6c62bb1def3b3db54a8e68fe0.svn-base 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. using System;
  2. using System.IO;
  3. using System.Net;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Collections;
  7. using System.ComponentModel;
  8. using System.Windows.Forms;
  9. using System.Configuration;
  10. using System.Threading;
  11. using Core.Mes.IBaseInterface;
  12. using Core.Mes.ClientFrameWork;
  13. namespace Core.Mes.ClientManager
  14. {
  15. /// <summary>
  16. /// 登录窗口
  17. /// </summary>
  18. public class FrmCover : System.Windows.Forms.Form
  19. {
  20. #region " 定义变量 "
  21. public MainForm _mainForm;
  22. public static int pot;
  23. public static string url;
  24. public static string messageFlag;
  25. public int _loginFlag = 0;
  26. //重新登录标志
  27. public bool ReLoginFlag = false;
  28. private int index = 1;
  29. #endregion //
  30. #region " 窗体自动生成代码 "
  31. public FrmCover()
  32. {
  33. //
  34. // Windows 窗体设计器支持所必需的
  35. //
  36. InitializeComponent();
  37. //
  38. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  39. //
  40. }
  41. public FrmCover(string sUserName)
  42. {
  43. //
  44. // Windows 窗体设计器支持所必需的
  45. //
  46. InitializeComponent();
  47. textBox1.Text = sUserName;
  48. textBox1.Enabled = false;
  49. //
  50. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  51. //
  52. }
  53. /// <summary>
  54. /// 清理所有正在使用的资源。
  55. /// </summary>
  56. protected override void Dispose(bool disposing)
  57. {
  58. if (disposing)
  59. {
  60. if (components != null)
  61. {
  62. components.Dispose();
  63. }
  64. }
  65. base.Dispose(disposing);
  66. }
  67. private System.Windows.Forms.Label label4;
  68. private System.Windows.Forms.Label label5;
  69. private System.Windows.Forms.TextBox textBox1;
  70. private System.Windows.Forms.TextBox textBox2;
  71. private System.Windows.Forms.Button btnLoad;
  72. private System.Windows.Forms.ToolTip toolTip1;
  73. private System.Windows.Forms.Button btnExit;
  74. private System.Windows.Forms.PictureBox pictureBox1;
  75. private System.ComponentModel.IContainer components;
  76. private global::Infragistics.Win.UltraWinProgressBar.UltraProgressBar ultraProgressBar1;
  77. private System.Windows.Forms.Timer timerAutoRun;
  78. #region Windows 窗体设计器生成的代码
  79. /// <summary>
  80. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  81. /// 此方法的内容。
  82. /// </summary>
  83. private void InitializeComponent()
  84. {
  85. this.components = new System.ComponentModel.Container();
  86. Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
  87. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmCover));
  88. this.textBox1 = new System.Windows.Forms.TextBox();
  89. this.textBox2 = new System.Windows.Forms.TextBox();
  90. this.btnLoad = new System.Windows.Forms.Button();
  91. this.btnExit = new System.Windows.Forms.Button();
  92. this.pictureBox1 = new System.Windows.Forms.PictureBox();
  93. this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
  94. this.ultraProgressBar1 = new Infragistics.Win.UltraWinProgressBar.UltraProgressBar();
  95. this.timerAutoRun = new System.Windows.Forms.Timer(this.components);
  96. this.label4 = new System.Windows.Forms.Label();
  97. this.label5 = new System.Windows.Forms.Label();
  98. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
  99. this.SuspendLayout();
  100. //
  101. // textBox1
  102. //
  103. this.textBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Append;
  104. this.textBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
  105. this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  106. this.textBox1.Location = new System.Drawing.Point(150, 133);
  107. this.textBox1.Name = "textBox1";
  108. this.textBox1.Size = new System.Drawing.Size(120, 21);
  109. this.textBox1.TabIndex = 0;
  110. this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown);
  111. this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
  112. //
  113. // textBox2
  114. //
  115. this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  116. this.textBox2.Location = new System.Drawing.Point(150, 161);
  117. this.textBox2.Name = "textBox2";
  118. this.textBox2.PasswordChar = '*';
  119. this.textBox2.Size = new System.Drawing.Size(120, 21);
  120. this.textBox2.TabIndex = 1;
  121. this.textBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox2_KeyPress);
  122. //
  123. // btnLoad
  124. //
  125. this.btnLoad.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  126. this.btnLoad.ImageIndex = 0;
  127. this.btnLoad.Location = new System.Drawing.Point(282, 132);
  128. this.btnLoad.Name = "btnLoad";
  129. this.btnLoad.Size = new System.Drawing.Size(56, 23);
  130. this.btnLoad.TabIndex = 2;
  131. this.btnLoad.Text = "登录";
  132. this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click);
  133. //
  134. // btnExit
  135. //
  136. this.btnExit.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  137. this.btnExit.ImageIndex = 3;
  138. this.btnExit.Location = new System.Drawing.Point(282, 160);
  139. this.btnExit.Name = "btnExit";
  140. this.btnExit.Size = new System.Drawing.Size(55, 23);
  141. this.btnExit.TabIndex = 3;
  142. this.btnExit.Text = "退出";
  143. this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
  144. //
  145. // pictureBox1
  146. //
  147. this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Top;
  148. this.pictureBox1.Location = new System.Drawing.Point(0, 0);
  149. this.pictureBox1.Name = "pictureBox1";
  150. this.pictureBox1.Size = new System.Drawing.Size(450, 104);
  151. this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
  152. this.pictureBox1.TabIndex = 6;
  153. this.pictureBox1.TabStop = false;
  154. //
  155. // ultraProgressBar1
  156. //
  157. this.ultraProgressBar1.BorderStyle = Infragistics.Win.UIElementBorderStyle.None;
  158. this.ultraProgressBar1.Dock = System.Windows.Forms.DockStyle.Bottom;
  159. appearance1.ForeColor = System.Drawing.Color.Yellow;
  160. this.ultraProgressBar1.FillAppearance = appearance1;
  161. this.ultraProgressBar1.Location = new System.Drawing.Point(0, 213);
  162. this.ultraProgressBar1.Maximum = 300;
  163. this.ultraProgressBar1.Name = "ultraProgressBar1";
  164. this.ultraProgressBar1.Size = new System.Drawing.Size(450, 14);
  165. this.ultraProgressBar1.Step = 1;
  166. this.ultraProgressBar1.SupportThemes = false;
  167. this.ultraProgressBar1.TabIndex = 8;
  168. this.ultraProgressBar1.Text = "新余钢铁有限责任公司技术中心";
  169. //
  170. // timerAutoRun
  171. //
  172. this.timerAutoRun.Tick += new System.EventHandler(this.timerAutoRun_Tick);
  173. //
  174. // label4
  175. //
  176. this.label4.AutoSize = true;
  177. this.label4.Location = new System.Drawing.Point(105, 137);
  178. this.label4.Name = "label4";
  179. this.label4.Size = new System.Drawing.Size(41, 12);
  180. this.label4.TabIndex = 12;
  181. this.label4.Text = "用户名";
  182. //
  183. // label5
  184. //
  185. this.label5.AutoSize = true;
  186. this.label5.Location = new System.Drawing.Point(117, 165);
  187. this.label5.Name = "label5";
  188. this.label5.Size = new System.Drawing.Size(29, 12);
  189. this.label5.TabIndex = 13;
  190. this.label5.Text = "密码";
  191. //
  192. // FrmCover
  193. //
  194. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  195. this.ClientSize = new System.Drawing.Size(450, 227);
  196. this.Controls.Add(this.label5);
  197. this.Controls.Add(this.label4);
  198. this.Controls.Add(this.textBox2);
  199. this.Controls.Add(this.textBox1);
  200. this.Controls.Add(this.ultraProgressBar1);
  201. this.Controls.Add(this.btnExit);
  202. this.Controls.Add(this.btnLoad);
  203. this.Controls.Add(this.pictureBox1);
  204. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  205. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  206. this.MaximizeBox = false;
  207. this.MinimizeBox = false;
  208. this.Name = "FrmCover";
  209. this.ShowInTaskbar = false;
  210. this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
  211. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  212. this.Text = "系统用户登录";
  213. this.Load += new System.EventHandler(this.FrmCover_Load);
  214. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
  215. this.ResumeLayout(false);
  216. this.PerformLayout();
  217. }
  218. #endregion
  219. #endregion
  220. #region " Init Form "
  221. DataSet dsetLoginUrl = new DataSet();
  222. /// <summary>
  223. /// 窗体初始化
  224. /// </summary>
  225. /// <param name="sender"></param>
  226. /// <param name="e"></param>
  227. private void FrmCover_Load(object sender, System.EventArgs e)
  228. {
  229. try
  230. {
  231. if (ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings["Corporation"].Value.ToString() != null)
  232. this.ultraProgressBar1.Text = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings["Corporation"].Value.ToString() + @" & 湖南视拓科技发展有限责任公司 联合研发";
  233. this.pictureBox1.Image = System.Drawing.Image.FromFile(@"LoginPic.jpg");
  234. url = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings["RemoteServerUrl"].Value.ToString();
  235. if (File.Exists("LoginUrl.txt"))
  236. {
  237. dsetLoginUrl.ReadXml("LoginUrl.txt");
  238. dsetLoginUrl.Tables[0].PrimaryKey = new DataColumn[] { dsetLoginUrl.Tables[0].Columns[0] };
  239. foreach (DataRow arow in dsetLoginUrl.Tables[0].Rows)
  240. {
  241. textBox1.AutoCompleteCustomSource.Add(arow[0].ToString());
  242. }
  243. }
  244. else
  245. {
  246. DataTable dtab = new DataTable();
  247. dtab.Columns.Add("LogID", typeof(string));
  248. dtab.PrimaryKey = new DataColumn[] { dtab.Columns[0] };
  249. dsetLoginUrl.Tables.Add(dtab);
  250. dsetLoginUrl.WriteXml("LoginUrl.txt", XmlWriteMode.IgnoreSchema);
  251. }
  252. }
  253. catch (Exception ex)
  254. {
  255. Console.WriteLine(ex.Message);
  256. }
  257. this.textBox1.Focus();
  258. }
  259. #endregion
  260. #region " Button Event "
  261. private bool IsLoginThreadFlag = false;
  262. private string loginID = "";
  263. private string passwd = "";
  264. private bool IsException = false;
  265. private Thread ThLogin;
  266. /// <summary>
  267. /// 登录按钮事件
  268. /// </summary>
  269. /// <param name="sender"></param>
  270. /// <param name="e"></param>
  271. private void btnLoad_Click(object sender, System.EventArgs e)
  272. {
  273. loginID = this.textBox1.Text.Trim();
  274. passwd = this.textBox2.Text.Trim();
  275. this.timerAutoRun.Interval = 100;
  276. index = 1;
  277. IsException = false;
  278. this.ultraProgressBar1.Value = this.ultraProgressBar1.Minimum;
  279. this.btnLoad.Enabled = false;
  280. if (!ReLoginFlag)
  281. {
  282. //this.ultraProgressBar1.Visible = true;
  283. this.timerAutoRun.Start();
  284. ThreadStart ts = new ThreadStart(LoginHandler);
  285. ThLogin = new Thread(ts);
  286. ThLogin.Name = "LoginThread";
  287. ThLogin.Start();
  288. }
  289. else
  290. {
  291. try
  292. {
  293. string ipaddress = ClientCommon.GetIp();
  294. SimpleReturnObject _out = new SimpleReturnObject(0, "");
  295. ClientCommon._RemotingHelp.InitServerUrlList("ServerCommon", url);
  296. object obj = ClientCommon._RemotingHelp.ExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "GetPurviewInfo",
  297. new object[] { this.loginID, this.passwd, Dns.GetHostName(), ipaddress }, out _out);
  298. if (_out.ErrCode != 0) throw new Exception(_out.ErrMessage);
  299. if (!string.IsNullOrEmpty(_out.ErrMessage))
  300. {
  301. this._mainForm.ShowPopUpMsg(_out.ErrMessage, "密码过于简单,请尽快修改密码!");
  302. }
  303. ClientCommon._UserInfo = (UserInfo)obj;
  304. //===
  305. //==
  306. AfterLogin();
  307. //调用服务器与客户端时间同步函数
  308. SetTime.SetClientTime();
  309. }
  310. catch (Exception ex)
  311. {
  312. MessageBox.Show("连接服务器失败!\n" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  313. }
  314. this.btnLoad.Enabled = true;
  315. }
  316. }
  317. private void AfterLogin()
  318. {
  319. try
  320. {
  321. _loginFlag = 1;
  322. try
  323. {
  324. if (dsetLoginUrl.Tables[0].Rows.Find(textBox1.Text.Trim()) == null)
  325. {
  326. if (dsetLoginUrl.Tables[0].Rows.Count == 10)
  327. dsetLoginUrl.Tables[0].Rows[0].Delete();
  328. dsetLoginUrl.Tables[0].Rows.Add(new object[] { textBox1.Text.Trim() });
  329. dsetLoginUrl.Tables[0].AcceptChanges();
  330. dsetLoginUrl.WriteXml("LoginUrl.txt", XmlWriteMode.IgnoreSchema);
  331. }
  332. }
  333. catch
  334. { }
  335. this.Close();
  336. }
  337. catch (Exception ex)
  338. {
  339. this.btnLoad.Enabled = true;
  340. _loginFlag = 0;
  341. MessageBox.Show("连接服务器失败!\n" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  342. }
  343. }
  344. private void LoginHandler()
  345. {
  346. string ipaddress = ClientCommon.GetIp();
  347. try
  348. {
  349. IsLoginThreadFlag = false;
  350. SimpleReturnObject outInfo = new SimpleReturnObject(0, "");
  351. ClientCommon._RemotingHelp.InitServerUrlList("ServerCommon", url);
  352. object obj = ClientCommon._RemotingHelp.ExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "GetPurviewInfo",
  353. new object[] { this.loginID, this.passwd, Dns.GetHostName(), ipaddress }, out outInfo);
  354. if (outInfo.ErrCode != 0) throw new Exception(outInfo.ErrMessage);
  355. if (!string.IsNullOrEmpty(outInfo.ErrMessage))
  356. {
  357. this._mainForm.ShowPopUpMsg(outInfo.ErrMessage, "密码过于简单,请尽快修改密码!");
  358. }
  359. ClientCommon._UserInfo = (UserInfo)obj;
  360. ClientCommon._RemotingHelp.ServerUrlList = (DataSet)ClientCommon._RemotingHelp.ExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "GetServerList",
  361. null, out outInfo);
  362. _loginFlag = 1;
  363. IsLoginThreadFlag = true;
  364. }
  365. catch (Exception ex)
  366. {
  367. //this.btnLoad.Enabled =true;
  368. IsException = true;
  369. _loginFlag = 0;
  370. IsLoginThreadFlag = true;
  371. if (ex.Message == "线程正被中止。") return;
  372. MessageBox.Show("连接服务器失败!\n" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  373. }
  374. }
  375. private void btnExit_Click(object sender, System.EventArgs e)
  376. {
  377. _loginFlag = -1;
  378. try
  379. {
  380. this.timerAutoRun.Stop();
  381. if (ThLogin != null)
  382. {
  383. ThLogin.Abort();
  384. }
  385. }
  386. catch { }
  387. this.Close();
  388. }
  389. private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  390. {
  391. if (e.KeyChar == (char)13)
  392. {
  393. }
  394. if (e.KeyChar == (char)27)
  395. {
  396. this.btnExit_Click(sender, new EventArgs());
  397. }
  398. }
  399. private void textBox2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  400. {
  401. if (e.KeyChar == (char)13)
  402. {
  403. this.btnLoad_Click(sender, new EventArgs());
  404. }
  405. if (e.KeyChar == (char)27)
  406. {
  407. this.btnExit_Click(sender, new EventArgs());
  408. }
  409. }
  410. private void button1_Click(object sender, System.EventArgs e)
  411. {
  412. FrmPasswd frm = new FrmPasswd();
  413. frm.strUserID = this.textBox1.Text.Trim();
  414. frm.ShowDialog();
  415. }
  416. #endregion
  417. #region " Monuse Events "
  418. #endregion
  419. private void timerAutoRun_Tick(object sender, System.EventArgs e)
  420. {
  421. int current = this.ultraProgressBar1.Value;
  422. int max = this.ultraProgressBar1.Maximum;
  423. int min = this.ultraProgressBar1.Minimum;
  424. int step = this.ultraProgressBar1.Step;
  425. if (index++ > 300)
  426. {
  427. string strInfo = "";
  428. try
  429. {
  430. this.timerAutoRun.Stop();
  431. if (ThLogin != null)
  432. {
  433. ThLogin.Abort();
  434. }
  435. }
  436. catch (Exception ex)
  437. {
  438. strInfo = ex.Message;
  439. }
  440. MessageBox.Show("连接超时!\n" + strInfo, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  441. return;
  442. }
  443. if (current == max && step > 0)
  444. this.ultraProgressBar1.Value = min;
  445. this.ultraProgressBar1.PerformStep();
  446. if (IsLoginThreadFlag)
  447. {
  448. if (IsException)
  449. {
  450. this.timerAutoRun.Stop();
  451. //this.ultraProgressBar1.Visible = false;
  452. }
  453. if (this.ultraProgressBar1.Value != max)
  454. {
  455. this.timerAutoRun.Interval = 10;
  456. this.ultraProgressBar1.Step = 5;
  457. }
  458. else
  459. {
  460. this.timerAutoRun.Stop();
  461. this.AfterLogin();
  462. }
  463. }
  464. else
  465. {
  466. }
  467. }
  468. private void textBox1_KeyDown(object sender, KeyEventArgs e)
  469. {
  470. if (e.KeyData == System.Windows.Forms.Keys.Return)
  471. {
  472. System.Windows.Forms.SendKeys.Send("{TAB}");
  473. }
  474. }
  475. }
  476. }