示例#1
0
        private void BulkImport(int vendorID, DataSet content, int?parentVendorID)
        {
            using (var unit = GetUnitOfWork())
            {
                var dataList = (from d in content.Tables[0].AsEnumerable()
                                let defaultVendorID = parentVendorID.HasValue ? parentVendorID.Value : vendorID
                                                      select new Concentrator.Objects.Vendors.Bulk.VendorStockBulk.VendorImportStock
                {
                    VendorID = vendorID,
                    VendorStockType = "Assortment",
                    QuantityOnHand = (int)d.Field <double>("QuantityOnHand") > 0 ? (int)d.Field <double>("QuantityOnHand") : 0,
                    CustomItemNumber = VendorImportUtility.SetDataSetValue("ShortItemNumber", d),
                    defaultVendorID = defaultVendorID,
                    PromisedDeliveryDate = VendorImportUtility.SetDataSetValue("PromisedDeliveryDate", d),
                    QuantityToReceive = VendorImportUtility.SetDataSetValue("QuantityToReceive", d) != null ? int.Parse(VendorImportUtility.SetDataSetValue("QuantityToReceive", d)) : 0,
                    StockStatus = VendorImportUtility.SetDataSetValue("StockStatus", d),
                    UnitCost = null,
                    VendorBrandCode = VendorImportUtility.SetDataSetValue("Brand", d),
                    VendorItemNumber = VendorImportUtility.SetDataSetValue("VendorItemNumber", d),
                    VendorStatus = VendorImportUtility.SetDataSetValue("StockStatus", d)
                });

                log.Debug("dataset to object");

                using (var vendorStockBulk = new VendorStockBulk(dataList, vendorID, parentVendorID, "BAS"))
                {
                    vendorStockBulk.Init(unit.Context);
                    vendorStockBulk.Sync(unit.Context);
                }
            }
        }
