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.

82 lines
4.2 KiB
C#

1 year ago
using Mesnac.Action.Base;
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
{
private RuntimeParameter _runtime;
private IBaseControl _startdate = null; //开始日期
private IBaseControl _enddate = null; //结束日期
private IBaseControl _starttime = null; //开始时间
private IBaseControl _endtime = null; //结束时间
private DbMCControl _clientDGV = null;
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime);
this._runtime = runtime;
ICSharpCode.Core.LoggingService<SelectWeightAction>.Debug("物料统计报表-查询..");
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
dbHelper.ClearParameter();
StringBuilder sbSql = new StringBuilder(@"SELECT LR_Plan.Recipe_Name,LR_Recipe.Material_Code,LR_Recipe.Material_Name,SUM(LR_Weigh.Real_Weight) as realWeight
FROM LR_Plan,LR_Recipe,LR_Weigh
Where LR_Plan.Plan_Id = LR_Recipe.Plan_id AND LR_Recipe.Plan_id=LR_weigh.Plan_id AND LR_Recipe.Material_Code = LR_Weigh.Material_Code ");
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;
}
sbSql.Append(" GROUP BY LR_Plan.Recipe_Name,LR_Recipe.Material_Code,LR_Recipe.Material_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;
}
}
}