From ae8f502a86594014d7237f9e249b025575d74af6 Mon Sep 17 00:00:00 2001 From: wenjy Date: Wed, 9 Aug 2023 10:19:04 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=20=E5=B9=B2=E6=B7=B7=E6=9C=BA=E6=8A=A5?= =?UTF-8?q?=E8=A1=A8=E6=95=B0=E6=8D=AE=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entity/Report/Report_DryMixer.cs | 32 ++- .../SaveHelper/ReportSaveHelper.cs | 247 +++++++++++++++++- 2 files changed, 262 insertions(+), 17 deletions(-) diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Entity/Report/Report_DryMixer.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Entity/Report/Report_DryMixer.cs index fb98543..c7023d9 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Entity/Report/Report_DryMixer.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Entity/Report/Report_DryMixer.cs @@ -11,8 +11,28 @@ namespace Mesnac.Action.ChemicalWeighing.Entity.Report /// public class Report_DryMixer { + /// + /// 构造函数 + /// + /// + public Report_DryMixer(Guid id = default) + { + report_Id = id == default ? Guid.NewGuid() : id; + } + + /// + /// 报表Id + /// + public Guid report_Id { get; set; } + + /// + /// Dos + /// public List dos { get;set; } + /// + /// Mix + /// public List mix { get;set; } } @@ -33,19 +53,19 @@ namespace Mesnac.Action.ChemicalWeighing.Entity.Report /// /// 设定重量 /// - public string setValue { get; set; } + public double setValue { get; set; } /// /// 设定公差 /// - public string setToler { get; set; } + public double setToler { get; set; } /// /// 实际重量 /// - public string actValue { get; set; } + public double actValue { get; set; } /// /// 实际公差 /// - public string actToLer { get; set; } + public double actToLer { get; set; } /// /// 步骤编号 /// @@ -83,11 +103,11 @@ namespace Mesnac.Action.ChemicalWeighing.Entity.Report /// /// 温度 /// - public string mixTemp { get; set; } + public double mixTemp { get; set; } /// /// 速度 /// - public string mixSpeed { get; set; } + public double mixSpeed { get; set; } public int mix { get; set; } diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/ReportSaveHelper.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/ReportSaveHelper.cs index b8d1a15..4fb6659 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/ReportSaveHelper.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/ReportSaveHelper.cs @@ -1,9 +1,12 @@ using DevExpress.DataAccess.Native.Json; +using DevExpress.Office.Utils; using DevExpress.XtraPrinting.Native.WebClientUIControl; using Mesnac.Action.ChemicalWeighing.Entity.Report; +using Mesnac.Codd.Session; using Microsoft.Office.Interop.Excel; using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -127,9 +130,6 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper List dryMixerMixes = new List (); for (int dos = 0;dos< 4; dos++) { - // var info = BasePlcHelper.Instance.dryerA_dos1_eqNo.LastValue.ToInt(); - var info1 = new Entity.DataKeyValue($"dryer{machineType}_dos{dos}_eqNo").LastValue.ToInt(); - var info2 = new Entity.DataKeyValue($"dryer{machineType}_dos{dos}_batch").NowValue.ToInt(); BasePlcHelper.Instance.dryer_eqNo = new Entity.DataKeyValue($"dryer{machineType}_dos{dos}_eqNo"); BasePlcHelper.Instance.dryer_batch = new Entity.DataKeyValue($"dryer{machineType}_dos{dos}_batch"); BasePlcHelper.Instance.dryer_matCode = new Entity.DataKeyValue($"dryer{machineType}_dos{dos}_matCode"); @@ -142,20 +142,18 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper eqNo = BasePlcHelper.Instance.dryer_eqNo.NowValue.ToInt(), batch = BasePlcHelper.Instance.dryer_batch.NowValue.ToInt(), matCode = BasePlcHelper.Instance.dryer_matCode.NowValue.ToInt(), - setValue = BasePlcHelper.Instance.dryer_setValue.NowValue.ToString(), - setToler = BasePlcHelper.Instance.dryer_setToler.NowValue.ToString(), - actValue = BasePlcHelper.Instance.dryer_actValue.NowValue.ToString(), - actToLer = BasePlcHelper.Instance.dryer_actToLer.NowValue.ToString(), + setValue = BasePlcHelper.Instance.dryer_setValue.NowValue.ToDouble(), + setToler = BasePlcHelper.Instance.dryer_setToler.NowValue.ToDouble(), + actValue = BasePlcHelper.Instance.dryer_actValue.NowValue.ToDouble(), + actToLer = BasePlcHelper.Instance.dryer_actToLer.NowValue.ToDouble(), dos = dos, recordTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }; - // _dryMixer.dos = new List { dryMixerDos }; dryMixerDoes.Add( dryMixerDos ); } for (int mix = 0; mix < 10; mix++) { - //BasePlcHelper.Instance.dryer_eqNo = new Entity.DataKeyValue($"dryer{machineType}_mix{mix}_eqNo"); BasePlcHelper.Instance.dryer_mixBatch = new Entity.DataKeyValue($"dryer{machineType}_mix{mix}_mixBatch"); BasePlcHelper.Instance.dryer_mixStep = new Entity.DataKeyValue($"dryer{machineType}_mix{mix}_mixStep"); BasePlcHelper.Instance.dryer_actCode = new Entity.DataKeyValue($"dryer{machineType}_mix{mix}_actCode"); @@ -169,8 +167,8 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper mixStep = BasePlcHelper.Instance.dryer_matCode.NowValue.ToInt(), actCode = BasePlcHelper.Instance.dryer_actCode.NowValue.ToInt(), mixTime = BasePlcHelper.Instance.dryer_mixTime.NowValue.ToInt(), - mixTemp = BasePlcHelper.Instance.dryer_mixTemp.NowValue.ToString(), - mixSpeed = BasePlcHelper.Instance.dryer_mixSpeed.NowValue.ToString(), + mixTemp = BasePlcHelper.Instance.dryer_mixTemp.NowValue.ToDouble(), + mixSpeed = BasePlcHelper.Instance.dryer_mixSpeed.NowValue.ToDouble(), mix = mix, recordTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }; @@ -196,6 +194,17 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper try { string str = serializer.Serialize(_dryMixer); + if(_dryMixer != null) + { + if(_dryMixer.dos != null) + { + InsertReportDryMixer(_dryMixer.report_Id,_dryMixer.dos); + }else if(_dryMixer.mix != null) + { + InsertReportDryMixerDetail(_dryMixer.report_Id, _dryMixer.mix); + } + } + ICSharpCode.Core.LoggingService.Warn($"报表数据打印:{str}"); } @@ -204,5 +213,221 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper ICSharpCode.Core.LoggingService.Error(String.Format("保存报表数据至数据库异常:{0}", ex.Message), ex); } } + + /// + /// 保存干混机报表数据 + /// + /// + /// + private static void InsertReportDryMixer(Guid reportId,List dryMixers) + { + try + { + + Task.Run(() => + { + DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); + if (dbHelper == null) + { + throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); + } + string sqlStr = @"insert into Report_DryMixer + (reportId, eqNo, batch, matCode, setValue, setToler, actValue, actToLer, dos) + values + (@reportId, @eqNo, @batch, @matCode, @setValue, @setToler, @actValue, @actToLer, @dos)"; + + foreach (DryMixerDos _dryMixerDos in dryMixers) + { + if (_dryMixerDos.actValue == 0) continue; + + dbHelper.ClearParameter(); + dbHelper.CommandType = CommandType.Text; + dbHelper.CommandText = sqlStr; + dbHelper.AddParameter("@reportId", reportId); + dbHelper.AddParameter("@eqNo", _dryMixerDos.eqNo); + dbHelper.AddParameter("@batch", _dryMixerDos.batch); + dbHelper.AddParameter("@matCode", _dryMixerDos.matCode); + dbHelper.AddParameter("@setValue", _dryMixerDos.setValue); + dbHelper.AddParameter("@setToler", _dryMixerDos.setToler); + dbHelper.AddParameter("@actValue", _dryMixerDos.actValue); + dbHelper.AddParameter("@actToLer", _dryMixerDos.actToLer); + dbHelper.AddParameter("@dos", _dryMixerDos.dos); + dbHelper.ExecuteNonQuery(); + + } + }); + }catch (Exception ex) + { + ICSharpCode.Core.LoggingService.Error(String.Format("保存干混机报表数据异常:{0}", ex.Message), ex); + } + } + + /// + /// 保存干混机报表明细数据 + /// + /// + /// + private static void InsertReportDryMixerDetail(Guid reportId, List dryMixers) + { + try + { + Task.Run(() => + { + DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); + if (dbHelper == null) + { + throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); + } + string sqlStr = @"insert into Report_DryMixer_Detail + (reportId, eqNo, mixBatch, mixStep, actCode, mixTime, mixTemp, mixSpeed, mix) + values + (@reportId, @eqNo, @mixBatch, @mixStep, @actCode, @mixTime, @mixTemp, @mixSpeed, @mix)"; + foreach (DryMixerMix _dryMixerMix in dryMixers) + { + if (_dryMixerMix.actCode == 0) continue; + + dbHelper.ClearParameter(); + dbHelper.CommandType = CommandType.Text; + dbHelper.CommandText = sqlStr; + dbHelper.AddParameter("@reportId", reportId); + dbHelper.AddParameter("@eqNo", _dryMixerMix.eqNo); + dbHelper.AddParameter("@mixBatch", _dryMixerMix.mixBatch); + dbHelper.AddParameter("@mixStep", _dryMixerMix.mixStep); + dbHelper.AddParameter("@actCode", _dryMixerMix.actCode); + dbHelper.AddParameter("@mixTime", _dryMixerMix.mixTime); + dbHelper.AddParameter("@mixTemp", _dryMixerMix.mixTemp); + dbHelper.AddParameter("@mixSpeed", _dryMixerMix.mixSpeed); + dbHelper.AddParameter("@mix", _dryMixerMix.mix); + dbHelper.ExecuteNonQuery(); + } + }); + }catch(Exception ex) + { + ICSharpCode.Core.LoggingService.Error(String.Format("保存干混机报表明细数据异常:{0}", ex.Message), ex); + } + } + +/*create table Report_DryMixer +( + objId int identity + primary key, + reportId varchar(36), + eqNo int, + batch int, + matCode int, + setValue decimal(18, 4), + setToler decimal(18, 4), + actValue decimal(18, 4), + actToLer decimal(18, 4), + dos int, + recordTime datetime default getdate() +) +go + +exec sp_addextendedproperty 'MS_Description', N'干混机报表', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer' +go + +exec sp_addextendedproperty 'MS_Description', N'主键标识', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer', 'COLUMN', + 'objId' +go + +exec sp_addextendedproperty 'MS_Description', N'报表标识', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer', 'COLUMN', + 'reportId' +go + +exec sp_addextendedproperty 'MS_Description', N'设备编号', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer', 'COLUMN', 'eqNo' +go + +exec sp_addextendedproperty 'MS_Description', N'批次号', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer', 'COLUMN', 'batch' +go + +exec sp_addextendedproperty 'MS_Description', N'物料代码', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer', 'COLUMN', + 'matCode' +go + +exec sp_addextendedproperty 'MS_Description', N'设定重量', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer', 'COLUMN', + 'setValue' +go + +exec sp_addextendedproperty 'MS_Description', N'设定公差', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer', 'COLUMN', + 'setToler' +go + +exec sp_addextendedproperty 'MS_Description', N'实际重量', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer', 'COLUMN', + 'actValue' +go + +exec sp_addextendedproperty 'MS_Description', N'实际公差', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer', 'COLUMN', + 'actToLer' +go + +exec sp_addextendedproperty 'MS_Description', N'dos编号', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer', 'COLUMN', 'dos' +go + +exec sp_addextendedproperty 'MS_Description', N'记录时间', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer', 'COLUMN', + 'recordTime' +go + + + create table Report_DryMixer_Detail +( + objId int identity + primary key, + reportId varchar(36), + eqNo int, + mixBatch int, + mixStep int, + actCode int, + mixTime int, + mixTemp decimal(18, 4), + mixSpeed decimal(18, 4), + mix int, + recordTime datetime default getdate() +) +go + +exec sp_addextendedproperty 'MS_Description', N'主键标识', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer_Detail', 'COLUMN', + 'objId' +go + +exec sp_addextendedproperty 'MS_Description', N'报表标识', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer_Detail', 'COLUMN', + 'reportId' +go + +exec sp_addextendedproperty 'MS_Description', N'设备编号', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer_Detail', 'COLUMN', + 'eqNo' +go + +exec sp_addextendedproperty 'MS_Description', N'批次', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer_Detail', 'COLUMN', + 'mixBatch' +go + +exec sp_addextendedproperty 'MS_Description', N'步号', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer_Detail', 'COLUMN', + 'mixStep' +go + +exec sp_addextendedproperty 'MS_Description', N'动作', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer_Detail', 'COLUMN', + 'actCode' +go + +exec sp_addextendedproperty 'MS_Description', N'时间', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer_Detail', 'COLUMN', + 'mixTime' +go + +exec sp_addextendedproperty 'MS_Description', N'温度', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer_Detail', 'COLUMN', + 'mixTemp' +go + +exec sp_addextendedproperty 'MS_Description', N'速度', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer_Detail', 'COLUMN', + 'mixSpeed' +go + +exec sp_addextendedproperty 'MS_Description', N'mix编号', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer_Detail', 'COLUMN', + 'mix' +go + +exec sp_addextendedproperty 'MS_Description', N'记录时间', 'SCHEMA', 'dbo', 'TABLE', 'Report_DryMixer_Detail', 'COLUMN', + 'recordTime' +go*/ } }