示例#2
0
        private void BulkImport(int vendorID, DataSet content, int?parentVendorID, Vendor vendor)
        {
            using (var unit = GetUnitOfWork())
            {
                if (content.Tables[0].AsEnumerable().Count() < 1000)
                {
                    return;
                }

                var dataList = (from d in content.Tables[0].AsEnumerable()
                                let DefaultVendorID = parentVendorID.HasValue ? parentVendorID.Value : vendorID
                                                      select new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem
                {
                    #region BrandVendor
                    BrandVendors = new List <VendorAssortmentBulk.VendorImportBrand>()
                    {
                        new VendorAssortmentBulk.VendorImportBrand()
                        {
                            VendorID = DefaultVendorID,
                            VendorBrandCode = VendorImportUtility.SetDataSetValue("Brand", d) ?? string.Empty,
                            ParentBrandCode = null,
                            Name = VendorImportUtility.SetDataSetValue("Brand", d) ?? string.Empty,
                        }
                    },
                    #endregion
                    #region GeneralProductInfo
                    VendorProduct = new VendorAssortmentBulk.VendorProduct
                    {
                        VendorItemNumber = VendorImportUtility.SetDataSetValue("VendorItemNumber", d),
                        CustomItemNumber = VendorImportUtility.SetDataSetValue("ShortItemNumber", d),
                        ShortDescription = VendorImportUtility.SetDataSetValue("Description1", d),
                        LongDescription = VendorImportUtility.SetDataSetValue("Description2", d),
                        LineType = VendorImportUtility.SetDataSetValue("LineType", d),
                        LedgerClass = d.Table.Columns.Contains("LedgerClass") ? VendorImportUtility.SetDataSetValue("LedgerClass", d) : null,
                        ProductDesk = d.Table.Columns.Contains("ProductDesk") ? VendorImportUtility.SetDataSetValue("ProductDesk", d) : null,
                        ExtendedCatalog = d.Table.Columns.Contains("Extendedcatalog") ? VendorImportUtility.SetDataSetValue("Extendedcatalog", d) : null,
                        VendorID = vendorID,
                        DefaultVendorID = DefaultVendorID,
                        VendorBrandCode = VendorImportUtility.SetDataSetValue("Brand", d),
                        Barcode = VendorImportUtility.SetDataSetValue("Barcode", d),
                        VendorProductGroupCode1 = VendorImportUtility.SetDataSetValue("ProductGroup", d),
                        VendorProductGroupCodeName1 = string.Empty,
                        VendorProductGroupCode2 = VendorImportUtility.SetDataSetValue("ProductSubGroup", d),
                        VendorProductGroupCodeName2 = string.Empty,
                        VendorProductGroupCode3 = VendorImportUtility.SetDataSetValue("ProductSubSubGroup", d),
                        VendorProductGroupCodeName3 = string.Empty,
                        VendorProductGroupCode4 = null,
                        VendorProductGroupCodeName4 = null,
                        VendorProductGroupCode5 = null,
                        VendorProductGroupCodeName5 = null,
                        VendorProductGroupCode6 = null,
                        VendorProductGroupCodeName6 = null,
                        VendorProductGroupCode7 = null,
                        VendorProductGroupCodeName7 = null,
                        VendorProductGroupCode8 = null,
                        VendorProductGroupCodeName8 = null,
                        VendorProductGroupCode9 = null,
                        VendorProductGroupCodeName9 = null,
                        VendorProductGroupCode10 = null,
                        VendorProductGroupCodeName10 = null
                    },
                    #endregion
                    #region RelatedProducts
                    RelatedProducts = new List <VendorAssortmentBulk.VendorImportRelatedProduct>(),
                    #endregion
                    #region Attribures
                    VendorImportAttributeValues = new List <VendorAssortmentBulk.VendorImportAttributeValue>(),
                    #endregion
                    #region Prices
                    VendorImportPrices = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice>()
                    {
                        new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice()
                        {
                            VendorID = vendorID,
                            DefaultVendorID = DefaultVendorID,
                            CustomItemNumber = VendorImportUtility.SetDataSetValue("ShortItemNumber", d),
                            Price = VendorImportUtility.SetDataSetValue("UnitPrice", d, "0"),
                            CostPrice = VendorImportUtility.SetDataSetValue("CostPrice", d, "0"),
                            TaxRate = VendorImportUtility.SetDataSetValue("TaxRate", d, "0"),
                            MinimumQuantity = VendorImportUtility.SetDataSetValue("MinimumQuantity", d).Try(x => int.Parse(x) < 0 ? 0 : int.Parse(x), 0),
                            CommercialStatus = VendorImportUtility.SetDataSetValue("CommercialStatus", d, "S")
                        }
                    },

                    #endregion
                    #region Stock
                    VendorImportStocks = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportStock>()
                    {
                        new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportStock()
                        {
                            VendorID = vendorID,
                            DefaultVendorID = DefaultVendorID,
                            CustomItemNumber = VendorImportUtility.SetDataSetValue("ShortItemNumber", d),
                            QuantityOnHand = VendorImportUtility.SetDataSetValue("QuantityOnHand", d).Try(x => int.Parse(x), 0),
                            StockType = "Assortment",
                            StockStatus = VendorImportUtility.SetDataSetValue("StockStatus", d)
                        }
                    },

                    #endregion
                });

                //var dataList = (from d in content.Tables[0].AsEnumerable()
                //                let defaultVendorID = parentVendorID.HasValue ? parentVendorID.Value : vendorID
                //                select new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem
                //                {
                //                  #region BrandVendor
                //                  BrandVendors = new List<Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportBrand>()
                //                  {
                //                    new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportBrand(){
                //                      Name = VendorImportUtility.SetDataSetValue("Brand", d),
                //                      VendorBrandCode = VendorImportUtility.SetDataSetValue("Brand", d),
                //                      VendorID = defaultVendorID
                //                    }
                //                  },
                //                  #endregion
                //                  #region GeneralProductInfo
                //                  VendorProduct = new VendorAssortmentBulk.VendorProduct
                //                  {
                //                    VendorItemNumber = VendorImportUtility.SetDataSetValue("VendorItemNumber", d),
                //                    CustomItemNumber = VendorImportUtility.SetDataSetValue("ShortItemNumber", d),
                //                    ShortDescription = VendorImportUtility.SetDataSetValue("Description1", d),
                //                    LongDescription = VendorImportUtility.SetDataSetValue("Description2", d),
                //                    LineType = VendorImportUtility.SetDataSetValue("LineType", d),
                //                    LedgerClass = d.Table.Columns.Contains("LedgerClass") ? VendorImportUtility.SetDataSetValue("LedgerClass", d) : null,
                //                    ProductDesk = d.Table.Columns.Contains("ProductDesk") ? VendorImportUtility.SetDataSetValue("ProductDesk", d) : null,
                //                    ExtendedCatalog = d.Table.Columns.Contains("Extendedcatalog") ? VendorImportUtility.SetDataSetValue("Extendedcatalog", d) : null,
                //                    VendorID = vendorID,
                //                    DefaultVendorID = defaultVendorID,
                //                    VendorBrandCode = VendorImportUtility.SetDataSetValue("Brand", d),
                //                    Barcode = VendorImportUtility.SetDataSetValue("Barcode", d),
                //                    VendorProductGroupCode1 = VendorImportUtility.SetDataSetValue("ProductGroup", d),
                //                    VendorProductGroupCode2 = VendorImportUtility.SetDataSetValue("ProductSubGroup", d),
                //                    VendorProductGroupCode3 = VendorImportUtility.SetDataSetValue("ProductSubSubGroup", d)
                //                  },
                //                  //                     VendorImportPrices = new List<Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice>()
                //                  //                     {
                //                  //                       new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice(){
                //                  //                         VendorID = vendorID,
                //                  //                         DefaultVendorID = defaultVendorID,
                //                  //                         CustomItemNumber = VendorImportUtility.SetDataSetValue("ShortItemNumber", d),
                //                  //                          Price = d.Field<decimal>("UnitPrice"),
                //                  //   CostPrice = (d.Table.Columns.Contains("CostPrice") ? d.Field<decimal?>("CostPrice") : 0) ?? 0,
                //                  //        TaxRate = (decimal)(d.Field<double>("TaxRate")),
                //                  //                         MinimumQuantity = (d.Field<int>("MinimumQuantity") > 0 ? d.Field<int>("MinimumQuantity") : 0),
                //                  //CommercialStatus = d.Field<string>("CommercialStatus")
                //                  //                       }
                //                  //                     }
                //                  #endregion
                //                });

                log.Debug("dataset to object");

                string vendorBrandID = vendor.VendorSettings.GetValueByKey("BrandID", string.Empty);
                if (!string.IsNullOrEmpty(vendorBrandID))
                {
                    dataList = dataList.Where(x => x.VendorProduct.VendorBrandCode == vendorBrandID);
                }

                using (var vendorAssortmentBulk = new VendorAssortmentBulk(dataList, vendorID, parentVendorID))
                {
                    vendorAssortmentBulk.Init(unit.Context);
                    vendorAssortmentBulk.Sync(unit.Context);
                }
            }
        }
        protected override void Process()
        {
            foreach (Vendor vendor in Vendors.Where(x => ((VendorType)x.VendorType).Has(VendorType.Barcodes) && x.IsActive))
            {
                try
                {
                    if (vendor.VendorSettings.GetValueByKey <int>("AssortmentImportID", 0) < 1)
                    {
                        continue;
                    }

                    log.DebugFormat("Start Barcodes Import for Vendor '{0} ({1})'", vendor.Name, vendor.VendorID);

                    using (var unit = GetUnitOfWork())
                    {
                        DataSet barcodes = new DataSet();

                        using (JdeAssortmentSoapClient cl = new JdeAssortmentSoapClient())
                        {
                            barcodes = cl.GetBarcodes();

                            var dataList = (from b in barcodes.Tables[0].AsEnumerable()
                                            where VendorImportUtility.SetDataSetValue("ivxrt", b) != "DC"
                                            select new Concentrator.Objects.Vendors.Bulk.VendorBarcodeBulk.VendorImportBarcode
                            {
                                Barcode = VendorImportUtility.SetDataSetValue("IVCITM", b),
                                CustomItemNumber = VendorImportUtility.SetDataSetValue("IVITM", b),
                                Type = 0,
                                VendorID = vendor.ParentVendorID.HasValue ? vendor.ParentVendorID.Value : vendor.VendorID
                            }).AsEnumerable();

                            using (var vendorAssortmentBulk = new VendorBarcodeBulk(dataList, vendor.ParentVendorID.HasValue ? vendor.ParentVendorID.Value : vendor.VendorID, 0))
                            {
                                vendorAssortmentBulk.Init(unit.Context);
                                vendorAssortmentBulk.Sync(unit.Context);
                            }

                            var sapDataList = (from b in barcodes.Tables[0].AsEnumerable()
                                               where VendorImportUtility.SetDataSetValue("ivxrt", b) == "DC"
                                               select new Concentrator.Objects.Vendors.Bulk.VendorBarcodeBulk.VendorImportBarcode
                            {
                                Barcode = VendorImportUtility.SetDataSetValue("IVCITM", b),
                                CustomItemNumber = VendorImportUtility.SetDataSetValue("IVITM", b),
                                Type = 3,
                                VendorID = vendor.ParentVendorID.HasValue ? vendor.ParentVendorID.Value : vendor.VendorID
                            }).AsEnumerable();

                            using (var vendorAssortmentBulk = new VendorBarcodeBulk(sapDataList, vendor.ParentVendorID.HasValue ? vendor.ParentVendorID.Value : vendor.VendorID, 3))
                            {
                                vendorAssortmentBulk.Init(unit.Context);
                                vendorAssortmentBulk.Sync(unit.Context);
                            }
                        }
                    }

                    log.DebugFormat("Finished Barcode Import for vendor '{0} ({1})'", vendor.Name, vendor.VendorID);
                }
                catch (Exception ex)
                {
                    log.Error("Error import BAS assortment", ex);
                }
            }
        }