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 { /// /// 料仓告警 /// 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 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.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.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.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.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 PlanIds = ReportHelper.GetPlanIDList(start,end,recipeNameCB.Text); if (PlanIds.Count == 0) { MessageBox.Show("未查询到该时间段的配方计划信息"); return; } string lR_planID = PlanIds[0]; List lR_Recipes = ReportHelper.GetLR_recipeList(lR_planID); TreeView treeView = new TreeView(); List lR_Lots = ReportHelper.GetAllLR_lotList(PlanIds); // List 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 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 lR_Lots, List 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 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