public void GetReport(string sourceDateBaseStr, DateTime startDate, DateTime stopDate) { OLDBHelper.dataSourceStr = sourceDateBaseStr; OleDbConnection con = recordDao.Begin(); DateTime inputDate = startDate; string outputPath = @".\resultDatas\"; if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } while (DateTime.Compare(inputDate, stopDate) < 0) { List <Record> listsRecordSum = recordDao.FindRecordSumDur(con, inputDate, inputDate.AddDays(1)); HashSet <string> uniqueSub = recordDao.GetUniqueSubject(con, inputDate); //写入CSV文件 using (StreamWriter sw = new StreamWriter(outputPath + inputDate.ToString ("yyyyMMdd") + ".csv", false, Encoding.Default)) { StringBuilder sb = new StringBuilder(); sb.Append("RequestID,BsType,ActionType,MailIncomeDate"); sw.WriteLine(sb.ToString()); for (int i = 0; i < listsRecordSum.Count; i++) { Record recordSum = listsRecordSum[i]; string m_RequestID = recordSum.M_requestID.ToUpper().Trim(); if (m_RequestID.StartsWith("S")) { if (!uniqueSub.Contains(m_RequestID)) { uniqueSub.Add(m_RequestID); sw.WriteLine("\"" + m_RequestID + "\"" + "," + "\"" + recordSum.M_businessType + "\"" + "," + "\"" + recordSum.M_actiontype + "\"" + "," + "\"" + recordSum.M_mailincometime.ToString() + "\""); } } if (m_RequestID.StartsWith("C")) { if (recordSum.M_businessType.ToLower().Trim() == "import") { if (recordSum.M_actiontype.Contains("2") || recordSum.M_actiontype.ToUpper().Contains("IM") || recordSum.M_actiontype.ToUpper().Contains("FL")) { sw.WriteLine("\"" + m_RequestID + "\"" + "," + "\"" + recordSum.M_businessType + "\"" + "," + "\"" + recordSum.M_actiontype + "\"" + "," + "\"" + recordSum.M_mailincometime.ToString() + "\""); } } else if (recordSum.M_businessType.ToLower().Trim() == "export") { if (recordSum.M_actiontype.Contains("1")) { sw.WriteLine("\"" + m_RequestID + "\"" + "," + "\"" + recordSum.M_businessType + "\"" + "," + "\"" + recordSum.M_actiontype + "\"" + "," + "\"" + recordSum.M_mailincometime.ToString() + "\""); } } } } } inputDate = inputDate.AddDays(1); } recordDao.Close(); OLDBHelper.DisposeDB(); }