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.DryMixer { /// /// 干混机报表查询事件 /// public class SelectAction : ChemicalWeighingAction, IAction { public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须要调用的 ICSharpCode.Core.LoggingService.Debug("干混机报表-查询..."); DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.Error("获取本地数据连接失败..."); return; } dbHelper.ClearParameter(); StringBuilder sbSql = new StringBuilder(@"select t1.objId,t1.reportId,t2.Name as eqNo,t1.batch,t1.matCode, t1.setValue,t1.setToler, t1.actValue,t1.actToLer,t1.dos,t1.recordTime from Report_DryMixer t1 left join Device t2 on t1.eqNo = t2.Id where 1=1"); List mcControllist = GetAllDbMCControlsByOption(DbOptionTypes.Query);//获取所有待初始化控件 IBaseControl startdate = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "startdate").FirstOrDefault().BaseControl; IBaseControl starttime = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "starttime").FirstOrDefault().BaseControl; if (startdate != null && starttime != null) { //Append sbSql.AppendLine(@"AND t1.recordTime>='" + Convert.ToDateTime(startdate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(starttime.MCValue).ToShortTimeString() + "' "); } else { ICSharpCode.Core.LoggingService.Debug("{干混机报表-查询} 缺少key值为startdate或者starttime的时间查询条件..."); return; } IBaseControl enddate = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "enddate").FirstOrDefault().BaseControl; IBaseControl endtime = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "endtime").FirstOrDefault().BaseControl; if (enddate != null && endtime != null) { sbSql.AppendLine(@"AND t1.recordTime<='" + Convert.ToDateTime(enddate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(endtime.MCValue).ToShortTimeString() + "' "); } else { ICSharpCode.Core.LoggingService.Debug("{干混机报表-查询} 缺少key值为enddate或者enddate的时间查询条件..."); return; } sbSql.Append(" ORDER BY t1.recordTime desc"); dbHelper.CommandText = sbSql.ToString(); dbHelper.CommandType = System.Data.CommandType.Text; DataTable table = dbHelper.ToDataTable(); //刷新DataGridView数据 DbMCControl _dgvDryMixer = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Report_DryMixer").FirstOrDefault(); if (_dgvDryMixer == null || !(_dgvDryMixer.BaseControl is DataGridView)) { ICSharpCode.Core.LoggingService.Warn("{干混机报表-查询} 缺少系统日志DataGridView控件..."); runtime.IsReturn = false; return; } _dgvDryMixer.BaseControl.BindDataSource = table; } } }