|
@@ -0,0 +1,626 @@
|
|
|
+/*
|
|
|
+ * V1
|
|
|
+*/
|
|
|
+
|
|
|
+//using LiveCharts.Helpers;
|
|
|
+//using Microsoft.DwayneNeed.Numerics;
|
|
|
+//using Mysqlx.Crud;
|
|
|
+//using NPOI.SS.Formula.Functions;
|
|
|
+//using SCADA.BarcodeReader;
|
|
|
+//using SCADA.Comm;
|
|
|
+//using SCADA.CommonLib.Data;
|
|
|
+//using SCADA.CommonLib.Data.DIL;
|
|
|
+//using SCADA.CommonLib.Helper;
|
|
|
+//using SCADA.SECS;
|
|
|
+//using SCADA_DAQ.Customer.Models.DeviceManagement;
|
|
|
+//using SCADA_DAQ.Customer.Models.MotorcycleTypeManagement;
|
|
|
+//using SCADA_DAQ.Customer.Models.RecordManagement;
|
|
|
+//using SCADA_DAQ.Customer.Models.TaskManagement;
|
|
|
+//using SCADA_DAQ.Plugin.Machine;
|
|
|
+//using SCADA_DAQ.Plugin.Machine.Device;
|
|
|
+//using SqlSchema.DBNames;
|
|
|
+//using System;
|
|
|
+//using System.Collections;
|
|
|
+//using System.Collections.Generic;
|
|
|
+//using System.ComponentModel;
|
|
|
+//using System.Diagnostics;
|
|
|
+//using System.Linq;
|
|
|
+//using System.Runtime.ConstrainedExecution;
|
|
|
+//using System.Security.Cryptography;
|
|
|
+//using System.Text;
|
|
|
+//using System.Text.RegularExpressions;
|
|
|
+//using System.Threading.Tasks;
|
|
|
+//using System.Windows.Forms;
|
|
|
+//using Xceed.Wpf.Toolkit;
|
|
|
+
|
|
|
+//namespace SCADA_DAQ.Customer.Machines
|
|
|
+//{
|
|
|
+// /// <summary>
|
|
|
+// /// 二维扫码枪
|
|
|
+// /// </summary>
|
|
|
+// [DisplayName("二维扫码枪")]
|
|
|
+// public class ScannerMachine : BaseBarcodeReaderMachine
|
|
|
+// {
|
|
|
+// // 数据库对象
|
|
|
+// private static SqlSchema.DIL.DILDB DAL = Env.SgIDAL;
|
|
|
+// private static DIL.DILDB sqliteDAL = Env.DAL;
|
|
|
+
|
|
|
+// // 测试环境
|
|
|
+// private static bool IsDev = false;
|
|
|
+
|
|
|
+// // 工单切换索引
|
|
|
+// private static int orderIndex = 0;
|
|
|
+// // 当前生产的工单号
|
|
|
+// private static string currentOrderId = "";
|
|
|
+// // 当前生成的车型名称
|
|
|
+// private static string currentMotorcycleTypeName = "";
|
|
|
+
|
|
|
+// // 上次扫码号
|
|
|
+// private static string lastScanCode = "";
|
|
|
+// // 上次生产的工单号
|
|
|
+// private static string lastOrderId = "";
|
|
|
+// // 上次生产的工单号
|
|
|
+// private static int lastId = -1;
|
|
|
+
|
|
|
+// // 扫码队列
|
|
|
+// Queue scanQueue = new Queue();
|
|
|
+
|
|
|
+// //// 任务模型
|
|
|
+// //private TaskManagementModel taskManagementModel = new TaskManagementModel();
|
|
|
+
|
|
|
+// /// <summary>
|
|
|
+// /// 构造函数
|
|
|
+// /// </summary>
|
|
|
+// /// <param name="id"></param>
|
|
|
+// public ScannerMachine(string id) : base(id)
|
|
|
+// {
|
|
|
+// Env.Schedual.DateTimeChanged += Schedual_DateTimeChanged; // 注册定时器事件
|
|
|
+
|
|
|
+// //A = MachineServer.GetInstance().GetMachine<ScannerMachine>("BarcodeReader1");
|
|
|
+// //A.BarCodeReceived += A_BarCodeReceived;
|
|
|
+
|
|
|
+// //DAL.ReadDataTable();
|
|
|
+// //DAL.ExecuteNonQuery("update APP_TaiLing_TaskManagement set CurrentProduction_Int=CurrentProduction_Int+1 where OrderState_Str='生产中' " +
|
|
|
+// // $"AND WorkShopId_Str='{scanItem.WorkShopId}' AND ProductionLineId_Str='{scanItem.ProductionLineId}'");
|
|
|
+
|
|
|
+// Init();
|
|
|
+// //if (lastOrderId == "")
|
|
|
+// if (lastId == -1)
|
|
|
+// Log.Warn("上次生产的工单号数据已丢失");
|
|
|
+// }
|
|
|
+
|
|
|
+// /// <summary>
|
|
|
+// /// 定时器
|
|
|
+// /// </summary>
|
|
|
+// /// <param name="sender"></param>
|
|
|
+// /// <param name="e"></param>
|
|
|
+// private void Schedual_DateTimeChanged(object sender, SCADA.CommonLib.DateTimeChangedArgs e)
|
|
|
+// {
|
|
|
+// // e.ChangeType == SCADA.CommonLib.DateTimeChangeType.SecondChanged 秒变化
|
|
|
+// // e.TimeFlag.Second 取值
|
|
|
+
|
|
|
+// //if (e.TimeFlag.Second % 60 == 0)
|
|
|
+// //{
|
|
|
+// // // 清空缓存
|
|
|
+// // CustomerEnv.TaskInfoCache.Clear();
|
|
|
+// //}
|
|
|
+
|
|
|
+// if (e.TimeFlag.Second % 1 == 0)
|
|
|
+// {
|
|
|
+// if (scanQueue.Count > 0) // 队列不为空
|
|
|
+// {
|
|
|
+// //ScanCounter();
|
|
|
+// if (BaseDevice.DeviceID == "上料扫码枪")
|
|
|
+// {
|
|
|
+// ImportSyncQueue();
|
|
|
+// }
|
|
|
+// else if (BaseDevice.DeviceID == "下料扫码枪")
|
|
|
+// {
|
|
|
+// ExportSyncQueue();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// if (IsDev)
|
|
|
+// {
|
|
|
+// // 测试
|
|
|
+// if (e.TimeFlag.Second % 5 == 0)
|
|
|
+// {
|
|
|
+// DataReceivedEventArg dr = new DataReceivedEventArg();
|
|
|
+// if (BaseDevice.DeviceID == "上料扫码枪")
|
|
|
+// {
|
|
|
+// LineImport(dr);
|
|
|
+// }
|
|
|
+// else if (BaseDevice.DeviceID == "下料扫码枪")
|
|
|
+// {
|
|
|
+// LineExport(dr);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// }
|
|
|
+
|
|
|
+// /// <summary>
|
|
|
+// /// 扫码事件
|
|
|
+// /// </summary>
|
|
|
+// /// <param name="e"></param>
|
|
|
+// protected override void OnBarCodeReceived(DataReceivedEventArg e)
|
|
|
+// {
|
|
|
+// base.OnBarCodeReceived(e);
|
|
|
+// if (BaseDevice.DeviceID == "上料扫码枪")
|
|
|
+// {
|
|
|
+// LineImport(e);
|
|
|
+// }
|
|
|
+// else if (BaseDevice.DeviceID == "下料扫码枪")
|
|
|
+// {
|
|
|
+// LineExport(e);
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// Log.Warn($"扫码枪ID无效 —— 当前扫码枪ID为{BaseDevice.DeviceID}");
|
|
|
+// }
|
|
|
+// // 持久化数据
|
|
|
+// sqliteDAL.APP_TaiLing_ScanRecord.Insert(
|
|
|
+// new UpdateItem(DBNames.T_Col_Name.APP_TaiLing_ScanRecord.ScannerId_Str, BaseDevice.DeviceID),
|
|
|
+// new UpdateItem(DBNames.T_Col_Name.APP_TaiLing_ScanRecord.ScanData_Str, e.ReceiveMsg),
|
|
|
+// new UpdateItem(DBNames.T_Col_Name.APP_TaiLing_ScanRecord.WorkShopId_Str, CustomerEnv.ProductionLineConfigValue.WorkShopId),
|
|
|
+// new UpdateItem(DBNames.T_Col_Name.APP_TaiLing_ScanRecord.ProductionLineId_Str, CustomerEnv.ProductionLineConfigValue.ProductionLineId)
|
|
|
+// );
|
|
|
+
|
|
|
+
|
|
|
+// }
|
|
|
+
|
|
|
+// /// <summary>
|
|
|
+// /// 初始化
|
|
|
+// /// </summary>
|
|
|
+// private void Init()
|
|
|
+// {
|
|
|
+// // 取上次的扫码记录
|
|
|
+// var scanRecordItem = DAL.APP_TaiLing_ScanRecord.GetData<ScanRecordModel>()?
|
|
|
+// .Where(t => t.ScannerId == BaseDevice.DeviceID && t.WorkShopId == CustomerEnv.ProductionLineConfigValue.WorkShopId
|
|
|
+// && t.ProductionLineId == CustomerEnv.ProductionLineConfigValue.ProductionLineId)
|
|
|
+// .OrderBy(t => t.ID).LastOrDefault();
|
|
|
+// if (scanRecordItem == null)
|
|
|
+// return;
|
|
|
+
|
|
|
+// var taskInfoItem = DAL.APP_TaiLing_TaskManagement.GetData<TaskManagementModel>()?
|
|
|
+// .Where(t => t.OrderId == scanRecordItem.OrderId && t.WorkShopId == CustomerEnv.ProductionLineConfigValue.WorkShopId
|
|
|
+// && t.ProductionLineId == CustomerEnv.ProductionLineConfigValue.ProductionLineId)
|
|
|
+// .OrderBy(t => t.ID).LastOrDefault();
|
|
|
+// if (taskInfoItem == null)
|
|
|
+// return;
|
|
|
+
|
|
|
+// if (BaseDevice.DeviceID == "上料扫码枪")
|
|
|
+// {
|
|
|
+// currentOrderId = taskInfoItem.OrderId;
|
|
|
+// currentMotorcycleTypeName = taskInfoItem.MotorcycleTypeName;
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderSequence = taskInfoItem.OrderSequence;
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderId = currentOrderId;
|
|
|
+// CustomerEnv.CurrentTaskInfo.MotorcycleTypeName = currentMotorcycleTypeName;
|
|
|
+// CustomerEnv.CurrentTaskInfo.CurrentProduction = taskInfoItem.CurrentProduction;
|
|
|
+// }
|
|
|
+// else if (BaseDevice.DeviceID == "下料扫码枪")
|
|
|
+// {
|
|
|
+// //lastOrderId = taskInfoItem.OrderId;
|
|
|
+// lastId = taskInfoItem.ID;
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderSequence = taskInfoItem.OrderSequence;
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderId = taskInfoItem.OrderId;
|
|
|
+// CustomerEnv.CurrentTaskInfo.MotorcycleTypeName = taskInfoItem.MotorcycleTypeName;
|
|
|
+// CustomerEnv.CurrentTaskInfo.CurrentProduction = taskInfoItem.CurrentProduction;
|
|
|
+// }
|
|
|
+
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+// #region 上料
|
|
|
+// /// <summary>
|
|
|
+// /// 上料
|
|
|
+// /// </summary>
|
|
|
+// /// <param name="e">扫码信息</param>
|
|
|
+// public void LineImport(DataReceivedEventArg e)
|
|
|
+// {
|
|
|
+// string scanMsg = e.ReceiveMsg;
|
|
|
+
|
|
|
+// if (IsDev)
|
|
|
+// {
|
|
|
+// // 测试
|
|
|
+// scanMsg = "change&&豪鲨2.0优享E版HD&&H3014010";
|
|
|
+// //scanMsg = "change&&夺冠超智版KS&&H3014010";
|
|
|
+// //Random random = new Random();
|
|
|
+// //scanMsg = $"{random.Next(100, 1000)}";
|
|
|
+// //currentOrderId = "Order0001";
|
|
|
+// //currentMotorcycleTypeName = "豪鲨2.0优享E版HD";
|
|
|
+// //CustomerEnv.CurrentOrderId = currentOrderId;
|
|
|
+// //CustomerEnv.CurrentMotorcycleTypeName = currentMotorcycleTypeName;
|
|
|
+// }
|
|
|
+
|
|
|
+// string[] QRInfo = Regex.Split(scanMsg, "&&", RegexOptions.None);
|
|
|
+
|
|
|
+
|
|
|
+// if (QRInfo.Count() == 1)
|
|
|
+// {
|
|
|
+// // 条形码
|
|
|
+// if (QRInfo[0] == "") // 空信息
|
|
|
+// {
|
|
|
+// Log.Debug("空信息");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// if (lastScanCode == scanMsg) // 重复扫码
|
|
|
+// {
|
|
|
+// Log.Debug("重复扫码");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// lastScanCode = scanMsg;
|
|
|
+
|
|
|
+// // 进队列
|
|
|
+// scanQueue.Enqueue(new ScanRecordModel
|
|
|
+// {
|
|
|
+// ScannerId = "上料扫码枪",
|
|
|
+// ScanData = scanMsg,
|
|
|
+// WorkShopId = CustomerEnv.ProductionLineConfigValue.WorkShopId,
|
|
|
+// ProductionLineId = CustomerEnv.ProductionLineConfigValue.ProductionLineId,
|
|
|
+// ProductId = QRInfo[0],
|
|
|
+// OrderId = currentOrderId,
|
|
|
+// MotorcycleTypeName = currentMotorcycleTypeName
|
|
|
+// });
|
|
|
+// CustomerEnv.ScanList.Add(scanMsg); // 显示用
|
|
|
+// if (CustomerEnv.ScanList.Count > 10)
|
|
|
+// {
|
|
|
+// CustomerEnv.ScanList.RemoveAt(0);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else if (QRInfo.Count() == 3 && QRInfo[0] == "change")
|
|
|
+// {
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderSequence = -1;
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderId = "";
|
|
|
+// CustomerEnv.CurrentTaskInfo.MotorcycleTypeName = "";
|
|
|
+
|
|
|
+// // 换型码
|
|
|
+// currentMotorcycleTypeName = QRInfo[1];
|
|
|
+
|
|
|
+// //// 查询车型
|
|
|
+// //currentMotorcycleTypeName = DAL.APP_TaiLing_MotorcycleTypeManagement.GetData<MotorcycleTypeModel>()?
|
|
|
+// // .Where(t => t.MotorcycleTypeId == QRInfo[2])
|
|
|
+// // .OrderBy(t => t.MotorcycleTypeId).Select(t => t.MotorcycleTypeName)
|
|
|
+// // .LastOrDefault();
|
|
|
+
|
|
|
+// Log.Debug($"正在换型:{currentMotorcycleTypeName}");
|
|
|
+// // 查询工单号
|
|
|
+// var taskList = DAL.APP_TaiLing_TaskManagement.GetData<TaskManagementModel>()?
|
|
|
+// .Where(t => t.MotorcycleTypeName == currentMotorcycleTypeName
|
|
|
+// && t.OrderState != "已生产"
|
|
|
+// && t.WorkShopId == CustomerEnv.ProductionLineConfigValue.WorkShopId
|
|
|
+// && t.ProductionLineId == CustomerEnv.ProductionLineConfigValue.ProductionLineId)
|
|
|
+// .ToList();
|
|
|
+
|
|
|
+// if (taskList == null)
|
|
|
+// {
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderSequence = -1;
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderId = "";
|
|
|
+// CustomerEnv.CurrentTaskInfo.MotorcycleTypeName = "查无工单任务\r\n请先添加工单";
|
|
|
+// Log.Warn("查无工单任务,请先添加工单");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// if (taskList.Count <= 0)
|
|
|
+// {
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderSequence = -1;
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderId = "";
|
|
|
+// CustomerEnv.CurrentTaskInfo.MotorcycleTypeName = "查无工单任务\r\n请先添加工单";
|
|
|
+// Log.Warn("查无工单任务,请先添加工单");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+
|
|
|
+// var OrderSequence = -1;
|
|
|
+// // 工单切换
|
|
|
+// if (lastScanCode != scanMsg) // 换码
|
|
|
+// {
|
|
|
+// orderIndex = 0;
|
|
|
+// lastScanCode = scanMsg;
|
|
|
+// }
|
|
|
+// if (currentOrderId != taskList[orderIndex].OrderId)
|
|
|
+// {
|
|
|
+// currentOrderId = taskList[orderIndex].OrderId;
|
|
|
+// OrderSequence = taskList[orderIndex].OrderSequence;
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// if (orderIndex < taskList.Count - 1)
|
|
|
+// {
|
|
|
+// orderIndex++;
|
|
|
+// currentOrderId = taskList[orderIndex].OrderId;
|
|
|
+// OrderSequence = taskList[orderIndex].OrderSequence;
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// // 循环切换
|
|
|
+// orderIndex = 0;
|
|
|
+// currentOrderId = taskList[orderIndex].OrderId;
|
|
|
+// OrderSequence = taskList[orderIndex].OrderSequence;
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderSequence = OrderSequence;
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderId = currentOrderId;
|
|
|
+// CustomerEnv.CurrentTaskInfo.MotorcycleTypeName = currentMotorcycleTypeName;
|
|
|
+
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// Log.Warn("二维码信息不符合规则");
|
|
|
+// }
|
|
|
+
|
|
|
+// if (currentOrderId == "")
|
|
|
+// return;
|
|
|
+// var taskInfoItem = DAL.APP_TaiLing_TaskManagement.GetData<TaskManagementModel>()?
|
|
|
+// .Where(t => t.OrderId == currentOrderId && t.WorkShopId == CustomerEnv.ProductionLineConfigValue.WorkShopId
|
|
|
+// && t.ProductionLineId == CustomerEnv.ProductionLineConfigValue.ProductionLineId)
|
|
|
+// .OrderBy(t => t.ID).LastOrDefault();
|
|
|
+// if (taskInfoItem == null)
|
|
|
+// return;
|
|
|
+// CustomerEnv.CurrentTaskInfo.CurrentProduction = taskInfoItem.CurrentProduction;
|
|
|
+// }
|
|
|
+
|
|
|
+// /// <summary>
|
|
|
+// /// 上料同步队列
|
|
|
+// /// </summary>
|
|
|
+// public void ImportSyncQueue()
|
|
|
+// {
|
|
|
+// // 出队列
|
|
|
+// ScanRecordModel scanItem = scanQueue.Dequeue() as ScanRecordModel;
|
|
|
+// //CustomerEnv.ScanList.RemoveAt(0);
|
|
|
+
|
|
|
+// // 保存上料记录
|
|
|
+// DAL.APP_TaiLing_ScanRecord.Insert(
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ScanRecord.ScannerId_Str, scanItem.ScannerId),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ScanRecord.ScanData_Str, scanItem.ScanData),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ScanRecord.WorkShopId_Str, scanItem.WorkShopId),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ScanRecord.ProductionLineId_Str, scanItem.ProductionLineId),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ScanRecord.ProductId_Str, scanItem.ProductId),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ScanRecord.OrderId_Str, scanItem.OrderId),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ScanRecord.MotorcycleTypeName_Str, scanItem.MotorcycleTypeName)
|
|
|
+// );
|
|
|
+
|
|
|
+// // 产品朔源记录
|
|
|
+// DAL.APP_TaiLing_ProductionRecord.Insert(
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ProductionRecord.StartTime_Dt, DateTime.Now.Format()),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ProductionRecord.WorkShopId_Str, scanItem.WorkShopId),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ProductionRecord.ProductionLineId_Str, scanItem.ProductionLineId),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ProductionRecord.ProductId_Str, scanItem.ProductId)
|
|
|
+// );
|
|
|
+
|
|
|
+// // 生产状态为“待生产”
|
|
|
+// var taskInfo = DAL.APP_TaiLing_TaskManagement.GetData<TaskManagementModel>()?
|
|
|
+// .Where(t => t.OrderId == scanItem.OrderId && t.WorkShopId == scanItem.WorkShopId
|
|
|
+// && t.ProductionLineId == scanItem.ProductionLineId && t.OrderState == "待生产").ToList();
|
|
|
+// if (taskInfo == null)
|
|
|
+// return;
|
|
|
+// if (taskInfo.Count <= 0)
|
|
|
+// return;
|
|
|
+
|
|
|
+
|
|
|
+// // 开始时间是否为默认值 new DateTime()
|
|
|
+// var firstWorkingTask = taskInfo.Where(t => t.WorkStartTime == new DateTime()).ToList();
|
|
|
+// if (firstWorkingTask.Count > 0)
|
|
|
+// {
|
|
|
+// // 开始时间为默认值
|
|
|
+// // 第一次生产更新开始生产时间和生产状态
|
|
|
+// DAL.APP_TaiLing_TaskManagement.Update($"OrderId_Str='{scanItem.OrderId}' AND WorkShopId_Str='{scanItem.WorkShopId}' AND ProductionLineId_Str='{scanItem.ProductionLineId}'",
|
|
|
+// new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "生产中"),
|
|
|
+// new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.WorkStartTime_Dt, DateTime.Now.Format())
|
|
|
+// );
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// // 非第一次生产更新生产状态
|
|
|
+// DAL.APP_TaiLing_TaskManagement.Update($"OrderId_Str='{scanItem.OrderId}' AND WorkShopId_Str='{scanItem.WorkShopId}' AND ProductionLineId_Str='{scanItem.ProductionLineId}'",
|
|
|
+// new UpdateItem(SqlSchema.DBNames.T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "生产中")
|
|
|
+// );
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// #endregion
|
|
|
+
|
|
|
+
|
|
|
+// #region 下料
|
|
|
+
|
|
|
+// /// <summary>
|
|
|
+// /// 下料
|
|
|
+// /// </summary>
|
|
|
+// /// <param name="e">扫码信息</param>
|
|
|
+// public void LineExport(DataReceivedEventArg e)
|
|
|
+// {
|
|
|
+// string scanMsg = e.ReceiveMsg;
|
|
|
+
|
|
|
+// if (IsDev)
|
|
|
+// {
|
|
|
+// // 测试
|
|
|
+// scanMsg = "33333333333";
|
|
|
+// }
|
|
|
+
|
|
|
+// // 条形码
|
|
|
+// if (scanMsg == "") // 空信息
|
|
|
+// {
|
|
|
+// Log.Debug("空信息");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// if (lastScanCode == scanMsg && !IsDev) // 重复扫码,调试允许重复
|
|
|
+// {
|
|
|
+// Log.Debug("重复扫码");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// lastScanCode = scanMsg;
|
|
|
+
|
|
|
+// // 升序取最新的数据
|
|
|
+// ScanRecordModel scanRecord = DAL.APP_TaiLing_ScanRecord.GetData<ScanRecordModel>()?
|
|
|
+// .Where(t => t.ProductId == scanMsg && t.ScannerId == "上料扫码枪")
|
|
|
+// .OrderBy(t => t.ID).LastOrDefault();
|
|
|
+// if (scanRecord == null)
|
|
|
+// {
|
|
|
+// //CustomerEnv.CurrentOrderId = $"请先将“{scanMsg}”绑定车型";
|
|
|
+// //CustomerEnv.CurrentMotorcycleTypeName = "";
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderSequence = -1;
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderId = "";
|
|
|
+// CustomerEnv.CurrentTaskInfo.MotorcycleTypeName = $"请先将\r\n“{scanMsg}”\r\n绑定车型";
|
|
|
+// Log.Warn($"请先将“{scanMsg}”绑定车型");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+
|
|
|
+// currentOrderId = scanRecord.OrderId;
|
|
|
+// currentMotorcycleTypeName = scanRecord.MotorcycleTypeName;
|
|
|
+// //CustomerEnv.CurrentOrderId = currentOrderId;
|
|
|
+// //CustomerEnv.CurrentMotorcycleTypeName = currentMotorcycleTypeName;
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderId = currentOrderId;
|
|
|
+// CustomerEnv.CurrentTaskInfo.MotorcycleTypeName = currentMotorcycleTypeName;
|
|
|
+
|
|
|
+// var taskInfo = DAL.APP_TaiLing_TaskManagement.GetData<TaskManagementModel>()?
|
|
|
+// .Where(t => t.OrderId == currentOrderId
|
|
|
+// && t.WorkShopId == CustomerEnv.ProductionLineConfigValue.WorkShopId
|
|
|
+// && t.ProductionLineId == CustomerEnv.ProductionLineConfigValue.ProductionLineId)
|
|
|
+// .OrderBy(t => t.ID).Last();
|
|
|
+// CustomerEnv.CurrentTaskInfo.OrderSequence = taskInfo.OrderSequence;
|
|
|
+
|
|
|
+// // 进队列
|
|
|
+// scanQueue.Enqueue(new ScanRecordModel
|
|
|
+// {
|
|
|
+// ScannerId = "下料扫码枪",
|
|
|
+// ScanData = scanMsg,
|
|
|
+// WorkShopId = CustomerEnv.ProductionLineConfigValue.WorkShopId,
|
|
|
+// ProductionLineId = CustomerEnv.ProductionLineConfigValue.ProductionLineId,
|
|
|
+// ProductId = scanMsg,
|
|
|
+// OrderId = currentOrderId,
|
|
|
+// MotorcycleTypeName = currentMotorcycleTypeName
|
|
|
+// });
|
|
|
+// CustomerEnv.ScanList.Add(scanMsg); // 显示用
|
|
|
+// if (CustomerEnv.ScanList.Count > 10)
|
|
|
+// {
|
|
|
+// CustomerEnv.ScanList.RemoveAt(0);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// /// <summary>
|
|
|
+// /// 下料同步队列
|
|
|
+// /// </summary>
|
|
|
+// public void ExportSyncQueue()
|
|
|
+// {
|
|
|
+// // 出队列
|
|
|
+// ScanRecordModel scanItem = scanQueue.Dequeue() as ScanRecordModel;
|
|
|
+// //CustomerEnv.ScanList.RemoveAt(0);
|
|
|
+
|
|
|
+// // 保存下料记录
|
|
|
+// DAL.APP_TaiLing_ScanRecord.Insert(
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ScanRecord.ScannerId_Str, scanItem.ScannerId),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ScanRecord.ScanData_Str, scanItem.ScanData),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ScanRecord.WorkShopId_Str, scanItem.WorkShopId),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ScanRecord.ProductionLineId_Str, scanItem.ProductionLineId),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ScanRecord.ProductId_Str, scanItem.ProductId),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ScanRecord.OrderId_Str, scanItem.OrderId),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_ScanRecord.MotorcycleTypeName_Str, scanItem.MotorcycleTypeName)
|
|
|
+// );
|
|
|
+
|
|
|
+// var taskInfo = DAL.APP_TaiLing_TaskManagement.GetData<TaskManagementModel>()?
|
|
|
+// .Where(t => t.OrderId == scanItem.OrderId && t.WorkShopId == scanItem.WorkShopId
|
|
|
+// && t.OrderState != "已生产" && t.ProductionLineId == scanItem.ProductionLineId)
|
|
|
+// .OrderBy(t => t.ID).LastOrDefault();
|
|
|
+// if (taskInfo == null)
|
|
|
+// {
|
|
|
+// Log.Warn($"“{scanItem.OrderId}”-查无生产的订单,请确认订单信息及状态!");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+// // 更新工单
|
|
|
+// // 计数
|
|
|
+// //DAL.APP_TaiLing_TaskManagement.Update($"OrderId_Str='{scanItem.OrderId}' AND WorkShopId_Str='{scanItem.WorkShopId}' AND ProductionLineId_Str='{scanItem.ProductionLineId}'",
|
|
|
+// // new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.CurrentProduction_Int, taskInfo.CurrentProduction + 1));
|
|
|
+// DAL.APP_TaiLing_TaskManagement.Update($"ID={taskInfo.ID}",
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.CurrentProduction_Int, taskInfo.CurrentProduction + 1));
|
|
|
+// CustomerEnv.CurrentTaskInfo.CurrentProduction = taskInfo.CurrentProduction + 1;
|
|
|
+
|
|
|
+
|
|
|
+// if (taskInfo.CurrentProduction + 1 >= taskInfo.ScheduledProduction)
|
|
|
+// {
|
|
|
+// // 结束生产
|
|
|
+// var dateDiff = (DateTime.Now - taskInfo.WorkStartTime).TotalSeconds.ToInt(); // 时间差/s
|
|
|
+// //DAL.APP_TaiLing_TaskManagement.Update($"OrderId_Str='{scanItem.OrderId}' AND WorkShopId_Str='{scanItem.WorkShopId}' AND ProductionLineId_Str='{scanItem.ProductionLineId}'",
|
|
|
+// // new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.WorkEndTime_Dt, DateTime.Now.Format()),
|
|
|
+// // new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.DurationSec_Int, dateDiff),
|
|
|
+// // new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "已生产")
|
|
|
+// //);
|
|
|
+// DAL.APP_TaiLing_TaskManagement.Update($"ID={taskInfo.ID}",
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.WorkEndTime_Dt, DateTime.Now.Format()),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.DurationSec_Int, dateDiff),
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "已生产")
|
|
|
+// );
|
|
|
+// //// 更新API缓存
|
|
|
+// //if (tableCacheItem != null)
|
|
|
+// //{
|
|
|
+// // tableCacheItem.WorkEndTime = DateTime.Now;
|
|
|
+// // tableCacheItem.DurationSec = dateDiff;
|
|
|
+// // tableCacheItem.OrderState = "已生产";
|
|
|
+// //}
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+// // 更新产品记录
|
|
|
+// DAL.ExecuteNonQuery("UPDATE APP_TaiLing_ProductionRecord SET EndTime_Dt=GETDATE(), " +
|
|
|
+// "DurationSec_Int=DATEDIFF(s, StartTime_Dt, GETDATE()), ModifyTime_Dt=GETDATE() " +
|
|
|
+// $"WHERE ProductId_Str='{scanItem.ProductId}' AND WorkShopId_Str='{scanItem.WorkShopId}' " +
|
|
|
+// $"AND ProductionLineId_Str='{scanItem.ProductionLineId}'");
|
|
|
+
|
|
|
+
|
|
|
+// // 切换生产工单
|
|
|
+// //if (currentOrderId != lastOrderId)
|
|
|
+// if (taskInfo.ID != lastId)
|
|
|
+// {
|
|
|
+// // 表示该订单已被切换了
|
|
|
+// //var oldTaskInfo = DAL.APP_TaiLing_TaskManagement.GetData<TaskManagementModel>()?
|
|
|
+// // .Where(t => t.OrderId == lastOrderId).OrderBy(t => t.ID)
|
|
|
+// // .Select(t => t.OrderState).LastOrDefault();
|
|
|
+// var oldTaskInfo = DAL.APP_TaiLing_TaskManagement.GetData<TaskManagementModel>()?
|
|
|
+// .Where(t => t.ID == lastId).Select(t => t.OrderState).LastOrDefault();
|
|
|
+// //if (oldTaskInfo == null)
|
|
|
+// // return;
|
|
|
+// if (oldTaskInfo == "生产中")
|
|
|
+// {
|
|
|
+// //DAL.APP_TaiLing_TaskManagement.Update($"OrderId_Str='{lastOrderId}' AND WorkShopId_Str='{scanItem.WorkShopId}' AND ProductionLineId_Str='{scanItem.ProductionLineId}'",
|
|
|
+// // new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "待生产"));
|
|
|
+// DAL.APP_TaiLing_TaskManagement.Update($"ID={lastId}",
|
|
|
+// new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "待生产"));
|
|
|
+
|
|
|
+// }
|
|
|
+// //lastOrderId = currentOrderId;
|
|
|
+// lastId = taskInfo.ID;
|
|
|
+// Log.Debug($"工单已切换为:{lastOrderId}");
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+// #endregion
|
|
|
+
|
|
|
+
|
|
|
+// ///// <summary>
|
|
|
+// ///// 取出缓存表的数据
|
|
|
+// ///// </summary>
|
|
|
+// ///// <param name="filter"></param>
|
|
|
+// ///// <returns></returns>
|
|
|
+// //private TaskManagementModel GetTableCacheItem(string filter)
|
|
|
+// //{
|
|
|
+// // if (CustomerEnv.TaskInfoCache.Count <= 0)
|
|
|
+// // return null;
|
|
|
+// // var result = CustomerEnv.TaskInfoCache.Where(t => t.OrderId == filter)
|
|
|
+// // .OrderBy(t => t.ID).LastOrDefault();
|
|
|
+// // return result;
|
|
|
+// //}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// /// <summary>
|
|
|
+// /// 释放非托管资源
|
|
|
+// /// </summary>
|
|
|
+// public override void Dispose()
|
|
|
+// {
|
|
|
+// Env.Schedual.DateTimeChanged -= Schedual_DateTimeChanged; // 销毁定时器
|
|
|
+// base.Dispose();
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|