コード例 #1
0
ファイル: Program.cs プロジェクト: leeleonis/QD
        static void ProductTypeSync()
        {
            Console.WriteLine("--- Start to access ProductType ---");

            List <ProductType> dbProductType = GetProductType();
            List <ProductType> ProductType   = new List <ProductType>();

            Company[] companyList = OS_sellerCloud.ListAllCompany(OS_authHeader, OS_options);
            foreach (Company company in companyList)
            {
                ProductType.AddRange(OS_sellerCloud.ListProductType(OS_authHeader, OS_options, company.ID)
                                     .Select(t => new ProductType()
                {
                    IsEnable = true, ID = t.ID, ProductTypeName = t.ProductTypeName
                }).ToArray());
            }

            Console.WriteLine("--- Get <" + ProductType.Count() + "> ProductType from Sellercloud ---");
            Console.WriteLine("--- End to access ProductType ---");

            IEnumerable <ProductType> newProductType = ProductType.Except(dbProductType);

            Console.WriteLine("--- There are <" + newProductType.Count() + "> new ProductType ---");
            if (newProductType.Any())
            {
                DataProcess.BulkInsert(conn, "ProductType", newProductType.ToList());
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: leeleonis/QD
        static void ManufacturersSync()
        {
            Console.WriteLine("--- Start to access Manufacturers ---");

            List <Manufacturers> dbManufacturers = GetManufacturers();
            List <Manufacturers> Manufacturers   = new List <Manufacturers>();

            Company[] companyList = OS_sellerCloud.ListAllCompany(OS_authHeader, OS_options);
            foreach (Company company in companyList)
            {
                Manufacturers.AddRange(OS_sellerCloud.Manufacturer_ListALL(OS_authHeader, OS_options, company.ID)
                                       .Select(m => new Manufacturers()
                {
                    IsEnable         = true,
                    ID               = m.ID,
                    CompanyID        = m.CompanyID,
                    ManufacturerName = m.ManufacturerName
                }).ToArray());
            }

            Console.WriteLine("--- Get <" + Manufacturers.Count() + "> Manufacturers from Sellercloud ---");
            Console.WriteLine("--- End to access Manufacturers ---");

            IEnumerable <Manufacturers> newManufacturers = Manufacturers.Except(dbManufacturers);

            Console.WriteLine("--- There are <" + newManufacturers.Count() + "> new Manufacturers ---");
            if (newManufacturers.Any())
            {
                DataProcess.BulkInsert(conn, "Manufacturers", newManufacturers.ToList());
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: leeleonis/QD
        static void ServicesSync()
        {
            Console.WriteLine("--- Start to access Services ---");

            List <Services> dbServices = GetServices();
            List <Services> Services   = new List <Services>();

            ShippingServiceInfo[] serviceList = OCS_sellerCloud.ShippingServices_ListAll(OCS_authHeader);
            foreach (ShippingServiceInfo service in serviceList)
            {
                Services.Add(new Services()
                {
                    IsEnable    = true,
                    ServiceCode = service.ServiceMethodID.Trim(),
                    ServiceName = service.ServiceMethodDescription.Trim()
                });
            }

            Console.WriteLine("--- Get <" + Services.Count() + "> Services from Sellercloud ---");
            Console.WriteLine("--- End to access Services ---");

            IEnumerable <Services> newServices = Services.Except(dbServices);

            Console.WriteLine("--- There are <" + newServices.Count() + "> new Services ---");
            if (newServices.Any())
            {
                DataProcess.BulkInsert(conn, "Services", newServices.ToList());
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: leeleonis/QD
        static void PurchaseItemSync(string[] productIDs)
        {
            Console.WriteLine("--- Start to access PurchaseItem ---");

            if (productIDs.Any())
            {
                List <PurchaseItemReceive> dbPurchaseItems  = GetPurchaseItems(productIDs);
                List <PurchaseItemReceive> PurchaseItemList = new List <PurchaseItemReceive>();

                foreach (string productID in productIDs)
                {
                    var serials = OS_sellerCloud.PurchaseItemReceiveSerial_All(OS_authHeader, OS_options, productID);
                    if (serials.SerialsList.Any())
                    {
                        PurchaseItemList.AddRange(serials.SerialsList.Select(s => new PurchaseItemReceive()
                        {
                            IsRequireSerialScan = serials.IsRequireSerialScan,
                            OrderID             = s.OrderID,
                            OrderItemID         = s.OrderItemID,
                            ProductID           = s.ProductID,
                            SerialNumber        = s.SerialNumber.Trim(),
                            PurchaseID          = s.PurchaseID,
                            PurchaseReceiveID   = s.PurchaseReceiveID,
                            RMAId            = s.RMAId,
                            CreditMemoID     = s.CreditMemoID,
                            CreditMemoReason = s.CreditMemoReason.Trim(),
                            WarehouseID      = s.WarehouseID,
                            WarehouseName    = s.WarehouseName.Trim(),
                            LocationBinID    = s.LocationBinID,
                            BinName          = s.BinName.Trim()
                        }).ToArray());
                    }
                }

                Console.WriteLine("--- Get <" + PurchaseItemList.Count() + "> PurchaseItems from Sellercloud ---");
                Console.WriteLine("--- End to access PurchaseItems ---");

                IEnumerable <PurchaseItemReceive> newPurchaseItems = PurchaseItemList.Except(dbPurchaseItems);
                int total = newPurchaseItems.Count();
                Console.WriteLine("--- There are <" + total + "> new PurchaseItems ---");

                if (newPurchaseItems.Any())
                {
                    DataProcess.BulkInsert(conn, "PurchaseItemReceive", newPurchaseItems.ToList());
                }
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: leeleonis/QD
        static void SkusSync()
        {
            Console.WriteLine("--- Start to access Skus ---");

            List <Skus> dbSkus  = GetSkus();
            List <Skus> SkuList = new List <Skus>();
            List <Skus> Skus    = new List <Skus>();

            Company[] companyList = OS_sellerCloud.ListAllCompany(OS_authHeader, OS_options);
            foreach (Company company in companyList)
            {
                SkuList.AddRange(OCS_sellerCloud.Products_ListSKU(OCS_authHeader, company.ID).Select(s => new Skus()
                {
                    Sku = s
                }));
            }

            Console.WriteLine("--- Get <" + SkuList.Count() + "> skus from Sellercloud ---");
            Console.WriteLine("--- End to access Skus ---");

            IEnumerable <Skus> newSkus = SkuList.Except(dbSkus);
            int total = newSkus.Count();

            Console.WriteLine("--- There are <" + total + "> new skus ---");

            if (newSkus.Any())
            {
                int      start = 0, take = 100;
                string[] skuList = newSkus.Select(s => s.Sku).ToArray();
                do
                {
                    Console.WriteLine("--- Take new skus from " + (start + 1) + " to " + (start + take) + " ---");
                    Skus.AddRange(OS_sellerCloud.GetProductFullInfos(OS_authHeader, OS_options, skuList.Skip(start).Take(take).ToArray())
                                  .Select(p => DataProcess.SetSkuData(new Skus()
                    {
                        IsEnable = true, Sku = p.ID, Battery = false, ParentShadow = GetProductParent(p.ID)
                    }, p)));
                } while ((start += take) < total);

                DataProcess.BulkInsert(conn, "Skus", Skus);
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: leeleonis/QD
        static void WarehousesSync()
        {
            Console.WriteLine("--- Start to access Warehouses ---");

            List <Warehouses> dbWarehouses = GetWarehouses();
            List <Warehouses> Warehouses   = new List <Warehouses>();

            OrderCreationService.Warehouse[] warehouseList = OCS_sellerCloud.Warehouse_ListAll(OCS_authHeader);
            foreach (OrderCreationService.Warehouse warehouse in warehouseList)
            {
                Warehouses.Add(new Warehouses()
                {
                    IsEnable   = true,
                    IsDefault  = warehouse.IsDefault,
                    IsSellable = warehouse.IsSellAble,
                    AllowUseQtyForFBAShipments = warehouse.AllowUseQtyForFBAShipments,
                    EnforceBins     = warehouse.EnforceBins,
                    ID              = warehouse.ID,
                    CompanyID       = warehouse.ClientID,
                    Name            = warehouse.Name,
                    QBWarehouseName = warehouse.QBWarehouseName,
                    WarehouseType   = (int)warehouse.WarehouseType,
                    DropShipCentralWarehouseCode = warehouse.DropShipCentralWarehouseCode,
                    CreatedBy = warehouse.CreatedBy,
                    CreatedOn = warehouse.CreatedOn
                });
            }

            Console.WriteLine("--- Get <" + Warehouses.Count() + "> Warehouses from Sellercloud ---");
            Console.WriteLine("--- End to access Warehouses ---");

            IEnumerable <Warehouses> newWarehouses = Warehouses.Except(dbWarehouses);

            Console.WriteLine("--- There are <" + newWarehouses.Count() + "> new Warehouses ---");
            if (newWarehouses.Any())
            {
                DataProcess.BulkInsert(conn, "Warehouses", newWarehouses.ToList());
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: leeleonis/QD
        static void OrdersSync(int day)
        {
            Console.WriteLine("--- Start to access Orderss ---");

            List <Orders>        dbOrders        = GetOrders(day);
            List <Payments>      dbPayments      = new List <Payments>();
            List <Packages>      dbPackages      = new List <Packages>();
            List <Items>         dbItems         = new List <Items>();
            List <SerialNumbers> dbSerialNumbers = new List <SerialNumbers>();
            List <Skus>          dbSkus          = new List <Skus>();

            List <Orders> OrderList = new List <Orders>();

            List <Orders>        Orders        = new List <Orders>();
            List <Addresses>     Addresses     = new List <Addresses>();
            List <Payments>      Payments      = new List <Payments>();
            List <Packages>      Packages      = new List <Packages>();
            List <Items>         Items         = new List <Items>();
            List <BundleItems>   BundleItems   = new List <BundleItems>();
            List <SerialNumbers> SerialNumbers = new List <SerialNumbers>();
            List <Skus>          Skus          = new List <Skus>();

            Console.WriteLine("--- Get Orders from " + Today.AddDays(-day).ToString() + " to " + Today.ToString() + " ---");
            var result = OCS_sellerCloud.SearchOrders(OCS_authHeader, Today.AddDays(-day), Today, "", 0);

            if (result.Rows.Count > 0)
            {
                int[] OrderIDs = result.Rows.Cast <DataRow>().Select(o => (int)o.ItemArray.First()).ToArray();
                OrderList = OS_sellerCloud.Orders_GetOrderStates(OS_authHeader, OS_options, OrderIDs).Where(o => o.DropShipStatus == OrderService.DropShipStatusType1.None)
                            .Select(o => new Orders()
                {
                    OrderID        = o.ID,
                    StatusCode     = (int)o.StatusCode,
                    PaymentStatus  = (int)o.PaymentStatus,
                    ShippingStatus = (int)o.ShippingStatus,
                    IsConfirmed    = o.IsConfirmed,
                    ConfirmBy      = o.ConfirmedBy,
                    ConfirmOn      = o.ConfirmedOn
                }).ToList();
            }

            Console.WriteLine("--- Get <" + OrderList.Count() + "> Orders from Sellercloud ---");
            Console.WriteLine("--- End to access Orders ---");

            IEnumerable <Orders> newOrders = OrderList.Except(dbOrders).Where(n => n.StatusCode != (int)OrderService.OrderStatusCode.Canceled).ToList();

            Console.WriteLine("--- There are <" + newOrders.Count() + "> new Orders ---");
            if (newOrders.Any())
            {
                OrderData[] newOrderList             = OS_sellerCloud.Orders_GetDatas(OS_authHeader, OS_options, newOrders.Select(o => o.OrderID).ToArray());
                Dictionary <int, string> eBayUserIDs = newOrderList.ToDictionary(o => o.OrderPackages.First().OrderID, o => o.User.eBayUserID);
                //Dictionary<int, OrderSerialNumber[]> serialNumbers = newOrderList.ToDictionary(o => o.Order.ID, o=> o.Serials);

                foreach (Orders order in newOrders)
                {
                    OrderCreationService.Order orderDetail = OCS_sellerCloud.GetOrderFull(OCS_authHeader, order.OrderID);

                    Addresses address = new Addresses()
                    {
                        Id = DataProcess.InsertAddress(conn)
                    };
                    Addresses.Add(DataProcess.SetAddressData(address, orderDetail.ShippingAddress));

                    order.ShippingAddress = address.Id;
                    order.eBayUserID      = eBayUserIDs[order.OrderID];
                    Orders.Add(DataProcess.SetOrderData(order, orderDetail));

                    foreach (OrderCreationService.OrderPayment paymentDetail in orderDetail.Payments)
                    {
                        Payments payment = new Payments()
                        {
                            IsEnable = true, ID = paymentDetail.ID
                        };
                        Payments.Add(DataProcess.SetPaymentData(payment, paymentDetail));
                    }

                    foreach (OrderCreationService.Package packageDetail in orderDetail.Packages)
                    {
                        Packages package = new Packages()
                        {
                            IsEnable = true, ID = packageDetail.ID
                        };
                        Packages.Add(DataProcess.SetPackageData(package, packageDetail));
                    }

                    ExistingOrderInfo orderInfo = OCS_sellerCloud.GetOrder(OCS_authHeader, order.OrderID);
                    foreach (OrderCreationService.OrderItem itemDetail in orderDetail.Items)
                    {
                        Items item = orderInfo.Items
                                     .Select(i => new Items()
                        {
                            IsEnable = true, ID = i.OrderItemUniqueIDInDB, SKU = i.SKU.Trim(), DisplayName = i.ItemName, UnitPrice = i.UnitPrice
                        })
                                     .First(i => i.ID == itemDetail.ID);
                        Items.Add(DataProcess.SetItemData(item, itemDetail));
                        Skus.Add(DataProcess.SetSkuData(
                                     new Skus()
                        {
                            IsEnable = true, Sku = item.ProductID, Battery = false, ParentShadow = GetProductParent(item.ProductID)
                        },
                                     OS_sellerCloud.GetProductFullInfo(OS_authHeader, OS_options, item.ProductID)));

                        if (itemDetail.KitItemsCount > 0)
                        {
                            foreach (OrderCreationService.OrderBundleItem bundleDetail in itemDetail.BundleItems)
                            {
                                BundleItems bundle = new BundleItems()
                                {
                                    IsEnable = true, ID = bundleDetail.ID
                                };
                                BundleItems.Add(DataProcess.SetBundleData(bundle, bundleDetail));
                                Skus.Add(new Skus()
                                {
                                    IsEnable = true, Sku = bundleDetail.ProductID, ProductName = bundleDetail.ProductName, Brand = 0, Battery = false
                                });
                            }
                        }
                    }
                }
                DataProcess.BulkInsert(conn, "Orders", Orders);
            }

            IEnumerable <Orders> updateOrders = OrderList.Except(OrderList.Except(dbOrders)).Except(dbOrders, new OrdersComparer()).ToList();

            Console.WriteLine("--- There are <" + updateOrders.Count() + "> Orders need to update ---");
            if (updateOrders.Any())
            {
                foreach (Orders order in updateOrders)
                {
                    OrderCreationService.Order orderDetail = OCS_sellerCloud.GetOrderFull(OCS_authHeader, order.OrderID);

                    Addresses address = new Addresses()
                    {
                        Id = dbOrders.Where(o => o.OrderID == order.OrderID).FirstOrDefault().ShippingAddress.Value
                    };
                    Addresses.Add(DataProcess.SetAddressData(address, orderDetail.ShippingAddress));

                    dbPayments = GetPayments(dbPayments, order.OrderID);
                    foreach (OrderCreationService.OrderPayment PaymentDetail in orderDetail.Payments)
                    {
                        Payments Payment = new Payments()
                        {
                            ID = PaymentDetail.ID
                        };
                        Payments.Add(DataProcess.SetPaymentData(Payment, PaymentDetail));
                    }

                    dbPackages = GetPackages(dbPackages, order.OrderID);
                    foreach (OrderCreationService.Package packageDetail in orderDetail.Packages)
                    {
                        Packages package = new Packages()
                        {
                            ID = packageDetail.ID
                        };
                        Packages.Add(DataProcess.SetPackageData(package, packageDetail));
                    }

                    dbItems = GetItems(dbItems, order.OrderID);
                    foreach (OrderCreationService.OrderItem itemDetail in orderDetail.Items)
                    {
                        Items item = new Items()
                        {
                            ID = itemDetail.ID
                        };
                        Items.Add(DataProcess.SetItemData(item, itemDetail));
                    }

                    dbSerialNumbers = GetSerialNumbers(dbSerialNumbers, order.OrderID);
                    foreach (OrderSerialNumber serialNumberDetail in OS_sellerCloud.Serials_ListFor(OS_authHeader, OS_options, order.OrderID))
                    {
                        SerialNumbers serialNumber = new SerialNumbers();
                        SerialNumbers.Add(DataProcess.SetSerialNumberData(serialNumber, serialNumberDetail));
                    }
                }

                DataTable orderTable = ToDataTable(updateOrders.Select(o => new
                {
                    OrderID        = o.OrderID,
                    StatusCode     = o.StatusCode,
                    PaymentStatus  = o.PaymentStatus,
                    ShippingStatus = o.ShippingStatus,
                    IsConfirmed    = o.IsConfirmed,
                    ConfirmBy      = o.ConfirmBy,
                    ConfirmOn      = o.ConfirmOn
                }).ToList());

                DataProcess.BatchUpdate(conn, orderTable, "OrderData");
            }

            if (Addresses.Any())
            {
                DataProcess.BatchUpdate(conn, ToDataTable(Addresses), "AddressData");
            }

            IEnumerable <Payments> newPayments = Payments.Except(dbPayments);

            if (newPayments.Any())
            {
                Console.WriteLine("--- There are <" + newPayments.Count() + "> new Payments ---");
                DataProcess.BulkInsert(conn, "Payments", newPayments);
            }
            IEnumerable <Payments> updatePayments = Payments.Except(newPayments).Except(dbPayments, new PaymentsComparer());

            if (updatePayments.Any())
            {
                Console.WriteLine("--- There are <" + updatePayments.Count() + "> Payments need to update ---");
                DataProcess.BatchUpdate(conn, ToDataTable(updatePayments), "PaymentData");
            }

            IEnumerable <Packages> newPackages = Packages.Except(dbPackages);

            if (newPackages.Any())
            {
                Console.WriteLine("--- There are <" + newPackages.Count() + "> new Packages ---");
                DataProcess.BulkInsert(conn, "Packages", newPackages);
            }

            IEnumerable <Packages> updatePackages = Packages.Except(newPackages).Except(dbPackages, new PackagesComparer());

            if (updatePackages.Any())
            {
                Console.WriteLine("--- There are <" + updatePackages.Count() + "> Packages need to update ---");
                DataProcess.BatchUpdate(conn, ToDataTable(updatePackages), "PackageData");
            }

            IEnumerable <Items> newItems = Items.Except(dbItems);

            if (newItems.Any())
            {
                Console.WriteLine("--- There are <" + newItems.Count() + "> new Items ---");
                DataProcess.BulkInsert(conn, "Items", newItems);
            }
            IEnumerable <Items> updateItems = Items.Except(newItems).Except(dbItems, new ItemsComparer());

            if (updateItems.Any())
            {
                Console.WriteLine("--- There are <" + updateItems.Count() + "> Items need to update ---");
                DataProcess.BatchUpdate(conn, ToDataTable(updateItems), "ItemData");
            }

            if (BundleItems.Any())
            {
                DataProcess.BulkInsert(conn, "BundleItems", BundleItems);
            }

            if (Skus.Any())
            {
                IEnumerable <Skus> newSkus = Skus.Except(GetSkus());
                if (newSkus.Any())
                {
                    DataProcess.BulkInsert(conn, "Skus", newSkus);
                }
            }

            IEnumerable <SerialNumbers> newSerialNumbers = SerialNumbers.Except(dbSerialNumbers);

            if (newSerialNumbers.Any())
            {
                Console.WriteLine("--- There are <" + newSerialNumbers.Count() + "> new SerialNumbers ---");
                DataProcess.BulkInsert(conn, "SerialNumbers", newSerialNumbers);
            }
        }