Ejemplo n.º 1
0
        //[TestMethod]
        public void CreateProductTest()
        {
            var target = new N11Service();

            //target.GetShipmentTemplates();

            var prod = new ProductModel
                       {
                           stockCode = "91.000015",
                           title = "TIMBERLAND 18617 KADIN AYAKKABI",
                           label = "TIMBERLAND 18617 KADIN AYAKKABI",
                           details = "TIMBERLAND 18617 KADIN AYAKKABI<br />",
                           displayPrice = 209,
                           picture1Path = "http://www.elektrostil.com/modules/catalog/products/pr_01_3448119_max.jpg?rev=1382934834",
                           stockAmount = 23
                       };

            target.CreateProduct(prod, 1520, null);

            Assert.IsTrue(true);
        }
Ejemplo n.º 2
0
        public List<ProductModel> ex_GetSourceProductsXml(string xmlPath, string priceColumn)
        {
            //var xmlPath = @"C:\Users\Ertan\Downloads\N11-XML.xml";
            //var xmlPath = @"http://www.elektrostil.com/index.php?do=catalog/output&pCode=9211982202";
            var dt = new DataTable("ProductsXml");

            var xdoc = XDocument.Load(xmlPath);
            //XDocument xdoc = null;
            //if (xmlPath.StartsWith("http"))
            //{
            //    var tempFile = Path.GetTempFileName();
            //    //var wr = (HttpWebRequest) WebRequest.Create(xmlPath);
            //    var wc = new WebClient();
            //    var data = wc.DownloadData(xmlPath);
            //    System.IO.File.WriteAllBytes(tempFile, data);

            //    xdoc = XDocument.Load(tempFile);

            //    System.IO.File.Delete(tempFile);
            //}
            //else
            //{
            //    xdoc = XDocument.Load(xmlPath);
            //}

            var q = from d in xdoc.Root.Descendants("item")
                    select d;
            var list = q.ToList();

            foreach (var xElement in list)
            {
                var valueList = new List<object>();
                foreach (var attr in xElement.Elements())
                {
                    if (dt.Columns[attr.Name.LocalName] == null)
                        dt.Columns.Add(attr.Name.LocalName);
                }
                var dr = dt.NewRow();
                foreach (var attr in xElement.Elements())
                {
                    dr[attr.Name.LocalName] = attr.Value;
                }

                dt.Rows.Add(dr);
            }

            var kurTable = GetDovizKurlari();
            var usdKur = kurTable["USD"];
            var eurKur = kurTable["EUR"];
            var karAmount = 0;

            if (usdKur < 1 || eurKur < 1)
            {
                throw new Exception("Kurlarda bir hata var.");
            }

            var productList = new List<ProductModel>();
            Func<string, string, string, decimal> calculatePrice = (x, curr, kdv) =>
            {
                var price = decimal.Parse(x.Replace(".", ","));
                if (curr == "USD")
                    price = price * usdKur;
                else if (curr == "EUR")
                    price = price * eurKur;
                else if (curr != "TL")
                    throw new NotImplementedException();

                price = price * (int.Parse(kdv) + 100) / 100;
                price = Math.Round(price * 100) / 100;
                price += karAmount;
                return price;
            };

            foreach (DataRow dr in dt.Rows)
            {
                var prod = new ProductModel
                {
                    //id = dr["id"],
                    title = (string)dr["label"],
                    stockCode = (string)dr["stockCode"],
                    displayPrice = calculatePrice((string)dr[priceColumn], (string)dr["currencyAbbr"], (string)dr["tax"]),
                    stockAmount = int.Parse(dr["stockAmount"].ToString()),

                    label = (string)dr["label"],
                    brand = (string)dr["brand"],
                    mainCategory = (string)dr["mainCategory"],
                    category = (string)dr["category"],
                    subCategory = (string)dr["subCategory"],

                    picture1Path = (string)dr["picture1Path"],
                    //picture2Path = (string)dr["picture2Path"],
                    //picture3Path = (string)dr["picture3Path"],
                    //picture4Path = (string)dr["picture4Path"],

                    details = (string)dr["details"],
                    //rebatedPriceWithoutTax = (string)dr["rebatedPriceWithoutTax"],
                };
                productList.Add(prod);

                // Stok değeri 1 olan ürünleri kaldır.
                var subList = productList.Where(x => x.stockAmount == 1).ToList();
                productList.RemoveAll(x => subList.Any(y => y == x));

            }

            return productList;
        }
