97efa01f7d2c0cb8af6808e36381059498b2f1a3.svn-base 17 KB

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