StartForm.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using System.Threading;
  6. using System.IO;
  7. using System.Linq;
  8. namespace MOTINOVA_Motor_Factory_Set
  9. {
  10. public partial class StartForm : Form
  11. {
  12. public static ftp myFtp = new ftp();
  13. public static server_cfg myServerCfg = new server_cfg();
  14. public static ImportForm ImportForm1 = new ImportForm();
  15. public static ExportForm ExportForm1 = new ExportForm();
  16. public static ManageForm ManageForm1 = new ManageForm();
  17. public static CheckForm CheckForm1 = new CheckForm();
  18. public static Enter EnterForm1 = new Enter();
  19. public static Note NoteForm = new Note();
  20. public static string UserPath = "";
  21. public static string Version = "Ver: V1.9.1";
  22. public static string BuildTime = "Build Time: 2024-07-02 18:00";
  23. public StartForm()
  24. {
  25. InitializeComponent();
  26. //配置网络服务参数
  27. myServerCfg.MyServerOption(Directory.GetCurrentDirectory() + "\\Server");
  28. //配置FTP服务器
  29. myFtp.FtpOption(myServerCfg.IP, myServerCfg.Port, myServerCfg.User, myServerCfg.PassWd, "factory_test", "ttium");// "admin", "ttium_admin");
  30. //配置数据存储路径
  31. UserPath = GetLogSavePath(Directory.GetCurrentDirectory() + "\\UserPath");
  32. ImportForm1.LocalCfgFilePath = UserPath + "\\cfg\\";
  33. ImportForm1.LogSavePath = UserPath + "\\walkTest\\";
  34. CheckForm1.LocalCfgFilePath = UserPath + "\\cfg\\";
  35. CheckForm1.LogSavePath = UserPath + "\\qcTest\\";
  36. ManageForm1.FilePath = UserPath + "\\cfg\\";
  37. ExportForm1.FilePath = UserPath + "\\cfg\\";
  38. ManageForm1.textBox_LocalPath.Text = UserPath;
  39. //检查本地文件夹
  40. if (!Directory.Exists(ImportForm1.LocalCfgFilePath))
  41. Directory.CreateDirectory(ImportForm1.LocalCfgFilePath);
  42. if (!Directory.Exists(ImportForm1.LogSavePath))
  43. Directory.CreateDirectory(ImportForm1.LogSavePath);
  44. if (!Directory.Exists(CheckForm1.LocalCfgFilePath))
  45. Directory.CreateDirectory(CheckForm1.LocalCfgFilePath);
  46. if (!Directory.Exists(CheckForm1.LogSavePath))
  47. Directory.CreateDirectory(CheckForm1.LogSavePath);
  48. if (!Directory.Exists(ManageForm1.FilePath))
  49. Directory.CreateDirectory(ManageForm1.FilePath);
  50. if (!Directory.Exists(ExportForm1.FilePath))
  51. Directory.CreateDirectory(ExportForm1.FilePath);
  52. //创建线程,定时检测网络连接状态
  53. Thread th = new Thread(NetworkCheck);
  54. th.IsBackground = true;
  55. th.Start();
  56. }
  57. //读取数据存储路径
  58. string GetLogSavePath(string fileName)
  59. {
  60. string result = "";
  61. try
  62. {
  63. //加载配置文件
  64. StreamReader objReader = new StreamReader(fileName);
  65. string sLine = "";
  66. List<string> array_CfgInfo = new List<string>();
  67. while (sLine != null)
  68. {
  69. sLine = objReader.ReadLine();
  70. array_CfgInfo.Add(sLine);
  71. }
  72. objReader.Close();
  73. result = array_CfgInfo[0].Substring(array_CfgInfo[0].LastIndexOf("=") + 1);
  74. if (result == "")
  75. {
  76. MessageBox.Show("文件加载失败,采用默认路径");
  77. result = Directory.GetCurrentDirectory();
  78. }
  79. }
  80. catch (Exception e)
  81. {
  82. MessageBox.Show("文件加载失败,采用默认路径", e.Message);
  83. result = Directory.GetCurrentDirectory();
  84. }
  85. return result;
  86. }
  87. //检查网络状态线程
  88. private void NetworkCheck()
  89. {
  90. //初始化第一次连接FTP服务器
  91. bool Result = myFtp.CheckFtp();
  92. this.Invoke((EventHandler)(delegate
  93. {
  94. if (Result == true)//服务器连接成功
  95. {
  96. label_NetStatus.Text = myServerCfg.ServerName + " | " + myServerCfg.IP + " | " + "连接成功";
  97. label_NetStatus.ForeColor = Color.Green;
  98. ImportForm1.label_NetStatus.Text = myServerCfg.ServerName + " | " + myServerCfg.IP + " | " + "连接成功";
  99. ImportForm1.label_NetStatus.BackColor = Color.Green;
  100. CheckForm1.label_NetStatus.Text = myServerCfg.ServerName + " | " + myServerCfg.IP + " | " + "连接成功";
  101. CheckForm1.label_NetStatus.BackColor = Color.Green;
  102. if (myServerCfg.Local == "DISABLE")//不允许本地文件
  103. {
  104. CheckForm1.checkBox_LocalFile.Checked = false;
  105. CheckForm1.checkBox_LocalFile.Enabled = false;
  106. ImportForm1.checkBox_LocalFile.Checked = false;
  107. ImportForm1.checkBox_LocalFile.Enabled = false;
  108. }
  109. else//允许本地文件,默认在线模式
  110. {
  111. CheckForm1.checkBox_LocalFile.Checked = false;
  112. CheckForm1.checkBox_LocalFile.Enabled = true;
  113. ImportForm1.checkBox_LocalFile.Checked = false;
  114. ImportForm1.checkBox_LocalFile.Enabled = true;
  115. }
  116. //检查最新版本号,与当前版本对比
  117. do
  118. {
  119. string[] VerOld = Version.Substring(6).Split('.');
  120. string[] VerNew = StartForm.myFtp.GetFileNameList(StartForm.myServerCfg.RootPath + "/version/")[0].Trim().Substring(1).Split('.');
  121. if (Convert.ToInt16(VerNew[0]) <= Convert.ToInt16(VerOld[0]))
  122. {
  123. if (Convert.ToInt16(VerNew[1]) <= Convert.ToInt16(VerOld[1]))
  124. {
  125. if (Convert.ToInt16(VerNew[2]) <= Convert.ToInt16(VerOld[2]))
  126. {
  127. break;
  128. }
  129. }
  130. }
  131. //下载最新版本
  132. if (MessageBox.Show("最新版本:" + StartForm.myFtp.GetFileNameList(StartForm.myServerCfg.RootPath + "/version/")[0].Trim() + ",确认更新?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  133. {
  134. string SavePath = Directory.GetCurrentDirectory();
  135. string[] FileList = myFtp.GetFileNameList("/MOTINOVA_MC_Factory_Set/version/update/");
  136. foreach (string file in FileList)
  137. myFtp.DownloadFile("/MOTINOVA_MC_Factory_Set/version/update/" + file, SavePath);
  138. MessageBox.Show("最新版本下载完成,请手动删除旧版本后重启\r\n最新版本:" + StartForm.myFtp.GetFileNameList(StartForm.myServerCfg.RootPath + "/version/")[0].Trim(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  139. this.Close();
  140. }
  141. else
  142. {
  143. MessageBox.Show("取消更新,自动退出!");
  144. this.Close();
  145. }
  146. } while (false);
  147. myFtp.IsNetConnected = true;
  148. }
  149. else//服务器连接失败
  150. {
  151. label_NetStatus.Text = "网络连接失败";
  152. label_NetStatus.ForeColor = Color.Red;
  153. ImportForm1.label_NetStatus.Text = "网络连接失败";
  154. ImportForm1.label_NetStatus.BackColor = Color.Red;
  155. CheckForm1.label_NetStatus.Text = "网络连接失败";
  156. CheckForm1.label_NetStatus.BackColor = Color.Red;
  157. if (myServerCfg.Local == "DISABLE")//不允许本地文件
  158. {
  159. CheckForm1.checkBox_LocalFile.Checked = false;
  160. CheckForm1.checkBox_LocalFile.Enabled = false;
  161. ImportForm1.checkBox_LocalFile.Checked = false;
  162. ImportForm1.checkBox_LocalFile.Enabled = false;
  163. }
  164. else//允许本地文件
  165. {
  166. CheckForm1.checkBox_LocalFile.Checked = true;
  167. CheckForm1.checkBox_LocalFile.Enabled = false;
  168. ImportForm1.checkBox_LocalFile.Checked = true;
  169. ImportForm1.checkBox_LocalFile.Enabled = false;
  170. }
  171. myFtp.IsNetConnected = false;
  172. if (MessageBox.Show("网络连接失败,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
  173. {
  174. this.Close();
  175. }
  176. }
  177. button_Export.Enabled = true;
  178. button_Import.Enabled = true;
  179. button_Mang.Enabled = true;
  180. button_Check.Enabled = true;
  181. }));
  182. //创建定时器,定时10s检查网络
  183. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  184. timer_CheckNet.Enabled = true;
  185. timer_CheckNet.Interval = 10000;
  186. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  187. timer_CheckNet.Start();
  188. while (true)
  189. {
  190. Thread.Sleep(1);
  191. }
  192. }
  193. //线程中定时任务,检查网络状态
  194. private void timer_CheckNet_Tick(object sender, EventArgs e)
  195. {
  196. //连接FTP服务器
  197. bool Result = myFtp.CheckFtp();
  198. this.Invoke((EventHandler)(delegate
  199. {
  200. if (Result == true)//服务器连接成功
  201. {
  202. label_NetStatus.Text = myServerCfg.ServerName + " | " + myServerCfg.IP + " | " + "连接成功";
  203. label_NetStatus.ForeColor = Color.Green;
  204. ImportForm1.label_NetStatus.Text = myServerCfg.ServerName + " | " + myServerCfg.IP + " | " + "连接成功";
  205. ImportForm1.label_NetStatus.BackColor = Color.Green;
  206. CheckForm1.label_NetStatus.Text = myServerCfg.ServerName + " | " + myServerCfg.IP + " | " + "连接成功";
  207. CheckForm1.label_NetStatus.BackColor = Color.Green;
  208. if (myServerCfg.Local == "DISABLE")//不允许本地文件
  209. {
  210. CheckForm1.checkBox_LocalFile.Enabled = false;
  211. ImportForm1.checkBox_LocalFile.Enabled = false;
  212. }
  213. else//允许本地文件
  214. {
  215. CheckForm1.checkBox_LocalFile.Enabled = true;
  216. ImportForm1.checkBox_LocalFile.Enabled = true;
  217. }
  218. myFtp.IsNetConnected = true;
  219. //定时与服务器同步文件
  220. #if false
  221. //cfg
  222. PathSyncWithServer("/cfg");
  223. //qcTest/errorlog
  224. PathSyncWithServer("/qcTest/errorlog");
  225. //qcTest/log
  226. PathSyncWithServer("/qcTest/log");
  227. //walkTest/errorlog
  228. PathSyncWithServer("/walkTest/errorlog");
  229. //walkTest/log
  230. PathSyncWithServer("/walkTest/log");
  231. #endif
  232. }
  233. else//服务器连接失败
  234. {
  235. label_NetStatus.Text = "网络连接失败";
  236. label_NetStatus.ForeColor = Color.Red;
  237. ImportForm1.label_NetStatus.Text = "网络连接失败";
  238. ImportForm1.label_NetStatus.BackColor = Color.Red;
  239. ImportForm1.checkBox_LocalFile.Checked = true;
  240. ImportForm1.checkBox_LocalFile.Enabled = false;
  241. CheckForm1.label_NetStatus.Text = "网络连接失败";
  242. CheckForm1.label_NetStatus.BackColor = Color.Red;
  243. CheckForm1.checkBox_LocalFile.Checked = true;
  244. CheckForm1.checkBox_LocalFile.Enabled = false;
  245. myFtp.IsNetConnected = false;
  246. //不允许离线使用时检查网络
  247. if (myServerCfg.Local == "DISABLE")//不允许本地文件
  248. {
  249. MessageBox.Show("请检查网络,或联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  250. System.Environment.Exit(0);
  251. }
  252. }
  253. }));
  254. }
  255. /// <summary>
  256. /// 获取本地和远端目录名差集,本地有但远端没有
  257. /// </summary>
  258. /// <param name="localPath">本地路径</param>
  259. /// <param name="remotePath">远端路径</param>
  260. /// <returns>差集文件夹名称集合</returns>
  261. private string[] FiltDiffDirectory(string localPath, string remotePath)
  262. {
  263. try
  264. {
  265. string[] Local = System.IO.Directory.GetDirectories(localPath);
  266. for (int i = 0; i < Local.Length; i++)
  267. Local[i] = Local[i].Substring(Local[i].LastIndexOf("\\") + 1);
  268. string[] Remote = StartForm.myFtp.GetDirectoryList(remotePath);
  269. for (int i = 0; i < Remote.Length; i++)
  270. Remote[i] = Remote[i].Substring(Remote[i].LastIndexOf("/") + 1);
  271. return Local.Except(Remote).ToList().ToArray();
  272. }
  273. catch (Exception ex)
  274. {
  275. throw new Exception("同步失败,原因: " + ex.Message);
  276. }
  277. }
  278. /// <summary>
  279. /// 获取本地和远端文件夹下目录名交集
  280. /// </summary>
  281. /// <param name="localPath"></param>
  282. /// <param name="remotePath"></param>
  283. /// <returns></returns>
  284. private string[] FiltCommonDirectory(string localPath, string remotePath)
  285. {
  286. try
  287. {
  288. string[] Local = System.IO.Directory.GetDirectories(localPath);
  289. for (int i = 0; i < Local.Length; i++)
  290. Local[i] = Local[i].Substring(Local[i].LastIndexOf("\\") + 1);
  291. string[] Remote = StartForm.myFtp.GetDirectoryList(remotePath);
  292. for (int i = 0; i < Remote.Length; i++)
  293. Remote[i] = Remote[i].Substring(Remote[i].LastIndexOf("/") + 1);
  294. return Local.Intersect(Remote).ToList().ToArray();
  295. }
  296. catch (Exception ex)
  297. {
  298. throw new Exception("同步失败,原因: " + ex.Message);
  299. }
  300. }
  301. /// <summary>
  302. /// 获取本地和远端文件名差集,本地存在而远端不存在
  303. /// </summary>
  304. /// <param name="localPath">本地路径</param>
  305. /// <param name="remotePath">远端路径</param>
  306. /// <returns>差集文件名集合</returns>
  307. private string[] FiltDiffFiles(string localPath, string remotePath)
  308. {
  309. try
  310. {
  311. string[] Local = System.IO.Directory.GetFiles(localPath);
  312. for (int i = 0; i < Local.Length; i++)
  313. Local[i] = Local[i].Substring(Local[i].LastIndexOf("\\") + 1);
  314. string[] Remote = StartForm.myFtp.GetFileNameList(remotePath);
  315. for (int i = 0; i < Remote.Length; i++)
  316. Remote[i] = Remote[i].Substring(Remote[i].LastIndexOf("/") + 1);
  317. return Local.Except(Remote).ToList().ToArray();
  318. }
  319. catch (Exception ex)
  320. {
  321. throw new Exception("同步失败,原因: " + ex.Message);
  322. }
  323. }
  324. /// <summary>
  325. /// 获取本地和远端文件名交集
  326. /// </summary>
  327. /// <param name="localPath"></param>
  328. /// <param name="remotePath"></param>
  329. /// <returns></returns>
  330. private string[] FiltCommonFiles(string localPath, string remotePath)
  331. {
  332. try
  333. {
  334. string[] Local = System.IO.Directory.GetFiles(localPath);
  335. for (int i = 0; i < Local.Length; i++)
  336. Local[i] = Local[i].Substring(Local[i].LastIndexOf("\\") + 1);
  337. string[] Remote = StartForm.myFtp.GetFileNameList(remotePath);
  338. for (int i = 0; i < Remote.Length; i++)
  339. Remote[i] = Remote[i].Substring(Remote[i].LastIndexOf("/") + 1);
  340. return Local.Intersect(Remote).ToList().ToArray();
  341. }
  342. catch (Exception ex)
  343. {
  344. throw new Exception("同步失败,原因: " + ex.Message);
  345. }
  346. }
  347. /// <summary>
  348. /// 同步本地和远端文件夹
  349. /// 本地有、远端无的文件夹,上传该目录下本地所有文件
  350. /// 本地有和远端有的文件夹,上传本地有但远端没有的文件
  351. /// </summary>
  352. /// <param name="PathName"></param>
  353. /// <returns></returns>
  354. private void PathSyncWithServer(string PathName)
  355. {
  356. List<string> pathResult = null;
  357. //获取本地和远端的目录差集
  358. pathResult = FiltDiffDirectory(UserPath + PathName, myServerCfg.RootPath + PathName).ToList();
  359. if (pathResult.Count != 0)
  360. {
  361. foreach (string path in pathResult)
  362. {
  363. //远端建立文件夹
  364. myFtp.MakeDir(myServerCfg.RootPath + PathName + "/" + path);
  365. //获取待上传文件列表
  366. string[] fileList = Directory.GetFiles(UserPath + PathName + "\\" + path);
  367. for (int i = 0; i < fileList.Length; i++)
  368. fileList[i] = fileList[i].Substring(fileList[i].LastIndexOf("\\") + 1);
  369. //上传文件
  370. if (fileList.Length != 0)
  371. {
  372. foreach (string file in fileList)
  373. {
  374. myFtp.UploadFile(UserPath + PathName + "\\" + path + "\\" + file, myServerCfg.RootPath + PathName + "/" + path);
  375. }
  376. }
  377. }
  378. }
  379. //获取本地和远端的目录交集
  380. pathResult = FiltCommonDirectory(UserPath + PathName, myServerCfg.RootPath + PathName).ToList();
  381. if (pathResult.Count != 0)
  382. {
  383. foreach (string path in pathResult)
  384. {
  385. //获取该目录本地和远端文件名的差集,本地有但远端无
  386. string[] fileList = FiltDiffFiles(UserPath + PathName + "\\" + path, myServerCfg.RootPath + PathName + "/" + path);
  387. //上传文件
  388. if (fileList.Length != 0)
  389. {
  390. foreach (string file in fileList)
  391. {
  392. myFtp.UploadFile(UserPath + PathName + "\\" + path + "\\" + file, myServerCfg.RootPath + PathName + "/" + path);
  393. }
  394. }
  395. }
  396. }
  397. }
  398. private void button_Import_Click(object sender, EventArgs e)
  399. {
  400. //不允许离线使用时检查网络
  401. if (myServerCfg.Local == "DISABLE")//不允许本地文件
  402. {
  403. if (myFtp.IsNetConnected == false)
  404. {
  405. MessageBox.Show("请检查网络,或联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  406. return;
  407. }
  408. }
  409. //输入用户名
  410. EnterForm1.ShowDialog();
  411. try
  412. {
  413. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//检验模式所有用户支持
  414. {
  415. CheckForm1.timer1.Enabled = false;
  416. if (EnterForm1.comboBox_User.Text == "武汉Wuhan") //武汉账户不使用本地文件,需要使用时采用工程账户登录
  417. ImportForm1.checkBox_LocalFile.Enabled = false;
  418. ImportForm1.ShowDialog();
  419. }
  420. else
  421. {
  422. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  423. }
  424. }
  425. catch (Exception)
  426. {
  427. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  428. }
  429. }
  430. private void button_Export_Click(object sender, EventArgs e)
  431. {
  432. //不允许离线使用时检查网络
  433. if (myServerCfg.Local == "DISABLE")//不允许本地文件
  434. {
  435. if (myFtp.IsNetConnected == false)
  436. {
  437. MessageBox.Show("请检查网络,或联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  438. return;
  439. }
  440. }
  441. EnterForm1.ShowDialog();
  442. try
  443. {
  444. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//生成参数模式仅用户PT
  445. {
  446. if (EnterForm1.comboBox_User.Text == "工程Engineer")
  447. {
  448. ExportForm1.ShowDialog();
  449. }
  450. else
  451. {
  452. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  453. }
  454. }
  455. else
  456. {
  457. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  458. }
  459. }
  460. catch (Exception)
  461. {
  462. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  463. }
  464. }
  465. private void button_Mang_Click(object sender, EventArgs e)
  466. {
  467. EnterForm1.ShowDialog();
  468. try
  469. {
  470. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//本地文件管理仅支持PT用户
  471. {
  472. if (EnterForm1.comboBox_User.Text == "工程Engineer")
  473. {
  474. ManageForm1.ShowDialog();
  475. }
  476. else
  477. {
  478. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  479. }
  480. }
  481. else
  482. {
  483. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  484. }
  485. }
  486. catch (Exception)
  487. {
  488. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  489. }
  490. }
  491. private void button_Check_Click(object sender, EventArgs e)
  492. {
  493. //不允许离线使用时,检查网络
  494. if (myServerCfg.Local == "DISABLE")//不允许本地文件
  495. {
  496. if (myFtp.IsNetConnected == false)
  497. {
  498. MessageBox.Show("请检查网络,或联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  499. return;
  500. }
  501. }
  502. //输入用户名
  503. EnterForm1.ShowDialog();
  504. try
  505. {
  506. if (EnterForm1.textBox_Passwd.Text == EnterForm1.UserAccount[EnterForm1.comboBox_User.Text])//所有用户支持
  507. {
  508. ImportForm1.timer1.Enabled = false;
  509. if (EnterForm1.comboBox_User.Text == "武汉Wuhan") //武汉账户不使用本地文件,需要使用时采用工程账户登录
  510. CheckForm1.checkBox_LocalFile.Enabled = false;
  511. CheckForm1.ShowDialog();
  512. }
  513. else
  514. {
  515. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  516. }
  517. }
  518. catch (Exception)
  519. {
  520. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  521. }
  522. }
  523. private void StartForm_Load(object sender, EventArgs e)
  524. {
  525. label_Ver.Text = Version + " " + BuildTime;
  526. }
  527. private void StartForm_FormClosing(object sender, FormClosingEventArgs e)
  528. {
  529. #if false
  530. //关闭前,删除本地所有配置文件
  531. string path = StartForm.UserPath + "\\cfg\\"; ;
  532. try
  533. {
  534. DirectoryInfo dir = new DirectoryInfo(path);
  535. FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
  536. foreach (FileSystemInfo i in fileinfo)
  537. {
  538. if (i is DirectoryInfo) //判断是否文件夹
  539. {
  540. DirectoryInfo subdir = new DirectoryInfo(i.FullName);
  541. subdir.Delete(true); //删除子目录和文件
  542. }
  543. else
  544. {
  545. File.Delete(i.FullName); //删除指定文件
  546. }
  547. }
  548. //MessageBox.Show("文件清理成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  549. }
  550. catch (Exception)
  551. {
  552. MessageBox.Show("文件清理失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  553. }
  554. #endif
  555. }
  556. }
  557. }