14 changed files with 610 additions and 63 deletions
@ -0,0 +1,37 @@ |
|||
<Window x:Class="JdShopListener.ItemsWindow" |
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
|||
xmlns:local="clr-namespace:JdShopListener" |
|||
mc:Ignorable="d" |
|||
Title="ItemsWindow" Height="450" Width="800"> |
|||
<Grid> |
|||
<ListBox BorderBrush="Transparent" ItemsSource="{Binding SkuList}"> |
|||
<ListBox.ItemTemplate> |
|||
<DataTemplate> |
|||
<DockPanel> |
|||
<StackPanel Orientation="Horizontal" Width="380" DockPanel.Dock="Left"> |
|||
<Image Width="50" Height="50" Source="{Binding ImgUrl}" Margin="0 0 10 0"></Image> |
|||
<StackPanel VerticalAlignment="Center"> |
|||
<StackPanel Orientation="Horizontal"> |
|||
<TextBlock Text="ID:"></TextBlock> |
|||
<TextBlock Text="{Binding SkuId}"></TextBlock> |
|||
</StackPanel> |
|||
<StackPanel Orientation="Horizontal" Margin="0 10 0 0"> |
|||
<TextBlock Text="备注:"></TextBlock> |
|||
<TextBlock Text="{Binding Desc}"></TextBlock> |
|||
</StackPanel> |
|||
</StackPanel> |
|||
</StackPanel> |
|||
|
|||
<Button Content="删除" VerticalAlignment="Center" HorizontalAlignment="Center" Padding="15 3" Click="btn_Del_Click" Name="btn_Del"> |
|||
|
|||
</Button> |
|||
|
|||
</DockPanel> |
|||
</DataTemplate> |
|||
</ListBox.ItemTemplate> |
|||
</ListBox> |
|||
</Grid> |
|||
</Window> |
@ -0,0 +1,53 @@ |
|||
using JdShopListener.Models; |
|||
using JdShopListener.SqlHelpers; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using System.Windows; |
|||
using System.Windows.Controls; |
|||
using System.Windows.Data; |
|||
using System.Windows.Documents; |
|||
using System.Windows.Input; |
|||
using System.Windows.Media; |
|||
using System.Windows.Media.Imaging; |
|||
using System.Windows.Shapes; |
|||
|
|||
namespace JdShopListener |
|||
{ |
|||
/// <summary>
|
|||
/// ItemsWindow.xaml 的交互逻辑
|
|||
/// </summary>
|
|||
public partial class ItemsWindow : Window |
|||
{ |
|||
|
|||
private System.Collections.ObjectModel.ObservableCollection<SkuModel> _SkuList; |
|||
/// <summary>
|
|||
/// sku监控列表
|
|||
/// </summary>
|
|||
public System.Collections.ObjectModel.ObservableCollection<SkuModel> SkuList |
|||
{ |
|||
get { return _SkuList; } |
|||
set { _SkuList = value; } |
|||
} |
|||
|
|||
public ItemsWindow(System.Collections.ObjectModel.ObservableCollection<SkuModel> skuList) |
|||
{ |
|||
InitializeComponent(); |
|||
SkuList = skuList; |
|||
this.DataContext = this; |
|||
} |
|||
|
|||
private void btn_Del_Click(object sender, RoutedEventArgs e) |
|||
{ |
|||
var model = (e.Source as FrameworkElement).DataContext as SkuModel; |
|||
|
|||
if (MessageBox.Show($"是否删除{model.Title}?", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes) |
|||
{ |
|||
if (DbHelper.Db.RemoveSkuModel(model)) |
|||
{ |
|||
SkuList.Remove(model); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,78 @@ |
|||
// <auto-generated />
|
|||
using System; |
|||
using JdShopListener; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Infrastructure; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
|||
|
|||
namespace JdShopListener.Migrations |
|||
{ |
|||
[DbContext(typeof(JdDBContext))] |
|||
[Migration("20210413085518_InitialCreate")] |
|||
partial class InitialCreate |
|||
{ |
|||
protected override void BuildTargetModel(ModelBuilder modelBuilder) |
|||
{ |
|||
#pragma warning disable 612, 618
|
|||
modelBuilder |
|||
.HasAnnotation("ProductVersion", "5.0.5"); |
|||
|
|||
modelBuilder.Entity("JdShopListener.Models.ItemChangeModel", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.ValueGeneratedOnAdd() |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<DateTime>("Date") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("Desc") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("ImgUrl") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<decimal>("NewPrice") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<decimal>("OldPrice") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("SkuId") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.ToTable("ItemChange"); |
|||
}); |
|||
|
|||
modelBuilder.Entity("JdShopListener.Models.SkuModel", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.ValueGeneratedOnAdd() |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("Desc") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("ImgUrl") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("SkuId") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("SpuId") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("Title") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.ToTable("SkuModel"); |
|||
}); |
|||
#pragma warning restore 612, 618
|
|||
} |
|||
} |
|||
} |
@ -0,0 +1,53 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace JdShopListener.Migrations |
|||
{ |
|||
public partial class InitialCreate : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.CreateTable( |
|||
name: "ItemChange", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "TEXT", nullable: false), |
|||
SkuId = table.Column<string>(type: "TEXT", nullable: true), |
|||
Desc = table.Column<string>(type: "TEXT", nullable: true), |
|||
ImgUrl = table.Column<string>(type: "TEXT", nullable: true), |
|||
OldPrice = table.Column<decimal>(type: "TEXT", nullable: false), |
|||
NewPrice = table.Column<decimal>(type: "TEXT", nullable: false), |
|||
Date = table.Column<DateTime>(type: "TEXT", nullable: false) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_ItemChange", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "SkuModel", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "TEXT", nullable: false), |
|||
SkuId = table.Column<string>(type: "TEXT", nullable: true), |
|||
ImgUrl = table.Column<string>(type: "TEXT", nullable: true), |
|||
SpuId = table.Column<string>(type: "TEXT", nullable: true), |
|||
Desc = table.Column<string>(type: "TEXT", nullable: true), |
|||
Title = table.Column<string>(type: "TEXT", nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_SkuModel", x => x.Id); |
|||
}); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "ItemChange"); |
|||
|
|||
migrationBuilder.DropTable( |
|||
name: "SkuModel"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,76 @@ |
|||
// <auto-generated />
|
|||
using System; |
|||
using JdShopListener; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Infrastructure; |
|||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
|||
|
|||
namespace JdShopListener.Migrations |
|||
{ |
|||
[DbContext(typeof(JdDBContext))] |
|||
partial class JdDBContextModelSnapshot : ModelSnapshot |
|||
{ |
|||
protected override void BuildModel(ModelBuilder modelBuilder) |
|||
{ |
|||
#pragma warning disable 612, 618
|
|||
modelBuilder |
|||
.HasAnnotation("ProductVersion", "5.0.5"); |
|||
|
|||
modelBuilder.Entity("JdShopListener.Models.ItemChangeModel", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.ValueGeneratedOnAdd() |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<DateTime>("Date") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("Desc") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("ImgUrl") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<decimal>("NewPrice") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<decimal>("OldPrice") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("SkuId") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.ToTable("ItemChange"); |
|||
}); |
|||
|
|||
modelBuilder.Entity("JdShopListener.Models.SkuModel", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.ValueGeneratedOnAdd() |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("Desc") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("ImgUrl") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("SkuId") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("SpuId") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.Property<string>("Title") |
|||
.HasColumnType("TEXT"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.ToTable("SkuModel"); |
|||
}); |
|||
#pragma warning restore 612, 618
|
|||
} |
|||
} |
|||
} |
@ -0,0 +1,141 @@ |
|||
using JdShopListener.Models; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using System.Linq; |
|||
using SQLitePCL; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
namespace JdShopListener.SqlHelpers |
|||
{ |
|||
public class DbHelper |
|||
{ |
|||
public static DbHelper Db = new DbHelper(); |
|||
|
|||
/// <summary>
|
|||
/// 添加sku监控
|
|||
/// </summary>
|
|||
/// <param name="model"></param>
|
|||
/// <returns></returns>
|
|||
public bool AddSkuModel(SkuModel model) |
|||
{ |
|||
using (var db = new JdDBContext()) |
|||
{ |
|||
model.Id = Guid.NewGuid(); |
|||
db.SkuItems.Add(model); |
|||
var count = db.SaveChanges(); |
|||
return count > 0; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 批量添加sku监控
|
|||
/// </summary>
|
|||
/// <param name="models"></param>
|
|||
/// <returns></returns>
|
|||
public bool AddSkuModel(List<SkuModel> models) |
|||
{ |
|||
using (var db = new JdDBContext()) |
|||
{ |
|||
models.ForEach(model => |
|||
{ |
|||
model.Id = Guid.NewGuid(); |
|||
db.SkuItems.Add(model); |
|||
}); |
|||
var count = db.SaveChanges(); |
|||
return count > 0; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取sku监控列表
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public List<SkuModel> GetSkuList() |
|||
{ |
|||
using (var db = new JdDBContext()) |
|||
{ |
|||
return db.SkuItems.ToList(); |
|||
} |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 删除Sku
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public bool RemoveSkuModel(SkuModel model) |
|||
{ |
|||
using (var db = new JdDBContext()) |
|||
{ |
|||
|
|||
db.SkuItems.Remove(model); |
|||
return db.SaveChanges()>0; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 添加变化记录
|
|||
/// </summary>
|
|||
/// <param name="model"></param>
|
|||
/// <returns></returns>
|
|||
public bool AddItemChangeModel(ItemChangeModel model) |
|||
{ |
|||
using (var db = new JdDBContext()) |
|||
{ |
|||
model.Id = Guid.NewGuid(); |
|||
db.ItemChanges.Add(model); |
|||
var count = db.SaveChanges(); |
|||
return count > 0; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 批量添加变化记录
|
|||
/// </summary>
|
|||
/// <param name="models"></param>
|
|||
/// <returns></returns>
|
|||
public bool AddItemChangeModel(List<ItemChangeModel> models) |
|||
{ |
|||
using (var db = new JdDBContext()) |
|||
{ |
|||
models.ForEach(model => |
|||
{ |
|||
model.Id = Guid.NewGuid(); |
|||
db.ItemChanges.Add(model); |
|||
}); |
|||
var count = db.SaveChanges(); |
|||
return count > 0; |
|||
} |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 根据日期批量获取变化记录
|
|||
/// </summary>
|
|||
/// <param name="date"></param>
|
|||
/// <returns></returns>
|
|||
public List<ItemChangeModel> GetItemChanges(DateTime date) |
|||
{ |
|||
using (var db = new JdDBContext()) |
|||
{ |
|||
return db.ItemChanges.Where(c => c.Date.Date == date.Date).ToList(); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 删除
|
|||
/// </summary>
|
|||
/// <param name="model"></param>
|
|||
/// <returns></returns>
|
|||
public bool RemoveItemChanges(ItemChangeModel model) |
|||
{ |
|||
using (var db = new JdDBContext()) |
|||
{ |
|||
|
|||
db.ItemChanges.Remove(model); |
|||
return db.SaveChanges() > 0; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -1,29 +0,0 @@ |
|||
using JdShopListener.Models; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace JdShopListener.SqlHelpers |
|||
{ |
|||
public class SkuModelSql |
|||
{ |
|||
/// <summary>
|
|||
/// 添加sku监控
|
|||
/// </summary>
|
|||
/// <param name="model"></param>
|
|||
/// <returns></returns>
|
|||
public bool AddSkuModel(SkuModel model) |
|||
{ |
|||
using (var db = new JdDBContext()) |
|||
{ |
|||
model.Id = Guid.NewGuid(); |
|||
db.SkuItems.Add(model); |
|||
var count = db.SaveChanges(); |
|||
return count > 0; |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
} |
Binary file not shown.
Loading…
Reference in new issue