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.
345 lines
17 KiB
C#
345 lines
17 KiB
C#
using Mesnac.Action.Base;
|
|
using Mesnac.Controls.Base;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.Report.ProductionAnalysisReport
|
|
{
|
|
/// <summary>
|
|
/// 生产质量分析
|
|
/// </summary>
|
|
class BinAlarmAction : ChemicalWeighingAction, IAction
|
|
{
|
|
#region 字段定义
|
|
|
|
private RuntimeParameter _runtime;
|
|
private IBaseControl _startdate = null; //开始日期
|
|
private IBaseControl _enddate = null; //结束日期
|
|
private IBaseControl _starttime = null; //开始时间
|
|
private IBaseControl _endtime = null; //结束时间
|
|
private DbMCControl _recipeNameControl = null; //配方名Combobox控件
|
|
private Control _clientGridControl = null; //多维表控件
|
|
private DataTable dataTable = null;
|
|
|
|
#endregion
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
{
|
|
base.RunIni(runtime);
|
|
this._runtime = runtime;
|
|
|
|
#region 获取开始/结束时间控件和质量分析控件
|
|
|
|
List<DbMCControl> mcControllist = GetAllDbMCControlsByOption(DbOptionTypes.Query);//获取所有待初始化控件
|
|
//开始时间条件
|
|
this._startdate = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "startdate").FirstOrDefault().BaseControl;
|
|
this._starttime = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "starttime").FirstOrDefault().BaseControl;
|
|
if(_startdate == null && _starttime == null)
|
|
{
|
|
ICSharpCode.Core.LoggingService<BinAlarmAction>.Debug("{生产分析报表} 缺少key值为startdate或者starttime的时间查询条件...");
|
|
return;
|
|
}
|
|
string start = Convert.ToDateTime(_startdate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(_starttime.MCValue).ToShortTimeString();
|
|
|
|
//结束时间条件
|
|
this._enddate = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "enddate").FirstOrDefault().BaseControl;
|
|
this._endtime = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "endtime").FirstOrDefault().BaseControl;
|
|
if (_enddate == null && _endtime == null)
|
|
{
|
|
ICSharpCode.Core.LoggingService<BinAlarmAction>.Debug("{生产分析报表} 缺少key值为enddate或者enddate的时间查询条件...");
|
|
return;
|
|
}
|
|
string end = Convert.ToDateTime(_enddate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(_endtime.MCValue).ToShortTimeString();
|
|
|
|
this._recipeNameControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[Pmt_recipe].[Recipe_Name]").FirstOrDefault();
|
|
if (_recipeNameControl == null)
|
|
{
|
|
ICSharpCode.Core.LoggingService<BinAlarmAction>.Warn("{生产分析报表} 缺少配方名控件...");
|
|
runtime.IsReturn = false;
|
|
return;
|
|
}
|
|
ComboBox recipeNameCB = this._recipeNameControl.BaseControl as ComboBox;
|
|
|
|
bool gridFlag = false;
|
|
foreach (Control ib in GetAllControls())
|
|
{
|
|
|
|
if (ib.Name.Contains("MultiColHeaderDgv"))
|
|
{
|
|
this._clientGridControl = ib;
|
|
gridFlag = true;
|
|
}
|
|
if (gridFlag)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
if (_clientGridControl == null)
|
|
{
|
|
ICSharpCode.Core.LoggingService<BinAlarmAction>.Warn("{生产分析报表} 缺少质量分析MultiColHeaderDgv控件...");
|
|
runtime.IsReturn = false;
|
|
return;
|
|
}
|
|
Mesnac.Controls.Default.MultiColHeaderDgv clientGrid = (this._clientGridControl as Mesnac.Controls.Default.MultiColHeaderDgv);
|
|
|
|
dataTable = new DataTable("AnalysisDT");
|
|
|
|
#endregion
|
|
|
|
#region 控件格式化
|
|
|
|
clientGrid.myColHeaderTreeView = null;
|
|
clientGrid.DataSource = null;
|
|
clientGrid.iNodeLevels = 0;
|
|
clientGrid.ColLists.Clear();
|
|
clientGrid.ColumnHeadersHeight = 23;
|
|
clientGrid.ScrollBars = ScrollBars.Both;
|
|
clientGrid.AllowUserToAddRows = false;
|
|
clientGrid.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
|
clientGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
|
clientGrid.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("宋体", 12);
|
|
clientGrid.DefaultCellStyle.Font = new System.Drawing.Font("宋体", 10);
|
|
|
|
#endregion
|
|
|
|
if (!string.IsNullOrEmpty(recipeNameCB.Text))
|
|
{
|
|
List<string> PlanIds = ReportHelper.GetPlanIDList(start,end,recipeNameCB.Text);
|
|
if (PlanIds.Count == 0)
|
|
{
|
|
MessageBox.Show("未查询到该时间段的配方计划信息");
|
|
return;
|
|
}
|
|
|
|
string lR_planID = PlanIds[0];
|
|
|
|
List<Entity.LR_recipe> lR_Recipes = ReportHelper.GetLR_recipeList(lR_planID);
|
|
TreeView treeView = new TreeView();
|
|
|
|
List<Entity.LR_lot> lR_Lots = ReportHelper.GetAllLR_lotList(PlanIds);
|
|
// List<Entity.LR_weigh> lR_Weighs = ReportHelper.GetAllLR_weighList(PlanIds, lR_Recipes.Count);
|
|
|
|
#region 表头建立
|
|
|
|
BuildTableHead(treeView, lR_Recipes);
|
|
clientGrid.myColHeaderTreeView = treeView;
|
|
|
|
#endregion
|
|
|
|
#region 数据填充
|
|
|
|
//DataTableWrite(lR_Lots, lR_Weighs);
|
|
|
|
#endregion
|
|
|
|
#region 增加最大最小平均合计值行
|
|
|
|
//DataTableAdd(lR_Recipes.Count);
|
|
|
|
#endregion
|
|
|
|
//clientGrid.DataSource = dataTable;
|
|
|
|
}
|
|
}
|
|
|
|
#region 建立表头结构
|
|
|
|
private void BuildTableHead(TreeView treeView, List<Entity.LR_recipe> lR_Recipes)
|
|
{
|
|
int treeIndex = 0;
|
|
TreeNode rootTreeNode = new TreeNode("物料");
|
|
treeView.Nodes.Add(rootTreeNode);
|
|
TreeNode childTreeNodeSerial_Num = new TreeNode("序号");
|
|
TreeNode childTreeNodeWeight_Time = new TreeNode("检量时间");
|
|
treeView.Nodes[treeIndex].Nodes.Add(childTreeNodeSerial_Num);
|
|
treeView.Nodes[treeIndex].Nodes.Add(childTreeNodeWeight_Time);
|
|
dataTable.Columns.Add("Serial_Num", typeof(System.String));
|
|
dataTable.Columns.Add("Weight_Time", typeof(System.String));
|
|
decimal sumSet_Weight = 0.0M;
|
|
decimal sumSet_Error = 0.0M;
|
|
|
|
if (lR_Recipes != null && lR_Recipes.Count > 0)
|
|
{
|
|
//物料表头
|
|
for (int i = 0; i < lR_Recipes.Count; i++)
|
|
{
|
|
sumSet_Weight = sumSet_Weight + (decimal)lR_Recipes[i].Set_Weight;
|
|
sumSet_Error = sumSet_Error + (decimal)lR_Recipes[i].Set_Error;
|
|
TreeNode rootTreeNodeMaterialName = new TreeNode(lR_Recipes[i].Material_Name);
|
|
treeView.Nodes.Add(rootTreeNodeMaterialName);
|
|
treeIndex++;
|
|
TreeNode childTreeNodeSet_Weight = new TreeNode("重量(kg)");
|
|
TreeNode childTreeNodeSet_Error = new TreeNode("误差(kg)");
|
|
TreeNode childTreeNodeWaste_Time = new TreeNode("时间(s)");
|
|
treeView.Nodes[treeIndex].Nodes.Add(childTreeNodeSet_Weight);
|
|
treeView.Nodes[treeIndex].Nodes.Add(childTreeNodeSet_Error);
|
|
treeView.Nodes[treeIndex].Nodes.Add(childTreeNodeWaste_Time);
|
|
dataTable.Columns.Add("Set_Weight" + treeIndex.ToString(), typeof(decimal));
|
|
dataTable.Columns.Add("Set_Error" + treeIndex.ToString(), typeof(decimal));
|
|
dataTable.Columns.Add("Waste_Time" + treeIndex.ToString(), typeof(decimal));
|
|
}
|
|
|
|
//加和重量表头
|
|
TreeNode rootTreeNodeSum = new TreeNode("加和重量");
|
|
treeView.Nodes.Add(rootTreeNodeSum);
|
|
treeIndex++;
|
|
TreeNode childTreeNodeSumSet_Weight = new TreeNode("重量(kg)");
|
|
TreeNode childTreeNodeSumSet_Error = new TreeNode("误差(kg)");
|
|
TreeNode childTreeNodesumWaste_Time = new TreeNode("T(s)");
|
|
treeView.Nodes[treeIndex].Nodes.Add(childTreeNodeSumSet_Weight);
|
|
treeView.Nodes[treeIndex].Nodes.Add(childTreeNodeSumSet_Error);
|
|
treeView.Nodes[treeIndex].Nodes.Add(childTreeNodesumWaste_Time);
|
|
dataTable.Columns.Add("SumSet_Weight", typeof(decimal));
|
|
dataTable.Columns.Add("SumSet_Error", typeof(decimal));
|
|
dataTable.Columns.Add("SumWaste_Time", typeof(decimal));
|
|
|
|
//检量重量表头
|
|
TreeNode rootTreeNodeCheck = new TreeNode("检量重量");
|
|
treeView.Nodes.Add(rootTreeNodeCheck);
|
|
treeIndex++;
|
|
TreeNode childTreeNodeCheckSet_Weight = new TreeNode("重量(kg)");
|
|
TreeNode childTreeNodeCheckSet_Error = new TreeNode("误差(kg)");
|
|
TreeNode childTreeNodeCheckWaste_Time = new TreeNode("T(s)");
|
|
TreeNode childTreeNodeCheckNet_Weight = new TreeNode("皮重");
|
|
treeView.Nodes[treeIndex].Nodes.Add(childTreeNodeCheckSet_Weight);
|
|
treeView.Nodes[treeIndex].Nodes.Add(childTreeNodeCheckSet_Error);
|
|
treeView.Nodes[treeIndex].Nodes.Add(childTreeNodeCheckWaste_Time);
|
|
treeView.Nodes[treeIndex].Nodes.Add(childTreeNodeCheckNet_Weight);
|
|
dataTable.Columns.Add("CheckSet_Weight", typeof(decimal));
|
|
dataTable.Columns.Add("CheckSet_Error", typeof(decimal));
|
|
dataTable.Columns.Add("CheckWaste_Time", typeof(decimal));
|
|
dataTable.Columns.Add("CheckNet_Weight", typeof(System.String));
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 数据表填充
|
|
|
|
//private void DataTableWrite(List<Entity.LR_lot> lR_Lots, List<Entity.LR_weigh> lR_Weighs)
|
|
//{
|
|
// if (lR_Lots != null && lR_Lots.Count > 0)
|
|
// {
|
|
// for (int i = 0; i < lR_Lots.Count; i++)
|
|
// {
|
|
// int sumRealWaste_Time = 0; //加和时间
|
|
|
|
// DataRow drow = dataTable.NewRow();
|
|
// //车次和检量时间数据填入
|
|
// drow["Serial_Num"] = lR_Lots[i].Serial_Num;
|
|
// drow["Weight_Time"] = lR_Lots[i].Prd_date;
|
|
|
|
// //每车物料数据填入
|
|
// List<Entity.LR_weigh> curWeights = lR_Weighs.FindAll(x => x.Serial_Num == lR_Lots[i].Serial_Num);
|
|
// if (curWeights != null && curWeights.Count > 0)
|
|
// {
|
|
// for (int j = 0; j < curWeights.Count; j++)
|
|
// {
|
|
// drow["Set_Weight" + (j + 1).ToString()] = curWeights[j].Real_Weight;
|
|
// drow["Set_Error" + (j + 1).ToString()] = curWeights[j].Real_Error;
|
|
// drow["Waste_Time" + (j + 1).ToString()] = curWeights[j].Waste_Time;
|
|
// sumRealWaste_Time = sumRealWaste_Time + (int)curWeights[j].Waste_Time;
|
|
// }
|
|
// }
|
|
|
|
// //加和重量数据填入
|
|
// drow["SumSet_Weight"] = lR_Lots[i].Real_weight;
|
|
// drow["SumSet_Error"] = lR_Lots[i].Real_weight;
|
|
// drow["SumWaste_Time"] = sumRealWaste_Time;
|
|
|
|
// //检量重量数据填入
|
|
|
|
// drow["CheckSet_Weight"] = lR_Lots[i].Real_weight;
|
|
// drow["CheckSet_Error"] = lR_Lots[i].Real_weight;
|
|
// drow["CheckWaste_Time"] = lR_Lots[i].Waste_Time;
|
|
// drow["CheckNet_Weight"] = lR_Lots[i].Net_Weight;
|
|
|
|
// dataTable.Rows.Add(drow);
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
#endregion
|
|
|
|
#region DataTable新增最大最小平均合计值行
|
|
|
|
private void DataTableAdd(int mNum)
|
|
{
|
|
//最大值行
|
|
DataRow drowMax = dataTable.NewRow();
|
|
drowMax["Weight_Time"] = "最大值";
|
|
for (int i=0; i<mNum;i++)
|
|
{
|
|
drowMax["Set_Weight" + (i + 1).ToString()] = dataTable.Compute("max(Set_Weight"+ (i + 1).ToString() + ")", "");
|
|
drowMax["Set_Error" + (i + 1).ToString()] = dataTable.Compute("max(Set_Error" + (i + 1).ToString() + ")", "");
|
|
drowMax["Waste_Time" + (i + 1).ToString()] = dataTable.Compute("max(Waste_Time" + (i + 1).ToString() + ")", "");
|
|
}
|
|
drowMax["SumSet_Weight"] = dataTable.Compute("max(SumSet_Weight)", "");
|
|
drowMax["SumSet_Error"] = dataTable.Compute("max(SumSet_Error)", "");
|
|
drowMax["SumWaste_Time"] = dataTable.Compute("max(SumWaste_Time)", "");
|
|
drowMax["CheckSet_Weight"] = dataTable.Compute("max(CheckSet_Weight)", "");
|
|
drowMax["CheckSet_Error"] = dataTable.Compute("max(CheckSet_Error)", "");
|
|
drowMax["CheckWaste_Time"] = dataTable.Compute("max(CheckWaste_Time)", "");
|
|
//最小值行
|
|
DataRow drowMin = dataTable.NewRow();
|
|
drowMin["Weight_Time"] = "最小值";
|
|
for (int i = 0; i < mNum; i++)
|
|
{
|
|
drowMin["Set_Weight" + (i + 1).ToString()] = dataTable.Compute("min(Set_Weight" + (i + 1).ToString() + ")", "");
|
|
drowMin["Set_Error" + (i + 1).ToString()] = dataTable.Compute("min(Set_Error" + (i + 1).ToString() + ")", "");
|
|
drowMin["Waste_Time" + (i + 1).ToString()] = dataTable.Compute("min(Waste_Time" + (i + 1).ToString() + ")", "");
|
|
}
|
|
drowMin["SumSet_Weight"] = dataTable.Compute("min(SumSet_Weight)", "");
|
|
drowMin["SumSet_Error"] = dataTable.Compute("min(SumSet_Error)", "");
|
|
drowMin["SumWaste_Time"] = dataTable.Compute("min(SumWaste_Time)", "");
|
|
drowMin["CheckSet_Weight"] = dataTable.Compute("min(CheckSet_Weight)", "");
|
|
drowMin["CheckSet_Error"] = dataTable.Compute("min(CheckSet_Error)", "");
|
|
drowMin["CheckWaste_Time"] = dataTable.Compute("min(CheckWaste_Time)", "");
|
|
//平均值行
|
|
DataRow drowAvg = dataTable.NewRow();
|
|
drowAvg["Weight_Time"] = "平均值";
|
|
for (int i = 0; i < mNum; i++)
|
|
{
|
|
drowAvg["Set_Weight" + (i + 1).ToString()] = dataTable.Compute("avg(Set_Weight" + (i + 1).ToString() + ")", "");
|
|
drowAvg["Set_Error" + (i + 1).ToString()] = dataTable.Compute("avg(Set_Error" + (i + 1).ToString() + ")", "");
|
|
drowAvg["Waste_Time" + (i + 1).ToString()] = dataTable.Compute("avg(Waste_Time" + (i + 1).ToString() + ")", "");
|
|
}
|
|
drowAvg["SumSet_Weight"] = dataTable.Compute("avg(SumSet_Weight)", "");
|
|
drowAvg["SumSet_Error"] = dataTable.Compute("avg(SumSet_Error)", "");
|
|
drowAvg["SumWaste_Time"] = dataTable.Compute("avg(SumWaste_Time)", "");
|
|
drowAvg["CheckSet_Weight"] = dataTable.Compute("avg(CheckSet_Weight)", "");
|
|
drowAvg["CheckSet_Error"] = dataTable.Compute("avg(CheckSet_Error)", "");
|
|
drowAvg["CheckWaste_Time"] = dataTable.Compute("avg(CheckWaste_Time)", "");
|
|
//合计
|
|
DataRow drowSum = dataTable.NewRow();
|
|
drowSum["Weight_Time"] = "合计";
|
|
for (int i = 0; i < mNum; i++)
|
|
{
|
|
drowSum["Set_Weight" + (i + 1).ToString()] = dataTable.Compute("sum(Set_Weight" + (i + 1).ToString() + ")", "");
|
|
drowSum["Set_Error" + (i + 1).ToString()] = dataTable.Compute("sum(Set_Error" + (i + 1).ToString() + ")", "");
|
|
drowSum["Waste_Time" + (i + 1).ToString()] = dataTable.Compute("sum(Waste_Time" + (i + 1).ToString() + ")", "");
|
|
}
|
|
drowSum["SumSet_Weight"] = dataTable.Compute("sum(SumSet_Weight)", "");
|
|
drowSum["SumSet_Error"] = dataTable.Compute("sum(SumSet_Error)", "");
|
|
drowSum["SumWaste_Time"] = dataTable.Compute("sum(SumWaste_Time)", "");
|
|
drowSum["CheckSet_Weight"] = dataTable.Compute("sum(CheckSet_Weight)", "");
|
|
drowSum["CheckSet_Error"] = dataTable.Compute("sum(CheckSet_Error)", "");
|
|
drowSum["CheckWaste_Time"] = dataTable.Compute("sum(CheckWaste_Time)", "");
|
|
|
|
dataTable.Rows.Add(drowMax);
|
|
dataTable.Rows.Add(drowMin);
|
|
dataTable.Rows.Add(drowAvg);
|
|
dataTable.Rows.Add(drowSum);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|