From 24f2e40e12576f9bd8841739734114239ec0d9f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A1=C2=B7=C3=A6?= <279202647@qq.com>
Date: Wed, 14 Apr 2021 14:34:37 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=80=E5=A7=8B=E7=BB=93?=
=?UTF-8?q?=E6=9D=9F=E4=BA=8B=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
JdShopListener/JdShopListener/App.xaml | 3 +-
.../Converters/ToStringConverter.cs | 68 +++++++++
JdShopListener/JdShopListener/MainWindow.xaml | 11 +-
.../JdShopListener/MainWindowViewModel.cs | 144 +++++++++++-------
4 files changed, 165 insertions(+), 61 deletions(-)
create mode 100644 JdShopListener/JdShopListener/Converters/ToStringConverter.cs
diff --git a/JdShopListener/JdShopListener/App.xaml b/JdShopListener/JdShopListener/App.xaml
index 7c0b171..f30edd3 100644
--- a/JdShopListener/JdShopListener/App.xaml
+++ b/JdShopListener/JdShopListener/App.xaml
@@ -2,8 +2,9 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:JdShopListener"
+ xmlns:helper="clr-namespace:WPF.Converters"
StartupUri="MainWindow.xaml">
-
+
diff --git a/JdShopListener/JdShopListener/Converters/ToStringConverter.cs b/JdShopListener/JdShopListener/Converters/ToStringConverter.cs
new file mode 100644
index 0000000..c2ae626
--- /dev/null
+++ b/JdShopListener/JdShopListener/Converters/ToStringConverter.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Windows.Data;
+
+namespace WPF.Converters
+{
+
+ public class ToStringConverter : IValueConverter
+ {
+
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (parameter == null)
+ {
+ return value;
+ }
+
+ string key = string.Empty;
+ if (value == null)
+ {
+ key = "null";
+ }
+ else
+ {
+ key = value.ToString().ToLower();
+ }
+ string[] arr = parameter.ToString().Split('|');
+
+ Dictionary dic = new Dictionary();
+
+ foreach (var str in arr)
+ {
+ string[] drr = str.Split(new string[] { "----" }, StringSplitOptions.None);
+ dic.Add(drr[0].ToLower(), drr[1]);
+ }
+
+ if (dic.ContainsKey(key))
+ {
+ if (dic[key] == "Collapsed")
+ return System.Windows.Visibility.Collapsed;
+ if (dic[key] == "Visible")
+ return System.Windows.Visibility.Visible;
+
+ return dic[key];
+ }
+ else
+ if (dic.FirstOrDefault().Value.ToString() == "Visible")
+ {
+ return System.Windows.Visibility.Collapsed;
+ }
+ else
+ if (dic.FirstOrDefault().Value.ToString() == "Collapsed")
+ return System.Windows.Visibility.Visible;
+ return value;
+ }
+
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ string strValue = value.ToString();
+ return value;
+ }
+
+ }
+}
diff --git a/JdShopListener/JdShopListener/MainWindow.xaml b/JdShopListener/JdShopListener/MainWindow.xaml
index 7212ae6..ec7978d 100644
--- a/JdShopListener/JdShopListener/MainWindow.xaml
+++ b/JdShopListener/JdShopListener/MainWindow.xaml
@@ -167,7 +167,12 @@
-
+
+
+
+
+
+
@@ -204,12 +209,12 @@
-
+
-
+
diff --git a/JdShopListener/JdShopListener/MainWindowViewModel.cs b/JdShopListener/JdShopListener/MainWindowViewModel.cs
index b5842da..0b15bc9 100644
--- a/JdShopListener/JdShopListener/MainWindowViewModel.cs
+++ b/JdShopListener/JdShopListener/MainWindowViewModel.cs
@@ -173,83 +173,107 @@ namespace JdShopListener
///
public RelayCommand Btn_ShowData { get; set; }
+ private bool _IsAdd;
+
+ public bool IsAdd
+ {
+ get { return _IsAdd; }
+ set { Set(ref _IsAdd, value); }
+ }
+
+ private bool _IsStart;
+
+ public bool IsStart
+ {
+ get { return _IsStart; }
+ set { Set(ref _IsStart, value); }
+ }
+
+
///
/// 添加
///
public void Add()
{
+ if (IsAdd)
+ return;
- Thread addThread=new Thread(()=>{
-
- var detail= GetItemDetail(Sku);
-
- var list = detail.product.colorSize;
+ IsAdd = true;
+ Thread addThread = new Thread(() =>
+ {
- //spuId
- string spuId = detail.product.mainSkuId;
+ var detail = GetItemDetail(Sku);
+ var list = detail.product.colorSize;
- List skus = new List();
+ //spuId
+ string spuId = detail.product.mainSkuId;
- foreach (var sku in list)
- {
- SkuModel model = new SkuModel()
- {
- Desc = Desc,
- SkuId = sku.skuId,
- SpuId=spuId
- };
- //去除重复
- if (SkuList.Count(c => c.SkuId == model.SkuId) > 0)
- continue;
+ List skus = new List();
- //加入本地数据库
- skus.Add(model);
- Application.Current.Dispatcher.Invoke(() => {
+ foreach (var sku in list)
+ {
+ 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 =>
- {
- var detail = GetItemDetail(sku.SkuId);
+ //加载sku详情
+ skus.ForEach(sku =>
+ {
+ var detail = GetItemDetail(sku.SkuId);
//主图
string src = detail.product.src;
- var catIds = detail.product.cat;
+ 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 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;
- Thread.Sleep(3000);
- });
+ Thread.Sleep(3000);
+ });
+
+ if (DbHelper.Db.AddSkuModel(skus))
+ {
+ MessageBox.Show("添加成功", "提示");
+ }
- if (DbHelper.Db.AddSkuModel(skus))
- {
- MessageBox.Show("添加成功","提示");
- }
+ IsAdd = false;
});
addThread.Start();
}
@@ -269,15 +293,20 @@ namespace JdShopListener
///
public void Start()
{
- Thread t = new Thread(() =>
+ if (!IsStart)
{
- LastItemChangeList.Clear();
- LastItemChangeList = DbHelper.Db.GetLastItemChanges();
+ IsStart = true;
+ Thread t = new Thread(() =>
+ {
+ LastItemChangeList.Clear();
+ LastItemChangeList = DbHelper.Db.GetLastItemChanges();
+ DoWork();
- DoWork();
- });
- t.Start();
+ IsStart = false;
+ });
+ t.Start();
+ }
}
///
@@ -293,7 +322,8 @@ namespace JdShopListener
if (SelectPro == null||SelectDate==null)
return;
- var list= DbHelper.Db.GetItemChanges(DateTime.Now.AddDays(SelectDate.Day));
+ var list = DbHelper.Db.GetItemChanges(DateTime.Now.AddDays(SelectDate.Day)).Where(c => c.OldPrice > 0).ToList();
+
switch (SelectPro.Type)
{
case ProType.Active:
@@ -588,9 +618,9 @@ namespace JdShopListener
if (lastSku.NewActive != item.NewActive||lastSku.NewCoupons!=item.NewCoupons||lastSku.NewPrice!=item.NewPrice||lastSku.NewPromotion!=item.NewPromotion)
{
item.OldActive = lastSku.NewActive;
- item.OldCoupons = lastSku.OldCoupons;
- item.OldPrice = lastSku.OldPrice;
- item.OldPromotion = lastSku.OldPromotion;
+ item.OldCoupons = lastSku.NewCoupons;
+ item.OldPrice = lastSku.NewPrice;
+ item.OldPromotion = lastSku.NewPromotion;
DbHelper.Db.AddItemChangeModel(item);