|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Mesnac.Action.Base;
|
|
|
|
|
using Mesnac.Controls.Base;
|
|
|
|
|
using Mesnac.Codd.Session;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace Mesnac.Action.Feeding.Qingquan.Report
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 导出报警日志到Excel中
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ExportAlarmDataAction : FeedingAction, IAction
|
|
|
|
|
{
|
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
|
|
|
{
|
|
|
|
|
base.RunIni(runtime);
|
|
|
|
|
|
|
|
|
|
StringBuilder sqlsb = new StringBuilder();
|
|
|
|
|
sqlsb.Append(@"select acdetail as 车次, acbz1 as 报警信息,acbz2 as 报警时间 from pmtalarmcode where 1=1 ");
|
|
|
|
|
List<DbMCControl> 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)
|
|
|
|
|
{
|
|
|
|
|
sqlsb.AppendLine(@"AND pmtalarmcode.Recordtime>='" + Convert.ToDateTime(startdate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(starttime.MCValue).ToShortTimeString() + "' ");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
base.LogError("{操作报警报表} 缺少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)
|
|
|
|
|
{
|
|
|
|
|
sqlsb.AppendLine(@"AND pmtalarmcode.Recordtime<='" + Convert.ToDateTime(enddate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(endtime.MCValue).ToShortTimeString() + "' ");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
base.LogError("{操作报警报表} 缺少key值为enddate或者enddate的时间查询条件...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//获取报警内容查询条件并执行模糊查询
|
|
|
|
|
DbMCControl mcTextBox = this.GetDbMCControlByBaseControlKey("acbz1").FirstOrDefault();
|
|
|
|
|
if (mcTextBox != null)
|
|
|
|
|
{
|
|
|
|
|
sqlsb.Append(@"and pmtalarmcode.acbz1 like '%" + mcTextBox.BaseControl.MCValue.ToString() + "%'");
|
|
|
|
|
}
|
|
|
|
|
//end
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
string sqlstr = sqlsb.ToString();
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
|
|
|
|
|
|
|
SaveFileDialog dialog = new SaveFileDialog();
|
|
|
|
|
dialog.Filter = "(*.xls)|*.xls";
|
|
|
|
|
DialogResult result = dialog.ShowDialog();
|
|
|
|
|
if (result == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
string fileName = dialog.FileName;
|
|
|
|
|
if (!String.IsNullOrEmpty(fileName))
|
|
|
|
|
{
|
|
|
|
|
Stream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
|
|
|
|
|
Mesnac.Basic.DataToFileHandler.Instance.ToExcel(table, ref fs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
base.LogError("导出报警日志失败:" + ex.Message);
|
|
|
|
|
Mesnac.Basic.MessageBoxTimeOut.Show("导出报警日志失败:" + ex.Message, "提示", 2000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|