private void Check_BundleItem(List <BundleItems> bundleItemDatas, List <OrderBundleItem1> SC_BundleItems) { List <BundleItems> bundleItemList = SC_BundleItems.Select(bundleItem => DataProcess.SetBundleItemData(new BundleItems() { IsEnable = true, ID = bundleItem.ID }, bundleItem)).ToList(); // New item data IEnumerable <BundleItems> newBundleItem = bundleItemList.Except(bundleItemDatas); foreach (BundleItems bundleItem in newBundleItem) { BundleItems.Create(bundleItem); } // Old item data IEnumerable <BundleItems> oldBundleItem = bundleItemDatas.Except(bundleItemList); foreach (BundleItems bundleItem in oldBundleItem) { bundleItem.IsEnable = false; BundleItems.Update(bundleItem, bundleItem.ID); } // Update item data IEnumerable <BundleItems> updateBundleItem = bundleItemDatas.Except(oldBundleItem).Except(bundleItemList, new BundleItemComparer()); foreach (BundleItems bundleItem in updateBundleItem) { BundleItems.Update(DataProcess.SetBundleItemData(bundleItem, SC_BundleItems.First(bi => bi.ID == bundleItem.ID)), bundleItem.ID); } }
private void Check_Serial(List <SerialNumbers> serialNumberDatas, List <OrderSerialNumber> SC_SerialNumbers) { List <SerialNumbers> serialNumberList = SC_SerialNumbers.Select(serial => DataProcess.SetSerialNumberData(new SerialNumbers() { }, serial)).ToList(); // New serialNumber data var newSerialNumber = serialNumberList.Except(serialNumberDatas).ToList(); foreach (SerialNumbers serialNumber in newSerialNumber) { SerialNumbers.Create(serialNumber); } // Old serialNumber data var oldSerialNumber = serialNumberDatas.Except(serialNumberList).ToList(); //foreach (SerialNumbers serialNumber in oldSerialNumber) //{ // SerialNumbers.Delete(serialNumber); //} // Update serialNumber data var updateSerialNumber = serialNumberDatas.Except(oldSerialNumber).Except(serialNumberList, new SerialNumberComparer()).ToList(); foreach (SerialNumbers serialNumber in updateSerialNumber) { SerialNumbers.Update(DataProcess.SetSerialNumberData(serialNumber, SC_SerialNumbers.First(s => s.SerialNumber == serialNumber.SerialNumber && s.OrderItemID == serialNumber.OrderItemID))); } }
private void Check_Package(List <Packages> packageDatas, List <Package> SC_Packages) { List <Packages> packageList = SC_Packages.Select(p => DataProcess.SetPackageData(new Packages() { IsEnable = true, ID = p.ID }, p)).ToList(); // New package data IEnumerable <Packages> newPackage = packageList.Except(packageDatas); foreach (Packages package in newPackage) { Packages.Create(package); } // Old package data IEnumerable <Packages> oldPackage = packageDatas.Except(packageList); foreach (Packages package in oldPackage) { package.IsEnable = false; Packages.Update(package, package.ID); } // Update package data IEnumerable <Packages> updatePackage = packageDatas.Except(oldPackage).Except(packageList, new PackageComparer()); foreach (Packages package in updatePackage) { Packages.Update(DataProcess.SetPackageData(package, SC_Packages.First(p => p.ID == package.ID)), package.ID); } }
private void Check_Payment(List <Payments> paymentDatas, List <OrderPayment> SC_Payments) { List <Payments> paymentList = SC_Payments.Select(p => DataProcess.SetPaymentData(new Payments() { IsEnable = true, ID = p.ID }, p)).ToList(); // New payment data IEnumerable <Payments> newPayment = paymentList.Except(paymentDatas); foreach (Payments payment in newPayment) { Payments.Create(payment); } // Old payment data IEnumerable <Payments> oldPayment = paymentDatas.Except(paymentList); foreach (Payments payment in oldPayment) { payment.IsEnable = false; Payments.Update(payment, payment.ID); } // Update payment data IEnumerable <Payments> updatePayment = paymentDatas.Except(oldPayment).Except(paymentList, new PaymentComparer()); foreach (Payments payment in updatePayment) { Payments.Update(DataProcess.SetPaymentData(payment, SC_Payments.First(p => p.ID == payment.ID)), payment.ID); } }
public string Sync_Warehouse() { string Message = ""; try { MyHelp.Log("Warehouses", null, "開始出貨倉資料同步"); if (!SCWS.Is_login) { throw new Exception("SC is not logged in!"); } Warehouses = new GenericRepository <Warehouses>(db); Warehouse[] SC_Warehouse = SCWS.Get_Warehouses(); List <Warehouses> warehouseData = db.Warehouses.AsNoTracking().ToList(); List <Warehouses> WarehouseList = SC_Warehouse.Select(w => DataProcess.SetWarehouseData(new Warehouses() { IsEnable = true, ID = w.ID }, w)).ToList(); IEnumerable <Warehouses> newWarehouse = WarehouseList.Except(warehouseData).ToList(); foreach (Warehouses warehouse in newWarehouse) { Warehouses.Create(warehouse); } IEnumerable <Warehouses> oldWarehouse = warehouseData.Except(WarehouseList); foreach (Warehouses warehouse in oldWarehouse) { warehouse.IsEnable = false; Warehouses.Update(warehouse, warehouse.ID); } IEnumerable <Warehouses> updateWarehouse = warehouseData.Except(oldWarehouse).Except(WarehouseList, new WarehouseComparer()); foreach (Warehouses warehouse in updateWarehouse) { Warehouses.Update(DataProcess.SetWarehouseData(warehouse, SC_Warehouse.First(w => w.ID.Equals(warehouse.ID))), warehouse.ID); } Warehouses.SaveChanges(); MyHelp.Log("Warehouses", null, "完成出貨倉資料同步"); } catch (Exception e) { Message = e.InnerException != null && !string.IsNullOrEmpty(e.InnerException.Message) ? e.InnerException.Message : e.Message; } return(Message); }
private void Check_Order(List <Orders> orderDatas, List <Order> SC_Orders) { List <Orders> orderList = SC_Orders.Select(o => DataProcess.SetOrderData(new Orders() { OrderID = o.ID }, o)).ToList(); // Update order data IEnumerable <Orders> updateOrder = orderDatas.Except(orderList, new OrdersComparer()); foreach (Orders order in updateOrder) { Order orderDetail = SC_Orders.First(o => o.ID == order.OrderID); Address addressDetail = orderDetail.ShippingAddress; Orders.Update(DataProcess.SetOrderData(order, orderDetail), order.OrderID); Addresses.Update(DataProcess.SetAddressData(order.Addresses, addressDetail, orderDetail.BillingAddress), order.ShippingAddress); } }
private void Dispatch(Packages package) { if (Order.StatusCode.Value.Equals((int)OrderStatusCode.InProcess) && Order.PaymentStatus.Equals((int)OrderPaymentStatus.Charged)) { ThreadTask threadTask = new ThreadTask(string.Format("訂單下載 - 自動提交訂單【{0}】至待出貨區", Order.OrderID), Session); MyHelp.Log("Orders", Order.OrderID, string.Format("訂單下載 - 自動提交訂單【{0}】至待出貨區", Order.OrderID), Session); package.ProcessStatus = (int)EnumData.ProcessStatus.鎖定中; Packages.Update(package, package.ID); lock (Factory) { threadTask.AddWork(Factory.StartNew(Session => { threadTask.Start(); string message = ""; using (QDLogisticsEntities db = new QDLogisticsEntities()) { IRepository <Packages> Packages = new GenericRepository <Packages>(db); IRepository <PickProduct> PickProduct = new GenericRepository <PickProduct>(db); Packages packageData = Packages.Get(package.ID); try { HttpSessionStateBase session = (HttpSessionStateBase)Session; SC_WebService SCWS = new SC_WebService("*****@*****.**", "timfromweypro"); if (!SCWS.Is_login) { throw new Exception("SC is not login"); } OrderStateInfo order = SCWS.Get_OrderStatus(packageData.OrderID.Value); if ((int)order.PaymentStatus == package.Orders.PaymentStatus) { ShipProcess shipProcess = new ShipProcess(SCWS); MyHelp.Log("Orders", packageData.OrderID, "提交至待出貨區", session); /***** 上傳Item出貨倉 *****/ var SC_order = SCWS.Get_OrderData(packageData.OrderID.Value).Order; var SC_items = SC_order.Items.Where(i => i.PackageID.Equals(packageData.ID)).ToArray(); foreach (var item in SC_items) { if (!db.Skus.AsNoTracking().Any(s => s.Sku.Equals(item.ProductID))) { throw new Exception(string.Format("系統尚未有品號 {0} 資料!", item.ProductID)); } item.ShipFromWareHouseID = packageData.Items.First(i => i.IsEnable == true && i.ID == item.ID).ShipFromWarehouseID.Value; SCWS.Update_OrderItem(SC_items.First(i => i.ID.Equals(item.ID))); } MyHelp.Log("Orders", packageData.OrderID, "更新訂單包裹的出貨倉", session); /***** 更新客戶地址 *****/ var address = SC_order.ShippingAddress; DataProcess.SetAddressData(packageData.Orders.Addresses, address, SC_order.BillingAddress); /***** 檢查運送國家 *****/ if (!string.IsNullOrEmpty(packageData.Method.CountryData)) { var countryData = JsonConvert.DeserializeObject <Dictionary <string, bool> >(packageData.Method.CountryData); if (!countryData.ContainsKey(packageData.Orders.Addresses.CountryCode.ToUpper())) { throw new Exception(string.Format("訂單【{0}】國家名稱不合,請重新確認", packageData.OrderID)); } if (!countryData[packageData.Orders.Addresses.CountryCode.ToUpper()]) { throw new Exception(string.Format("訂單【{0}】不可寄送至國家{1}", packageData.OrderID, packageData.Orders.Addresses.CountryName)); } } shipProcess.Init(packageData); var result = shipProcess.Dispatch(); if (result.Status) { MyHelp.Log("Orders", packageData.OrderID, "訂單提交完成", session); if (packageData.Items.First(i => i.IsEnable.Value).ShipWarehouses.Name.Equals("TWN")) { int[] itemIDs = packageData.Items.Where(i => i.IsEnable.Value).Select(i => i.ID).ToArray(); List <PickProduct> pickList = PickProduct.GetAll(true).Where(p => itemIDs.Contains(p.ItemID.Value)).ToList(); foreach (Items item in packageData.Items.Where(i => i.IsEnable == true)) { PickProduct pick = pickList.FirstOrDefault(pk => pk.ItemID == item.ID); if (pick != null) { pick.IsEnable = true; pick.IsPicked = false; pick.IsMail = false; pick.QtyPicked = 0; DataProcess.setPickProductData(pick, item); PickProduct.Update(pick, pick.ID); } else { pick = new PickProduct() { IsEnable = true }; DataProcess.setPickProductData(pick, item); PickProduct.Create(pick); } } PickProduct.SaveChanges(); } packageData.ProcessStatus = (int)EnumData.ProcessStatus.待出貨; } else { message = result.Message; packageData.ProcessStatus = (int)EnumData.ProcessStatus.訂單管理; } } else { message = "Payment status is different"; packageData.Orders.StatusCode = (int)OrderStatusCode.OnHold; packageData.ProcessStatus = (int)EnumData.ProcessStatus.訂單管理; } Packages.Update(packageData, packageData.ID); Packages.SaveChanges(); } catch (Exception e) { message = e.InnerException != null && !string.IsNullOrEmpty(e.InnerException.Message) ? e.InnerException.Message : e.Message; packageData.ProcessStatus = (int)EnumData.ProcessStatus.訂單管理; if (!string.IsNullOrEmpty(package.WinitNo)) { Winit_API winit = new Winit_API(); winit.CancelOutboundOrder(package.WinitNo); package.WinitNo = null; } Packages.Update(packageData, packageData.ID); Packages.SaveChanges(); } } return(message); }, Session)); } } }
private void Check_PurchaseItem(List <PurchaseItemReceive> purchaseItemDatas, List <PurchaseItemReceive_All_Response> SC_PurchaseItems) { List <PurchaseItemReceive> purchaseItemList = SC_PurchaseItems.SelectMany(product => product.SerialsList.Select(item => DataProcess.SetPurchaseItemData(new PurchaseItemReceive() { }, item, product.IsRequireSerialScan))).ToList(); // New purchaseItem data IEnumerable <PurchaseItemReceive> newPurchaseItem = purchaseItemList.Except(purchaseItemDatas); var count = newPurchaseItem.Count(); foreach (PurchaseItemReceive purchaseItem in newPurchaseItem) { PurchaseItems.Create(purchaseItem); } // Old purchaseItem data IEnumerable <PurchaseItemReceive> oldPurchaseItem = purchaseItemDatas.Except(purchaseItemList); foreach (PurchaseItemReceive purchaseItem in oldPurchaseItem) { PurchaseItems.Delete(purchaseItem); } }
private void Check_Item(List <Items> itemDatas, List <OrderItem> SC_Items) { List <Items> itemList = SC_Items.Where(i => !i.PackageID.Equals(0)).Select(i => DataProcess.SetItemData(new Items() { IsEnable = true, ID = i.ID }, i)).ToList(); if (SC_Items.Any(i => i.PackageID.Equals(0))) { foreach (OrderItem orderItem in SC_Items.Where(i => i.PackageID.Equals(0)).ToArray()) { Items item = DataProcess.SetItemData(new Items() { IsEnable = true, ID = orderItem.ID }, orderItem); if (SC_Items.Any(i => !i.ID.Equals(orderItem.ID) && i.OrderID.Equals(orderItem.OrderID))) { item.PackageID = SC_Items.First(i => !i.ID.Equals(orderItem.ID) && i.OrderID.Equals(orderItem.OrderID)).PackageID; } if (!item.PackageID.Equals(0)) { itemList.Add(item); } } } // New item data IEnumerable <Items> newItem = itemList.Except(itemDatas); foreach (Items item in newItem) { if (Items.Get(item.ID) != null) { Items.Update(item, item.ID); } else { Items.Create(item); } } // Old item data IEnumerable <Items> oldItem = itemDatas.Except(itemList); foreach (Items item in oldItem) { item.IsEnable = false; Items.Update(item, item.ID); } // Update item data IEnumerable <Items> updateItem = itemDatas.Except(oldItem).Except(itemList, new ItemComparer()); foreach (Items item in updateItem) { Items.Update(DataProcess.SetItemData(item, SC_Items.First(i => i.ID == item.ID)), item.ID); } Check_BundleItem(itemDatas.SelectMany(i => i.BundleItems).ToList(), SC_Items.SelectMany(i => i.BundleItems).ToList()); }
public string Sync_Order(int OrderID) { string Message = ""; try { MyHelp.Log("Orders", OrderID, "訂單資料同步開始", Session); if (!SCWS.Is_login) { throw new Exception("SC is not logged in!"); } OrderStateInfo orderStateInfo = SCWS.Get_OrderStatus(OrderID); if (orderStateInfo == null) { throw new Exception("Not found order!"); } orderData = Orders.Get(OrderID); if (orderData == null) { Addresses address = new Addresses() { IsEnable = true }; Addresses.Create(address); Addresses.SaveChanges(); orderData = new Orders() { OrderID = orderStateInfo.ID, ShippingAddress = address.Id }; Orders.Create(orderData); Orders.SaveChanges(); } if (orderStateInfo.DropShipStatus == DropShipStatusType2.None) { OrderData order = SCWS.Get_OrderData(OrderID); orderData.eBayUserID = order.User.eBayUserID; Order orderDetail = order.Order; DataProcess.SetOrderData(orderData, orderDetail); DataProcess.SetAddressData(orderData.Addresses, orderDetail.ShippingAddress, orderDetail.BillingAddress); Check_Payment(orderData.Payments.Where(p => p.IsEnable.Equals(true)).ToList(), orderDetail.Payments.ToList()); int[] PackageIDs = orderDetail.Items.Select(i => i.PackageID).ToArray(); Check_Package(orderData.Packages.Where(p => p.IsEnable.Equals(true)).ToList(), orderDetail.Packages.Where(p => PackageIDs.Contains(p.ID)).ToList()); Check_Item(orderData.Items.Where(i => i.IsEnable.Equals(true)).ToList(), orderDetail.Items.ToList()); if (orderData.Packages.All(p => p.IsEnable.Value && !p.ProcessStatus.Equals((byte)EnumData.ProcessStatus.待出貨) && !p.ProcessStatus.Equals((byte)EnumData.ProcessStatus.保留中))) { if (orderData.Packages.SelectMany(p => p.Items.Select(i => i.ShipWarehouses)).All(w => !w.WarehouseType.Equals(WarehouseTypeType.DropShip))) { OrderSerialNumber[] SC_SerialNumbers = SCWS.Get_OrderItem_Serial(OrderID); List <SerialNumbers> serialNumberDatas = orderData.Packages.Where(p => p.IsEnable.Value).SelectMany(p => p.Items.Where(i => i.IsEnable.Value).SelectMany(i => i.SerialNumbers)).ToList(); Check_Serial(serialNumberDatas, SC_SerialNumbers.ToList()); } } } else { orderStateInfo.StatusCode = OrderStatusCode.Completed; Update_OrderState(orderData, orderStateInfo); } Orders.Update(orderData); Orders.SaveChanges(); MyHelp.Log("Orders", OrderID, "訂單資料同步完成", Session); } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage); Message = string.Join("; ", errorMessages); } catch (Exception e) { MyHelp.ErrorLog(e, string.Format("訂單【{0}】資料同步失敗", orderData.OrderID), orderData.OrderID.ToString()); Message = e.InnerException != null && !string.IsNullOrEmpty(e.InnerException.Message) ? e.InnerException.Message : e.Message; } return(Message); }