将从数据库导出的数据以excel的附件形势发送到指定邮箱
SysRunLog objSysRunLog = SysRunLog.GetInstance();
private Int16 daynum = Convert.ToInt16(ConfigurationSettings.AppSettings["DaysNum"].Trim());
private DateTime beginDate ;
private DateTime endDate;
public void Run()
{
beginDate = DateTime.Now.AddDays(- daynum);
endDate = DateTime.Now;
//objSysRunLog.WriteLog("准备发邮件……");
string emailSubject = "";
string emailBody = "";
DataSet ds = new DataSet();
//emailSubject = beginDate.ToString("yyyy年MM月dd日") + "至" + endDate.ToString("yyyy年MM月dd日") + "未注册客户服务结算办法信息表(试行)";
emailSubject = endDate.ToString("yyyy年MM月dd日") + "未注册用户救援情况";
ProcessFile process = new ProcessFile();
string basePath = AppDomain.CurrentDomain.BaseDirectory;
string excel = basePath + @"temp\" + DateTime.Now.ToString("yyyymmddhhmm") + ".xls";
//objSysRunLog.WriteLog(excel);
try
{
ds = WriteLetter2();
}
catch (Exception e)
{
objSysRunLog.WriteLog("查询失败……" + e);
}
EMail email = new EMail();
//如果有数据,将数据写入EXCEL
if (ds == null)
{
emailBody = "连接数据库失败!";
}
else if (ds.Tables[0].Rows.Count > 0)
{
try
{
//构建用户数据导入的标准DataGrid,并绑定数据;
System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid();
dg.DataSource = ds.Tables[0];
dg.DataBind();
//将数据写入EXCEL中
process.ExportDataGridToExcel(dg, excel);
emailBody = beginDate.ToString("yyyy年MM月dd日") + ConfigurationSettings.AppSettings["Hour2"].Trim() + "时" + ConfigurationSettings.AppSettings["Minute2"].Trim() + "分至" + endDate.ToString("yyyy年MM月dd日") + ConfigurationSetti