public HttpResponseBase GetVendorBand()/*品牌列表*/ { VendorBrand vb = new VendorBrand(); _vbrand = new VendorBrandMgr(mySqlConnectionString); List<VendorBrand> stores = new List<VendorBrand>(); string json = string.Empty; try { DataTable dt = _vbrand.GetBandList(""); for (int i = 0; i < dt.Rows.Count; i++) { vb = new VendorBrand(); vb.Brand_Id = uint.Parse(dt.Rows[i]["brand_id"].ToString()); vb.Brand_Name = dt.Rows[i]["brand_name"].ToString(); stores.Add(vb); } json = "{success:true,data:" + JsonConvert.SerializeObject(stores) + "}";//返回json數據 } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); json = "{success:true,totalCount:0,data:[]}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
/// <summary> /// 品牌營業額統計匯出 /// </summary> /// <returns></returns> public void GetNewOrderRevenueExprot() { string json = string.Empty; try { OrderDetailQuery query = new OrderDetailQuery(); #region 前置查詢條件 if (!string.IsNullOrEmpty(Request.Params["Brand_Id"]))/*品牌編號*/ { query.Brand_Id_In = Request.Params["Brand_Id"]; } if (!string.IsNullOrEmpty(Request.Params["product_manage"]) && Request.Params["product_manage"] != "null")//管理人員 {//獲取管理人 query.product_manage = int.Parse(Request.Params["product_manage"]); } if (!string.IsNullOrEmpty(Request.Params["dateOne"])) { query.time_start = CommonFunction.GetPHPTime(DateTime.Parse(Request.Params["dateOne"]).ToString("yyyy/MM/dd 00:00:00")); } if (!string.IsNullOrEmpty(Request.Params["dateTwo"])) { query.time_end = CommonFunction.GetPHPTime(DateTime.Parse(Request.Params["dateTwo"]).ToString("yyyy/MM/dd 23:59:59")); } long start = query.time_start;//開始時間 long end = query.time_end;//結束時間 if (!string.IsNullOrEmpty(Request.Params["Channel_Id"]) && Request.Params["Channel_Id"] != "null")//賣場 { query.channel = int.Parse(Request.Params["Channel_Id"]); } if (!string.IsNullOrEmpty(Request.Params["slave_status"]) && Request.Params["slave_status"]!="null")//訂單狀態 { query.Status = int.Parse(Request.Params["slave_status"]); } if (!string.IsNullOrEmpty(Request.Params["order_payment"]) && Request.Params["order_payment"] != "null")//付款方式 { query.order_payment = int.Parse(Request.Params["order_payment"]); } if (!string.IsNullOrEmpty(Request.Params["selecttype"]))//關鍵字查詢類型 { query.select_type = int.Parse(Request.Params["selecttype"]); if (!string.IsNullOrEmpty(Request.Params["searchcon"]))//關鍵字查詢內容 { query.select_con = Request.Params["searchcon"]; } } #endregion VendorBrandQuery Vendorbrandquery = new VendorBrandQuery(); Dictionary<uint, VendorBrandQuery> brands = new Dictionary<uint, VendorBrandQuery>();///字典----儲存供應商編號,供應商名稱和錧別,錧別編號的信息 Dictionary<uint, Dictionary<string, Dictionary<string, uint>>> brandDailyTotal = new Dictionary<uint, Dictionary<string, Dictionary<string, uint>>>();///字典,儲存錧別,每天的計算和每天的購物金 ///////////////brand_id//////////daysum,dayduct/////日期///值 List<VendorBrandQuery> aDB_Brand_Select = new List<VendorBrandQuery>(); _vbrand = new VendorBrandMgr(mySqlConnectionString); aDB_Brand_Select = _vbrand.GetBandList(Vendorbrandquery);//把錧別和供應商信息保存到字典里 for (int i = 0; i < aDB_Brand_Select.Count; i++) { if (!brands.Keys.Contains(aDB_Brand_Select[i].Brand_Id)) { brands.Add(aDB_Brand_Select[i].Brand_Id, aDB_Brand_Select[i]); } } bool CrossMonth = CommonFunction.GetNetTime(start).Month == CommonFunction.GetNetTime(end).Month ? false : true; string timelong = ""; while (start <= end)//時間格式化,用來保存每天的小計 { timelong += CommonFunction.GetNetTime(start).ToString("yyyy/MM/dd") + ","; start += 86400; } timelong = timelong.Substring(0, timelong.LastIndexOf(",")); string[] times = timelong.Split(','); Dictionary<string, uint> timetro = new Dictionary<string, uint>(); for (int i = 0; i < times.Count(); i++)//字典加上日期時間 { timetro.Add(times[i], 0); } Dictionary<string, Dictionary<string, uint>> daysum_deduct = new Dictionary<string, Dictionary<string, uint>>();//保存每個商品每日的小計和購物金 daysum_deduct.Add("daysum", timetro);//每日小計 daysum_deduct.Add("daydeduct", timetro);//每日小計 _orderDetailMgr = new OrderDetailMgr(mySqlConnectionString); List<OrderDetailQuery> ordertailList = new List<OrderDetailQuery>(); DataTable _dt = new DataTable(); ordertailList = _orderDetailMgr.GetOrderDetailList(query);//通過查詢條件獲取的數據 string[] quanxuan = query.Brand_Id_In.Split(','); foreach (uint item in brands.Keys) { if (!brandDailyTotal.Keys.Contains(item)) { daysum_deduct = new Dictionary<string, Dictionary<string, uint>>(); timetro = new Dictionary<string, uint>(); for (int a = 0; a < times.Count(); a++)//字典加上日期時間 { timetro.Add(times[a], 0); } daysum_deduct.Add("daysum", timetro);//每日小計 timetro = new Dictionary<string, uint>(); for (int a = 0; a < times.Count(); a++)//字典加上日期時間 { timetro.Add(times[a], 0); } daysum_deduct.Add("daydeduct", timetro);//購物金 brandDailyTotal.Add(item, daysum_deduct); } } //if (ordertailList.Count > 0) //{ for (int i = 0; i < ordertailList.Count; i++) { ordertailList[i].subtotal = ordertailList[i].Single_Money * ordertailList[i].Buy_Num; ordertailList[i].cost = (ordertailList[i].Event_Cost != 0 && ordertailList[i].Single_Cost != ordertailList[i].Single_Money) ? ordertailList[i].Event_Cost : ordertailList[i].Single_Cost; if (!brands.Keys.Contains(ordertailList[i].Brand_Id)) { VendorBrandQuery brand = new VendorBrandQuery(); brand.Vendor_Id = ordertailList[i].Vendor_Id; brand.Brand_Name = ordertailList[i].Brand_Name; brand.Brand_Id = ordertailList[i].Brand_Id; brand.vendor_name_simple = ordertailList[i].Vendor_Name_Simple; brands.Add(ordertailList[i].Brand_Id, brand); } if (!brandDailyTotal.Keys.Contains(ordertailList[i].Brand_Id)) { daysum_deduct = new Dictionary<string, Dictionary<string, uint>>(); timetro = new Dictionary<string, uint>(); for (int a = 0; a < times.Count(); a++)//字典加上日期時間 { timetro.Add(times[a], 0); } daysum_deduct.Add("daysum", timetro);//每日小計 timetro = new Dictionary<string, uint>(); for (int a = 0; a < times.Count(); a++)//字典加上日期時間 { timetro.Add(times[a], 0); } daysum_deduct.Add("daydeduct", timetro);//購物金 brandDailyTotal.Add(ordertailList[i].Brand_Id, daysum_deduct); } string time = CommonFunction.GetNetTime(ordertailList[i].Order_Createdate).ToString("yyyy/MM/dd"); brandDailyTotal[ordertailList[i].Brand_Id]["daysum"][time] += ordertailList[i].subtotal;//每個商品的小計 brandDailyTotal[ordertailList[i].Brand_Id]["daydeduct"][time] += ordertailList[i].Deduct_Bonus;//每個商品的購物金小計 } Dictionary<string, uint> daysum_allbrand = new Dictionary<string, uint>();//所有品牌的每日小計 Dictionary<string, uint> deductsum_allbrand = new Dictionary<string, uint>();//所有品牌的每日購物金 foreach (uint key in brandDailyTotal.Keys) { foreach (string time in brandDailyTotal[key]["daysum"].Keys)//循環每個品牌的每日小計,計算到所有品牌的每日小計 { if (!daysum_allbrand.Keys.Contains(time)) { daysum_allbrand.Add(time, brandDailyTotal[key]["daysum"][time]); } else { daysum_allbrand[time] += brandDailyTotal[key]["daysum"][time]; } } foreach (string time in brandDailyTotal[key]["daydeduct"].Keys)//循環每個品牌的每日購物金小計,計算到所有品牌的每日小計 { if (!deductsum_allbrand.Keys.Contains(time)) { deductsum_allbrand.Add(time, brandDailyTotal[key]["daydeduct"][time]); } else { deductsum_allbrand[time] += brandDailyTotal[key]["daydeduct"][time]; } } } // _dt.Columns.Add("品牌名稱", typeof(String)); _dt.Columns.Add("供應商名稱", typeof(String)); string ym_last = ""; foreach (string it in timetro.Keys) { string ym = it.Substring(0, 7); if (string.IsNullOrEmpty(ym_last)) ym_last = ym; if (!ym_last.Equals(ym)) { _dt.Columns.Add(ym_last.Split('/')[1] + "月小計", typeof(String)); _dt.Columns.Add("購物金(" + ym_last.Split('/')[0] + "/" + ym_last.Split('/')[1] + "月)", typeof(String)); _dt.Columns.Add("扣除購物金(" + ym_last.Split('/')[0] + "/" + ym_last.Split('/')[1] + "月)", typeof(String)); ym_last = ym; } _dt.Columns.Add(it, typeof(String)); _dt.Columns.Add("購物金(" + it + ")", typeof(String)); _dt.Columns.Add("扣除購物金(" + it + ")", typeof(String)); } if (CrossMonth) { _dt.Columns.Add(ym_last.Split('/')[1] + "月小計", typeof(String)); _dt.Columns.Add("購物金(" + ym_last.Split('/')[0] + "/" + ym_last.Split('/')[1] + "月)", typeof(String)); _dt.Columns.Add("扣除購物金(" + ym_last.Split('/')[0] + "/" + ym_last.Split('/')[1] + "月)", typeof(String)); } _dt.Columns.Add("品牌總計", typeof(String)); _dt.Columns.Add(" 購物金總計", typeof(String)); _dt.Columns.Add(" 扣除購物金總計", typeof(String)); DataRow addrow = _dt.NewRow();//添加一行 addrow[0] = " "; addrow[1] = "每日小計"; int r = 2; ym_last = ""; uint sum_monthly = 0;//每月小計 uint deduct_monthly = 0;//每月購物金小計 uint sum_year = 0;//總計 uint deduct_year = 0;//購物金總計 foreach (string it in daysum_allbrand.Keys) { string ym = it.Substring(0, 7); if (string.IsNullOrEmpty(ym_last)) ym_last = ym; if (!ym_last.Equals(ym)) { addrow[r] = sum_monthly; r++; addrow[r] = deduct_monthly; r++; addrow[r] = sum_monthly - deduct_monthly; r++; ym_last = ym; sum_monthly = 0; deduct_monthly = 0; } sum_monthly += daysum_allbrand[it]; deduct_monthly += deductsum_allbrand[it]; sum_year += daysum_allbrand[it]; deduct_year += deductsum_allbrand[it]; addrow[r] = daysum_allbrand[it]; r++; addrow[r] = deductsum_allbrand[it]; r++; addrow[r] = daysum_allbrand[it] - deductsum_allbrand[it]; r++; } if (CrossMonth) { addrow[r] = sum_monthly; r++; addrow[r] = deduct_monthly; r++; addrow[r] = sum_monthly - deduct_monthly; r++; } addrow[r] = sum_year; r++; addrow[r] = deduct_year; r++; addrow[r] = sum_year - deduct_year; _dt.Rows.Add(addrow); foreach (uint it in brandDailyTotal.Keys) { ym_last = ""; sum_monthly = 0; deduct_monthly = 0; sum_year = 0; deduct_year = 0; r = 0; addrow = _dt.NewRow(); if (brands.Keys.Contains(it)) { addrow[r] = brands[it].Brand_Name; r++; addrow[r] = brands[it].vendor_name_simple; r++; } else { addrow[r] = " "; r++; addrow[r] = " "; r++; } foreach (string ite in brandDailyTotal[it]["daysum"].Keys) { string ym = ite.Substring(0, 7); if (string.IsNullOrEmpty(ym_last)) ym_last = ym; if (!ym_last.Equals(ym)) { addrow[r] = sum_monthly; r++; addrow[r] = deduct_monthly; r++; addrow[r] = sum_monthly - deduct_monthly; r++; ym_last = ym; sum_monthly = 0; deduct_monthly = 0; } sum_monthly += brandDailyTotal[it]["daysum"][ite]; sum_year += brandDailyTotal[it]["daysum"][ite]; deduct_monthly += brandDailyTotal[it]["daydeduct"][ite]; deduct_year += brandDailyTotal[it]["daydeduct"][ite]; addrow[r] = brandDailyTotal[it]["daysum"][ite]; r++; addrow[r] = brandDailyTotal[it]["daydeduct"][ite]; r++; addrow[r] = brandDailyTotal[it]["daysum"][ite] - brandDailyTotal[it]["daydeduct"][ite]; r++; } if (CrossMonth) { addrow[r] = sum_monthly; r++; addrow[r] = deduct_monthly; r++; addrow[r] = sum_monthly - deduct_monthly; r++; } addrow[r] = sum_year; r++; addrow[r] = deduct_year; r++; addrow[r] = sum_year - deduct_year; _dt.Rows.Add(addrow); } // } //if (_dt.Rows.Count > 0) //{ //string fileName = "品牌營業額匯出_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"; //MemoryStream ms = ExcelHelperXhf.ExportDT(_dt, ""); //Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName); //Response.BinaryWrite(ms.ToArray()); string fileName = "品牌營業額匯出_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv"; //MemoryStream ms = ExcelHelperXhf.ExportDT(_dt, ""); //Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName); //Response.BinaryWrite(ms.ToArray()); StringWriter sw = ExcelHelperXhf.SetCsvFromData(_dt, fileName); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName); Response.ContentType = "application/ms-excel"; Response.ContentEncoding = Encoding.Default; Response.Write(sw); Response.End(); //} //else //{ // Response.Write("匯出數據不存在"); //} } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); } }
//加購物金欄位 public HttpResponseBase GetOrderRevenue() { string json = string.Empty; string brandserch = "是否单个查询"; StringBuilder sb = new StringBuilder();//查詢訂單的條件 StringBuilder Sbandlist = new StringBuilder();//查詢賣場和管別的條件 OrderBrandProducesQuery oq = new OrderBrandProducesQuery(); uint id; int cid; try { if (!string.IsNullOrEmpty(Request.Params["Brand_Id"]))/*品牌編號*/ { oq.bid = Request.Params["Brand_Id"]; if (oq.bid.Substring(0, 1) != "0") { sb.AppendFormat("and p.brand_id in ({0})", oq.bid); Sbandlist.AppendFormat("and vb.brand_id in ( {0})", oq.bid); } } if (uint.TryParse(Request.Params["product_manage"], out id)) {//獲取管理人 oq.product_manage = id; if (id > 0) { sb.AppendFormat(" AND v.product_manage='{0}'", id); } } if (int.TryParse(Request.Params["channel"], out cid)) {//獲取管理人 oq.channel = cid; if (cid > 0) { sb.AppendFormat(" AND om.channel='{0}'", cid); } } if (uint.TryParse(Request.Params["slave_status"], out id)) {//獲取 訂單狀態 oq.slave_status = id; switch (id) { case 0: sb.AppendFormat(" and os.slave_status in(0,2,4,99,5,6)"); break; default: sb.AppendFormat(" and os.slave_status={0}", id); break; } } if (uint.TryParse(Request.Params["order_payment"], out id)) {//獲取 付款方式 oq.order_payment = id; if (id > 0) { sb.AppendFormat(" and om.order_payment={0}", id); } } if (!string.IsNullOrEmpty(Request.Params["selecttype"])) { oq.selecttype = Request.Params["selecttype"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["searchcon"])) { oq.searchcon = Request.Params["searchcon"].ToString(); if (string.IsNullOrEmpty(oq.searchcon) && oq.searchcon != "null") {//查詢內容不為空就執行模糊查詢 switch (oq.selecttype) { case "1": sb.AppendFormat(" AND od.product_name LIKE '%{0}%'", oq.searchcon); break; case "2"://會員編號 sb.AppendFormat(" AND om.user_id LIKE '%{0}%'", oq.searchcon); break; case "3": sb.AppendFormat(" om.order_name LIKE '%{0}%'", oq.searchcon); break; default: break; } } } string sqlap = sb.ToString(); #region 日期條件 DateTime dtime; if (DateTime.TryParse(Request.Params["dateOne"], out dtime)) { oq.dateOne = DateTime.Parse(dtime.ToString("yyyy-MM-dd 00:00:00")); if (oq.dateOne > DateTime.MinValue) { sb.AppendFormat(" AND om.order_createdate >= '{0}' ", CommonFunction.GetPHPTime(oq.dateOne.ToString())); } } if (DateTime.TryParse(Request.Params["dateTwo"], out dtime)) { oq.dateTwo = DateTime.Parse(dtime.ToString("yyyy-MM-dd 23:59:59")); if (oq.dateTwo > DateTime.MinValue) { sb.AppendFormat(" AND om.order_createdate <= '{0}' ", CommonFunction.GetPHPTime(oq.dateTwo.ToString())); } } #endregion int a = 0; _vbrand = new VendorBrandMgr(mySqlConnectionString); _Iorderbrandproduces = new OrderBrandProducesMgr(mySqlConnectionString); dt = _vbrand.GetBandList(Sbandlist.ToString());//查詢品牌列表 if (string.IsNullOrEmpty(brandserch))//查询所有 { DataTable ds = _Iorderbrandproduces.GetOrderVendorRevenuebyday(sb.ToString(), brandserch);//查詢品牌列表中的營業額,之查詢每天的 #region 没有的品牌添加上 foreach (DataRow item in ds.Rows) { DataRow[] rows = dt.Select("brand_id='" + item["brand_id"] + "' and vendor_id='" + item["vendor_id"] + "'"); if (rows.Count() == 0) { DataRow drr = dt.NewRow(); drr[0] = item["brand_id"]; drr[1] = item["brand_name"]; drr[2] = item["vendor_id"]; drr[3] = item["vendor_name_simple"]; dt.Rows.Add(drr); } } #endregion } string q = a.ToString(); TimeSpan s = oq.dateTwo - oq.dateOne;//查詢的開始日期和結束日期相差的天數 int day = s.Days; #region 測試方法 _Iorderbrandproduces = new OrderBrandProducesMgr(mySqlConnectionString); DataColumn addcolms;//循環添加列每月的統計 DataRow addrow = dt.NewRow();//添加一行每日小計 addrow[3] = "每日小計"; int m = 0;//記錄增加了多少列,來確定每月一記的具體位置 int M_total = 0;//每月一記 StringBuilder html_table = new StringBuilder();//匯出html頁面 html_table.AppendFormat(@"<div style='overflow:auto;text-align:right;width:1650px;height:550px;'><table style='border:1px;'>"); html_table.AppendFormat("<tr><td>品牌名稱</td><td>供應商名稱</td>"); int startclome = 4;//設求每月之初的列的下標,初始為4/。 int stopclome = 3;//每個月結束的列的下標,初始為3/。 #region 循環每天 for (int d = 0; d <= day; d++)//查詢每天 { int D_bandsum = 0; //所有品牌每日的營業額 string daytimes = oq.dateOne.AddDays(d).ToString("yyyy-MM-dd");//循環的每一天 addcolms = new DataColumn(daytimes, typeof(String)); dt.Columns.Add(addcolms); html_table.AppendFormat("<td> {0} </td>", daytimes); stopclome++;//加一列 #region 每日一記 string daytimeone = DateTime.Parse(daytimes).ToString("yyyy-MM-dd 00:00:00");//把每天轉換成初始從零點開始 string daytimetwo = DateTime.Parse(daytimes).ToString("yyyy-MM-dd 23:59:59");//每天的結束時間 string orderby = string.Format(" AND om.order_createdate >= '{0}' AND om.order_createdate <= '{1}'", CommonFunction.GetPHPTime(daytimeone), CommonFunction.GetPHPTime(daytimetwo)); DataTable ds = _Iorderbrandproduces.GetOrderVendorRevenuebyday(sqlap + orderby, brandserch);//查詢品牌列表中的營業額,之查詢每天的 for (int i = 0; i < dt.Rows.Count; i++)//循環品牌列表,把每天的營業額追加進這個表裡 { DataRow[] rows = ds.Select("brand_id='" + dt.Rows[i]["brand_id"] + "' and vendor_id='" + dt.Rows[i]["vendor_id"] + "'");//篩選出一個品牌的這個時間段的營業額 dt.Rows[i][daytimes] = 0;//單個品牌每日的營業額先賦初始值為0 foreach (DataRow row in rows)//篩選出的最多只有一條數據,如果有,加入某個品牌的每日營業額,沒有就為初始值 { if (!string.IsNullOrEmpty(row["order_createdate"].ToString())) { string tb_createdate = CommonFunction.GetNetTime(long.Parse(rows[0]["order_createdate"].ToString())).ToString("yyyy-MM-dd"); dt.Rows[i][daytimes] = int.Parse(rows[0]["subtotal"].ToString()); D_bandsum = D_bandsum + int.Parse(rows[0]["subtotal"].ToString()); } } } #endregion #region 是否添加每月小計 addrow[4 + d + m] = D_bandsum; M_total = M_total + D_bandsum; if (oq.dateOne.Month != oq.dateTwo.Month || oq.dateOne.Year != oq.dateTwo.Year)//開始時間和結束時間不是在同一個月 { DateTime days = DateTime.Parse(daytimes); int t = DateTime.DaysInMonth(days.Year, days.Month);//一個月多少天 if (t == days.Day || d == day)//現在這個月的月底 { addcolms = new DataColumn(days.Month + "月小計", typeof(String));//style='float:left;width:500px' dt.Columns.Add(addcolms); html_table.AppendFormat("<td ><font color='red'> {0}月小計 </font></td>", days.Month); m++; foreach (DataRow item in dt.Rows) { item[stopclome + 1] = 0;//每月總計賦初始值 for (int i = startclome; i <= stopclome; i++)//每個品牌的每月總計 { item[stopclome + 1] = int.Parse(item[stopclome + 1].ToString()) + int.Parse(item[i].ToString()); } } addrow[stopclome + 1] = M_total; startclome = stopclome + 2; stopclome++; M_total = 0; } } #endregion } #endregion dt.Rows.InsertAt(addrow, 0);//添加一行總計 #region 品牌總計 addcolms = new DataColumn("品牌總計", typeof(String)); html_table.AppendFormat("<td><font color='red'>品牌總計</font></td></tr>"); dt.Columns.Add(addcolms); int S_total = 0;//所有品牌的總計 DataTable dstable = _Iorderbrandproduces.GetOrderVendorRevenuebyday(sb.ToString(), brandserch);//查詢品牌列表中的營業額 for (int i = 1; i < dt.Rows.Count; i++) { int Aull_bandSum = 0;//每個商品的開始時間和結束時間的總計 DataRow[] rows = dstable.Select("brand_id='" + dt.Rows[i]["brand_id"] + "' and vendor_id='" + dt.Rows[i]["vendor_id"] + "'");//篩選出一個品牌的這個時間段的營業額 foreach (DataRow row in rows) { if (!string.IsNullOrEmpty(row["subtotal"].ToString())) { Aull_bandSum = Aull_bandSum + int.Parse(row["subtotal"].ToString()); } S_total = S_total + Aull_bandSum; } dt.Rows[i]["品牌總計"] = Aull_bandSum; } dt.Rows[0]["品牌總計"] = S_total; #endregion #endregion #region 要查詢的列表,匯成一張table dt.Columns.RemoveAt(2);//移除多餘的列,供應商編號 dt.Columns.RemoveAt(0);//移除多餘的列,品牌編號 dt.Columns[0].ColumnName = "品牌名稱"; dt.Columns[1].ColumnName = "供應商名稱"; for (int x = 0; x < dt.Rows.Count; x++) { html_table.AppendFormat("<tr>"); for (int y = 0; y < dt.Columns.Count; y++) { if (dt.Columns[y].ColumnName.ToString().IndexOf("月小計") > 0 || dt.Columns[y].ColumnName.ToString() == "品牌總計") { html_table.AppendFormat("<td style='text-align:right'> <font color='red'>{0}</font> </td>", dt.Rows[x][y]); } else { html_table.AppendFormat("<td style='text-align:right'> {0} </td>", dt.Rows[x][y]); } if (y == dt.Columns.Count - 1) { html_table.AppendFormat("</tr>"); } } } html_table.AppendFormat(@"</table></div>"); #endregion string n = html_table.ToString(); json = "{success:true,msg:\"" + html_table.ToString() + "\"}"; } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); json = "{success:false,totalCount:0,data:[]}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase GetNewOrderRevenueList() { string json = string.Empty; try { OrderDetailQuery query = new OrderDetailQuery(); #region 前置查詢條件 if (!string.IsNullOrEmpty(Request.Params["Brand_Id"]))/*品牌編號*/ { query.Brand_Id_In = Request.Params["Brand_Id"]; } if (!string.IsNullOrEmpty(Request.Params["product_manage"]))//管理人員 {//獲取管理人 query.product_manage = int.Parse(Request.Params["product_manage"]); } if (!string.IsNullOrEmpty(Request.Params["dateOne"])) { query.time_start = CommonFunction.GetPHPTime(DateTime.Parse(Request.Params["dateOne"]).ToString("yyyy/MM/dd 00:00:00")); } if (!string.IsNullOrEmpty(Request.Params["dateTwo"])) { query.time_end = CommonFunction.GetPHPTime(DateTime.Parse(Request.Params["dateTwo"]).ToString("yyyy/MM/dd 23:59:59")); } long start = query.time_start;//開始時間 long end = query.time_end;//結束時間 if (!string.IsNullOrEmpty(Request.Params["Channel_Id"]))//賣場 { query.channel = int.Parse(Request.Params["Channel_Id"]); } if (!string.IsNullOrEmpty(Request.Params["slave_status"]))//訂單狀態 { query.Status = int.Parse(Request.Params["slave_status"]); } if (!string.IsNullOrEmpty(Request.Params["order_payment"]))//付款方式 { query.order_payment = int.Parse(Request.Params["order_payment"]); } if (!string.IsNullOrEmpty(Request.Params["selecttype"]))//關鍵字查詢類型 { query.select_type = int.Parse(Request.Params["selecttype"]); if (!string.IsNullOrEmpty(Request.Params["searchcon"]))//關鍵字查詢內容 { query.select_con = Request.Params["searchcon"]; } } #endregion VendorBrandQuery Vendorbrandquery = new VendorBrandQuery(); Dictionary<uint, VendorBrandQuery> brands = new Dictionary<uint, VendorBrandQuery>();///字典----儲存供應商編號,供應商名稱和錧別,錧別編號的信息 Dictionary<uint, Dictionary<string, Dictionary<string, uint>>> brandDailyTotal = new Dictionary<uint, Dictionary<string, Dictionary<string, uint>>>();///字典,儲存錧別,每天的計算和每天的購物金 ///////////////brand_id//////////daysum,dayduct/////日期///值 List<VendorBrandQuery> aDB_Brand_Select = new List<VendorBrandQuery>(); _vbrand = new VendorBrandMgr(mySqlConnectionString); aDB_Brand_Select = _vbrand.GetBandList(Vendorbrandquery);//把錧別和供應商信息保存到字典里 for (int i = 0; i < aDB_Brand_Select.Count; i++) { if (!brands.Keys.Contains(aDB_Brand_Select[i].Brand_Id)) { brands.Add(aDB_Brand_Select[i].Brand_Id, aDB_Brand_Select[i]); } } bool CrossMonth = CommonFunction.GetNetTime(start).Month == CommonFunction.GetNetTime(end).Month ? false : true; string timelong = ""; while (start <= end)//時間格式化,用來保存每天的小計 { timelong += CommonFunction.GetNetTime(start).ToString("yyyy/MM/dd") + ","; start += 86400; } timelong = timelong.Substring(0, timelong.LastIndexOf(",")); string[] times = timelong.Split(','); Dictionary<string, uint> timetro = new Dictionary<string, uint>(); for (int i = 0; i < times.Count(); i++)//字典加上日期時間 { timetro.Add(times[i], 0); } Dictionary<string, Dictionary<string, uint>> daysum_deduct = new Dictionary<string, Dictionary<string, uint>>();//保存每個商品每日的小計和購物金 daysum_deduct.Add("daysum", timetro);//每日小計 daysum_deduct.Add("daydeduct", timetro);//每日小計 _orderDetailMgr = new OrderDetailMgr(mySqlConnectionString); List<OrderDetailQuery> ordertailList = new List<OrderDetailQuery>(); ordertailList = _orderDetailMgr.GetOrderDetailList(query);//通過查詢條件獲取的數據 //if (ordertailList.Count == 0) //{ // json = "{success:true,msg:\"" + "<div style='overflow:auto;text-align:center;width:1650px;height:550px;><p tyle='text-align:center'>~~暫無數據~~</p></div>" + "\"}"; //} //else //{ string[] quanxuan = query.Brand_Id_In.Split(','); foreach (uint item in brands.Keys) { if (!brandDailyTotal.Keys.Contains(item)) { daysum_deduct = new Dictionary<string, Dictionary<string, uint>>(); timetro = new Dictionary<string, uint>(); for (int a = 0; a < times.Count(); a++)//字典加上日期時間 { timetro.Add(times[a], 0); } daysum_deduct.Add("daysum", timetro);//每日小計 timetro = new Dictionary<string, uint>(); for (int a = 0; a < times.Count(); a++)//字典加上日期時間 { timetro.Add(times[a], 0); } daysum_deduct.Add("daydeduct", timetro);//購物金 brandDailyTotal.Add(item, daysum_deduct); } } for (int i = 0; i < ordertailList.Count; i++) { ordertailList[i].subtotal = ordertailList[i].Single_Money * ordertailList[i].Buy_Num; ordertailList[i].cost = (ordertailList[i].Event_Cost != 0 && ordertailList[i].Single_Cost != ordertailList[i].Single_Money) ? ordertailList[i].Event_Cost : ordertailList[i].Single_Cost; if (!brands.Keys.Contains(ordertailList[i].Brand_Id)) { VendorBrandQuery brand = new VendorBrandQuery(); brand.Vendor_Id = ordertailList[i].Vendor_Id; brand.Brand_Name = ordertailList[i].Brand_Name; brand.Brand_Id = ordertailList[i].Brand_Id; brand.vendor_name_simple = ordertailList[i].Vendor_Name_Simple; brands.Add(ordertailList[i].Brand_Id, brand); } if (!brandDailyTotal.Keys.Contains(ordertailList[i].Brand_Id)) { daysum_deduct = new Dictionary<string, Dictionary<string, uint>>(); timetro = new Dictionary<string, uint>(); for (int a = 0; a < times.Count(); a++)//字典加上日期時間 { timetro.Add(times[a], 0); } daysum_deduct.Add("daysum", timetro);//每日小計 timetro = new Dictionary<string, uint>(); for (int a = 0; a < times.Count(); a++)//字典加上日期時間 { timetro.Add(times[a], 0); } daysum_deduct.Add("daydeduct", timetro);//購物金 brandDailyTotal.Add(ordertailList[i].Brand_Id, daysum_deduct); } string time = CommonFunction.GetNetTime(ordertailList[i].Order_Createdate).ToString("yyyy/MM/dd"); brandDailyTotal[ordertailList[i].Brand_Id]["daysum"][time] += ordertailList[i].subtotal;//每個商品的小計 brandDailyTotal[ordertailList[i].Brand_Id]["daydeduct"][time] += ordertailList[i].Deduct_Bonus;//每個商品的購物金小計 } Dictionary<string, uint> daysum_allbrand = new Dictionary<string, uint>();//所有品牌的每日小計 Dictionary<string, uint> deductsum_allbrand = new Dictionary<string, uint>();//所有品牌的每日購物金 foreach (uint key in brandDailyTotal.Keys) { foreach (string time in brandDailyTotal[key]["daysum"].Keys)//循環每個品牌的每日小計,計算到所有品牌的每日小計 { if (!daysum_allbrand.Keys.Contains(time)) { daysum_allbrand.Add(time, brandDailyTotal[key]["daysum"][time]); } else { daysum_allbrand[time] += brandDailyTotal[key]["daysum"][time]; } } foreach (string time in brandDailyTotal[key]["daydeduct"].Keys)//循環每個品牌的每日購物金小計,計算到所有品牌的每日小計 { if (!deductsum_allbrand.Keys.Contains(time)) { deductsum_allbrand.Add(time, brandDailyTotal[key]["daydeduct"][time]); } else { deductsum_allbrand[time] += brandDailyTotal[key]["daydeduct"][time]; } } } StringBuilder html_table = new StringBuilder();//匯出html頁面 html_table.AppendFormat(@"<div style='overflow:auto;text-align:right;width:1590px;height:580px;'><table style='border:0px;'>"); html_table.AppendFormat("<thead style='text-align:center;border-bottom: 1px solid #ccc;color: #000;'><tr><td style='border-bottom: 1px solid #ccc;color: #000;line-height: 1.2em;white-space: nowrap;font-size: 12px; text-align: center; text-align: center;'> 品牌名稱 </td>"); html_table.AppendFormat("<td style='border-bottom: 1px solid #ccc;color: #000;line-height: 1.2em;white-space: nowrap;font-size: 12px; text-align: center; text-align: center;'> 供應商名稱 </td>"); string ym_last = ""; foreach (string it in timetro.Keys) { string ym = it.Substring(0, 7); if (string.IsNullOrEmpty(ym_last)) ym_last = ym; if (!ym_last.Equals(ym)) { html_table.AppendFormat("<td style= 'color: #c00;border-bottom: 1px solid #ccc;line-height: 1.2em;white-space: nowrap;font-size: 12px; text-align: center;'> {0} </td>", ym_last.Split('/')[1] + "月小計"); ym_last = ym; } html_table.AppendFormat("<td style='color: #000;border-bottom: 1px solid #ccc; text-align: center;'> {0} </td>", it); } if (CrossMonth) { html_table.AppendFormat("<td style= 'color: #c00;border-bottom: 1px solid #ccc;line-height: 1.2em;white-space: nowrap;font-size: 12px; text-align: center;'> {0} </td>", ym_last.Split('/')[1] + "月小計"); } html_table.AppendFormat("<td style= 'color: #c00;border-bottom: 1px solid #ccc;line-height: 1.2em;white-space: nowrap;font-size: 12px; text-align: center;'> 品牌總計 </td></tr>"); html_table.AppendFormat("<tr><td colspan='2' style= 'text-align: right;border-bottom: 1px solid #ccc;color: #000;'> 每日小計 </td>"); ym_last = ""; uint sum_monthly = 0; uint sum_year = 0; foreach (string it in daysum_allbrand.Keys) { string ym = it.Substring(0, 7); if (string.IsNullOrEmpty(ym_last)) ym_last = ym; if (!ym_last.Equals(ym)) { html_table.AppendFormat("<td style= 'border-bottom: 1px solid #ccc; text-align: right;color: #c00; '> {0} </td>", sum_monthly); ym_last = ym; sum_monthly = 0; } sum_monthly += daysum_allbrand[it]; sum_year += daysum_allbrand[it]; html_table.AppendFormat("<td style='text-align:right;border-bottom: 1px solid #ccc; '> {0} </td>", daysum_allbrand[it]); } if (CrossMonth) { html_table.AppendFormat("<td style= 'text-align:right;color: #c00;border-bottom: 1px solid #ccc; '> {0} </td>", sum_monthly); } html_table.AppendFormat("<td style= 'text-align:right;color: #c00;border-bottom: 1px solid #ccc; '> {0} </td></tr></thead>", sum_year); html_table.AppendFormat("<tbody>"); foreach (uint it in brandDailyTotal.Keys) { ym_last = ""; sum_monthly = 0; sum_year = 0; if (brands.Keys.Contains(it)) { html_table.AppendFormat("<tr><td style=' white-space: nowrap;text-align:left;line-height: 1.2em;font-size: 12px;'> {0} </td><td style='text-align:left; white-space: nowrap;line-height: 1.2em;font-size: 12px;'> {1} </td>", brands[it].Brand_Name, brands[it].vendor_name_simple); } else { html_table.AppendFormat("<tr><td> {0} </td><td > {1} </td>", " ", " "); } foreach (string ite in brandDailyTotal[it]["daysum"].Keys) { string ym = ite.Substring(0, 7); if (string.IsNullOrEmpty(ym_last)) ym_last = ym; if (!ym_last.Equals(ym)) { html_table.AppendFormat("<td style= 'text-align:right;color: #c00; white-space: nowrap;line-height: 1.2em;font-size: 12px;'> {0} </td>", sum_monthly); ym_last = ym; sum_monthly = 0; } sum_monthly += brandDailyTotal[it]["daysum"][ite]; sum_year += brandDailyTotal[it]["daysum"][ite]; html_table.AppendFormat("<td style='text-align:right;white-space: nowrap;line-height: 1.2em;font-size: 12px;'> {0} </td>", brandDailyTotal[it]["daysum"][ite]); } if (CrossMonth) { html_table.AppendFormat("<td style= 'text-align:right;color: #c00; white-space: nowrap;line-height: 1.2em;font-size: 12px;'> {0} </td>", sum_monthly); } html_table.AppendFormat("<td style= 'text-align:right;color: #c00; white-space: nowrap;line-height: 1.2em;font-size: 12px;'> {0} </td> </tr>", sum_year); } html_table.AppendFormat("</tbody></table>"); json = "{success:true,msg:\"" + html_table.ToString() + "\"}"; } // } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); json = "{success:false,totalCount:0,data:[]}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }