예제 #1
0
        public void Process(DataSet content, Vendor vendor, ILog log)
        {
            if (content != null)
            {
                //DataLoadOptions options = new DataLoadOptions();
                //options.LoadWith<VendorAssortment>(x => x.Product);
                //options.LoadWith<VendorAssortment>(x => x.VendorPrices);

                //context.LoadOptions = options;
                using (var unit = ServiceLocator.Current.GetInstance <IUnitOfWork>())
                {
                    int totalProducts = content.Tables[0].AsEnumerable().Count();
                    log.DebugFormat("Start Process Prices for {0}, {1} productlines", vendor.Name, totalProducts);

                    var parentVendorID = unit.Scope.Repository <Vendor>().GetSingle(v => v.VendorID == vendor.VendorID).ParentVendorID;


                    int couterProduct = 0;
                    int logCount      = 0;

                    VendorDataParser util = new VendorDataParser(unit, vendor, log);
                    foreach (DataRow p in content.Tables[0].AsEnumerable())
                    {
                        couterProduct++;
                        logCount++;
                        if (logCount == 250)
                        {
                            log.DebugFormat("Products prices Processed : {0}/{1} for Vendor {2}", couterProduct, totalProducts, vendor.Name);
                            logCount = 0;
                        }

                        string vendorItemNumber = p.Field <string>("VendorItemNumber").Trim().ToUpper();
                        util.UpdatePrices(p, log);
                    }
                    unit.Save();
                    log.DebugFormat("Finished Process prices for {0}", vendor.VendorID);
                }
            }
            else
            {
                log.DebugFormat("Empty dataset for vendor {0} processing prices failed", vendor.Name);
            }
        }
예제 #2
0
        public void Process(DataSet content, int ImportVendorID, ILog log)
        {
            if (content != null)
            {
                int totalProducts = content.Tables[0].AsEnumerable().Count();
                log.DebugFormat("Start ProcessBSCStock for {0}, {1} productlines", ImportVendorID, totalProducts);
                using (ConcentratorDataContext context = new ConcentratorDataContext())
                {
                    VendorDataParser util = new VendorDataParser(context, ImportVendorID, log);

                    foreach (DataRow p in content.Tables[0].AsEnumerable())
                    {
                        util.LoadProduct(p, log);
                        util.UpdateBSCStockLevels(p, log);
                    }
                }
                log.DebugFormat("Finish ProcessBSCStock for {0}", ImportVendorID);
            }
            else
            {
                log.DebugFormat("Empty dataset for vendor {0} processing assorment failed", ImportVendorID);
            }
        }
