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.
214 lines
9.8 KiB
C#
214 lines
9.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.Data;
|
|
using Mesnac.Action.Base;
|
|
using Mesnac.Codd.Session;
|
|
using System.Reflection;
|
|
using Mesnac.Controls.Base;
|
|
using Mesnac.Action.ChemicalWeighing.Entity;
|
|
using Mesnac.Action.ChemicalWeighing.Product.PptPlan;
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.Report.SolventReport
|
|
{
|
|
/// <summary>
|
|
/// 生产报表业务
|
|
/// </summary>
|
|
public class SelectRowAction : ChemicalWeighingAction,IAction
|
|
{
|
|
#region 字段定义
|
|
|
|
public static bool IsFirstRun = true; //是否首次运行
|
|
private RuntimeParameter _runtime;
|
|
private Control _clientGridControl = null; //多维表控件
|
|
private DbMCControl _dgvLRPlan = null; //生产计划
|
|
private DbMCControl _weighGridControl = null; //物料详情
|
|
private DataTable dataTable = null;
|
|
|
|
#endregion
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
{
|
|
base.RunIni(runtime);
|
|
this._runtime = runtime;
|
|
|
|
#region 获取界面生产计划控件和称量明细控件
|
|
|
|
this._dgvLRPlan = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Hw_plan").FirstOrDefault();
|
|
if (_dgvLRPlan == null || !(_dgvLRPlan.BaseControl is DataGridView))
|
|
{
|
|
ICSharpCode.Core.LoggingService<SelectPlanAction>.Warn("{生产报表} 缺少生产计划DataGridView控件...");
|
|
runtime.IsReturn = false;
|
|
return;
|
|
}
|
|
|
|
DbMCControl weighGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Hw_weigh").FirstOrDefault();
|
|
|
|
if (weighGridControl == null || !(weighGridControl.BaseControl is DataGridView))
|
|
{
|
|
ICSharpCode.Core.LoggingService<SelectPlanAction>.Warn("{生产报表} 缺少生产计划DataGridView控件...");
|
|
runtime.IsReturn = false;
|
|
return;
|
|
}
|
|
Mesnac.Controls.Default.MultiColHeaderDgv clientGrid = (this._clientGridControl as Mesnac.Controls.Default.MultiColHeaderDgv);
|
|
|
|
#endregion
|
|
|
|
|
|
DataGridView lR_planGridView = this._dgvLRPlan.BaseControl as DataGridView;
|
|
|
|
if (lR_planGridView.SelectedRows.Count == 1)
|
|
{
|
|
string plan_Id = lR_planGridView.SelectedRows[0].Cells["Plan_Id"].Value as string;
|
|
string real_Num =Convert.ToInt32(lR_planGridView.SelectedRows[0].Cells["Real_Num"].Value).ToString();
|
|
if (!string.IsNullOrEmpty(plan_Id))
|
|
{
|
|
#region 数据源获取及定义
|
|
|
|
DataTable lR_Weighs = PlanHelper.GetHwWeighDataTable(plan_Id, real_Num);
|
|
|
|
#endregion
|
|
this._weighGridControl = weighGridControl;
|
|
|
|
|
|
if (this._weighGridControl != null && lR_Weighs != null)
|
|
{
|
|
_weighGridControl.BaseControl.BindDataSource = null;
|
|
_weighGridControl.BaseControl.BindDataSource = lR_Weighs;
|
|
}
|
|
else
|
|
{
|
|
this._weighGridControl.BaseControl.BindDataSource = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#region 方法定义
|
|
|
|
#region 建立表头结构
|
|
|
|
private void BuildTableHead(TreeView treeView)
|
|
{
|
|
dataTable.Columns.Add("物料名称", typeof(System.String));
|
|
dataTable.Columns.Add("设定值", typeof(decimal));
|
|
dataTable.Columns.Add("实际值", typeof(decimal));
|
|
dataTable.Columns.Add("设置误差", typeof(decimal));
|
|
dataTable.Columns.Add("实际误差", typeof(decimal));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 数据表填充
|
|
|
|
private void DataTableWrite(List<Entity.LR_recipe> lR_Recipes, List<Entity.LR_weigh> lR_Weighs)
|
|
{
|
|
//if(lR_Recipes != null && lR_Recipes.Count > 0)
|
|
//{
|
|
// for(int i = 0; i < lR_Recipes.Count; i++)
|
|
// {
|
|
// int sumRealWaste_Time = 0; //加和时间
|
|
|
|
// DataRow drow = dataTable.NewRow();
|
|
|
|
// //每车物料数据填入
|
|
// List<Entity.LR_weigh> curWeights = lR_Weighs.FindAll(x => x.Plan_id == lR_Recipes[i].Plan_id);
|
|
// 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;
|
|
// }
|
|
// }
|
|
|
|
// dataTable.Rows.Add(drow);
|
|
// }
|
|
//}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DataTable新增最大最小平均合计值行
|
|
|
|
private void DataTableAdd(int mNum)
|
|
{
|
|
if (mNum == 0) return;
|
|
//最大值行
|
|
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
|
|
|
|
#endregion
|
|
}
|
|
}
|