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日") + ConfigurationSettings.AppSettings["Hour2"].Trim() + "时" + ConfigurationSettings.AppSettings["Minute2"].Trim() + "分" + "时间内数据详见附件。(请不要回复此邮件)";
email.Attach = excel;
}
catch (Exception e)
{
objSysRunLog.WriteLog("写入EXCEL失败……" + e.ToString());
}
}
else
{
emailBody = beginDate.ToString("yyyy年MM月dd日") + ConfigurationSettings.AppSettings["Hour2"].Trim() + "时" + ConfigurationSettings.AppSettings["Minute2"].Trim() + "分至" + endDate.ToString("yyyy年MM月dd日") + ConfigurationSettings.AppSettings["Hour2"].Trim() + "时" + ConfigurationSettings.AppSettings["Minute2"].Trim() + "分" + "时间内无数据。(请不要回复此邮件)";
}
try
{
email.To = ConfigurationSettings.AppSettings["MailTo2"].Trim();
email.Subject = emailSubject;
email.Body = emailBody;
email.send();
objSysRunLog.WriteLog("邮件发送成功:");
}
catch (Exception e)
{
objSysRunLog.WriteLog("邮件发送失败:" + e.Message);
}
}
public DataSet WriteLetter2()
{
string result = "";
string connectString = System.Configuration.ConfigurationSettings.AppSettings["connString"];
OracleConnection myConn = new OracleConnection(connectString);
OracleCommand myCMD = new OracleCommand();
myCMD.CommandType = CommandType.StoredProcedure;
myCMD.CommandText = @"PK_EXPORT.P_NOTREG_USER_INTRADAY_INFO";
myCMD.Parameters.Add("V_DAYS_NUM", OracleType.Number).Value = dayn
补充:软件开发 , C# ,