From e61fe395628499b5331c3e45b2f1f23b87b88a26 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A1=C2=B7=C3=A6?= <279202647@qq.com>
Date: Sun, 18 Apr 2021 14:06:23 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97=E8=AE=B0?=
=?UTF-8?q?=E5=BD=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../JdShopListener/JdShopListener.csproj | 1 +
JdShopListener/JdShopListener/MainWindow.xaml | 4 +
.../JdShopListener/MainWindowViewModel.cs | 142 +++++++++++-------
3 files changed, 95 insertions(+), 52 deletions(-)
diff --git a/JdShopListener/JdShopListener/JdShopListener.csproj b/JdShopListener/JdShopListener/JdShopListener.csproj
index 46ad476..5bfc419 100644
--- a/JdShopListener/JdShopListener/JdShopListener.csproj
+++ b/JdShopListener/JdShopListener/JdShopListener.csproj
@@ -4,6 +4,7 @@
WinExe
netcoreapp3.1
true
+ 跟屁虫
diff --git a/JdShopListener/JdShopListener/MainWindow.xaml b/JdShopListener/JdShopListener/MainWindow.xaml
index ec7978d..6ea4902 100644
--- a/JdShopListener/JdShopListener/MainWindow.xaml
+++ b/JdShopListener/JdShopListener/MainWindow.xaml
@@ -303,6 +303,10 @@
+
+
+
+
diff --git a/JdShopListener/JdShopListener/MainWindowViewModel.cs b/JdShopListener/JdShopListener/MainWindowViewModel.cs
index 00796da..0267641 100644
--- a/JdShopListener/JdShopListener/MainWindowViewModel.cs
+++ b/JdShopListener/JdShopListener/MainWindowViewModel.cs
@@ -97,6 +97,16 @@ namespace JdShopListener
set { Set(ref _SelectPro, value); ShowData(); }
}
+ private string _LogText;
+ ///
+ /// 日志
+ ///
+ public string LogText
+ {
+ get { return _LogText; }
+ set { Set(ref _LogText, value); }
+ }
+
private DateModel _SelectDate;
///
@@ -190,6 +200,14 @@ namespace JdShopListener
}
+ private void AddLog(string log)
+ {
+ Application.Current.Dispatcher.Invoke(() =>
+ {
+ LogText += log + "\r\n";
+ });
+ }
+
///
/// 添加
///
@@ -201,79 +219,99 @@ namespace JdShopListener
IsAdd = true;
Thread addThread = new Thread(() =>
{
+ try
+ {
+ var detail = GetItemDetail(Sku);
- var detail = GetItemDetail(Sku);
+ var list = detail.product.colorSize;
- var list = detail.product.colorSize;
+ //spuId
+ string spuId = detail.product.mainSkuId;
- //spuId
- string spuId = detail.product.mainSkuId;
+ //if (list.Count == 0 || list.Count == null)
+ //{
+ // list.Add(new { skuId = Sku });
+ //}
- List skus = new List();
+ List skus = new List();
- foreach (var sku in list)
- {
- SkuModel model = new SkuModel()
+ foreach (var sku in list)
{
- Desc = Desc,
- SkuId = sku.skuId,
- SpuId = spuId
- };
-
- //去除重复
- if (SkuList.Count(c => c.SkuId == model.SkuId) > 0)
- continue;
-
- //加入本地数据库
- skus.Add(model);
- Application.Current.Dispatcher.Invoke(() =>
+ SkuModel model = new SkuModel()
+ {
+ Desc = Desc,
+ SkuId = sku.skuId,
+ SpuId = spuId
+ };
+
+ //去除重复
+ if (SkuList.Count(c => c.SkuId == model.SkuId) > 0)
+ continue;
+
+ //加入本地数据库
+ skus.Add(model);
+ Application.Current.Dispatcher.Invoke(() =>
+ {
+ SkuList.Add(model);
+ });
+ }
+
+ //加载sku详情
+ skus.ForEach(sku =>
{
- SkuList.Add(model);
- });
- }
+ var detail = GetItemDetail(sku.SkuId);
- //加载sku详情
- skus.ForEach(sku =>
- {
- var detail = GetItemDetail(sku.SkuId);
+ //主图
+ string src = detail.product.src;
+ var catIds = detail.product.cat;
- //主图
- string src = detail.product.src;
- var catIds = detail.product.cat;
+ List cats = new List();
- List cats = new List();
+ foreach (var catId in catIds)
+ {
+ cats.Add((int)catId);
+ }
- foreach (var catId in catIds)
- {
- cats.Add((int)catId);
- }
+ string cat = string.Join(",", cats);
- string cat = string.Join(",", cats);
+ //标题
+ string title = detail.product.name;
- //标题
- string title = detail.product.name;
+ string shopId = detail.product.shopId;
- string shopId = detail.product.shopId;
+ string vid = detail.product.venderId;
- string vid = detail.product.venderId;
+ sku.ImgUrl = "http://img11.360buyimg.com/n1/" + src;
+ sku.Title = title;
+ sku.Cat = cat;
+ sku.ShopId = shopId;
+ sku.VenderId = vid;
- sku.ImgUrl = "http://img11.360buyimg.com/n1/" + src;
- sku.Title = title;
- sku.Cat = cat;
- sku.ShopId = shopId;
- sku.VenderId = vid;
+ if (DbHelper.Db.AddSkuModel(sku))
+ {
+ AddLog($"{sku.SkuId}添加监控成功!");
+ }
+ else {
+ AddLog($"{sku.SkuId}添加监控列表失败!");
+ }
- Thread.Sleep(3000);
- });
+ Thread.Sleep(3000);
+ });
- if (DbHelper.Db.AddSkuModel(skus))
- {
- MessageBox.Show("添加成功", "提示");
- }
+ //if (DbHelper.Db.AddSkuModel(skus))
+ //{
+ MessageBox.Show("添加成功", "提示");
+ AddLog("全部相关sku添加成功!");
+ //}
- IsAdd = false;
+ IsAdd = false;
+ }
+ catch(Exception ex)
+ {
+ MessageBox.Show("添加失败,异常信息:"+ex.Message);
+ }
});
addThread.Start();
}