修改产前检测,修改告警提醒

main
liulb@mesnac.com 1 year ago
parent 6efbcaf5cc
commit d1f9aaafc9

@ -625,14 +625,12 @@ namespace Mesnac.Action.ChemicalWeighing.Alarm
{
IFreeSql fsql = FreeHelper.Instance;
string sql = @"select * from Pmt_Alarm ";
//string sql = @"select * from Pmt_Alarm ";
List<Pmt_Alarm> list = fsql.Select<Pmt_Alarm>().WithSql(sql).ToList();
List<Pmt_Alarm> list = fsql.Select<Pmt_Alarm>().ToList();
if (list!=null&&list.Count() > 1)
{
// var affrows = Convert.ToInt32(fsql.Insert<Pmt_Alarm>(lrPlan).ExecuteIdentity());
foreach ( var item in list)
{
ReadAlarm(item);
@ -665,7 +663,7 @@ namespace Mesnac.Action.ChemicalWeighing.Alarm
}
else
{
//alarm.Alarm_ClearTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
//alarm.Alarm_ClearTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
//alarm.Alarm_Status = 1;
//_= _lrAlarmlogServices.UpdateAsync(alarm).Result;
}
@ -678,7 +676,16 @@ namespace Mesnac.Action.ChemicalWeighing.Alarm
{
alarm.Alarm_ClearTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
alarm.Alarm_Status = 0;
var affrows = Convert.ToInt32(fsql.Update<LR_Alarmlog>(alarm).ExecuteAffrows());
// var affrows = Convert.ToInt32(fsql.Update<LR_Alarmlog>(alarm).ExecuteAffrows());
int affrows = fsql.Update<LR_Alarmlog>().Set(a => new LR_Alarmlog
{
Alarm_ClearTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
Alarm_Status = 0
}).Where(d => d.Alarm_ID == item.Alarm_ID && d.Alarm_Status == 1).ExecuteAffrows();
Console.WriteLine($"更新预警信息:{alarm.Alarm_ID}");
}
}

@ -0,0 +1,321 @@
using HslCommunication.Profinet.Siemens;
using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Action.ChemicalWeighing.Entity.PptPlan;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesnac.Action.ChemicalWeighing.DBHelper
{
public class PlanDbHelper
{
#region 根据计划号获取当前正在执行的计划任务
/// <summary>
/// 根据计划号获取当前正在执行的计划任务
/// </summary>
/// <param name="planId"></param>
/// <param name="recipeId"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static List<Xl_DownLoadPlan> GetExecPlan(int serial)
{
try
{
SiemensS7Net plc = PlcConnect.Instance;
string strSql = string.Empty;
//处理任务取消,但是当前任务会在执行完当前物料称量结束后才能
if (GetPlanInfo().Count() > 0)
{
strSql = $@"select 0 Id,p.Dosing_Id,p.Plan_Id,p.Plan_Serial,p.Recipe_ID,p.Recipe_Name,p.Version,p.Plan_Num,p.Real_Num,p.Shift_Id,p.Shift_Class,p.Plan_State,p.Plan_StateText,p.Plan_TotalWeight,p.Plan_TotalError,
r.Total_Weight,r.Total_Error,m.Material_ID as MaterialID,m.Material_name,m.Bin_Serial as Station,m.Bin_Name as StationName,w.Set_Weight,w.Set_Error,p.IsRetransmission,p.Retransmission_Num,p.IsPrenatalTest,ISNULL(p.FlagNum,0) as FlagNum
from xl_plan p left join xl_recipe r on p.Recipe_ID=r.ID left join xl_weigh w on r.ID=w.Recipe_ID left join
(select b.Bin_Serial,b.Bin_Name,b.Bin_Code,b.Material_ID,m.Material_name from Pmt_Bin b left join xl_material m on m.ID=b.Material_ID) m on w.Bin_Serial=m.Bin_Serial
where p.Plan_State=3 ";
IFreeSql fsql = FreeHelper.Instance;
Console.WriteLine($"正在执行的计划:{strSql}");
var list = fsql.Select<Xl_DownLoadPlan>().WithSql(strSql).ToList();
Console.WriteLine($"正在执行的计划:{list.Count}");
return list;
}
else
{
if (plc.ReadInt16("DB104.DBX4.1").Content == 1)
{
strSql = @"select 0 Id,p.Dosing_Id,p.Plan_Id,p.Plan_Serial,p.Recipe_ID,p.Recipe_Name,p.Version,p.Plan_Num,p.Real_Num,p.Shift_Id,p.Shift_Class,p.Plan_State,p.Plan_StateText,p.Plan_TotalWeight,p.Plan_TotalError,
r.Total_Weight,r.Total_Error,m.Material_ID as MaterialID,m.Material_name,m.Bin_Serial as Station,m.Bin_Name as StationName,w.Set_Weight,w.Set_Error,p.IsRetransmission,p.Retransmission_Num,p.IsPrenatalTest,ISNULL(p.FlagNum,0) as FlagNum
from (select * from xl_plan where Plan_State=7 and Start_Date=(select Max(Start_Date) from xl_plan where Plan_State=7) ) p left join xl_recipe r on p.Recipe_ID=r.ID left join xl_weigh w on r.ID=w.Recipe_ID left join
(select b.Bin_Serial,b.Bin_Name,b.Bin_Code,b.Material_ID,m.Material_name from Pmt_Bin b left join xl_material m on m.ID=b.Material_ID) m on w.Bin_Serial=m.Bin_Serial";
IFreeSql fsql = FreeHelper.Instance;
Console.WriteLine($"正在执行的计划:{strSql}");
var list = fsql.Select<Xl_DownLoadPlan>().WithSql(strSql).ToList();
Console.WriteLine($"正在执行的计划:{list.Count}");
return list;
}
}
return null;
}
catch (Exception ex)
{
Console.WriteLine($"查询执行计划:{ex.Message}");
return null;
}
}
public static List<Xl_DownLoadPlan> GetPlanInfo()
{
try
{
string sql = @"select 0 Id,p.Dosing_Id,p.Plan_Id,p.Plan_Serial,p.Recipe_ID,p.Recipe_Name,p.Version,p.Plan_Num,p.Real_Num,p.Shift_Id,p.Shift_Class,p.Plan_State,p.Plan_StateText,p.Plan_TotalWeight,p.Plan_TotalError,
r.Total_Weight,r.Total_Error,m.Material_ID as MaterialID,m.Material_name,m.Bin_Serial as Station,m.Bin_Name as StationName,w.Set_Weight,w.Set_Error,p.IsRetransmission,p.Retransmission_Num,p.IsPrenatalTest,0 FlagNum
from xl_plan p left join xl_recipe r on p.Recipe_ID=r.ID left join xl_weigh w on r.ID=w.Recipe_ID left join
(select b.Bin_Serial,b.Bin_Name,b.Bin_Code,b.Material_ID,m.Material_name from Pmt_Bin b left join xl_material m on m.ID=b.Material_ID) m on w.Bin_Serial=m.Bin_Serial
where p.Plan_State=3 ";
IFreeSql fsql = FreeHelper.Instance;
Console.WriteLine($"验证正在执行的计划1");
var list = fsql.Select<Xl_DownLoadPlan>().WithSql(sql).ToList();
Console.WriteLine($"验证正在执行的计划:{list.Count}");
var planList = list.OrderBy(d => d.Plan_Serial);
return planList.ToList();
}
catch (Exception ex)
{
Console.WriteLine($"验证正在执行的计划:{ex.Message}");
return null;
}
}
#endregion
#region 获取LR_plan
/// <summary>
/// 获取LR_plan
/// </summary>
/// <param name="planID">计划号</param>
/// <returns>返回符合条件List<LR_weigh></returns>
public static LR_plan GetLrPlan(string planID, int realNum, int flagNum)
{
try
{
string strSql = "SELECT * FROM LR_plan where Plan_Id = @Plan_Id and Real_Num=@Real_Num and FlagNum=@flagNum";
IFreeSql fsql = FreeHelper.Instance;
LR_plan list = fsql.Select<LR_plan>().WithSql(strSql, new { Plan_Id = planID, Real_Num = realNum, flagNum = flagNum }).ToOne();
return list;
}
catch (Exception ex)
{
Console.WriteLine($"查询LR_plan表数据失败:{ex.Message}");
return null;
}
}
#endregion
#region 产前检测——更新计划完成数量
/// <summary>
/// 更新计划完成数量
/// </summary>
/// <param name="planId">计划号</param>
/// <param name="quantity">完成数量</param>
/// <returns></returns>
public static bool UpdateCheckPlanCompletedQuantity(Xl_DownLoadPlan dp, int tcheckBatch, int state, DateTime endTime, double totalWeight)
{
try
{
IFreeSql fsql = FreeHelper.Instance;
int result = fsql.Update<xl_plan>().Set(a => new xl_plan
{
Real_Num = tcheckBatch,
Plan_TotalWeight = totalWeight,
Plan_State = state,
Plan_StateText = StateToShow(state),
End_Date = endTime.ToString("yyyy-MM-dd HH:mm:ss")
}).Where(a => a.Plan_Id == dp.Plan_Id).ExecuteAffrows();
if (result > 0) return true;
else return false;
}
catch (Exception ex)
{
Console.WriteLine($"产前检测更新xl_plan数据失败:{ex.Message}");
return false;
}
}
#endregion
#region 将计划运行状态转换为文字进行显示
/// <summary>
/// 将计划运行状态转换为文字进行显示
/// </summary>
/// <param name="stateNum">计划状态代码</param>
/// <returns>显示的文字信息</returns>
public static string StateToShow(int stateNum)
{
string reStr = null;
if (stateNum == 3)
{
reStr = "正在运行";
}
else if (stateNum == 4)
{
reStr = "已下传";
}
else if (stateNum == 5)
{
reStr = "未启动";
}
else if (stateNum == 7)
{
reStr = "已终止";
}
else if (stateNum == 8)
{
reStr = "已完成";
}
return reStr;
}
#endregion
#region 根据ID获取料仓
/// <summary>
/// 获取所有物料对象集合
/// </summary>
/// <returns></returns>
public static Pmt_Bin GetFristBinInfo(int Id)
{
IFreeSql fsql = FreeHelper.Instance;
Pmt_Bin bin = fsql.Select<Pmt_Bin>().Where(d => d.Bin_Serial == Id).ToOne();
return bin;
}
#endregion
#region 更新计划详情
public static bool UpdatePlanDetail(Xl_DownLoadPlan item, LR_plan lrPlan, LR_weigh lrWeigh, Pmt_Bin bin, Hw_BinAlarm alarm, int key)
{
try
{
IFreeSql fsql = FreeHelper.Instance;
if (item.IsPrenatalTest == 1)
{
if (key == 1)
{
fsql.Transaction(() =>
{
var affrows = fsql.Insert<LR_plan>(lrPlan).ExecuteAffrows();
//判断是否插入成功
if (affrows < 1)
throw new Exception("存盘计划详细数据失败!"); //抛出异常,回滚事务,事务退出
affrows = fsql.Insert<LR_weigh>(lrWeigh).ExecuteAffrows();
if (affrows < 1)
throw new Exception("存盘详细数据失败!");//抛出异常,回滚事务,事务退出
});
}
else
{
fsql.Transaction(() =>
{
var affrows = fsql.Insert<LR_plan>(lrPlan).ExecuteAffrows();
//判断是否插入成功
if (affrows < 1)
throw new Exception("存盘计划详细数据失败!"); //抛出异常,回滚事务,事务退出
lrWeigh.MainId = affrows;
affrows = fsql.Insert<LR_weigh>(lrWeigh).ExecuteAffrows();
if (affrows < 1)
throw new Exception("存盘详细数据失败!");//抛出异常,回滚事务,事务退出
});
}
}
else
{
if (key == 1)
{
fsql.Transaction(() =>
{
var affrows = Convert.ToInt32(fsql.Insert<LR_plan>(lrPlan).ExecuteIdentity());
//判断是否插入成功
if (affrows < 1)
throw new Exception("存盘计划详细数据失败!"); //抛出异常,回滚事务,事务退出
lrWeigh.MainId = affrows;
affrows = fsql.Insert<LR_weigh>(lrWeigh).ExecuteAffrows();
if (affrows < 1)
throw new Exception("存盘详细数据失败!");//抛出异常,回滚事务,事务退出
affrows = fsql.Update<Pmt_Bin>(bin.Bin_Serial).Set(a => a.BinWeight, bin.BinWeight).ExecuteAffrows();
if (affrows < 1)
throw new Exception("保存库存实时数据失败!");//抛出异常,回滚事务,事务退出
affrows = fsql.Insert<Hw_BinAlarm>(alarm).ExecuteAffrows();
if (affrows < 1)
throw new Exception("物料出库存盘数据失败!");//抛出异常,回滚事务,事务退出
});
}
else
{
fsql.Transaction(() =>
{
var affrows = fsql.Insert<LR_weigh>(lrWeigh).ExecuteAffrows();
if (affrows < 1)
throw new Exception("存盘详细数据失败!");//抛出异常,回滚事务,事务退出
bin.Equip_Code = "00";
affrows = fsql.Update<Pmt_Bin>(bin.Bin_Serial).Set(a => a.BinWeight, bin.BinWeight).ExecuteAffrows();
if (affrows < 1)
throw new Exception("保存库存实时数据失败!");//抛出异常,回滚事务,事务退出
affrows = fsql.Insert<Hw_BinAlarm>(alarm).ExecuteAffrows();
if (affrows < 1)
throw new Exception("物料出库存盘数据失败!");//抛出异常,回滚事务,事务退出
});
}
}
return true;
}
catch (Exception ex)
{
return false;
}
}
#endregion
#region 保存执行计划
public static bool UpdateCheckLrPlanCompletedQuantity(Xl_DownLoadPlan dp, int tcheckBatch, int state, DateTime endTime, double totalWeight, int flagNum)
{
try
{
IFreeSql fsql = FreeHelper.Instance;
int result = fsql.Update<LR_plan>().Set(a => new LR_plan
{
Real_Num = tcheckBatch,
Total_Weight = decimal.Parse(totalWeight.ToString()),
Plan_State = state,
End_Date = endTime.ToString("yyyy-MM-dd HH:mm:ss")
}).Where(a => a.Plan_Id == dp.Plan_Id && a.FlagNum == flagNum).ExecuteAffrows();
if (result > 0) return true;
else return false;
}
catch (Exception)
{
return false;
}
}
#endregion
}
}

@ -0,0 +1,43 @@
using HslCommunication.Profinet.Siemens;
using System;
namespace Mesnac.Action.ChemicalWeighing
{
public class PlcConnect
{
private static readonly Lazy<SiemensS7Net> lazy = new Lazy<SiemensS7Net>(() => new PlcConnect().SiemensS7NetConnection());
public static SiemensS7Net Instance => lazy.Value;
private PlcConnect()
{
}
public SiemensS7Net SiemensS7NetConnection()
{
SiemensPLCS siemensPLCS = SiemensPLCS.S1500;
SiemensS7Net s7 = new SiemensS7Net(siemensPLCS);
//配料IP
s7.IpAddress = "192.168.10.100";
s7.Port = 102;
var su = s7.ConnectServer();
if (!su.IsSuccess)
{
s7.IpAddress = "192.168.10.100";
s7.Port = 102;
var su1 = s7.ConnectServer();
if (!su1.IsSuccess)
{
return new SiemensS7Net(siemensPLCS);
}
}
return s7;
}
}
}

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesnac.Action.ChemicalWeighing.DBHelper
{
public class Xl_DownLoadPlan
{
public int Id { get; set; }
public string Dosing_Id { get; set; }
public string Plan_Id { get; set; }
public int Plan_Serial { get; set; }
public string Recipe_ID { get; set; }
public string Recipe_Name { get; set; }
public int Version { get; set; }
public int Plan_Num { get; set; }
public int Real_Num { get; set; }
public int Shift_Id { get; set; }
public string Shift_Class { get; set; }
public int Plan_State { get; set; }
public string Plan_StateText { get; set; }
/// <summary>
/// 计划实际执行重量总计
/// </summary>
public double Plan_TotalWeight { get; set; }
/// <summary>
/// 计划实际执行误差总计
/// </summary>
public double Plan_TotalError { get; set; }
/// <summary>
/// 配方总重量
/// </summary>
public double Total_Weight { get; set; }
/// <summary>
/// 配方总误差
/// </summary>
public double Total_Error { get; set; }
public string MaterialID { get; set; }
public string Material_name { get; set; }
/// <summary>
/// 工位编码
/// </summary>
public int Station { get; set; }
/// <summary>
/// 工位名称
/// </summary>
public string StationName { get; set; }
/// <summary>
/// 物料设置重量
/// </summary>
public decimal Set_Error { get; set; }
/// <summary>
/// 物料设置误差
/// </summary>
public decimal Set_Weight { get; set; }
/// <summary>
/// 是否重传
/// </summary>
public int IsRetransmission { get; set; }
/// <summary>
/// 重传次数
/// </summary>
public int Retransmission_Num { get; set; }
/// <summary>
/// 是否产前检查
/// </summary>
public int IsPrenatalTest { get; set; }
/// <summary>
/// 是否产前检查执行计数
/// </summary>
public int FlagNum { get; set; }
}
}

@ -1,17 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using ICSharpCode.Core;
using Mesnac.Equips;
using Mesnac.Codd.Session;
using Mesnac.Controls.Base;
using Mesnac.Action.ChemicalWeighing.DBHelper;
using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Action.ChemicalWeighing.Product.PptPlan;
using Mesnac.Action.ChemicalWeighing.Alarm;
using System.Timers;
using HslCommunication.Profinet.Siemens;
using Mesnac.Action.ChemicalWeighing.Services;
namespace Mesnac.Action.ChemicalWeighing.FinishBatch
{
@ -26,7 +16,7 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch
/// 运行状态true:已运行false未运行
/// </summary>
private bool runState = false;
private bool flag = true;
#endregion
#region 单例实现
@ -35,7 +25,11 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch
private FinishBatchService()
{
System.Timers.Timer timer = new System.Timers.Timer(1000);
timer.Elapsed += new ElapsedEventHandler(ReadData);
timer.AutoReset = true;
timer.Enabled = true;
timer.Start();
}
public static FinishBatchService Instance
@ -68,12 +62,12 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch
lock (String.Empty)
{
//BasePlcHelper.Instance.PlcRead(BasePlcHelper.Instance.read_data, out int[] p);
Mesnac.Equips.Factory.Instance.SetMinHZReadDataEvent(ReadData);
Mesnac.Equips.Factory.Instance.SetMinHZReadDataEvent(UpdateAlarmData);
//Mesnac.Equips.Factory.Instance.SetMinHZReadDataEvent(ReadData);
//Mesnac.Equips.Factory.Instance.SetMinHZReadDataEvent(UpdateAlarmData);
this.runState = true;
}
}
catch(Exception ex)
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<FinishBatchService>.Error("自动更新计划状态服务异常:" + ex.Message, ex);
}
@ -114,63 +108,51 @@ namespace Mesnac.Action.ChemicalWeighing.FinishBatch
{
try
{
lock(String.Empty)
lock (String.Empty)
{
#region 实时刷新自动保存报警
SaveHelper.AlarmSaveHelper.Save();
// SaveHelper.AlarmSaveHelper.Save();
#endregion
#region 更新小料计划状态
//XlPlcHelper.PlcPlanHelper.ExecPlanState();
XlPlcHelper.PlcPlanHelper.ExecPlanState();
#endregion
}
}
catch(Exception ex)
{
ICSharpCode.Core.LoggingService<FinishBatchService>.Error(ex.Message, ex);
}
}
private void UpdateAlarmData2(object sender, Mesnac.Equips.ReadEventArgs e)
{
try
{
lock (String.Empty)
{
#region 更新计划状态
XlPlcHelper.PlcPlanHelper.UpdateXlPlanStateFromPlc();
XlPlcHelper.PlcPlanHelper.UpdateBinAlarm();
#endregion
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<FinishBatchService>.Error(ex.Message, ex);
}
}
#endregion
private void UpdateAlarmData(object sender, Mesnac.Equips.ReadEventArgs e)
private void ReadData(object sender, ElapsedEventArgs e)
{
try
if (flag)
{
lock (String.Empty)
flag = false;
try
{
#region 更新计划状态
AlarmHelper.QueryUpdateAlarm();
#endregion
PlanHelperServer.SavePlcData();
}
catch (Exception ex)
{
Console.WriteLine($"FinishBatchService异常:{ex.Message}");
ICSharpCode.Core.LoggingService<FinishBatchService>.Error(ex.Message, ex);
}
finally
{
GC.Collect();
flag = true;
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<FinishBatchService>.Error(ex.Message, ex);
}
}
}
}

