public void ExportAseldMessage() { string json = string.Empty; AseldQuery m = new AseldQuery(); if (!string.IsNullOrEmpty(Request.Params["job_id"])) {//料位開始 m.assg_id = Request.Params["job_id"]; } if (!string.IsNullOrEmpty(Request.Params["aseld_type"])) { m.commodity_type = Request.Params["aseld_type"]; } if (!System.IO.Directory.Exists(Server.MapPath(excelPath))) { System.IO.Directory.CreateDirectory(Server.MapPath(excelPath)); } DataTable dtHZ = new DataTable(); string newExcelName = string.Empty; dtHZ.Columns.Add("出貨單號", typeof(String)); dtHZ.Columns.Add("訂單編號", typeof(String)); dtHZ.Columns.Add("料位", typeof(String)); dtHZ.Columns.Add("數量", typeof(String)); dtHZ.Columns.Add("已撿", typeof(String)); dtHZ.Columns.Add("缺", typeof(String)); dtHZ.Columns.Add("品號", typeof(String)); dtHZ.Columns.Add("條碼", typeof(String)); dtHZ.Columns.Add("商品名稱", typeof(String)); dtHZ.Columns.Add("狀態", typeof(String)); dtHZ.Columns.Add("規格", typeof(String)); try { DataTable dt = new DataTable(); _iasdMgr = new AseldMgr(mySqlConnectionString); _IiupcMgr = new IupcMgr(mySqlConnectionString); dt = _iasdMgr.ExportAseldMessage(m); foreach (DataRow item in dt.Rows) { DataRow dr = dtHZ.NewRow(); dr[0] = item["deliver_code"]; dr[1] = item["ord_id"]; //dr[1] = item["sel_loc"]; if (string.IsNullOrEmpty(item["loc_id"].ToString())) { switch (item["commodity_type"].ToString()) { case "2": dr[2] = "YY999999"; break; case "3": dr[2] = "ZZ999999"; break; } } else { dr[2] = item["loc_id"]; } dr[3] = item["out_qty"]; dr[4] = string.Empty; dr[5] = string.Empty; dr[6] = item["item_id"]; dr[7] = " " + _IiupcMgr.Getupc(item["item_id"].ToString(), "0"); dr[8] = item["product_name"]; dr[9] = item["wust_id"]; dr[10] = item["prod_sz"]; dtHZ.Rows.Add(dr); } string str = "撿貨報表by料位"; if (!string.IsNullOrEmpty(m.assg_id)) { if (m.assg_id.IndexOf('N') == 0) { str = m.assg_id + "(常溫/"; } else if (m.assg_id.IndexOf('N') != 0 && m.assg_id.IndexOf('F') == 0) { str = m.assg_id + "(冷凍/"; } } if (m.commodity_type == "2") { str = str + "寄倉)"; } else if (m.commodity_type == "3") { str = str + "調度)"; } string fileName = str + DateTime.Now.ToString("_yyyyMMddHHmmss") + ".xls"; MemoryStream ms = ExcelHelperXhf.ExportDT(dtHZ, str + "_" + DateTime.Now.ToString("yyyyMMddHHmmss")); Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName); Response.BinaryWrite(ms.ToArray()); } 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:[]}"; } }