Files
T-DAS/Epost.BLL/CommandBLL.cs
2024-11-28 10:51:15 +08:00

693 lines
24 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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();
AddressstorageBLL addrBLL = new AddressstorageBLL();
public static DataTable Controls = new DataTable();
public static DataTable Labels = new DataTable();
string IP = ConfigurationManager.AppSettings["WebAPIUrl"];
#region
public ResultModel Initialization_T(bool isback = true)
{
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);
model = new LabelParamModel();
model.ControlIP = item["ControlIP"].ToString();
model.Address = "9999";
model.Command = "LED_OFF";
model.Timeout = "0.5";
list.Add(model);
}
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
public ResultModel GetAllLabelList_M(string batchno)
{
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)
{
DataTable lableDt = addrBLL.getLabelList(item["id"].ToString(), batchno);
if (lableDt != null && lableDt.Rows.Count > 0)
{
foreach (DataRow labelItem in lableDt.Rows)
{
string shopid = labelItem["address"].ToString();
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
{
if (!string.IsNullOrEmpty(labelItem["shopid"].ToString()))
{
shopid = labelItem["shopid"].ToString();
if (shopid.Length > 4)
{
shopid = shopid.Substring(shopid.Length-4,4);
}
}
LabelParamModel lablemodel = new LabelParamModel();
lablemodel.Address = labelItem["address"].ToString();
lablemodel.ControlIP = item["ControlIP"].ToString();
lablemodel.Command = "DISPLAY_JOB";
lablemodel.Type = "N";
lablemodel.Quantity = shopid;
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;
}
}
#endregion
#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);
}
}
}
#endregion
#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 = "11111000";
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 = "11111000";
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
#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
#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";
clearModel.Uid = "C"+item.Address;
clearModel.Type = "N";
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
#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
#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);
LED_OFF_CLEAR(item["ControlIP"].ToString());
}
}
}
#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 = "U" + 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
#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();
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";
}
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
}
}