예제 #3
0
        public void Process(DataSet content, Vendor vendor, ILog log)
        {
            if (content != null)
            {
                long start         = DateTime.Now.Ticks;
                int  totalProducts = content.Tables[0].AsEnumerable().Count();

                using (var unit = ServiceLocator.Current.GetInstance <IUnitOfWork>())
                {
                    //DataLoadOptions options = new DataLoadOptions();
                    //options.LoadWith<VendorAssortment>(x => x.VendorPrice);
                    //options.LoadWith<Product>(x => x.ProductBarcodes);

                    //context.LoadOptions = options;

                    int couterProduct = 0;
                    int logCount      = 0;
                    log.DebugFormat("Start Assortment processing for {0}, {1} Products", vendor.Name, totalProducts);
                    List <double> customItemNumbers = new List <double>();

                    VendorDataParser util = new VendorDataParser(unit, vendor, log);
                    foreach (DataRow p in content.Tables[0].AsEnumerable())
                    {
                        if (!customItemNumbers.Contains(p.Field <double>("ShortItemNumber")))
                        {
                            couterProduct++;
                            logCount++;
                            if (logCount == 250)
                            {
                                log.DebugFormat("Products Processed : {0}/{1} for Vendor {2}", couterProduct, totalProducts, vendor.Name);
                                logCount = 0;
                            }

                            if (util.LoadProduct(p, log))
                            {
                                util.ParseAssortment(log);
                            }

                            customItemNumbers.Add(p.Field <double>("ShortItemNumber"));
                        }
                        else
                        {
                            log.DebugFormat("Product {0} already imported for {1}", p.Field <double>("ShortItemNumber"), vendor.Name);
                        }
                    }
                    unit.Save();

                    log.DebugFormat("Start cleanup assortment for {0}", vendor.Name);

                    VendorParserUtility util1 = new VendorParserUtility(unit, vendor.VendorID, log);

                    util1.SyncUneeded(content, vendor.VendorID);
                    unit.Save();

                    log.DebugFormat("Finish cleanup assormtent for {0}", vendor.Name);

                    long finish = DateTime.Now.Ticks - start;
                    log.DebugFormat("Finish Assortment processing for {0}, {1} productlines in {2} minutes", vendor.Name, totalProducts, TimeSpan.FromTicks(finish).Minutes);
                }
            }
            else
            {
                log.DebugFormat("Empty dataset for vendor {0}, processing assortiment failed", vendor.Name);
            }
        }
        public void Process(DataSet content, Vendor vendor, ILog log, bool processStock)
        {
            using (var unit = ServiceLocator.Current.GetInstance <IKernel>().Get <IUnitOfWork>())
            {
                if (content != null)
                {
                    long start         = DateTime.Now.Ticks;
                    int  totalProducts = content.Tables[0].AsEnumerable().Count();
                    var  stockRepo     = unit.Scope.Repository <VendorStock>();

                    //TODO: Load options
                    //var options = new DataLoadOptions();
                    //  options.LoadWith<VendorAssortment>(v => v.VendorPrice);
                    //  options.LoadWith<VendorAssortment>(v => v.Product);
                    //  context.LoadOptions = options;

                    int couterProduct = 0;
                    int logCount      = 0;
                    log.DebugFormat("Start ProcessBSCStockAssortment for {0}, {1} productlines", vendor.Name, totalProducts);
                    List <string> vendorItemsInResultSet = stockRepo.GetAll(vs => vs.VendorID == vendor.VendorID).Select(c => c.Product.VendorItemNumber.Trim().ToUpper()).Distinct().ToList();

                    List <double> customItemNumbers = new List <double>();

                    VendorDataParser util = new VendorDataParser(unit, vendor, log);
                    foreach (DataRow p in content.Tables[0].AsEnumerable())
                    {
                        if (!customItemNumbers.Contains(p.Field <double>("ShortItemNumber")))
                        {
                            couterProduct++;
                            logCount++;
                            if (logCount == 250)
                            {
                                log.DebugFormat("Procces product {0}/{1} for vendor {2}", couterProduct, totalProducts, vendor.Name);
                                logCount = 0;
                            }

                            if (processStock)
                            {
                                util.UpdateBSCStockLevels(p, log);
                            }
                            else
                            {
                                // util.LoadProduct(p, log);
                                //util.ParseAssortment(log);
                            }
                            customItemNumbers.Add(p.Field <double>("ShortItemNumber"));
                            string vendorItemNumber = p.Field <string>("VendorItemNumber").Trim().ToUpper();
                            vendorItemsInResultSet.Remove(vendorItemNumber);
                        }
                        else
                        {
                            log.DebugFormat("Product {0} already importerted for {1}", p.Field <double>("ShortItemNumber"), vendor.Name);
                        }
                    }
                    unit.Save();

                    log.DebugFormat("Start cleanup ProcessBSCStockAssortment for {0}", vendor.Name);


                    foreach (var vendorItemNumber in vendorItemsInResultSet)
                    {
                        string vin     = vendorItemNumber;
                        var    records = stockRepo.GetAllAsQueryable(vs => vs.VendorID == vendor.VendorID
                                                                     //&& vs.VendorStockTypeID == 1//(int)VendorStockType.VendorStockRegularID
                                                                     && vs.Product.VendorItemNumber.Trim().ToUpper() == vin);

                        stockRepo.Delete(records);
                    }
                    unit.Save();


                    //VendorParserUtility util1 = new VendorParserUtility(unit, vendor.VendorID, log);

                    //util1.SyncUneeded(content, vendor.VendorID);
                    //unit.Save();

                    log.DebugFormat("Finish cleanup ProcessBSCStockAssortment for {0}", vendor.Name);

                    long finish = DateTime.Now.Ticks - start;
                    log.DebugFormat("Finish ProcessBSCStockAssortment for {0}, {1} productlines in {2} minutes", vendor.Name, totalProducts, TimeSpan.FromTicks(finish).Minutes);
                }
                else
                {
                    log.DebugFormat("Empty dataset for vendor {0} processing assorment failed", vendor.Name);
                }
            }
        }
        public void Process(DataSet content, Vendor vendor, ILog log)
        {
            if (content != null)
            {
                using (var unit = ServiceLocator.Current.GetInstance <IKernel>().Get <IUnitOfWork>())
                {
                    //TODO: LOAD OPTIONS
                    //DataLoadOptions options = new DataLoadOptions();
                    //options.LoadWith<VendorAssortment>(x => x.Product);

                    //context.LoadOptions = options;

                    var repoFreeGood      = unit.Scope.Repository <VendorFreeGood>();
                    var repoAccruel       = unit.Scope.Repository <VendorAccruel>();
                    VendorDataParser util = new VendorDataParser(unit, vendor, log);


                    var vendorAssortment = (from a in unit.Scope.Repository <VendorAssortment>().GetAllAsQueryable(l => l.VendorID == vendor.VendorID && l.IsActive)
                                            select a).Distinct().ToDictionary(x => x.CustomItemNumber, x => x);

                    #region FreeGoods
                    int totalProducts = content.Tables[1].AsEnumerable().Count();
                    log.DebugFormat("Start Process FreeGoods for {0}, {1} productlines", vendor.Name, totalProducts);
                    int couterProduct = 0;
                    int logCount      = 0;

                    var freeGoods = (from a in repoFreeGood.GetAllAsQueryable()
                                     where a.VendorAssortment.VendorID == vendor.VendorID
                                     select a).ToList();

                    foreach (DataRow p in content.Tables[1].AsEnumerable())
                    {
                        //util.LoadProduct(p, log);
                        couterProduct++;
                        logCount++;
                        if (logCount == 250)
                        {
                            log.DebugFormat("FreeGoods Processed : {0}/{1} for Vendor {2}", couterProduct, totalProducts, vendor.Name);
                            logCount = 0;
                        }

                        if (vendorAssortment.ContainsKey(p.Field <int>("ProductID").ToString()) && vendorAssortment.ContainsKey(p.Field <int>("FreeGoodProductID").ToString()))
                        {
                            var vendorAssortmentProduct = vendorAssortment[p.Field <int>("ProductID").ToString()];
                            var freeGoodProduct         = vendorAssortment[p.Field <int>("FreeGoodProductID").ToString()];

                            if (freeGoodProduct != null && vendorAssortmentProduct != null)
                            {
                                var freeGood = freeGoods.FirstOrDefault(x => x.VendorAssortmentID == vendorAssortmentProduct.VendorAssortmentID && x.ProductID == freeGoodProduct.ProductID);

                                if (freeGood == null)
                                {
                                    freeGood = new VendorFreeGood()
                                    {
                                        VendorAssortmentID  = vendorAssortmentProduct.VendorAssortmentID,
                                        ProductID           = freeGoodProduct.ProductID,
                                        MinimumQuantity     = p.Field <int>("MinimumQuantity"),
                                        OverOrderedQuantity = p.Field <int>("OverOrderedQuantity"),
                                        FreeGoodQuantity    = p.Field <int>("FreeGoodQuantity"),
                                        UnitPrice           = p.Field <decimal>("FreeGoodUnitPrice"),
                                        Description         = p.Field <string>("FreeGoodDescription")
                                    };
                                    repoFreeGood.Add(freeGood);
                                }
                                else
                                {
                                    freeGoods.Remove(freeGood);
                                }
                            }
                        }
                    }

                    repoFreeGood.Delete(freeGoods);
                    unit.Save();

                    log.DebugFormat("Finish FreeGoods for {0}", vendor.Name);
                    #endregion

                    #region Accruals
                    totalProducts = content.Tables[2].AsEnumerable().Count();
                    log.DebugFormat("Start Process Accruels for {0}, {1} productlines", vendor.Name, totalProducts);
                    couterProduct = 0;
                    logCount      = 0;

                    var accruels = repoAccruel.GetAll(a => a.VendorAssortment.VendorID == vendor.VendorID).ToList();


                    foreach (DataRow p in content.Tables[2].AsEnumerable())
                    {
                        //util.LoadProduct(p, log);
                        couterProduct++;
                        logCount++;
                        if (logCount == 250)
                        {
                            log.DebugFormat("Accruels Processed : {0}/{1} for Vendor {2}", couterProduct, totalProducts, vendor.Name);
                            logCount = 0;
                        }
                        if (p.Table.Columns.Contains("ProductID"))
                        {
                            if (vendorAssortment.ContainsKey(p.Try(c => c.Field <int>("ProductID").ToString(), string.Empty)))
                            {
                                var vendorAssortmentProduct = vendorAssortment[p.Field <int>("ProductID").ToString()];

                                if (vendorAssortmentProduct != null)
                                {
                                    var accruel = accruels.FirstOrDefault(x => x.VendorAssortmentID == vendorAssortmentProduct.VendorAssortmentID && x.AccruelCode == p.Field <string>("AccruelCode"));

                                    if (accruel == null)
                                    {
                                        accruel = new VendorAccruel()
                                        {
                                            VendorAssortmentID = vendorAssortmentProduct.VendorAssortmentID,
                                            AccruelCode        = p.Field <string>("AccruelCode"),
                                            Description        = p.Field <string>("AccruelDescription"),
                                            UnitPrice          = p.Field <decimal>("UnitPrice"),
                                            MinimumQuantity    = p.Field <int>("MinimumQuantity") > 0 ? p.Field <int>("MinimumQuantity") : 0
                                        };
                                        repoAccruel.Add(accruel);
                                    }
                                    else
                                    {
                                        accruels.Remove(accruel);
                                    }
                                }
                            }
                        }
                    }

                    repoAccruel.Delete(accruels);
                    unit.Save();

                    log.DebugFormat("Finish Accruels for {0}", vendor.Name);
                    #endregion
                }
            }
            else
            {
                log.DebugFormat("Empty dataset for vendor {0}, processing assortiment failed", vendor.Name);
            }
        }
