FormCentralController.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. using centralController.model;
  2. using DevComponents.DotNetBar.Controls;
  3. using nettyCommunication;
  4. using parkMonitor.model;
  5. using PLC_Communication;
  6. using PLCConnector;
  7. using PLCS7;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Drawing;
  11. using System.IO;
  12. using System.Net;
  13. using System.Runtime.InteropServices;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. using System.Windows.Forms;
  17. using Terminal;
  18. using Excel = Microsoft.Office.Interop.Excel;
  19. namespace centralController
  20. {
  21. public partial class centralController : Form
  22. {
  23. private List<TermModel> TermDispList;
  24. private bool closing = false;
  25. /// <summary>
  26. /// 窗体初始化
  27. /// </summary>
  28. public centralController()
  29. {
  30. InitializeComponent();
  31. TermDispList = new List<TermModel>();
  32. if (Monitor.Monitor.ins == null)
  33. {
  34. Monitor.Monitor.ins = new Monitor.Monitor(this, flowLayoutPanel1.Handle);
  35. }
  36. Monitor.Monitor.ins.Start();
  37. //进度条显示
  38. Task.Factory.StartNew(() =>
  39. {
  40. int temp = 0;
  41. while (true)
  42. {
  43. if (temp != Monitor.Monitor.initializeState)
  44. {
  45. temp = Monitor.Monitor.initializeState;
  46. progressBar1.Invoke(new Action(() => { progressBar1.Value = temp * 20; }));
  47. }
  48. if (temp == 5)
  49. {
  50. dgvx_parkingRecords.Invoke(new Action(() => { RefreshRecords(null, null); }));
  51. break;
  52. }
  53. Thread.Sleep(300);
  54. }
  55. });
  56. //定时器,定时更新停车记录
  57. System.Windows.Forms.Timer recordsTimer = new System.Windows.Forms.Timer();
  58. recordsTimer.Interval = 10000;
  59. recordsTimer.Tick += new EventHandler(RefreshRecords);
  60. recordsTimer.Start();
  61. ////定时器,定时更新提示信息
  62. //System.Windows.Forms.Timer NoteTimer = new System.Windows.Forms.Timer();
  63. //NoteTimer.Interval = 1000;
  64. //NoteTimer.Tick += new EventHandler(UpdateText);
  65. //NoteTimer.Start();
  66. //定时器,定时更新系统时间与剩余车位数
  67. System.Windows.Forms.Timer freeSpaceTimer = new System.Windows.Forms.Timer();
  68. freeSpaceTimer.Interval = 1000;
  69. freeSpaceTimer.Tick += new EventHandler(UpdateFreeSpace);
  70. freeSpaceTimer.Start();
  71. rtb_notification.Text = "";
  72. Task.Factory.StartNew(() =>
  73. {
  74. while (!closing)
  75. {
  76. List<TerminalStru> tList = Terminal.Terminal.terminalInfo;
  77. for (int i = 0; i < tList.Count; i++)
  78. {
  79. TerminalStru ts = tList[i];
  80. this.Invoke(new Action(() =>
  81. {
  82. bool updated = false;
  83. for (int j = 0; j < TermDispList.Count; j++)
  84. {
  85. if (ts.terminalID == TermDispList[j].id)
  86. {
  87. UpdateTermGP(TermDispList[j], ts.terminalID,
  88. ts.terminalStatus == (short)1 ? true : false,
  89. ts.cmd == ts.terminalStatus ? true : false,
  90. ts.groundStatus == (short)1 ? true : false,
  91. ts.numMachineLaunch == (short)1 ? true : false);
  92. updated = true;
  93. break;
  94. }
  95. }
  96. if (!updated)
  97. InitTermGP(ts.terminalID,
  98. ts.terminalStatus == (short)1 ? true : false,
  99. ts.cmd == ts.terminalStatus ? true : false,
  100. ts.groundStatus == (short)1 ? true : false,
  101. ts.numMachineLaunch == (short)1 ? true : false);
  102. }));
  103. }
  104. Thread.Sleep(5000);
  105. }
  106. });
  107. }
  108. private void InitTermGP(int id, bool park, bool launched, bool groundSensor, bool numMachine)
  109. {
  110. GroupPanel gpTerm = new GroupPanel();
  111. PictureBox pbCar = new PictureBox();
  112. PictureBox pbNum = new PictureBox();
  113. pbNum.Dock = DockStyle.Top;
  114. //pbNum.Anchor = AnchorStyles.Top;
  115. pbNum.Image = Properties.Resources.numMachine;
  116. pbNum.Location = new Point(27, 1);
  117. pbNum.Name = "term" + id + "pbNum";
  118. pbNum.Size = new Size(50, 29);
  119. pbNum.SizeMode = PictureBoxSizeMode.Zoom;
  120. pbNum.TabStop = false;
  121. pbCar.Dock = DockStyle.Bottom;
  122. //pbCar.Anchor = ((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right);
  123. pbCar.Image = Properties.Resources.car;
  124. pbCar.Location = new Point(23, 45);
  125. pbCar.Name = "term" + id + "pbCar";
  126. pbCar.Size = new Size(56, 43);
  127. pbCar.SizeMode = PictureBoxSizeMode.Zoom;
  128. gpTerm.BackColor = SystemColors.AppWorkspace;
  129. gpTerm.CanvasColor = SystemColors.Control;
  130. gpTerm.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007;
  131. gpTerm.ColorTable = ePanelColorTable.Red;
  132. gpTerm.Controls.Add(pbCar);
  133. gpTerm.Controls.Add(pbNum);
  134. gpTerm.DisabledBackColor = Color.Empty;
  135. gpTerm.Name = "term" + id + "gp";
  136. gpTerm.Size = new Size(105, 112);
  137. gpTerm.Style.BackColor = Color.FromArgb(((int)(((byte)(229)))), ((int)(((byte)(191)))), ((int)(((byte)(191)))));
  138. gpTerm.Style.BackColor2 = Color.FromArgb(((int)(((byte)(211)))), ((int)(((byte)(150)))), ((int)(((byte)(150)))));
  139. gpTerm.Style.BackColorGradientAngle = 90;
  140. gpTerm.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid;
  141. gpTerm.Style.BorderBottomWidth = 1;
  142. gpTerm.Style.BorderColor = Color.FromArgb(((int)(((byte)(149)))), ((int)(((byte)(55)))), ((int)(((byte)(52)))));
  143. gpTerm.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid;
  144. gpTerm.Style.BorderLeftWidth = 1;
  145. gpTerm.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid;
  146. gpTerm.Style.BorderRightWidth = 1;
  147. gpTerm.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid;
  148. gpTerm.Style.BorderTopWidth = 1;
  149. gpTerm.Style.CornerDiameter = 4;
  150. gpTerm.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded;
  151. gpTerm.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center;
  152. gpTerm.Style.TextColor = Color.FromArgb(((int)(((byte)(99)))), ((int)(((byte)(36)))), ((int)(((byte)(35)))));
  153. gpTerm.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near;
  154. gpTerm.StyleMouseDown.CornerType = DevComponents.DotNetBar.eCornerType.Square;
  155. gpTerm.StyleMouseOver.CornerType = DevComponents.DotNetBar.eCornerType.Square;
  156. gpTerm.Text = "地面车位" + id;
  157. TermModel tm = new TermModel(gpTerm, pbNum, pbCar);
  158. UpdateTermGP(tm, id, park, launched, groundSensor, numMachine);
  159. TermDispList.Add(tm);
  160. flp_Term.Controls.Add(gpTerm);
  161. }
  162. private void UpdateTermGP(TermModel tm, int id, bool park, bool launched, bool groundSensor, bool numMachine)
  163. {
  164. tm.UpdateStatus(id, park, launched, groundSensor, numMachine);
  165. if (tm.gp != null)
  166. {
  167. //停取状态
  168. if (park)
  169. tm.gp.ColorTable = ePanelColorTable.Red;
  170. else
  171. tm.gp.ColorTable = ePanelColorTable.Green;
  172. //启动/空闲
  173. if (launched)
  174. tm.gp.BackColor = SystemColors.Highlight;
  175. else
  176. tm.gp.BackColor = SystemColors.AppWorkspace;
  177. //地感
  178. if (groundSensor && tm.pbCar != null)
  179. tm.pbCar.Visible = true;
  180. else
  181. tm.pbCar.Visible = false;
  182. //号牌机
  183. if (numMachine && tm.pbNum != null)
  184. tm.pbNum.Visible = true;
  185. else
  186. tm.pbNum.Visible = false;
  187. }
  188. }
  189. #region 测试
  190. /// <summary>
  191. /// 获取号牌测试
  192. /// </summary>
  193. /// <param name="sender"></param>
  194. /// <param name="e"></param>
  195. private void button1_Click(object sender, EventArgs e)
  196. {
  197. string ip = textBox1.Text;
  198. IPAddress temp;
  199. if (IPAddress.TryParse(ip, out temp))
  200. {
  201. string license = "";
  202. int id = 0;
  203. int.TryParse(textBox1.Text, out id);
  204. Task.Factory.StartNew(() =>
  205. {
  206. license = Monitor.Monitor.numMachineLinker.GetLicensePlate(id);
  207. if (textBox2.InvokeRequired)
  208. {
  209. textBox2.Invoke(new Action(() => { textBox2.Text = license; }));
  210. }
  211. else
  212. {
  213. textBox2.Text = license;
  214. }
  215. });
  216. }
  217. }
  218. /// <summary>
  219. /// 屏显测试
  220. /// </summary>
  221. /// <param name="sender"></param>
  222. /// <param name="e"></param>
  223. private void button2_Click(object sender, EventArgs e)
  224. {
  225. string disp = textBox1.Text;
  226. string audio = textBox2.Text;
  227. Monitor.Monitor.allInOneMachine.DispForAWhile(0, disp, 10, 1, audio);
  228. }
  229. #endregion
  230. #region 系统
  231. /// <summary>
  232. /// 结束按钮
  233. /// </summary>
  234. /// <param name="sender"></param>
  235. /// <param name="e"></param>
  236. private void btn_exit_Click(object sender, EventArgs e)
  237. {
  238. //DialogResult result = MessageBox.Show("确定退出系统吗?", "温馨提示", MessageBoxButtons.OKCancel);
  239. //if (result.Equals(DialogResult.OK))
  240. //{
  241. // Monitor.Monitor.ins.Stop();
  242. // Close();
  243. //}
  244. Close();
  245. }
  246. #endregion
  247. #region 文件
  248. /// <summary>
  249. /// 打开日志
  250. /// </summary>
  251. /// <param name="sender"></param>
  252. /// <param name="e"></param>
  253. private void btn_openFile_Click(object sender, EventArgs e)
  254. {
  255. }
  256. /// <summary>
  257. /// 刷新停车记录按钮
  258. /// </summary>
  259. /// <param name="sender"></param>
  260. /// <param name="e"></param>
  261. private void btn_recordManagement_Click(object sender, EventArgs e)
  262. {
  263. FormRecordsManager formRecordsManager = new FormRecordsManager();
  264. formRecordsManager.ShowDialog();
  265. }
  266. /// <summary>
  267. /// 导出停车记录按钮
  268. /// </summary>
  269. /// <param name="sender"></param>
  270. /// <param name="e"></param>
  271. private void btn_exportRecords_Click(object sender, EventArgs e)
  272. {
  273. Export(dgvx_parkingRecords, Directory.GetCurrentDirectory() + "\\");
  274. Console.WriteLine(Directory.GetCurrentDirectory() + "\\");
  275. }
  276. /// <summary>
  277. /// 显示与设置收费策略
  278. /// </summary>
  279. /// <param name="sender"></param>
  280. /// <param name="e"></param>
  281. private void btn_setScheme_Click(object sender, EventArgs e)
  282. {
  283. FormPaymentScheme form_PaymentScheme = new FormPaymentScheme();
  284. form_PaymentScheme.ShowDialog();
  285. }
  286. /// <summary>
  287. /// 手动更新广告
  288. /// </summary>
  289. /// <param name="sender"></param>
  290. /// <param name="e"></param>
  291. private void btn_advertUpdate_Click(object sender, EventArgs e)
  292. {
  293. Task.Factory.StartNew(() =>
  294. {
  295. MessageBox.Show("更新中,请稍候。", "提示");
  296. string adAlert = "";
  297. if (Monitor.Monitor.advertMgr != null)
  298. {
  299. if (Monitor.Monitor.advertMgr.UpdateAdvert(out adAlert))
  300. MessageBox.Show("更新成功\n" + adAlert, "提示");
  301. else
  302. MessageBox.Show("更新失败,请稍后重试", "提示");
  303. }
  304. });
  305. }
  306. #endregion
  307. #region 视图
  308. /// <summary>
  309. /// 车位视图
  310. /// </summary>
  311. /// <param name="sender"></param>
  312. /// <param name="e"></param>
  313. private void btn_parkingSpace_Click(object sender, EventArgs e)
  314. {
  315. if (bar_mainWin.Visible == false) { bar_mainWin.Visible = true; }
  316. if (dci_ParkingSpace.Visible == false) { dci_ParkingSpace.Visible = true; }
  317. }
  318. /// <summary>
  319. /// 显示号牌机视图
  320. /// </summary>
  321. /// <param name="sender"></param>
  322. /// <param name="e"></param>
  323. private void btn_numMachine_Click(object sender, EventArgs e)
  324. {
  325. if (bar_mainWin.Visible == false) { bar_mainWin.Visible = true; }
  326. if (dci_NumMachine.Visible == false) { dci_NumMachine.Visible = true; }
  327. }
  328. /// <summary>
  329. /// 支付视图
  330. /// </summary>
  331. /// <param name="sender"></param>
  332. /// <param name="e"></param>
  333. private void btn_payment_Click(object sender, EventArgs e)
  334. {
  335. if (bar_mainWin.Visible == false) { bar_mainWin.Visible = true; }
  336. if (dci_payment.Visible == false) { dci_payment.Visible = true; }
  337. }
  338. /// <summary>
  339. /// 显示测试选项卡
  340. /// </summary>
  341. /// <param name="sender"></param>
  342. /// <param name="e"></param>
  343. private void btn_test_Click(object sender, EventArgs e)
  344. {
  345. if (bar_mainWin.Visible == false) { bar_mainWin.Visible = true; }
  346. if (dci_Test.Visible == false) { dci_Test.Visible = true; }
  347. }
  348. /// <summary>
  349. /// 终端视图
  350. /// </summary>
  351. /// <param name="sender"></param>
  352. /// <param name="e"></param>
  353. private void btn_terminals_Click(object sender, EventArgs e)
  354. {
  355. if (bar_side.Visible == false) { bar_side.Visible = true; }
  356. if (dci_terminal.Visible == false) { dci_terminal.Visible = true; }
  357. }
  358. /// <summary>
  359. /// 停取记录
  360. /// </summary>
  361. /// <param name="sender"></param>
  362. /// <param name="e"></param>
  363. private void btn_records_Click(object sender, EventArgs e)
  364. {
  365. if (bar_bottom.Visible == false) { bar_bottom.Visible = true; }
  366. if (dci_ParkingRecords.Visible == false) { dci_ParkingRecords.Visible = true; }
  367. }
  368. #endregion
  369. #region 设备
  370. /// <summary>
  371. /// 手动连接PLC
  372. /// </summary>
  373. /// <param name="sender"></param>
  374. /// <param name="e"></param>
  375. private void btn_linkPLC_Click(object sender, EventArgs e)
  376. {
  377. if (!Monitor.Monitor.PLC.isConnected)
  378. {
  379. Monitor.Monitor.PLC.PLCConnect();
  380. }
  381. }
  382. /// <summary>
  383. /// PLC数据调试工具
  384. /// </summary>
  385. /// <param name="sender"></param>
  386. /// <param name="e"></param>
  387. private void btn_PLCConf_Click(object sender, EventArgs e)
  388. {
  389. FormPLCConf formPLCConf = new FormPLCConf();
  390. formPLCConf.Show();
  391. }
  392. /// <summary>
  393. /// 启动号牌机调试工具
  394. /// </summary>
  395. /// <param name="sender"></param>
  396. /// <param name="e"></param>
  397. private void btn_numMachineConf_Click(object sender, EventArgs e)
  398. {
  399. FormModbus form = new FormModbus();
  400. form.Show();
  401. }
  402. #endregion
  403. /// <summary>
  404. /// 更新提示信息
  405. /// </summary>
  406. /// <param name="sender"></param>
  407. /// <param name="e"></param>
  408. public void UpdateText(string str, TextColor tc)
  409. {
  410. if (str == "clear")
  411. {
  412. rtb_notification.Clear();
  413. }
  414. else
  415. {
  416. string appendingText = str;
  417. rtb_notification.AppendText(appendingText);
  418. string currentTxt = rtb_notification.Text;
  419. string temp = currentTxt.Substring(0, currentTxt.Length - appendingText.Length + 2);
  420. int index = temp.LastIndexOf("\n", temp.Length);
  421. //rtb_notification.Select(index < 0 ? 0 : index, appendingText.Length - 1);
  422. rtb_notification.Select(index < 0 ? 0 : index, appendingText.Length - 2);
  423. //Console.WriteLine("******************");
  424. //Console.WriteLine("选中 "+rtb_notification.SelectedText);
  425. //Console.WriteLine("******************");
  426. //rtb_notification.SelectionFont = new Font(rtb_notification.SelectionFont, FontStyle.Bold);
  427. switch (tc)
  428. {
  429. case TextColor.Log:
  430. rtb_notification.SelectionColor = Color.Gray;
  431. break;
  432. case TextColor.Info:
  433. rtb_notification.SelectionColor = Color.Black;
  434. break;
  435. case TextColor.Warning:
  436. rtb_notification.SelectionColor = Color.Orange;
  437. break;
  438. case TextColor.Error:
  439. rtb_notification.SelectionColor = Color.Red;
  440. break;
  441. }
  442. rtb_notification.Select(index + appendingText.Length - 1, 0);
  443. }
  444. //rtb_notification.Text = Monitor.Monitor.ins.GetNotification();
  445. //rtb_notification.ScrollToCaret();
  446. }
  447. /// <summary>
  448. /// 定时更新时间与空闲车位显示
  449. /// </summary>
  450. /// <param name="sender"></param>
  451. /// <param name="e"></param>
  452. private void UpdateFreeSpace(object sender, EventArgs e)
  453. {
  454. string currentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  455. string freeSpace = "剩余车位:" + Monitor.Monitor.ins.GetFreeSpaceCount(0);
  456. string bookableSpace = "可预约车位:" + Monitor.Monitor.ins.GetFreeSpaceCount(2);
  457. lbx_freeSpace.Text = currentTime + "\r\n" + freeSpace + " " + bookableSpace;
  458. }
  459. /// <summary>
  460. /// 刷新停车记录显示
  461. /// </summary>
  462. /// <param name="data"></param>
  463. private void RefreshRecords(object data, EventArgs e)
  464. {
  465. dgvx_parkingRecords.Rows.Clear();
  466. List<object[]> list = Monitor.Monitor.GetParkingRecords();
  467. List<object[]>.Enumerator listEnumer = list.GetEnumerator();
  468. while (listEnumer.MoveNext())
  469. {
  470. dgvx_parkingRecords.Rows.Add(listEnumer.Current);
  471. }
  472. }
  473. /// <summary>
  474. /// 导出excel文件
  475. /// </summary>
  476. /// <param name="dataGridView1"></param>
  477. /// <param name="path">绝对路径,"D:\\abc\\xxx.xls"</param>
  478. private void Export(DataGridViewX dataGridView1, string path)
  479. {
  480. try
  481. {
  482. if (dataGridView1.Rows.Count == 0)
  483. {
  484. return;
  485. }
  486. Excel.Application excel = new Excel.Application();
  487. excel.Visible = false;
  488. Excel.Workbook workbook = excel.Workbooks.Add(true);
  489. Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Worksheets[1];
  490. for (int i = 0; i < dataGridView1.Columns.Count; i++)
  491. {
  492. if (dataGridView1.Columns[i].Visible == true)
  493. {
  494. worksheet.Cells[1, i + 1] = dataGridView1.Columns[i].HeaderText;
  495. }
  496. }
  497. for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
  498. {
  499. System.Windows.Forms.Application.DoEvents();
  500. for (int j = 0; j < dataGridView1.Columns.Count; j++)
  501. {
  502. if (dataGridView1.Columns[j].Visible == true)
  503. {
  504. if (dataGridView1[j, i].ValueType == typeof(string))
  505. {
  506. worksheet.Cells[i + 2, j + 1] = "'" + dataGridView1[j, i].Value.ToString();
  507. }
  508. else
  509. {
  510. worksheet.Cells[i + 2, j + 1] = dataGridView1[j, i].Value.ToString();
  511. }
  512. }
  513. }
  514. }
  515. //设置禁止弹出保存和覆盖的询问提示框
  516. excel.DisplayAlerts = false;
  517. excel.AlertBeforeOverwriting = false;
  518. worksheet.Cells.Columns.AutoFit();
  519. //保存写入的数据,这里还没有保存到磁盘
  520. workbook.Saved = true;
  521. if (Directory.Exists(path))
  522. {
  523. //设置新建文件路径及名称
  524. string savePath = path + DateTime.Now.ToString("yyyy-MM-dd") + "停车记录.xls";
  525. //创建文件
  526. FileStream file = new FileStream(savePath, FileMode.CreateNew);
  527. //关闭释放流,不然没办法写入数据
  528. file.Close();
  529. file.Dispose();
  530. //保存到指定的路径
  531. workbook.SaveCopyAs(savePath);
  532. }
  533. workbook.Close(false, Type.Missing, Type.Missing);
  534. //确保Excel进程关闭
  535. excel.Quit();
  536. //释放 COM 对象
  537. Marshal.ReleaseComObject(worksheet);
  538. Marshal.ReleaseComObject(workbook);
  539. Marshal.ReleaseComObject(excel);
  540. excel = null;
  541. worksheet = null;
  542. workbook = null;
  543. GC.Collect();//如果不使用这条语,excel会无法正常退出
  544. }
  545. catch (Exception e) { Console.WriteLine("导出excel文件异常," + e.Message); }
  546. }
  547. /// <summary>
  548. /// 动态调整号牌机界面
  549. /// </summary>
  550. /// <param name="sender"></param>
  551. /// <param name="e"></param>
  552. private void flowLayoutPanel1_Resize(object sender, EventArgs e)
  553. {
  554. Control.ControlCollection flpCC = flowLayoutPanel1.Controls;
  555. try
  556. {
  557. int rows = (int)Math.Sqrt(flowLayoutPanel1.Controls.Count + 1);
  558. int columns = (int)(flowLayoutPanel1.Controls.Count * 1.0 / rows + 1);
  559. for (int i = 0; i < flpCC.Count; i++)
  560. {
  561. flpCC[i].Width = (int)(flowLayoutPanel1.Width * 1.0 / (columns * 1.1));
  562. flpCC[i].Height = (int)(flowLayoutPanel1.Height * 1.0 / (rows * 1.15));
  563. Console.WriteLine("flp::" + flowLayoutPanel1.Width + "," + flowLayoutPanel1.Height);
  564. //Console.WriteLine("tlp--"+flpCC[i].Width + "," + flpCC[i].Height);
  565. Control.ControlCollection tlpCC = flpCC[i].Controls;
  566. if (tlpCC.Count == 2)
  567. {
  568. tlpCC[0].Width = (int)(flpCC[i].Width * 0.95);
  569. tlpCC[0].Height = (int)(flpCC[i].Height * 0.79);
  570. tlpCC[1].Width = (int)(flpCC[i].Width * 0.95);
  571. tlpCC[1].Height = (int)(flpCC[i].Height * 0.20);
  572. }
  573. }
  574. }
  575. catch (Exception ex) { Console.WriteLine(ex.Message); }
  576. }
  577. /// <summary>
  578. /// 右上角关闭函数
  579. /// </summary>
  580. /// <param name="sender"></param>
  581. /// <param name="e"></param>
  582. private void centralController_FormClosing(object sender, FormClosingEventArgs e)
  583. {
  584. DialogResult result = MessageBox.Show("确定退出系统吗?", "温馨提示", MessageBoxButtons.OKCancel);
  585. if (result.Equals(DialogResult.OK))
  586. {
  587. Monitor.Monitor.ins.Stop();
  588. closing = true;
  589. }
  590. else
  591. {
  592. e.Cancel = true;
  593. }
  594. }
  595. #region 帮助
  596. /// <summary>
  597. /// 系统信息
  598. /// </summary>
  599. /// <param name="sender"></param>
  600. /// <param name="e"></param>
  601. private void btn_sysInfo_Click(object sender, EventArgs e)
  602. {
  603. FormSysInfo sysInfo = new FormSysInfo(Monitor.Monitor.GetSysInfo());
  604. sysInfo.ShowDialog();
  605. }
  606. #endregion
  607. #region 快捷菜单栏
  608. private void shortcut_sysInfo_Click(object sender, EventArgs e)
  609. {
  610. FormSysInfo sysInfo = new FormSysInfo(Monitor.Monitor.GetSysInfo());
  611. sysInfo.ShowDialog();
  612. }
  613. private void shortcut_close_Click(object sender, EventArgs e)
  614. {
  615. DialogResult result = MessageBox.Show("确定退出系统吗?", "温馨提示", MessageBoxButtons.OKCancel);
  616. if (result.Equals(DialogResult.OK))
  617. {
  618. Monitor.Monitor.ins.Stop();
  619. closing = true;
  620. Close();
  621. }
  622. }
  623. #endregion
  624. }
  625. }