Files
T-DAS/Epost.BLL/CommandBLL.cs

691 lines
24 KiB
C#
Raw Normal View History

2023-01-13 15:30:20 +08:00
using ComposerSDK;
using Epost.Common;
using Epost.DAL;
using Epost.DAL.Cache;
using Epost.DAL.Enum;
using Epost.Model;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static Epost.Common.LogHelper;
namespace Epost.BLL
{
public class CommandBLL
{
CommandDAL dal = new CommandDAL();
2023-04-21 17:29:50 +08:00
2023-01-13 15:30:20 +08:00
AddressstorageBLL addrBLL = new AddressstorageBLL();
public static DataTable Controls = new DataTable();
public static DataTable Labels = new DataTable();
2023-04-21 17:29:50 +08:00
2023-01-13 15:30:20 +08:00
string IP = ConfigurationManager.AppSettings["WebAPIUrl"];
#region
2024-11-08 11:54:40 +08:00
public ResultModel Initialization_T(bool isback = true)
2023-01-13 15:30:20 +08:00
{
ResultModel resultModel = new ResultModel();
List<LabelParamModel> list = new List<LabelParamModel>();
try
{
DataTable dt = addrBLL.getControlList();
bool result = false;
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);
2024-11-08 11:54:40 +08:00
model = new LabelParamModel();
model.ControlIP = item["ControlIP"].ToString();
model.Address = "9999";
model.Command = "LED_OFF";
model.Timeout = "0.5";
list.Add(model);
2023-01-13 15:30:20 +08:00
}
if (list.Any())
{
resultModel = SendALL_Init(list);
}
}
return resultModel;
}
catch (Exception ex)
{
resultModel.result = "0";
resultModel.msg = "初始化失败!";
LogHelper.WriteLogInfo("初始化异常:" + ex.Message);
}
return resultModel;
}
#endregion
#region
2024-11-08 11:54:40 +08:00
public ResultModel GetAllLabelList_M(string batchno)
2023-01-13 15:30:20 +08:00
{
ResultModel model = new ResultModel();
try
{
bool bo = true;
DataTable dt = addrBLL.getControlList();
List<LabelParamModel> list = new List<LabelParamModel>();
if (dt.Rows.Count > 0)
{
foreach (DataRow item in dt.Rows)
{
2024-11-08 11:54:40 +08:00
DataTable lableDt = addrBLL.getLabelList(item["id"].ToString(), batchno);
2023-01-13 15:30:20 +08:00
if (lableDt != null && lableDt.Rows.Count > 0)
{
foreach (DataRow labelItem in lableDt.Rows)
{
2024-11-08 11:54:40 +08:00
string shopid = labelItem["address"].ToString();
2023-01-13 15:30:20 +08:00
if (labelItem["addresstype"].ToString() == "2")
{
LabelParamModel CNlablemodel = new LabelParamModel();
CNlablemodel.Address = labelItem["address"].ToString();
CNlablemodel.ControlIP = item["ControlIP"].ToString();
CNlablemodel.Command = "DISPLAY_JOB";
CNlablemodel.Uid = labelItem["address"].ToString();
CNlablemodel.Type = "C";
CNlablemodel.Mode = "10";
CNlablemodel.Title = labelItem["address"].ToString();
list.Add(CNlablemodel);
}
else
{
2024-11-08 11:54:40 +08:00
if (!string.IsNullOrEmpty(labelItem["shopid"].ToString()))
{
shopid = labelItem["shopid"].ToString();
if (shopid.Length > 4)
{
shopid = shopid.Substring(shopid.Length-4,4);
}
}
2023-01-13 15:30:20 +08:00
LabelParamModel lablemodel = new LabelParamModel();
lablemodel.Address = labelItem["address"].ToString();
lablemodel.ControlIP = item["ControlIP"].ToString();
lablemodel.Command = "DISPLAY_JOB";
lablemodel.Type = "N";
2024-11-08 11:54:40 +08:00
lablemodel.Quantity = shopid;
2023-01-13 15:30:20 +08:00
lablemodel.Uid = labelItem["address"].ToString();
lablemodel.Mode = "10";
list.Add(lablemodel);
}
//result= combll.DISPLAY_JOB(model);
}
}
}
DISPLAY_JOBALL(list);
}
if (bo)
{
model.result = "1";
model.msg = "成功!";
}
return model;
}
catch (Exception ex)
{
model.result = "0";
model.msg = ex.Message;
return model;
}
}
2023-04-21 17:29:50 +08:00
#endregion
2023-01-13 15:30:20 +08:00
#region
public void clearALL_M()
{
bool result = false;
DataTable dt = addrBLL.getControlList();
if (dt.Rows.Count > 0)
{
foreach (DataRow item in dt.Rows)
{
LabelParamModel model = new LabelParamModel();
model.Address = "9999";
model.ControlIP = item["ControlIP"].ToString();
result = FORMATE_JOB_DATA(model);
}
}
}
2023-04-21 17:29:50 +08:00
#endregion
2023-01-13 15:30:20 +08:00
#region
public bool FORMATE_JOB_DATA(LabelParamModel model)
{
return dal.FORMATE_JOB_DATA(model);
}
#endregion
#region
public bool CONNECT(LabelParamModel model)
{
return dal.CONNECT(model);
}
#endregion
#region device/job/scan默认job
public bool START_POLLING(LabelParamModel model)
{
return dal.START_POLLING(model);
}
#endregion
#region ()
public void DISPLAY_JOB_M(LabelParamModel model, bool clear = false, bool islock = false )
{
List<LabelParamModel> list = new List<LabelParamModel>();
if (clear)
{
LabelParamModel clearModel = new LabelParamModel();
clearModel.Address = model.Address;
clearModel.ControlIP = model.ControlIP;
clearModel.Parameter = model.Parameter;
clearModel.Uid = model.Uid;
clearModel.Command = "REMOVE_JOB";
clearModel.Timeout = "0.5";
clearModel.Type = model.Type;
// 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.Loc = model.Loc;
DisplayModel.Quantity = model.Quantity;
DisplayModel.Uid = model.Uid;
DisplayModel.W_quantity = model.W_quantity;
DisplayModel.Unit = model.Unit;
DisplayModel.W_unit = model.W_unit;
DisplayModel.Command = "DISPLAY_JOB";
DisplayModel.Timeout = "0.5";
DisplayModel.Type = model.Type;
DisplayModel.Mode = model.Mode;
// dal.UNLOCK(lockModel);
list.Add(DisplayModel);
if (islock)
{
LabelParamModel lockModel = new LabelParamModel();
lockModel.Address = model.Address;
lockModel.ControlIP = model.ControlIP;
lockModel.Parameter = "11101000";
lockModel.Command = "LOCK";
lockModel.Timeout = "0.5";
lockModel.Type = model.Type;
// dal.LOCK(lockModel);
list.Add(lockModel);
}
else
{
LabelParamModel lockModel = new LabelParamModel();
lockModel.Address = model.Address;
lockModel.ControlIP = model.ControlIP;
lockModel.Parameter = "00011000";
lockModel.Command = "UNLOCK";
lockModel.Timeout = "0.5";
lockModel.Type = model.Type;
// dal.UNLOCK(lockModel);
list.Add(lockModel);
}
dal.DISPLAY_JOBALL(list);
}
#endregion
#region ()
public void LED_ON_M(LabelParamModel model, bool islock = false)
{
List<LabelParamModel> list = new List<LabelParamModel>();
LabelParamModel clearModel = new LabelParamModel();
clearModel.Address = model.Address;
clearModel.ControlIP = model.ControlIP;
clearModel.Parameter = "";
clearModel.Command = "LED_OFF";
clearModel.Timeout = "0.5";
// dal.REMOVE_JOB(clearModel);
list.Add(clearModel);
LabelParamModel DisplayModel = new LabelParamModel();
DisplayModel.Address = model.Address;
DisplayModel.ControlIP = model.ControlIP;
DisplayModel.Parameter = model.Parameter;
DisplayModel.Command = "LED_ON";
DisplayModel.Timeout = "0.5";
// dal.UNLOCK(lockModel);
list.Add(DisplayModel);
if (islock)
{
LabelParamModel lockModel = new LabelParamModel();
lockModel.Address = model.Address;
lockModel.ControlIP = model.ControlIP;
lockModel.Parameter = "11101000";
lockModel.Command = "LOCK";
lockModel.Timeout = "0.5";
// dal.LOCK(lockModel);
list.Add(lockModel);
}
else
{
LabelParamModel lockModel = new LabelParamModel();
lockModel.Address = model.Address;
lockModel.ControlIP = model.ControlIP;
lockModel.Parameter = "00011000";
lockModel.Command = "UNLOCK";
lockModel.Timeout = "0.5";
// dal.UNLOCK(lockModel);
list.Add(lockModel);
}
dal.DISPLAY_JOBALL(list);
}
#endregion
2023-04-21 17:29:50 +08:00
2023-01-13 15:30:20 +08:00
#region LED_OFF()
public void LED_OFF_M(List<JobModel> list)
{
List<LabelParamModel> sendlist = new List<LabelParamModel>();
foreach (JobModel model in list)
{
LabelParamModel clearModel = new LabelParamModel();
clearModel.Address = model.Address;
clearModel.ControlIP = model.ControlIP;
clearModel.Command = "LED_OFF";
clearModel.Timeout = "0.5";
sendlist.Add(clearModel);
}
dal.DISPLAY_JOBALL(sendlist);
}
#endregion
#region LED_OFF()
public void LED_OFF_CLEAR(string ip)
{
LabelParamModel clearModel = new LabelParamModel();
clearModel.Address = "9999";
clearModel.ControlIP = ip;
clearModel.Parameter = "1";
clearModel.Command = "LED_OFF";
clearModel.Timeout = "0.5";
dal.Send(clearModel);
}
#endregion
2023-04-21 17:29:50 +08:00
2023-01-13 15:30:20 +08:00
#region LED_OFF()
public void LED_OFF_CLEAR(List<JobModel> offList)
{
List<LabelParamModel> list = new List<LabelParamModel>();
if (offList.Any())
{
foreach (JobModel item in offList)
{
LabelParamModel clearModel = new LabelParamModel();
clearModel.Address = item.Address;
clearModel.ControlIP = item.ControlIP;
clearModel.Parameter = "1";
clearModel.Command = "LED_OFF";
clearModel.Timeout = "0.5";
list.Add(clearModel);
}
}
dal.SendALL(list);
}
#endregion
#region ()
public bool DISPLAY_JOB(LabelParamModel model)
{
return dal.DISPLAY_JOB(model);
}
#endregion
#region ()
public void DISPLAY_JOBALL(List<LabelParamModel> model)
{
dal.DISPLAY_JOBALL(model);
}
#endregion
2023-04-21 17:29:50 +08:00
2023-01-13 15:30:20 +08:00
#region
public ResultModel SendALL_Init(List<LabelParamModel> model)
{
return dal.SendALL_Init(model);
}
#endregion
#region ()
public bool REMOVE_JOB(LabelParamModel model)
{
return dal.REMOVE_JOB(model);
}
#endregion
2023-04-21 17:29:50 +08:00
2023-01-13 15:30:20 +08:00
#region
public bool DISPLAY_LIGHT(LabelParamModel model)
{
return dal.DISPLAY_LIGHT(model);
}
#endregion
#region
public bool LOCK(LabelParamModel model)
{
return dal.LOCK(model);
}
#endregion
#region
public bool UNLOCK(LabelParamModel model)
{
return dal.UNLOCK(model);
}
#endregion
#region
public bool SLEEP(LabelParamModel model)
{
return dal.SLEEP(model);
}
#endregion
#region
public void CloseALL_M()
{
DataTable dt = addrBLL.getControlList();
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);
2024-11-08 11:54:40 +08:00
LED_OFF_CLEAR(item["ControlIP"].ToString());
2023-01-13 15:30:20 +08:00
}
}
}
#endregion
#region
public void UNLOCK_M(List<JobModel> offList)
{
// DataTable dt = addrBLL.getAddresslist(block,area,type);
if (offList.Any())
{
List<LabelParamModel> list = new List<LabelParamModel>();
foreach (JobModel item in offList)
{
LabelParamModel model = new LabelParamModel();
model.ControlIP = item.ControlIP;
model.Address = item.Address;
model.Command = "UNLOCK";
model.Parameter = "11111000";
list.Add(model);
}
dal.SendALL(list);
}
}
#endregion
#region
public void ClearArea_M(List<JobModel> offList)
{
// DataTable dt = addrBLL.getAddresslist(block,area,type);
if(offList.Any())
{
List<LabelParamModel> list = new List<LabelParamModel>();
foreach (JobModel item in offList)
{
LabelParamModel model = new LabelParamModel();
model.ControlIP = item.ControlIP;
model.Address = item.Address;
model.Command = "REMOVE_JOB";
model.Uid = item.ID;
model.Type = "N";
list.Add(model);
LabelParamModel Unlockmodel = new LabelParamModel();
Unlockmodel.ControlIP = item.ControlIP;
Unlockmodel.Address = item.Address;
Unlockmodel.Command = "UNLOCK";
Unlockmodel.Type = "N";
Unlockmodel.Parameter = "11111000";
list.Add(Unlockmodel);
}
dal.SendALL(list);
}
}
#endregion
#region
public void ClearAreaLEDOFF(List<JobModel> offList)
{
// DataTable dt = addrBLL.getAddresslist(block,area,type);
if (offList.Any())
{
List<LabelParamModel> list = new List<LabelParamModel>();
foreach (JobModel item in offList)
{
LabelParamModel model = new LabelParamModel();
model.ControlIP = item.ControlIP;
model.Address = item.Address;
model.Command = "LED_OFF";
model.Parameter = "0";
list.Add(model);
}
dal.SendALL(list);
}
}
#endregion
2023-04-21 17:29:50 +08:00
2023-01-13 15:30:20 +08:00
#region
public void ShowBoxMessage_M(ShowMessageModel_M show)
{
//获取作业区对应的显示标签地址
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;
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;
lablemodel.Content = show.Contents;
lablemodel.Quantity = show.Qty;
lablemodel.Unit = show.Unit;
lablemodel.W_unit = show.Wholeunit;
lablemodel.W_quantity = show.Wholeqty.ToString();
}
else
{
lablemodel.Type = "N";
lablemodel.Quantity = show.Qty;
lablemodel.Loc = show.Location;
}
DISPLAY_JOB_M(lablemodel, true, show.Islock);
LogHelper.WriteLogInfo("点亮显示标签" + addritem["address"].ToString());
}
}
}
/// <summary>
/// 判断输入的字符串是否只包含数字和英文字母
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static bool IsNumAndEnCh(string input)
{
string pattern = @"^[A-Za-z0-9]+$";
Regex regex = new Regex(pattern);
return regex.IsMatch(input);
}
#endregion
#region
public bool DISPLAY_LIGHT_BLOCK(string block, string area, string isoff)
{
DataTable dt = addrBLL.GetBoxAddress(block, area, 4);
List<LabelParamModel> list = new List<LabelParamModel>();
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow item in dt.Rows)
{
LabelParamModel model = new LabelParamModel();
model.Command = "DISPLAY_LIGHT";
model.Timeout = "0.5";
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;
list.Add(model);
}
}
dal.SendALL(list);
return true;
}
#endregion
#region
public void RemoveBoxMessage_M(ShowMessageModel_M show)
{
//获取作业区对应的显示标签地址
DataTable showaddrDT = addrBLL.GetBoxAddress(show.Block, show.Area, show.Type);
if (showaddrDT != null && showaddrDT.Rows.Count > 0)
{
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();
2024-09-02 16:42:28 +08:00
model.Parameter =show.No;
model.Uid = show.Uid;
if (string.IsNullOrEmpty(show.Uid))
{ model.Uid = addritem["address"].ToString(); }
model.Type = "N";
if (addritem["addresstype"].ToString() == "2")
{
model.Type = "C";
}
2023-01-13 15:30:20 +08:00
model.Command = "REMOVE_JOB";
model.Timeout = "0.5";
list.Add(model);
}
if (list != null && list.Count > 0)
{
LogHelper.WriteLogInfo("熄灭点亮的list———————" + list.Count);
dal.DISPLAY_JOBALL(list);
}
}
}
#endregion
2023-04-21 17:29:50 +08:00
2023-01-13 15:30:20 +08:00
}
}