/// <summary> /// 2014年1月15日12:07:13 /// </summary> /// <param name="model"></param> /// <returns></returns> public String ExportReportByChannelList(ReportsModel model) { using (PermaisuriCMSEntities db = new PermaisuriCMSEntities()) { var adapter = (IObjectContextAdapter)db; var objectContext = adapter.ObjectContext; objectContext.CommandTimeout = 5 * 60; // value in seconds List <ReportByProductModel> list = new List <ReportByProductModel>(); String OrderType = "asc"; String OrderBy = "UnitsSold"; if (model.OrderType > 0) { OrderType = "desc"; } if (model.OrderBy > 0) { switch (model.OrderBy) { case 1: //order by SKUOrder OrderBy = "ChannelName"; break; case 2: // SalesTotal OrderBy = "SalesTotal"; break; case 3: // UnitesSold OrderBy = "UnitsSold"; break; case 4: //AvgAmount OrderBy = "AvgAmount"; break; default: OrderBy = "UnitsSold"; break; } } //var res = db.Excel_ReportByProduct_SP(model.Channel, model.Brand, model.StartTime, model.EndTime, OrderBy, OrderType).ToList().AsEnumerable(); var res = db.Excel_ReportByChannel_SP(model.Channel, model.Brand, model.StartTime, model.EndTime, OrderBy, OrderType).AsEnumerable(); StringBuilder sw = new StringBuilder("Channel,Sales Totals ,Units Sold, Avg.Sale Amount"); sw.AppendLine(); //直接从DB读取转化为String返回去,少了一层实体类的转化,减少性能损耗.... // Lee 2013年10月17日17:14:00 foreach (Excel_ReportByChannel_SP_Result r in res) { sw.Append(r.ChannelName).Append(","); sw.Append(r.SalesTotal.ConvertToNotNull().ToString("C", new CultureInfo("en-US")).Replace(",", "")).Append(","); sw.Append(r.UnitsSold.ConvertToNotNull()).Append(","); sw.Append(r.AvgAmont.ConvertToNotNull().ToString("C", new CultureInfo("en-US")).Replace(",", "")).Append(","); sw.AppendLine(); } return(sw.ToString()); } }