Example #1
0
        public string UpdateERP_ID() {
            string connString = Request.Params["connString"];
            int resut = 0;
            int total_count = 0;
            try
            {
                proItem_Dao = new ProductItemDao(connString);
                pro_Dao = new ProductDao(connString);

                List<Product> proList = pro_Dao.Query(new Product());
                total_count = proList.Count;
                foreach (Product p in proList)
                {
                    try
                    {
                        proItem_Dao.UpdateErpId(p.Product_Id.ToString());
                        resut++;
                    } catch
                    {
                    }
                }
            } catch (Exception ex)
            {
                return string.Format("error:{0}", ex.Message);
            }
            return string.Format("total:{0},updated:{1}", total_count, resut);
        }
Example #2
0
 public ProductMgr(string connectionStr)
 {
     _productDao = new ProductDao(connectionStr);
     _productPicDao = new ProductPictureDao(connectionStr);
     pmDao = new PriceMasterDao(connectionStr);
     pmTSDao = new PriceMasterTsDao(connectionStr);
     puApplyDao = new PriceUpdateApplyDao(connectionStr);
     this.connectionStr = connectionStr;
     _mysqlDao = new MySqlDao(connectionStr);
     productDao = new ProductDao(connectionStr);
     _rProductAttribute = new RecommendedProductAttributeDao(connectionStr);
 }
        public List<ProdDeliverySetImport> Save(string filePath,out string resultPath,ProductDeliverySet deliverySet)
        {
            try
            {
                _productDao = new ProductDao(connectionString);
                List<ProdDeliverySetImport> productAll = ExcelHelperXhf.ReadExcel<ProdDeliverySetImport>(filePath);
                //查詢已經存在的
                List<ProductDeliverySet> existProds = ds.Query(productAll.Select(p => uint.Parse(p.ProductId)).Distinct().ToArray(), deliverySet);

                foreach (var prod in productAll)
                {
                    if (existProds.Find(p => p.Product_id == uint.Parse(prod.ProductId)) != null)
                        prod.Status = 2;//2為存在
                }
                
                List<Product> products = _productDao.Query((from p in productAll where p.Status == 0 select uint.Parse(p.ProductId)).Distinct().ToArray());

                foreach (var prod in productAll.FindAll(p => p.Status == 0))
                {
                    var findProd = products.Find(p => p.Product_Id == uint.Parse(prod.ProductId));
                    if (findProd == null)
                    {
                        prod.Status = 4;//該商品不存在
                    }
                    else if (!findProd.CheckdStoreFreight())
                    {
                        prod.Status = 3;//3為不符合条件
                    }
                }

                //符合條件的
                var fitPords = (from p in productAll
                               where p.Status == 0
                               select new ProductDeliverySet
                                      {
                                          Product_id = int.Parse(p.ProductId),
                                          Freight_big_area = deliverySet.Freight_big_area,
                                          Freight_type = deliverySet.Freight_type
                                      }).Distinct();
                if (fitPords.Count()>0&&Save(fitPords.ToList(), 0))
                {
                    productAll.FindAll(p=>p.Status==0).ForEach(p => p.Status = 1);//1保存成功
                }

                #region 將結果保存到excel
                Dictionary<string, string> columns = new Dictionary<string, string>();
                columns.Add("ProductId", "商品ID");
                columns.Add("BrandName", "品牌名稱");
                columns.Add("ProductName", "商品名稱");
                columns.Add("Msg", "結果");
                
                MemoryStream ms = ExcelHelperXhf.ExportExcel(productAll, columns);
                resultPath=Path.GetDirectoryName(filePath)+"\\result.xls";
                FileStream fs = new FileStream(resultPath, FileMode.Create);
                byte[] data = ms.ToArray();
                fs.Write(data, 0, data.Length);
                fs.Dispose(); 
                #endregion

                return productAll;
            }
            catch (Exception ex)
            {

                throw new Exception("ProductDeliverySetMgr-->Save-->" + ex.Message, ex);
            }
        }
 /// <summary>
 /// 根據上傳的excel批量刪除配送模式
 /// </summary>
 /// <param name="filePath">excel路徑</param>
 /// <param name="deliverySet">要刪除的配送模式</param>
 /// <returns></returns>
 public bool Delete(string filePath,ProductDeliverySet deliverySet)
 {
     try
     {
         _productDao = new ProductDao(connectionString);
         List<ProdDeliverySetImport> productAll = ExcelHelperXhf.ReadExcel<ProdDeliverySetImport>(filePath);
         return Delete(deliverySet, productAll.Select(p => uint.Parse(p.ProductId)).ToArray());
     }
     catch (Exception ex)
     {
         throw new Exception("ProductDeliverySetMgr-->Delete-->" + ex.Message, ex);
     }
 }