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 ("prepare to send an email ...... "); String emailSubject =" "; string emailBody =" "; DataSet ds = new DataSet (); // emailSubject = beginDate. toString ("MM dd, yyyy") + "to" + endDate. toString ("MM dd, yyyy") + "Unsettled customer service settlement information table (Trial)"; emailSubject = endDate. toString ("MM dd, yyyy") + "un-registered user Rescue"; 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 ("query failed ...... "+ E);} EMail email = new EMail (); // if data exists, write the data into EXCEL if (ds = null) {emailBody =" failed to connect to the database! ";} Else if (ds. tables [0]. rows. count> 0) {try {// construct the standard DataGrid for user data import and bind the data; System. web. UI. webControls. dataGrid dg = new System. web. UI. webControls. dataGrid (); dg. dataSource = ds. tables [0]; dg. dataBind (); // write data to the process in EXCEL. exportDataGridToExcel (dg, excel); emailBody = beginDate. toString ("MM dd, yyyy") + ConfigurationSettings. appSettings ["Hour2"]. trim () + "Hour" + ConfigurationSettings. appSetting S ["Minute2"]. trim () + "Minute to" + endDate. toString ("MM dd, yyyy") + ConfigurationSettings. appSettings ["Hour2"]. trim () + "Hour" + ConfigurationSettings. appSettings ["Minute2"]. for more information about Trim () + "Minute" + ", see the attachment. (Please do not reply to this email) "; email. Attach = excel;} catch (Exception e) {objSysRunLog. WriteLog (" EXCEL writing failed ...... "+ E. toString () ;}} else {emailBody = beginDate. toString ("MM dd, yyyy") + ConfigurationSettings. appSettings ["Hour2"]. trim () + "Hour" + ConfigurationSettings. appSettings ["Minute2"]. trim () + "Minute to" + endDate. toString ("MM dd, yyyy") + ConfigurationSettings. appSettings ["Hour2"]. trim () + "Hour" + ConfigurationSettings. appSettings ["Minute2"]. no data in Trim () + "Minute" + "time. (Please do not reply to this email) ";} try {email. to = ConfigurationSettings. appSettings ["MailTo2"]. trim (); email. subject = emailSubject; email. body = emailBody; email. send (); objSysRunLog. writeLog ("email sent successfully:");} catch (Exception e) {objSysRunLog. writeLog ("failed to send email:" + 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 = daynum; myCMD. parameters. add ("V_RESULT", OracleType. cursor); myCMD. parameters ["V_RESULT"]. direction = ParameterDirection. output; myCMD. parameters. add ("RETURN_CODE", OracleType. int32); myCMD. parameters ["RETURN_CODE"]. direction = ParameterDirection. output; myCMD. parameters. add ("RETURN_TEXT", OracleType. (VarChar, 100); myCMD. parameters ["RETURN_TEXT"]. direction = ParameterDirection. output; myConn. open (); myCMD. connection = myConn; OracleDataAdapter myAdapter = new OracleDataAdapter (myCMD); DataSet ds = new DataSet (); try {myAdapter. fill (ds);} catch (Exception exp) {result = "An error occurred while connecting to the database:" + exp. toString (); ds = null;} finally {if (ConnectionState. open = myConn. state) {myConn. close () ;}} return ds ;}