You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1602 lines
74 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using AUCMA.STORE.Business;
using AUCMA.STORE.Business.Implements;
using AUCMA.STORE.Business.Interface;
using AUCMA.STORE.Common;
using AUCMA.STORE.Entity.DAO;
using AUCMA.STORE.Entity.DTO;
using AUCMA.STORE.Entity.Enums;
using AUCMA.STORE.NetWork;
using AUCMA.STORE.SqlSugar;
using AUCMA.STORE.SqlSugar.serviceImpl;
using AUCMA.STORE.WebAPI.Controllers;
using AutoMapper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AUCMA.STORE
{
public partial class InStoreForm : Form
{
public delegate void MyInvoke(BaseMaterialDTO baseMaterialDTO);
public delegate void PlcInvok(PLCAddressTypeDTO[] pLCAddressTypeDTO);
public delegate void PilerAlarmInvok(PLCAlarmInfoDTO[] pLCAlarmInfoDTOs, string pilerName);
public delegate void BarCodeIncok(string BarCode);
private static IInStoreBusiness inStoreBusiness = new InStoreBusinessImpl();
private static IOutStoreBusiness outStoreBusiness = new OutStoreBusinessImpl();
private static IPlcBusinessService plcBusiness = new PlcBusinessService();
private static TaskHandleBusiness taskHandleBusiness = TaskHandleBusiness.GetInstance();
private static BaseLocationInfo inStoreLocationInfo = new BaseLocationInfo();
private static IBaseServices<RealStoreAreaMaterialTypeInfo> realStoreMaterialInfo = new BaseServices<RealStoreAreaMaterialTypeInfo>();
private static string boxCode = "";
private static int taskCount = 0;
private static List<BaseMaterialDTO> webApiList = new List<BaseMaterialDTO>();
public static List<TaskDTO> inStoreTaskList = new List<TaskDTO>();
public static List<TaskDTO> outStoreTaskList = new List<TaskDTO>();
public static bool stop1_Flag = false;
public static bool stop2_Flag = false;
private static IBaseTaskQueueBusiness baseTaskQueueBusiness = new BaseTaskQueueBusiness();
#region Add by CaesarBao 19点30分
public delegate void SignalReadInvoke(int status,int type);
public bool iFlag = false;
public static string m_StoreCode = ConfigHelper.GetConfig("storeCode");
private string PosionCode = "";
#endregion
//1.声明自适应类实例
AutoSizeFormClass asc = new AutoSizeFormClass();
public InStoreForm()
{
InitializeComponent();
//string ss = "012345678";
//int iii = Convert.ToInt32(ss.Substring(ss.Length-7, 7));
if (!HslControls.Authorization.SetAuthorizationCode("ce5ade06-6f14-4b0d-b9c2-0d625664dc3f"))
{
return;
}
//hslMoveText3.Text = DateTime.Now.ToString("HH:mm:ss") + " 箱体码:" + "B920348920384902839" + "未匹配到当前所需物料!";
//this.SizeChanged += new Resize(this).Form1_Resize; //窗口自适应代码
LoadPosionCode();
NetWorkServer.init();
plcBusiness.LoadDeviceInfo();
NetWorkServer.BaseMaterialInfoRefreshEvent += MaterialRefreshInfo;
plcBusiness.RecvIdentifyRGVDataEvent += RecvIdentifyRGVDataEvent;
plcBusiness.RecvIdentifyPilerDataEvent += RecvIdentifyPilerDataEvent;
plcBusiness.RecvIdentifyPilerAlarmEvent += PilerAlarmEvent;
plcBusiness.RecvIdentifyBarCodeEvent += RecvIdentifyBarCodeEvent;
plcBusiness.SignalReadRefreshEvent += SignalReadInfo;
taskHandleBusiness.TaskInfoRefreshEvent += RefreshTaskInfostate;
}
/// <summary>
/// 加载工位编号
/// </summary>
private void LoadPosionCode()
{
//北线
if (m_StoreCode == "A")
{
PosionCode = "1014";
}
else
{
PosionCode = "1015";
}
}
private void initTaskQueue()
{
Console.WriteLine("启动初始化队列任务");
List<BaseTaskQueue> info = baseTaskQueueBusiness.GetTaskQueueList().Result;
info.ForEach(x =>
{
if (x.storeCode == ConfigHelper.GetConfig("storeCode"))
{
LogHelper.record("初始化队列任务" + x.storeCode);
TaskDTO task = new TaskDTO();
//task.locationIndex = x.uuid;
task.taskCode = x.pilerTaskCode;
task.materialType = x.materialCode;
task.materialCode = x.materialCode;
task.recordTime = x.recordTime;
task.plcCode = x.plcCode;
task.boxCode = x.boxCode;
task.storeCode = x.storeCode;
task.taskStatus = x.taskStatus;
task.taskType = x.pilerTaskType;
task.locationArea = x.locationArea;
task.operationType = x.operationType;
task.pilerClaimGoodsRows = x.pilerClaimGoodsRows;
task.pilerClaimGoodsLine = x.pilerClaimGoodsLine;
task.pilerClaimGoodsTier = x.pilerClaimGoodsTier;
task.pilerUnloadRows = x.pilerUnloadRows;
task.pilerUnloadLine = x.pilerUnloadLine;
task.pilerUnloadTier = x.pilerUnloadTier;
if (x.pilerTaskType == TaskType.InStore)
{
task.locationCode = x.pilerUnloadRows + "-" + x.pilerUnloadLine + "-" + x.pilerUnloadTier;
inStoreTaskList.Add(task);
}
else
{
task.locationCode = x.pilerClaimGoodsRows + "-" + x.pilerClaimGoodsLine + "-" + x.pilerClaimGoodsTier;
outStoreTaskList.Add(task);
}
Fresh_TaskInfo_dgv(task);
}
});
}
/// <summary>
/// 入库接口数据
/// </summary>
/// <param name="baseMaterialDTO"></param>
private void MaterialRefreshInfo(BaseMaterialDTO baseMaterialDTO)
{
if (baseMaterialDTO == null) return;
MyInvoke mi = new MyInvoke(InStore);
this.Invoke(mi, baseMaterialDTO);
}
/// <summary>
/// 入库操作
/// </summary>
/// <param name="baseMaterialDTO"></param>
private async void InStore(BaseMaterialDTO baseMaterialDTO)
{
try
{
if (baseMaterialDTO != null)
{
Console.WriteLine("物料信息:" + JsonChange.ModeToJson(baseMaterialDTO));
LogHelper.record(string.Format("收到手持上传的物料信息:类型编码:{0};类型名称:{1};位置:{2}", baseMaterialDTO.materialCode, baseMaterialDTO.materialName, baseMaterialDTO.InStoreArea));
//webApiBaseMaterialInfo = baseMaterialDTO;
//保存物料信息
int savaMaterialInfo = await inStoreBusiness.SaveMaterialInfo(baseMaterialDTO);
//修改手动入库所需实时表数据,如果有数据更新,没有添加
Expression<Func<RealStoreAreaMaterialTypeInfo, bool>> exp = s1 => true;
exp = exp.And(s1 => s1.storeCode == ConfigHelper.GetConfig("storeCode") && s1.locationArea == baseMaterialDTO.InStoreArea);
List<RealStoreAreaMaterialTypeInfo> realStoreAreaMaterialTypeInfos = await realStoreMaterialInfo.Query(exp);
if (realStoreAreaMaterialTypeInfos.Count() > 0)
{
RealStoreAreaMaterialTypeInfo realStoreAreaMaterial = realStoreAreaMaterialTypeInfos.FirstOrDefault();
realStoreAreaMaterial.detialMaterialCode = baseMaterialDTO.materialCode.Length == 0 ? baseMaterialDTO.materialType : baseMaterialDTO.materialCode;
realStoreAreaMaterial.detialMaterialName = baseMaterialDTO.materialName;
realStoreAreaMaterial.recordTime = DateTime.Now;
await realStoreMaterialInfo.Update(realStoreAreaMaterial);
}
else
{
await realStoreMaterialInfo.Add(new RealStoreAreaMaterialTypeInfo(ConfigHelper.GetConfig("storeCode"),
baseMaterialDTO.InStoreArea,
baseMaterialDTO.materialCode.Length == 0 ? baseMaterialDTO.materialType : baseMaterialDTO.materialCode,
baseMaterialDTO.materialName,
DateTime.Now));
}
var webApiCount = webApiList.Where(x => x.InStoreArea == baseMaterialDTO.InStoreArea).ToList();
if (webApiCount.Count() > 0)
{
LogHelper.record("获取到相同条码:" + webApiCount);
for (int i = 0; i < webApiCount.Count(); i++)
{
LogHelper.record("清除相同条码:" + webApiCount[i].materialCode);
webApiList.Remove(webApiCount[i]);
}
}
webApiList.Add(baseMaterialDTO);
LogHelper.record("手持条码数量:" + webApiList.Count()+";内容:"+JsonChange.ModeToJson(webApiList));
}
}catch(Exception ex)
{
LogHelper.Error("接口处理方法异常", ex);
}
}
/// <summary>
/// 报警委托实现
/// </summary>
/// <param name="pLCAlarmInfoDTOs"></param>
/// <param name="pilerName"></param>
private void PilerAlarmEvent(Object[] pLCAlarmInfoDTOs, string pilerName)
{
try
{
if (pLCAlarmInfoDTOs.Length == 0) return;
if (pilerName == null) return;
PilerAlarmInvok mi = new PilerAlarmInvok(PilerAlarmSingal);
this.Invoke(mi, pLCAlarmInfoDTOs, pilerName);
}catch(Exception ex)
{
Console.WriteLine(ex);
}
}
/// <summary>
/// 报警处理
/// </summary>
/// <param name="pLCAlarmInfoDTOs"></param>
/// <param name="pilerName"></param>
private void PilerAlarmSingal(PLCAlarmInfoDTO[] pLCAlarmInfoDTOs, string pilerName)
{
try
{
ReFresh_PilerWarnInfo_dgv(pLCAlarmInfoDTOs, pilerName);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
/// <summary>
/// RGV入库信号处理
/// </summary>
/// <param name="pLCAddressTypeDTO"></param>
private void RecvIdentifyRGVDataEvent(Object[] pLCAddressTypeDTO)
{
if (pLCAddressTypeDTO.Length == 0) return;
PlcInvok plcInvok = new PlcInvok(RecvIdentifyRGVData);
this.Invoke(plcInvok, pLCAddressTypeDTO);
}
/// <summary>
/// 收到箱体码
/// </summary>
/// <param name="BarCode"></param>
private void RecvIdentifyBarCodeEvent(string BarCode)
{
if (BackColor == null) return;
BarCodeIncok barCodeIncok = new BarCodeIncok(RecvIdentifyBarCode);
this.Invoke(barCodeIncok, BarCode);
}
/// <summary>
/// 堆垛机状态信号处理
/// </summary>
/// <param name="pLCAddressTypeDTO"></param>
private void RecvIdentifyPilerDataEvent(Object[] pLCAddressTypeDTO)
{
if (pLCAddressTypeDTO.Length == 0) return;
PlcInvok plcInvok = new PlcInvok(RecvIdentifyPilerData);
this.Invoke(plcInvok, pLCAddressTypeDTO);
}
/// <summary>
/// RGV入库信号处理
/// </summary>
/// <param name="pLcAddressTypeDTO"></param>
private async void RecvIdentifyRGVData(PLCAddressTypeDTO[] pLcAddressTypeDTO)
{
try
{
//自动模式运行
//if (!iFlag)
//{
//List<BaseMaterialDTO> materialInfo = webApiList.Where(x => x.InStoreArea == (LocationArea)pLcAddressTypeDTO[Convert.ToInt32(x.InStoreArea) - 1].Area).ToList();
for (int i = 0; i < pLcAddressTypeDTO.Length; i++)
{
if (pLcAddressTypeDTO[i].PLCValue == "1")
{
LogHelper.record("PLC入库信号" + pLcAddressTypeDTO[i].PLCName + ";数据:" + pLcAddressTypeDTO[i].PLCValue+";区域:"+ pLcAddressTypeDTO[i].Area);
List<BaseMaterialDTO> materialInfo = webApiList.Where(x => x.InStoreArea == (LocationArea)pLcAddressTypeDTO[i].Area).ToList();
if (materialInfo.Count() == 0 && materialInfo == null)
{
LogHelper.record("没有对应入库信号的条码信息,请手动入库!!!" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
return;
}
BaseMaterialDTO baseMaterialInfo = materialInfo.FirstOrDefault();
LogHelper.record("该入库信号对应物料条码信息:" + JsonChange.ModeToJson(baseMaterialInfo));
TaskDTO inStoreTask = await ReceiveInStoreSignal(baseMaterialInfo);
if (inStoreTask.taskCode == null)
{
LogHelper.record("入库任务创建异常--" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
return;
}
/*Mapper.Initialize(cret => cret.CreateMap<TaskDTO, PlcDirectiveDTO>());
PlcDirectiveDTO plcDirectiveDTO = Mapper.Map<PlcDirectiveDTO>(inStoreTask);
plcDirectiveDTO.plcCode = (ushort)Convert.ToInt16(inStoreTask.pilerCode);
int key = Convert.ToInt32(DateTime.Now.ToString("MMddHHmmss"));*/
if (baseTaskQueueBusiness.WriteTaskQueue(inStoreTask).Result > 0)
{
LogHelper.record("入库任务写入成功:" + JsonChange.ModeToJson(inStoreTask));
//创建待入库记录
int createPrepareInStoreResult = await inStoreBusiness.CreatePrepareInStore(inStoreTask);
inStoreTask.taskStatus = Entity.Enums.TaskStatus.Await;
ReFresh_TaskInfo_dgv(inStoreTask);
inStoreTaskList.Add(inStoreTask);
}
}
}
//}
//else
//{
// LogHelper.record("收到入库信号,入库方式为手动入库!!!!");
//}
}catch(Exception ex)
{
LogHelper.Error("入库信号处理方法RecvIdentifyRGVData异常", ex);
}
}
/// <summary>
/// 收到箱体码
/// </summary>
/// <param name="BarCode"></param>
private async void RecvIdentifyBarCode(string BarCode)
{
try
{
LogHelper.record("收到箱体码:" + BarCode );
if (BarCode == null || BarCode == "0")
return;
//if (iFlag == true)
// return;
//将背板码插入MES箱体码记录表
if (!outStoreBusiness.SaveBarCode(BarCode, PosionCode))
{
LogHelper.record( "箱体码:" +BarCode + "记录IMOS_UP_PROD_EXEC2失败");
}
BaseMaterialInfo baseMaterial = await outStoreBusiness.GetMaterialInfo(BarCode);
if(baseMaterial.materialCode == null)
{
label19.Text = "";
label19.Text = DateTime.Now.ToString("HH:mm:ss") + " 箱体码:" + BarCode + ",未在MES系统查询到BOM!";
hslMoveText3.Text = DateTime.Now.ToString("HH:mm:ss") + " 箱体码:"+ BarCode + ",未在MES系统查询到BOM!";
LogHelper.record("收到箱体码:" + BarCode + ",未在MES系统查询到该条码的BOM信息!!!!");
return;
}
//判断物料所在库位
List<BaseLocationInfo> baseLocationInfos = await outStoreBusiness.EstimateMaterialLocation(baseMaterial);
if (baseLocationInfos == null || baseLocationInfos.Count() == 0)
{
label19.Text = "";
label19.Text = DateTime.Now.ToString("HH:mm:ss") + " 箱体码:" + BarCode + ",物料编码:" + baseMaterial.materialCode + ",未匹配到物料!";
hslMoveText3.Text = DateTime.Now.ToString("HH:mm:ss") + " 箱体码:" + BarCode + ",物料编码:" + baseMaterial.materialCode + ",未匹配到物料!";
LogHelper.record("收到箱体码:" + BarCode + "未匹配到当前所需物料!!!!");
return;
}
BaseLocationInfo outStoreLocationInfo = outStoreBusiness.FiltrateBestlocation(baseLocationInfos);
LogHelper.record("筛选出物料所在库位,出库最佳库位为:" + outStoreLocationInfo.locationCode+"不指定该库位,下发时再判断库位");
if (outStoreLocationInfo.locationCode == null)
return;
TaskDTO outStoreTask = await outStoreBusiness.CreateTask(outStoreLocationInfo, baseMaterial,OperationType.Automatic);
if (outStoreTask.taskCode == null)
{
LogHelper.record("出库任务创建异常!!!");
return;
}
outStoreTask.boxCode = BarCode;
outStoreTaskList.Add(outStoreTask);
Fresh_TaskInfo_dgv(outStoreTask);
Expression<Func<BasePlcInfo, bool>> exp = s1 => true;
exp = exp.And(s1 => s1.plcArea == outStoreLocationInfo.locationArea && s1.storeCode == ConfigHelper.GetConfig("storeCode") && s1.deleteFlag == DeleteFlag.No);
List<BasePlcInfo> basePlcInfos = await new BaseServices<BasePlcInfo>().Query(exp);
//outStoreTask.plcCode = basePlcInfos.FirstOrDefault().plcCode;
if (baseTaskQueueBusiness.WriteTaskQueue(outStoreTask).Result > 0)
{
//bool occupyLocation = await outStoreBusiness.updateLocationStatus(outStoreTask, LocationStatus.Occupy);
LogHelper.record("出库任务写入成功:" + JsonChange.ModeToJson(outStoreTask));
//创建待出库记录
int createPrepareOutStoreResult = await outStoreBusiness.CreatePrepareOutStore(outStoreTask);
outStoreTask.taskStatus = Entity.Enums.TaskStatus.Await;
ReFresh_TaskInfo_dgv(outStoreTask);
}
}
catch(Exception ex)
{
LogHelper.Error("RecvIdentifyBarCode方法异常",ex);
}
}
/// <summary>
/// 堆垛机状态信号处理
/// </summary>
/// <param name="pLcAddressTypeDTO"></param>
private void RecvIdentifyPilerData(PLCAddressTypeDTO[] pLcAddressTypeDTO)
{
for (int i = 0; i< pLcAddressTypeDTO.Length;i++)
{
LogHelper.record("堆垛机:" + pLcAddressTypeDTO[i].PLCName + ";状态:" + pLcAddressTypeDTO[i].PLCValue + ";任务号:" + pLcAddressTypeDTO[i].TaskNo+";任务类型(1-入库2-出库)"+ pLcAddressTypeDTO[i].TaskType);
try
{
//堆垛机任务完成
if (pLcAddressTypeDTO[i].PLCValue == "2")
{
LogHelper.record("收到堆垛机状态:完成信号,任务:" + JsonChange.ModeToJson(pLcAddressTypeDTO[i]));
//1入库
if (pLcAddressTypeDTO[i].TaskType == 1)
{
LogHelper.record("收到堆垛机状态:完成,入库任务:" + pLcAddressTypeDTO[i].TaskNo);
var inStore = inStoreTaskList.Where(x => x.taskCode == pLcAddressTypeDTO[i].TaskNo).ToList();
LogHelper.record("收到堆垛机状态:完成,入库任务:" + pLcAddressTypeDTO[i].TaskNo + ";执行完成!");
if (pLcAddressTypeDTO[i].TaskNo == "0" || pLcAddressTypeDTO[i].TaskNo == "" || pLcAddressTypeDTO[i].TaskNo.Length < 3)
{
inStore = inStoreTaskList.Where(x => x.taskStatus == Entity.Enums.TaskStatus.Being).OrderBy(x => x.recordTime).ToList();
}
if (inStore.Count() > 0 && inStore != null)
{
/*for (int j = 0; j < inStore.Count() && inStore[j].taskCode == pLcAddressTypeDTO[i].TaskNo; j++)
{
if (inStore[j].taskCode == pLcAddressTypeDTO[i].TaskNo)
{
InStorePilerFinishStatusSignal(inStore[j]);
}
}*/
InStorePilerFinishStatusSignal(inStore.FirstOrDefault());
}
else
{
LogHelper.record("收到堆垛机状态:完成,入库任务:" + pLcAddressTypeDTO[i].TaskNo + ";获取入库任务信息为空!");
}
}
//2出库
if (pLcAddressTypeDTO[i].TaskType == 2)
{
LogHelper.record("收到堆垛机状态:完成,出库任务:" + pLcAddressTypeDTO[i].TaskNo);
var outStore = outStoreTaskList.Where(x => x.taskCode == pLcAddressTypeDTO[i].TaskNo).ToList();
LogHelper.record("收到堆垛机状态:完成,出库任务:" + pLcAddressTypeDTO[i].TaskNo + ";执行完成!");
if (pLcAddressTypeDTO[i].TaskNo == "0" || pLcAddressTypeDTO[i].TaskNo == "" || pLcAddressTypeDTO[i].TaskNo.Length < 3)
{
outStore = outStoreTaskList.Where(x => x.taskStatus == Entity.Enums.TaskStatus.Being).OrderBy(x => x.recordTime).ToList();
}
if (outStore.Count() > 0 && outStore != null)
{
/*for (int j=0;j< outStore.Count();j++)
{
if (pLcAddressTypeDTO[i].TaskNo == outStore[j].taskCode)
{
RefreshMessageListBox("收到堆垛机状态:完成,出库任务:" + outStore[j].taskCode + ";执行完成!");
OutStorePilerFinishStatusSignal(outStore[j]);
}
}*/
OutStorePilerFinishStatusSignal(outStore.FirstOrDefault());
}
else
{
LogHelper.record("收到堆垛机状态:完成,出库任务:" + pLcAddressTypeDTO[i].TaskNo + ";获取出库任务信息为空!");
}
}
if(pLcAddressTypeDTO[i].TaskType == 0)
{
if(outStoreTaskList.Any(x=> x.taskCode == pLcAddressTypeDTO[i].TaskNo))
{
LogHelper.record("收到堆垛机状态:完成,出库任务:" + pLcAddressTypeDTO[i].TaskNo+"异常完成");
var outStore = outStoreTaskList.Where(x => x.taskCode == pLcAddressTypeDTO[i].TaskNo).ToList();
OutStorePilerFinishStatusSignal(outStore.FirstOrDefault());
}else if(inStoreTaskList.Any(x=>x.taskCode == pLcAddressTypeDTO[i].TaskNo))
{
LogHelper.record("收到堆垛机状态:完成,入库任务:" + pLcAddressTypeDTO[i].TaskNo + "异常完成");
var inStore = inStoreTaskList.Where(x => x.taskCode == pLcAddressTypeDTO[i].TaskNo).ToList();
InStorePilerFinishStatusSignal(inStore.FirstOrDefault());
}
}
}
//堆垛机故障
if (pLcAddressTypeDTO[i].PLCValue == "3")
{
//1入库
if (pLcAddressTypeDTO[i].TaskType == 1)
{
RefreshMessageListBox("收到堆垛机状态:故障!!!!!,入库任务:" + pLcAddressTypeDTO[i].TaskNo + "");
ReFresh_TaskInfo_dgv(pLcAddressTypeDTO[i].TaskNo);
//InStorePilerWarnStatuSignal(pLcAddressTypeDTO[i].TaskNo);
}
//2出库
if (pLcAddressTypeDTO[i].TaskType == 2)
{
RefreshMessageListBox("收到堆垛机状态:故障!!!!!,出库任务:" + pLcAddressTypeDTO[i].TaskNo + "");
ReFresh_TaskInfo_dgv(pLcAddressTypeDTO[i].TaskNo);
//var outStore = outStoreTaskList.Where(x => x.taskCode == pLcAddressTypeDTO[i].TaskNo).ToList();
//if (outStore.Count() > 0 && outStore != null)
//{
// for (int j = 0; j < outStore.Count(); j++)
// {
// if (pLcAddressTypeDTO[i].TaskNo == outStore[j].taskCode)
// {
// RefreshMessageListBox("收到堆垛机状态:故障!!!!出库任务:" + outStore[j].taskCode + "");
// OutStorePilerWarnStatuSignal(outStore[j]);
// }
// }
//}
}
}
}catch (Exception ex)
{
LogHelper.Error($"堆垛机:{pLcAddressTypeDTO[i].PLCName};状态:{pLcAddressTypeDTO[i].PLCValue};任务号:{pLcAddressTypeDTO[i].TaskNo};状态信号处理异常:{ex.Message}", ex);
}
}
}
/// <summary>
/// 创建入库任务
/// </summary>
/// <param name="baseMaterialDTO"></param>
public async Task<TaskDTO> ReceiveInStoreSignal(BaseMaterialDTO baseMaterialDTO)
{
LogHelper.record("系统创建入库任务:"+JsonChange.ModeToJson(baseMaterialDTO));
TaskDTO inStoreTask = new TaskDTO();
try
{
List<BaseLocationInfo> locationInfo = await inStoreBusiness.IsOrNotEmptyLocation(baseMaterialDTO);
if (locationInfo.Count() > 0)
{
LogHelper.record("筛选空余库位,剩余:" + locationInfo.Count() + "个空余库位");
//筛选库位
inStoreLocationInfo = inStoreBusiness.FiltrateLocation(locationInfo);
if (inStoreLocationInfo != null)
{
LogHelper.record("最佳入库库位为:" + inStoreLocationInfo.locationCode);
//创建入库任务
inStoreTask = await inStoreBusiness.CreateInStoreTask(inStoreLocationInfo, baseMaterialDTO,OperationType.Automatic);
if (inStoreTask.taskCode != null)
{
LogHelper.record("入库任务创建完成,任务号:" + inStoreTask.taskCode + ";物料类别:" + inStoreTask.materialCode + ";库位:" + inStoreTask.locationCode + ";库位区域:" + inStoreTask.locationArea);
Fresh_TaskInfo_dgv(inStoreTask);
//锁定库位
bool occupyLocation = await inStoreBusiness.updateLocationStatus(LocationStatus.Occupy, inStoreTask);
if (occupyLocation)
{
LogHelper.record("库位锁定成功!");
}
}
}
}
else
{
LogHelper.record("没有空余库位!!!" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
}catch(Exception ex)
{
LogHelper.Error("创建入库任务方法异常", ex);
}
return inStoreTask;
}
/// <summary>
/// 入库收到堆垛机完成信号
/// </summary>
/// <param name="baseLocationInfo"></param>
/// <param name="task"></param>
public async void InStorePilerFinishStatusSignal(TaskDTO task)
{
LogHelper.record("入库收到堆垛机完成信息处理:" + task.taskCode);
try
{
for (int i = 0; i < inStoreTaskList.Count(); i++)
{
if (inStoreTaskList[i].taskCode == task.taskCode)
{
task.taskStatus = Entity.Enums.TaskStatus.Achieve;
ReFresh_TaskInfo_dgv(task);
//更新库位状态
//bool inUseLocation = await inStoreBusiness.updateLocationStatus(LocationStatus.InUse, task);
//更新入库任务状态
//bool updateInStoreTask = await inStoreBusiness.UpdateInStoreTaskStatus(task);
//更新待入库状态
// bool updatePrePareInstoreStatus = await inStoreBusiness.UpdatePrePareInStoreStatus(task);
//创建入库记录
int recordInStore = await inStoreBusiness.SaveInStoreRecord(task);
//记录物料与库位绑定记录
await inStoreBusiness.SaveMaterialLocation(task);
inStoreTaskList.Remove(inStoreTaskList[i]);
}
}
}catch(Exception ex)
{
LogHelper.Error("入库收到堆垛机完成信息处理异常"+ ex.ToString());
}
}
/// <summary>
/// 出库收到堆垛机完成信号
/// </summary>
/// <param name="baseLocationInfo"></param>
/// <param name="task"></param>
public async void OutStorePilerFinishStatusSignal(TaskDTO task)
{
LogHelper.record("出库收到堆垛机完成信息处理:"+task.taskCode+";箱体码:"+task.boxCode);
try
{
for (int i = 0; i < outStoreTaskList.Count(); i++)
{
if (outStoreTaskList[i].taskCode == task.taskCode)
{
task.taskStatus = Entity.Enums.TaskStatus.Achieve;
ReFresh_TaskInfo_dgv(task);
//更新库位状态
//bool inUseLocation = await outStoreBusiness.updateLocationStatus(task, LocationStatus.UnUsed);
//更新出库任务状态
//bool updateOutStoreTask = await outStoreBusiness.UpdateOutStoreStatus(task);
//更新待出库状态
//bool updatePrePareOutstoreStatus = await outStoreBusiness.UpdatePrePareOutStoreStatus(task);
//创建出库记录
int recordOutStore = await outStoreBusiness.SaveOutStoreRecord(task);
//清楚物料与库位绑定记录
await outStoreBusiness.DeleteMaterialLocation(task);
outStoreTaskList.Remove(outStoreTaskList[i]);
}
}
}catch(Exception ex)
{
LogHelper.Error("出库收到堆垛机完成信息处理异常"+ ex.ToString());
}
}
/// <summary>
/// 入库堆垛机故障处理
/// </summary>
/// <param name="task"></param>
public async void InStorePilerWarnStatuSignal(string taskCode)
{
for (int i = 0; i < inStoreTaskList.Count(); i++)
{
if (inStoreTaskList[i].taskCode == taskCode)
{
inStoreTaskList[i].taskStatus = Entity.Enums.TaskStatus.Warning;
ReFresh_TaskInfo_dgv(inStoreTaskList[i]);
//更新入库任务状态
await inStoreBusiness.UpdateInStoreTaskStatus(inStoreTaskList[i]);
}
}
}
/// <summary>
/// 出库堆垛机故障处理
/// </summary>
/// <param name="task"></param>
public async void OutStorePilerWarnStatuSignal(TaskDTO task)
{
task.taskStatus = Entity.Enums.TaskStatus.Warning;
ReFresh_TaskInfo_dgv(task);
//更新出库任务状态
bool updateInStoreTask = await inStoreBusiness.UpdateInStoreTaskStatus(task);
}
public void RefreshMessageListBox(string strMessage)
{
//LogHelper.Info(strMessage);
Console.Write(DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss]") + "-" + strMessage + "\r\n");
}
private void SignalReadInfo(int status,int type)
{
SignalReadInvoke SignalReadInvoke = new SignalReadInvoke(SignalRead_Invoke);
this.Invoke(SignalReadInvoke, status,type);
}
private void SignalRead_Invoke(int status,int type)
{
//机械手状态
if (type == 0)
{
switch (status)
{
case 0:
pictureBox6.Image = Image.FromFile("Resources\\Red.png");
break;
default:
pictureBox6.Image = Image.FromFile("Resources\\Green.png");
break;
}
}
//1#堆垛机状态
else if (type == 1)
{
switch (status)
{
case 0:
pictureBox3.Image = Image.FromFile("Resources\\Red.png");
break;
default:
pictureBox3.Image = Image.FromFile("Resources\\Green.png");
break;
}
}
//2#堆垛机状态
else if (type == 2)
{
switch (status)
{
case 0:
pictureBox2.Image = Image.FromFile("Resources\\Red.png");
break;
default:
pictureBox2.Image = Image.FromFile("Resources\\Green.png");
break;
}
}
//RGV状态
else if (type == 3)
{
switch (status)
{
case 0:
pictureBox1.Image = Image.FromFile("Resources\\Red.png");
break;
default:
pictureBox1.Image = Image.FromFile("Resources\\Green.png");
break;
}
}
//1#门体出库口状态
else if(type == 4)
{
switch (status)
{
case 0:
pictureBox7.Image = Image.FromFile("Resources\\Red.png");
break;
default:
pictureBox7.Image = Image.FromFile("Resources\\Green.png");
break;
}
}
//2#门体库出口状态
else if (type == 5)
{
switch (status)
{
case 0:
pictureBox8.Image = Image.FromFile("Resources\\Red.png");
break;
default:
pictureBox8.Image = Image.FromFile("Resources\\Green.png");
break;
}
}
//1#门体入库口状态
else if (type == 6)
{
switch (status)
{
case 0:
pictureBox9.Image = Image.FromFile("Resources\\Red.png");
break;
default:
pictureBox9.Image = Image.FromFile("Resources\\Green.png");
break;
}
}
//2#门体库入口状态
else if (type == 7)
{
switch (status)
{
case 0:
pictureBox10.Image = Image.FromFile("Resources\\Red.png");
break;
default:
pictureBox10.Image = Image.FromFile("Resources\\Green.png");
break;
}
}
//准备就绪
//else if (type == 8)
//{
//}
//else if (type == 9)
//{
//}
}
private void InStoreForm_Load(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.None; //设置窗体为无边框样式
this.WindowState = FormWindowState.Maximized; //最大化窗体
this.Focus();
asc.controllInitializeSize(this);
timer1.Interval = 1000;
timer1.Start();
initTaskQueue();
}
private void InStoreForm_SizeChanged(object sender, EventArgs e)
{
asc.controlAutoSize(this);
}
private void timer1_Tick(object sender, EventArgs e)
{
this.label5.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var leftinfo = SearchStoreCountAsync(LocationArea.Location_Left);
var rightinfo = SearchStoreCountAsync(LocationArea.Location_Right);
label12.Text = leftinfo.Result.ToString();
label13.Text = rightinfo.Result.ToString();
}
/// <summary>
/// 获取堆垛机当前急停状态
/// </summary>
private void CheckPLCStopState()
{
try
{
stop1_Flag = true;
string img = AppDomain.CurrentDomain.BaseDirectory + "\\Resources\\恢复.png";
btn_Stop_1.BackgroundImage = Image.FromFile(img);
}
catch (Exception ex)
{
}
}
private void btn_Instore_1_Click(object sender, EventArgs e)
{
InStore form = new InStore();
form.Text = "1#手动入库";
form.PilerInfo = "1";
form.TaskType = TaskType.InStore;
form.inStoreForm = this;
form.ShowDialog(this);
}
private void button10_Click(object sender, EventArgs e)
{
//TaskDTO taskDTO = new TaskDTO();
//Random random = new Random();
//int x = random.Next(1000000, 9999999);
//taskDTO.taskCode = x.ToString();
//taskDTO.taskStatus = Entity.Enums.TaskStatus.Warning;
//taskDTO.taskType = TaskType.OutStore;
//taskDTO.storeCode = "A";
//taskDTO.materialType = "12315893248";
//taskDTO.locationArea = LocationArea.Location_Left;
//taskDTO.locationCode = "1-5-11";
//taskDTO.recordTime = DateTime.Now;
//Fresh_TaskInfo_dgv(taskDTO);
//outStoreTaskList.Add(taskDTO);
//PLCAlarmInfoDTO[] pLCAlarmInfoDTOs = new PLCAlarmInfoDTO[2];
//pLCAlarmInfoDTOs[0] = new PLCAlarmInfoDTO("满叉", "1");
//pLCAlarmInfoDTOs[0].DateTime = DateTime.Now;
//pLCAlarmInfoDTOs[1] = new PLCAlarmInfoDTO("取货时货架无货", "2");
//pLCAlarmInfoDTOs[1].DateTime = DateTime.Now;
//ReFresh_PilerWarnInfo_dgv(pLCAlarmInfoDTOs, "1#堆垛机");
if (MessageBox.Show("请您确认是否退出(Y/N)", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
try
{
InStoreForm_FormClosed(null, null);
}
catch (System.Exception error)
{
//WinIO卸载失败异常
MessageBox.Show(error.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
else
{
return;
}
}
private void button8_Click(object sender, EventArgs e)
{
InStore form = new InStore();
form.Text = "2#手动入库";
form.PilerInfo = "2";
form.TaskType = TaskType.InStore;
form.inStoreForm = this;
//iFlag = true;
form.ShowDialog(this);
}
private void button7_Click(object sender, EventArgs e)
{
OutStore form = new OutStore();
//InStore form = new InStore();
form.Text = "2#手动出库";
form.PilerInfo = "2";
form.TaskType = TaskType.OutStore;
form.inStoreForm = this;
//iFlag = true;
form.ShowDialog(this);
}
private void button2_Click(object sender, EventArgs e)
{
OutStore form = new OutStore();
//InStore form = new InStore();
form.Text = "1#手动出库";
form.PilerInfo = "1";
form.TaskType = TaskType.OutStore;
form.inStoreForm = this;
iFlag = true;
form.ShowDialog(this);
}
/// <summary>
/// 急停按钮改为清除任务按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void btn_Stop_1_Click(object sender, EventArgs e)
{
Expression<Func<BasePlcInfo, bool>> exp1 = s1 => true;
exp1 = exp1.And(s1 => s1.plcArea == LocationArea.Location_Left && s1.storeCode == ConfigHelper.GetConfig("storeCode") && s1.deleteFlag == DeleteFlag.No); ;
List<BasePlcInfo> basePlcInfos = await new BaseServices<BasePlcInfo>().Query(exp1);
if (!stop1_Flag)
{
plcBusiness.WritePilerStop(basePlcInfos.FirstOrDefault().plcCode, "1");
stop1_Flag = true;
string img = AppDomain.CurrentDomain.BaseDirectory + "\\Resources\\恢复.png";
btn_Stop_1.BackgroundImage = Image.FromFile(img);
}
else
{
plcBusiness.WritePilerStop(basePlcInfos.FirstOrDefault().plcCode, "0");
string img = AppDomain.CurrentDomain.BaseDirectory + "\\Resources\\急停.png";
btn_Stop_1.BackgroundImage = Image.FromFile(img);
stop1_Flag = false;
}
}
private async void btn_Stop_2_Click(object sender, EventArgs e)
{
Expression<Func<BasePlcInfo, bool>> exp1 = s1 => true;
exp1 = exp1.And(s1 => s1.plcArea == LocationArea.Location_Left && s1.storeCode == ConfigHelper.GetConfig("storeCode") && s1.deleteFlag == DeleteFlag.No); ;
List<BasePlcInfo> basePlcInfos = await new BaseServices<BasePlcInfo>().Query(exp1);
if (!stop2_Flag)
{
//if (m_StoreCode == "A")
//{
// plcBusiness.WritePilerStop(1003, "1");
//}
//else
//{
// plcBusiness.WritePilerStop(1007, "1");
//}
plcBusiness.WritePilerStop(basePlcInfos.FirstOrDefault().plcCode, "1");
string img = AppDomain.CurrentDomain.BaseDirectory + "\\Resources\\恢复.png";
btn_Stop_2.BackgroundImage = Image.FromFile(img);
stop2_Flag = true;
}
else
{
//if (m_StoreCode == "A")
//{
// plcBusiness.WritePilerStop(1003, "0");
//}
//else
//{
// plcBusiness.WritePilerStop(1007, "0");
//}
plcBusiness.WritePilerStop(basePlcInfos.FirstOrDefault().plcCode, "0");
string img = AppDomain.CurrentDomain.BaseDirectory + "\\Resources\\急停.png";
btn_Stop_2.BackgroundImage = Image.FromFile(img);
stop2_Flag = false;
}
}
private void InStoreForm_Activated(object sender, EventArgs e)
{
dataGridView1.ColumnHeadersHeight = 30; //设置标题行高
this.dataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;//单元格标题栏居中显示
dataGridView1.ClearSelection(); //可消除所有选择的行
dataGridView1.CurrentCell = null; //可消除选择行的行头箭头
dataGridView1.AllowUserToAddRows = false;
dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;
//dataGridView1.Anchor = (AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left);
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.ReadOnly = true;
dataGridView1.RowHeadersVisible = false;
//禁止用户改变DataGridView1の所有行的行高
dataGridView1.AllowUserToResizeRows = false;
// 禁止用户改变列头的高度
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
//设置单元格行背景色
dataGridView1.RowsDefaultCellStyle.BackColor = Color.FromArgb(3, 27, 61);
dataGridView2.ColumnHeadersHeight = 30; //设置标题行高
this.dataGridView2.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
dataGridView2.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;//单元格标题栏居中显示
dataGridView2.ClearSelection(); //可消除所有选择的行
dataGridView2.CurrentCell = null; //可消除选择行的行头箭头
dataGridView2.AllowUserToAddRows = false;
dataGridView2.EnableHeadersVisualStyles = false;
dataGridView2.CellBorderStyle = DataGridViewCellBorderStyle.None;
//dataGridView1.Anchor = (AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left);
dataGridView2.AllowUserToDeleteRows = false;
dataGridView2.ReadOnly = true;
dataGridView2.RowHeadersVisible = false;
//禁止用户改变DataGridView1の所有行的行高
dataGridView2.AllowUserToResizeRows = false;
// 禁止用户改变列头的高度
dataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
//设置单元格行背景色
dataGridView2.RowsDefaultCellStyle.BackColor = Color.FromArgb(3, 27, 61);
}
public void ReFresh_PilerWarnInfo_dgv(PLCAlarmInfoDTO[] pLCAlarmInfoDTOs,string pilername)
{
dataGridView2.Rows.Clear();
foreach (var warninfo in pLCAlarmInfoDTOs)
{
int index = this.dataGridView2.Rows.Add(); //添加行的索引
this.dataGridView2.Rows[index].Cells[0].Value = pilername;
this.dataGridView2.Rows[index].Cells[1].Value = warninfo.PLCName;
this.dataGridView2.Rows[index].Cells[2].Value = warninfo.DateTime.ToString("HH:mm:ss");
//字体颜色
this.dataGridView2.Rows[index].DefaultCellStyle.ForeColor = Color.FromArgb(106, 203, 254);
}
dataGridView2.CurrentCell = null;
}
#region DataGridView1
public delegate void TaskInfoInvoke(int TaskNo, TaskType taskType);
public void RefreshTaskInfostate(int TaskNo,TaskType taskType,LocationArea locationArea,string locationCode)
{
if (taskType == TaskType.InStore)
{
var inStore = inStoreTaskList.Where(x => x.taskCode == TaskNo.ToString()).FirstOrDefault();
ReFresh_TaskInfo_dgv(inStore,1);
}
else
{
var outStore = outStoreTaskList.Where(x => x.taskCode == TaskNo.ToString()).FirstOrDefault();
if(outStore != null)
{
outStore.locationArea = locationArea;
outStore.locationCode = locationCode;
}
ReFresh_TaskInfo_dgv(outStore,1);
}
}
public virtual void ReFresh_TaskInfo_dgv(TaskDTO inStoreTask,int state)
{
try
{
LogHelper.Pilerlog($"任务:{inStoreTask.taskCode};修改界面展示");
if(dataGridView1 != null)
{
if (dataGridView1.Rows.Count > 0)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Cells[0].FormattedValue.ToString() == inStoreTask.taskCode)
{
if (inStoreTask.locationArea == LocationArea.Location_Left)
{
dataGridView1.Rows[i].Cells[3].Value = "1#库";
}
else
{
dataGridView1.Rows[i].Cells[3].Value = "2#库";
}
dataGridView1.Rows[i].Cells[4].Value = inStoreTask.locationCode;
dataGridView1.Rows[i].Cells[5].Value = "执行中";
dataGridView1.Rows[i].Cells[6].Value = inStoreTask.recordTime.ToString("HH:mm:ss");
}
}
}
}
else
{
LogHelper.Pilerlog($"任务:{inStoreTask.taskCode};修改界面展示失败任务列表为null");
}
}catch(Exception ex)
{
LogHelper.Error($"ReFresh_TaskInfo_dgv异常:{ex.Message}", ex);
}
}
/// <summary>
/// 将界面任务状态改为异常;并将库位设置锁库
/// </summary>
/// <param name="TaskNo"></param>
public async void ReFresh_TaskInfo_dgv(string taskCode)
{
if (dataGridView1.Rows.Count > 0)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Cells[0].FormattedValue.ToString() == taskCode)
{
//字体颜色
dataGridView1.Rows[i].Cells[5].Value = "异常";
dataGridView1.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
//bool iflag = await inStoreBusiness.selectLocationStatus(dataGridView1.Rows[i].Cells[3].Value.ToString(), dataGridView1.Rows[i].Cells[4].Value.ToString());
//if(!iflag)
//{
// await inStoreBusiness.updateLocationState(dataGridView1.Rows[i].Cells[3].Value.ToString(), dataGridView1.Rows[i].Cells[4].Value.ToString(),LocationStatus.Occupy);
//}
}
}
}
}
public void ReFresh_TaskInfo_dgv(TaskDTO inStoreTask)
{
if (dataGridView1.Rows.Count > 0)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Cells[0].FormattedValue.ToString() == inStoreTask.taskCode)
{
if (inStoreTask.taskStatus == Entity.Enums.TaskStatus.Warning)
{
//字体颜色
dataGridView1.Rows[i].Cells[5].Value = "异常";
dataGridView1.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
}
else if (inStoreTask.taskStatus == Entity.Enums.TaskStatus.Being)
{
dataGridView1.Rows[i].Cells[5].Value = "执行中";
}
else if (inStoreTask.taskStatus == Entity.Enums.TaskStatus.Await)
{
dataGridView1.Rows[i].Cells[5].Value = "等待";
}
else if (inStoreTask.taskStatus == Entity.Enums.TaskStatus.Achieve)
{
dataGridView1.Rows[i].Cells[5].Value = "完成";
}
dataGridView1.Rows[i].Cells[6].Value = inStoreTask.recordTime.ToString("HH:mm:ss");
}
}
}
}
public void Fresh_TaskInfo_dgv(TaskDTO inStoreTask)
{
int index = this.dataGridView1.Rows.Add(); //添加行的索引
this.dataGridView1.Rows[index].Cells[0].Value = inStoreTask.taskCode;
string operationType = inStoreTask.operationType.ToString() == "Automatic" ? "自动" : "手动";
if (inStoreTask.taskType == TaskType.InStore)
{
this.dataGridView1.Rows[index].Cells[1].Value = operationType + "入库";
}
else
{
this.dataGridView1.Rows[index].Cells[1].Value = operationType + "出库";
}
this.dataGridView1.Rows[index].Cells[2].Value = inStoreTask.materialType;
if (inStoreTask.locationArea == LocationArea.Location_Left)
{
this.dataGridView1.Rows[index].Cells[3].Value = "1#库";
}
else
{
this.dataGridView1.Rows[index].Cells[3].Value = "2#库";
}
this.dataGridView1.Rows[index].Cells[4].Value = inStoreTask.locationCode;
if (inStoreTask.taskStatus == Entity.Enums.TaskStatus.Await)
{
this.dataGridView1.Rows[index].Cells[5].Value = "等待";
}
else if (inStoreTask.taskStatus == Entity.Enums.TaskStatus.Being)
{
this.dataGridView1.Rows[index].Cells[5].Value = "执行中";
}
else if (inStoreTask.taskStatus == Entity.Enums.TaskStatus.Warning)
{
this.dataGridView1.Rows[index].Cells[5].Value = "异常";
dataGridView1.Rows[index].DefaultCellStyle.ForeColor = Color.Red;
}
else if (inStoreTask.taskStatus == Entity.Enums.TaskStatus.Achieve)
{
this.dataGridView1.Rows[index].Cells[5].Value = "完成";
}
this.dataGridView1.Rows[index].Cells[6].Value = inStoreTask.recordTime.ToString("HH:mm:ss");
//字体颜色
this.dataGridView1.Rows[index].DefaultCellStyle.ForeColor = Color.FromArgb(106, 203, 254);
dataGridView1.CurrentCell = null;
// 按自编号排序
DataGridViewColumn col = dataGridView1.Columns[6];
// 按降序(即始终每次新添加的数据排最前)
ListSortDirection direction = ListSortDirection.Descending;
dataGridView1.Sort(col, direction); // 执行指定排序规则
}
//单击单元格事件
private async void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
int rowindex = e.RowIndex;
if (dataGridView1.Rows[rowindex].Cells["Column5"].Value.ToString() != "异常")
return;
else
{
if (MessageBox.Show("异常结束此任务(Y/N)", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
string taskNo = dataGridView1.Rows[rowindex].Cells["Column0"].Value.ToString();
string taskType = dataGridView1.Rows[rowindex].Cells["Column1"].Value.ToString();
Console.WriteLine("异常结束此" + taskType + "任务,任务号:" + dataGridView1.Rows[rowindex].Cells["Column1"].Value.ToString());
if (taskType.Contains("出库"))
{
if (MessageBox.Show("该物料是否已经出库(Y/N)", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
//RefreshMessageListBox("收到堆垛机状态:完成,出库任务:" + outStore[j].taskCode + ";执行完成!");
//OutStorePilerFinishStatusSignal(outStore[j]);
bool inUseLocation = await inStoreBusiness.updateLocationState(dataGridView1.Rows[rowindex].Cells["Column3"].Value.ToString(), dataGridView1.Rows[rowindex].Cells["Column4"].Value.ToString(), LocationStatus.UnUsed);
dataGridView1.Rows[rowindex].Cells["Column5"].Value = "完成";
}
else
{
dataGridView1.Rows[rowindex].Cells["Column5"].Value = "异常结束";
bool inUseLocation = await inStoreBusiness.updateLocationState(dataGridView1.Rows[rowindex].Cells["Column3"].Value.ToString(), dataGridView1.Rows[rowindex].Cells["Column4"].Value.ToString(), LocationStatus.InUse);
//outStoreTaskList.Remove(outStore[j]);
}
dataGridView1.Refresh();
Console.WriteLine("异常任务处理完成!");
//var outStore = outStoreTaskList.Where(x => x.taskCode == taskNo).ToList();
//if (outStore.Count() > 0 && outStore != null)
//{
// for (int j = 0; j < outStore.Count(); j++)
// {
// if (taskNo == outStore[j].taskCode)
// {
// if (MessageBox.Show("该物料是否已经出库(Y/N)", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
// {
// RefreshMessageListBox("收到堆垛机状态:完成,出库任务:" + outStore[j].taskCode + ";执行完成!");
// OutStorePilerFinishStatusSignal(outStore[j]);
// dataGridView1.Rows[rowindex].Cells["Column5"].Value = "完成";
// }
// else
// {
// dataGridView1.Rows[rowindex].Cells["Column5"].Value = "异常结束";
// outStoreTaskList.Remove(outStore[j]);
// }
// dataGridView1.Refresh();
// Console.WriteLine("异常任务处理完成!");
// }
// }
// //plcBusiness.WriteRGVStop("0");
//}
}
if (taskType.Contains("入库"))
{
if (MessageBox.Show("该物料是否已经入库(Y/N)", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
bool inUseLocation = await inStoreBusiness.updateLocationState(dataGridView1.Rows[rowindex].Cells["Column3"].Value.ToString(), dataGridView1.Rows[rowindex].Cells["Column4"].Value.ToString(), LocationStatus.InUse);
//RefreshMessageListBox("收到堆垛机状态:完成,入库任务:" + inStore[j].taskCode + ";执行完成!");
//InStorePilerFinishStatusSignal(inStore[j]);
dataGridView1.Rows[rowindex].Cells["Column5"].Value = "完成";
}
else
{
bool inUseLocation = await inStoreBusiness.updateLocationState(dataGridView1.Rows[rowindex].Cells["Column3"].Value.ToString(), dataGridView1.Rows[rowindex].Cells["Column4"].Value.ToString(), LocationStatus.UnUsed);
dataGridView1.Rows[rowindex].Cells["Column5"].Value = "异常结束";
//bool inUseLocation = await inStoreBusiness.updateLocationStatus(LocationStatus.UnUsed, inStore[j]);
//inStoreTaskList.Remove(inStore[j]);
}
dataGridView1.Refresh();
Console.WriteLine("异常任务处理完成!");
//var inStore = inStoreTaskList.Where(x => x.taskCode == taskNo).ToList();
//RefreshMessageListBox("收到堆垛机状态:完成,入库任务:" + taskNo + ";执行完成!");
//if (inStore.Count() > 0 && inStore != null)
//{
// for (int j = 0; j < inStore.Count(); j++)
// {
// if (inStore[j].taskCode == taskNo)
// {
// //InStorePilerFinishStatusSignal(inStore[j]);
// if (MessageBox.Show("该物料是否已经入库(Y/N)", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
// {
// RefreshMessageListBox("收到堆垛机状态:完成,入库任务:" + inStore[j].taskCode + ";执行完成!");
// InStorePilerFinishStatusSignal(inStore[j]);
// dataGridView1.Rows[rowindex].Cells["Column5"].Value = "完成";
// }
// else
// {
// dataGridView1.Rows[rowindex].Cells["Column5"].Value = "异常结束";
// bool inUseLocation = await inStoreBusiness.updateLocationStatus(LocationStatus.UnUsed, inStore[j]);
// inStoreTaskList.Remove(inStore[j]);
// }
// dataGridView1.Refresh();
// Console.WriteLine("异常任务处理完成!");
// }
// }
//}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw;
}
}
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//设置为整行被选中
//单元格居中显示
e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
}
private void dataGridView1_Paint(object sender, PaintEventArgs e)
{
//e.Graphics.DrawRectangle(Pens.DarkBlue, new Rectangle(0, 0, this.dataGridView1.Width - 1, this.dataGridView1.Height - 1));
}
#endregion
#region DataGridView2
private void dataGridView2_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(Pens.DarkBlue, new Rectangle(0, 0, this.dataGridView2.Width - 1, this.dataGridView2.Height - 1));
}
private void dataGridView2_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
this.dataGridView2.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//设置为整行被选中
//单元格居中显示
e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
}
#endregion
private void InStoreForm_FormClosed(object sender, FormClosedEventArgs e)
{
this.Dispose();
System.Environment.Exit(System.Environment.ExitCode);
this.Close();
}
private void pictureBox4_MouseClick(object sender, MouseEventArgs e)
{
try
{
//ToolTip ttpSettings = new ToolTip();
toolTip1.InitialDelay = 200;
toolTip1.AutoPopDelay = 10 * 1000;
toolTip1.ReshowDelay = 200;
toolTip1.ShowAlways = true;
//toolTip1.IsBalloon = true;
toolTip1.BackColor = Color.FromArgb(3, 27, 61);
toolTip1.ForeColor = Color.FromArgb(106, 203, 254);
string tipOverwrite = "Enable this to allow overwrite an existing file on skydrive while uploading a duplicated file.";
toolTip1.SetToolTip(pictureBox4, tipOverwrite); // ckbOverwrite is a checkbox
}
catch (Exception ex)
{
}
}
private void pictureBox4_Click(object sender, EventArgs e)
{
Chart chart = new Chart();
chart.Text = "1#库存占比明细";
chart.locationArea = LocationArea.Location_Left;
chart.ShowDialog(this);
}
private void pictureBox5_Click(object sender, EventArgs e)
{
Chart chart = new Chart();
chart.Text = "2#库存占比明细";
chart.locationArea = LocationArea.Location_Right;
chart.ShowDialog(this);
}
/// <summary>
/// 库存数量查询
/// </summary>
/// <param name="locationArea">库位区域</param>
/// <returns></returns>
private async Task<string> SearchStoreCountAsync(LocationArea locationArea)
{
Expression<Func<BaseLocationInfo, bool>> exp = s1 => true;
exp = exp.And(s1 => s1.locationArea == locationArea && s1.locationStatus == LocationStatus.InUse && s1.storeCode == m_StoreCode && s1.deleteFlag == DeleteFlag.No);
List<BaseLocationInfo> baseLocationInfos = await new BaseServices<BaseLocationInfo>().Query(exp);
return baseLocationInfos.Count.ToString() == null ? "0" : baseLocationInfos.Count.ToString() + "/"+"156";
}
private async void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
int rowindex = e.RowIndex;
if (dataGridView1.Rows[rowindex].Cells["Column5"].Value.ToString() != "等待")
return;
if (MessageBox.Show("是否强制结束此任务(Y/N)", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
string taskNo = dataGridView1.Rows[rowindex].Cells["Column0"].Value.ToString();
string taskType = dataGridView1.Rows[rowindex].Cells["Column1"].Value.ToString();
Console.WriteLine("强制结束此" + taskType + "任务,任务号:" + dataGridView1.Rows[rowindex].Cells["Column1"].Value.ToString());
if (taskType.Contains("出库"))
{
var outStore = outStoreTaskList.Where(x => x.taskCode == taskNo).FirstOrDefault();
if (taskNo == outStore.taskCode)
{
dataGridView1.Rows[rowindex].Cells["Column5"].Value = "任务删除";
dataGridView1.Rows[rowindex].DefaultCellStyle.ForeColor = Color.Red;
outStoreTaskList.Remove(outStore);
bool inUseLocation = await inStoreBusiness.updateLocationStatus(LocationStatus.InUse, outStore);
baseTaskQueueBusiness.DeleteAssignTask(taskNo);
//int key = TaskDictionary.FindKey(int.Parse(taskNo));
//TaskDictionary.removeOutTask(key);
dataGridView1.Refresh();
Console.WriteLine("异常任务处理完成!");
}
}
else
{
var inStore = inStoreTaskList.Where(x => x.taskCode == taskNo).FirstOrDefault();
if (taskNo == inStore.taskCode)
{
dataGridView1.Rows[rowindex].Cells["Column5"].Value = "任务删除";
dataGridView1.Rows[rowindex].DefaultCellStyle.ForeColor = Color.Red;
outStoreTaskList.Remove(inStore);
bool inUseLocation = await inStoreBusiness.updateLocationStatus(LocationStatus.UnUsed, inStore);
baseTaskQueueBusiness.DeleteAssignTask(taskNo);
//int key = TaskDictionary.FindKey(int.Parse(taskNo));
//TaskDictionary.removeOutTask(key);
dataGridView1.Refresh();
Console.WriteLine("异常任务处理完成!");
}
}
}
}
private void btn_Unlock_1_Click(object sender, EventArgs e)
{
UnLockStoreLocationInfo unLockStoreLocationInfo = new UnLockStoreLocationInfo();
unLockStoreLocationInfo.Text = "1#解锁库存";
unLockStoreLocationInfo.PilerInfo = "1";
unLockStoreLocationInfo.TaskType = (TaskType)2;
unLockStoreLocationInfo.inStoreForm = this;
iFlag = true;
unLockStoreLocationInfo.ShowDialog(this);
}
private void btn_Unlock_2_Click(object sender, EventArgs e)
{
UnLockStoreLocationInfo unLockStoreLocationInfo = new UnLockStoreLocationInfo();
unLockStoreLocationInfo.Text = "2#解锁库存";
unLockStoreLocationInfo.PilerInfo = "2";
unLockStoreLocationInfo.TaskType = (TaskType)2;
unLockStoreLocationInfo.inStoreForm = this;
iFlag = true;
unLockStoreLocationInfo.ShowDialog(this);
}
private async void btn_clearTask_Click(object sender, EventArgs e)
{
Expression<Func<BaseTaskQueue, bool>> exp = s1 => true;
List<BaseTaskQueue> taskQueues = await new BaseServices<BaseTaskQueue>().Query(x => x.storeCode == "A" && x.pilerTaskType == TaskType.OutStore && x.taskStatus == Entity.Enums.TaskStatus.Await);
if (taskQueues != null)
{
if (taskQueues.Count > 0)
{
DialogResult result = MessageBox.Show($"确认删除{taskQueues.Count}条出库任务", "确认对话", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
bool res = await new BaseServices<BaseTaskQueue>().DeleteByIds(taskQueues.Select(x => x.uuid).ToArray());
MessageBox.Show($"操作已执行,删除{(res ? "" : "")}", "通知", MessageBoxButtons.OK, MessageBoxIcon.Information);
LogHelper.Pilerlog($"手动删除{taskQueues.Count}条出库任务{(res ? "" : "")}:{JsonChange.ModeToJson(taskQueues)}");
if (res)
{
inStoreTaskList.Clear();
outStoreTaskList.Clear();
dataGridView1.Rows.Clear();
initTaskQueue();
}
}
else
{
MessageBox.Show("操作已取消。", "通知", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
MessageBox.Show("当前没有未执行的等待任务。", "通知", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
}