Browse Source

增加开始结束事件

master
С·æ 4 years ago
parent
commit
24f2e40e12
  1. 3
      JdShopListener/JdShopListener/App.xaml
  2. 68
      JdShopListener/JdShopListener/Converters/ToStringConverter.cs
  3. 11
      JdShopListener/JdShopListener/MainWindow.xaml
  4. 44
      JdShopListener/JdShopListener/MainWindowViewModel.cs

3
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">
<Application.Resources>
<helper:ToStringConverter x:Key="toString"></helper:ToStringConverter>
</Application.Resources>
</Application>

68
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<string, string> dic = new Dictionary<string, string>();
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;
}
}
}

11
JdShopListener/JdShopListener/MainWindow.xaml

@ -167,7 +167,12 @@
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding Title}"></TextBlock>
<TextBlock Text="{Binding Title}" x:Name="txt" ToolTip="{Binding Value}"></TextBlock>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Value}" Value="">
<Setter Property="ToolTip" TargetName="txt" Value="{x:Null}"></Setter>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</Setter.Value>
</Setter>
@ -204,12 +209,12 @@
<StackPanel DockPanel.Dock="Top">
<StackPanel Orientation="Horizontal">
<TextBox Tag="请输入SKu" Width="350" Text="{Binding Sku}"></TextBox>
<Button Content="添加" Command="{Binding Btn_Add}"></Button>
<Button Content="添加" Command="{Binding Btn_Add}" IsEnabled="{Binding IsAdd,Converter={StaticResource toString},ConverterParameter=true----false|false----true}"></Button>
<Button Content="监控列表" Command="{Binding Btn_ShowList}"></Button>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBox Tag="请输入备注" Text="{Binding Desc}" Width="350" Margin="0 10 0 0" HorizontalAlignment="Left"></TextBox>
<Button Content="开始监控" Command="{Binding Btn_Start}" Margin="10 10 0 0"></Button>
<Button Content="开始监控" IsEnabled="{Binding IsStart,Converter={StaticResource toString},ConverterParameter=true----false|false----true}" Command="{Binding Btn_Start}" Margin="10 10 0 0"></Button>
</StackPanel>
</StackPanel>

44
JdShopListener/JdShopListener/MainWindowViewModel.cs

@ -173,13 +173,34 @@ namespace JdShopListener
/// </summary>
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); }
}
/// <summary>
/// 添加
/// </summary>
public void Add()
{
if (IsAdd)
return;
Thread addThread=new Thread(()=>{
IsAdd = true;
Thread addThread = new Thread(() =>
{
var detail = GetItemDetail(Sku);
@ -206,7 +227,8 @@ namespace JdShopListener
//加入本地数据库
skus.Add(model);
Application.Current.Dispatcher.Invoke(() => {
Application.Current.Dispatcher.Invoke(() =>
{
SkuList.Add(model);
});
}
@ -250,6 +272,8 @@ namespace JdShopListener
MessageBox.Show("添加成功", "提示");
}
IsAdd = false;
});
addThread.Start();
}
@ -269,16 +293,21 @@ namespace JdShopListener
/// </summary>
public void Start()
{
if (!IsStart)
{
IsStart = true;
Thread t = new Thread(() =>
{
LastItemChangeList.Clear();
LastItemChangeList = DbHelper.Db.GetLastItemChanges();
DoWork();
IsStart = false;
});
t.Start();
}
}
/// <summary>
/// 显示数据
@ -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);

Loading…
Cancel
Save