//收貨上架匯出 public void IinvdExcelList() { string json = string.Empty; IinvdQuery iivd = new IinvdQuery(); DataTable dtIinvdExcel = new DataTable(); DateTime dtime = DateTime.Now; _IiupcMgr = new IupcMgr(mySqlConnectionString); try { iivd.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量 iivd.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");//用於分頁的變量 string content = string.Empty; if (!string.IsNullOrEmpty(Request.Params["search_type"])) { iivd.serch_type = int.Parse(Request.Params["search_type"]); if (!string.IsNullOrEmpty(Request.Params["searchcontent"]) && Request.Params["searchcontent"].Trim().Length > 0) { switch (iivd.serch_type) { case 1: case 2: iivd.serchcontent = Request.Params["searchcontent"].Trim(); break; case 3: #region 之後的更改 content = Request.Params["searchcontent"].Replace(',', ',').Replace('|', ',').Replace(' ', ',');//.Replace(' ',',') string[] list = content.Split(','); string test = "^[0-9]*$"; int count = 0;//實現最後一個不加, for (int i = 0; i < list.Length; i++) { if (!string.IsNullOrEmpty(list[i])) { if (Regex.IsMatch(list[i], test)) { count = count + 1; if (count == 1) { iivd.serchcontent = list[i]; } else { iivd.serchcontent = iivd.serchcontent + "," + list[i]; } } else { iivd.serchcontent = iivd.serchcontent + list[i] + ","; } } } #endregion break; default: break; } } } DateTime time; if (DateTime.TryParse(Request.Params["starttime"].ToString(), out time)) { iivd.starttime = DateTime.Parse(time.ToString("yyyy-MM-dd HH:mm:ss")); } if (DateTime.TryParse(Request.Params["endtime"].ToString(), out time)) { iivd.endtime = DateTime.Parse(time.ToString("yyyy-MM-dd HH:mm:ss")); } List<IinvdQuery> store = new List<IinvdQuery>(); _iinvd = new IinvdMgr(mySqlConnectionString); store = _iinvd.GetIinvdExprotList(iivd); #region 列名 dtIinvdExcel.Columns.Add("商品細項編號", typeof(String)); dtIinvdExcel.Columns.Add("商品名稱", typeof(String)); dtIinvdExcel.Columns.Add("數量", typeof(String)); dtIinvdExcel.Columns.Add("有效日期", typeof(String)); dtIinvdExcel.Columns.Add("上架料位", typeof(String)); dtIinvdExcel.Columns.Add("主料位", typeof(String)); dtIinvdExcel.Columns.Add("允收天數", typeof(String)); dtIinvdExcel.Columns.Add("建立日期", typeof(String)); dtIinvdExcel.Columns.Add("建立人員", typeof(String)); dtIinvdExcel.Columns.Add("鎖定狀態", typeof(String)); dtIinvdExcel.Columns.Add("庫鎖原因", typeof(String)); dtIinvdExcel.Columns.Add("店內碼", typeof(String)); dtIinvdExcel.Columns.Add("國際碼", typeof(String)); dtIinvdExcel.Columns.Add("庫鎖備註", typeof(String)); #endregion for (int i = 0; i < store.Count; i++) { string upc = ""; Iupc iu = new Iupc(); DataRow newRow = dtIinvdExcel.NewRow(); newRow[0] = store[i].item_id.ToString(); #region 添加店內碼 if (DateTime.TryParse(store[i].cde_dt.ToString(), out dtime)) { upc = CommonFunction.GetUpc(store[i].item_id.ToString(), store[i].vendor_id.ToString(), dtime.ToString("yyMMdd")); } else { upc = CommonFunction.GetUpc(store[i].item_id.ToString(), store[i].vendor_id.ToString(), dtime.ToString("yyMMdd")); } iu.upc_id = upc; iu.item_id = uint.Parse(store[i].item_id.ToString()); iu.upc_type_flg = "2";//店內碼 iu.create_user = (Session["caller"] as Caller).user_id; string result = _IiupcMgr.IsExist(iu);//是否有重複的條碼 if (result == "0") { _IiupcMgr.Insert(iu); } #endregion newRow[1] = store[i].product_name.ToString(); newRow[2] = store[i].prod_qty.ToString(); newRow[3] = store[i].cde_dt.ToString(); newRow[4] = store[i].plas_loc_id.ToString(); newRow[5] = store[i].loc_id.ToString(); newRow[6] = store[i].cde_dt_var.ToString(); newRow[7] = store[i].create_dtim.ToString(); newRow[8] = store[i].user_name.ToString(); newRow[9] = store[i].ista_id.ToString(); newRow[10] = store[i].qity_name.ToString(); newRow[11] = " " + upc; newRow[12] = " " + store[i].upc_id.ToString(); iivd.item_id = uint.Parse(store[i].item_id.ToString()); iivd.plas_loc_id = store[i].plas_loc_id.ToString(); iivd.made_date = store[i].made_date; if (store[i].ista_id.ToString() == "H") { newRow[13] = _iinvd.remark(iivd); } else { newRow[13] = ""; } dtIinvdExcel.Rows.Add(newRow); } if (dtIinvdExcel.Rows.Count > 0) { string fileName = "收貨上架_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"; MemoryStream ms = ExcelHelperXhf.ExportDT(dtIinvdExcel, "收貨上架_" + DateTime.Now.ToString("yyyyMMddHHmmss")); Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName); Response.BinaryWrite(ms.ToArray()); } 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); } }