|
|
|
|
using Mesnac.Action.Base;
|
|
|
|
|
using Mesnac.Action.ChemicalWeighing.Test;
|
|
|
|
|
using Mesnac.Codd.Session;
|
|
|
|
|
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.MaterialStatisticsReport
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 物料统计报表
|
|
|
|
|
/// </summary>
|
|
|
|
|
class SelectWeightAction : ChemicalWeighingAction, IAction
|
|
|
|
|
{
|
|
|
|
|
public static event EventHandler MaterialSynchronousComplete;
|
|
|
|
|
private RuntimeParameter _runtime;
|
|
|
|
|
private IBaseControl _startdate = null; //开始日期
|
|
|
|
|
private IBaseControl _enddate = null; //结束日期
|
|
|
|
|
private IBaseControl _starttime = null; //开始时间
|
|
|
|
|
private IBaseControl _endtime = null; //结束时间
|
|
|
|
|
private DbMCControl _clientDGV = null;
|
|
|
|
|
private IBaseControl _recipeName = null; //配方名
|
|
|
|
|
private IBaseControl _shiftName = null; //班次
|
|
|
|
|
private IBaseControl _materialName = null; //物料名称
|
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
|
|
|
{
|
|
|
|
|
base.RunIni(runtime);
|
|
|
|
|
this._runtime = runtime;
|
|
|
|
|
ICSharpCode.Core.LoggingService<SelectWeightAction>.Debug("物料统计报表-查询..");
|
|
|
|
|
//1.按配方、按时间、按班次物料统计
|
|
|
|
|
//ComboBox comboBox = base.GetControlById("MCCombobox1") as ComboBox;
|
|
|
|
|
//if (SelectWeightAction.MaterialSynchronousComplete != null)
|
|
|
|
|
//{
|
|
|
|
|
// SelectWeightAction.MaterialSynchronousComplete(null, EventArgs.Empty);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//2.按名称累加物料统计
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
|
|
|
|
|
StringBuilder sbSql = new StringBuilder(@"SELECT Base_PlanInfo.recipe_Name AS Recipe_Name,Base_MaterialInfo.material_Id AS Material_Code,Base_MaterialInfo.material_Name AS Material_Name, SUM(LR_Weigh.Real_Weight) as realWeight,Pmt_Shiftime.Shift_name FROM
|
|
|
|
|
LR_weigh,Base_PlanInfo,Base_RecipeInfo,Base_MaterialInfo,Pmt_Shiftime
|
|
|
|
|
WHERE Base_PlanInfo.plan_Id = LR_weigh.Plan_id AND Base_MaterialInfo.material_Id = LR_weigh.Material_Code AND Base_RecipeInfo.recipe_Id = LR_weigh.Recipe_code AND Pmt_Shiftime.Shift_id = Base_PlanInfo.plan_Team ");
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
sbSql.AppendLine(@"And LR_Weigh.Weight_Time >= '" + Convert.ToDateTime(_startdate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(_starttime.MCValue).ToShortTimeString() + "' ");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService<SelectWeightAction>.Debug("{物料统计报表} 缺少key值为startdate或者starttime的时间查询条件...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//结束时间条件
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
sbSql.AppendLine(@"And LR_Weigh.Weight_Time <= '" + Convert.ToDateTime(_enddate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(_endtime.MCValue).ToShortTimeString() + "' ");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService<SelectWeightAction>.Debug("{物料统计报表} 缺少key值为enddate或者enddate的时间查询条件...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//配方名称、物料名称及班次
|
|
|
|
|
this._recipeName = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey == "[DataSource1].[Base_RecipeInfo].[recipe_Name]").FirstOrDefault().BaseControl;
|
|
|
|
|
this._shiftName = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey == "[DataSource1].[Pmt_Shiftime].[Shift_name]").FirstOrDefault().BaseControl;
|
|
|
|
|
|
|
|
|
|
this._materialName = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey == "[DataSource1].[Base_MaterialInfo].[material_Name]").FirstOrDefault().BaseControl;
|
|
|
|
|
|
|
|
|
|
if (!String.IsNullOrEmpty(this._recipeName.MCValue.ToString()))
|
|
|
|
|
{
|
|
|
|
|
if (_recipeName.MCValue.ToString() != "--")
|
|
|
|
|
{
|
|
|
|
|
sbSql.AppendLine(@"And Base_PlanInfo.Recipe_Name = '" + _recipeName.MCValue.ToString() + "' ");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!String.IsNullOrEmpty(this._shiftName.MCValue.ToString()))
|
|
|
|
|
{
|
|
|
|
|
if (_shiftName.MCValue.ToString() != "--")
|
|
|
|
|
{
|
|
|
|
|
sbSql.AppendLine(@"And Shift_Name = '" + _shiftName.MCValue.ToString() + "' ");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!String.IsNullOrEmpty(this._materialName.MCValue.ToString()))
|
|
|
|
|
{
|
|
|
|
|
if (_materialName.MCValue.ToString() != "--")
|
|
|
|
|
{
|
|
|
|
|
sbSql.AppendLine(@"And Material_Name = '" + _materialName.MCValue.ToString() + "' ");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sbSql.Append(" GROUP BY Base_PlanInfo.recipe_Name,Base_MaterialInfo.material_Id,Base_MaterialInfo.material_Name,Pmt_Shiftime.Shift_name");
|
|
|
|
|
|
|
|
|
|
dbHelper.CommandText = sbSql.ToString();
|
|
|
|
|
dbHelper.CommandType = System.Data.CommandType.Text;
|
|
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
|
|
|
|
|
|
|
this._clientDGV = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "LR_weigh").FirstOrDefault();
|
|
|
|
|
if (_clientDGV == null || !(_clientDGV.BaseControl is DataGridView))
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService<SelectWeightAction>.Warn("{物料统计报表-查询} 缺少DataGridView控件...");
|
|
|
|
|
runtime.IsReturn = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_clientDGV.BaseControl.BindDataSource = null;
|
|
|
|
|
_clientDGV.BaseControl.BindDataSource = table;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|