using DevComponents.DotNetBar.Controls;
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 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) { break; }
Thread.Sleep(200);
}
});
//TimerCallback tc = new TimerCallback(RefreshRecords);
//System.Threading.Timer t = new System.Threading.Timer(tc,null,5000,1000);
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Interval = 5000;
timer.Tick += new EventHandler(RefreshRecords);
timer.Start();
UpdateBasicInfo();
}
///
/// 结束按钮
///
///
///
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();
}
}
///
/// 获取号牌测试
///
///
///
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;
}
});
}
}
///
/// 手动连接PLC
///
///
///
private void btn_linkPLC_Click(object sender, EventArgs e)
{
if (!Monitor.Monitor.PLC.isConnected)
{
Monitor.Monitor.PLC.PLCConnect();
}
}
///
/// 刷新停车记录按钮
///
///
///
private void btn_refreshRecords_Click(object sender, EventArgs e)
{
RefreshRecords(null, null);
}
///
/// 刷新停车记录显示
///
///
private void RefreshRecords(object data, EventArgs e)
{
dataGridViewX1.Rows.Clear();
List