Пример #1
0
        public void ExportInoiupc()
        {
            string json = string.Empty;
            IplasQuery m = new IplasQuery();
            if (!string.IsNullOrEmpty(Request.Params["startIloc"]))
            {//料位開始
                m.startloc = Request.Params["startIloc"].ToUpper();
            }
            if (!string.IsNullOrEmpty(Request.Params["endIloc"]))
            {
                m.endloc = Request.Params["endIloc"] + "Z";
                m.endloc = m.endloc.ToUpper();
            }
            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));
            try
            {
                //List<IplasQuery> store = new List<IplasQuery>();
                DataTable _dt = new DataTable();
                _IiplasMgr = new IplasMgr(mySqlConnectionString);

                //store = _IiplasMgr.Export(m);
                _dt = _IiplasMgr.ExportMessage(m);
                foreach (DataRow Drow in _dt.Rows)
                {
                    DataRow dr = dtHZ.NewRow();
                    dr[0] = Drow["loc_id"];
                    dr[1] = Drow["lcat_id"];
                    dr[2] = Drow["item_id"];
                    dr[3] = Drow["prod_qtys"];
                    dr[4] = Drow["product_name"];
                    dr[5] = Drow["prod_sz"];
                    dr[6] = " " + Drow["upc_id"];
                    if (Drow["cde_dt"].ToString() != null && Drow["cde_dt"].ToString().Trim() != "")
                    {
                        dr[7] = DateTime.Parse(Drow["cde_dt"].ToString()).ToString("yyyy-MM-dd");
                    }
                    else
                    {
                        dr[7] = "";
                    }
                    dtHZ.Rows.Add(dr);
                }
                string fileName = DateTime.Now.ToString("無條碼商品報表_yyyyMMddHHmm") + ".xls";
                MemoryStream ms = ExcelHelperXhf.ExportDT(dtHZ, "無條碼商品報表_" + DateTime.Now.ToString("yyyyMMddHHmm"));
                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:[]}";
            }
        }