Example #1
0
        public override void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            //DataSet ds = new DataSet();
            int    connectorID = 0;
            int    customerID  = 0;
            string password    = "******";

            if (string.IsNullOrEmpty(context.Request.Params["CustomerID"]))
            {
                context.Response.Write("Invalid Customer Number");
                return;
            }
            if (!int.TryParse(context.Request.Params["CustomerID"], out customerID) && customerID < 1)
            {
                context.Response.Write("Invalid Customer Number");
                return;
            }

            if (string.IsNullOrEmpty(context.Request.Params["Password"]))
            {
                context.Response.Write("Invalid Password");
                return;
            }
            if (context.Request.Params["Password"] != password)
            {
                context.Response.Write("Invalid Password");
                return;
            }

            if (string.IsNullOrEmpty(context.Request.Params["ConnectorID"]))
            {
                context.Response.Write("Invalid ConnectorID");
                return;
            }
            if (!int.TryParse(context.Request.Params["ConnectorID"], out connectorID) && connectorID < 1)
            {
                context.Response.Write("Invalid ConnectorID");
                return;
            }

            using (var unit = GetUnitOfWork())
            {
                Connector con = unit.Scope.Repository <Connector>().GetSingle(x => x.ConnectorID == connectorID);

                var preferredVendor = con.PreferredConnectorVendors.FirstOrDefault(c => c.isPreferred).Vendor;

                JdeAssortmentSoapClient soap = new JdeAssortmentSoapClient();
                var prices = soap.GenerateFullProductList(
                    customerID,//int.Parse(preferredVendor.VendorSettings.Where(c => c.SettingKey == "AssortmentImportID").FirstOrDefault().Value),
                    int.Parse(preferredVendor.VendorSettings.Where(c => c.SettingKey == "InternetAssortment").FirstOrDefault().Value),
                    int.Parse(preferredVendor.VendorSettings.Where(c => c.SettingKey == "AllowDC10OItems").FirstOrDefault().Value),
                    int.Parse(preferredVendor.VendorSettings.Where(c => c.SettingKey == "AllowDC10ObyStatus").FirstOrDefault().Value),
                    false,
                    false
                    );

                string separator = ";";

                //int languageid = EntityExtensions.GetValueByKey(con.ConnectorSettings, "LanguageID", 2);
                var funcRepo = ((IFunctionScope)unit.Scope).Repository();
                var records  = funcRepo.GetAssortmentContentView(connectorID).Where(x => x.BrandID > 0);
                var language = con.ConnectorLanguages.FirstOrDefault();
                language.ThrowArgNull("No Language specified for connector");
                var languageid = language.LanguageID;


                var assortment = (from a in records.ToList()
                                  join advancedPrice in prices.Tables[0].AsEnumerable() on a.VendorItemNumber equals advancedPrice.Field <string>("VendorItemNumber").Trim().ToUpper()
                                  //barcodes.ContainsKey(a.ProductID) ? barcodes[a.ProductID] : new List<string>()
                                  select new
                {
                    ManufacturerID = a.VendorItemNumber,
                    ConcentratorProductID = a.ProductID,
                    PriceExVat = advancedPrice.Field <decimal>("UnitPrice").ToString().Replace(',', '.'),
                    VatRate = decimal.Parse(advancedPrice.Field <double>("TaxRate").ToString(), CultureInfo.InvariantCulture),
                    MinimumQuantity = advancedPrice.Field <int>("MinimumQuantity") > 0 ? advancedPrice.Field <int>("MinimumQuantity") : 0,
                    Sbo = 0,        //advancedPrice.Field<string>("SBO"),
                    CustomerQuantityOnHand = advancedPrice.Field <double>("QuantityOnHand")
                });


                foreach (var row in assortment)
                {
                    var line = String.Format("{0};{1};{2};{3};{4};{5};{6}\r\n", row.ManufacturerID, row.ConcentratorProductID, row.PriceExVat, row.VatRate, row.MinimumQuantity, row.Sbo, row.CustomerQuantityOnHand);
                    context.Response.Write(line);
                }
            }
        }
Example #2
0
        private DataSet GetContent(Vendor vendor)
        {
            DataSet content = null;

            JdeAssortmentSoapClient cl = new JdeAssortmentSoapClient();

            if (_retailStock)
            {
                content = cl.GenerateFullProductListWithRetailStock(
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "AssortmentImportID").FirstOrDefault().Value),
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "InternetAssortment").FirstOrDefault().Value),
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "AllowDC10OItems").FirstOrDefault().Value),
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "AllowDC10ObyStatus").FirstOrDefault().Value));
            }
            else if (_auctionStock)
            {
                content = cl.GenerateFullProductListSpecialAssortment(
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "AssortmentImportID").FirstOrDefault().Value),
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "InternetAssortment").FirstOrDefault().Value),
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "AllowDC10OItems").FirstOrDefault().Value),
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "AllowDC10ObyStatus").FirstOrDefault().Value),
                    0,
                    vendor.VendorSettings.Where(c => c.SettingKey == "BSCStock").FirstOrDefault().Value,
                    vendor.VendorSettings.Where(c => c.SettingKey == "CostPriceDC10").FirstOrDefault().Value,
                    vendor.VendorSettings.Where(c => c.SettingKey == "CostPriceBSC").FirstOrDefault().Value,
                    true
                    );
            }
            else if (_shopAssortment)
            {
                content = cl.GenerateFullProductListWithNonStock(
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "AssortmentImportID").FirstOrDefault().Value),
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "InternetAssortment").FirstOrDefault().Value),
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "AllowDC10OItems").FirstOrDefault().Value),
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "AllowDC10ObyStatus").FirstOrDefault().Value),
                    false,
                    true
                    );
            }
            else
            {
                content = cl.GenerateFullProductList(
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "AssortmentImportID").FirstOrDefault().Value),
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "InternetAssortment").FirstOrDefault().Value),
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "AllowDC10OItems").FirstOrDefault().Value),
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "AllowDC10ObyStatus").FirstOrDefault().Value),
                    false,
                    false
                    );
            }

            if (vendor.VendorSettings.Where(c => c.SettingKey == "CostPriceImportID").FirstOrDefault() != null)
            {
                DataSet contentCostPrice = cl.GenerateFullProductList(
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "CostPriceImportID").FirstOrDefault().Value),
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "InternetAssortment").FirstOrDefault().Value),
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "AllowDC10OItems").FirstOrDefault().Value),
                    int.Parse(vendor.VendorSettings.Where(c => c.SettingKey == "AllowDC10ObyStatus").FirstOrDefault().Value),
                    false,
                    false
                    );
                content.Tables[0].Columns.Add("CostPrice", typeof(decimal));
                content.Tables[0].Columns["CostPrice"].AllowDBNull = true;

                if (contentCostPrice != null)
                {
                    foreach (DataRow row in content.Tables[0].AsEnumerable())
                    {
                        row["CostPrice"] = (from ccp in contentCostPrice.Tables[0].AsEnumerable()
                                            where
                                            ccp.Field <double>("ShortItemNumber") == row.Field <double>("ShortItemNumber") &&
                                            ccp.Field <int>("MinimumQuantity") == row.Field <int>("MinimumQuantity")
                                            select ccp.Field <decimal>("UnitPrice")).FirstOrDefault();
                    }
                }
                else
                {
                    log.Error("Cosprices list empty");
                }
            }

            return(content);
        }
        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);
                }
            }
        }