Ejemplo n.º 3
0
        private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            var i = 0;
            if (btnProcessNew.Checked)
            {
                bgw.ReportProgress(0, "Yeni ürünler kaydediliyor.");
                foreach (DataRow dr in newProductsTable.Rows)
                {
                    i++;
                    var percent = (int) Math.Round((double) (i*100/newProductsTable.Rows.Count));
                    if (dr["n11Category"] == System.DBNull.Value || String.IsNullOrWhiteSpace(dr["n11Category"].ToString()))
                    {
                        bgw.ReportProgress(percent, String.Format("{0} için kategori seçilmedi.", dr["stockCode"]));
                        continue;
                    }
                    if (!rowAttributeTable.ContainsKey((string) dr["stockCode"]))
                    {
                        bgw.ReportProgress(percent, String.Format("{0} için özellikler seçilmedi.", dr["stockCode"]));
                        continue;
                    }
                    var prod = new ProductModel
                    {
                        stockCode = (string) dr["stockCode"],
                        label = (string) dr["label"],
                        brand = (string) dr["brand"],
                        title = (string) dr["label"],
                        //dr["category"] = String.Format("{0} / {1} / {2}", sourceProd.mainCategory, sourceProd.category, sourceProd.subCategory);
                        displayPrice = (decimal) dr["price"],
                        stockAmount = (int) dr["stockAmount"],
                        picture1Path = (string) dr["picture1Path"],
                        details = (string) dr["details"]
                    };
                    //var catId = long.Parse(((string)dr["n11Category"]).Split('-')[0]);
                    var catIdStr = ((string) dr["n11Category"]).Split('-')[0];
                    //var cat = categoryTable[catId];
                    var cat = categoryTable.Values.First(x => x.Code == catIdStr);
                    var attList = rowAttributeTable[(string) dr["stockCode"]];

                    var result = n11Service.CreateProduct(prod, long.Parse(cat.Code), attList);
                    if (result == false)
                    {
                        result.GetType();
                    }
                    bgw.ReportProgress(percent,
                        String.Format("{0} / {1} ({2} %)", i, newProductsTable.Rows.Count, percent));
                    if (bgw.CancellationPending)
                        return;
                }
            }

            if (btnProcessUpdates.Checked)
            {
                i = 0;
                bgw.ReportProgress(0, "Ürün fiyat ve stok miktarları güncelleniyor.");
                foreach (DataRow dr in updateProductsTable.Rows)
                {
                    i++;
                    var percent = (int) Math.Round((double) (i*100/updateProductsTable.Rows.Count));

                    var stockCode = (string) dr["stockCode"];
                    var oldPrice = (decimal) dr["oldPrice"];
                    var newPrice = (decimal) dr["newPrice"];
                    var oldStock = (int) dr["oldStock"];
                    var newStock = (int) dr["newStock"];
                    var diff = (decimal) dr["diff"];

                    if (btnFiyatGuncelle.Checked && oldPrice != newPrice)
                    {
                        // update price
                        if (diff > 10)
                            diff.GetType();
                        if (!n11Service.UpdateProduct(stockCode, newPrice))
                            oldPrice.GetType();
                    }

                    if (btnStokGuncelle.Checked && oldStock != newStock)
                    {
                        // update stock
                        n11Service.UpdateProductStock(stockCode, newStock);
                    }

                    bgw.ReportProgress(percent, String.Format("{0} / {1} ({2} %)", i, updateProductsTable.Rows.Count, percent));
                }
            }

            if (btnProcessDelete.Checked)
            {
                i = 0;
                bgw.ReportProgress(0, "N11deki eski ürünlerin stok bilgileri sıfırlanıyor.");
                foreach (DataRow dr in oldProductsTable.Rows)
                {
                    i++;
                    var percent = (int) Math.Round((double) (i*100/oldProductsTable.Rows.Count));

                    var productStockCode = (string) dr["stockCode"];
                    var productTitle = (string) dr["label"];

                    if (productTitle.Contains("Timberland"))
                    {
                        bgw.ReportProgress(percent, String.Format("{0} / {1} ({2} %) {3} SIFIRLANMADI.", i, oldProductsTable.Rows.Count, percent, productTitle));
                        if (bgw.CancellationPending)
                            return;
                        continue;
                    }

                    var sourceProd = sourceList.FirstOrDefault(x => productStockCode.Contains("_" + x.stockCode + "_"));
                    if (sourceProd == null)
                    {
                        // Remove
                        n11Service.RemoveProduct(productStockCode);
                        bgw.ReportProgress(percent, String.Format("{0} / {1} ({2} %)", i, oldProductsTable.Rows.Count, percent));
                        Debug.WriteLine("{0} sıfırlandı\t{1}\t{2}", i, productStockCode, productTitle);
                    }
                    else
                    {
                        bgw.ReportProgress(percent, String.Format("{0} / {1} ({2} %) Ürün ES'de mevcut, sıfırlanmıyor.", i, oldProductsTable.Rows.Count, percent));
                        sourceProd.GetType();
                    }

                    if (bgw.CancellationPending)
                        return;
                }
            }
            bgw.ReportProgress(100, "Bitti");
        }