/// <summary> /// 导出报表类型:Sales by Product /// </summary> /// <param name="model"></param> /// <returns></returns> public String ExportReportByProductList(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 = "SKUOrder"; break; case 2: //order by SKUName OrderBy = "ProductName"; break; case 3: // SalesTotal OrderBy = "SalesTotal"; break; case 4: // UnitesSold OrderBy = "UnitsSold"; break; case 5: //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_ReportByProduct_SP(model.SKUOrder, model.ProductName, model.Channel, model.Brand, model.StartTime, model.EndTime, OrderBy, OrderType).AsEnumerable(); StringBuilder sw = new StringBuilder("SKUOrder,Product Name,Sales Totals ,Units Sold,Avg.Sale Amount"); sw.AppendLine(); //直接从DB读取转化为String返回去,少了一层实体类的转化,减少性能损耗.... // Lee 2013年10月17日17:14:00 foreach (Excel_ReportByProduct_SP_Result r in res) { sw.Append(r.SKUOrder).Append(","); sw.Append(r.ProductName.Replace(",", "-")).Append(","); sw.Append(r.SalesTotal.ConvertToNotNull().ToString("C", new CultureInfo("en-US")).Replace(",", "")).Append(","); sw.Append(r.UnitsSold).Append(","); sw.Append(r.AvgAmont.ConvertToNotNull().ToString("C", new CultureInfo("en-US")).Replace(",", "")).Append(","); sw.AppendLine(); } return(sw.ToString()); } }