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.

826 lines
34 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.Data.Filtering.Helpers;
using DevExpress.Office.Utils;
using Mesnac.Action.Base;
using Mesnac.Action.ChemicalWeighing.BinManage;
using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Action.ChemicalWeighing.Entity.PptPlan;
using Mesnac.Action.ChemicalWeighing.Product.XlPlan;
using Mesnac.Communication;
using Mesnac.Controls.Default;
using System;
using System.Collections.Generic;
using System.ComponentModel;
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 XlInitAction : ChemicalWeighingAction, IAction
{
#region 字段定义
bool flag = true;
public static bool IsFirstRun = true; //是否首次运行
private RuntimeParameter _runtime;
//private DbMCControl _planDateControl = null; //计划日期
//private DbMCControl _pptShiftControl = null; //班次
private DbMCControl _clientGridControl = null; //本地计划控件
private static System.Threading.Timer timer;
string planFlag = string.Empty;//标识
#endregion
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, "xl_weigh").FirstOrDefault(); //获取本机台计划控件
if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<XlInitAction>.Error("{首页展示}缺少本机台计划网格控件...");
return;
}
#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
ServerStart();
//timer = new System.Threading.Timer(ServerStart, null, 5000, Timeout.Infinite);
}
#region 方法定义
#region 网格事件处理方法
/// <summary>
/// 初始化网格样式
/// </summary>
/// <param name="dgv">DataGridView网格控件对象</param>
private void InitGridViewEvent(DataGridView dgv)
{
}
#endregion
#region 初始化界面控件数据
/// <summary>
/// 初始化界面控件数据
/// </summary>
private void InitData()
{
}
#endregion
#endregion
private void ServerStart()//Object source
{
try
{
if (flag)
{
flag = false;
var lblRecipeName = base.GetControlById("lblRecipeName") as System.Windows.Forms.Label;//配方名称
if (lblRecipeName == null) { return; }
var lblStandardWeight = base.GetControlById("lblStandardWeight") as System.Windows.Forms.Label;//标重
//var lblActualWeight = base.GetControlById("lblActualWeight") as System.Windows.Forms.Label;//实际重量
var lblPlan = base.GetControlById("MCLabel4") as System.Windows.Forms.Label;//标重
//var lblSetError = base.GetControlById("lblActualWeight") as System.Windows.Forms.Label;//总误差
//var lblActualError = base.GetControlById("lblActualWeight") as System.Windows.Forms.Label;//实际误差
var lblTotalBatch = base.GetControlById("lblTotalBatch") as System.Windows.Forms.Label;//总批次
// var lblCurrentBatch = base.GetControlById("lblCurrentBatch") as System.Windows.Forms.Label;//当前批次
if (lblRecipeName == null) { return; }
var labeTaskState = base.GetControlById("MCLabeTaskState") as System.Windows.Forms.Label;//任务状态
List<Xl_DowLoadPlan> materialList = PlanHelper.GetPlanList();//正在执行的任务
if (materialList == null) { return; }
var item = materialList.FirstOrDefault();
if (!string.IsNullOrEmpty(planFlag))
{
if (item != null)
{
labeTaskState.Text = item.Plan_StateText;
if (planFlag == item.Plan_Id) return;
}
else
{
labeTaskState.Text = "状态";
}
}
if (item != null)
{
planFlag=item.Plan_Id;
lblTotalBatch.Text = item.Plan_Num.ToString();
lblPlan.Text = item.Plan_Id;
lblRecipeName.Text = item.Recipe_Name;
lblStandardWeight.Text = item.Total_Weight.ToString("f3");
}
else
{
lblTotalBatch.Text = "0";
lblPlan.Text = "计划号";
lblRecipeName.Text = "配方名";
lblStandardWeight.Text = "0";
}
#region 计划物料展示
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "xl_weigh").FirstOrDefault(); //获取本机台计划控件
if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<XlInitAction>.Error("{首页展示}缺少本机台计划网格控件...");
return;
}
lock (String.Empty)
{
//本地计划
if (clientGridControl != null && clientGridControl.BaseControl != null)
{
var data = PlanHelper.GetExecPlanDataTable();
if (data != null && data.Rows.Count > 0)
{
clientGridControl.BaseControl.BindDataSource = null;
clientGridControl.BaseControl.BindDataSource = data;
}
else
{
clientGridControl.BaseControl.BindDataSource = null;
}
#region 根据计划状态处理背景色
DataGridView clientGrid = clientGridControl.BaseControl as DataGridView;
SetBackColor(clientGrid);
#endregion
}
else
{
ICSharpCode.Core.LoggingService<XlInitAction>.Warn("接在首页展示物料失败本地控件为Null...");
}
}
#endregion
AlarmShow();
SetWeight(materialList);
///MaterialShow();
}
}
catch (Exception)
{
throw;
}
finally
{
flag = true;
// 重新设置计时器
//timer.Change(1000, Timeout.Infinite);
}
}
#region 预警展示
/// <summary>
/// 预警展示
/// </summary>
private void AlarmShow()
{
//异常报警
lock (String.Empty)
{
DbMCControl alarmClientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pmt_Alarm").FirstOrDefault();
//本地计划
if (alarmClientGridControl != null && alarmClientGridControl.BaseControl != null)
{
var alarmData = Alarm.AlarmHelper.QueryAlarmLogDataTable();
if (alarmData != null && alarmData.Rows.Count > 0)
{
alarmClientGridControl.BaseControl.BindDataSource = null;
alarmClientGridControl.BaseControl.BindDataSource = alarmData;
}
#region 根据计划状态处理背景色
DataGridView alarmClientGrid = alarmClientGridControl.BaseControl as DataGridView;
SetBackColor(alarmClientGrid);
#endregion
}
else
{
ICSharpCode.Core.LoggingService<XlInitAction>.Warn("接在首页展示预警失败本地预警控件为Null...");
}
}
}
#endregion
public void SetWeight(List<Xl_DowLoadPlan> materialList)
{
if (materialList.Count==0)
{
for (int i = 1; i <= 28; i++)
{
switch (i)
{
case 1:
case 2:
var btnStation1 = base.GetControlById("MCBtn1") as System.Windows.Forms.Button;
btnStation1.Text = "0";
break;
case 3:
case 4:
var btnStatio2 = base.GetControlById("MCBtn2") as System.Windows.Forms.Button;
btnStatio2.Text = "0";
break;
case 5:
case 6:
var btnStatio3 = base.GetControlById("MCBtn3") as System.Windows.Forms.Button;
btnStatio3.Text = "0";
break;
case 7:
case 8:
var btnStatio4 = base.GetControlById("MCBtn4") as System.Windows.Forms.Button;
btnStatio4.Text = "0";
break;
case 9:
case 10:
var btnStatio5 = base.GetControlById("MCBtn5") as System.Windows.Forms.Button;
btnStatio5.Text = "0";
break;
case 11:
case 12:
var btnStatio6 = base.GetControlById("MCBtn6") as System.Windows.Forms.Button;
btnStatio6.Text = "0";
break;
case 13:
case 14:
var btnStatio7 = base.GetControlById("MCBtn7") as System.Windows.Forms.Button;
btnStatio7.Text = "0";
break;
case 15:
case 16:
var btnStatio8 = base.GetControlById("MCBtn8") as System.Windows.Forms.Button;
btnStatio8.Text = "0";
break;
case 17:
case 18:
var btnStatio9 = base.GetControlById("MCBtn9") as System.Windows.Forms.Button;
btnStatio9.Text = "0";
break;
case 19:
case 20:
var btnStatio10 = base.GetControlById("MCBtn10") as System.Windows.Forms.Button;
btnStatio10.Text = "0";
break;
case 21:
case 22:
var btnStatio11 = base.GetControlById("MCBtn11") as System.Windows.Forms.Button;
btnStatio11.Text = "0";
break;
case 23:
case 24:
var btnStatio12 = base.GetControlById("MCBtn12") as System.Windows.Forms.Button;
btnStatio12.Text = "0";
break;
case 25:
case 26:
var btnStatio13 = base.GetControlById("MCBtn13") as System.Windows.Forms.Button;
btnStatio13.Text = "0";
break;
case 27:
case 28:
var btnStatio14 = base.GetControlById("MCBtn14") as System.Windows.Forms.Button;
btnStatio14.Text = "0";
break;
default:
break;
}
}
}
else
{
foreach (var item in materialList)
{
switch (item.Station)
{
case 1:
case 2:
var btnStation1 = base.GetControlById("MCBtn1") as System.Windows.Forms.Button;
btnStation1.Text = item.Set_Weight.ToString();
break;
case 3:
case 4:
var btnStatio2 = base.GetControlById("MCBtn2") as System.Windows.Forms.Button;
btnStatio2.Text = item.Set_Weight.ToString();
break;
case 5:
case 6:
var btnStatio3 = base.GetControlById("MCBtn3") as System.Windows.Forms.Button;
btnStatio3.Text = item.Set_Weight.ToString();
break;
case 7:
case 8:
var btnStatio4 = base.GetControlById("MCBtn4") as System.Windows.Forms.Button;
btnStatio4.Text = item.Set_Weight.ToString();
break;
case 9:
case 10:
var btnStatio5 = base.GetControlById("MCBtn5") as System.Windows.Forms.Button;
btnStatio5.Text = item.Set_Weight.ToString();
break;
case 11:
case 12:
var btnStatio6 = base.GetControlById("MCBtn6") as System.Windows.Forms.Button;
btnStatio6.Text = item.Set_Weight.ToString();
break;
case 13:
case 14:
var btnStatio7 = base.GetControlById("MCBtn7") as System.Windows.Forms.Button;
btnStatio7.Text = item.Set_Weight.ToString();
break;
case 15:
case 16:
var btnStatio8 = base.GetControlById("MCBtn8") as System.Windows.Forms.Button;
btnStatio8.Text = item.Set_Weight.ToString();
break;
case 17:
case 18:
var btnStatio9 = base.GetControlById("MCBtn9") as System.Windows.Forms.Button;
btnStatio9.Text = item.Set_Weight.ToString();
break;
case 19:
case 20:
var btnStatio10 = base.GetControlById("MCBtn10") as System.Windows.Forms.Button;
btnStatio10.Text = item.Set_Weight.ToString();
break;
case 21:
case 22:
var btnStatio11 = base.GetControlById("MCBtn11") as System.Windows.Forms.Button;
btnStatio11.Text = item.Set_Weight.ToString();
break;
case 23:
case 24:
var btnStatio12 = base.GetControlById("MCBtn12") as System.Windows.Forms.Button;
btnStatio12.Text = item.Set_Weight.ToString();
break;
case 25:
case 26:
var btnStatio13 = base.GetControlById("MCBtn13") as System.Windows.Forms.Button;
btnStatio13.Text = item.Set_Weight.ToString();
break;
case 27:
case 28:
var btnStatio14 = base.GetControlById("MCBtn14") as System.Windows.Forms.Button;
btnStatio14.Text = item.Set_Weight.ToString();
break;
default:
break;
}
}
}
}
public void MaterialShow()
{
var materialList = BinHelper.GetBinMaterialList();
foreach (var item in materialList)
{
switch (item.Bin_Serial)
{
case 1:
var lbl1 = base.GetControlById("lbl1") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl1.Text = item.Material_name;
}
else
{
lbl1.Text = "0";
}
break;
case 2:
var lbl2 = base.GetControlById("lbl2") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl2.Text = item.Material_name;
}
else
{
lbl2.Text = "0";
}
break;
case 3:
var lbl3 = base.GetControlById("lbl3") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl3.Text = item.Material_name;
}
else
{
lbl3.Text = "0";
}
break;
case 4:
var lbl4 = base.GetControlById("lbl4") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl4.Text = item.Material_name;
}
else
{
lbl4.Text = "0";
}
break;
case 5:
var lbl5 = base.GetControlById("lbl5") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl5.Text = item.Material_name;
}
else
{
lbl5.Text = "0";
}
break;
case 6:
var lbl6 = base.GetControlById("lbl6") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl6.Text = item.Material_name;
}
else
{
lbl6.Text = "0";
}
break;
case 7:
var lbl7 = base.GetControlById("lbl7") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl7.Text = item.Material_name;
}
else
{
lbl7.Text = "0";
}
break;
case 8:
var lbl8 = base.GetControlById("lbl8") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl8.Text = item.Material_name;
}
else
{
lbl8.Text = "0";
}
break;
case 9:
var lbl9 = base.GetControlById("lbl9") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl9.Text = item.Material_name;
}
else
{
lbl9.Text = "0";
}
break;
case 10:
var lbl10 = base.GetControlById("lbl10") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl10.Text = item.Material_name;
}
else
{
lbl10.Text = "0";
}
break;
case 11:
var lbl11 = base.GetControlById("lbl11") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl11.Text = item.Material_name;
}
else
{
lbl11.Text = "0";
}
break;
case 12:
var lbl12 = base.GetControlById("lbl12") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl12.Text = item.Material_name;
}
else
{
lbl12.Text = "0";
}
break;
case 13:
var lbl13 = base.GetControlById("lbl13") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl13.Text = item.Material_name;
}
else
{
lbl13.Text = "0";
}
break;
case 14:
var lbl14 = base.GetControlById("lbl14") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl14.Text = item.Material_name;
}
else
{
lbl14.Text = "0";
}
break;
case 15:
var lbl15 = base.GetControlById("lbl15") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl15.Text = item.Material_name;
}
else
{
lbl15.Text = "0";
}
break;
case 16:
var lbl16 = base.GetControlById("lbl16") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl16.Text = item.Material_name;
}
else
{
lbl16.Text = "0";
}
break;
case 17:
var lbl17 = base.GetControlById("lbl17") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl17.Text = item.Material_name;
}
else
{
lbl17.Text = "0";
}
break;
case 18:
var lbl18 = base.GetControlById("lbl18") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl18.Text = item.Material_name;
}
else
{
lbl18.Text = "0";
}
break;
case 19:
var lbl19 = base.GetControlById("lbl19") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl19.Text = item.Material_name;
}
else
{
lbl19.Text = "0";
}
break;
case 20:
var lbl20 = base.GetControlById("lbl20") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl20.Text = item.Material_name;
}
else
{
lbl20.Text = "0";
}
break;
case 21:
var lbl21 = base.GetControlById("lbl21") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl21.Text = item.Material_name;
}
else
{
lbl21.Text = "0";
}
break;
case 22:
var lbl22 = base.GetControlById("lbl22") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl22.Text = item.Material_name;
}
else
{
lbl22.Text = "0";
}
break;
case 23:
var lbl23 = base.GetControlById("lbl23") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl23.Text = item.Material_name;
}
else
{
lbl23.Text = "0";
}
break;
case 24:
var lbl24 = base.GetControlById("lbl24") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl24.Text = item.Material_name;
}
else
{
lbl24.Text = "0";
}
break;
case 25:
var lbl25 = base.GetControlById("lbl25") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl25.Text = item.Material_name;
}
else
{
lbl25.Text = "0";
}
break;
case 26:
var lbl26 = base.GetControlById("lbl26") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl26.Text = item.Material_name;
}
else
{
lbl26.Text = "0";
}
break;
case 27:
var lbl27 = base.GetControlById("lbl27") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl27.Text = item.Material_name;
}
else
{
lbl27.Text = "0";
}
break;
case 28:
var lbl28 = base.GetControlById("lbl28") as System.Windows.Forms.Label;
if (!string.IsNullOrEmpty(item.Material_name))
{
lbl28.Text = item.Material_name;
}
else
{
lbl28.Text = "0";
}
break;
default:
break;
}
}
}
#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); //灰色
}
DataGridViewCellStyle headerStyle = new DataGridViewCellStyle();
headerStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
grid.ColumnHeadersDefaultCellStyle = headerStyle;
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<XlInitAction>.Error("设置背景色失败:" + ex.Message);
}
}
}
#endregion
}
}