This commit is contained in:
@ -4,6 +4,7 @@ using Epost.DAL;
|
||||
using Epost.DAL.Cache;
|
||||
using Epost.DAL.Enum;
|
||||
using Epost.Model;
|
||||
using LightContrl;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
@ -11,6 +12,7 @@ using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using static Epost.Common.LogHelper;
|
||||
|
||||
@ -23,53 +25,64 @@ namespace Epost.BLL
|
||||
AddressstorageBLL addrBLL = new AddressstorageBLL();
|
||||
public static DataTable Controls = new DataTable();
|
||||
public static DataTable Labels = new DataTable();
|
||||
JobDownCacheDAL JobCache = new JobDownCacheDAL();
|
||||
OrdersDAL orderDal = new OrdersDAL();
|
||||
JobDownCacheDAL JobCache = new JobDownCacheDAL();
|
||||
OrdersDAL orderDal = new OrdersDAL();
|
||||
ConfigurationOperator txtbll = new ConfigurationOperator();
|
||||
string IP = ConfigurationManager.AppSettings["WebAPIUrl"];
|
||||
|
||||
LightControlCacheDAL cachedal = new LightControlCacheDAL();
|
||||
MainControl lig = new MainControl();
|
||||
#region 初始化数据
|
||||
public ResultModel Initialization_M(bool isback = true)
|
||||
{
|
||||
ResultModel resultModel = new ResultModel();
|
||||
resultModel.result = "0";
|
||||
resultModel.msg = "成功";
|
||||
List<LabelParamModel> list = new List<LabelParamModel>();
|
||||
try
|
||||
{
|
||||
DataTable dt = addrBLL.getControlList();
|
||||
bool result = false;
|
||||
DataTable dt = addrBLL.QueryControlList("");
|
||||
|
||||
if (dt != null && dt.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow item in dt.Rows)
|
||||
{
|
||||
LabelParamModel model = new LabelParamModel();
|
||||
model.ControlIP = item["ControlIP"].ToString();
|
||||
model.Address = "9999";
|
||||
model.Command = "FORMAT_JOB_DATA";
|
||||
model.Parameter = "50";
|
||||
model.Timeout = "0.5";
|
||||
list.Add(model);
|
||||
model = new LabelParamModel();
|
||||
model.ControlIP = item["ControlIP"].ToString();
|
||||
model.Address = "9999";
|
||||
model.Command = "CONNECT";
|
||||
model.Parameter = IP;
|
||||
model.Timeout = "0.5";
|
||||
list.Add(model);
|
||||
model = new LabelParamModel();
|
||||
model.ControlIP = item["ControlIP"].ToString();
|
||||
model.Address = "9999";
|
||||
model.Parameter = "11111000";
|
||||
model.Command = "UNLOCK";
|
||||
model.Timeout = "0.5";
|
||||
list.Add(model);
|
||||
|
||||
}
|
||||
if (list.Any())
|
||||
{
|
||||
resultModel = SendALL_Init(list);
|
||||
|
||||
string ipaddress = item["controlip"].ToString().Trim();
|
||||
List<LightcontrolModel> conlist = cachedal.GetControlList().FindAll(o => o.controlip == ipaddress);
|
||||
if (conlist != null && conlist.Count > 0)
|
||||
{
|
||||
LogHelper.WriteLogInfo(ipaddress + "已连接!");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
int port = Convert.ToInt32(item["port"].ToString().Trim());
|
||||
int timeout = 2000;
|
||||
bool bo = lig.Connect(ipaddress, port, timeout);//timeout 毫秒
|
||||
if (bo)
|
||||
{
|
||||
LightcontrolModel model = new LightcontrolModel();
|
||||
model.controlip = ipaddress;
|
||||
model.maincontrol = lig;
|
||||
model.port = port;
|
||||
cachedal.UpdateControlList(new List<LightcontrolModel> { model }, EcontrolCommend.Create);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.WriteLogInfo("连接失败" + ipaddress);
|
||||
resultModel.result = "-1";
|
||||
resultModel.msg = "连接失败" + ipaddress;
|
||||
return resultModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return resultModel;
|
||||
|
||||
}
|
||||
@ -127,7 +140,7 @@ namespace Epost.BLL
|
||||
lablemodel.Mode = "10";
|
||||
list.Add(lablemodel);
|
||||
}
|
||||
|
||||
|
||||
//result= combll.DISPLAY_JOB(model);
|
||||
|
||||
}
|
||||
@ -154,9 +167,9 @@ namespace Epost.BLL
|
||||
#endregion
|
||||
|
||||
#region 获取参数中文
|
||||
public string GETDISPLAYJOBPAR_CN(string no,string Lightcolor,string IsTwinkle,string Title,string BigQuantity, string BigUnit,string Quantity, string Unit,string Content,string Rfcode)
|
||||
public string GETDISPLAYJOBPAR_CN(string no, string Lightcolor, string IsTwinkle, string Title, string BigQuantity, string BigUnit, string Quantity, string Unit, string Content, string Rfcode)
|
||||
{
|
||||
string parar = no+"00" + Lightcolor + IsTwinkle+"30CQ" + Title + "\n\n" + BigQuantity + "\n" + BigUnit + "\n" + Quantity + "\n" + Unit + "\n" + Content + "\n00\n\n" + Rfcode + "\n"; ;
|
||||
string parar = no + "00" + Lightcolor + IsTwinkle + "30CQ" + Title + "\n\n" + BigQuantity + "\n" + BigUnit + "\n" + Quantity + "\n" + Unit + "\n" + Content + "\n00\n\n" + Rfcode + "\n"; ;
|
||||
return parar;
|
||||
}
|
||||
#endregion
|
||||
@ -246,7 +259,7 @@ namespace Epost.BLL
|
||||
#endregion
|
||||
|
||||
#region 任务指令(传参地址)
|
||||
public void DISPLAY_JOB_M(LabelParamModel model, bool clear = false, bool islock = false )
|
||||
public void DISPLAY_JOB_M(LabelParamModel model, bool clear = false, bool islock = false)
|
||||
{
|
||||
List<LabelParamModel> list = new List<LabelParamModel>();
|
||||
if (clear)
|
||||
@ -259,14 +272,14 @@ namespace Epost.BLL
|
||||
clearModel.Command = "REMOVE_JOB";
|
||||
clearModel.Timeout = "0.5";
|
||||
clearModel.Type = model.Type;
|
||||
// dal.REMOVE_JOB(clearModel);
|
||||
// dal.REMOVE_JOB(clearModel);
|
||||
list.Add(clearModel);
|
||||
}
|
||||
LabelParamModel DisplayModel = new LabelParamModel();
|
||||
DisplayModel.Address = model.Address;
|
||||
DisplayModel.ControlIP = model.ControlIP;
|
||||
DisplayModel.Content =model.Content;
|
||||
DisplayModel.Title =model.Title;
|
||||
DisplayModel.Content = model.Content;
|
||||
DisplayModel.Title = model.Title;
|
||||
DisplayModel.Loc = model.Loc;
|
||||
DisplayModel.Quantity = model.Quantity;
|
||||
DisplayModel.Uid = model.Uid;
|
||||
@ -362,9 +375,9 @@ namespace Epost.BLL
|
||||
LabelParamModel clearModel = new LabelParamModel();
|
||||
clearModel.Address = model.Address;
|
||||
clearModel.ControlIP = model.ControlIP;
|
||||
|
||||
|
||||
clearModel.Command = "LED_OFF";
|
||||
clearModel.Timeout = "0.5";
|
||||
clearModel.Timeout = "0.5";
|
||||
sendlist.Add(clearModel);
|
||||
}
|
||||
dal.DISPLAY_JOBALL(sendlist);
|
||||
@ -401,14 +414,14 @@ namespace Epost.BLL
|
||||
clearModel.Timeout = "0.5";
|
||||
list.Add(clearModel);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
dal.SendALL(list);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region 任务指令(传参地址)
|
||||
public bool DISPLAY_JOB(LabelParamModel model)
|
||||
{
|
||||
@ -431,7 +444,7 @@ namespace Epost.BLL
|
||||
return dal.SendALL_Init(model);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 移除任务指令(传参地址)
|
||||
public bool REMOVE_JOB(LabelParamModel model)
|
||||
{
|
||||
@ -500,27 +513,128 @@ namespace Epost.BLL
|
||||
#region 清除所有任务并熄灭通道灯
|
||||
public void CloseALL_M()
|
||||
{
|
||||
DataTable dt = addrBLL.getControlList();
|
||||
//DataTable dt = addrBLL.getControlList();
|
||||
|
||||
if (dt != null && dt.Rows.Count > 0)
|
||||
//if (dt != null && dt.Rows.Count > 0)
|
||||
//{
|
||||
// foreach (DataRow item in dt.Rows)
|
||||
// {
|
||||
|
||||
// LabelParamModel model = new LabelParamModel();
|
||||
// model.ControlIP = item["ControlIP"].ToString();
|
||||
// FORMATE_JOB_DATA(model);
|
||||
|
||||
// }
|
||||
|
||||
//}
|
||||
List<LightcontrolModel> conlist = cachedal.GetControlList();
|
||||
if (conlist.Any() && conlist.Count > 0)
|
||||
{
|
||||
foreach (DataRow item in dt.Rows)
|
||||
Ledonoff_dengdai("0","");
|
||||
Thread.Sleep(500);
|
||||
foreach (LightcontrolModel con in conlist)
|
||||
{
|
||||
|
||||
LabelParamModel model = new LabelParamModel();
|
||||
model.ControlIP = item["ControlIP"].ToString();
|
||||
FORMATE_JOB_DATA(model);
|
||||
|
||||
bool b = con.maincontrol.DisConnect(con.controlip, con.port);
|
||||
LogHelper.WriteLogInfo(b + "断开连接" + con.controlip + "==" + con.port);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cachedal.ClearControlList();
|
||||
|
||||
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 亮灭灯带所有格口
|
||||
public void Ledonoff_dengdai(string lightType, string lightcolor)
|
||||
{
|
||||
DataTable dt = addrBLL.QueryControlList(" ");
|
||||
if (dt != null && dt.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow rowitem in dt.Rows)
|
||||
{
|
||||
string ipaddress = rowitem["controlip"].ToString().Trim();
|
||||
List<LightcontrolModel> conlist = cachedal.GetControlList().FindAll(o => o.controlip == ipaddress);
|
||||
if (conlist != null && conlist.Count > 0)
|
||||
{
|
||||
|
||||
MainControl control = conlist.FirstOrDefault().maincontrol;
|
||||
bool bo = false;
|
||||
string Address = dt.Rows[0]["address"].ToString().Trim();
|
||||
string resstr = string.Empty;
|
||||
if (lightType == "0")
|
||||
{
|
||||
|
||||
bo = control.LED_OFF(ipaddress, Address, ref resstr);
|
||||
}
|
||||
else
|
||||
{
|
||||
bo = control.LED_ON(ipaddress, Address, ref resstr, "3", "0", lightcolor);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 点亮/熄灭灯带格口
|
||||
public void display_dengdai(string location,string color)
|
||||
{
|
||||
DataTable dt = addrBLL.QueryControlList("");
|
||||
if (dt != null && dt.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow rowitem in dt.Rows)
|
||||
{
|
||||
string ipaddress = rowitem["controlip"].ToString().Trim();
|
||||
List<LightcontrolModel> conlist = cachedal.GetControlList().FindAll(o => o.controlip == ipaddress);
|
||||
if (conlist != null && conlist.Count > 0)
|
||||
{
|
||||
MainControl control = conlist.FirstOrDefault().maincontrol;
|
||||
DataTable locdt = addrBLL.QueryAddrList(" and location ='" + location + "' and controlip='" + ipaddress + "'");
|
||||
if (locdt != null && locdt.Rows.Count > 0)
|
||||
{
|
||||
List<LightParagraph> list = new List<LightParagraph>();
|
||||
string address = locdt.Rows[0]["address"].ToString().Trim();
|
||||
foreach (DataRow locitem in locdt.Rows)
|
||||
{
|
||||
//根据播种墙号、格口号查询播种墙ip及灯带地址
|
||||
|
||||
LightParagraph show = new LightParagraph();
|
||||
show.WayNu = Convert.ToInt32(locitem["wayno"].ToString().Trim());
|
||||
show.LightBeganNu = locitem["beginno"].ToString().Trim();
|
||||
show.LightEndNu = locitem["endno"].ToString().Trim();
|
||||
show.LightColor = color; //1:蓝色 2:绿色 3:青色 4:红色 5:紫色 6黄色 7白色
|
||||
show.Brightness = "9";//亮度 1-9
|
||||
list.Add(show);
|
||||
|
||||
}
|
||||
string resstr = string.Empty;
|
||||
bool bo = control.LED_By_Paragraph(ipaddress, address, list, ref resstr);
|
||||
if (bo)
|
||||
{
|
||||
LogHelper.WriteLogInfo("成功" + ipaddress + "list:" + JsonHelper.SerializeObject(list));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.WriteLogInfo("失败" + ipaddress + "list:" + JsonHelper.SerializeObject(list), LogHelper.Log_Type.ERROR);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
LogHelper.WriteLogInfo("请先连接设备!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region 根据区解锁标签
|
||||
public void UNLOCK_M(List<JobModel> offList)
|
||||
{
|
||||
@ -553,7 +667,7 @@ namespace Epost.BLL
|
||||
{
|
||||
// DataTable dt = addrBLL.getAddresslist(block,area,type);
|
||||
|
||||
if(offList.Any())
|
||||
if (offList.Any())
|
||||
{
|
||||
List<LabelParamModel> list = new List<LabelParamModel>();
|
||||
foreach (JobModel item in offList)
|
||||
@ -570,7 +684,7 @@ namespace Epost.BLL
|
||||
Unlockmodel.ControlIP = item.ControlIP;
|
||||
Unlockmodel.Address = item.Address;
|
||||
Unlockmodel.Command = "UNLOCK";
|
||||
|
||||
|
||||
Unlockmodel.Type = "N";
|
||||
Unlockmodel.Parameter = "11111000";
|
||||
list.Add(Unlockmodel);
|
||||
@ -615,25 +729,25 @@ namespace Epost.BLL
|
||||
#region 点亮显示标签
|
||||
public void ShowBoxMessage_M(ShowMessageModel_M show)
|
||||
{
|
||||
//获取作业区对应的显示标签地址
|
||||
DataTable showaddrDT = addrBLL.GetBoxAddress(show.Block,show.Area,show.Type);
|
||||
//获取作业区对应的显示标签地址
|
||||
DataTable showaddrDT = addrBLL.GetBoxAddress(show.Block, show.Area, show.Type);
|
||||
if (showaddrDT != null && showaddrDT.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow addritem in showaddrDT.Rows)
|
||||
{
|
||||
|
||||
|
||||
LabelParamModel lablemodel = new LabelParamModel();
|
||||
lablemodel.Address = addritem["address"].ToString();
|
||||
lablemodel.ControlIP = addritem["controlip"].ToString();
|
||||
lablemodel.Command = "DISPLAY_JOB";
|
||||
lablemodel.Uid =show.Uid;
|
||||
lablemodel.Uid = show.Uid;
|
||||
if (string.IsNullOrEmpty(show.Uid))
|
||||
{ lablemodel.Uid = addritem["address"].ToString(); }
|
||||
|
||||
|
||||
lablemodel.Mode = show.Color + "0";
|
||||
if (addritem["addresstype"].ToString() == "2")
|
||||
{
|
||||
|
||||
{
|
||||
|
||||
lablemodel.Type = "C";
|
||||
lablemodel.Loc = show.Location;
|
||||
lablemodel.Title = show.Title;
|
||||
@ -646,13 +760,13 @@ namespace Epost.BLL
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
lablemodel.Type = "N";
|
||||
lablemodel.Quantity = show.Qty;
|
||||
lablemodel.Quantity = show.Qty;
|
||||
lablemodel.Loc = show.Location;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
DISPLAY_JOB_M(lablemodel, true, show.Islock);
|
||||
LogHelper.WriteLogInfo("点亮显示标签" + addritem["address"].ToString());
|
||||
|
||||
@ -691,7 +805,7 @@ namespace Epost.BLL
|
||||
model.Type = "T";
|
||||
model.Address = item["address"].ToString();
|
||||
model.ControlIP = item["ControlIP"].ToString();
|
||||
model.Parameter = ConvertHexHelper.ConvertString(item["addresstype"].ToString(), 10, 16).ToString().PadLeft(2,'0')+ isoff;
|
||||
model.Parameter = ConvertHexHelper.ConvertString(item["addresstype"].ToString(), 10, 16).ToString().PadLeft(2, '0') + isoff;
|
||||
list.Add(model);
|
||||
}
|
||||
|
||||
@ -711,16 +825,16 @@ namespace Epost.BLL
|
||||
List<LabelParamModel> list = new List<LabelParamModel>();
|
||||
foreach (DataRow addritem in showaddrDT.Rows)
|
||||
{
|
||||
|
||||
|
||||
LabelParamModel model = new LabelParamModel();
|
||||
model.Address = addritem["address"].ToString();
|
||||
model.ControlIP = addritem["controlip"].ToString();
|
||||
model.Parameter =show.No;
|
||||
model.Parameter = show.No;
|
||||
model.Command = "REMOVE_JOB";
|
||||
model.Timeout = "0.5";
|
||||
list.Add(model);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (list != null && list.Count > 0)
|
||||
{
|
||||
LogHelper.WriteLogInfo("熄灭点亮的list———————:" + list.Count);
|
||||
@ -728,16 +842,16 @@ namespace Epost.BLL
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user