@ -130,6 +130,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\dll\FreeSql.Repository.dll</HintPath>
</Reference>
<Reference Include="HslCommunication">
<HintPath>E:\普力通处理\dll\HslCommunication.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.Core, Version=4.3.0.9338, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\PlugInPlatform\ICSharpCode.Core.dll</HintPath>
@ -269,6 +272,9 @@
<Compile Include="CylinderManage\InsertAction.cs" />
<Compile Include="CylinderManage\RefreshAction.cs" />
<Compile Include="DBHelper\FreeHelper.cs" />
<Compile Include="DBHelper\PlanDbHelper.cs" />
<Compile Include="DBHelper\PlcConnect.cs" />
<Compile Include="DBHelper\Xl_DownLoadPlan.cs" />
<Compile Include="DeviceParamManage\InitDeviceParamInfo.cs" />
<Compile Include="DeviceParamManage\SelectDeviceParamInfo.cs" />
<Compile Include="DeviceParamManage\WriteDeviceParamInfo.cs" />
@ -412,6 +418,7 @@
<Compile Include="Report\SolventReport\SelectPlanTotalAction.cs" />
<Compile Include="Report\SolventReport\SelectRowAction.cs" />
<Compile Include="Report\XlDbHelper.cs" />
<Compile Include="Services\PlanHelperServer.cs" />
<Compile Include="Show\InitFormAction.cs" />
<Compile Include="Show\XlInitAction.cs" />
<Compile Include="SmallMaterial\Parameter\DeleteMaterialAction.cs" />