예제 #6
0
        public void Process(DataSet content, Vendor vendor, ILog log)
        {
            if (content != null)
            {
                using (var unit = ServiceLocator.Current.GetInstance <IUnitOfWork>())
                {
                    var stockRepo = unit.Scope.Repository <VendorStock>();
                    //DataLoadOptions options = new DataLoadOptions();
                    //options.LoadWith<VendorAssortment>(x => x.Product);

                    //context.LoadOptions = options;

                    int totalProducts = content.Tables[0].AsEnumerable().Count();
                    log.DebugFormat("Start Process Stock for {0}, {1} productlines", vendor.Name, totalProducts);

                    var parentVendorID = unit.Scope.Repository <Vendor>().GetSingle(c => c.VendorID == vendor.VendorID).Try(l => l.ParentVendorID, null);



                    List <string> vendorItemsInResultSet = stockRepo.GetAll(vs => vs.VendorID == vendor.VendorID &&
                                                                            vs.VendorStockTypeID == 1).Select(c => c.Product.VendorItemNumber).ToList();


                    int couterProduct = 0;
                    int logCount      = 0;

                    VendorDataParser util = new VendorDataParser(unit, vendor, log);
                    foreach (DataRow p in content.Tables[0].AsEnumerable())
                    {
                        //util.LoadProduct(p, log);

                        couterProduct++;
                        logCount++;
                        if (logCount == 250)
                        {
                            log.DebugFormat("Products Processed : {0}/{1} for Vendor {2}", couterProduct, totalProducts, vendor.Name);
                            logCount = 0;
                        }

                        string vendorItemNumber = p.Field <string>("VendorItemNumber").Trim().ToUpper();

                        util.UpdateStockLevels(p, log);
                        vendorItemsInResultSet.Remove(vendorItemNumber);
                    }

                    unit.Save();
                    log.DebugFormat("Cleaning up old stock records for vendor {0}", vendor.Name);
                    foreach (var vendorItemNumber in vendorItemsInResultSet)
                    {
                        string vin     = vendorItemNumber;
                        var    records = stockRepo.GetAllAsQueryable(vs => vs.VendorID == vendor.VendorID &&
                                                                     vs.VendorStockTypeID == 1 &&//(int)VendorStockType.VendorStockRegularID
                                                                     vs.Product.VendorItemNumber.Trim().ToUpper() == vin);

                        stockRepo.Delete(records);
                    }
                    unit.Save();
                }
                log.DebugFormat("Finished Process Stock for {0}", vendor.VendorID);
            }
            else
            {
                log.DebugFormat("Empty dataset for vendor {0} processing assorment failed", vendor.Name);
            }
        }