Exemplo n.º 1
0
        /// <summary>
        /// 對表中的數據進行更新
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase UpdateStock()
        {
            string json = string.Empty;
            ProductItem pi;
            try
            {
                // json = "{success:true,data:" + JsonConvert.SerializeObject(stores, Formatting.Indented) + "}";
                _pStockMgr = new ProductStockImportMgr(connectionString);
                // _pSpecStatusMgr = new ProductSpecMgr(connectionString);
                int i = 0;
                int j = 0;
                foreach (var item in productStockStores)
                {
                    pi = new ProductItem();
                    if (!string.IsNullOrEmpty(item.item_id))
                    {
                        pi.Item_Id = uint.Parse(item.item_id.Trim());
                    }
                    if (!string.IsNullOrEmpty(item.item_alarm))
                    {
                        pi.Item_Alarm = uint.Parse(item.item_alarm.Trim());
                    }
                    //非寄倉、非買斷商品更新庫存和警告值 +備註
                    if (item.type == 0)
                    {
                        if (!string.IsNullOrEmpty(item.item_stock))
                        {
                            pi.Item_Stock = int.Parse(item.item_stock.Trim());
                        }
                        if (!string.IsNullOrEmpty(item.remark))
                        {
                            pi.Remark = item.remark;
                        }
                        i += _pStockMgr.UpdateStock(pi);
                    }
                    //寄倉、買斷商品只更新警告值,+備註
                    else
                    {
                        pi.Item_Stock = 999999999;
                        if (!string.IsNullOrEmpty(item.remark))
                        {
                            pi.Remark = item.remark;
                        }
                        j += _pStockMgr.UpdateStock(pi);
                    }
                    //if (item.spec_status == "顯示")
                    //{
                    //    item.spec_status = "1";
                    //}
                    //else if (item.spec_status == "隱藏")
                    //{
                    //    item.spec_status = "0";
                    //}
                    //else
                    //{
                    //    item.spec_status = string.Empty;
                    //}
                    //if (item.spec_status2 == "顯示")
                    //{
                    //    item.spec_status2 = "1";
                    //}
                    //else if (item.spec_status2 == "隱藏")
                    //{
                    //    item.spec_status2 = "0";
                    //}
                    //else
                    //{
                    //    item.spec_status2 = string.Empty;
                    //}
                    //_pSpecStatusMgr.Updspecstatus(item);
                }
                json = "{success:true,msg:\"" + "匯入成功!<br/>非寄倉、非買斷商品更新" + i + "條,<br/>寄倉、買斷商品更新" + j + "條。\"}";
            }
            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,msg:\"" + "匯入失敗!" + "\"}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 上傳文件,匯入到datatable里
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase UploadExcel()
        {
            string newName = string.Empty;
            string json = string.Empty;
            productStockStores = new List<ProductStockQuery>();
            try
            {
                if (Request.Files["ImportExcelFile"] != null && Request.Files["ImportExcelFile"].ContentLength > 0)
                {
                    HttpPostedFileBase excelFile = Request.Files["ImportExcelFile"];
                    //FileManagement fileManagement = new FileManagement();
                    newName = Server.MapPath(excelPath) + excelFile.FileName;
                    excelFile.SaveAs(newName);
                    DataTable dt = new DataTable();
                    NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newName);
                    dt = helper.SheetData();
                    if (dt.Rows.Count > 0)
                    {
                        ProductStockQuery ps;
                        _pStockMgr = new ProductStockImportMgr(connectionString);
                        foreach (DataRow dr in dt.Rows)
                        {
                            ps = new ProductStockQuery();
                            ps.item_id = dr["細項編號"].ToString();
                            ps.product_id = dr["商品編號"].ToString();
                            ps.item_stock = dr["庫存"].ToString();
                            ps.item_alarm = dr["警告值"].ToString();
                            ps.product_name = dr["商品名稱"].ToString();
                            ps.spec_name1 = dr["規格1"].ToString();
                            ps.spec_name2 = dr["規格2"].ToString();
                            ps.product_mode = dr["出貨方式"].ToString();
                            ps.prepaid = dr["已買斷商品"].ToString();
                            ps.spec_status = dr["規格1顯示狀態"].ToString();
                            ps.spec_status2 = dr["規格2顯示狀態"].ToString();
                            //if (ps.spec_status == "顯示")
                            //{
                            //    ps.spec_status = "1";
                            //}
                            //else if (ps.spec_status == "隱藏")
                            //{
                            //    ps.spec_status = "0";
                            //}
                            //else {
                            //    ps.spec_status = string.Empty;
                            //}
                            //if (ps.spec_status2 == "顯示")
                            //{
                            //    ps.spec_status2 = "1";
                            //}
                            //else if (ps.spec_status2 == "隱藏")
                            //{
                            //    ps.spec_status2 = "0";
                            //}
                            //else
                            //{
                            //    ps.spec_status2 = string.Empty;
                            //}
                            ps.remark = dr["備註"].ToString();

                            if (dr[11].ToString() == "寄倉" || dr[12].ToString() == "是")
                            {
                                ps.type = 1;
                            }
                            productStockStores.Add(ps);
                        }
                    }
                    json = "{success:true,data:" + JsonConvert.SerializeObject(productStockStores, Formatting.Indented) + "}";
                }
            }
            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:" + "" + "}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }