1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096 |
- using centralController.model;
- using DevComponents.DotNetBar.Controls;
- using nettyCommunication;
- using parkMonitor.LOG;
- using parkMonitor.model;
- using PLC_Communication;
- using PLCConnector;
- using PLCS7;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Net;
- using System.Runtime.InteropServices;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Terminal;
- using Excel = Microsoft.Office.Interop.Excel;
- namespace centralController
- {
- public partial class centralController : Form
- {
- private List<TermModel> TermDispList;
- private Dictionary<int, ParkingSpaceStru> idPssMap;
- private bool closing = false;
- /// <summary>
- /// 窗体初始化
- /// </summary>
- public centralController()
- {
- InitializeComponent();
- TermDispList = new List<TermModel>();
- idPssMap = new Dictionary<int, ParkingSpaceStru>();
- if (Monitor.Monitor.ins == null)
- {
- Monitor.Monitor.ins = new Monitor.Monitor(this, flowLayoutPanel1.Handle);
- }
- Monitor.Monitor.ins.Start();
- //进度条显示
- Task.Factory.StartNew(() =>
- {
- Stopwatch sw = new Stopwatch();
- sw.Start();
- int temp = 0;
- while (true)
- {
- if (temp != Monitor.Monitor.initializeState)
- {
- temp = Monitor.Monitor.initializeState;
- progressBar1.Invoke(new Action(() => { progressBar1.Value = temp * 20; }));
- }
- if (temp == 5)
- {
- dgvx_parkingRecords.Invoke(new Action(() =>
- {
- //RefreshRecords(null, null);
- //定时器,定时更新停车记录
- System.Windows.Forms.Timer recordsTimer = new System.Windows.Forms.Timer();
- recordsTimer.Interval = 10000;
- recordsTimer.Tick += new EventHandler(RefreshRecords);
- recordsTimer.Start();
- ////定时器,定时更新提示信息
- //System.Windows.Forms.Timer NoteTimer = new System.Windows.Forms.Timer();
- //NoteTimer.Interval = 1000;
- //NoteTimer.Tick += new EventHandler(UpdateText);
- //NoteTimer.Start();
- //地面车位显示
- Task.Factory.StartNew(() =>
- {
- UpdateAllTerms();
- });
- Task.Factory.StartNew(() =>
- {
- UpdateParkingSpaceView();
- });
- }));
- break;
- }
- sw.Stop();
- if (sw.ElapsedMilliseconds / 1000 > 45)
- {
- Log.WriteLog(LogType.process, LogFile.ERROR, "初始化超时");
- Monitor.Monitor.SetNotification("初始化超时,请检查连接后重启中控", TextColor.Error);
- this.Close();
- }
- Thread.Sleep(300);
- }
- });
- //定时器,定时更新系统时间与剩余车位数
- System.Windows.Forms.Timer freeSpaceTimer = new System.Windows.Forms.Timer();
- freeSpaceTimer.Interval = 1000;
- freeSpaceTimer.Tick += new EventHandler(UpdateFreeSpace);
- freeSpaceTimer.Start();
- rtb_notification.Text = "";
- }
- /// <summary>
- /// 实时更新所有车位显示
- /// </summary>
- private void UpdateAllTerms()
- {
- while (!closing)
- {
- List<TerminalStru> tList = Terminal.Terminal.terminalInfo;
- this.Invoke(new Action(() =>
- {
- int currentDispID = 0;
- //出现终端丢失情况,必定是与PLC连接问题导致数据异常,重新初始化显示模块
- for (int i = 0; i < TermDispList.Count; i++)
- {
- bool finded = false;
- if (currentDispID < TermDispList[i].id)
- {
- currentDispID = TermDispList[i].id;
- for (int j = 0; j < tList.Count; j++)
- {
- if (currentDispID == tList[j].terminalID)
- {
- finded = true; break;
- }
- }
- }
- else
- {
- finded = false;
- }
- if (!finded)
- {
- flp_Term.Controls.Clear();
- TermDispList.Clear();
- Console.WriteLine("******************************");
- break;
- }
- }
- for (int i = 0; i < tList.Count; i++)
- {
- TerminalStru ts = tList[i];
- bool updated = false;
- for (int j = 0; j < TermDispList.Count; j++)
- {
- if (ts.terminalID == TermDispList[j].id)
- {
- UpdateTermGP(TermDispList[j], ts.terminalID,
- ts.terminalStatus == (short)1 ? true : false,
- ts.cmd == ts.terminalStatus ? true : false,
- ts.groundStatus == (short)1 ? true : false,
- ts.numMachineLaunch == (short)1 ? true : false);
- updated = true;
- break;
- }
- }
- if (!updated)
- InitTermGP(ts.terminalID,
- ts.terminalStatus == (short)1 ? true : false,
- ts.cmd == ts.terminalStatus ? true : false,
- ts.groundStatus == (short)1 ? true : false,
- ts.numMachineLaunch == (short)1 ? true : false);
- }
- }));
- Thread.Sleep(5000);
- }
- }
- /// <summary>
- /// 初始化地面车位信息
- /// </summary>
- /// <param name="id"></param>
- /// <param name="park"></param>
- /// <param name="launched"></param>
- /// <param name="groundSensor"></param>
- /// <param name="numMachine"></param>
- private void InitTermGP(int id, bool park, bool launched, bool groundSensor, bool numMachine)
- {
- GroupPanel gpTerm = new GroupPanel();
- PictureBox pbCar = new PictureBox();
- PictureBox pbNum = new PictureBox();
- pbNum.Dock = DockStyle.Top;
- //pbNum.Anchor = AnchorStyles.Top;
- pbNum.Image = Properties.Resources.numMachine;
- pbNum.Location = new Point(27, 1);
- pbNum.Name = "term" + id + "pbNum";
- pbNum.Size = new Size(50, 29);
- pbNum.SizeMode = PictureBoxSizeMode.Zoom;
- pbNum.TabStop = false;
- pbCar.Dock = DockStyle.Bottom;
- //pbCar.Anchor = ((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right);
- pbCar.Image = Properties.Resources.car;
- pbCar.Location = new Point(23, 45);
- pbCar.Name = "term" + id + "pbCar";
- pbCar.Size = new Size(56, 43);
- pbCar.SizeMode = PictureBoxSizeMode.Zoom;
- gpTerm.BackColor = SystemColors.AppWorkspace;
- gpTerm.CanvasColor = SystemColors.Control;
- gpTerm.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007;
- gpTerm.ColorTable = ePanelColorTable.Red;
- gpTerm.Controls.Add(pbCar);
- gpTerm.Controls.Add(pbNum);
- gpTerm.DisabledBackColor = Color.Empty;
- gpTerm.Name = "term" + id + "gp";
- gpTerm.Size = new Size(105, 112);
- gpTerm.Style.BackColor = Color.FromArgb(((int)(((byte)(229)))), ((int)(((byte)(191)))), ((int)(((byte)(191)))));
- gpTerm.Style.BackColor2 = Color.FromArgb(((int)(((byte)(211)))), ((int)(((byte)(150)))), ((int)(((byte)(150)))));
- gpTerm.Style.BackColorGradientAngle = 90;
- gpTerm.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid;
- gpTerm.Style.BorderBottomWidth = 1;
- gpTerm.Style.BorderColor = Color.FromArgb(((int)(((byte)(149)))), ((int)(((byte)(55)))), ((int)(((byte)(52)))));
- gpTerm.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid;
- gpTerm.Style.BorderLeftWidth = 1;
- gpTerm.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid;
- gpTerm.Style.BorderRightWidth = 1;
- gpTerm.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid;
- gpTerm.Style.BorderTopWidth = 1;
- gpTerm.Style.CornerDiameter = 4;
- gpTerm.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded;
- gpTerm.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center;
- gpTerm.Style.TextColor = Color.FromArgb(((int)(((byte)(99)))), ((int)(((byte)(36)))), ((int)(((byte)(35)))));
- gpTerm.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near;
- gpTerm.StyleMouseDown.CornerType = DevComponents.DotNetBar.eCornerType.Square;
- gpTerm.StyleMouseOver.CornerType = DevComponents.DotNetBar.eCornerType.Square;
- gpTerm.Text = "地面车位" + id;
- TermModel tm = new TermModel(gpTerm, pbNum, pbCar);
- UpdateTermGP(tm, id, park, launched, groundSensor, numMachine);
- TermDispList.Add(tm);
- flp_Term.Controls.Add(gpTerm);
- }
- /// <summary>
- /// 更新地面车位信息
- /// </summary>
- /// <param name="tm"></param>
- /// <param name="id"></param>
- /// <param name="park"></param>
- /// <param name="launched"></param>
- /// <param name="groundSensor"></param>
- /// <param name="numMachine"></param>
- private void UpdateTermGP(TermModel tm, int id, bool park, bool launched, bool groundSensor, bool numMachine)
- {
- tm.UpdateStatus(id, park, launched, groundSensor, numMachine);
- if (tm.gp != null)
- {
- //停取状态
- if (park)
- tm.gp.ColorTable = ePanelColorTable.Red;
- else
- tm.gp.ColorTable = ePanelColorTable.Green;
- //启动/空闲
- if (launched)
- tm.gp.BackColor = SystemColors.Highlight;
- else
- tm.gp.BackColor = SystemColors.AppWorkspace;
- //地感
- if (groundSensor && tm.pbCar != null)
- tm.pbCar.Visible = true;
- else
- tm.pbCar.Visible = false;
- //号牌机
- if (numMachine && tm.pbNum != null)
- tm.pbNum.Visible = true;
- else
- tm.pbNum.Visible = false;
- }
- }
- /// <summary>
- /// 更新立体停车位显示
- /// </summary>
- private void UpdateParkingSpaceView()
- {
- bool needUpdate = false;
- while (!closing)
- {
- List<ParkingSpaceStru> psList = Monitor.Monitor.parkingSpaceInfo;
- if (psList.Count <= 0)
- {
- Thread.Sleep(10000);
- continue;
- }
- //更新映射表
- if (idPssMap.Count != psList.Count)
- {
- idPssMap.Clear();
- for (int i = 0; i < psList.Count; i++)
- {
- idPssMap.Add(psList[i].parkingSpace, psList[i]);
- }
- }
- else
- {
- for (int i = 0; i < psList.Count; i++)
- {
- try
- {
- idPssMap[psList[i].parkingSpace] = psList[i];
- }
- catch { }
- }
- }
- TableLayoutPanel tlp = new TableLayoutPanel();
- tlp.Name = "tlp_ParkingSpace";
- tlp.ColumnCount = Monitor.Monitor.rows;
- tlp.RowCount = 1;
- tlp.Dock = DockStyle.Fill;
- tlp.AutoScroll = true;
- tlp.BackColor = SystemColors.GradientActiveCaption;
- this.Invoke(new Action(() =>
- {
- //List<TableLayoutPanel> tlpList = new List<TableLayoutPanel>();
- int blockSize = Monitor.Monitor.spacesInRow * Monitor.Monitor.floors * Monitor.Monitor.rows;
- int offset = (Monitor.Monitor.rows + 1 - ((blockSize / Monitor.Monitor.spacesInRow) % Monitor.Monitor.rows)) * Monitor.Monitor.spacesInRow;
- //创建控件
- if (ParkingSpaceMonitorPanel.Controls.Count == 0 || needUpdate)
- {
- for (int i = 0; i < Monitor.Monitor.rows; i++)
- {
- TableLayoutPanel temp = new TableLayoutPanel();
- temp.Name = "tlp_ParkingSpaceSection" + (i + 1).ToString();
- temp.RowCount = Monitor.Monitor.floors;
- temp.ColumnCount = Monitor.Monitor.spacesInRow;
- temp.Dock = DockStyle.Fill;
- temp.AutoSize = true;
- temp.BackColor = SystemColors.GradientActiveCaption;
- temp.Margin = new Padding(5, 2, 5, 2);
- for (int j = Math.Max(psList.Count, blockSize) - 1; j >= 0; j--)
- {
- Label lb = new Label();
- lb.Anchor = (AnchorStyles.Top | AnchorStyles.Left);
- lb.AutoSize = true;
- lb.Location = new Point(10, 10);
- lb.Margin = new Padding(3, 10, 3, 10);
- lb.Padding = new Padding(5);
- lb.Name = "lb_parkingSpace" + j;
- lb.TextAlign = ContentAlignment.MiddleCenter;
- if (((j + offset) / Monitor.Monitor.spacesInRow) % Monitor.Monitor.rows == i)
- {
- if (j > psList.Count - 1)
- {
- lb.Text = "#####";
- temp.Controls.Add(lb);
- lb.BackColor = GetPSColor(-1);
- }
- else
- {
- lb.Text = "车位" + psList[j].parkingSpace;
- lb.BackColor = GetPSColor(psList[j].spaceStatus);
- temp.Controls.Add(lb);
- }
- }
- }
- tlp.Controls.Add(temp);
- //tlpList.Add(temp);
- }
- ParkingSpaceMonitorPanel.Controls.Clear();
- ParkingSpaceMonitorPanel.Controls.Add(tlp);
- needUpdate = false;
- }
- //更新控件
- else
- {
- Control.ControlCollection psCC = ParkingSpaceMonitorPanel.Controls;
- foreach (Control segment in psCC)
- {
- Control.ControlCollection segmentCC = segment.Controls;
- //Console.WriteLine("seg::"+segmentCC.Count);
- foreach (Control spaces in segmentCC)
- {
- Control.ControlCollection spaceCC = spaces.Controls;
- //Console.WriteLine("spaces::"+spaceCC.Count);
- foreach (Control space in spaceCC)
- {
- if (space.GetType() == typeof(Label))
- {
- int index = -1;
- bool result = int.TryParse(space.Text.Substring(2), out index);
- //Console.WriteLine("text is :" + space.Text+", index:"+index);
- if (idPssMap.ContainsKey(index))
- {
- //Console.WriteLine("index:" + index+", status:"+ idPssMap[index].spaceStatus);
- space.BackColor = GetPSColor(idPssMap[index].spaceStatus);
- }
- else if (result)
- {
- needUpdate = true;
- //Console.WriteLine("need update:"+index);
- break;
- }
- }
- }
- }
- if (needUpdate)
- {
- break;
- }
- }
- }
- }));
- Thread.Sleep(5000);
- }
- }
- private Color GetPSColor(int status)
- {
- switch (status)
- {
- case 0: return Color.White;
- case 1: return Color.Yellow;
- case 2: return Color.SkyBlue;
- case 3: return Color.Blue;
- case 4: return Color.Red;
- default: return Color.Violet;
- }
- }
- #region 测试
- /// <summary>
- /// 获取号牌测试
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- //string ip = textBox1.Text;
- //IPAddress temp;
- //if (IPAddress.TryParse(ip, out temp))
- //{
- string license = "";
- int id = 0;
- int.TryParse(textBox1.Text, out id);
- Task.Factory.StartNew(() =>
- {
- license = Monitor.Monitor.numMachineLinker.GetLicensePlate(id);
- if (textBox2.InvokeRequired)
- {
- textBox2.Invoke(new Action(() => { textBox2.Text = license; }));
- }
- else
- {
- textBox2.Text = license;
- }
- });
- //}
- }
- /// <summary>
- /// 屏显测试
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, EventArgs e)
- {
- string disp = textBox1.Text;
- string audio = textBox2.Text;
- //Monitor.Monitor.allInOneMachine.DispForAWhile(0, disp, 10, 1, audio);
- //Monitor.Monitor.allInOneMachine.boardList[0].UpdateText(disp, 8);
- try
- {
- Monitor.Monitor.allInOneMachine.boardList[0].UpdateText(disp==""?"智象停车欢迎您!":disp, 30, int.Parse(audio));
- }
- catch { }
- //Monitor.Monitor.allInOneMachine.boardList[0].UpdateText("请将方向盘回正,带好随身携带的物品,关闭车窗与车门,收起后视镜,确认所有人员离开车辆后,操作终端停车", 30, 2);
- //Thread.Sleep(1000);
- //Monitor.Monitor.allInOneMachine.boardList[0].UpdateArrow(2, 5, 2);
- }
- /// <summary>
- /// 终端id获取测试
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- string license = textBox1.Text;
- int id = Monitor.Monitor.numMachineLinker.GetLicenseID(license);
- textBox2.Text = "终端" + id.ToString();
- }
- /// <summary>
- /// tableLayoutPanel测试
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- Control c = tableLayoutPanel3.GetControlFromPosition(0, 0);
- Console.WriteLine(tableLayoutPanel3.Controls.Count);
- Control c1 = tableLayoutPanel3.GetControlFromPosition(0, 1);
- Console.WriteLine(c1.Controls.Count);
- Console.WriteLine("...");
- }
- #endregion
- #region 系统
- /// <summary>
- /// 结束按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_exit_Click(object sender, EventArgs e)
- {
- //DialogResult result = MessageBox.Show("确定退出系统吗?", "温馨提示", MessageBoxButtons.OKCancel);
- //if (result.Equals(DialogResult.OK))
- //{
- // Monitor.Monitor.ins.Stop();
- // Close();
- //}
- Close();
- }
- #endregion
- #region 文件
- /// <summary>
- /// 打开日志
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_openFile_Click(object sender, EventArgs e)
- {
- }
- /// <summary>
- /// 刷新停车记录按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_recordManagement_Click(object sender, EventArgs e)
- {
- FormRecordsManager formRecordsManager = new FormRecordsManager();
- formRecordsManager.ShowDialog();
- }
- /// <summary>
- /// 导出停车记录按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_exportRecords_Click(object sender, EventArgs e)
- {
- Export(dgvx_parkingRecords, Directory.GetCurrentDirectory() + "\\");
- Console.WriteLine(Directory.GetCurrentDirectory() + "\\");
- }
- /// <summary>
- /// 显示与设置收费策略
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_setScheme_Click(object sender, EventArgs e)
- {
- FormPaymentScheme form_PaymentScheme = new FormPaymentScheme();
- form_PaymentScheme.ShowDialog();
- }
- /// <summary>
- /// 手动更新广告
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_advertUpdate_Click(object sender, EventArgs e)
- {
- Task.Factory.StartNew(() =>
- {
- MessageBox.Show("更新中,请稍候。", "提示");
- string adAlert = "";
- if (Monitor.Monitor.advertMgr != null)
- {
- if (Monitor.Monitor.advertMgr.UpdateAdvert(out adAlert))
- MessageBox.Show("更新成功\n" + adAlert, "提示");
- else
- MessageBox.Show("更新失败,请稍后重试", "提示");
- }
- });
- }
- /// <summary>
- /// 系统配置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_config_Click(object sender, EventArgs e)
- {
- FormSysConfig formSysConfig = new FormSysConfig();
- formSysConfig.ShowDialog();
- }
- #endregion
- #region 视图
- /// <summary>
- /// 车位视图
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_parkingSpace_Click(object sender, EventArgs e)
- {
- if (bar_mainWin.Visible == false) { bar_mainWin.Visible = true; }
- if (dci_ParkingSpace.Visible == false) { dci_ParkingSpace.Visible = true; }
- }
- /// <summary>
- /// 显示号牌机视图
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_numMachine_Click(object sender, EventArgs e)
- {
- if (bar_mainWin.Visible == false) { bar_mainWin.Visible = true; }
- if (dci_NumMachine.Visible == false) { dci_NumMachine.Visible = true; }
- }
- /// <summary>
- /// 支付视图
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_payment_Click(object sender, EventArgs e)
- {
- if (bar_mainWin.Visible == false) { bar_mainWin.Visible = true; }
- if (dci_payment.Visible == false) { dci_payment.Visible = true; }
- }
- /// <summary>
- /// 显示测试选项卡
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_test_Click(object sender, EventArgs e)
- {
- if (bar_mainWin.Visible == false) { bar_mainWin.Visible = true; }
- if (dci_Test.Visible == false) { dci_Test.Visible = true; }
- }
- /// <summary>
- /// 终端视图
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_terminals_Click(object sender, EventArgs e)
- {
- if (bar_side.Visible == false) { bar_side.Visible = true; }
- if (dci_terminal.Visible == false) { dci_terminal.Visible = true; }
- }
- /// <summary>
- /// 停取记录
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_records_Click(object sender, EventArgs e)
- {
- if (bar_bottom.Visible == false) { bar_bottom.Visible = true; }
- if (dci_ParkingRecords.Visible == false) { dci_ParkingRecords.Visible = true; }
- }
- #endregion
- #region 设备
- /// <summary>
- /// 手动连接PLC
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_linkPLC_Click(object sender, EventArgs e)
- {
- if (Monitor.Monitor.PLC != null)
- {
- if (!Monitor.Monitor.PLC.isConnected)
- {
- Monitor.Monitor.SetNotification("检测到PLC掉线,尝试重连", TextColor.Info);
- Monitor.Monitor.PLC.PLCConnect();
- Monitor.Monitor.updateCount = true;
- }
- else
- {
- //List<object> received = Monitor.Monitor.PLC.ReadFromPLC(PLCDataType.terminal, 0);
- //if (received.Count != Monitor.Monitor.plcTerminalCount)
- //{
- // Monitor.Monitor.SetNotification("检测到PLC数据异常", TextColor.Warning);
- Monitor.Monitor.SetNotification("尝试关闭并重新建立与PLC的连接", TextColor.Info);
- Monitor.Monitor.PLC.PLCDisconnect();
- Monitor.Monitor.PLC.PLCConnect();
- Monitor.Monitor.updateCount = true;
- //}
- //else
- //{
- // Monitor.Monitor.SetNotification("PLC连接正常,无需连接", TextColor.Info);
- //}
- }
- }
- }
- /// <summary>
- /// 手动连接Web
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_linkWeb_Click(object sender, EventArgs e)
- {
- Task.Factory.StartNew(() =>
- {
- Monitor.Monitor.webServer.Connect();
- });
- }
- /// <summary>
- /// PLC数据调试工具
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_PLCConf_Click(object sender, EventArgs e)
- {
- FormPLCConf formPLCConf = new FormPLCConf();
- formPLCConf.Show();
- }
- /// <summary>
- /// 启动号牌机调试工具
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_numMachineConf_Click(object sender, EventArgs e)
- {
- FormModbus form = new FormModbus();
- form.Show();
- }
- #endregion
- /// <summary>
- /// 更新提示信息,将被从外部调用
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void UpdateText(string str, TextColor tc, int maxlines)
- {
- if (!rtb_notification.Focused)
- rtb_notification.ScrollToCaret();
- string[] strs = rtb_notification.Text.Split('\n');
- //Console.WriteLine(strs.ToString());
- if (strs.Length > maxlines * 2)
- {
- string[] newStrs = new string[maxlines];
- Array.Copy(strs, strs.Length - maxlines, newStrs, 0, maxlines);
- string temp = String.Join("\n", newStrs);
- rtb_notification.Text = temp;
- }
- if (str == "clear")
- {
- rtb_notification.Clear();
- }
- else
- {
- //Console.WriteLine("---------------------");
- //Console.WriteLine(rtb_notification.SelectionStart);
- string appendingText = str;
- rtb_notification.AppendText(appendingText);
- string currentTxt = rtb_notification.Text;
- string temp = currentTxt.Substring(0, currentTxt.Length - appendingText.Length + 2);
- int index = temp.LastIndexOf("\n", temp.Length);
- //rtb_notification.Select(index < 0 ? 0 : index, appendingText.Length - 1);
- rtb_notification.Select(index < 0 ? 0 : index, appendingText.Length - 2);
- //Console.WriteLine("******************");
- //Console.WriteLine("选中 "+rtb_notification.SelectedText);
- //Console.WriteLine("******************");
- //rtb_notification.SelectionFont = new Font(rtb_notification.SelectionFont, FontStyle.Bold);
- switch (tc)
- {
- case TextColor.Log:
- rtb_notification.SelectionColor = Color.Gray;
- break;
- case TextColor.Info:
- rtb_notification.SelectionColor = Color.Black;
- break;
- case TextColor.Warning:
- rtb_notification.SelectionColor = Color.Orange;
- break;
- case TextColor.Error:
- rtb_notification.SelectionColor = Color.Red;
- break;
- }
- rtb_notification.Select(index + appendingText.Length - 1, 0);
- if (!rtb_notification.Focused)
- rtb_notification.ScrollToCaret();
- }
- //rtb_notification.Text = Monitor.Monitor.ins.GetNotification();
- }
- /// <summary>
- /// 定时更新时间与空闲车位显示,以及设备连接状态
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void UpdateFreeSpace(object sender, EventArgs e)
- {
- string currentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- string freeSpace = "剩余车位:" + Monitor.Monitor.ins.GetFreeSpaceCount(0);
- string bookableSpace = "可预约车位:" + Monitor.Monitor.ins.GetFreeSpaceCount(2);
- lbx_freeSpace.Text = currentTime + "\r\n" + freeSpace + " " + bookableSpace;
- lbx_PLCStatus.SymbolColor = (Monitor.Monitor.PLC != null && Monitor.Monitor.PLC.isConnected) ? Color.Green : Color.OrangeRed;
- lbx_webStatus.SymbolColor = (Monitor.Monitor.webServer != null && Monitor.Monitor.webServer.GetConnectStatus()) ? Color.Green : Color.OrangeRed;
- lbx_led1Status.SymbolColor = (Monitor.Monitor.allInOneMachine != null && Monitor.Monitor.allInOneMachine.boardList.Count > 0 && Monitor.Monitor.allInOneMachine.boardList[0].connected) ? Color.Green : Color.OrangeRed;
- }
- /// <summary>
- /// 刷新停车记录显示
- /// </summary>
- /// <param name="data"></param>
- private void RefreshRecords(object data, EventArgs e)
- {
- dgvx_parkingRecords.Rows.Clear();
- List<object[]> list = Monitor.Monitor.GetParkingRecords();
- List<object[]>.Enumerator listEnumer = list.GetEnumerator();
- while (listEnumer.MoveNext())
- {
- dgvx_parkingRecords.Rows.Add(listEnumer.Current);
- }
- }
- /// <summary>
- /// 导出excel文件
- /// </summary>
- /// <param name="dataGridView1"></param>
- /// <param name="path">绝对路径,"D:\\abc\\xxx.xls"</param>
- private void Export(DataGridViewX dataGridView1, string path)
- {
- try
- {
- if (dataGridView1.Rows.Count == 0)
- {
- return;
- }
- Excel.Application excel = new Excel.Application();
- excel.Visible = false;
- Excel.Workbook workbook = excel.Workbooks.Add(true);
- Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Worksheets[1];
- for (int i = 0; i < dataGridView1.Columns.Count; i++)
- {
- if (dataGridView1.Columns[i].Visible == true)
- {
- worksheet.Cells[1, i + 1] = dataGridView1.Columns[i].HeaderText;
- }
- }
- for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
- {
- System.Windows.Forms.Application.DoEvents();
- for (int j = 0; j < dataGridView1.Columns.Count; j++)
- {
- if (dataGridView1.Columns[j].Visible == true)
- {
- if (dataGridView1[j, i].ValueType == typeof(string))
- {
- worksheet.Cells[i + 2, j + 1] = "'" + dataGridView1[j, i].Value.ToString();
- }
- else
- {
- worksheet.Cells[i + 2, j + 1] = dataGridView1[j, i].Value.ToString();
- }
- }
- }
- }
- //设置禁止弹出保存和覆盖的询问提示框
- excel.DisplayAlerts = false;
- excel.AlertBeforeOverwriting = false;
- worksheet.Cells.Columns.AutoFit();
- //保存写入的数据,这里还没有保存到磁盘
- workbook.Saved = true;
- if (Directory.Exists(path))
- {
- //设置新建文件路径及名称
- string savePath = path + DateTime.Now.ToString("yyyy-MM-dd") + "停车记录.xls";
- //创建文件
- FileStream file = new FileStream(savePath, FileMode.CreateNew);
- //关闭释放流,不然没办法写入数据
- file.Close();
- file.Dispose();
- //保存到指定的路径
- workbook.SaveCopyAs(savePath);
- }
- workbook.Close(false, Type.Missing, Type.Missing);
- //确保Excel进程关闭
- excel.Quit();
- //释放 COM 对象
- Marshal.ReleaseComObject(worksheet);
- Marshal.ReleaseComObject(workbook);
- Marshal.ReleaseComObject(excel);
- excel = null;
- worksheet = null;
- workbook = null;
- GC.Collect();//如果不使用这条语,excel会无法正常退出
- }
- catch (Exception e) { Console.WriteLine("导出excel文件异常," + e.Message); }
- }
- /// <summary>
- /// 动态调整号牌机界面
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void flowLayoutPanel1_Resize(object sender, EventArgs e)
- {
- Control.ControlCollection flpCC = flowLayoutPanel1.Controls;
- try
- {
- int rows = (int)Math.Sqrt(flowLayoutPanel1.Controls.Count + 1);
- int columns = (int)(flowLayoutPanel1.Controls.Count * 1.0 / rows + 1);
- for (int i = 0; i < flpCC.Count; i++)
- {
- flpCC[i].Width = (int)(flowLayoutPanel1.Width * 1.0 / (columns * 1.1));
- flpCC[i].Height = (int)(flowLayoutPanel1.Height * 1.0 / (rows * 1.15));
- Console.WriteLine("flp::" + flowLayoutPanel1.Width + "," + flowLayoutPanel1.Height);
- //Console.WriteLine("tlp--"+flpCC[i].Width + "," + flpCC[i].Height);
- Control.ControlCollection tlpCC = flpCC[i].Controls;
- if (tlpCC.Count == 2)
- {
- tlpCC[0].Width = (int)(flpCC[i].Width * 0.95);
- tlpCC[0].Height = (int)(flpCC[i].Height * 0.79);
- tlpCC[1].Width = (int)(flpCC[i].Width * 0.95);
- tlpCC[1].Height = (int)(flpCC[i].Height * 0.20);
- }
- }
- }
- catch (Exception ex) { Console.WriteLine(ex.Message); }
- }
- /// <summary>
- /// 右上角关闭函数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void centralController_FormClosing(object sender, FormClosingEventArgs e)
- {
- DialogResult result = MessageBox.Show("确定退出系统吗?", "温馨提示", MessageBoxButtons.OKCancel);
- if (result.Equals(DialogResult.OK))
- {
- Monitor.Monitor.ins.Stop();
- closing = true;
- }
- else
- {
- e.Cancel = true;
- }
- }
- #region 帮助
- /// <summary>
- /// 系统信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_sysInfo_Click(object sender, EventArgs e)
- {
- FormSysInfo sysInfo = new FormSysInfo(Monitor.Monitor.GetSysInfo());
- sysInfo.ShowDialog();
- }
- /// <summary>
- /// 关于我们信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btn_about_Click(object sender, EventArgs e)
- {
- FormAboutUs aboutUs = new FormAboutUs(Monitor.Monitor.GetAboutInfo());
- aboutUs.ShowDialog();
- }
- #endregion
- #region 快捷菜单栏
- /// <summary>
- /// 快捷显示系统信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void shortcut_sysInfo_Click(object sender, EventArgs e)
- {
- FormSysInfo sysInfo = new FormSysInfo(Monitor.Monitor.GetSysInfo());
- sysInfo.ShowDialog();
- }
- /// <summary>
- /// 快捷关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void shortcut_close_Click(object sender, EventArgs e)
- {
- Close();
- }
- /// <summary>
- /// 终止与启动流程
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void shortcut_pause_Click(object sender, EventArgs e)
- {
- if (shortcut_pause.Enabled)
- {
- shortcut_pause.Enabled = false;
- Monitor.Monitor.globalStatus = !Monitor.Monitor.globalStatus;
- if (Monitor.Monitor.globalStatus)
- {
- shortcut_pause.Image = Properties.Resources.circulate;
- shortcut_pause.Text = "点击终止";
- }
- else
- {
- shortcut_pause.Image = Properties.Resources.circulate2;
- shortcut_pause.Text = "点击启动";
- }
- Monitor.Monitor.SetNotification(Monitor.Monitor.globalStatus ? "工作正常" : "终止状态");
- Task.Factory.StartNew(() =>
- {
- Thread.Sleep(1500);
- try
- {
- this.Invoke(new Action(() =>
- {
- shortcut_pause.Enabled = true;
- }));
- }
- catch (Exception ex) { Console.WriteLine(ex.Message); }
- });
- }
- }
- /// <summary>
- /// 关于我们信息框
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void shortcut_about_Click(object sender, EventArgs e)
- {
- FormAboutUs aboutUs = new FormAboutUs(Monitor.Monitor.GetAboutInfo());
- aboutUs.ShowDialog();
- }
- #endregion
- /// <summary>
- /// 支付信息查询功能
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnx_paymentSearch_Click(object sender, EventArgs e)
- {
- DateTime start, end;
- string license = "";
- try
- {
- start = DateTime.Parse(dtp_paymentStartDate.Text);
- end = DateTime.Parse(dtp_paymentEndDate.Text);
- license = tb_paymentLicense.Text;
- }
- catch { MessageBox.Show("日期输入异常,请重新输入"); return; }
- dgvx_payment.Rows.Clear();
- List<object[]> list = Monitor.Monitor.GetParkingRecords(license, start.ToString("yyyy-MM-dd"), end.AddDays(1).ToString("yyyy-MM-dd"));
- List<object[]>.Enumerator listEnumer = list.GetEnumerator();
- while (listEnumer.MoveNext())
- {
- dgvx_payment.Rows.Add(listEnumer.Current);
- //Console.WriteLine(listEnumer.Current);
- }
- }
- /// <summary>
- /// 支付信息修改
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvx_payment_CellEndEdit(object sender, DataGridViewCellEventArgs e)
- {
- int columnIndex = e.ColumnIndex;
- int rowIndex = e.RowIndex;
- if (columnIndex == 8)
- {
- DataGridViewRow selectedRow = dgvx_payment.Rows[rowIndex];
- DataGridViewCellCollection cellCollection = selectedRow.Cells;
- string license = cellCollection[2].Value.ToString();
- string receiptNum = cellCollection[6].Value.ToString();
- string parkingFee = cellCollection[7].Value.ToString();
- string paymentStatus = cellCollection[8].Value.ToString();
- string notification = "确认将号牌 " + license + " 凭证号 " + receiptNum + " 的这条记录中,停车费用与支付状态改为 " + parkingFee + " 与 " + paymentStatus + " 吗?";
- DialogResult dResult = MessageBox.Show(notification, "修改确认", MessageBoxButtons.OKCancel);
- if (dResult == DialogResult.OK)
- {
- Monitor.Monitor.UpdateParkingRecords(license, receiptNum, parkingFee, paymentStatus, true);
- Monitor.Monitor.UpdateParkingRecords(license, receiptNum, parkingFee, paymentStatus, false);
- Monitor.Monitor.UpdateTermFeeStatus(receiptNum);
- Monitor.Monitor.SetNotification("支付信息已修改", TextColor.Warning);
- Log.WriteLog(LogType.process, LogFile.INFO, "手动修改支付信息,号牌:" + license + ",凭证号:" + receiptNum + ",停车费用与支付状态改为:\n" + parkingFee + "与" + paymentStatus);
- }
- }
- }
- }
- }
|