public void ExportKucunLockList() { string json = string.Empty; IinvdQuery m = new IinvdQuery(); if (!string.IsNullOrEmpty(Request.Params["startIloc"])) {//料位開始 m.startIloc = Request.Params["startIloc"].ToUpper(); } if (!string.IsNullOrEmpty(Request.Params["endIloc"])) { m.endIloc = Request.Params["endIloc"] + "Z"; m.endIloc = m.endIloc.ToUpper(); } _iinvd = new IinvdMgr(mySqlConnectionString); if (!String.IsNullOrEmpty(Request.Params["item_id"]))//料位和條碼不再通過長度來判斷了 { ////if (Request.Params["item_id"].ToString().Length >= 8) ////{ DataTable dt = new DataTable(); dt = _iinvd.Getprodubybar(Request.Params["item_id"].ToString()); if (dt.Rows.Count > 0) { m.item_id = Convert.ToUInt32(dt.Rows[0]["item_id"].ToString()); } ////} else { int itemid = 0; } //m.upc_id } 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("有效期/FIFO", typeof(String)); dtHZ.Columns.Add("是否買斷", typeof(String)); dtHZ.Columns.Add("條碼", typeof(String)); dtHZ.Columns.Add("庫鎖原因", typeof(String)); dtHZ.Columns.Add("庫鎖備註", typeof(String)); try { List<IinvdQuery> store = new List<IinvdQuery>(); _iinvd = new IinvdMgr(mySqlConnectionString); _IiupcMgr = new IupcMgr(mySqlConnectionString); store = _iinvd.KucunExport(m); foreach (var item in store) { DataRow dr = dtHZ.NewRow(); dr[0] = item.plas_loc_id; dr[1] = item.prod_qty; dr[2] = item.item_id; dr[3] = item.product_name; dr[4] = GetProductSpec(item.item_id.ToString()); dr[5] = item.cde_dt.ToString("yyyy-MM-dd"); dr[6] = item.prepaid == 0 ? "否" : "是"; dr[7] = " " + _IiupcMgr.Getupc(item.item_id.ToString(), "0"); dr[8] = item.parameterName; m.item_id = uint.Parse(item.item_id.ToString()); m.plas_loc_id = item.plas_loc_id.ToString(); m.made_date = item.made_date; if (item.ista_id.ToString() == "H") { dr[9] = _iinvd.remark(m); } else { dr[9] = ""; } dtHZ.Rows.Add(dr); } string fileName = DateTime.Now.ToString("庫存鎖住管理報表_yyyyMMddHHmmss") + ".xls"; MemoryStream ms = ExcelHelperXhf.ExportDT(dtHZ, "庫存鎖住管理報表_" + 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:[]}"; } }