/// <summary> /// 匯出yahoo出貨當 /// </summary> public void OutChannelOrderCSV() { DeliverMasterQuery query = new DeliverMasterQuery(); _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString); try { int totalCount = 0; string condition = Request.Params["condition"]; string content = Request.Params["content"]; string deliverystore = Request.Params["delivery_store"]; string channel = Request.Params["channel"]; string ddstatus = Request.Params["delivery_status"]; string retrieve_mode = Request.Params["retrieve_mode"]; string datequery = Request.Params["datequery"]; string starttime = Request.Params["time_start"]; string endtime = Request.Params["time_end"]; query.IsPage = false; if (condition != "0") { if (!string.IsNullOrEmpty(content)) { switch (condition) { case "1": query.od_order_id = uint.Parse(content); break; case "2": query.channel_order_id = content; break; case "3": query.sub_order_id = content; break; default: break; } } } if (deliverystore != "0" && !string.IsNullOrEmpty(deliverystore)) { query.delivery_store = uint.Parse(deliverystore); } if (channel != "0" && !string.IsNullOrEmpty(channel)) { query.channel = int.Parse(channel); } if (ddstatus != "-1") { query.dd_status = int.Parse(ddstatus); } if (retrieve_mode != "-1" && !string.IsNullOrEmpty(retrieve_mode)) { query.retrieve_mode = int.Parse(retrieve_mode); } if (datequery != "0") { if (!string.IsNullOrEmpty(starttime)) { starttime = DateTime.Parse(starttime).ToString("yyyy-MM-dd HH:mm:ss"); query.sqlwhere = " and dm.delivery_date >='" + starttime + "'"; } if (!string.IsNullOrEmpty(endtime)) { endtime = DateTime.Parse(endtime).ToString("yyyy-MM-dd") + " 23:59:59"; query.sqlwhere += " and dm.delivery_date <='" + endtime + "'"; } } object ob = _DeliverDetailMgr.GetChannelOrderList(query, out totalCount, 1); DataTable channelorder = new DataTable(); if (ob.GetType() == typeof(DataTable)) { channelorder = (DataTable)ob; } //DataTable newchannel = channelorder.DefaultView.ToTable(false, new string[] { "sub_order_id", "delivery_code" }); // newchannel.Columns["delivery_store"].Expression = " IIF (delivery_store <> 11,11,11)"; DataColumn dcol = new DataColumn("delivery_store", typeof(String)); dcol.DefaultValue = 11; channelorder.Columns.Add(dcol); channelorder.Columns["delivery_store"].SetOrdinal(1); //dcol.Expression = " IIF (delivery_store <> 11,11,11)"; DataColumn col = new DataColumn("ok", typeof(String)); col.DefaultValue = "OK"; channelorder.Columns.Add(col); string fileName = string.Empty; string newName = string.Empty; fileName = "channel_order_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".csv"; if (!System.IO.Directory.Exists(Server.MapPath(excelPath))) { System.IO.Directory.CreateDirectory(Server.MapPath(excelPath)); } newName = Server.MapPath(excelPath) + fileName; if (System.IO.File.Exists(newName)) { //設置文件的屬性,以防刪除文件的時候因為文件的屬性造成無法刪除 System.IO.File.SetAttributes(newName, FileAttributes.Normal); System.IO.File.Delete(newName); } //StringWriter sw = ExcelHelperXhf.SetCsvFromData(channelorder, fileName); // CsvHelper.ExportDataTableToCsv(channelorder,newName,null,false); StringWriter sw = new StringWriter(); foreach (DataRow dr in channelorder.Rows) { for (int i = 0; i < channelorder.Columns.Count; i++) { sw.Write(dr[i].ToString()); if (i != channelorder.Columns.Count - 1) { sw.Write(","); } } sw.WriteLine(""); } sw.Close(); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName); Response.ContentType = "application/ms-excel"; Response.ContentEncoding = Encoding.Default; Response.Write(sw); Response.End(); } 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 GetChannelOrderList() { string json = String.Empty; List<DeliverMasterQuery> store = new List<DeliverMasterQuery>(); try { DeliverMasterQuery query = new DeliverMasterQuery(); _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString); query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量 query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");//用於分頁的變量 int totalCount = 0; string condition = Request.Params["condition"]; string content = Request.Params["content"]; string deliverystore = Request.Params["delivery_store"]; string channel = Request.Params["channel"]; string ddstatus = Request.Params["delivery_status"]; string retrieve_mode = Request.Params["retrieve_mode"]; string datequery = Request.Params["datequery"]; string starttime = Request.Params["time_start"]; string endtime = Request.Params["time_end"]; if (condition != "0") { if (!string.IsNullOrEmpty(content)) { switch (condition) { case "1": query.od_order_id = uint.Parse(content); break; case "2": query.channel_order_id = content; break; case "3": query.sub_order_id = content; break; default: break; } } } if (deliverystore != "0" && !string.IsNullOrEmpty(deliverystore)) { query.delivery_store = uint.Parse(deliverystore); } if (channel != "0") { query.channel = int.Parse(channel); } if (ddstatus != "-1") { query.dd_status = int.Parse(ddstatus); } if (retrieve_mode != "-1" && !string.IsNullOrEmpty(retrieve_mode)) { query.retrieve_mode = int.Parse(retrieve_mode); } if (datequery != "0") { if (!string.IsNullOrEmpty(starttime)) { starttime = DateTime.Parse(starttime).ToString("yyyy-MM-dd HH:mm:ss"); query.sqlwhere = " and dm.delivery_date >='" + starttime + "'"; } if (!string.IsNullOrEmpty(endtime)) { endtime = DateTime.Parse(endtime).ToString("yyyy-MM-dd") + " 23:59:59"; query.sqlwhere += " and dm.delivery_date <='" + endtime + "'"; } } object ob = _DeliverDetailMgr.GetChannelOrderList(query, out totalCount); if (ob.GetType() == typeof(List<DeliverMasterQuery>)) { store = (List<DeliverMasterQuery>)ob; } IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(store, Formatting.Indented, timeConverter) + "}";//返回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:false,data:[]}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }