public static int Csvout_S04(string lumpBilledNum)
{
string fileName = null;
StringBuilder sb = new StringBuilder();
sb.Append("SELECT ........");
.....
OracleDataReader dr = (OracleDataReader)......ExecuteReader(sb.ToString());
StringBuilder sbCsv = new StringBuilder();
if (dr.HasRows)
{
int count = 0;
for(int t=0; t<dr.FieldCount; t++)
{
if (t != 0)
{
sbCsv.Append(",");
}
sbCsv.Append(dr.GetName(t));
}
sbCsv.Append("/r/n");
while(dr.Read())
{
for(int i=0; i<dr.FieldCount; i++)
{
if (i != 0)
{
sbCsv.Append(",");
}
if (!(dr[i] is DBNull))
{
sbCsv.Append(dr[i].ToString());
}
}
sbCsv.Append("/r/n");
count++;
}
if(count>1)
{
fileName = string.Format("S0403_{0:yyyyMMddhhmmssfff}.csv", DateTime.Now);
}
else
{
fileName = string.Format("S0401_{0:yyyyMMddhhmmssfff}.csv", DateTime.Now);
}
}
dr.Close();
CsvReportCreate(sbCsv.ToString(), fileName);
return 0;
}
//做成CSV
protected static void CsvReportCreate(string CsvInfo, string CsvFileName)
{
try
{
if(CsvInfo.Trim() == String.Empty)
{
return;
}
//名称
string CsvFilePath = Path.Combine(ReportCsv, CsvFileName);
if (!Directory.Exists(ReportCsv))
{
Directory.CreateDirectory(ReportCsv);
}
StreamWriter writer = new StreamWriter(CsvFilePath, false, Encoding.GetEncoding("shift-jis"));
writer.Write(CsvInfo);
writer.Flush();
writer.Close();
}
catch (Exception ex)
{
}
}
//获取config 中PATH
public static string ReportCsv
{
get
{
if (reportCsv == null)
{
reportCsv = ConfigurationSettings.AppSettings["ReportCsv"];
if (reportCsv == null || reportCsv.Trim() == "")
{
log.Error("reportCsv not set");
reportCsv = HttpRuntime.AppDomainAppPath;
log.Info("use default instead: " + reportCsv);
}
}
return reportCsv;
}
set
{
reportCsv = value;
}
}
4953

被折叠的 条评论
为什么被折叠?