@ -2927,7 +2927,6 @@ namespace Mesnac.Action.ChemicalWeighing.Product.XlPlan
{
if (BasePlcHelper.Instance.plt_plc_SystemRunning.NowValue.ToInt() == 1)
{
strSql = @"select p.Dosing_Id,p.Plan_Id,p.Plan_Serial,p.Recipe_ID,p.Recipe_Name,p.Version,p.Plan_Num,p.Real_Num,p.Shift_Id,p.Shift_Class,p.Plan_State,p.Plan_StateText,p.Plan_TotalWeight,p.Plan_TotalError,
r.Total_Weight,r.Total_Error,m.Material_ID as MaterialID,m.Material_name,m.Bin_Serial as Station,m.Bin_Name as StationName,w.Set_Weight,w.Set_Error,p.IsRetransmission,p.Retransmission_Num,p.IsPrenatalTest,ISNULL(p.FlagNum,0) as FlagNum
from (select * from xl_plan where Plan_State=7 and Start_Date=(select Max(Start_Date) from xl_plan where Plan_State=7) ) p left join xl_recipe r on p.Recipe_ID=r.ID left join xl_weigh w on r.ID=w.Recipe_ID left join

@ -0,0 +1,866 @@
using HslCommunication.Profinet.Siemens;
using Mesnac.Action.ChemicalWeighing.DBHelper;
using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Action.ChemicalWeighing.Entity.PptPlan;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesnac.Action.ChemicalWeighing.Services
{
public class PlanHelperServer
{
#region 更新任务状态
/// <summary>
/// 更新任务状态
/// </summary>
/// <returns></returns>
public static void ExecPlanState()
{
bool result = true;
#region 获取当前计划号,判断当前计划状态
//读取配方编码获取配方物料所在的工位,根据工位查询状态
//当PLC状态未"1" PLC准备好 上位机读取数据
//存盘完成后上位机需要将PLC点位置为2
//点位DBW0 设定PLC需要执行次数点位DBW212 为计量秤称量批次,可以此判断计划是否完成
if (result)
{
result = false;
try
{
}
catch (Exception ex)
{
Console.WriteLine($"执行称量任务异常:{ex.Message}");
}
finally { result = true; }
}
#endregion
}
#endregion
#region 保存数据
/// <summary>
/// 保存数据 PLC点位信息
/// </summary>
/// <param name="listMaterial">计划列表</param>
/// <returns>是否设置成功</returns>
public static void SavePlcData()
{
try
{
SiemensS7Net plc = PlcConnect.Instance;
int plt_Set_Plan_Serial = plc.ReadInt16("DB114.DBW126").Content;//执行序号 Plan_Serial
List<Xl_DownLoadPlan> materialList = PlanDbHelper.GetExecPlan(plt_Set_Plan_Serial);//正在执行的任务
if (materialList == null || materialList.Count == 0) { return; }
materialList.OrderBy(d => d.Station);
foreach (var item in materialList)
{
switch (item.Station)
{
case 1:
if (plc.ReadInt16("DB110.DBW0").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW152").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW150").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW0", short.Parse("2"));
Console.WriteLine("1工位存盘成功上位机完成置为2");
}
}
break;
case 2:
if (plc.ReadInt16("DB110.DBW2").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW152").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW150").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW2", short.Parse("2"));
Console.WriteLine("2工位存盘成功上位机完成置为2");
}
}
break;
case 3:
if (plc.ReadInt16("DB110.DBW6").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW156").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW154").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW6", short.Parse("2"));
Console.WriteLine("3工位存盘成功上位机完成置为2");
}
}
break;
case 4:
if (plc.ReadInt16("DB110.DBW8").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW156").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW156").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW8", short.Parse("2"));
Console.WriteLine("4工位存盘成功上位机完成置为2");
}
}
break;
case 5:
if (plc.ReadInt16("DB110.DBW12").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW160").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW158").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW12", short.Parse("2"));
Console.WriteLine("5工位存盘成功上位机完成置为2");
}
}
break;
case 6:
if (plc.ReadInt16("DB110.DBW14").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW160").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW158").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW14", short.Parse("2"));
Console.WriteLine("6工位存盘成功上位机完成置为2");
}
}
break;
case 7:
if (plc.ReadInt16("DB110.DBW18").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW164").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW162").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW18", short.Parse("2"));
Console.WriteLine("7工位存盘成功上位机完成置为2");
}
}
break;
case 8:
if (plc.ReadInt16("DB110.DBW20").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW164").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW162").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW20", short.Parse("2"));
Console.WriteLine("8工位存盘成功上位机完成置为2");
}
}
break;
case 9:
if (plc.ReadInt16("DB110.DBW24").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW168").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW166").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW24", short.Parse("2"));
Console.WriteLine("9工位存盘成功上位机完成置为2");
}
}
break;
case 10:
if (plc.ReadInt16("DB110.DBW26").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW168").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW166").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW26", short.Parse("2"));
Console.WriteLine("10工位存盘成功上位机完成置为2");
}
}
break;
case 11:
if (plc.ReadInt16("DB110.DBW30").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW172").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW170").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW30", short.Parse("2"));
Console.WriteLine("11工位存盘成功上位机完成置为2");
}
}
break;
case 12:
if (plc.ReadInt16("DB110.DBW32").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW172").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW170").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW32", short.Parse("2"));
Console.WriteLine("12工位存盘成功上位机完成置为2");
}
}
break;
case 13:
if (plc.ReadInt16("DB110.DBW36").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW176").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW174").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW36", short.Parse("2"));
Console.WriteLine("13工位存盘成功上位机完成置为2");
}
}
break;
case 14:
if (plc.ReadInt16("DB110.DBW38").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW176").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW174").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW38", short.Parse("2"));
Console.WriteLine("14工位存盘成功上位机完成置为2");
}
}
break;
case 15:
if (plc.ReadInt16("DB110.DBW42").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW180").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW178").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW42", short.Parse("2"));
Console.WriteLine("15工位存盘成功上位机完成置为2");
}
}
break;
case 16:
if (plc.ReadInt16("DB110.DBW44").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW180").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW178").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW44", short.Parse("2"));
Console.WriteLine("16工位存盘成功上位机完成置为2");
}
}
break;
case 17:
if (plc.ReadInt16("DB110.DBW48").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW184").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW182").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW48", short.Parse("2"));
Console.WriteLine("17工位存盘成功上位机完成置为2");
}
}
break;
case 18:
if (plc.ReadInt16("DB110.DBW50").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW184").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW182").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW50", short.Parse("2"));
Console.WriteLine("18工位存盘成功上位机完成置为2");
}
}
break;
case 19:
if (plc.ReadInt16("DB110.DBW54").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW188").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW186").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW54", short.Parse("2"));
Console.WriteLine("19工位存盘成功上位机完成置为2");
}
}
break;
case 20:
if (plc.ReadInt16("DB110.DBW56").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW188").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW186").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW56", short.Parse("2"));
Console.WriteLine("20工位存盘成功上位机完成置为2");
}
}
break;
case 21:
if (plc.ReadInt16("DB110.DBW60").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW192").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW190").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW60", short.Parse("2"));
Console.WriteLine("21工位存盘成功上位机完成置为2");
}
}
break;
case 22:
if (plc.ReadInt16("DB110.DBW62").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW192").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW190").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW62", short.Parse("2"));
Console.WriteLine("22工位存盘成功上位机完成置为2");
}
}
break;
case 23:
if (plc.ReadInt16("DB110.DBW66").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW196").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW194").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW66", short.Parse("2"));
Console.WriteLine("23工位存盘成功上位机完成置为2");
}
}
break;
case 24:
if (plc.ReadInt16("DB110.DBW68").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW196").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW194").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW68", short.Parse("2"));
Console.WriteLine("24工位存盘成功上位机完成置为2");
}
}
break;
case 25:
if (plc.ReadInt16("DB110.DBW72").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW200").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW198").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW72", short.Parse("2"));
Console.WriteLine("25工位存盘成功上位机完成置为2");
}
}
break;
case 26:
if (plc.ReadInt16("DB110.DBW74").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW200").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW198").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW74", short.Parse("2"));
Console.WriteLine("26工位存盘成功上位机完成置为2");
}
}
break;
case 27:
if (plc.ReadInt16("DB110.DBW78").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW204").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW202").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW78", short.Parse("2"));
Console.WriteLine("27工位存盘成功上位机完成置为2");
}
}
break;
case 28:
if (plc.ReadInt16("DB110.DBW80").Content == 1)//1工位A
{
int batch = plc.ReadInt16("DB110.DBW204").Content;//工位批次
Console.WriteLine($"工位批次:{batch}");
decimal real_Weight = Convert.ToDecimal(plc.ReadInt16("DB110.DBW202").Content) / 1000;//实际重量
Console.WriteLine($"实际重量:{real_Weight}");
bool result = SaveToData(item, batch, real_Weight);
Console.WriteLine($"保存结果{result}");
if (result)
{
//存盘成功上位机完成置为2
plc.Write("DB110.DBW80", short.Parse("2"));
Console.WriteLine("28工位存盘成功上位机完成置为2");
}
}
break;
default:
break;
}
}
//检量秤检查结束信息
Xl_DownLoadPlan down = materialList.FirstOrDefault();
if (down == null) return;
if (down.IsPrenatalTest == 1)
{
Console.WriteLine($"产前自检检量称:{plc.ReadInt16("DB110.DBW90").Content}");
if (plc.ReadInt16("DB110.DBW90").Content == 1)
{
double tcheckWeight = plc.ReadInt16("DB110.DBW210").Content / 1000;//检量秤重量
int tcheckBatch = plc.ReadInt16("DB110.DBW212").Content;//当前执行的批次
if (tcheckBatch == down.Plan_Num)
{
PlanDbHelper.UpdateCheckPlanCompletedQuantity(down, tcheckBatch, 8, DateTime.Now, tcheckWeight);
PlanDbHelper.UpdateCheckLrPlanCompletedQuantity(down, tcheckBatch, 8, DateTime.Now, tcheckWeight, down.FlagNum);
plc.Write("DB110.DBW90",short.Parse("2"));
}
}
}
}
catch (Exception ex)
{
Console.WriteLine($"执行保存工位称量数据异常:{ex.Message}");
}
}
#endregion
#region 存盘数据
public static bool SaveToData(Xl_DownLoadPlan item, int batch, decimal real_Weight)
{
try
{
decimal error = real_Weight - item.Set_Weight;
if (item.IsPrenatalTest == 1)
{
bool result = SaveCHeckData(item, batch, real_Weight, error);
return result;
}
return SavePlanInfo(item, batch, real_Weight, error);
}
catch (Exception)
{
return false;
}
}
#endregion
#region 保存产前检查数据
/// <summary>
/// 保存产前检查数据
/// </summary>
/// <param name="item"></param>
/// <param name="batch"></param>
/// <param name="real_Weight"></param>
/// <param name="error"></param>
/// <returns></returns>
public static bool SaveCHeckData(Xl_DownLoadPlan item, int batch, decimal real_Weight, decimal error)
{
LR_plan lrPlan = PlanDbHelper.GetLrPlan(item.Plan_Id, batch, item.FlagNum);
if (lrPlan != null)
{
//保存物料
LR_weigh weigh = new LR_weigh();
weigh.Dosing_ID = batch.ToString();
weigh.Plan_ID = item.Plan_Id;
weigh.Recipe_ID = item.Recipe_ID;
weigh.Bin_Serial = item.Station;
weigh.Material_ID = item.MaterialID;
weigh.Material_Name = item.Material_name;
weigh.Set_Weight = item.Set_Weight;
weigh.Set_Error = item.Set_Error;
weigh.Real_Weight = real_Weight;
weigh.Real_Error = error;
weigh.EndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
weigh.MainId = lrPlan.ID;
bool saveResult = SaveDataToBDb(item, weigh, lrPlan, null, null, 0);
if (saveResult) return true;
else return false;
}
else
{
//保存计划
LR_plan plan = new LR_plan();
plan.Plan_Id = item.Plan_Id;
plan.Plan_Serial = item.Plan_Serial;
plan.Recipe_ID = item.Recipe_ID;
plan.Recipe_Name = item.Recipe_Name;
plan.Version = item.Version;
plan.Plan_Num = item.Plan_Num;
plan.Real_Num = batch;
plan.Shift_Id = item.Shift_Id;
plan.Shift_Class = item.Shift_Class;
plan.Total_Weight = real_Weight;
plan.Total_Error = error;
plan.IsRetransmission = item.IsRetransmission;
plan.Retransmission_Num = item.Retransmission_Num;
plan.FlagNum = item.FlagNum;
//保存物料
LR_weigh weigh = new LR_weigh();
weigh.Dosing_ID = batch.ToString();
weigh.Plan_ID = item.Plan_Id;
weigh.Recipe_ID = item.Recipe_ID;
weigh.Bin_Serial = item.Station;
weigh.Material_ID = item.MaterialID;
weigh.Material_Name = item.Material_name;
weigh.Set_Weight = item.Set_Weight;
weigh.Set_Error = item.Set_Error;
weigh.Real_Weight = real_Weight;
weigh.Real_Error = error;
weigh.EndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
bool result = SaveDataToBDb(item, weigh, plan, null, null, 1);
if (result)
{
return true;
}
else
{
return false;
}
}
}
#endregion
#region 根据料仓号实时更新料仓物料重量
public static bool SaveDataToBDb(Xl_DownLoadPlan item, LR_weigh lrWeigh, LR_plan lrPlan, Pmt_Bin bin, Hw_BinAlarm alarm, int key)
{
try
{
IFreeSql fsql = FreeHelper.Instance;
{
if (item.IsPrenatalTest == 1)
{
if (key == 1)
{
fsql.Transaction(() =>
{
var affrows = Convert.ToInt32(fsql.Insert<LR_plan>(lrPlan).ExecuteIdentity());
if (affrows < 1)
{
throw new Exception("存盘计划详细数据失败!");//抛出异常,回滚事务,事务退出
}
lrWeigh.MainId = affrows;//获取主键
affrows = fsql.Insert<LR_weigh>(lrWeigh).ExecuteAffrows();
//判断是否插入成功
if (affrows < 1)
{
throw new Exception("存盘物料详细数据失败!"); //抛出异常,回滚事务,事务退出
}
});
}
else
{
fsql.Transaction(() =>
{
var affrows = fsql.Insert<LR_weigh>(lrWeigh).ExecuteAffrows();
if (affrows < 1)
throw new Exception("存盘物料详细数据失败!");//抛出异常,回滚事务,事务退出
});
}
}
else
{
if (key == 1)
{
fsql.Transaction(() =>
{
var affrows = Convert.ToInt32(fsql.Insert<LR_plan>(lrPlan).ExecuteIdentity());
if (affrows < 1)
throw new Exception("存盘计划详细数据失败!");//抛出异常,回滚事务,事务退出
affrows = fsql.Insert<LR_weigh>(lrWeigh).ExecuteAffrows();
//判断是否插入成功
if (affrows < 1)
throw new Exception("存盘物料详细数据失败!"); //抛出异常,回滚事务,事务退出
});
}
else
{
fsql.Transaction(() =>
{
var affrows = fsql.Insert<LR_weigh>(lrWeigh).ExecuteAffrows();
//判断是否插入成功
if (affrows < 1)
throw new Exception("存盘物料详细数据失败!"); //抛出异常,回滚事务,事务退出
affrows = fsql.Update<Pmt_Bin>(bin.Bin_Serial).Set(a => a.BinWeight, bin.BinWeight).ExecuteAffrows();
//判断是否插入成功
if (affrows < 1)
throw new Exception("存盘物料详细数据失败!"); //抛出异常,回滚事务,事务退出
});
}
}
return true;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return false;
}
}
#endregion
#region 保存非产前检查数据
/// <summary>
/// 保存非产前检查数据
/// </summary>
/// <param name="item"></param>
/// <param name="batch"></param>
/// <param name="real_Weight"></param>
/// <param name="error"></param>
/// <returns></returns>
private static bool SavePlanInfo(Xl_DownLoadPlan item, int batch, decimal real_Weight, decimal error)
{
try
{
LR_plan lrPlan = PlanDbHelper.GetLrPlan(item.Plan_Id, batch, item.FlagNum);
if (lrPlan != null)
{
decimal totalWeight = lrPlan.Total_Weight + real_Weight;
decimal totalError = lrPlan.Total_Error + error;
//保存物料
LR_weigh weigh = new LR_weigh();
weigh.Dosing_ID = batch.ToString();
weigh.Plan_ID = item.Plan_Id;
weigh.Recipe_ID = item.Recipe_ID;
weigh.Bin_Serial = item.Station;
weigh.Material_ID = item.MaterialID;
weigh.Material_Name = item.Material_name;
weigh.Set_Weight = item.Set_Weight;
weigh.Set_Error = item.Set_Error;
weigh.Real_Weight = real_Weight;
weigh.Real_Error = error;
weigh.MainId = lrPlan.ID;
weigh.EndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
lrPlan.Plan_Id = item.Plan_Id;
lrPlan.Real_Num = batch;
lrPlan.Total_Weight = totalWeight;
lrPlan.Total_Error = totalError;
var binInfo = PlanDbHelper.GetFristBinInfo(item.Station);
binInfo.BinWeight = binInfo.BinWeight - real_Weight;
Hw_BinAlarm alarm = new Hw_BinAlarm();
alarm.BinId = item.Station;
alarm.BinName = item.StationName;
alarm.MaterialCode = item.MaterialID;
alarm.MaterialName = item.Material_name;
alarm.Weights = real_Weight;
alarm.TypeName = "出库";
return PlanDbHelper.UpdatePlanDetail(item, lrPlan, weigh, binInfo, alarm, 0);
}
else
{
//保存计划
LR_plan plan = new LR_plan();
plan.Plan_Id = item.Plan_Id;
plan.Plan_Serial = item.Plan_Serial;
plan.Recipe_ID = item.Recipe_ID;
plan.Recipe_Name = item.Recipe_Name;
plan.Version = item.Version;
plan.Plan_Num = item.Plan_Num;
plan.Real_Num = batch;
plan.Shift_Id = item.Shift_Id;
plan.Shift_Class = item.Shift_Class;
plan.Total_Weight = real_Weight;
plan.Total_Error = error;
plan.IsRetransmission = item.IsRetransmission;
plan.Retransmission_Num = item.Retransmission_Num;
//保存物料
LR_weigh weigh = new LR_weigh();
weigh.Dosing_ID = batch.ToString();
weigh.Plan_ID = item.Plan_Id;
weigh.Recipe_ID = item.Recipe_ID;
weigh.Bin_Serial = item.Station;
weigh.Material_ID = item.MaterialID;
weigh.Material_Name = item.Material_name;
weigh.Set_Weight = item.Set_Weight;
weigh.Set_Error = item.Set_Error;
weigh.Real_Weight = real_Weight;
weigh.Real_Error = error;
weigh.EndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var binInfo = PlanDbHelper.GetFristBinInfo(item.Station);
binInfo.Equip_Code = "00";
binInfo.BinWeight = binInfo.BinWeight - real_Weight;
Hw_BinAlarm alarm = new Hw_BinAlarm();
alarm.BinId = binInfo.Bin_Serial;
alarm.BinName = binInfo.Bin_Name;
alarm.MaterialCode = binInfo.Material_ID;
alarm.MaterialName = item.Material_name;
alarm.Weights = real_Weight;
alarm.TypeName = "出库";
return PlanDbHelper.UpdatePlanDetail(item, plan, weigh, binInfo, alarm, 1);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
#endregion
}
}

@ -1,9 +1,11 @@
using DevExpress.Data.Filtering.Helpers;
using DevExpress.Office.Utils;
using Mesnac.Action.Base;
using Mesnac.Action.ChemicalWeighing.Alarm;
using Mesnac.Action.ChemicalWeighing.BinManage;
using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Action.ChemicalWeighing.Entity.PptPlan;
using Mesnac.Action.ChemicalWeighing.FinishBatch;
using Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper;
using Mesnac.Action.ChemicalWeighing.Product.XlPlan;
using Mesnac.Communication;
@ -12,6 +14,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@ -25,6 +28,7 @@ namespace Mesnac.Action.ChemicalWeighing.Show
{
#region 字段定义
bool flag = true;
bool alarm = true;
public static bool IsFirstRun = true; //是否首次运行
private RuntimeParameter _runtime;
//private DbMCControl _planDateControl = null; //计划日期
@ -113,6 +117,12 @@ namespace Mesnac.Action.ChemicalWeighing.Show
timer2.AutoReset = true;
timer2.Enabled = true;
timer2.Start();
System.Timers.Timer timer3 = new System.Timers.Timer(5000);
timer3.Elapsed += new ElapsedEventHandler(UpdateAlarmData);
timer3.AutoReset = true;
timer3.Enabled = true;
timer3.Start();
}
#region 方法定义
@ -166,9 +176,10 @@ namespace Mesnac.Action.ChemicalWeighing.Show
var labeTaskState = base.GetControlById("MCLabeTaskState") as System.Windows.Forms.Label;//任务状态
List<Xl_DowLoadPlan> materialList = PlanHelper.GetPlanList();//正在执行的任务
if (materialList == null&& materialList.Count()==0) { return; }
if (materialList == null|| materialList.Count()==0) { return; }
var item = materialList.FirstOrDefault();
if (!string.IsNullOrEmpty(planFlag))
{
if (item != null)
@ -185,7 +196,8 @@ namespace Mesnac.Action.ChemicalWeighing.Show
}
else
{
planFlag = item.Plan_Id;
if (item!=null) planFlag = item.Plan_Id;
}
if (item != null)
@ -220,8 +232,8 @@ namespace Mesnac.Action.ChemicalWeighing.Show
var data = PlanHelper.GetExecPlanDataTable();
if (data != null && data.Rows.Count > 0)
{
clientGridControl.BaseControl.BindDataSource = null;
((DataGridView)clientGridControl.BaseControl).AutoGenerateColumns = false;
clientGridControl.BaseControl.BindDataSource = data;
SetWeight(materialList);
}
@ -795,6 +807,37 @@ namespace Mesnac.Action.ChemicalWeighing.Show
}
private void UpdateAlarmData(object sender, ElapsedEventArgs e)
{
try
{
if (alarm)
{
try
{
alarm = false;
#region 更新计划状态
AlarmHelper.QueryUpdateAlarm();
}
catch (Exception ex)
{
Console.WriteLine($"异常:{ex.Message}");
}
finally
{
alarm = true;
}
#endregion
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<FinishBatchService>.Error(ex.Message, ex);
}
}
#region 设置(网格控件)计划状态背景色
/// <summary>
/// 设置计划状态背景色

@ -1,3 +1,3 @@
<DataSources>
<DataSourceItem Name="DataSource1" Driver="MS SQL Server" Server="localhost" UserName="sa" Password="sa" DataBase="cwss_xl" ConnectionTimeout="5" DriverAssembly="ICSharpCode.Data.SQLServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" DriverClass="ICSharpCode.Data.Core.DatabaseDrivers.SQLServer.SQLServerDatabaseDriver" DataSourceClass="ICSharpCode.Data.Core.DatabaseObjects.Database" />
<DataSourceItem Name="DataSource1" Driver="MS SQL Server" Server="192.168.10.50" UserName="sa" Password="sa" DataBase="cwss_xl" ConnectionTimeout="5" DriverAssembly="ICSharpCode.Data.SQLServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" DriverClass="ICSharpCode.Data.Core.DatabaseDrivers.SQLServer.SQLServerDatabaseDriver" DataSourceClass="ICSharpCode.Data.Core.DatabaseObjects.Database" />
</DataSources>

@ -7,7 +7,7 @@
<ReadHz value="1000" />
<UnitLen value="8" />
<Connection mode="Net">
<IP value="127.0.0.1" />
<IP value="192.168.10.100" />
<Rack value="0" />
<Slot value="0" />
</Connection>

@ -6,7 +6,7 @@
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{91C803A6-90D1-4361-8B92-9AFD9E766411}</ProjectGuid>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MCRun</RootNamespace>
<AssemblyName>MCRun</AssemblyName>
@ -96,6 +96,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Libraries\Host.dll</HintPath>
</Reference>
<Reference Include="HslCommunication">
<HintPath>E:\普力通处理\dll\HslCommunication.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.Core, Version=4.3.0.9338, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\PlugInPlatform\ICSharpCode.Core.dll</HintPath>

Loading…
Cancel
Save