You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/ReportSaveHelper.cs

209 lines
12 KiB
C#

This file contains ambiguous Unicode characters!

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

using DevExpress.DataAccess.Native.Json;
using DevExpress.XtraPrinting.Native.WebClientUIControl;
using Mesnac.Action.ChemicalWeighing.Entity.Report;
using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
{
public class ReportSaveHelper
{
/// <summary>
/// 干混机报表数据保存
/// </summary>
public static void SaveDryMixerReport()
{
try
{
ICSharpCode.Core.LoggingService<GHFinshBatchHelper>.Debug("干混机报表数据保存开始!!!");
//准备信号读取
#region 注释代码 读取复杂
//if (BasePlcHelper.Instance.RdyRpt_D1.NowValue.ToInt() == 1)
//{
// Report_DryMixer _dryMixer = new Report_DryMixer();
// _dryMixer.eqNo = BasePlcHelper.Instance.dryerA_dos0_eqNo.NowValue.ToInt();
// _dryMixer.batch = BasePlcHelper.Instance.dryerA_dos0_batch.NowValue.ToInt();
// _dryMixer.matCode = BasePlcHelper.Instance.dryerA_dos0_matCode.NowValue.ToInt();
// _dryMixer.setValue = BasePlcHelper.Instance.dryerA_dos0_setValue.NowValue.ToString();
// _dryMixer.setToler = BasePlcHelper.Instance.dryerA_dos0_setToler.NowValue.ToString();
// _dryMixer.actValue = BasePlcHelper.Instance.dryerA_dos0_actValue.NowValue.ToString();
// _dryMixer.actToLer = BasePlcHelper.Instance.dryerA_dos0_actToLer.NowValue.ToString();
// _dryMixer.dos = "0";
// _dryMixer.recordTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
//}
//else if (BasePlcHelper.Instance.RdyRpt_D2.NowValue.ToInt() == 1)
//{
// Report_DryMixer _dryMixer = new Report_DryMixer();
// _dryMixer.eqNo = BasePlcHelper.Instance.dryerA_dos1_eqNo.NowValue.ToInt();
// _dryMixer.batch = BasePlcHelper.Instance.dryerA_dos1_batch.NowValue.ToInt();
// _dryMixer.matCode = BasePlcHelper.Instance.dryerA_dos1_matCode.NowValue.ToInt();
// _dryMixer.setValue = BasePlcHelper.Instance.dryerA_dos1_setValue.NowValue.ToString();
// _dryMixer.setToler = BasePlcHelper.Instance.dryerA_dos1_setToler.NowValue.ToString();
// _dryMixer.actValue = BasePlcHelper.Instance.dryerA_dos1_actValue.NowValue.ToString();
// _dryMixer.actToLer = BasePlcHelper.Instance.dryerA_dos1_actToLer.NowValue.ToString();
// _dryMixer.dos = "1";
// _dryMixer.recordTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
//}
//else if (BasePlcHelper.Instance.RdyRpt_D3.NowValue.ToInt() == 1)
//{
// Report_DryMixer _dryMixer = new Report_DryMixer();
// _dryMixer.eqNo = BasePlcHelper.Instance.dryerA_dos2_eqNo.NowValue.ToInt();
// _dryMixer.batch = BasePlcHelper.Instance.dryerA_dos2_batch.NowValue.ToInt();
// _dryMixer.matCode = BasePlcHelper.Instance.dryerA_dos2_matCode.NowValue.ToInt();
// _dryMixer.setValue = BasePlcHelper.Instance.dryerA_dos2_setValue.NowValue.ToString();
// _dryMixer.setToler = BasePlcHelper.Instance.dryerA_dos2_setToler.NowValue.ToString();
// _dryMixer.actValue = BasePlcHelper.Instance.dryerA_dos2_actValue.NowValue.ToString();
// _dryMixer.actToLer = BasePlcHelper.Instance.dryerA_dos2_actToLer.NowValue.ToString();
// _dryMixer.dos = "2";
// _dryMixer.recordTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
//}
//else if (BasePlcHelper.Instance.RdyRpt_D4.NowValue.ToInt() == 1)
//{
// Report_DryMixer _dryMixer = new Report_DryMixer();
// _dryMixer.eqNo = BasePlcHelper.Instance.dryerA_dos3_eqNo.NowValue.ToInt();
// _dryMixer.batch = BasePlcHelper.Instance.dryerA_dos3_batch.NowValue.ToInt();
// _dryMixer.matCode = BasePlcHelper.Instance.dryerA_dos3_matCode.NowValue.ToInt();
// _dryMixer.setValue = BasePlcHelper.Instance.dryerA_dos3_setValue.NowValue.ToString();
// _dryMixer.setToler = BasePlcHelper.Instance.dryerA_dos3_setToler.NowValue.ToString();
// _dryMixer.actValue = BasePlcHelper.Instance.dryerA_dos3_actValue.NowValue.ToString();
// _dryMixer.actToLer = BasePlcHelper.Instance.dryerA_dos3_actToLer.NowValue.ToString();
// _dryMixer.dos = "3";
// _dryMixer.recordTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
//}
#endregion
//if (BasePlcHelper.Instance.RdyRpt_D1.NowValue.ToInt() == 1)
//{
// Report_DryMixer dryMixer_dos0 = readDryMixer("A"); //读取报表数据
// SaveReportDb(dryMixer_dos0); //保存报表数据
//}
//else if (BasePlcHelper.Instance.RdyRpt_D1.NowValue.ToInt() == 2)
//{
// Report_DryMixer dryMixer_dos0 = readDryMixer("B"); //读取报表数据
// SaveReportDb(dryMixer_dos0); //保存报表数据
//}
//else if (BasePlcHelper.Instance.RdyRpt_D1.NowValue.ToInt() == 3)
//{
// Report_DryMixer dryMixer_dos0 = readDryMixer("C"); //读取报表数据
// SaveReportDb(dryMixer_dos0); //保存报表数据
//}
//else if (BasePlcHelper.Instance.RdyRpt_D1.NowValue.ToInt() == 4)
//{
// Report_DryMixer dryMixer_dos0 = readDryMixer("D"); //读取报表数据
// SaveReportDb(dryMixer_dos0); //保存报表数据
//}
Report_DryMixer dryMixer_dos0 = readDryMixer("A"); //读取报表数据
SaveReportDb(dryMixer_dos0); //保存报表数据
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<GHFinshBatchHelper>.Error(String.Format("干混机报表数据保存异常:{0}", ex.Message), ex);
}
}
/// <summary>
/// 通过PLC读取干混机报表数据
/// </summary>
/// <param name="machineType">干混机A、干混机B</param>
/// <param name="dos">操作步骤Dos[0]、Dos[1]、Dos[2]、Dos[3]</param>
/// <returns></returns>
private static Report_DryMixer readDryMixer( string machineType)
{
Report_DryMixer _dryMixer = null;
try
{
var s= BasePlcHelper.Instance.dryerA_dos0_eqNo.LastValue.ToInt();
_dryMixer = new Report_DryMixer();
List<DryMixerDos> dryMixerDoes = new List<DryMixerDos> ();
List<DryMixerMix> dryMixerMixes = new List<DryMixerMix> ();
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");
BasePlcHelper.Instance.dryer_setValue = new Entity.DataKeyValue($"dryer{machineType}_dos{dos}_setValue");
BasePlcHelper.Instance.dryer_setToler = new Entity.DataKeyValue($"dryer{machineType}_dos{dos}_setToler");
BasePlcHelper.Instance.dryer_actValue = new Entity.DataKeyValue($"dryer{machineType}_dos{dos}_actValue");
BasePlcHelper.Instance.dryer_actToLer = new Entity.DataKeyValue($"dryer{machineType}_dos{dos}_actToLer");
DryMixerDos dryMixerDos = new DryMixerDos()
{
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(),
dos = dos,
recordTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
};
// _dryMixer.dos = new List<DryMixerDos> { 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");
BasePlcHelper.Instance.dryer_mixTime = new Entity.DataKeyValue($"dryer{machineType}_mix{mix}_mixTime");
BasePlcHelper.Instance.dryer_mixTemp = new Entity.DataKeyValue($"dryer{machineType}_mix{mix}_mixTemp");
BasePlcHelper.Instance.dryer_mixSpeed = new Entity.DataKeyValue($"dryer{machineType}_mix{mix}_mixSpeed");
DryMixerMix dryMixerMix = new DryMixerMix()
{
eqNo = BasePlcHelper.Instance.dryer_eqNo.NowValue.ToInt(),
mixBatch = BasePlcHelper.Instance.dryer_mixBatch.NowValue.ToInt(),
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(),
mix = mix,
recordTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
};
dryMixerMixes.Add( dryMixerMix );
}
_dryMixer.dos = dryMixerDoes;
_dryMixer.mix = dryMixerMixes;
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<GHFinshBatchHelper>.Error(String.Format("通过PLC读取干混机报表数读取异常{0}", ex.Message), ex);
}
return _dryMixer;
}
/// <summary>
/// 保存报表数据至数据库
/// </summary>
/// <param name="_dryMixer"></param>
private static void SaveReportDb(Report_DryMixer _dryMixer)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
try
{
string str = serializer.Serialize(_dryMixer);
ICSharpCode.Core.LoggingService<GHFinshBatchHelper>.Warn($"报表数据打印:{str}");
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<GHFinshBatchHelper>.Error(String.Format("保存报表数据至数据库异常:{0}", ex.Message), ex);
}
}
}
}