/// <summary> /// 讀取指定路徑的Excel文件 /// </summary> /// <param name="filePath">文件路徑</param> /// <returns>記錄Exel文件內容的List集合</returns> public List<OrdersImport> ReadExcel2Page(string filePath, string template, string model_in) { try { if (!System.IO.File.Exists(filePath)) { return null; } orderImportMgr = new OrderImportMgr(MySqlConnStr, CurChannel.channel_id); //添加 排除條件 排除 空的 廠商編號 和 空的 訂單編號 var tmp = orderImportMgr.ReadExcelMatch<OrdersImport>(filePath, template, model_in).Where(o => o.dmtshxuid != "" && o.chlitpdno != "").ToList(); if (tmp.Count() > 0) { tmp.Where(w => w.dmtshxuid != "" && w.chlitpdno != "").ToList().ForEach(m => { //edit by wangwei0216w 2014/8/15 暫時設置訂購人與收購人是同一個人,默認宅配方式 m.ordpesnm = m.agpesnm; m.shipco = "宅配"; ////移除訂單編號為空的記錄 edit by xinglu0624w //if (string.IsNullOrEmpty(m.chlitpdno) || string.IsNullOrEmpty(m.dmtshxuid)) //{ // order.Remove(m); //} }); } var orderGroup = from g in tmp group g by g.dmtshxuid; // 訂單分組 #region 訂單分組 foreach (var group in orderGroup) { PriceSum = 0;//金額清0 Excel_Price_Sum = 0;//金額清0 var orders = group.ToList(); //組合商品的父商品chlitpdno = 0,只需要計算其父商品Price_sum var o = orders.Find(m => m.chlitpdno == "0"); if (o != null) { Excel_Price_Sum += Convert.ToInt32(o.sumup); orders.Remove(o); tmp.Remove(o); } else { //單一商品需要計算sumup //Int32.Parse(p.qty) * sumup 表示在excel文檔中的總價 購買數量 乘以 單價 orders.ForEach(p => Excel_Price_Sum += Int32.Parse(p.sumup)); // edit by zhuoqin0830w 2015/07/23 } ValidateOrders(orders); #region 數據分析 foreach (var item in orders) { if (item.OrderState == "不可配送") //判斷是否可配送 { item.Msg = Resource.CoreMessage.GetResource("UNDISPATCHING"); continue; } bool oResult = orderImportMgr.IsExistsOrder(item); if (oResult) { orders.FindAll(m => m.dmtshxuid == item.dmtshxuid).ForEach(m => m.Msg = Resource.CoreMessage.GetResource("ORDER_EXISTS")); continue; } ProductItemMap map = orderImportMgr.QueryProductMapping(item); if (map == null) { item.Msg = Resource.CoreMessage.GetResource("PRODUCT_MAP_NOT_EXISTS"); continue; } uint product_id = map.product_id; if (map.item_id != 0) { ProductItem proItem = orderImportMgr.QueryProductItem(Convert.ToUInt32(map.item_id)); if (proItem == null) { item.Msg = Resource.CoreMessage.GetResource("ITEMID_ID_NOT_EXISTS"); continue; } product_id = proItem.Product_Id; } Product pro = product_id == 0 ? null : orderImportMgr.QueryProduct(product_id); if (pro == null) { item.Msg = Resource.CoreMessage.GetResource("PRODUCT_NOT_EXISTS"); continue; } else { if (pro.Combination == 0) { item.Msg = Resource.CoreMessage.GetResource("PRODUCT_NOT_USE_IN_ORDER"); continue; } if (pro.Product_Status != 5 && item.chlitpdno != "6727_13742" && item.chlitpdno != "6727_13743") { item.Msg = Resource.CoreMessage.GetResource("PRODUCT_STATUS_WRONG"); continue; } if (pro.Product_Start != 0 && pro.Product_Start > CommonFunction.GetPHPTime()) { item.Msg = Resource.CoreMessage.GetResource("PRODUCT_TIME_OUT"); continue; } if (pro.Product_End != 0 && pro.Product_End < CommonFunction.GetPHPTime()) { item.Msg = Resource.CoreMessage.GetResource("PRODUCT_TIME_OUT"); continue; } } item.sumup = (map.product_price * (Convert.ToInt32(item.qty))).ToString(); PriceSum += Convert.ToInt32(item.sumup);//累加總金額 } if (PriceSum != Excel_Price_Sum)//則對比金額是否正確 { orders.ForEach(m => { if (m.Msg == "") { m.Msg = Resource.CoreMessage.GetResource("SUM_WRONG"); } }); } #endregion } #endregion return tmp; } catch (Exception ex) { throw new Exception("OrderImportPayEasy-->ReadExcel2Page-->" + ex.Message, ex); } }
public List<OrdersImport> ReadExcel2Page(string filePath, string template, string model_in) { try { if (!System.IO.File.Exists(filePath)) { return null; } orderImportMgr = new OrderImportMgr(MySqlConnStr, CurChannel.channel_id); var tmp = orderImportMgr.ReadExcelMatch<OrdersImport>(filePath, template, model_in).Where(o => o.agpesacttel != "").ToList(); /////移除訂單編號為空的記錄 edit by xinglu0624w //if (tmp.Count() > 0) //{ // tmp.ForEach(m => // { // if (string.IsNullOrEmpty(m.agpesacttel)) // { // tmp.Remove(m); // } // }); //} ValidateOrders(tmp); #region 數據分析 foreach (var item in tmp) { if (item.dsr == "物流服務費" || !string.IsNullOrEmpty(item.Msg)) { continue; } bool oResult = orderImportMgr.IsExistsOrder(item); if (oResult) { tmp.FindAll(m => m.dmtshxuid == item.dmtshxuid).ForEach(m => m.Msg = Resource.CoreMessage.GetResource("ORDER_EXISTS")); continue; } ProductItemMap map = orderImportMgr.QueryProductMapping(item); if (map == null) { item.Msg = Resource.CoreMessage.GetResource("PRODUCT_MAP_NOT_EXISTS"); continue; } uint product_id = map.product_id; if (map.item_id != 0) { ProductItem proItem = orderImportMgr.QueryProductItem(Convert.ToUInt32(map.item_id)); if (proItem == null) { item.Msg = Resource.CoreMessage.GetResource("ITEMID_ID_NOT_EXISTS"); continue; } product_id = proItem.Product_Id; } Product pro = product_id == 0 ? null : orderImportMgr.QueryProduct(product_id); if (pro == null) { item.Msg = Resource.CoreMessage.GetResource("PRODUCT_NOT_EXISTS"); continue; } else { if (pro.Combination == 0) { item.Msg = Resource.CoreMessage.GetResource("PRODUCT_NOT_USE_IN_ORDER"); continue; } if (pro.Product_Status != 5) { item.Msg = Resource.CoreMessage.GetResource("PRODUCT_STATUS_WRONG"); continue; } if (pro.Product_Start != 0 && pro.Product_Start > CommonFunction.GetPHPTime()) { item.Msg = Resource.CoreMessage.GetResource("PRODUCT_TIME_OUT"); continue; } if (pro.Product_End != 0 && pro.Product_End < CommonFunction.GetPHPTime()) { item.Msg = Resource.CoreMessage.GetResource("PRODUCT_TIME_OUT"); continue; } } } #endregion return tmp; } catch (Exception ex) { throw new Exception("OrderImportZero-->ReadExcel2Page-->" + ex.Message, ex); } }