using DevComponents.DotNetBar.Controls;
using PLC_Communication;
using PLCConnector;
using System;
using System.Collections.Generic;
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
{
///
/// 窗体初始化
///
public centralController()
{
InitializeComponent();
if (Monitor.Monitor.ins == null)
{
Monitor.Monitor.ins = new Monitor.Monitor(flowLayoutPanel1.Handle);
Monitor.Monitor.ins.Start();
}
//进度条测试
Task.Factory.StartNew(() =>
{
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)
{
dataGridViewX1.Invoke(new Action(() => { RefreshRecords(null, null); }));
break;
}
Thread.Sleep(300);
}
});
//定时器,定时更新停车记录
System.Windows.Forms.Timer recordsTimer = new System.Windows.Forms.Timer();
recordsTimer.Interval = 5000;
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();
//定时器,定时更新系统时间与剩余车位数
System.Windows.Forms.Timer freeSpaceTimer = new System.Windows.Forms.Timer();
freeSpaceTimer.Interval = 1000;
freeSpaceTimer.Tick += new EventHandler(UpdateFreeSpace);
freeSpaceTimer.Start();
UpdateBasicInfo();
tbx_notification.Text = "";
}
#region 测试
///
/// 获取号牌测试
///
///
///
private void button1_Click(object sender, EventArgs e)
{
string ip = textBox1.Text;
IPAddress temp;
if (IPAddress.TryParse(ip, out temp))
{
string license = "";
Task.Factory.StartNew(() =>
{
license = Monitor.Monitor.numMachineLinker.GetLicensePlate(1);
if (textBox2.InvokeRequired)
{
textBox2.Invoke(new Action(() => { textBox2.Text = license; }));
}
else
{
textBox2.Text = license;
}
});
}
}
#endregion
#region 系统
///
/// 结束按钮
///
///
///
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 文件
///
/// 打开日志
///
///
///
private void btn_openFile_Click(object sender, EventArgs e)
{
}
///
/// 刷新停车记录按钮
///
///
///
private void btn_refreshRecords_Click(object sender, EventArgs e)
{
RefreshRecords(null, null);
}
///
/// 导出停车记录按钮
///
///
///
private void btn_exportRecords_Click(object sender, EventArgs e)
{
Export(dataGridViewX1, Directory.GetCurrentDirectory() + "\\");
Console.WriteLine(Directory.GetCurrentDirectory() + "\\");
}
///
/// 显示与设置收费策略
///
///
///
private void btn_setScheme_Click(object sender, EventArgs e)
{
Form_paymentScheme form_PaymentScheme = new Form_paymentScheme();
form_PaymentScheme.ShowDialog();
}
#endregion
#region 视图
///
/// 车位视图
///
///
///
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; }
}
///
/// 显示号牌机视图
///
///
///
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; }
}
///
/// 支付视图
///
///
///
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; }
}
///
/// 显示测试选项卡
///
///
///
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; }
}
///
/// 终端视图
///
///
///
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; }
}
///
/// 停取记录
///
///
///
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 设备
///
/// 手动连接PLC
///
///
///
private void btn_linkPLC_Click(object sender, EventArgs e)
{
if (!Monitor.Monitor.PLC.isConnected)
{
Monitor.Monitor.PLC.PLCConnect();
}
}
///
/// PLC数据调试工具
///
///
///
private void btn_PLCConf_Click(object sender, EventArgs e)
{
FormPLCConf formPLCConf = new FormPLCConf();
formPLCConf.Show();
}
///
/// 启动号牌机调试工具
///
///
///
private void btn_numMachineConf_Click(object sender, EventArgs e)
{
FormModbus form = new FormModbus();
form.Show();
}
#endregion
///
/// 定时更新提示信息
///
///
///
private void UpdateText(object sender, EventArgs e)
{
tbx_notification.Text = Monitor.Monitor.GetNotification();
tbx_notification.ScrollToCaret();
}
///
/// 定时更新时间与空闲车位显示
///
///
///
private void UpdateFreeSpace(object sender, EventArgs e)
{
string currentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string freeSpace = "剩余车位:" + Monitor.Monitor.GetFreeSpaceCount();
string bookableSpace = "可预约车位:" + Monitor.Monitor.GetBookableSpaceCount();
lbx_freeSpace.Text = currentTime + "\r\n" + freeSpace + " " + bookableSpace;
}
///
/// 刷新停车记录显示
///
///
private void RefreshRecords(object data, EventArgs e)
{
dataGridViewX1.Rows.Clear();
List