diff --git a/src/Khd.Core.Api/Controllers/ReceiveProdPlanController.cs b/src/Khd.Core.Api/Controllers/ReceiveProdPlanController.cs deleted file mode 100644 index 905bf5b..0000000 --- a/src/Khd.Core.Api/Controllers/ReceiveProdPlanController.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Khd.Core.Application.Interface; -using Khd.Core.Domain.Models; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Masuit.Tools.Logging; -using System; -using NuGet.Protocol; -using Khd.Core.Application; -using Khd.Core.Domain.Dto.webapi; -using Microsoft.Build.Utilities; -using Masuit.Tools; - -namespace Khd.Core.Api.Controllers -{ - [Route("wcs/[controller]")] - [ApiController] - public class ReceiveProdPlanController : ControllerBase - { - //private readonly IMesProdPlanApplication _application; - - - //public ReceiveProdPlanController(IMesProdPlanApplication application) - //{ - // _application = application; - //} - - [HttpPost] - public ReponseBase SaveProdPlan(RequestInfo model) - { - LogManager.Info($"收到MES接口信息:{model.ToJsonString()}"); - //return _application.SaveProdPlan(model); - return null; - } - - } -} \ No newline at end of file diff --git a/src/Khd.Core.Api/Controllers/RecieveRcsController.cs b/src/Khd.Core.Api/Controllers/RecieveRcsController.cs new file mode 100644 index 0000000..ac8927f --- /dev/null +++ b/src/Khd.Core.Api/Controllers/RecieveRcsController.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Khd.Core.Application.Interface; +using Khd.Core.Domain.Models; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Masuit.Tools.Logging; +using System; +using NuGet.Protocol; +using Khd.Core.Application; +using Khd.Core.Domain.Dto.webapi; +using Microsoft.Build.Utilities; +using Masuit.Tools; + +namespace Khd.Core.Api.Controllers +{ + [Route("wcs/[controller]")] + [ApiController] + public class RecieveRcsController : ControllerBase + { + private readonly IWcsTaskApplication _application; + public RecieveRcsController(IWcsTaskApplication application) + { + _application = application; + } + + /// + /// 接收agv接收任务通知接口 + /// + /// + /// + [HttpPost("agvCallback")] + public ReponseagvCallbackDto agvCallback(string a) + { + LogManager.Info($"RecieveRcsController接口信息:{a.ToJsonString()}"); + agvCallbackDto agvCallbackDto=new agvCallbackDto(); + return _application.AgvCallback(agvCallbackDto); + + } + + } +} \ No newline at end of file diff --git a/src/Khd.Core.Api/appsettings.json b/src/Khd.Core.Api/appsettings.json index 243821c..ee669a9 100644 --- a/src/Khd.Core.Api/appsettings.json +++ b/src/Khd.Core.Api/appsettings.json @@ -11,7 +11,7 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "DefaultConnection": "server=106.12.13.113;port=3336;database=khd_suspension_chain;uid=khd;pwd=khd@123;charset='utf8';persistsecurityinfo=True;SslMode=none;Allow User Variables=True" + "DefaultConnection": "server=106.12.13.113;port=3336;database=khd_jyhb;uid=khd;pwd=khd@123;charset='utf8';persistsecurityinfo=True;SslMode=none;Allow User Variables=True" // "DefaultConnection": "Data Source=localhost;Initial Catalog=lanju_op_xiaolan_ds;Persist Security Info=True;User ID=sa;Password=root;MultipleActiveResultSets=True;TrustServerCertificate=True", //"DefaultConnection": "Data Source=121.36.58.109;Initial Catalog=lanju_op_xiaolan_ds;Persist Security Info=True;User ID=sa;Password=haiwei@123;MultipleActiveResultSets=True;TrustServerCertificate=True" }, diff --git a/src/Khd.Core.Application/ApplicationExtensions.cs b/src/Khd.Core.Application/ApplicationExtensions.cs index 84271ec..fb9b924 100644 --- a/src/Khd.Core.Application/ApplicationExtensions.cs +++ b/src/Khd.Core.Application/ApplicationExtensions.cs @@ -8,7 +8,7 @@ namespace Khd.Core.Application { public static void AddApplication(this IServiceCollection services) { - //services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/src/Khd.Core.Application/Interface/IBaseApplication.cs b/src/Khd.Core.Application/Interface/IBaseApplication.cs index c8aafcf..2303e3b 100644 --- a/src/Khd.Core.Application/Interface/IBaseApplication.cs +++ b/src/Khd.Core.Application/Interface/IBaseApplication.cs @@ -7,6 +7,6 @@ namespace Khd.Core.Application.Interface { } - public interface IProWetMaterialPlanDetail { } + } \ No newline at end of file diff --git a/src/Khd.Core.Application/Interface/IWcsTaskApplication.cs b/src/Khd.Core.Application/Interface/IWcsTaskApplication.cs new file mode 100644 index 0000000..d8f4f32 --- /dev/null +++ b/src/Khd.Core.Application/Interface/IWcsTaskApplication.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Khd.Core.Domain.Dto.webapi; +using Khd.Core.Domain.Models; + +namespace Khd.Core.Application.Interface +{ + public interface IWcsTaskApplication : IBaseApplication + { + WcsTask Get(int id); + WcsTask Add(WcsTask model); + WcsTask Update(WcsTask model); + + ReponseagvCallbackDto AgvCallback(agvCallbackDto agvCallbackDto); + + + } +} \ No newline at end of file diff --git a/src/Khd.Core.Application/WcsTaskApplication.cs b/src/Khd.Core.Application/WcsTaskApplication.cs new file mode 100644 index 0000000..848ec27 --- /dev/null +++ b/src/Khd.Core.Application/WcsTaskApplication.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +using Khd.Core.Application.Interface; +using Khd.Core.Domain.Dto.webapi; +using Khd.Core.Domain.Models; +using Khd.Core.EntityFramework; +using Masuit.Tools; +using Masuit.Tools.Logging; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Microsoft.Extensions.DependencyInjection; +using Z.EntityFramework.Plus; + +namespace Khd.Core.Application +{ + public class WcsTaskApplication : IWcsTaskApplication + { + private readonly DefaultDbContext _dbContext; + + public WcsTaskApplication(IServiceProvider serviceProvider) + { + _dbContext = serviceProvider.GetService(); + } + + public WcsTask Get(int id) + { + var entity = _dbContext.WcsTask + .Where(c => 1== 1) + .FirstOrDefault(); + return entity; + } + public WcsTask Add(WcsTask model) + { + var entity = _dbContext.Add(model); + _dbContext.SaveChanges(); + return entity.Entity; + + } + public WcsTask Update(WcsTask model) + { + var list = _dbContext.WcsTask.Where(t => t.objid == model.objid).Update(a => model); + return model; + } + /// + /// 接收agv接收任务通知接口 + /// + /// + /// + public ReponseagvCallbackDto AgvCallback(agvCallbackDto agvCallbackDto) + { + ReponseagvCallbackDto reponseagvCallbackDto = new ReponseagvCallbackDto(); + //记录日志 + LogManager.Info("AgvCallback入参:"+ agvCallbackDto.ToJsonString()); + //处理逻辑 + + //返回请求 + reponseagvCallbackDto.code = "0"; + reponseagvCallbackDto.message = "成功"; + reponseagvCallbackDto.reqCode = reponseagvCallbackDto.reqCode; + return reponseagvCallbackDto; + + } + } +} \ No newline at end of file diff --git a/src/Khd.Core.Domain/Dto/webapi/ReponseBase.cs b/src/Khd.Core.Domain/Dto/webapi/ReponseBase.cs index 51674a2..7ad3ac8 100644 --- a/src/Khd.Core.Domain/Dto/webapi/ReponseBase.cs +++ b/src/Khd.Core.Domain/Dto/webapi/ReponseBase.cs @@ -12,4 +12,44 @@ namespace Khd.Core.Domain.Dto.webapi public string CODE { get; set; } public string MESSAGE { get; set; } } + /// + /// 手工出库参数 + /// + public class ManualOutWareDto + { + public string MATERIAL_CODE { get; set; } + public string BATCH_NO { get; set; } + public int QTY { get; set; } + public string LOCALTION_CODE { get; set; } + public string ORDER_CODE { get; set; } + public string WARE_TYPE { get; set; } + public string CREATE_TIME { get; set; } + } + /// + /// 盘点参数 + /// + public class CheckDto + { + public string MATERIAL_CODE { get; set; } + public string BATCH_NO { get; set; } + public int QTY { get; set; } + public string LOCALTION_CODE { get; set; } + public string CHECK_CODE { get; set; } + + public string CREATE_TIME { get; set; } + } + /// + /// 手工出库入参 + /// + public class RequestManualOutWare + { + List DATA { get; set; } + } + /// + /// 盘点入参 + /// + public class RequestCheck + { + List DATA { get; set; } + } } diff --git a/src/Khd.Core.Domain/Dto/webapi/agvCallback.cs b/src/Khd.Core.Domain/Dto/webapi/agvCallback.cs index d18c30d..7f9e98d 100644 --- a/src/Khd.Core.Domain/Dto/webapi/agvCallback.cs +++ b/src/Khd.Core.Domain/Dto/webapi/agvCallback.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; namespace Khd.Core.Domain.Dto.webapi { + //RCS调用WCS接口参数 public class agvCallbackDto { /// @@ -34,5 +35,21 @@ namespace Khd.Core.Domain.Dto.webapi public string seq { get; set; } public string eqpCode { get; set; } } + public class ReponseagvCallbackDto + { + /// + /// 返回码 + /// + public string code { get; set; } + /// + /// 返回消息 + /// + public string message { get; set; } + /// + /// 请求编号 + /// + public string reqCode { get; set; } + } + } diff --git a/src/Khd.Core.Domain/Models/WcsCmd.cs b/src/Khd.Core.Domain/Models/WcsCmd.cs index 13956af..01a7ee8 100644 --- a/src/Khd.Core.Domain/Models/WcsCmd.cs +++ b/src/Khd.Core.Domain/Models/WcsCmd.cs @@ -135,6 +135,12 @@ namespace Khd.Core.Domain.Models /// [Column("remark")] public string remark { get; set; } + + /// + /// 下发标志 + /// + [Column("send_flag")] + public int? sendFlag { get; set; } } } diff --git a/src/Khd.Core.Domain/Models/WcsTask.cs b/src/Khd.Core.Domain/Models/WcsTask.cs index a724bad..81cc9a9 100644 --- a/src/Khd.Core.Domain/Models/WcsTask.cs +++ b/src/Khd.Core.Domain/Models/WcsTask.cs @@ -62,7 +62,7 @@ namespace Khd.Core.Domain.Models /// 物料号 /// [Column("material_no")] - public int? materialNo { get; set; } + public string? materialNo { get; set; } /// /// 数量 @@ -177,6 +177,8 @@ namespace Khd.Core.Domain.Models /// [Column("remark")] public string remark { get; set; } + + } } diff --git a/src/Khd.Core.Wcs/Wcs/SnowflakeIdGenerator.cs b/src/Khd.Core.Wcs/Global/SnowflakeIdGenerator.cs similarity index 100% rename from src/Khd.Core.Wcs/Wcs/SnowflakeIdGenerator.cs rename to src/Khd.Core.Wcs/Global/SnowflakeIdGenerator.cs diff --git a/src/Khd.Core.Wcs/Wcs/CreateTaskByRecord.cs b/src/Khd.Core.Wcs/Wcs/CreateTaskByRecord.cs index a2ca3ad..7bfc31e 100644 --- a/src/Khd.Core.Wcs/Wcs/CreateTaskByRecord.cs +++ b/src/Khd.Core.Wcs/Wcs/CreateTaskByRecord.cs @@ -113,7 +113,6 @@ namespace Khd.Core.Wcs.Wcs dbContext.Add(wcsTask); dbContext.SaveChanges(); } - } } catch (Exception ex) diff --git a/src/Khd.Core.Wcs/Wcs/DownLine.cs b/src/Khd.Core.Wcs/Wcs/DownLine.cs deleted file mode 100644 index cd03829..0000000 --- a/src/Khd.Core.Wcs/Wcs/DownLine.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Khd.Core.Wcs.Wcs -{ - /// - /// 下件点线程 - /// - public class DownLine - { - } -} diff --git a/src/Khd.Core.Wcs/Wcs/FirstFloor.cs b/src/Khd.Core.Wcs/Wcs/FirstFloor.cs index 3d44ab0..67c3193 100644 --- a/src/Khd.Core.Wcs/Wcs/FirstFloor.cs +++ b/src/Khd.Core.Wcs/Wcs/FirstFloor.cs @@ -23,16 +23,20 @@ using Thrift.Protocol; using System.Security.Cryptography.Xml; using Z.EntityFramework.Plus; using System.Net.NetworkInformation; +using Khd.Core.Application.Interface; +using Khd.Core.Application; namespace Khd.Core.Wcs.Wcs { /// - /// 一楼线程 + /// 一楼线程(包括接驳位,提升机调度) /// public class FirstFloor { private readonly IHost _host; private readonly Plc.S7.Plc _plc; + private long F01=1; + private long T01 = 6; /// /// 一楼RFID 读 /// @@ -53,35 +57,82 @@ namespace Khd.Core.Wcs.Wcs /// 流水号 读 /// BasePlcpoint? serialno01 { get; set; } + /// - /// 反馈流水号 写 - /// - BasePlcpoint? feedserialno01 { get; set; } - /// - /// 一楼提升机流水号 读 + /// 提升机流水号 读 /// BasePlcpoint? serialno06 { get; set; } /// - /// 一楼提升机状态 读 + /// 提升机状态 读 /// BasePlcpoint? equipstate06 { get; set; } /// - /// 一楼提升机任务状态 读 + /// 提升机任务状态 读 /// BasePlcpoint? taskstate06 { get; set; } /// - /// 一楼提升机当前楼层 写 + /// 提升机当前楼层 写 /// BasePlcpoint? currentfloor06 { get; set; } /// - /// 一楼提升机目的楼层 写 + /// 提升机目的楼层 写 /// BasePlcpoint? targetfloor06 { get; set; } /// - /// 一楼提升机到位信号 读 + /// 提升机到位信号 读 /// BasePlcpoint? linesignal06 { get; set; } + /// + /// 一楼提升机前允许取 读 + /// + BasePlcpoint? hoisterallowedtake01 { get; set; } + /// + /// 一楼提升机前反馈流水号 读 + /// + BasePlcpoint? feedserialno01 { get; set; } + + /// + /// 二楼提升机前允许取 读 + /// + BasePlcpoint? hoisterallowedtake02 { get; set; } + /// + /// 二楼提升机前反馈流水号 读 + /// + BasePlcpoint? feedserialno02 { get; set; } + + /// + /// 三楼提升机前允许取 读 + /// + BasePlcpoint? hoisterallowedtake03 { get; set; } + /// + /// 三楼提升机前反馈流水号 读 + /// + BasePlcpoint? feedserialno03 { get; set; } + + /// + /// 四楼提升机前允许取 读 + /// + BasePlcpoint? hoisterallowedtake04 { get; set; } + /// + /// 四楼提升机前反馈流水号 读 + /// + BasePlcpoint? feedserialno04 { get; set; } + + /// + /// 五楼提升机前允许取 读 + /// + BasePlcpoint? hoisterallowedtake05 { get; set; } + /// + /// 五楼提升机前反馈流水号 读 + /// + BasePlcpoint? feedserialno05 { get; set; } + + + + + + public FirstFloor(IHost host, Plc.S7.Plc plc, string siteNo) { this._host = host; @@ -97,8 +148,7 @@ namespace Khd.Core.Wcs.Wcs this.wcsrun01 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorLine") && t.plcpointNo.Contains("wcsrun01")); //流水号 读 this.serialno01 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorLine") && t.plcpointNo.Contains("serialno01")); - //反馈流水号 写 - this.feedserialno01 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorLine") && t.plcpointNo.Contains("feedserialno01")); + //一楼提升机流水号 读 this.serialno06 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorHoister") && t.plcpointNo.Contains("serialno06")); @@ -112,6 +162,20 @@ namespace Khd.Core.Wcs.Wcs this.targetfloor06 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorHoister") && t.plcpointNo.Contains("targetfloor06")); //一楼提升机到位信号 读 this.linesignal06 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorHoister") && t.plcpointNo.Contains("linesignal06")); + + //一楼提升机前允许取 + this.hoisterallowedtake01 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorBeforeHoister") && t.plcpointNo.Contains("hoisterallowedtake01")); + //一楼提升机前反馈流水号 + this.feedserialno01 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FirstFloorBeforeHoister") && t.plcpointNo.Contains("feedserialno01")); + this.hoisterallowedtake02 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("SecondFloorBeforeHoister") && t.plcpointNo.Contains("hoisterallowedtake02")); + this.feedserialno02 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("SecondFloorBeforeHoister") && t.plcpointNo.Contains("feedserialno02")); + this.hoisterallowedtake03 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("ThirdFloorBeforeHoister") && t.plcpointNo.Contains("hoisterallowedtake03")); + this.feedserialno03 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("ThirdFloorBeforeHoister") && t.plcpointNo.Contains("feedserialno03")); + this.hoisterallowedtake04 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FourthlyFloorBeforeHoister") && t.plcpointNo.Contains("hoisterallowedtake04")); + this.feedserialno04 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FourthlyFloorBeforeHoister") && t.plcpointNo.Contains("feedserialno04")); + this.hoisterallowedtake05 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FifthFloorBeforeHoister") && t.plcpointNo.Contains("hoisterallowedtake05")); + this.feedserialno05 = StaticData.BasePlcpointList.FirstOrDefault(t => t.equipmentNo.Contains("FifthFloorBeforeHoister") && t.plcpointNo.Contains("feedserialno05")); + } /// /// 启动线程 @@ -142,7 +206,7 @@ namespace Khd.Core.Wcs.Wcs var ispallet01Value = this._plc.Read(this.ispallet01.plcpointAddress); //是否有托盘 读 var wcsrun01Value = this._plc.Read(this.wcsrun01.plcpointAddress); //去向 写 var serialno01Value = this._plc.Read(this.serialno01.plcpointAddress); //流水号 读 - var feedserialno01Value = this._plc.Read(this.feedserialno01.plcpointAddress); //反馈流水号 写 + using (var scope = _host.Services.CreateScope()) { using (var dbContext = scope.ServiceProvider.GetRequiredService()) @@ -153,12 +217,59 @@ namespace Khd.Core.Wcs.Wcs //正常托盘到位 if (Convert.ToInt32(linesignal01Value) != 0 && Convert.ToInt32(serialno01Value) != 0 && Convert.ToInt32(ispallet01Value) == 1 && Convert.ToInt32(ispallet01Value) != 0) { - //根据托盘号获取物料码 - //下发去向 + //判断task表里没有该rfid的未完成的入库信息,未下发去向 + var task = dbContext.WcsTask.Where(t => t.customerNo == RFID001Value.ToString() && t.taskStatus < 1).FirstOrDefault(); + if (task == null) + { + //根据托盘号获取物料码 + var material = dbContext.MesBasePalletInfo.Where(t => t.palletInfoCode == RFID001Value.ToString()).FirstOrDefault(); + if (material != null) + { + var warehouseId = dbContext.WmsWarehouseMaterial.Where(t => t.storageType == "1" && t.storageId == material.materialId).FirstOrDefault()?.warehouseId; + if (warehouseId != null) + { + var TargetFloor = dbContext.WmsBaseWarehouse.Where(t => t.warehouseId == warehouseId).FirstOrDefault(); + if (TargetFloor != null) + { + //插入task表 + IWcsTaskApplication wcsTaskApplication=new WcsTaskApplication(scope.ServiceProvider); + Jc.SnowId.JcSnowId id = new Jc.SnowId.JcSnowId(1, 1); + var dic = StaticData.BaseDictionary.Where(t => t.dicKey == "TaskType" && t.ud1 == "I" && t.dicField == TargetFloor.warehouseInstockType).FirstOrDefault(); + + WcsTask newTask = new WcsTask() + { + objid = id.NextId(), + serialNo = Convert.ToInt32(serialno01Value), + equipmentNo = "F01", + taskType = Convert.ToInt32(dic.dicValue), + taskStatus = 0, + customerNo = RFID001Value.ToString(), + materialNo = material.materialCode, + materialId = material.materialId, + qty = Convert.ToInt32(material.bindAmount), + startPointId = F01, + startPointNo = "F01", + currPointId = F01, + currPointNo = "F01", + nextPointId = T01, + nextPointNo = "T01", + endPointId= warehouseId, + floorNo=1, + useFlag=1, + createBy= "一楼接驳位", + createTime =DateTime.Now, + remark="一楼创建入库任务" + }; + wcsTaskApplication.Add(newTask); + //下发去向 + this._plc.Write(this.wcsrun01.plcpointAddress, 1); + } + } + } + } } } - } } } @@ -166,14 +277,12 @@ namespace Khd.Core.Wcs.Wcs { LogManager.Error(ex); } - Thread.Sleep(2000); + Thread.Sleep(1000); } - - } /// - /// 启动一楼提升机线程 + /// 提升机线程 /// private void FirstFloorHoister() { @@ -181,12 +290,23 @@ namespace Khd.Core.Wcs.Wcs { try { - var serialno06Value = this._plc.Read(this.serialno06.plcpointAddress); //一楼提升机流水号 读 - var equipstate06Value = this._plc.Read(this.equipstate06.plcpointAddress); //一楼提升机状态 读 - var taskstate06Value = this._plc.Read(this.taskstate06.plcpointAddress); //一楼提升机任务状态 读 - var currentfloor06Value = this._plc.Read(this.currentfloor06.plcpointAddress); //一楼提升机当前楼层 写 - var targetfloor06Value = this._plc.Read(this.targetfloor06.plcpointAddress); //一楼提升机目的楼层 写 - var linesignal06Value = this._plc.Read(this.linesignal06.plcpointAddress); //一楼提升机到位信号 读 + var serialno06Value = this._plc.Read(this.serialno06.plcpointAddress); //提升机流水号 读 + var equipstate06Value = this._plc.Read(this.equipstate06.plcpointAddress); //提升机状态 读 + var taskstate06Value = this._plc.Read(this.taskstate06.plcpointAddress); //提升机任务状态 读 + var currentfloor06Value = this._plc.Read(this.currentfloor06.plcpointAddress); //提升机当前楼层 写 + var targetfloor06Value = this._plc.Read(this.targetfloor06.plcpointAddress); //提升机目的楼层 写 + var linesignal06Value = this._plc.Read(this.linesignal06.plcpointAddress); //提升机到位信号 读 + + var hoisterallowedtake01Value = this._plc.Read(this.hoisterallowedtake01.plcpointAddress); //一楼提升机前允许取 + var feedserialno01Value = this._plc.Read(this.feedserialno01.plcpointAddress); //一楼提升机前反馈流水号 + var hoisterallowedtake02Value = this._plc.Read(this.hoisterallowedtake02.plcpointAddress); //二楼提升机前允许取 + var feedserialno02Value = this._plc.Read(this.feedserialno02.plcpointAddress); //二楼提升机前反馈流水号 + var hoisterallowedtake03Value = this._plc.Read(this.hoisterallowedtake03.plcpointAddress); //三楼提升机前允许取 + var feedserialno03Value = this._plc.Read(this.feedserialno03.plcpointAddress); //三楼提升机前反馈流水号 + var hoisterallowedtake04Value = this._plc.Read(this.hoisterallowedtake04.plcpointAddress); //四楼提升机前允许取 + var feedserialno04Value = this._plc.Read(this.feedserialno04.plcpointAddress); //四楼提升机前反馈流水号 + var hoisterallowedtake05Value = this._plc.Read(this.hoisterallowedtake05.plcpointAddress); //五楼提升机前允许取 + var feedserialno05Value = this._plc.Read(this.feedserialno05.plcpointAddress); //五楼提升机前反馈流水号 using (var scope = _host.Services.CreateScope()) { using (var dbContext = scope.ServiceProvider.GetRequiredService()) @@ -194,10 +314,144 @@ namespace Khd.Core.Wcs.Wcs //正常读到plc值 if (serialno06Value != null && equipstate06Value != null || taskstate06Value != null || linesignal06Value != null) { - //正常托盘到位 - if (Convert.ToInt32(serialno06Value) != 0 && Convert.ToInt32(equipstate06Value) != 1 && Convert.ToInt32(linesignal06Value) == 1) + //提升机空闲 + if ( Convert.ToInt32(equipstate06Value) == 0) { - //根据流水号查询任务 分配去向 + //一楼到位 + if (Convert.ToInt32(hoisterallowedtake01Value) == 1 && Convert.ToInt32(feedserialno01Value) > 0) + { + var task = dbContext.WcsTask.Where(t => t.serialNo == Convert.ToInt32(feedserialno01Value)).FirstOrDefault(); + if (task != null) + { + if (task.nextPointId == T01) + { + //给提升机下发去向 + this._plc.Write(this.currentfloor06.plcpointAddress, 1); + this._plc.Write(this.targetfloor06.plcpointAddress,task.floorNo); + var nextPoint = dbContext.BaseEquip.Where(t => t.floorNo == task.floorNo).FirstOrDefault(); + //修改task状态 + task.currPointId = T01; + task.currPointNo = "T01"; + task.nextPointId = nextPoint.objid; + task.nextPointNo = nextPoint.equipNo; + task.taskStatus = 1; + task.updateBy = "提升机线程"; + task.updateTime = DateTime.Now; + task.remark = "一楼到位提升机线程"; + dbContext.WcsTask.Update(task); + dbContext.SaveChanges(); + } + } + continue; + } + //二楼到位 + if (Convert.ToInt32(hoisterallowedtake02Value) == 1 && Convert.ToInt32(feedserialno02Value) > 0) + { + var task = dbContext.WcsTask.Where(t => t.serialNo == Convert.ToInt32(feedserialno01Value)).FirstOrDefault(); + if (task != null) + { + if (task.nextPointId == T01) + { + //给提升机下发去向 + this._plc.Write(this.currentfloor06.plcpointAddress, 2); + this._plc.Write(this.targetfloor06.plcpointAddress, task.floorNo); + var nextPoint = dbContext.BaseEquip.Where(t => t.floorNo == task.floorNo).FirstOrDefault(); + //修改task状态 + task.currPointId = T01; + task.currPointNo = "T01"; + task.nextPointId = nextPoint.objid; + task.nextPointNo = nextPoint.equipNo; + task.taskStatus = 1; + task.updateBy = "提升机线程"; + task.updateTime = DateTime.Now; + task.remark = "二楼到位提升机线程"; + dbContext.WcsTask.Update(task); + dbContext.SaveChanges(); + } + } + continue; + } + //三楼到位 + if (Convert.ToInt32(hoisterallowedtake03Value) == 1 && Convert.ToInt32(feedserialno03Value) > 0) + { + var task = dbContext.WcsTask.Where(t => t.serialNo == Convert.ToInt32(feedserialno01Value)).FirstOrDefault(); + if (task != null) + { + if (task.nextPointId == T01) + { + //给提升机下发去向 + this._plc.Write(this.currentfloor06.plcpointAddress, 1); + this._plc.Write(this.targetfloor06.plcpointAddress, task.floorNo); + var nextPoint = dbContext.BaseEquip.Where(t => t.floorNo == task.floorNo).FirstOrDefault(); + //修改task状态 + task.currPointId = T01; + task.currPointNo = "T01"; + task.nextPointId = nextPoint.objid; + task.nextPointNo = nextPoint.equipNo; + task.taskStatus = 1; + task.updateBy = "提升机线程"; + task.updateTime = DateTime.Now; + task.remark = "三楼到位提升机线程"; + dbContext.WcsTask.Update(task); + dbContext.SaveChanges(); + } + } + continue; + } + //四楼到位 + if (Convert.ToInt32(hoisterallowedtake04Value) == 1 && Convert.ToInt32(feedserialno04Value) > 0) + { + var task = dbContext.WcsTask.Where(t => t.serialNo == Convert.ToInt32(feedserialno01Value)).FirstOrDefault(); + if (task != null) + { + if (task.nextPointId == T01) + { + //给提升机下发去向 + this._plc.Write(this.currentfloor06.plcpointAddress, 1); + this._plc.Write(this.targetfloor06.plcpointAddress, task.floorNo); + var nextPoint = dbContext.BaseEquip.Where(t => t.floorNo == task.floorNo).FirstOrDefault(); + //修改task状态 + task.currPointId = T01; + task.currPointNo = "T01"; + task.nextPointId = nextPoint.objid; + task.nextPointNo = nextPoint.equipNo; + task.taskStatus = 1; + task.updateBy = "提升机线程"; + task.updateTime = DateTime.Now; + task.remark = "四楼到位提升机线程"; + dbContext.WcsTask.Update(task); + dbContext.SaveChanges(); + } + } + continue; + } + //五楼到位 + if (Convert.ToInt32(hoisterallowedtake05Value) == 1 && Convert.ToInt32(feedserialno05Value) > 0) + { + var task = dbContext.WcsTask.Where(t => t.serialNo == Convert.ToInt32(feedserialno01Value)).FirstOrDefault(); + if (task != null) + { + if (task.nextPointId == T01) + { + //给提升机下发去向 + this._plc.Write(this.currentfloor06.plcpointAddress, 1); + this._plc.Write(this.targetfloor06.plcpointAddress, task.floorNo); + var nextPoint = dbContext.BaseEquip.Where(t => t.floorNo == task.floorNo).FirstOrDefault(); + //修改task状态 + task.currPointId = T01; + task.currPointNo = "T01"; + task.nextPointId = nextPoint.objid; + task.nextPointNo = nextPoint.equipNo; + task.taskStatus = 1; + task.updateBy = "提升机线程"; + task.updateTime = DateTime.Now; + task.remark = "五楼到位提升机线程"; + dbContext.WcsTask.Update(task); + dbContext.SaveChanges(); + } + } + continue; + } } } @@ -208,7 +462,7 @@ namespace Khd.Core.Wcs.Wcs { LogManager.Error(ex); } - Thread.Sleep(2000); + Thread.Sleep(1000); } diff --git a/src/Khd.Core.Wcs/Wcs/InWarePoint.cs b/src/Khd.Core.Wcs/Wcs/InWarePoint.cs deleted file mode 100644 index 94c94a8..0000000 --- a/src/Khd.Core.Wcs/Wcs/InWarePoint.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Khd.Core.Wcs.Wcs -{ - //入库点线程 - public class InWarePoint - { - } -} diff --git a/src/Khd.Core.Wcs/Wcs/OrderProcess.cs b/src/Khd.Core.Wcs/Wcs/OrderProcess.cs deleted file mode 100644 index f97d4ee..0000000 --- a/src/Khd.Core.Wcs/Wcs/OrderProcess.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Khd.Core.Wcs.Wcs -{ - /// - /// 处理订单 - /// - public class OrderProcess - { - } -} diff --git a/src/Khd.Core.Wcs/Wcs/OutWare.cs b/src/Khd.Core.Wcs/Wcs/OutWare.cs deleted file mode 100644 index 97866f2..0000000 --- a/src/Khd.Core.Wcs/Wcs/OutWare.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Khd.Core.Wcs.Wcs -{ - /// - /// 出库线程 - /// - public class OutWare - { - } -} diff --git a/src/Khd.Core.Wcs/Wcs/SecondFloor.cs b/src/Khd.Core.Wcs/Wcs/SecondFloor.cs index 2fb629e..b0987d1 100644 --- a/src/Khd.Core.Wcs/Wcs/SecondFloor.cs +++ b/src/Khd.Core.Wcs/Wcs/SecondFloor.cs @@ -113,11 +113,12 @@ namespace Khd.Core.Wcs.Wcs var equip = StaticData.BaseEquip.ToList(); var startEquip = equip.Where(t => t.equipNo == equipNo).FirstOrDefault(); //var currEquip= + Jc.SnowId.JcSnowId id = new Jc.SnowId.JcSnowId(1, 1); if (palletInfo != null) { WcsTask newTask = new() { - objid = Guid.NewGuid(), + objid = id.NextId(), taskType = Convert.ToInt32(dic.dicValue), customerNo = customerNo, taskStatus = 0, diff --git a/src/Khd.Core.Wcs/Wcs/WcsToWms.cs b/src/Khd.Core.Wcs/Wcs/WcsToWms.cs new file mode 100644 index 0000000..a76d7d7 --- /dev/null +++ b/src/Khd.Core.Wcs/Wcs/WcsToWms.cs @@ -0,0 +1,82 @@ +using Khd.Core.Domain.Dto.webapi; +using Masuit.Tools; +using Masuit.Tools.Logging; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Khd.Core.Wcs.Wcs +{ + public class WcsToWms + { + /// + /// 手工出库调用 + /// + /// + /// + public bool ManualOutWare(RequestManualOutWare requestManualOutWare) + { + //推送出库数据 + var url = "/api/Interface/ManualOutWare"; + var concontentType = "application/json"; + var result = HttpHelper.HttpPost(url, requestManualOutWare.ToJsonString(), concontentType, 60, null); + var model = (ReponseBase)JsonConvert.DeserializeObject(result.ToString(), typeof(ReponseBase)); + if (model.CODE =="S") + { + LogManager.Info("调用成功。"); + } + else + { + LogManager.Info("调用失败。"); + } + return true; + } + /// + /// 盘盈调用 + /// + /// + /// + public bool CheckProfit(RequestCheck requestCheck) + { + //推送出库数据 + var url = "/api/Interface/CheckProfit"; + var concontentType = "application/json"; + var result = HttpHelper.HttpPost(url, requestCheck.ToJsonString(), concontentType, 60, null); + var model = (ReponseBase)JsonConvert.DeserializeObject(result.ToString(), typeof(ReponseBase)); + if (model.CODE == "S") + { + LogManager.Info("调用成功。"); + } + else + { + LogManager.Info("调用失败。"); + } + return true; + } + /// + /// 盘亏调用 + /// + /// + /// + public bool CheckLoss(RequestCheck requestCheck) + { + //推送出库数据 + var url = "/api/Interface/CheckLoss"; + var concontentType = "application/json"; + var result = HttpHelper.HttpPost(url, requestCheck.ToJsonString(), concontentType, 60, null); + var model = (ReponseBase)JsonConvert.DeserializeObject(result.ToString(), typeof(ReponseBase)); + if (model.CODE == "S") + { + LogManager.Info("调用成功。"); + } + else + { + LogManager.Info("调用失败。"); + } + return true; + } + } +} diff --git a/src/Khd.Core.Wpf/Form/CheShenChangDuGuanLi.xaml b/src/Khd.Core.Wpf/Form/CheShenChangDuGuanLi.xaml index 0364763..10e1a46 100644 --- a/src/Khd.Core.Wpf/Form/CheShenChangDuGuanLi.xaml +++ b/src/Khd.Core.Wpf/Form/CheShenChangDuGuanLi.xaml @@ -7,7 +7,7 @@ xmlns:local="clr-namespace:Khd.Core.Wpf.Form" mc:Ignorable="d" d:DesignHeight="600" d:DesignWidth="950" - Title="车身长度管理页面" Height="600" Width="950" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" Loaded="Window_Loaded"> + Title="物料管理" Height="600" Width="950" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" Loaded="Window_Loaded"> @@ -276,148 +276,62 @@ - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + diff --git a/src/Khd.Core.Wpf/Form/CheShenChangDuGuanLi.xaml.cs b/src/Khd.Core.Wpf/Form/CheShenChangDuGuanLi.xaml.cs index eb56d52..1037d9c 100644 --- a/src/Khd.Core.Wpf/Form/CheShenChangDuGuanLi.xaml.cs +++ b/src/Khd.Core.Wpf/Form/CheShenChangDuGuanLi.xaml.cs @@ -1,4 +1,5 @@ -using Khd.Core.Domain.Models; +using HandyControl.Tools.Extension; +using Khd.Core.Domain.Models; using Khd.Core.EntityFramework; using Masuit.Tools.Logging; using Microsoft.EntityFrameworkCore; @@ -45,49 +46,13 @@ namespace Khd.Core.Wpf.Form { try { - GetCarMessage(""); + } catch (Exception ex) { LogManager.Info($"窗体加载事件报错 >>> {ex.Message}"); } } - private void GetCarMessage(string sql) - { - try - { - string wheresql = string.IsNullOrEmpty(sql) ? "" : $"and material_no like '%{sql}'"; - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - var data = dbContext.ExecuteSqlQuery - ($@"SELECT id, - material_no as materialNo, - k46up_length as k46upLength, - k48up_length as k48upLength, - down_length as downLength - FROM `base_materialinfo` - where is_delete = 0 {wheresql} order by material_no;"); - if (data?.Count > 0) - { - List materialinfo_list = new(); - foreach (var item in data) - { - BaseMaterialinfo materialinfo_model = new(); - materialinfo_model.materialNo = item.materialNo; - materialinfo_model.k46upLength = item.k46upLength; - materialinfo_model.k48upLength = item.k48upLength; - materialinfo_model.downLength = item.downLength; - materialinfo_list.Add(materialinfo_model); - } - this.dtg_LoadCarMessage.ItemsSource = materialinfo_list; - this.dtg_LoadCarMessage.Items.Refresh(); - } - } - catch (Exception ex) - { - LogManager.Info($"获取辆号信息加载到datagrid方法报错 >>> {ex.Message}"); - } - } /// /// 显示序号事件 /// @@ -95,62 +60,7 @@ namespace Khd.Core.Wpf.Form /// private void dgData_LoadingRow(object sender, DataGridRowEventArgs e) { e.Row.Header = e.Row.GetIndex() + 1; } - /// - /// datagrid编辑文本框触发事件 - /// - /// - /// - private void dtg_LoadCarMessage_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) - { - try - { - if (e != null) - { - if (e.EditAction == DataGridEditAction.Commit) - { - // 获取鼠标点击的单元格 - DataGridCellInfo cellInfo = dtg_LoadCarMessage.CurrentCell; - int columnIndex = cellInfo.Column.DisplayIndex; - BaseMaterialinfo data = this.dtg_LoadCarMessage.SelectedItem as BaseMaterialinfo; - var editedTextbox = e.EditingElement as System.Windows.Controls.TextBox; // 假设编辑的是文本框 - var newValue = editedTextbox.Text; // 获取编辑后的值 - string zfc; - switch (columnIndex) - { - case 1: - zfc = "material_no"; - break; - case 2: - zfc = "k46up_length"; - break; - case 3: - zfc = "k48up_length"; - break; - case 4: - zfc = "down_length"; - break; - default: - zfc = ""; - break; - } - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - if (!string.IsNullOrWhiteSpace(data.materialNo)) - { - string setsql = zfc == "material_no" ? $",material_name ='{newValue}'" : ""; - dbContext.ExecuteSqlQuery($@" UPDATE base_materialinfo set {zfc} = '{newValue}'{setsql} where material_no = '{data.materialNo}';"); - this.dtg_LoadCarMessage.ItemsSource = null; - GetCarMessage(""); - LogManager.Info($"当前事件 :{DateTime.Now},修改字段{zfc}为{newValue} >>> 日志记录!"); - } - } - } - } - catch (Exception ex) - { - LogManager.Info("datagrid编辑文本框触发事件报错 >>> " + ex.Message.ToString()); - } - } + private void DataGrid_KeyDown(object sender, KeyEventArgs e) { try @@ -182,36 +92,13 @@ namespace Khd.Core.Wpf.Form { try { - - var datagridMessage = dtg_LoadCarMessage.ItemsSource as List; - if (datagridMessage != null) + if (!marterCode.Text.IsNullOrEmpty()&&!marterName.Text.IsNullOrEmpty()&&marterType.SelectedIndex!=-1) { - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - var material_model = dbContext.BaseMaterialinfo.Where(t => t.isDelete == 0).ToList(); - foreach (var item in datagridMessage) - { - var number = material_model.Find(C => C.materialNo == item.materialNo); - if (number == null && !string.IsNullOrWhiteSpace(item.materialNo)) - { - BaseMaterialinfo model = new BaseMaterialinfo(); - model.id = Guid.NewGuid(); - model.materialNo = item.materialNo; - model.k46upLength = string.IsNullOrWhiteSpace(item.k46upLength) ? "" : item.k46upLength; - model.k48upLength = string.IsNullOrWhiteSpace(item.k48upLength) ? "" : item.k48upLength; - model.downLength = string.IsNullOrWhiteSpace(item.downLength) ? "" : item.downLength; - model.isDelete = 0; - model.materialName = item.materialNo; - model.createTime = DateTime.Now; - model.createBy = "AdmianInsert"; - dbContext.Add(model); - var insertresult = dbContext.SaveChanges(); - string showResult = insertresult == 1 ? "成功" : "失败"; - MessageBox.Show($"物料{item.materialNo}添加操作{showResult}!", "操作成功提示!"); - this.dtg_LoadCarMessage.ItemsSource = null; - GetCarMessage(""); - } - } + + } + else + { + MessageBox.Show("请输入完整数据!!!"); } } catch (Exception ex) @@ -219,44 +106,5 @@ namespace Khd.Core.Wpf.Form MessageBox.Show($"数据添加报错 >>> {ex.Message}","操作失败提示!"); } } - /// - /// 添加按钮点击事件 - /// - /// - /// - private void jia_Click(object sender, RoutedEventArgs e) - { - try - { - var listinfo = this.dtg_LoadCarMessage.ItemsSource as List; - BaseMaterialinfo model = new BaseMaterialinfo(); - listinfo.Add(model); - dtg_LoadCarMessage.ItemsSource = listinfo; - dtg_LoadCarMessage.Items.Refresh(); - var lastItem = listinfo[listinfo.Count - 1]; - // 将数据源的最后一个元素滚动到可视区域 - this.dtg_LoadCarMessage.ScrollIntoView(lastItem); - } - catch (Exception ex) - { - MessageBox.Show($"数据添加报错 >>> {ex.Message}"); - } - } - /// - /// 查询按钮 - /// - /// - /// - private void ChaXunButton_Click(object sender, RoutedEventArgs e) - { - try - { - var liangxing = this.tbx_wuliaoname.Text.Trim().ToUpper().ToString(); - GetCarMessage(liangxing); - } - catch (Exception) - { - } - } } } diff --git a/src/Khd.Core.Wpf/Form/FormBoard.xaml b/src/Khd.Core.Wpf/Form/FormBoard.xaml index 0bf6082..15577cf 100644 --- a/src/Khd.Core.Wpf/Form/FormBoard.xaml +++ b/src/Khd.Core.Wpf/Form/FormBoard.xaml @@ -1,10 +1,10 @@  - - + + @@ -291,13 +275,20 @@ Width="1920" Height="1080" Background="#172557"> + + @@ -485,7 +476,20 @@ VerticalAlignment="Center" Foreground="White" FontSize="25" - Margin="360,0,0,0" + Margin="150,0,0,0" + Visibility="Visible" + Style="{StaticResource ClearOrderButton}" + Click="btn_ClearOrder_Click"> + + + + + + + + + + + + + + + diff --git a/src/Khd.Core.Wpf/Form/FormBoard.xaml.cs b/src/Khd.Core.Wpf/Form/FormBoard.xaml.cs index 873c7ad..fd14539 100644 --- a/src/Khd.Core.Wpf/Form/FormBoard.xaml.cs +++ b/src/Khd.Core.Wpf/Form/FormBoard.xaml.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Data; using System.Linq; -using System.Threading; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; @@ -13,22 +12,22 @@ using Masuit.Tools.Logging; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.DependencyInjection; using Khd.Core.EntityFramework; -using Khd.Core.Plc.S7; -using Khd.Core.Wpf; using Thrift.Server; using Thrift.Transport; using ThriftService; using Thrift.Protocol; using Khd.Core.Domain.Models; using Z.EntityFramework.Plus; -using Khd.Core.Wpf.Form; using OfficeOpenXml; using Microsoft.Win32; using System.IO; -using AngleSharp.Dom; using System.Windows; +using Masuit.Tools; +using Microsoft.EntityFrameworkCore; +using System.Text.RegularExpressions; +using Khd.Core.Plc.S7; -namespace XGL.FormItem +namespace Khd.Core.Wpf.Form { /// /// FormBoard.xaml 的交互逻辑 @@ -36,14 +35,10 @@ namespace XGL.FormItem public partial class FormBoard : Window { private readonly IHost _host; - private Plc _plc; - /// - /// 时间刷新计时器 - /// - + private Khd.Core.Plc.S7.Plc _plc; private DispatcherTimer ShowTimer;//刷新时间 - private DispatcherTimer PLCMessage;//呈现PLC机柜信息 + private DispatcherTimer ShowOrderMessage;//呈现PLC机柜信息 private object order_code; private int UpState;//对应上件站点的状态,0为良好 1为损坏 //FormShowSelect formSelect; @@ -66,21 +61,19 @@ namespace XGL.FormItem { try { + LogManager.Info($"--------------------------当前时间 :{DateTime.Now} >>> 客户端启动;"); //设置显示任务栏 if (WindowState == WindowState.Normal) { MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight; WindowState = WindowState.Maximized; } - - + //加载dategrid信息 LoadMaterial_GetMessage(""); - - //连接PLC判断 var plc = new Khd.Core.Plc.S7.Plc((CpuType)PlcConfig.CpuType, PlcConfig.IP, PlcConfig.Port, PlcConfig.Rack, PlcConfig.Slot); - plc.Open(); + // plc.Open(); if (!plc.IsConnected) { MessageBox.Show("PLC连接失败,重新连接"); @@ -90,68 +83,68 @@ namespace XGL.FormItem this._plc = plc; } - ShowTimer = new System.Windows.Threading.DispatcherTimer(); - ShowTimer.Tick += new EventHandler(ShowCurTimer);//起个Timer一直获取当前时间 - ShowTimer.Interval = new TimeSpan(0, 0, 0, 1, 0); - ShowTimer.Start(); + //ShowTimer = new System.Windows.Threading.DispatcherTimer(); + //ShowTimer.Tick += new EventHandler(ShowCurTimer);//起个Timer一直获取当前时间 + //ShowTimer.Interval = new TimeSpan(0, 0, 0, 1, 0); + //ShowTimer.Start(); - #region 测试client,调用wcs服务端 + //#region 测试client,调用wcs服务端 - //TTransport transport = new TSocket("localhost", 9091); - //transport.Open(); - //TProtocol protocol = new TBinaryProtocol(transport); - //WcsThrift.Client client = new WcsThrift.Client(protocol); - //client.hello("Sunzy"); + ////TTransport transport = new TSocket("localhost", 9091); + ////transport.Open(); + ////TProtocol protocol = new TBinaryProtocol(transport); + ////WcsThrift.Client client = new WcsThrift.Client(protocol); + ////client.hello("Sunzy"); - #endregion + //#endregion - //启动Thriftserver - Thread ThriftThread = new Thread(StartThriftServer);//接收服务端的推送信息 - ThriftThread.IsBackground = true; - ThriftThread.Start(); + ////启动Thriftserver + //Thread ThriftThread = new Thread(StartThriftServer);//接收服务端的推送信息 + //ThriftThread.IsBackground = true; + //ThriftThread.Start(); - PLCMessage = new DispatcherTimer(); - PLCMessage.Tick += new EventHandler(PLCmessage); //委托获取点位方法 - PLCMessage.Interval = new TimeSpan(0, 0, 0, 0, 300); - PLCMessage.Start(); + //PLCMessage = new DispatcherTimer(); + //PLCMessage.Tick += new EventHandler(PLCmessage); //委托获取点位方法 + //PLCMessage.Interval = new TimeSpan(0, 0, 0, 0, 300); + //PLCMessage.Start(); - //string result = ThriftConfig.UpSite == "k46" ? " K46" : " K48"; - //this.lab_Title.Content = (string)this.lab_Title.Content + result; + ////string result = ThriftConfig.UpSite == "k46" ? " K46" : " K48"; + ////this.lab_Title.Content = (string)this.lab_Title.Content + result; - //载具到位状态 - this.labzjydw.Visibility = System.Windows.Visibility.Hidden; - this.imgzjydw.Visibility = System.Windows.Visibility.Hidden; - this.labzjwdw.Visibility = System.Windows.Visibility.Visible; - this.imgzjwdw.Visibility = System.Windows.Visibility.Visible; + ////载具到位状态 + //this.labzjydw.Visibility = System.Windows.Visibility.Hidden; + //this.imgzjydw.Visibility = System.Windows.Visibility.Hidden; + //this.labzjwdw.Visibility = System.Windows.Visibility.Visible; + //this.imgzjwdw.Visibility = System.Windows.Visibility.Visible; - if (ThriftConfig.UpSite == "k48") - { - this.spl_sunhuaizhakoumianban.Visibility = System.Windows.Visibility.Visible; - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - var getFlagState = dbContext.BaseAmima.Where(t => t.name == "UpState").FirstOrDefault(); - if (getFlagState != null) - { - int zhuangtai = getFlagState.password == "2" ? 2 : 1; - string quxiang = getFlagState.direction == 1 ? "直通" : "弯通"; - if (zhuangtai == 2) - { - this.lab_shangjiandianzhuangtai.Content = "上件点正常!K22按照任务线别方向流转."; - this.lab_shangjiandianzhuangtai.Foreground = new SolidColorBrush(Colors.Green); - this.spl_sunhuaizhakouquxiang.Visibility = System.Windows.Visibility.Hidden; - } - else - { - this.lab_shangjiandianzhuangtai.Content = $"上件点损坏!人工维护去向:{quxiang}"; - this.lab_shangjiandianzhuangtai.Foreground = new SolidColorBrush(Colors.Red); - this.spl_sunhuaizhakouquxiang.Visibility = System.Windows.Visibility.Visible; - } - } - } - else - { - this.spl_sunhuaizhakoumianban.Visibility = System.Windows.Visibility.Hidden; - } + //if (ThriftConfig.UpSite == "k48") + //{ + // this.spl_sunhuaizhakoumianban.Visibility = System.Windows.Visibility.Visible; + // using var scope = _host.Services.CreateScope(); + // using var dbContext = scope.ServiceProvider.GetRequiredService(); + // var getFlagState = dbContext.BaseAmima.Where(t => t.name == "UpState").FirstOrDefault(); + // if (getFlagState != null) + // { + // int zhuangtai = getFlagState.password == "2" ? 2 : 1; + // string quxiang = getFlagState.direction == 1 ? "直通" : "弯通"; + // if (zhuangtai == 2) + // { + // this.lab_shangjiandianzhuangtai.Content = "上件点正常!K22按照任务线别方向流转."; + // this.lab_shangjiandianzhuangtai.Foreground = new SolidColorBrush(Colors.Green); + // this.spl_sunhuaizhakouquxiang.Visibility = System.Windows.Visibility.Hidden; + // } + // else + // { + // this.lab_shangjiandianzhuangtai.Content = $"上件点损坏!人工维护去向:{quxiang}"; + // this.lab_shangjiandianzhuangtai.Foreground = new SolidColorBrush(Colors.Red); + // this.spl_sunhuaizhakouquxiang.Visibility = System.Windows.Visibility.Visible; + // } + // } + //} + //else + //{ + // this.spl_sunhuaizhakoumianban.Visibility = System.Windows.Visibility.Hidden; + //} } catch (Exception ex) @@ -164,14 +157,14 @@ namespace XGL.FormItem { try { - int point = Convert.ToInt32(ThriftConfig.JiesShouDuanKou); - WcsServer wcsServer = new WcsServer(); - //wcsServer.SendCarEvent += SendCar; - wcsServer.helloEvent += hello; - WcsThrift.Processor processor = new WcsThrift.Processor(wcsServer); - TServerTransport serverTransport = new TServerSocket(point); - TServer server = new TSimpleServer(processor, serverTransport); - server.Serve(); + //int point = Convert.ToInt32(ThriftConfig.JiesShouDuanKou); + //WcsServer wcsServer = new WcsServer(); + ////wcsServer.SendCarEvent += SendCar; + //wcsServer.helloEvent += hello; + //WcsThrift.Processor processor = new WcsThrift.Processor(wcsServer); + //TServerTransport serverTransport = new TServerSocket(point); + //TServer server = new TSimpleServer(processor, serverTransport); + //server.Serve(); } catch (Exception ex) { @@ -179,7 +172,7 @@ namespace XGL.FormItem delegate { //设置图片为未到位 - this.CarNo.Clear(); + this.CarNo.Text = "Null"; this.labzjydw.Visibility = System.Windows.Visibility.Hidden; this.imgzjydw.Visibility = System.Windows.Visibility.Hidden; this.labzjwdw.Visibility = System.Windows.Visibility.Visible; @@ -214,6 +207,7 @@ namespace XGL.FormItem delegate { //设置图片为未到位 + //this.CarNo.Clear(); this.labzjydw.Visibility = System.Windows.Visibility.Hidden; this.imgzjydw.Visibility = System.Windows.Visibility.Hidden; this.labzjwdw.Visibility = System.Windows.Visibility.Visible; @@ -233,8 +227,7 @@ namespace XGL.FormItem /// /// /// Vin条码号 - /// 三轮车辆长度 - public void SendCar(List carlist, string order_code, string amount) + public void SendCar(List carlist, string order_code) { TTransport transport = new TSocket(ThriftConfig.ThriftIpAddress, ThriftConfig.TuiSongDuankou); try @@ -244,37 +237,37 @@ namespace XGL.FormItem transport.Open(); TProtocol protocol = new TBinaryProtocol(transport); WcsThrift.Client client = new WcsThrift.Client(protocol); - var ret = client.SendCar(carlist, order_code, amount); - if (ret == "1")//与服务端交互成功发车时 - { - Application.Current.Dispatcher.Invoke(new Action( - delegate - { - //发车成功提示反馈 - this.lba_ThrifTtitle.Foreground = new SolidColorBrush(Colors.Green); - this.lba_ThrifTtitle.Content = "发车成功!"; - //设置为未到位 - this.labzjwdw.Visibility = System.Windows.Visibility.Visible; - this.imgzjwdw.Visibility = System.Windows.Visibility.Visible; - this.labzjydw.Visibility = System.Windows.Visibility.Hidden; - this.imgzjydw.Visibility = System.Windows.Visibility.Hidden; - })); - } - else//与服务端交互失败时 - { + //var ret = client.SendCar(carlist, order_code, order_code); + //if (ret == "1")//与服务端交互成功发车时 + //{ + // Application.Current.Dispatcher.Invoke(new Action( + // delegate + // { + // //发车成功提示反馈 + // this.lba_ThrifTtitle.Foreground = new SolidColorBrush(Colors.Green); + // this.lba_ThrifTtitle.Content = "发车成功!"; + // //设置为未到位 + // this.labzjwdw.Visibility = System.Windows.Visibility.Visible; + // this.imgzjwdw.Visibility = System.Windows.Visibility.Visible; + // this.labzjydw.Visibility = System.Windows.Visibility.Hidden; + // this.imgzjydw.Visibility = System.Windows.Visibility.Hidden; + // })); + //} + //else//与服务端交互失败时 + //{ - Application.Current.Dispatcher.Invoke(new Action( - delegate - { - this.lba_ThrifTtitle.Foreground = new SolidColorBrush(Colors.Red); - this.lba_ThrifTtitle.Content = $"Thrift交互失败!"; - //发车失败依然显示到位 - this.labzjwdw.Visibility = System.Windows.Visibility.Hidden; - this.imgzjwdw.Visibility = System.Windows.Visibility.Hidden; - this.labzjydw.Visibility = System.Windows.Visibility.Visible; - this.imgzjydw.Visibility = System.Windows.Visibility.Visible; - })); - } + // Application.Current.Dispatcher.Invoke(new Action( + // delegate + // { + // this.lba_ThrifTtitle.Foreground = new SolidColorBrush(Colors.Red); + // this.lba_ThrifTtitle.Content = $"Thrift交互失败!"; + // //发车失败依然显示到位 + // this.labzjwdw.Visibility = System.Windows.Visibility.Hidden; + // this.imgzjwdw.Visibility = System.Windows.Visibility.Hidden; + // this.labzjydw.Visibility = System.Windows.Visibility.Visible; + // this.imgzjydw.Visibility = System.Windows.Visibility.Visible; + // })); + //} } catch (Exception ex) { @@ -316,11 +309,15 @@ namespace XGL.FormItem /// private void btnExit_Click(object sender, RoutedEventArgs e) { - if (MessageBox.Show("是否确认关闭程序", "提示信息", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.No) - { + //if (MessageBox.Show("是否确认关闭程序", "提示信息", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.No) + //{ - } - else + //} + //else + //{ + // System.Environment.Exit(System.Environment.ExitCode); + //} + if (MessageBox.Show("是否确认关闭程序", "提示信息", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { System.Environment.Exit(System.Environment.ExitCode); } @@ -830,8 +827,6 @@ namespace XGL.FormItem { } } - - /// /// 使用DataTable当做数据传递中介向DataGrid中传输数据源 /// @@ -850,10 +845,10 @@ namespace XGL.FormItem IsOver AS isover FROM base_production_order_split {pjsql} - ORDER BY est ,IsOver"; + ORDER BY IsOver , est ;"; var QueryOrder = dbContext.ExecuteSqlQuery(sql); #region 注释代码折叠 - //($@"SELECT + //string sql = ($@"SELECT // a.line_code AS lineCode, @@ -871,7 +866,7 @@ namespace XGL.FormItem // LEFT JOIN base_waitdownline b - // ON a.order_code = b.materiel_no {sql} ORDER BY est ,IsOver "); + // ON a.order_code = b.materiel_no {pjsql} ORDER BY est ,IsOver "); //var QueryOrder = dbContext.BaseProductionOrderSplit.OrderBy(t => t.est).OrderBy(t => t.isover).ToList(); #endregion if (QueryOrder?.Count > 0) @@ -892,11 +887,14 @@ namespace XGL.FormItem dr["isover"] = i.isover.ToString(); switch (i.isover) { - case 1: - dr["isover"] = "已完成"; - break; case 0: - dr["isover"] = "未完成"; + dr["isover"] = "未上线"; + break; + case 1: + dr["isover"] = "已上线"; + break; + case 2: + dr["isover"] = "已完成"; break; default: dr["isover"] = "状态错误!"; @@ -904,7 +902,7 @@ namespace XGL.FormItem } dt.Rows.Add(dr); } - this.LoadMaterial.ItemsSource = dt.DefaultView; + this.LoadMaterial.ItemsSource = dt.DefaultView; this.LoadMaterial.Items.Refresh(); } } @@ -944,14 +942,14 @@ namespace XGL.FormItem /// private void Btn_shangjiansunhuai_Click(object sender, RoutedEventArgs e) { - this.spl_sunhuaizhakouquxiang.Visibility = System.Windows.Visibility.Visible; - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - dbContext.BaseAmima.Where(t => t.name == "UpState").Update(a => new BaseAmima() { password = "1" }); - var data = dbContext.BaseAmima.Where(t => t.name == "UpState").FirstOrDefault(); - string quxiang = data.direction == 1 ? "直通" : "弯通"; - this.lab_shangjiandianzhuangtai.Content = $"上件点状态:损坏!K22固定去向:" + quxiang; - this.lab_shangjiandianzhuangtai.Foreground = new SolidColorBrush(Colors.Red); + //this.spl_sunhuaizhakouquxiang.Visibility = System.Windows.Visibility.Visible; + //using var scope = _host.Services.CreateScope(); + //using var dbContext = scope.ServiceProvider.GetRequiredService(); + //dbContext.BaseAmima.Where(t => t.name == "UpState").Update(a => new BaseAmima() { password = "1" }); + //var data = dbContext.BaseAmima.Where(t => t.name == "UpState").FirstOrDefault(); + //string quxiang = data.direction == 1 ? "直通" : "弯通"; + //this.lab_shangjiandianzhuangtai.Content = $"上件点状态:损坏!K22固定去向:" + quxiang; + //this.lab_shangjiandianzhuangtai.Foreground = new SolidColorBrush(Colors.Red); } /// /// 上件点状态良好确认按钮点击事件 @@ -965,7 +963,7 @@ namespace XGL.FormItem this.lab_shangjiandianzhuangtai.Content = $"上件点状态:正常!K22走任务线别去向!"; this.lab_shangjiandianzhuangtai.Foreground = new SolidColorBrush(Colors.Green); this.spl_sunhuaizhakouquxiang.Visibility = System.Windows.Visibility.Hidden; - dbContext.BaseAmima.Where(t => t.name == "UpState").Update(a => new BaseAmima() { password = "2" }); + // dbContext.BaseAmima.Where(t => t.name == "UpState").Update(a => new BaseAmima() { password = "2" }); } /// /// 上件点状态维护损坏后固定K22去向1 @@ -974,11 +972,11 @@ namespace XGL.FormItem /// private void Btn_K22QuXiang1_Click(object sender, RoutedEventArgs e) { - this.spl_sunhuaizhakouquxiang.Visibility = System.Windows.Visibility.Visible; - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - dbContext.BaseAmima.Where(t => t.name == "UpState").Update(a => new BaseAmima() { direction = 1 }); - Btn_shangjiansunhuai_Click(null, null); + //this.spl_sunhuaizhakouquxiang.Visibility = System.Windows.Visibility.Visible; + //using var scope = _host.Services.CreateScope(); + //using var dbContext = scope.ServiceProvider.GetRequiredService(); + //dbContext.BaseAmima.Where(t => t.name == "UpState").Update(a => new BaseAmima() { direction = 1 }); + //Btn_shangjiansunhuai_Click(null, null); } /// @@ -991,7 +989,7 @@ namespace XGL.FormItem this.spl_sunhuaizhakouquxiang.Visibility = System.Windows.Visibility.Visible; using var scope = _host.Services.CreateScope(); using var dbContext = scope.ServiceProvider.GetRequiredService(); - dbContext.BaseAmima.Where(t => t.name == "UpState").Update(a => new BaseAmima() { direction = 2 }); + //dbContext.BaseAmima.Where(t => t.name == "UpState").Update(a => new BaseAmima() { direction = 2 }); Btn_shangjiansunhuai_Click(null, null); } /// @@ -1019,27 +1017,26 @@ namespace XGL.FormItem using var scope = _host.Services.CreateScope(); using var dbContext = scope.ServiceProvider.GetRequiredService(); string VinResult = this.tBoxMessage.Text.Trim().ToUpper().ToString(); - if (string.IsNullOrWhiteSpace(VinResult)) - { - return; - } - var orderModel = dbContext.BaseProductionOrderSplit.Where(t => t.orderCode == VinResult).FirstOrDefault(); - if (orderModel == null) - { - return; - } - var waitdownlineModel = dbContext.BaseWaitdownline.Where(t => t.definefield1 == orderModel.lineCode).ToList(); - int FlagNum = waitdownlineModel.Count(); - if (FlagNum >= FlagConfig.UpFlagNum) - { - //如果上件数量大于等于设置的闸口数量时 - SolidColorBrush myBrush = new SolidColorBrush(); - myBrush.Color = System.Windows.Media.Color.FromRgb(255, 130, 0); // 设置RGB值为(255, 0, 0)(红色) - this.lba_ThrifTtitle.Foreground = myBrush; - this.lba_ThrifTtitle.Content = $"上线数量:{FlagNum}>=缓存数量:{FlagConfig.UpFlagNum},限制发车!"; - LogManager.Info($"当前时间:{DateTime.Now},物料:{orderModel.orderCode},线别:{orderModel.lineCode},数量:{FlagNum} >= 缓存数量:{FlagConfig.UpFlagNum},限制发车操作!"); - return; - } + //var orderModel = dbContext.BaseProductionOrderSplit.Where(t => t.orderCode == VinResult).FirstOrDefault(); + //if (orderModel == null) + //{ + // MessageBox.Show($"该VIN条码:{VinResult}未搜索到对应订单!"); + // return; + //} + //if (orderModel.isover != 0) + //{ + // if (orderModel.isover == 1) MessageBox.Show($"该Vin条码:{VinResult}对应订单已上线!", "发车错误提示!"); + // if (orderModel.isover == 2) MessageBox.Show($"该Vin条码:{VinResult}对应订单已下线完成!", "发车错误提示!"); + // return; + //} + // var waitdownlineModel = dbContext.BaseWaitdownline.Where(t => t.definefield1 == orderModel.lineCode).ToList(); + //int FlagNum = waitdownlineModel.Count(); + //if (FlagNum >= FlagConfig.UpFlagNum) + //{ + // MessageBox.Show($"已上线数量:{FlagNum}>=缓存闸口设置数量:{FlagConfig.UpFlagNum},限制发车操作!", "发车错误提示!"); + // LogManager.Info($"当前时间:{DateTime.Now},物料:{orderModel.orderCode},线别:{orderModel.lineCode},数量:{FlagNum} >= 缓存数量:{FlagConfig.UpFlagNum},限制发车操作!"); + // return; + //} string sqlQuery = @$" SELECT b1.material_no AS materialNo, @@ -1070,26 +1067,37 @@ namespace XGL.FormItem #endregion if (QueryOrder?.Count == 0) { - MessageBox.Show($"Vin:{VinResult}不存在对应车型长度", "发车操作提示!"); + MessageBox.Show($"未查找到Vin:{VinResult}对应车型", "发车错误提示!"); return; } string changduText = ThriftConfig.UpSite == "k46" ? QueryOrder[0].k46upLength : QueryOrder[0].k48upLength; - changduText = changduText == "" ? "Null" : changduText; - string zhandianText = ThriftConfig.UpSite == "k46" ? "K46" : "K48"; - this.tbx_CheLiangChangDu.Text = changduText; - string CarLengthResult = this.tbx_CheLiangChangDu.Text.Trim().ToString(); - if (!string.IsNullOrWhiteSpace(CarLengthResult) && !string.IsNullOrWhiteSpace(VinResult)) + if (string.IsNullOrWhiteSpace(changduText)) { - List carList = new List - { - $"上件站点 >>> {zhandianText}" - }; - SendCar(carList, VinResult, CarLengthResult); - LogManager.Info($"当前时间;{DateTime.Now},发车方法调用记录 >>> 上件站点:{carList[0]} , Vin条码号:{VinResult},车身长度:{CarLengthResult}"); - carList.Clear(); - this.LoadMaterial.ItemsSource = null; - LoadMaterial_GetMessage(""); + MessageBox.Show($"未查找到Vin:{VinResult}对应车型长度", "发车错误提示!"); + return; } + string carId = this.CarNo.Text; + if (string.IsNullOrWhiteSpace(carId)) + { + MessageBox.Show($"挂具号为空!", "发车错误提示!"); + return; + } + string zhandianText = ThriftConfig.UpSite == "k46" ? "K46" : "K48"; + List carList = new() + { + $"上件站点 >>> {zhandianText}" + }; + SendCar(carList, VinResult); + LogManager.Info($"当前时间;{DateTime.Now},发车方法调用记录 >>> 挂具ID:{carId},上件站点:{carList[0]} , Vin条码号:{VinResult},车身长度:{changduText}"); + carList.Clear(); + //this.LoadMaterial.Items.Refresh(); + this.LoadMaterial.ItemsSource = null; + LoadMaterial_GetMessage(""); + } + else if (this.tBoxMessage.Text.Trim().Length < 17 && e.Key == Key.Enter) + { + MessageBox.Show($"输入Vin条码:{this.tBoxMessage.Text.Trim()}长度有误!"); + return; } } catch (Exception ex) @@ -1107,107 +1115,111 @@ namespace XGL.FormItem try { Application.Current.Dispatcher.Invoke(new Action( - delegate - { - // 设置 EPPlus 许可上下文 - ExcelPackage.LicenseContext = LicenseContext.NonCommercial; - OpenFileDialog openFileDialog = new OpenFileDialog(); - openFileDialog.Filter = "Excel Files|*.xls;*.xlsx"; - if (openFileDialog.ShowDialog() == true) - { - FileInfo fileInfo = new FileInfo(openFileDialog.FileName); + delegate + { + // 设置 EPPlus 许可上下文 + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + OpenFileDialog openFileDialog = new OpenFileDialog(); + openFileDialog.Filter = "Excel Files|*.xls;*.xlsx"; + if (openFileDialog.ShowDialog() == true) + { + FileInfo fileInfo = new FileInfo(openFileDialog.FileName); - using (ExcelPackage package = new ExcelPackage(fileInfo)) - { - ExcelWorksheet worksheet = package.Workbook.Worksheets.FirstOrDefault(); + using (ExcelPackage package = new ExcelPackage(fileInfo)) + { + ExcelWorksheet worksheet = package.Workbook.Worksheets.FirstOrDefault(); - if (worksheet != null) - { - // 获取 Excel 表头 - var columnHeaders = worksheet.Cells[1, 1, 1, worksheet.Dimension.End.Column] - .Select(cell => cell.Text) - .ToList(); - BaseProductionOrderSplit orderMoedel = new(); - // 映射数据库字段,这里需要根据你的实际需求进行调整 - var columnMappings = new Dictionary - { - // 添加映射 - {columnHeaders[0],"production_sequence"}, - {columnHeaders[1],"line_code"}, - {columnHeaders[3],"prod_code"}, - {columnHeaders[4],"Quantity"}, - {columnHeaders[5],"order_code"} - }; - int ordernum = 0; - // 遍历 Excel 数据行 - for (int row = 2; row <= worksheet.Dimension.End.Row; row++) - { - // 创建 SQL 插入语句 - //string insertCommand = $"INSERT INTO YourTableName ({string.Join(", ", columnMappings.Values)}) VALUES ("; - List values = new(); + if (worksheet != null) + { + // 获取 Excel 表头 + var columnHeaders = worksheet.Cells[1, 1, 1, worksheet.Dimension.End.Column] + .Select(cell => cell.Text) + .ToList(); + BaseProductionOrderSplit orderMoedel = new(); + // 映射数据库字段,这里需要根据你的实际需求进行调整 + var columnMappings = new Dictionary + { + // 添加映射 + {columnHeaders[0],"production_sequence"}, + {columnHeaders[1],"line_code"}, + {columnHeaders[3],"prod_code"}, + {columnHeaders[4],"Quantity"}, + {columnHeaders[5],"order_code"} + }; + int ordernum = 0; + // 获取实际的行数和列数 + int rowCount = worksheet.Dimension.Rows; + int colCount = worksheet.Dimension.Columns; + // 遍历 Excel 数据行 + for (int row = 2; row <= rowCount; row++) + { + // 创建 SQL 插入语句 + //string insertCommand = $"INSERT INTO YourTableName ({string.Join(", ", columnMappings.Values)}) VALUES ("; + List values = new(); + // 遍历 Excel 数据列 + for (int col = 1; col <= colCount; col++) + { + string columnName = columnHeaders[col - 1]; + string databaseColumnName; + // 映射 Excel 列名到数据库列名 + if (columnMappings.TryGetValue(columnName, out databaseColumnName)) + { + // 获取 Excel 单元格的值 + var cellValue = worksheet.Cells[row, col].Text; + // 添加值到插入语句 + values.Add(cellValue); + //values.Add($"'{cellValue.Replace("'", "''")}'"); + //if (!string.IsNullOrWhiteSpace(cellValue)) + //{ + // values.Add(cellValue); + //} + } + } + // 使用 LINQ 查询空值 + bool containsNull = values.Any(item => item == "" || item == null); + if (containsNull) + { + //MessageBox.Show("Excel表格中存在空值,不执行导入操作!", "订单导入操作提示!"); + //LogManager.Info($"订单导入按钮事件错误 >>> Excel表格中存在空值!不执行导入操作!"); + break; + } + // 获得插入语句 + //string fullInsertCommand = $"{insertCommand} {string.Join(", ", values)} )"; + var xianbiename = Char.GetNumericValue(values[1][values[1].Length - 1]).ToString(); + int orderSequence = int.Parse(values[0].Trim()); + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + // var orderModel = dbContext.BaseProductionOrderSplit.OrderBy(t => t.productionSequence).ToList(); + //var data = orderModel.Find(t => t.orderCode == values[4].Trim().ToUpper()); + //if (data == null) + //{ + // BaseProductionOrderSplit InserOrderModel = new() + // { + // id = Guid.NewGuid().ToString(), + // lineCode = values[1].Trim(), + // lineName = xianbiename == "1" ? "二线" : "一线", + // orderCode = values[4].Trim().ToUpper(), + // prodCode = values[2].Trim(), + // prodDesc = values[2].Trim(), + // productionSequence = orderSequence, + // est = DateTime.Now, + // isover = 0, + // quantity = 1, + // createBy = "ExcelInsert" + // }; + // dbContext.Add(InserOrderModel); + // dbContext.SaveChanges(); + // ordernum++; + //} + } - // 遍历 Excel 数据列 - for (int col = 1; col <= worksheet.Dimension.End.Column; col++) - { - string columnName = columnHeaders[col - 1]; - string databaseColumnName; - // 映射 Excel 列名到数据库列名 - if (columnMappings.TryGetValue(columnName, out databaseColumnName)) - { - // 获取 Excel 单元格的值 - var cellValue = worksheet.Cells[row, col].Text; - // 添加值到插入语句 - values.Add(cellValue); - //values.Add($"'{cellValue.Replace("'", "''")}'"); - //if (!string.IsNullOrWhiteSpace(cellValue)) - //{ - // values.Add(cellValue); - //} - } - } - // 使用 LINQ 查询空值 - bool containsNull = values.Any(item => item == "" || item == null); - if (containsNull) - { - MessageBox.Show("Excel表格中存在空值,不执行导入操作!", "订单导入操作提示!"); - LogManager.Info($"按钮订单导入事件粗无日志 >>> Excel表格中存在空值!不执行导入操作!"); - continue; - } - // 获得插入语句 - //string fullInsertCommand = $"{insertCommand} {string.Join(", ", values)} )"; - var xianbiename = Char.GetNumericValue(values[1][values[1].Length - 1]).ToString(); - int orderSequence = int.Parse(values[0].Trim()); - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - var orderModel = dbContext.BaseProductionOrderSplit.OrderBy(t => t.productionSequence).ToList(); - var data = orderModel.Find(t => t.orderCode == values[4].Trim().ToUpper()); - if (data == null) - { - BaseProductionOrderSplit InserOrderModel = new() - { - id = Guid.NewGuid().ToString(), - lineCode = values[1].Trim(), - lineName = xianbiename == "1" ? "二线" : "一线", - orderCode = values[4].Trim().ToUpper(), - prodCode = values[2].Trim(), - prodDesc = values[2].Trim(), - productionSequence = orderSequence, - est = DateTime.Now, - isover = 0, - quantity = 1 - }; - dbContext.Add(InserOrderModel); - dbContext.SaveChanges(); - ordernum++; - } - } - MessageBox.Show($"{ordernum}条订单导入系统!", "订单导入操作提示!"); - this.LoadMaterial.ItemsSource = null; - LoadMaterial_GetMessage(""); - } - } - } - })); + MessageBox.Show($"{ordernum}条订单导入系统!", "订单导入操作提示!"); + this.LoadMaterial.ItemsSource = null; + LoadMaterial_GetMessage(""); + } + } + } + })); } catch (Exception ex) { @@ -1231,5 +1243,155 @@ namespace XGL.FormItem this.lba_ThrifTtitle.Content = string.Empty; } } + /// + /// 订单清空按钮 + /// + /// + /// + private void btn_ClearOrder_Click(object sender, RoutedEventArgs e) + { + try + { + var data = this.LoadMaterial.ItemsSource; + if (data == null) + { + MessageBox.Show($"当前订单信息为空,无需清空操作!", "订单手动清空提示!"); + return; + } + if (MessageBox.Show("确认是否清空当前预存订单?", + "订单手动清空提示", + MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) + { + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + string sqlQuery = @"INSERT INTO + base_production_order_split_bak + (id,site_code, line_code, line_name, order_code,prod_code,prod_desc,IsOver,est,Quantity,production_sequence) + SELECT + id,site_code, line_code, line_name, order_code,prod_code,prod_desc,IsOver,est,Quantity,production_sequence + FROM base_production_order_split;"; + string sqlDelete = @"Delete + FROM + base_production_order_split;"; + var ret = dbContext.Database.ExecuteSqlRaw(sqlQuery); + dbContext.Database.ExecuteSqlRaw(sqlDelete); + string zhandianText = ThriftConfig.UpSite == "k46" ? "K46" : "K48"; + string saveLog = ret == 0 ? "清空后备份任务SQL执行失败!" : "清空后备份任务SQL语句执行成功!"; + if (ret != 0) MessageBox.Show($"{ret}条订单清空完毕!", "订单清空提示!"); + LogManager.Info($"手动清空任务日志记录 >>> 站点:{zhandianText}{saveLog}"); + this.LoadMaterial.ItemsSource = null; + LoadMaterial_GetMessage(""); + } + } + catch (Exception ex) + { + LogManager.Info($"手动清空任务方法报错 >>> {ex.Message}"); + } + } + /// + /// 查询挂具绑定Vin物料点击事件 + /// + /// + /// + private void Btn_ChaXunByCarNo_Click(object sender, RoutedEventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(this.tbx_JieBangByCarNo.Text)) + { + MessageBox.Show("上线挂具号输入框为空!", "查询挂具物料绑定关系操作提示!"); + return; + } + if (!Regex.IsMatch(this.tbx_JieBangByCarNo.Text, @"^\d+$")) + { + MessageBox.Show("挂具号输入格式有误!", "查询挂具物料绑定关系操作提示!"); + this.tbx_JieBangByVin.Clear(); + return; + //textBox.Text = textBox.Text.Replace("非数字字符", ""); // 移除非数字字符 + } + if (this.tbx_JieBangByCarNo.Text.Length >= 3) + { + MessageBox.Show("挂具号输入长度有误!", "查询挂具物料绑定关系操作提示!"); + this.tbx_JieBangByVin.Clear(); + return; + } + int ShuRuCarNo = int.Parse(this.tbx_JieBangByCarNo.Text); + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + //var listWaitDownLine = dbContext.BaseWaitdownline.Where(t => t.isDelete == 0 && t.carNo == ShuRuCarNo).ToList(); + //if (string.IsNullOrWhiteSpace(listWaitDownLine[0].materielNo)) + //{ + // MessageBox.Show($"{ShuRuCarNo}号为空挂具,不存在与Vin绑定信息!", "查询挂具物料绑定关系操作提示!"); + // return; + //} + // var listOrder = dbContext.BaseProductionOrderSplit.Where(t => t.orderCode == listWaitDownLine[0].materielNo).ToList(); + //var resultOrderList = (from waitdownline in listWaitDownLine + // join order in listOrder on waitdownline.materielNo equals order.orderCode + // select new BaseProductionOrderSplit + // { + // id = order.id, + // lineCode = order.lineCode, + // orderCode = order.orderCode + // }).ToList(); + //if (resultOrderList?.Count > 0) + //{ + // this.tbx_JieBangByVin.Text = resultOrderList[0].orderCode; + //} + } + catch (Exception ex) + { + MessageBox.Show($"查询挂具物料绑定关系报错 >>> {ex.Message}"); + LogManager.Info($"查询挂具物料绑定关系报错 >>> {ex.Message}"); + } + } + /// + /// 解绑按钮点击事件 + /// + /// + /// + private void Btn_JieBangByCarNo_Click(object sender, RoutedEventArgs e) + { + try + { + + } + catch (Exception ex) + { + LogManager.Info($"解绑载具物料绑定关系操作报错 >>> {ex.Message}"); + } + } + /// + /// 清空输入框点击事件 + /// + /// + /// + private void Btn_ChaXunByCarNoClear_Click(object sender, RoutedEventArgs e) + { + try + { + this.tbx_JieBangByCarNo.Clear(); + this.tbx_JieBangByVin.Clear(); + } + catch (Exception) + { + } + } + /// + /// 一键重置点击事件 + /// + /// + /// + private void Btn_JieBangAll_Click(object sender, RoutedEventArgs e) + { + try + { + + } + catch (Exception EX) + { + LogManager.Info($"一键重置订单、挂具状态方法报错 >>> {EX.Message}"); + } + + } } } diff --git a/src/Khd.Core.Wpf/Form/FormBoardT.xaml b/src/Khd.Core.Wpf/Form/FormBoardT.xaml new file mode 100644 index 0000000..7acde81 --- /dev/null +++ b/src/Khd.Core.Wpf/Form/FormBoardT.xaml @@ -0,0 +1,1213 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Khd.Core.Wpf/Form/FormBoardT.xaml.cs b/src/Khd.Core.Wpf/Form/FormBoardT.xaml.cs new file mode 100644 index 0000000..3821470 --- /dev/null +++ b/src/Khd.Core.Wpf/Form/FormBoardT.xaml.cs @@ -0,0 +1,684 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Threading; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Threading; +using Masuit.Tools.Logging; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Khd.Core.EntityFramework; +using Khd.Core.Plc.S7; +using Thrift.Server; +using Thrift.Transport; +using ThriftService; +using Thrift.Protocol; +using Khd.Core.Domain.Models; +using Z.EntityFramework.Plus; +using OfficeOpenXml; +using Microsoft.Win32; +using System.IO; +using System.Windows; +using Microsoft.EntityFrameworkCore; +using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net.Http.Json; +using Khd.Core.Domain.Dto.webapi; +using Newtonsoft.Json; +using HandyControl.Tools.Extension; + +namespace Khd.Core.Wpf.Form +{ + /// + /// FormBoardT.xaml 的交互逻辑 + /// + public partial class FormBoardT : Window + { + private readonly IHost _host; + private Khd.Core.Plc.S7.Plc _plc; + private DispatcherTimer ShowTimer;//刷新时间 + private DispatcherTimer PLCMessage;//呈现PLC机柜信息 + private DispatcherTimer UPMessageTimer;//刷新上件记录 + private DispatcherTimer ShowOrderMessage;//呈现PLC机柜信息 + private object order_code; + private int UpState;//对应上件站点的状态,0为良好 1为损坏 + List basePlcpoints = new List(); + object timerjilu; + public class selectOrderData + { + public string Id { get; set; } + public string orderCode { get; set; } + } + private string selectedId; + //FormShowSelect formSelect; + // public static int WeekNo = CommonHelper.WeekOfYear(DateTime.Now, new System.Globalization.CultureInfo("zh-CN")); + public FormBoardT(IHost host) + { + InitializeComponent(); + this._host = host; + } + /// + /// 页面加载事件 + /// + /// + /// + private void FormBoard_Loaded(object sender, RoutedEventArgs e) + { + try + { + LogManager.Info($"--------------------------当前时间 :{DateTime.Now} >>> 客户端启动;"); + //设置显示任务栏 + if (WindowState == WindowState.Normal) + { + MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight; + WindowState = WindowState.Maximized; + } + //加载dategrid信息 + //LoadMaterial_GetMessage(""); + //连接PLC判断 + var plc = new Khd.Core.Plc.S7.Plc((CpuType)PlcConfig.CpuType, PlcConfig.IP, PlcConfig.Port, + PlcConfig.Rack, PlcConfig.Slot); + //plc.Open(); + //if (!plc.IsConnected) + //{ + // MessageBox.Show("PLC连接失败,重新连接"); + //} + //else + //{ + // this._plc = plc; + //} + + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + basePlcpoints = dbContext.BasePlcpoint.Where(t => t.isDelete == 0).ToList(); + //var baseMaterials = dbContext.BaseMaterial.Where(t => t.IsDelete == 0).ToList(); + // + + PLCMessage = new DispatcherTimer(); + PLCMessage.Tick += new EventHandler(PLCmessage); //委托获取点位方法 + PLCMessage.Interval = new TimeSpan(0, 0, 0, 0, 1000); + PLCMessage.Start(); + + UPMessageTimer = new DispatcherTimer(); + UPMessageTimer.Tick += new EventHandler(UpMessage); //委托刷新上件记录 + UPMessageTimer.Interval = new TimeSpan(0, 0, 0, 0, 2000); + UPMessageTimer.Start(); + Button_Click_1(null, null); + SetTime(); + List list = new List + { + "101上件点", + "102上件点", + "103上件点" + }; + MoHuChaXunWuLiaoName.ItemsSource = list; + MoHuChaXunWuLiaoName.SelectedIndex = 0; + List list2 = new List + { + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10" + }; + comnumber.ItemsSource = list2; + comnumber.SelectedIndex = 5; + // shangjianwuliaocombox.ItemsSource= dbContext.BaseProductionOrderSplit.Where( t => t.isCompleted == "0" && t.quantity != t.onlineQuantity).GroupBy(c=>c.prodDesc).Select(r=>r.Key).ToList(); + //StartThriftServer(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + /// + /// 刷新日期 + /// + private void SetTime() + { + new Thread(() => + { + while (true) + { + try + { + Dispatcher.Invoke(new Action(delegate + { + LabDate.Content = DateTime.Now.ToString("yyyy年MM月dd日"); + LabTime.Content = DateTime.Now.ToString("HH:mm:ss"); + })); + } + catch (Exception ex) + { + } + finally + { + Thread.Sleep(1000); + } + } + }).Start(); + } + public void UpMessage(object sender, EventArgs e) + { + MoHuChaXunWuLiaoName_SelectionChanged(timerjilu, null); + } + /// + /// WCS通讯方法 + /// + public void StartThriftServer() + { + try + { + int point = Convert.ToInt32(ThriftConfig.JiesShouDuanKou); + WcsServer wcsServer = new WcsServer(); + //wcsServer.SendCarEvent += SendCar; + // wcsServer.helloEvent += hello; + WcsThrift.Processor processor = new WcsThrift.Processor(wcsServer); + TServerTransport serverTransport = new TServerSocket(point); + TServer server = new TSimpleServer(processor, serverTransport); + server.Serve(); + } + catch (Exception ex) + { + Application.Current.Dispatcher.Invoke(new Action( + delegate + { + //设置图片为未到位 + this.CarNo.Text = "Null"; + this.labzjydw.Visibility = System.Windows.Visibility.Hidden; + this.imgzjydw.Visibility = System.Windows.Visibility.Hidden; + this.labzjwdw.Visibility = System.Windows.Visibility.Visible; + this.imgzjwdw.Visibility = System.Windows.Visibility.Visible; + })); + LogManager.Error(ex); + } + + } + public string hello(string name) + { + //Console.WriteLine($"hello {name}"); + //return $"ServerResponse receive from client name:{name}"; + try + { + if (!string.IsNullOrWhiteSpace(name)) + { + Application.Current.Dispatcher.Invoke(new Action( + delegate + { + //设置图片为已到位、显示挂具号 + this.CarNo.Text = name; + this.labzjydw.Visibility = System.Windows.Visibility.Visible; + this.imgzjydw.Visibility = System.Windows.Visibility.Visible; + this.labzjwdw.Visibility = System.Windows.Visibility.Hidden; + this.imgzjwdw.Visibility = System.Windows.Visibility.Hidden; + })); + } + else + { + Application.Current.Dispatcher.Invoke(new Action( + delegate + { + //设置图片为未到位 + //this.CarNo.Clear(); + this.labzjydw.Visibility = System.Windows.Visibility.Hidden; + this.imgzjydw.Visibility = System.Windows.Visibility.Hidden; + this.labzjwdw.Visibility = System.Windows.Visibility.Visible; + this.imgzjwdw.Visibility = System.Windows.Visibility.Visible; + })); + } + } + catch (Exception ex) + { + LogManager.Info($"客户端接收服务端推送的小车信息方法报错 >>> {ex.Message}"); + } + return ""; + } + + /// + /// 发车方法 + /// + /// + /// + /// 物料号 + /// 三轮车辆长度 + public void SendCar(List carlist, string prodCode, string bunber,string ordercodeid) + { + TTransport transport = new TSocket(ThriftConfig.ThriftIpAddress, ThriftConfig.TuiSongDuankou); + try + { + //Console.WriteLine($"hello carlist[0]:{carlist.FirstOrDefault()}|order_code:{order_code}|amount:{amount}"); + //return $"ServerResponse receive from client order_code:{order_code}"; + transport.Open(); + TProtocol protocol = new TBinaryProtocol(transport); + WcsThrift.Client client = new WcsThrift.Client(protocol); + // var ret = client.SendCar(carlist, prodCode, bunber, ordercodeid); + if ("1" == "1")//与服务端交互成功发车时 + { + Application.Current.Dispatcher.Invoke(new Action( + delegate + { + //发车成功提示反馈 + this.lba_ThrifTtitle.Foreground = new SolidColorBrush(Colors.Green); + this.lba_ThrifTtitle.Text = "发车成功!"; + //设置为未到位 + this.labzjwdw.Visibility = System.Windows.Visibility.Visible; + this.imgzjwdw.Visibility = System.Windows.Visibility.Visible; + this.labzjydw.Visibility = System.Windows.Visibility.Hidden; + this.imgzjydw.Visibility = System.Windows.Visibility.Hidden; + })); + } + + else//与服务端交互失败时 + { + + Application.Current.Dispatcher.Invoke(new Action( + delegate + { + this.lba_ThrifTtitle.Foreground = new SolidColorBrush(Colors.Red); + this.lba_ThrifTtitle.Text = $"Thrift交互失败!"; + //发车失败依然显示到位 + this.labzjwdw.Visibility = System.Windows.Visibility.Hidden; + this.imgzjwdw.Visibility = System.Windows.Visibility.Hidden; + this.labzjydw.Visibility = System.Windows.Visibility.Visible; + this.imgzjydw.Visibility = System.Windows.Visibility.Visible; + })); + } + } + catch (Exception ex) + { + LogManager.Info($"发车方法报错 >>> {ex.Message}"); + } + finally + { + transport.Close(); + transport.Dispose(); + } + } + /// + /// 显示序号事件 + /// + /// + /// + private void dgData_LoadingRow(object sender, DataGridRowEventArgs e) + { e.Row.Header = e.Row.GetIndex() + 1; } + /// + /// 点击退出按钮 + /// + /// + /// + private void btnExit_Click(object sender, RoutedEventArgs e) + { + if (MessageBox.Show("是否确认关闭程序", "提示信息", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) + { + System.Environment.Exit(System.Environment.ExitCode); + } + } + private void Close(object sender, EventArgs e) + { + System.Environment.Exit(System.Environment.ExitCode); + } + public int i = 0; + /// + /// 电气机柜信息面板定时器调用方法 + /// + /// + /// + private void PLCmessage(object sender, EventArgs e) + { + try + { + if (i == 1000) + { + i = 0; + } + foreach (var item in basePlcpoints) + { + //通过名称找到TextBox + TextBox FoundTextBox = (TextBox)FindName(item.plcpointNo); + if (FoundTextBox == null) + { + continue; + } + string value = i.ToString(); + //string value = _plc.Read(item.plcpointAddress).ToString(); + //if (value.IsNullOrEmpty()) + //{ + // continue; + //} + //if (FoundTextBox.IsFocused == true) + //{ + // continue; + //} + FoundTextBox.Text = value; + i++; + LogManager.Info(i.ToString()); + } + + + } + catch (Exception ex) + { + LogManager.Info($"电气机柜信息面板定时器调用方法报错 >>> {ex.Message}"); + } + } + + /// + /// PLC读取方法封装 + /// + /// plc地址位 + /// plc数据类型(int类型默认为1) + /// plc地址位长度(string类型默认为2) + /// 载具号文本输入框 + /// 载具到位文本输入框 + /// PLC车辆状态文本输入框 + /// 载具去向文本输入框 + /// WCS处理状态文本输入框 + private void ReadPlcData(string plcAddress, int plcDataType, string plcValueLength, + TextBox textBoxXcid, TextBox textBoxGjdw, TextBox textBoxClzt, + TextBox textBoxXcqx, TextBox textBoxWcsclzt) + { + try + { + // 载具号 + ReadAndSetText(plcAddress, textBoxXcid); + + // 载具到位 + //DQXX.plcpointAddress = $"DB4.DBW{GetOffset(plcAddress, 0)}"; + string gjdw = $"DB4.DBW{GetOffset(plcAddress, 0)}"; + ReadAndSetText(gjdw, textBoxGjdw); + + // PLC处理状态 + //DQXX.plcpointAddress = $"DB4.DBW{GetOffset(plcAddress, 2)}"; + string plcclzt = $"DB4.DBW{GetOffset(plcAddress, 2)}"; + ReadAndSetText(plcclzt, textBoxClzt); + + // 小车去向 + //DQXX.plcpointAddress = $"DB5.DBW{GetOffset(plcAddress, 0)}"; + string xcqx = $"DB5.DBW{GetOffset(plcAddress, 0)}"; + ReadAndSetText(xcqx, textBoxXcqx, textBoxXcqx.IsFocused); + + // WCS处理完成 + //DQXX.plcpointAddress = $"DB5.DBW{GetOffset(plcAddress, 2)}"; + string wcsclzt = $"DB5.DBW{GetOffset(plcAddress, 2)}"; + ReadAndSetText(wcsclzt, textBoxWcsclzt, textBoxWcsclzt.IsFocused); + //-------------------------------------------------------------------------以下为方法内部嵌套方法 + //嵌套方法1 + void ReadAndSetText(string dw, TextBox textBox, bool checkFocus = false) + { + string value = _plc.Read(dw).ToString(); + if (value != null && (!checkFocus || !textBox.IsFocused)) + { + textBox.Text = value; + } + } + //嵌套方法2 + int GetOffset(string PlcAddress, int baseOffset) + { + int result = int.Parse(PlcAddress.Substring(4, 1)) * 4 + baseOffset; + return result; + } + + } + catch (Exception ex) + { + LogManager.Info($"PLC读取方法封装报错 >>> {ex.Message}"); + } + + } + + /// + /// 订单导入按钮点击事件 + /// + /// + /// + private void btn_dingdandaoru_Click(object sender, RoutedEventArgs e) + { + try + { + Application.Current.Dispatcher.Invoke(new Action( + delegate + { + // 设置 EPPlus 许可上下文 + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + OpenFileDialog openFileDialog = new OpenFileDialog(); + openFileDialog.Filter = "Excel Files|*.xls;*.xlsx"; + if (openFileDialog.ShowDialog() == true) + { + FileInfo fileInfo = new FileInfo(openFileDialog.FileName); + + using (ExcelPackage package = new ExcelPackage(fileInfo)) + { + ExcelWorksheet worksheet = package.Workbook.Worksheets.FirstOrDefault(); + + if (worksheet != null) + { + // 获取 Excel 表头 + var columnHeaders = worksheet.Cells[1, 1, 1, worksheet.Dimension.End.Column] + .Select(cell => cell.Text) + .ToList(); + BaseProductionOrderSplit orderMoedel = new(); + // 映射数据库字段,这里需要根据你的实际需求进行调整 + var columnMappings = new Dictionary + { + // 添加映射 + {columnHeaders[0],"production_sequence"}, + {columnHeaders[1],"line_code"}, + {columnHeaders[3],"prod_code"}, + {columnHeaders[4],"Quantity"}, + {columnHeaders[5],"order_code"} + }; + int ordernum = 0; + // 获取实际的行数和列数 + int rowCount = worksheet.Dimension.Rows; + int colCount = worksheet.Dimension.Columns; + // 遍历 Excel 数据行 + for (int row = 2; row <= rowCount; row++) + { + // 创建 SQL 插入语句 + //string insertCommand = $"INSERT INTO YourTableName ({string.Join(", ", columnMappings.Values)}) VALUES ("; + List values = new(); + // 遍历 Excel 数据列 + for (int col = 1; col <= colCount; col++) + { + string columnName = columnHeaders[col - 1]; + string databaseColumnName; + // 映射 Excel 列名到数据库列名 + if (columnMappings.TryGetValue(columnName, out databaseColumnName)) + { + // 获取 Excel 单元格的值 + var cellValue = worksheet.Cells[row, col].Text; + // 添加值到插入语句 + values.Add(cellValue); + //values.Add($"'{cellValue.Replace("'", "''")}'"); + //if (!string.IsNullOrWhiteSpace(cellValue)) + //{ + // values.Add(cellValue); + //} + } + } + // 使用 LINQ 查询空值 + bool containsNull = values.Any(item => item == "" || item == null); + if (containsNull) + { + //MessageBox.Show("Excel表格中存在空值,不执行导入操作!", "订单导入操作提示!"); + //LogManager.Info($"订单导入按钮事件错误 >>> Excel表格中存在空值!不执行导入操作!"); + break; + } + // 获得插入语句 + //string fullInsertCommand = $"{insertCommand} {string.Join(", ", values)} )"; + var xianbiename = Char.GetNumericValue(values[1][values[1].Length - 1]).ToString(); + int orderSequence = int.Parse(values[0].Trim()); + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + // var orderModel = dbContext.BaseProductionOrderSplit.OrderBy(t => t.productionSequence).ToList(); +///var data = orderModel.Find(t => t.orderCode == values[4].Trim().ToUpper()); + // + } + + MessageBox.Show($"{ordernum}条订单导入系统!", "订单导入操作提示!"); + //LoadMaterial_GetMessage(""); + } + } + } + })); + } + catch (Exception ex) + { + MessageBox.Show($"订单导入失败 >>> {ex.Message}", "订单导入操作提示!"); + LogManager.Info($"按钮订单导入事件报错 >>> {ex.Message}"); + } + } + /// + /// 接收到载具号后,清空残留信息 + /// + /// + /// + private void CarNo_TextChanged(object sender, TextChangedEventArgs e) + { + //if (!string.IsNullOrWhiteSpace(this.tBoxMessage.Text) && this.tBoxMessage.Text.Length == 17) + //{ + // //清空缓存信息 + // this.CarNo.Clear(); + // this.tBoxMessage.Clear(); + // this.lba_ThrifTtitle.Text = string.Empty; + //} + } + /// + /// 订单清空按钮 + /// + /// + /// + private void btn_ClearOrder_Click(object sender, RoutedEventArgs e) + { + try + { + var data = this.LoadMaterial.ItemsSource; + if (data == null) + { + MessageBox.Show($"当前订单信息为空,无需清空操作!", "订单手动清空提示!"); + return; + } + if (MessageBox.Show("确认是否清空当前预存订单?", + "订单手动清空提示", + MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) + { + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + string sqlQuery = @"INSERT INTO + base_production_order_split_bak + (id,site_code, line_code, line_name, order_code,prod_code,prod_desc,IsOver,est,Quantity,production_sequence) + SELECT + id,site_code, line_code, line_name, order_code,prod_code,prod_desc,IsOver,est,Quantity,production_sequence + FROM base_production_order_split;"; + string sqlDelete = @"Delete + FROM + base_production_order_split;"; + var ret = dbContext.Database.ExecuteSqlRaw(sqlQuery); + dbContext.Database.ExecuteSqlRaw(sqlDelete); + string zhandianText = ThriftConfig.UpSite == "k46" ? "K46" : "K48"; + string saveLog = ret == 0 ? "清空后备份任务SQL执行失败!" : "清空后备份任务SQL语句执行成功!"; + if (ret != 0) MessageBox.Show($"{ret}条订单清空完毕!", "订单清空提示!"); + LogManager.Info($"手动清空任务日志记录 >>> 站点:{zhandianText}{saveLog}"); + this.LoadMaterial.ItemsSource = null; + //LoadMaterial_GetMessage(""); + } + } + catch (Exception ex) + { + LogManager.Info($"手动清空任务方法报错 >>> {ex.Message}"); + } + } + + private void Button_Click_1(object sender, RoutedEventArgs e) + { + try + { + // + } + catch (Exception ex) + { + MessageBox.Show("查询订单遇到错误~>>>>>>>>>>>>>>>>>>>>" + ex); + LogManager.Info("查询订单遇到错误~>>>>>>>>>>>>>>>>>>>>" + ex); + } + } + /// + /// 选择事件 + /// + /// + /// + private void MoHuChaXunWuLiaoName_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + timerjilu = sender; + ComboBox comboBox = (ComboBox)sender; + var shangjiandian = comboBox.SelectedItem; + string numberPart = Regex.Match(shangjiandian.ToString(), @"\d+").Value; + try + { + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + // + } + catch (Exception ex) + { + MessageBox.Show("查询订单遇到错误~>>>>>>>>>>>>>>>>>>>>" + ex); + LogManager.Info("查询订单遇到错误~>>>>>>>>>>>>>>>>>>>>" + ex); + } + } + /// + /// 删除物料 + /// + /// + /// + private void Button_Click_2(object sender, RoutedEventArgs e) + { + if (LoadMaterial0.SelectedIndex == -1) + { + MessageBox.Show("请选择要删除的物料!"); + } + else + { + var quere = MessageBox.Show("确定删除吗", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Asterisk); + // + + } + } + /// + /// 刷新产线 + /// + /// + /// + private void Button_Click_3(object sender, RoutedEventArgs e) + { + // + } + /// + /// 物料选择事件 + /// + /// + /// + private void shangjianwuliaocombox_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + // + + } + + private void orderselect_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + // + } + } + + +} diff --git a/src/Khd.Core.Wpf/Form/TabItemInfo.cs b/src/Khd.Core.Wpf/Form/TabItemInfo.cs new file mode 100644 index 0000000..0cf3bea --- /dev/null +++ b/src/Khd.Core.Wpf/Form/TabItemInfo.cs @@ -0,0 +1,43 @@ +using System.ComponentModel; + +namespace Khd.Core.Wpf.Form +{ + public class TabItemInfo : INotifyPropertyChanged + { + private string imagePath; + private string text; + + public string ImagePath + { + get { return imagePath; } + set + { + if (imagePath != value) + { + imagePath = value; + OnPropertyChanged(nameof(ImagePath)); + } + } + } + + public string Text + { + get { return text; } + set + { + if (text != value) + { + text = value; + OnPropertyChanged(nameof(Text)); + } + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + protected virtual void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/src/Khd.Core.Wpf/Form/UserControl1.xaml b/src/Khd.Core.Wpf/Form/UserControl1.xaml new file mode 100644 index 0000000..d992cee --- /dev/null +++ b/src/Khd.Core.Wpf/Form/UserControl1.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + diff --git a/src/Khd.Core.Wpf/Form/UserControl1.xaml.cs b/src/Khd.Core.Wpf/Form/UserControl1.xaml.cs new file mode 100644 index 0000000..f12c5ac --- /dev/null +++ b/src/Khd.Core.Wpf/Form/UserControl1.xaml.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Khd.Core.Wpf.Form +{ + /// + /// UserControl1.xaml 的交互逻辑 + /// + public partial class UserControl1 : UserControl + { + public static readonly DependencyProperty TabItemInfoProperty = DependencyProperty.Register( + "TabItemInfo", + typeof(TabItemInfo), + typeof(UserControl1), + new PropertyMetadata(null, OnTabItemInfoChanged)); + + public TabItemInfo TabItemInfo + { + get { return (TabItemInfo)GetValue(TabItemInfoProperty); } + set { SetValue(TabItemInfoProperty, value); } + } + + public UserControl1() + { + InitializeComponent(); + } + + private static void OnTabItemInfoChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is UserControl1 userControl) + { + // 在这里处理数据变更,例如更新UI + // userControl.TabItemInfo 包含了最新的数据 + Debug.WriteLine($"ImagePath: {userControl.TabItemInfo?.ImagePath}, Text: {userControl.TabItemInfo?.Text}"); + } + } + + } +} diff --git a/src/Khd.Core.Wpf/Khd.Core.Wpf.csproj b/src/Khd.Core.Wpf/Khd.Core.Wpf.csproj index 2cb6fce..4d6bbb3 100644 --- a/src/Khd.Core.Wpf/Khd.Core.Wpf.csproj +++ b/src/Khd.Core.Wpf/Khd.Core.Wpf.csproj @@ -9,12 +9,11 @@ - - - + + @@ -123,12 +122,12 @@ - - - - - - + + PreserveNewest + + + PreserveNewest + Always @@ -149,6 +148,11 @@ + + + C:\Users\ZJ\.nuget\packages\hbinformationbase\22.2.15.1313\lib\net5.0\HBInformationBase.dll + + Always @@ -468,7 +472,4 @@ PreserveNewest - - - diff --git a/src/Khd.Core.Wpf/LoginPage.xaml.cs b/src/Khd.Core.Wpf/LoginPage.xaml.cs index de6106d..3cabfa9 100644 --- a/src/Khd.Core.Wpf/LoginPage.xaml.cs +++ b/src/Khd.Core.Wpf/LoginPage.xaml.cs @@ -14,7 +14,6 @@ using System.Windows.Media.Imaging; using System.Windows.Shapes; using Masuit.Tools.Logging; using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; -using XGL.FormItem; using System.Collections; using Masuit.Tools.Logging; using Microsoft.Extensions.Logging; @@ -24,6 +23,8 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.DependencyInjection; using Khd.Core.EntityFramework; using Microsoft.EntityFrameworkCore; +using System.Diagnostics; +using Khd.Core.Wpf.Form; namespace Khd.Core.Wpf { @@ -37,11 +38,26 @@ namespace Khd.Core.Wpf { InitializeComponent(); this.Hide(); - //string[] args; - IHost host = CreateHostBuilder(null).Build(); - _host = host; - FormBoard mainWindow = new FormBoard(_host); - mainWindow.Show(); + //IHost host = CreateHostBuilder(null).Build(); + //_host = host; + //FormBoard mainWindow = new FormBoard(_host); + //mainWindow.Show(); + // 通过进程名称查找进程 + bool ret; + string upsite = ThriftConfig.UpSite == "k48" ? "K48" : "K46"; + System.Threading.Mutex mutex = new System.Threading.Mutex(true, $"Khd.Core.Wpf", out ret); + if (ret) + { + IHost host = CreateHostBuilder(null).Build(); + _host = host; + FormBoardT mainWindow = new FormBoardT(_host); + mainWindow.Show(); + } + else + { + MessageBox.Show("系统重复开启,请先关闭之前窗口!"); + mutex.ReleaseMutex(); // 释放 Mutex + } } private void Window_Loaded(object sender, RoutedEventArgs e) { diff --git a/src/Khd.Core.Wpf/Resources/amma.png b/src/Khd.Core.Wpf/Resources/amma.png new file mode 100644 index 0000000..fc7206d Binary files /dev/null and b/src/Khd.Core.Wpf/Resources/amma.png differ diff --git a/src/Khd.Core.Wpf/Resources/amma3.png b/src/Khd.Core.Wpf/Resources/amma3.png new file mode 100644 index 0000000..094c27f Binary files /dev/null and b/src/Khd.Core.Wpf/Resources/amma3.png differ diff --git a/src/Khd.Core.Wpf/ThriftServer/WcsServer.cs b/src/Khd.Core.Wpf/ThriftServer/WcsServer.cs index 8482444..5d4c9d7 100644 --- a/src/Khd.Core.Wpf/ThriftServer/WcsServer.cs +++ b/src/Khd.Core.Wpf/ThriftServer/WcsServer.cs @@ -8,25 +8,15 @@ namespace ThriftService { public class WcsServer : WcsThrift.Iface { - public delegate string deletehello(string name); - public deletehello helloEvent; - public string hello(string name) + public string hello(string name) { - if (helloEvent != null) - { - return helloEvent(name); - } - return ""; + Console.WriteLine($"hello {name}"); + return $"ServerResponse receive from client name:{name}"; } - public delegate string deleteSendCar(List carlist, string order_code, string amount); - public deleteSendCar SendCarEvent; public string SendCar(List carlist, string order_code, string amount) { - if (SendCarEvent != null) - { - return SendCarEvent(carlist, order_code, amount); - } - return ""; + Console.WriteLine($"hello carlist[0]:{carlist.FirstOrDefault()}|order_code:{order_code}|amount:{amount}"); + return $"ServerResponse receive from client order_code:{order_code}"; } } diff --git a/src/Khd.Core.Wpf/appsettings.json b/src/Khd.Core.Wpf/appsettings.json index 60e33fa..2c45796 100644 --- a/src/Khd.Core.Wpf/appsettings.json +++ b/src/Khd.Core.Wpf/appsettings.json @@ -1,14 +1,14 @@ { "ConnectionStrings": { //mysql 本地 - "DefaultConnection": "server=localhost;port=3306;database=khd_suspension_chain;uid=root;pwd=root;charset='utf8';persistsecurityinfo=True;SslMode=none;Allow User Variables=True" + "DefaultConnection": "server=localhost;port=3306;database=khd_jyhb;uid=root;pwd=root;charset='utf8';persistsecurityinfo=True;SslMode=none;Allow User Variables=True" //khd服务器 - //"DefaultConnection": "server=106.12.13.113;port=3336;database=khd_suspension_chain;uid=khd;pwd=khd@123;charset='utf8';persistsecurityinfo=True;SslMode=none;Allow User Variables=True" + // "DefaultConnection": "server=106.12.13.113;port=3336;database=khd_suspension_chain;uid=khd;pwd=khd@123;charset='utf8';persistsecurityinfo=True;SslMode=none;Allow User Variables=True" //雅迪数据库 //"DefaultConnection": "server=localhost;port=3306;database=khd_suspension_chain;uid=root;pwd=123456;charset='utf8';persistsecurityinfo=True;SslMode=none;Allow User Variables=True" }, "PlcConfig": { - "IP": "192.168.0.1", + "IP": "127.0.0.1", "Port": "102", "CpuType": 30, "Rack": "0",