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.

550 lines
22 KiB
C#

1 year ago
using DevExpress.Office.Drawing;
using DevExpress.Office.Utils;
10 months ago
using DevExpress.XtraEditors.Filtering.Templates;
10 months ago
using HslCommunication.Profinet.Siemens;
1 year ago
using Mesnac.Action.Base;
using Mesnac.Action.ChemicalWeighing.ChemicalWeighingPlc;
using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Action.ChemicalWeighing.Entity.PptPlan;
using Mesnac.Action.ChemicalWeighing.Entity.station;
using Mesnac.Action.ChemicalWeighing.Product.PptPlan;
10 months ago
using Mesnac.Controls.Default;
1 year ago
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
namespace Mesnac.Action.ChemicalWeighing.Show
{
public class InitFormAction : ChemicalWeighingAction, IAction
{
#region 字段定义
public static bool IsFirstRun = true; //是否首次运行
private RuntimeParameter _runtime;
//private DbMCControl _planDateControl = null; //计划日期
//private DbMCControl _pptShiftControl = null; //班次
private DbMCControl _clientGridControl = null; //本地计划控件
string planFlag= string.Empty;
10 months ago
string planFlag2 = string.Empty;
bool planFlag3 = true;
1 year ago
#endregion
10 months ago
System.Timers.Timer timer = new System.Timers.Timer(3000);
System.Timers.Timer timer2 = new System.Timers.Timer(3000);
1 year ago
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime);
#region 首次执行,进行事件订阅
if (IsFirstRun)
{
ICSharpCode.Core.LoggingService<XlInitAction>.Debug("小料展示界面-窗体初始化业务...");
}
#endregion
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pmt_weigh").FirstOrDefault(); //获取本机台计划控件
if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<InitFormAction>.Error("{首页展示}缺少本机台计划网格控件...");
return;
}
//StartServer1();
//StartServer2();
//InitData();
//1号地磅
10 months ago
1 year ago
timer.Elapsed += new ElapsedEventHandler(StartServer1);
timer.AutoReset = true;
timer.Enabled = true;
timer.Start();
1 year ago
10 months ago
////IsFirstRun = false;
//////2号地磅
1 year ago
timer2.Elapsed += new ElapsedEventHandler(StartServer2);
timer2.AutoReset = true;
timer2.Enabled = true;
timer2.Start();
//StartServer1();
//StartServer2();
1 year ago
#region 初始化
#region 获取界面控件
string source = string.Empty;
//DbMCControl planDateControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[xl_plan].[Plan_Date]").FirstOrDefault();
//DbMCControl pptShiftControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pmt_Shiftime").FirstOrDefault();
//DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "xl_plan").FirstOrDefault(); //获取本机台计划网格控件
//if (planDateControl == null)
//{
// ICSharpCode.Core.LoggingService<InitFormAction>.Error("{当班计划-窗体加载} 缺少日期选择控件...");
// return;
//}
//if (pptShiftControl == null)
//{
// ICSharpCode.Core.LoggingService<InitFormAction>.Error("{当班计划-窗体加载} 缺少班次组合框控件...");
// return;
//}
//if (clientGridControl == null)
//{
// ICSharpCode.Core.LoggingService<XlInitAction>.Error("{小料展示界面-窗体加载} 缺少计划列表网格控件...");
// return;
//}
//this._runtime = runtime;
//this._clientGridControl = clientGridControl;
#endregion
#region 初始化操作
//DataGridView clientGrid = (clientGridControl.BaseControl as DataGridView);
//this.InitGridViewEvent(clientGrid);
//this.InitData();
#endregion
#endregion
}
#region 方法定义
#region 网格事件处理方法
/// <summary>
/// 初始化网格样式
/// </summary>
/// <param name="dgv">DataGridView网格控件对象</param>
private void InitGridViewEvent(DataGridView dgv)
{
}
#endregion
#region 初始化界面控件数据
/// <summary>
/// 初始化界面控件数据
/// </summary>
private void InitData()
{
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pmt_weigh").FirstOrDefault(); //获取本机台计划控件
if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<InitFormAction>.Error("{首页展示}缺少本机台计划网格控件...");
return;
}
lock (String.Empty)
{
//本地计划
if (clientGridControl != null && clientGridControl.BaseControl != null)
{
//clientGridControl.BaseControl.BindDataSource = null;
//clientGridControl.BaseControl.BindDataSource = dt;
#region 根据计划状态处理背景色
DataGridView clientGrid = clientGridControl.BaseControl as DataGridView;
SetBackColor(clientGrid);
#endregion
}
else
{
ICSharpCode.Core.LoggingService<InitFormAction>.Warn("接在首页展示物料失败本地控件为Null...");
}
}
}
#endregion
#endregion
1 year ago
private void StartServer1(object sender, ElapsedEventArgs e)
1 year ago
{
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pmt_weigh").FirstOrDefault(); //获取本机台计划控件
if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<InitFormAction>.Error("{首页展示}缺少本机台计划网格控件...");
return;
}
10 months ago
if (true)
1 year ago
{
10 months ago
planFlag3 = false;
1 year ago
10 months ago
try
1 year ago
{
10 months ago
var lblPlanName = base.GetControlById("lblPlanName") as System.Windows.Forms.Label;//配方名称
if (lblPlanName == null)
{
timer.Stop();
timer.Close();
return;
}
var lblRecipeName = base.GetControlById("lblRecipeName") as System.Windows.Forms.Label;//配方名称
var lblTotalBatch = base.GetControlById("lblTotalBatch") as System.Windows.Forms.Label;//总批次
var lblMaterial = base.GetControlById("lblMaterial") as System.Windows.Forms.Label;//物料名称
var XProgressBar = base.GetControlById("XProgressBar") as System.Windows.Forms.ProgressBar;//进度条
var lblStandardWeight = base.GetControlById("lblStandardWeight") as System.Windows.Forms.Label;//标重
var lblStateMessage = base.GetControlById("lblStateMessage") as System.Windows.Forms.Label;//配方名称
var lblPlanStateMessage = base.GetControlById("lblPlanState") as System.Windows.Forms.Label;//计划状态
var rate = base.GetControlById("MCLabel2") as System.Windows.Forms.Label;//理论固含
DataTable table = PlanHelper.GetProPlan();//正在执行的任务
if (table == null)
{
lblStateMessage.Text = "状态信息";
lblMaterial.Text = "物料";
lblPlanName.Text = "计划号";
lblRecipeName.Text = "配方";
clientGridControl.BaseControl.BindDataSource = null;
return;
}
SiemensS7Net plc = PlcConnect.Instance;
int status01 = plc.ReadInt16("DB110.DBW1770").Content;
//int status01 = BasePlcHelper.Instance.solvent_status01.NowValue.ToInt();
if (status01 == 1)
{
lblStateMessage.Text = "请加料!";
}
int status02 = plc.ReadInt16("DB110.DBW1772").Content;
//int status02 = BasePlcHelper.Instance.solvent_status02.NowValue.ToInt();
if (status02 == 1)
{
lblStateMessage.Text = "超重";
}
int statusEnd = plc.ReadInt16("DB110.DBW1774").Content;
int runState = plc.ReadInt16("DB110.DBW1780").Content;
//int runState = BasePlcHelper.Instance.solvent_SystemRuning.NowValue.ToInt();
if (runState == 1 && status01 == 1&& statusEnd==0)
{
lblStateMessage.Text = "请加料!";
}
int status04 = plc.ReadInt16("DB110.DBW1776").Content;
//int status04 = BasePlcHelper.Instance.solvent_status04.NowValue.ToInt();
if (status04 == 1&& runState == 1)
{
lblStateMessage.Text = "请清空地磅,扫描之后放物料!";
}
if (status04 == 1 && runState == 0)
{
lblStateMessage.Text = "请清空地磅,扫描之后放物料!";
}
if (status04 == 0 && runState == 1 && status01 ==0)
{
lblStateMessage.Text = "请扫描拉缸条码,核对投料类型!";
}
if (runState == 0 && status01 == 0 && status04 == 0 && status02 == 0)
{
lblStateMessage.Text = "状态信息";
}
if (statusEnd ==1 )
{
lblStateMessage.Text = "完成";
}
List<MetagePlan> materialList = PlanHelper.DataTableToList(table);
if (materialList.Count == 0) { return; }
MetagePlan plan2 = null;
var matlCode = BasePlcHelper.Instance.solvent_materialNo.NowValue.ToInt();
if (matlCode == 0)
{
plan2 = materialList.FirstOrDefault(d => d.MID == 1);
}
else
{
plan2 = materialList.FirstOrDefault(d => d.MID == matlCode);
}
if (plan2 == null)
{
return;
}
var matSerial = plan2.MID;
MetagePlan plan = materialList.FirstOrDefault(d => d.MID == matSerial);
if (plan2 != null) { lblPlanStateMessage.Text = plan2.Plan_StateText; }
if (!string.IsNullOrEmpty(planFlag))
{
if (planFlag == plan.Plan_Id)
{
return;
}
else
{
planFlag = plan.Plan_Id;
}
}
else
{
planFlag = plan.Plan_Id;
}
if (plan != null)
{
lblPlanStateMessage.Text = plan2.Plan_StateText;
var p = materialList.FirstOrDefault();
lblPlanName.Text = p.Plan_Id;
lblRecipeName.Text = p.Recipe_Name;
lblMaterial.Text = plan.Material_name;//正在执行的物料号
lblStandardWeight.Text = plan.Total_Weight.ToString("f2");
rate.Text = plan.TheoryRate.ToString();
}
else
{
return;
}
lock (String.Empty)
{
//本地计划
if (clientGridControl != null && clientGridControl.BaseControl != null)
{
clientGridControl.BaseControl.BindDataSource = null;
clientGridControl.BaseControl.BindDataSource = table;
#region 根据计划状态处理背景色
DataGridView clientGrid = clientGridControl.BaseControl as DataGridView;
SetBackColor(clientGrid);
#endregion
}
else
{
ICSharpCode.Core.LoggingService<InitFormAction>.Warn("接在首页展示物料失败本地计划控件为Null...");
}
}
1 year ago
}
10 months ago
catch (Exception ex)
1 year ago
{
10 months ago
planFlag3 = true;
Console.WriteLine(ex.Message);
1 year ago
}
10 months ago
finally
1 year ago
{
10 months ago
planFlag3 = true;
1 year ago
}
}
}
10 months ago
private void StartServer2(object sender, ElapsedEventArgs e)
1 year ago
{
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "xl_weigh").FirstOrDefault(); //获取本机台计划控件
if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<InitFormAction>.Error("{首页展示}缺少本机台计划网格控件...");
return;
}
var lblPlanName = base.GetControlById("lblPlanName2") as System.Windows.Forms.Label;//计划名称
10 months ago
if (lblPlanName == null)
{
timer.Stop();
timer.Close();
return;
}
1 year ago
var lblRecipeName = base.GetControlById("lblRecipeName2") as System.Windows.Forms.Label;//配方名称
var lblTotalBatch = base.GetControlById("lblTotalBatch2") as System.Windows.Forms.Label;//总批次
var lblMaterial = base.GetControlById("lblMaterial2") as System.Windows.Forms.Label;//物料名称
var XProgressBar = base.GetControlById("XProgressBar2") as System.Windows.Forms.ProgressBar;//进度条
var lblStandardWeight = base.GetControlById("lblStandardWeight2") as System.Windows.Forms.Label;//标重
var lblStateMessage = base.GetControlById("lblStateMessage2") as System.Windows.Forms.Label;//配方名称
var lblPlanStateMessage = base.GetControlById("lblPlanState2") as System.Windows.Forms.Label;//计划状态
10 months ago
var rate = base.GetControlById("lblRate") as System.Windows.Forms.Label;//理论固含
1 year ago
DataTable table = PlanHelper.GetProWeighbridge2Plan();//正在执行的任务
if (table == null)
{
lblStateMessage.Text = "状态信息";
lblMaterial.Text = "物料";
lblPlanName.Text = "计划号";
lblRecipeName.Text = "配方";
clientGridControl.BaseControl.BindDataSource = null;
return;
}
10 months ago
10 months ago
SiemensS7Net plc = PlcConnect.Instance;
int status01 = plc.ReadInt16("DB111.DBW1770").Content;
//int status01 = BasePlcHelper.Instance.solvent_status01.NowValue.ToInt();
10 months ago
if (status01 == 1)
1 year ago
{
10 months ago
lblStateMessage.Text = "请加料!";
}
10 months ago
int status02 = plc.ReadInt16("DB111.DBW1772").Content;
//int status02 = BasePlcHelper.Instance.solvent_status02.NowValue.ToInt();
10 months ago
if (status02 == 1)
{
10 months ago
lblStateMessage.Text = "超重";
1 year ago
}
10 months ago
int statusEnd = plc.ReadInt16("DB111.DBW1774").Content;
int runState = plc.ReadInt16("DB111.DBW1780").Content;
//int runState = BasePlcHelper.Instance.solvent_SystemRuning.NowValue.ToInt();
if (runState == 1 && status01 == 1 && statusEnd == 0)
{
lblStateMessage.Text = "请加料!";
}
int status04 = plc.ReadInt16("DB111.DBW1776").Content;
//int status04 = BasePlcHelper.Instance.solvent_status04.NowValue.ToInt();
if (status04 == 1 && runState == 1)
1 year ago
{
lblStateMessage.Text = "请清空地磅,扫描之后放物料!";
}
10 months ago
if (status04 == 1 && runState == 0)
1 year ago
{
10 months ago
lblStateMessage.Text = "请清空地磅,扫描之后放物料!";
1 year ago
}
10 months ago
if (status04 == 0 && runState == 1 && status01 == 0)
1 year ago
{
10 months ago
lblStateMessage.Text = "请扫描拉缸条码,核对投料类型!";
1 year ago
}
10 months ago
if (runState == 0 && status01 == 0 && status04 == 0 && status02 == 0)
1 year ago
{
10 months ago
lblStateMessage.Text = "状态信息";
1 year ago
}
10 months ago
10 months ago
if (statusEnd == 1)
{
lblStateMessage.Text = "完成";
}
1 year ago
List<MetagePlan> materialList = PlanHelper.DataTableToList(table);
if (materialList.Count == 0) { return; }
1 year ago
MetagePlan plan2 = null;
var matlCode = BasePlcHelper.Instance.solvent2_materialNo.NowValue.ToInt();
if (matlCode == 0)
{
plan2 = materialList.FirstOrDefault(d => d.MID == 1);
}
else
{
plan2 = materialList.FirstOrDefault(d => d.MID == matlCode);
}
1 year ago
1 year ago
if (plan2 == null)
1 year ago
{
1 year ago
return;
1 year ago
}
1 year ago
if (!string.IsNullOrEmpty(planFlag))
{
if (planFlag == plan2.Plan_Id)
1 year ago
{
1 year ago
return;
1 year ago
}
else
{
1 year ago
planFlag = plan2.Plan_Id;
1 year ago
}
}
else
{
1 year ago
planFlag = plan2.Plan_Id;
1 year ago
}
10 months ago
if (plan2 != null)
{
var p = materialList.FirstOrDefault();
lblPlanName.Text = p.Plan_Id;
lblRecipeName.Text = p.Recipe_Name;
lblMaterial.Text = plan2.Material_name;//正在执行的物料号
lblStandardWeight.Text = plan2.Total_Weight.ToString("f2");
rate.Text = plan2.TheoryRate.ToString();
}
else
{
return;
}
1 year ago
lock (String.Empty)
{
//本地计划
if (clientGridControl != null && clientGridControl.BaseControl != null)
{
clientGridControl.BaseControl.BindDataSource = null;
clientGridControl.BaseControl.BindDataSource = table;
#region 根据计划状态处理背景色
DataGridView clientGrid = clientGridControl.BaseControl as DataGridView;
SetBackColor(clientGrid);
#endregion
}
else
{
ICSharpCode.Core.LoggingService<InitFormAction>.Warn("接在首页展示物料失败本地计划控件为Null...");
}
}
}
#region 设置(网格控件)计划状态背景色
/// <summary>
/// 设置计划状态背景色
/// </summary>
/// <param name="grid"></param>
public static void SetBackColor(DataGridView grid)
{
lock (String.Empty)
{
try
{
if (grid == null || grid.Visible == false)
{
ICSharpCode.Core.LoggingService.Warn("设置背景色失败网格控件为null或不可见");
return;
}
grid.ClearSelection(); //清空选中行
grid.ColumnHeadersHeight = 25;
grid.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
grid.RowHeadersVisible = false;
grid.RowTemplate.Height = 28;
grid.RowsDefaultCellStyle.Font = new System.Drawing.Font("宋体", 12, System.Drawing.FontStyle.Bold);
foreach (DataGridViewRow row in grid.Rows)
{
row.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(220, 220, 220); //灰色
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<InitFormAction>.Error("设置背景色失败:" + ex.Message);
}
}
}
#endregion
}
}