using EC.AutoWeightServer.Center;
using EC.AutoWeightServer.IfManager.Speech;
using EC.AutoWeightServer.Model.Config;
using EC.AutoWeightServer.Model.EventArgsEx;
using EC.AutoWeightServer.Model.State;
using EC.AutoWeightServer.Properties;
using EC.Utils;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace EC.AutoWeightServer.UI
{
public partial class FrmMainServer : Base.FrmBase
{
internal LocalAttrCenter LocalAttrCenter { get; set; }
internal DeviceCenter DeviceCenter { get; set; }
public FrmMainServer()
{
InitializeComponent();
}
#region Gather
///
/// 主界面构造函数完成后加载的事件,用于加载摄像头事件
///
private void FrmMainServer_Loading(object sender, EventArgs e)
{
LocalAttrCenter = new LocalAttrCenter();
DeviceCenter = new DeviceCenter(this);
LocalAttrCenter.CheckSiteConfig();
DeviceCenter.OpenDevices();
DeviceCenter.CheckDevicesConnect();
LoadDevicesCallBack();
InitUiContent();
OpenCheckPhotoSaveCycle(true);
OpenTimeAuto();
OpenScrollTextLabel();
OpenWeightRecDataHandle();
OpenAutoDetectPlateHandle(true, true);
OpenStationBoardThread();
}
///
/// 退出系统事件触发后,冒泡捕捉的确认事件
///
///
///
private void FrmMainServer_Closing(object sender, FormClosingEventArgs e)
{
var enablePass = UiExtendCenter.VerifyUser(LocalAttrCenter.User);
if (!enablePass)
{
e.Cancel = true;
return;
}
DeviceCenter.CloseDevices();
CloseScrollTextLabel();
Environment.Exit(0);
}
private void LoadDevicesCallBack()
{
DeviceCenter.PlateManager1.PlateInfoCallBack += PlateCallBackInFront;
DeviceCenter.PlateManager2.PlateInfoCallBack += PlateCallBackInBack;
DeviceCenter.PlateManager3.PlateInfoCallBack += PlateCallBackOutFront;
DeviceCenter.PlateManager4.PlateInfoCallBack += PlateCallBackOutBack;
if (DeviceCenter.ScalesManager != null)
DeviceCenter.ScalesManager.OnRecData += WeightRecDataCallback;
}
private void InitUiContent()
{
Btn_Top_Click(null, null);
Btn_Max_Click(null, null);
ucCarIn.SetMainServer(this);
ucCarOut.SetMainServer(this);
panel9.Visible = (ServerConfig.ShowDebug > 0);
//引发的异常:“System.ArgumentException”(位于 mscorlib.dll 中)
//LabelCompany.Text = company.F_FullName;
//LabelSite.Text = site.Name;
//labelUserInfo.Text = $"管理员:{user?.F_RealName}";
}
#endregion Gather
#region 界面组件监听方法
///
/// 点击进入站点按钮所响应的事件
///
private void Btn_In_Click(object sender, EventArgs e)
{
var plate = "京AF0236";
PlateCallBackInFront(this, new PlateEventArgs(plate, "t1", "t2"));
}
///
/// 点击离开站点按钮所响应的事件
///
private void Btn_Out_Click(object sender, EventArgs e)
{
var plate = "京AF0236";
PlateCallBackOutFront(this, new PlateEventArgs(plate, "t1", "t2"));
}
///
/// 置顶
///
///
///
private void Btn_Top_Click(object sender, EventArgs e)
{
if (TopMost)
{
TopMost = false;
btnTop.Image = Resources.top1;
}
else
{
TopMost = true;
btnTop.Image = Resources.top2;
}
}
///
/// 窗口最小化
///
///
///
private void Btn_Min_Click(object sender, EventArgs e)
{
var enablePass = UiExtendCenter.VerifyUser(LocalAttrCenter.User);
if (!enablePass)
return;
WindowState = FormWindowState.Minimized;
}
///
/// 窗口最大化
///
///
///
private void Btn_Max_Click(object sender, EventArgs e)
{
switch (WindowState)
{
case FormWindowState.Maximized:
WindowState = FormWindowState.Normal;
btnMax.Image = Resources.max1;
break;
case FormWindowState.Minimized:
WindowState = FormWindowState.Maximized;
btnMax.Image = Resources.max2;
break;
case FormWindowState.Normal:
WindowState = FormWindowState.Maximized;
btnMax.Image = Resources.max2;
break;
}
}
///
/// 点击退出系统按钮所响应的事件
///
private void Btn_Close_Click(object sender, EventArgs e)
{
Close();
}
///
/// 点击重置系统按钮所响应的事件
///
///
///
private void Btn_Reset_Click(object sender, EventArgs e)
{
//var enablePass = UiExtendCenter.VerifyUser(LocalAttrCenter.User);
//if (!enablePass)
// return;
SetResetState();
}
private void Btn_History_Click(object sender, EventArgs e)
{
//var enablePass = UiExtendCenter.VerifyUser(LocalAttrCenter.User);
//if (!enablePass)
// return;
UiExtendCenter.ShowBillFrame(this);
}
#endregion 界面组件监听方法
#region 界面组件内容读写方法
internal string GetLabelPlate()
{
return LabelPlate.Text;
}
private void SetLabelPlate(string plate)
{
LabelPlate.Invoke((MethodInvoker)delegate ()
{
LabelPlate.Text = plate;
});
}
internal string GetLabelWeight()
{
return LabelWeight.Text;
}
private void SetLabelWeight(decimal weightDec)
{
LabelWeight.Invoke((MethodInvoker)delegate ()
{
var weightStr = CommonUtil.WeightDecToStr(weightDec, 3, '0');
LabelWeight.Text = weightStr;
});
}
private void SetLabelState(string txt)
{
LabelState.Invoke((MethodInvoker)delegate ()
{
LabelState.Text = txt;
});
}
private void SetLabelTime(string txt)
{
LabelTime.Invoke((MethodInvoker)delegate ()
{
LabelTime.Text = txt;
});
}
private string GetScrollLabelText()
{
return LabelScrollText.Text;
}
///
/// 设置跑马灯内容
///
///
internal void SetScrollLabelText(string text)
{
LabelScrollText.Invoke((MethodInvoker)delegate ()
{
var label = LabelScrollText;
var parent = label.Parent;
label.Text = text;
if (label.Width < parent.Width)
label.Left = 0;
else
label.Left = (int)(parent.Width * 0.10);
});
}
public void UcVisible()
{
Invoke((MethodInvoker)delegate ()
{
var state = LocalAttrCenter.GetCarState();
switch (state)
{
case CarState.Empty:
LabelLoading.Visible = true;
CommonUtil.SetTimeout(() =>
{
var method = new MethodInvoker(delegate
{
if (LocalAttrCenter.GetCarState() != CarState.Empty)
return;
ucCarIn.ClearBillComponent();
ucCarOut.ClearBillComponent();
LabelLoading.Visible = false;
ucCarOut.Visible = false;
ucCarIn.Visible = false;
ucWelcome.Visible = true;
});
Invoke(method);
}, 500);
break;
case CarState.In:
ucCarOut.Visible = false;
ucCarIn.Visible = true;
ucWelcome.Visible = false;
break;
case CarState.Out:
ucCarOut.Visible = true;
ucCarIn.Visible = false;
ucWelcome.Visible = false;
break;
}
});
}
#endregion 界面组件内容读写方法
#region 摄像头分流处理
private readonly HashSet _plateMap = new HashSet();
///
/// 1号摄像机,入场 前摄像头,处理入场开始前事件
///
///
private void PlateCallBackInFront(object sender, PlateEventArgs plateArgs)
{
string hint;
var state = LocalAttrCenter.GetCarState();
var plate = plateArgs.Plate;
switch (state)
{
case CarState.Empty:
if (ucCarOut.IsJustOutFinish(plate))
{
hint = $"{plate},出入站时间间隔小于{ServerConfig.BillInterval}秒!";
ShowRecvMessage(hint, true);
SetScrollLabelText(hint);
break;
}
SetLabelPlate(plate);
ucCarIn.InStartBill(plateArgs);
_plateMap.Remove(plate);
break;
case CarState.In:
if (plate.Equals(ucCarIn.GetLabelPlate()))
break;
if (_plateMap.Contains(plate))
break;
_plateMap.Add(plate);
hint = $"{plate}:请保持安全距离!";
SpeakHelper.SpeakAsync(hint);
ShowRecvMessage(hint, true);
break;
case CarState.Out:
if (plate.Equals(ucCarIn.GetLabelPlate()))
break;
if (_plateMap.Contains(plate))
break;
_plateMap.Add(plate);
hint = $"{plate},请保持安全距离!";
SpeakHelper.SpeakAsync(hint);
ShowRecvMessage(hint, true);
break;
}
}
///
/// 2号摄像机,入场 后摄像头,处理入场开始后事件
///
///
private void PlateCallBackInBack(object sender, PlateEventArgs plateArgs)
{
//const string now = "2号摄像头";
var state = LocalAttrCenter.GetCarState();
if (state != CarState.Empty)
return;
PlateCallBackOutFront(sender, plateArgs);
}
///
/// 3号摄像机,离场 前摄像头,处理离场开始前事件
///
///
private void PlateCallBackOutFront(object sender, PlateEventArgs plateArgs)
{
string hint;
var state = LocalAttrCenter.GetCarState();
var plate = plateArgs.Plate;
switch (state)
{
case CarState.Empty:
if (ucCarIn.IsJustInFinish(plate))
{
hint = $"{plate},出入站时间间隔小于{ServerConfig.BillInterval}秒!";
ShowRecvMessage(hint, true);
SetScrollLabelText(hint);
break;
}
SetLabelPlate(plate);
ucCarOut.OutStartBill(plateArgs);
_plateMap.Remove(plate);
break;
case CarState.In:
if (plate.Equals(ucCarOut.GetLabelPlate()))
break;
if (_plateMap.Contains(plate))
break;
_plateMap.Add(plate);
hint = $"{plate},请保持安全距离!";
SpeakHelper.SpeakAsync(hint);
ShowRecvMessage(hint, true);
break;
case CarState.Out:
if (plate.Equals(ucCarOut.GetLabelPlate()))
break;
if (_plateMap.Contains(plate))
break;
_plateMap.Add(plate);
hint = $"{plate},请保持安全距离!";
SpeakHelper.SpeakAsync(hint);
ShowRecvMessage(hint, true);
break;
}
}
///
/// 4号摄像机,离场 后摄像头,处理离场开始后事件
///
///
private void PlateCallBackOutBack(object sender, PlateEventArgs plateArgs)
{
//const string now = "4号摄像头";
var state = LocalAttrCenter.GetCarState();
if (state != CarState.Empty)
return;
PlateCallBackInFront(sender, plateArgs);
}
///
/// 用于展示操作错误,并给出相应提示
///
///
///
///
///
internal void ShowOperateException(Exception ex, bool enSpeak, bool showMsg, bool showHelp)
{
var msg = (string)ex.Data["msg"];
var help = (string)ex.Data["help"];
ControlLightLabel(false);//设置灯光
if (enSpeak)
SpeakHelper.SpeakAsync(msg);//陈述信息
if (showMsg)
ShowRecvMessage($"{msg}", true);//展示信息
if (showHelp)
SetScrollLabelText(help);//展示帮助
}
#endregion 摄像头分流处理
#region 界面切换
///
/// 设置入场开始状态
///
///
internal void SetInStartState(string plate)
{
const string now = "1号摄像头";
var hint = $"{plate},{VoiceConfig.InStartHint}";
var help = $"{plate},{VoiceConfig.InStartHelp}";
//var help = $"{plate},请输入运单重量,并等待自动计重。确认无误后,点击确认按钮确认,操作成功后方可完成入场!";
LocalAttrCenter.SetCarState(CarState.In);//设置入场状态
SetLabelState("入场");//设置状态文本
ControlLightOn(1);//设置灯光
UcVisible();//切换入场界面
SpeakHelper.SpeakAsync(hint);//陈述信息
CommonUtil.SetTimeout(() =>
{
SpeakHelper.SpeakAsync(VoiceConfig.InStartHint2);//陈述信息
}, VoiceConfig.HintInterval);
ShowRecvMessage($"{now}:{hint}");//展示信息
SetScrollLabelText(help);//展示帮助
}
///
/// 设置入场结束状态
///
///
internal void SetInFinishState(string plate)
{
const string now = "2号摄像头";
var hint = $"{plate},{VoiceConfig.InFinishHint}";
var help = $"{plate},{VoiceConfig.InFinishHelp}";
LocalAttrCenter.SetCarState(CarState.Empty);//设置空闲状态
SetLabelState("空闲");//设置状态文本
ControlLightOn(3);//设置灯光
UcVisible();//切换空闲界面
SpeakHelper.SpeakAsync(hint);//陈述信息
CommonUtil.SetTimeout(() =>
{
SpeakHelper.SpeakAsync(VoiceConfig.InFinishHint2);//陈述信息
}, VoiceConfig.HintInterval);
ShowRecvMessage($"{now}:{hint}");//展示信息
SetScrollLabelText(help);//展示帮助
}
///
/// 设置出场开始状态
///
///
internal void SetOutStartState(string plate)
{
const string now = "3号摄像头";
var hint = $"{plate},{VoiceConfig.OutStartHint}!";
var help = $"{plate},{VoiceConfig.OutStartHelp}";
//var help = $"{plate},请等待自动计重。确认无误后,点击签名按钮签名,点击打印按钮打印,并进行指纹比对,操作成功后方可完成出场!(请在左上角显示时间内完成入场)";
LocalAttrCenter.SetCarState(CarState.Out);//设置出场状态
SetLabelState("出场");//设置状态文本
ControlLightOn(4);//设置灯光
UcVisible();//切换出场界面
SpeakHelper.SpeakAsync(hint);//陈述信息
CommonUtil.SetTimeout(() =>
{
SpeakHelper.SpeakAsync(VoiceConfig.OutStartHint2);//陈述信息
}, VoiceConfig.HintInterval);
ShowRecvMessage($"{now}:{hint}");//展示信息
SetScrollLabelText(help);//展示帮助
}
///
/// 设置出场结束状态
///
///
internal void SetOutFinishState(string plate)
{
const string now = "4号摄像头";
var hint = $"{plate},{VoiceConfig.OutFinishHint}";
var help = $"{plate},{VoiceConfig.OutFinishHelp}";
LocalAttrCenter.SetCarState(CarState.Empty);//设置空闲状态
SetLabelState("空闲");//设置状态文本
ControlLightOn(2);//设置灯光
UcVisible();//切换空闲界面
SpeakHelper.SpeakAsync(hint);//陈述信息
CommonUtil.SetTimeout(() =>
{
SpeakHelper.SpeakAsync(VoiceConfig.OutFinishHint2);//陈述信息
}, VoiceConfig.HintInterval);
ShowRecvMessage($"{now}:{hint}");//展示信息
SetScrollLabelText(help);//展示帮助
}
///
/// 设置重置状态
///
///
///
internal void SetResetState(string hint = "", string help = "")
{
hint = hint.Equals("") ? "已完成重置!" : hint;
help = help.Equals("") ? "已完成重置,若自动识别车牌失效,请点击手动识别!" : help;
LocalAttrCenter.SetCarState(CarState.Empty);//设置空闲状态
SetLabelState("空闲");//设置状态文本
ControlLightOff();//设置灯光关闭
UcVisible();
//SpeakHelper.SpeakAsync(hint);//陈述信息
ShowRecvMessage(hint, true);//展示信息
SetScrollLabelText(help);//展示帮助
}
#endregion 界面切换
#region 称重回调处理
private readonly object _weightRecObj = new object();
///
/// 称重回调
///
///
///
private void WeightRecDataCallback(object sender, decimal dec)
{
BeginInvoke((MethodInvoker)new MethodInvoker(delegate
{
lock (_weightRecObj)
{
LocalAttrCenter.AppendWeight(dec);
SetLabelWeight(dec);
}
}));
}
private readonly object _weightRecHandleObj = new object();
///
/// ?,响应事件
///
private void OpenWeightRecDataHandle()
{
CommonUtil.SetInterval(() =>
{
lock (_weightRecHandleObj)
{
WeightRecDataHandle();
}
}, ServerConfig.WtInterval);
}
private void WeightRecDataHandle()
{
decimal? stableWeight;
var state = LocalAttrCenter.GetCarState();
switch (state)
{
case CarState.Empty:
//通过称重,识别到车离开称时,关闭所有灯光
if (LocalAttrCenter.IsLightOn() && LocalAttrCenter.IsCarOutDelayWeight())
{
ControlLightOff(false);
}
break;
case CarState.In:
//通过称重,识别到车入场到称上时,关闭所有灯光
if (LocalAttrCenter.IsLightOn() && LocalAttrCenter.IsCarInDelayWeight())
{
ControlLightOff(false);
break;
}
//是否入场
if (!string.IsNullOrEmpty(ucCarIn.GetLabelPlate()))
{
//没有取得稳定重量
if (string.IsNullOrEmpty(ucCarIn.GetLabelInWeight()))
{
stableWeight = LocalAttrCenter.GetStableWeight();
if (stableWeight != null)
{
var help = $"{VoiceConfig.InStableWeightHelp}";
SetScrollLabelText(help);//展示帮助
ucCarIn.SetLabelInWeight((decimal)stableWeight);
}
break;
}
//判断有无未确认入场
//if (LocalAttrCenter.IsLightOff() && LocalAttrCenter.IsCarOutDelayWeight())
//{
// ucCarIn.SafeTempBill();
// break;
//}
}
break;
case CarState.Out:
//通过称重,识别到车出场到称上时,关闭所有灯光
if (LocalAttrCenter.IsLightOn() && LocalAttrCenter.IsCarInDelayWeight())
{
ControlLightOff(false);
break;
}
//是否出场
if (!string.IsNullOrEmpty(ucCarOut.GetLabelPlate()))
{
//没有取得稳定重量
if (string.IsNullOrEmpty(ucCarOut.GetLabelOutWeight()))
{
stableWeight = LocalAttrCenter.GetStableWeight();
if (stableWeight != null)
{
ucCarOut.SetOutWeight((decimal)stableWeight);
var help = $"{VoiceConfig.OutStableWeightHelp}";
SetScrollLabelText(help); //展示帮助
}
break;
}
//判断有无未确认出场
//if (LocalAttrCenter.IsLightOff() && LocalAttrCenter.IsCarOutDelayWeight())
//{
// ucCarOut.SafeTempBill();
// break;
//}
}
break;
}
}
#endregion 称重回调处理
#region 控制灯光
///
/// 控制摄像头某个灯互斥亮
///
///
private void ControlLightOn(int index)
{
ControlLightLabel(true);
LocalAttrCenter.SetLightState(true);
switch (index)
{
case 1:
DeviceCenter.LightManager?.LockLightOn(1);
LightLabelTest(true, false, false, false);
break;
case 2:
DeviceCenter.LightManager?.LockLightOn(2);
LightLabelTest(false, true, false, false);
break;
case 3:
DeviceCenter.LightManager?.LockLightOn(4);
LightLabelTest(false, false, true, false);
break;
case 4:
DeviceCenter.LightManager?.LockLightOn(3);
LightLabelTest(false, false, false, true);
break;
}
}
///
/// 控制所有摄像头灯灭
///
///
private void ControlLightOff(bool useLabel = true)
{
if (useLabel)
ControlLightLabel(false);
DeviceCenter.LightManager?.CloseAllLight();
LocalAttrCenter.SetLightState(false);
LightLabelTest(false, false, false, false);
}
///
///
///
///
private void ControlLightLabel(bool on)
{
LabelLight.Invoke((MethodInvoker)delegate ()
{
LabelLight.Image = null;
if (on)
CommonUtil.SetTimeout(() => { LabelLight.Image = Resources.绿灯警示60; }, ServerConfig.LightBlink);
else
CommonUtil.SetTimeout(() => { LabelLight.Image = Resources.红灯警示60; }, ServerConfig.LightBlink);
});
}
///
/// 用于反应四个外灯运行状态
///
///
///
///
///
private void LightLabelTest(bool f1, bool f2, bool f3, bool f4)
{
panel6.Invoke((MethodInvoker)delegate ()
{
CommonUtil.SetTimeout(() => { lightLabel1.Image = f1 ? Resources.绿灯警示60 : Resources.红灯警示60; }, ServerConfig.LightBlink);
CommonUtil.SetTimeout(() => { lightLabel2.Image = f2 ? Resources.绿灯警示60 : Resources.红灯警示60; }, ServerConfig.LightBlink);
CommonUtil.SetTimeout(() => { lightLabel3.Image = f3 ? Resources.绿灯警示60 : Resources.红灯警示60; }, ServerConfig.LightBlink);
CommonUtil.SetTimeout(() => { lightLabel4.Image = f4 ? Resources.绿灯警示60 : Resources.红灯警示60; }, ServerConfig.LightBlink);
});
}
#endregion 控制灯光
#region 自动检测车牌
private readonly object _autoDetectObj = new object();
///
/// 打开自动检测车牌
///
private void OpenAutoDetectPlateHandle(bool front, bool back)
{
CommonUtil.SetInterval(() =>
{
lock (_autoDetectObj)
{
AutoDetectPlate();
}
}, ServerConfig.AutoDetectInterval);
}
///
/// 入场出场结束后,入场前摄像头和入场后摄像头,自动检测车牌
///
private void AutoDetectPlate()
{
var state = LocalAttrCenter.GetCarState();
if (state != CarState.Empty)
return;
ucLicensePlate1.ForceTrigger();
ucLicensePlate3.ForceTrigger();
}
#endregion 自动检测车牌
#region time
///
///
///
private void OpenTimeAuto()
{
CommonUtil.SetInterval(() =>
{
var str = DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss dddd");
SetLabelTime(str);
}, 1000);
}
#endregion time
#region 站牌
private void OpenStationBoardThread()
{
CommonUtil.SetInterval(() =>
{
if (DeviceCenter.LedZKManager == null || !DeviceCenter.LedZKManager.IsConnected())
return;
var type = ServerConfig.BoardType;
switch (type)
{
case 0:
Board0();
break;
case 1:
Board1();
break;
case 2:
Board2();
break;
default:
Board1();
break;
}
}, ServerConfig.BoardThreadInterval);
}
private void Board0()
{
var inCarNum = ServiceCenter.BillService.ComputeInCar8();
var carArea1Num = 4;
var carArea2Num = 2;
if (inCarNum <= 0)
{
carArea1Num = 4;
carArea2Num = 2;
}
else if (inCarNum <= 4)
{
carArea1Num = 4 - inCarNum;
carArea2Num = 2;
}
else if (inCarNum <= 6)
{
carArea1Num = 0;
carArea2Num = inCarNum - 4;
}
else
{
carArea1Num = 0;
carArea2Num = 0;
}
DeviceCenter.LedZKManager.SendDynamicArea(0, 0, 0, 96, 12, (carArea2Num > 0) ? @"\C2未满" : @"\C3已满", 0x01, 0x01, 10);
DeviceCenter.LedZKManager.SendDynamicArea(1, 0, 12, 96, 12, $@"\C1区域1余{((carArea1Num > 0) ? @"\C2" : @"\C3")}{carArea1Num}\C1车位", 0x01, 0x01, 10);
DeviceCenter.LedZKManager.SendDynamicArea(2, 0, 24, 96, 12, $@"\C1区域2余{((carArea2Num > 0) ? @"\C2" : @"\C3")}{carArea2Num}\C1车位", 0x01, 0x01, 10);
DeviceCenter.LedZKManager.SendDynamicMoveArea(3, 0, 36, 96, 12, @"\C1提高安全意识,落实操作规范!", 0x01, 0x01, 10);
}
private void Board1()
{
var list = ServiceCenter.BillService.ComputeInCarList();
var list1 = new List();
var num = (byte)list.Count;
var area1Num = 4;
var area2Num = 2;
if (num <= area1Num)
{
for (byte i = 0; i < num; i++)
list1.Add($@"\C2{list[i].LicensePlate}-{list[i].InStartTime:hh:mm}");
for (byte i = num; i < area1Num + 1; i++)
list1.Add("");
for (byte i = 0; i < list1.Count; i++)
DeviceCenter.LedZKManager.SendDynamicArea(i, 0, (ushort)(i * 12), 96, 12, list1[i], 0x01, 0x01, 10);
}
else if (num > area1Num)
{
for (byte i = 0; i < 4; i++)
list1.Add($@"\C2{list[i].LicensePlate}-{list[i].InStartTime:hh:mm}");
for (byte i = 0; i < list1.Count; i++)
DeviceCenter.LedZKManager.SendDynamicArea(i, 0, (ushort)(i * 12), 96, 12, list1[i], 0x01, 0x01, 10);
var list2 = list.Skip(4).Select(e => e.LicensePlate).ToList();
DeviceCenter.LedZKManager.SendDynamicMoveArea(4, 0, 48, 96, 16, $@"\C3{string.Join(",", list2)}", 0x01, 0x01, 10);
}
}
private void Board2()
{
var list = ServiceCenter.BillService.ComputeInCarList();
var list1 = new List();
var num = (byte)list.Count;
if (num <= 4)
{
for (byte i = 0; i < num; i++)
list1.Add($@"\C2{list[i].LicensePlate}-{list[i].InStartTime:hh:mm}");
DeviceCenter.LedZKManager.SendDynamicArea(0, 0, 0, 96, 48, String.Join(@"\n", list1), 0x02, 0x01, 10);
}
else if (num > 4)
{
for (byte i = 0; i < 4; i++)
list1.Add($@"\C2{list[i].LicensePlate}-{list[i].InStartTime:hh:mm}");
DeviceCenter.LedZKManager.SendDynamicArea(0, 0, 0, 96, 48, String.Join(@"\n", list1), 0x02, 0x01, 10);
var list2 = list.Skip(4).Select(e => e.LicensePlate).ToList();
DeviceCenter.LedZKManager.SendDynamicMoveArea(4, 0, 48, 96, 16, $@"\C3{String.Join(",", list2)}", 0x01, 0x01, 10);
}
//DeviceCenter.LedZKManager.SendDynamicMoveArea(0, 0, 0, 96, 12, @"\C2粤AAQ841 09:20:51", 0x01, 0x01, 10);
//DeviceCenter.LedZKManager.SendDynamicMoveArea(1, 0, 12, 96, 12, @"\C2粤AAQ842 09:20:52", 0x01, 0x01, 10);
//DeviceCenter.LedZKManager.SendDynamicMoveArea(2, 0, 24, 96, 12, @"\C2粤AAQ843 09:20:53", 0x01, 0x01, 10);
//DeviceCenter.LedZKManager.SendDynamicMoveArea(3, 0, 36, 96, 12, @"\C2粤AAQ844 09:20:54", 0x01, 0x01, 10);
//DeviceCenter.LedZKManager.SendDynamicMoveArea(4, 0, 48, 96, 16, @"\C3粤AAV141,粤AAV142,\C1粤AAM491,粤AAM492", 0x01, 0x01, 10);
//DeviceCenter.LedZKManager.SendDynamicArea(0, 0, 0, 96, 64,
// @"\C2粤AAQ841 09:20:51\n\C2粤AAQ842 09:20:52\n\C2粤AAQ843 09:20:53\n\C2粤AAQ844 09:20:54\n\C3粤AAV141,粤AAV142,\C1粤AAM491,粤AAM492",
// 0x02, 0x01, 10);
}
#endregion 站牌
#region 图片保存周期
private void OpenCheckPhotoSaveCycle(bool soon)
{
if (soon)
CheckPhotoSaveCycle();
var now = DateTime.Now;
var next = now.AddDays(1);
var timeSpan = new DateTime(next.Year, next.Month, next.Day) - now;
CommonUtil.SetTimeout(() =>
{
CheckPhotoSaveCycle();
OpenCheckPhotoSaveCycle(false);
}, timeSpan.TotalMilliseconds);
}
private void CheckPhotoSaveCycle()
{
var now = DateTime.Now;
var workPath = Directory.GetCurrentDirectory();
var capDir = new DirectoryInfo(Path.Combine(workPath, "cap"));
if (!capDir.Exists)
return;
try
{
foreach (var yearDir in capDir.GetDirectories())
{
if (!yearDir.Exists || !CommonUtil.IsInt(yearDir.Name))
continue;
var year = int.Parse(yearDir.Name);
foreach (var monthDir in yearDir.GetDirectories())
{
if (!monthDir.Exists || !CommonUtil.IsInt(monthDir.Name))
continue;
var month = int.Parse(monthDir.Name);
foreach (var dayDir in monthDir.GetDirectories())
{
if (!dayDir.Exists || !CommonUtil.IsInt(dayDir.Name))
continue;
var day = int.Parse(dayDir.Name);
var curTime = new DateTime(year, month, day);
var timeSpan = now - curTime;
var diff = timeSpan.Days + 1;
if (diff > ServerConfig.SavePhotoDay)
dayDir.Delete(true);
}
if (monthDir.GetDirectories().Length <= 0)
monthDir.Delete();
}
if (yearDir.GetDirectories().Length <= 0)
yearDir.Delete();
}
}
catch (Exception e)
{
LogUnit.Error(e.Message);
}
}
#endregion 图片保存周期
#region 提示帮助跑马灯
private System.Timers.Timer _scrollTimer; //滑动 Timer
///
/// 打开滑动跑马灯
///
private void OpenScrollTextLabel()
{
if (_scrollTimer != null)
return;
_scrollTimer = new System.Timers.Timer(ServerConfig.ScrollTextInterval);
_scrollTimer.Elapsed += (sender1, e1) =>
{
MethodInvoker method = ScrollText;
LabelScrollText.BeginInvoke(method);
};
_scrollTimer.Enabled = true;
}
///
/// 关闭滑动跑马灯
///
private void CloseScrollTextLabel()
{
if (_scrollTimer == null)
return;
_scrollTimer.Enabled = false;
_scrollTimer.Stop();
_scrollTimer.Dispose();
_scrollTimer.Close();
_scrollTimer = null;
}
///
/// 滑动文字
///
private void ScrollText()
{
var label = LabelScrollText;
var parent = label.Parent;
if (label.Width < parent.Width)
{
label.Left = 0;
return;
}
label.Left -= ServerConfig.ScrollTextGap;
if (label.Right <= parent.Width * 0.85)
label.Left = (int)(parent.Width * 0.10);
}
#endregion 提示帮助跑马灯
#region 添加提示信息
private readonly object _lockTextObj = new object();
///
/// 添加提示信息
///
///
///
private void AddTxtLine(string showMsg, bool showErr = false)
{
RcTextBox.Invoke((MethodInvoker)delegate ()
{
lock (_lockTextObj)
{
var text = $"{showMsg} - {DateTime.Now}{Environment.NewLine}";
if (RcTextBox.Lines.Count() > 500)
RcTextBox.Clear();
RcTextBox.SelectionColor = showErr ? Color.Red : Color.White;
RcTextBox.AppendText(text);
LogUnit.Info(showMsg);
RcTextBox.ScrollToCaret();
}
});
}
internal void ShowRecvMessage(string str, bool showErr = false)
{
AddTxtLine(str, showErr);
}
#endregion 添加提示信息
}
}