Browse Source

增加日志记录

master
С·æ 4 years ago
parent
commit
e61fe39562
  1. 1
      JdShopListener/JdShopListener/JdShopListener.csproj
  2. 4
      JdShopListener/JdShopListener/MainWindow.xaml
  3. 46
      JdShopListener/JdShopListener/MainWindowViewModel.cs

1
JdShopListener/JdShopListener/JdShopListener.csproj

@ -4,6 +4,7 @@
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
<AssemblyName>跟屁虫</AssemblyName>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

4
JdShopListener/JdShopListener/MainWindow.xaml

@ -303,6 +303,10 @@
</TabItem> </TabItem>
<TabItem Header="日志">
<TextBox Text="{Binding LogText}" AcceptsReturn="True" IsReadOnly="True"></TextBox>
</TabItem>
</TabControl> </TabControl>
</Grid> </Grid>
</Window> </Window>

46
JdShopListener/JdShopListener/MainWindowViewModel.cs

@ -97,6 +97,16 @@ namespace JdShopListener
set { Set(ref _SelectPro, value); ShowData(); } set { Set(ref _SelectPro, value); ShowData(); }
} }
private string _LogText;
/// <summary>
/// 日志
/// </summary>
public string LogText
{
get { return _LogText; }
set { Set(ref _LogText, value); }
}
private DateModel _SelectDate; private DateModel _SelectDate;
/// <summary> /// <summary>
@ -190,6 +200,14 @@ namespace JdShopListener
} }
private void AddLog(string log)
{
Application.Current.Dispatcher.Invoke(() =>
{
LogText += log + "\r\n";
});
}
/// <summary> /// <summary>
/// 添加 /// 添加
/// </summary> /// </summary>
@ -201,7 +219,8 @@ namespace JdShopListener
IsAdd = true; IsAdd = true;
Thread addThread = new Thread(() => Thread addThread = new Thread(() =>
{ {
try
{
var detail = GetItemDetail(Sku); var detail = GetItemDetail(Sku);
var list = detail.product.colorSize; var list = detail.product.colorSize;
@ -209,6 +228,11 @@ namespace JdShopListener
//spuId //spuId
string spuId = detail.product.mainSkuId; string spuId = detail.product.mainSkuId;
//if (list.Count == 0 || list.Count == null)
//{
// list.Add(new { skuId = Sku });
//}
List<SkuModel> skus = new List<SkuModel>(); List<SkuModel> skus = new List<SkuModel>();
@ -264,16 +288,30 @@ namespace JdShopListener
sku.ShopId = shopId; sku.ShopId = shopId;
sku.VenderId = vid; 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)) //if (DbHelper.Db.AddSkuModel(skus))
{ //{
MessageBox.Show("添加成功", "提示"); MessageBox.Show("添加成功", "提示");
} AddLog("全部相关sku添加成功!");
//}
IsAdd = false; IsAdd = false;
}
catch(Exception ex)
{
MessageBox.Show("添加失败,异常信息:"+ex.Message);
}
}); });
addThread.Start(); addThread.Start();
} }

Loading…
Cancel
Save