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.
72 lines
3.5 KiB
C#
72 lines
3.5 KiB
C#
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 ExportOperateDataAction : FeedingAction, IAction
|
|
{
|
|
public void Run(RuntimeParameter runtime)
|
|
{
|
|
base.RunIni(runtime);
|
|
|
|
StringBuilder sqlsb = new StringBuilder();
|
|
sqlsb.Append(@"select WorkType as 操作类型, OperDest as 操作目标, OperMemo as 操作备注, RecordTime as 操作时间 from SysLog left join dbo.BasUser on SysLog.userid=BasUser.ObjID
|
|
left join dbo.BasRole on BasUser.RoleID=BasRole.ObjID 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 SysLog.recordtime>='" + Convert.ToDateTime(startdate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(starttime.MCValue).ToShortTimeString() + "' ");
|
|
}
|
|
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 SysLog.recordtime<='" + Convert.ToDateTime(enddate.MCValue).ToString("yyyy-MM-dd") + " " + Convert.ToDateTime(endtime.MCValue).ToShortTimeString() + "' ");
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|