예제 #1
0
        public HttpResponseBase GetCountBookOBK()
        {
            string json = string.Empty;
            IinvdQuery m = new IinvdQuery();
            CbjobMaster cm = new CbjobMaster();
            CbjobDetail cd = new CbjobDetail();
            try
            {
                #region 條件
                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();
                }
                if (!string.IsNullOrEmpty(Request.Params["startcost"]))//金額
                {
                    m.startcost = int.Parse(Request.Params["startcost"].ToString());
                }
                if (!string.IsNullOrEmpty(Request.Params["endcost"]))//金額
                {
                    m.endcost = int.Parse(Request.Params["endcost"].ToString());
                }
                #endregion

                _iinvd = new IinvdMgr(mySqlConnectionString);
                DataTable dt = _iinvd.CountBookOBK(m);
                if (dt.Rows.Count > 0)
                {
                    #region 生成報表
                    DataTable dtCountBook = new DataTable();
                    dtCountBook.Columns.Add("編號", typeof(String));
                    dtCountBook.Columns.Add("料位", typeof(String));
                    dtCountBook.Columns.Add("狀態", typeof(String));
                    dtCountBook.Columns.Add("商品細項編號", typeof(String));
                    dtCountBook.Columns.Add("成本", typeof(String));
                    dtCountBook.Columns.Add("商品名稱", typeof(String));
                    dtCountBook.Columns.Add("商品規格", typeof(String));
                    dtCountBook.Columns.Add("製造日期", typeof(String));
                    dtCountBook.Columns.Add("有效日期", typeof(String));
                    dtCountBook.Columns.Add("原有數量", typeof(String));
                    dtCountBook.Columns.Add("現有數量", typeof(String));
                    dtCountBook.Columns.Add("差異金額", typeof(String));
                    foreach (DataRow item in dt.Rows)
                    {
                        DataRow dr = dtCountBook.NewRow();
                        dr[0] = item["row_id"];
                        dr[1] = item["loc_id"];
                        dr[2] = item["lsta_id"];
                        dr[3] = item["item_id"];
                        dr[4] = item["cost"];
                        dr[5] = item["product_name"];
                        dr[6] = GetProductSpec(item["item_id"].ToString());
                        dr[7] = DateTime.Parse(item["made_date"].ToString()).ToString("yyyy/MM/dd");
                        dr[8] = DateTime.Parse(item["cde_dt"].ToString()).ToString("yyyy/MM/dd");
                        dr[9] = item["prod_qty"];
                        dr[10] = item["st_qty"];
                        dr[11] = item["money"];
                        dtCountBook.Rows.Add(dr);
                    }
                    #endregion
                    string fileName = "盤點差異報表OBK" + DateTime.Now.ToString("_yyyyMMddHHmmss") + ".xls";
                    String str = "盤點差異報表OBK" + DateTime.Now.ToString("_yyyyMMddHHmmss");
                    MemoryStream ms = ExcelHelperXhf.ExportDT(dtCountBook, str);
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
                    Response.BinaryWrite(ms.ToArray());
                }
                else
                {
                    Response.Clear();
                    this.Response.Write("該範圍內沒有差異數據<br/>");
                }
            }
            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);
            }
            return this.Response;
        }