@@ -8,6 +8,9 @@ using Microsoft.Extensions.Configuration; | |||||
using HKCardOUT.Helper; | using HKCardOUT.Helper; | ||||
using HKCardOUT.QuartzUtil.Job; | using HKCardOUT.QuartzUtil.Job; | ||||
using HKCardOUT.QuartzUtil; | using HKCardOUT.QuartzUtil; | ||||
using HKCardOUT.Logic; | |||||
using HKCardOUT.Logic.Service; | |||||
using ImTools; | |||||
namespace HKCardOUT | namespace HKCardOUT | ||||
{ | { | ||||
@@ -23,6 +26,7 @@ namespace HKCardOUT | |||||
protected override void ConfigureIoC(IStyletIoCBuilder builder) | protected override void ConfigureIoC(IStyletIoCBuilder builder) | ||||
{ | { | ||||
builder.Bind<HKCore>().ToSelf(); | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -34,6 +38,7 @@ namespace HKCardOUT | |||||
DataBus.ConnectionString = configer.GetConnectionString("Sqlite"); | DataBus.ConnectionString = configer.GetConnectionString("Sqlite"); | ||||
DataBus.Cron = configer["Cron"]; | DataBus.Cron = configer["Cron"]; | ||||
DataBus.SaasRoute = configer["SaasRoute"]; | DataBus.SaasRoute = configer["SaasRoute"]; | ||||
DbContext.InitTable(); | |||||
base.Configure(); | base.Configure(); | ||||
} | } | ||||
@@ -39,9 +39,6 @@ | |||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||||
</None> | </None> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | |||||
<Folder Include="Logic\Model\" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\HKLog\HKLog.csproj" /> | <ProjectReference Include="..\HKLog\HKLog.csproj" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
@@ -17,7 +17,7 @@ namespace HKCardOUT.Helper | |||||
set | set | ||||
{ | { | ||||
var Route = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DATA"); | var Route = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DATA"); | ||||
_ConnectionString = SyncStatic.CreateFile(Path.Combine(SyncStatic.CreateDir(Route), value)); | |||||
_ConnectionString = $"DataSource={SyncStatic.CreateFile(Path.Combine(SyncStatic.CreateDir(Route), value))}"; | |||||
} | } | ||||
} | } | ||||
public static bool NetWordState { get; set; } = false; | public static bool NetWordState { get; set; } = false; | ||||
@@ -0,0 +1,22 @@ | |||||
using SqlSugar; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace HKCardOUT.Logic | |||||
{ | |||||
public class BaseEntity | |||||
{ | |||||
[SugarColumn(IsPrimaryKey = true)] | |||||
public Guid Id { get; set; } | |||||
[SugarColumn(ColumnDataType = "DATETIME")] | |||||
public DateTime CreateTime { get; set; } | |||||
public void Create() | |||||
{ | |||||
this.Id = Guid.NewGuid(); | |||||
this.CreateTime = DateTime.Now; | |||||
} | |||||
} | |||||
} |
@@ -3,6 +3,7 @@ using SqlSugar; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Reflection; | |||||
using System.Text; | using System.Text; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
@@ -22,5 +23,12 @@ namespace HKCardOUT.Logic | |||||
}; | }; | ||||
}); | }); | ||||
public static void InitTable() | |||||
{ | |||||
var Tables = Assembly.GetAssembly(typeof(DbContext)) | |||||
.GetTypes().Where(t => t.BaseType == typeof(BaseEntity)).ToArray(); | |||||
Context.CodeFirst.InitTables(Tables); | |||||
} | |||||
} | } | ||||
} | } |
@@ -0,0 +1,29 @@ | |||||
using SqlSugar; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace HKCardOUT.Logic.Model | |||||
{ | |||||
[SugarTable("SaleLog")] | |||||
public class SaleLog : BaseEntity | |||||
{ | |||||
/// <summary> | |||||
/// 卡号 | |||||
/// </summary> | |||||
[SugarColumn(IsNullable = false)] | |||||
public string CardNo { get; set; } | |||||
/// <summary> | |||||
/// 消费金额 | |||||
/// </summary> | |||||
[SugarColumn(IsNullable = false, ColumnDataType = "decimal(10,2)")] | |||||
public decimal Money { get; set; } | |||||
/// <summary> | |||||
/// 消费位置 | |||||
/// </summary> | |||||
[SugarColumn(IsNullable = false)] | |||||
public string Location { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,48 @@ | |||||
using HKCardOUT.Logic.Model; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace HKCardOUT.Logic.Service | |||||
{ | |||||
public class HKCore | |||||
{ | |||||
/// <summary> | |||||
/// 刷卡消费 | |||||
/// </summary> | |||||
/// <param name="input"></param> | |||||
/// <returns></returns> | |||||
public bool DeviceSale(SaleLog input) | |||||
{ | |||||
var Old = DbContext.Context.Queryable<SaleLog>() | |||||
.Where(t => t.CardNo == input.CardNo).OrderByDescending(t => t.CreateTime).First(); | |||||
if (Old != null) | |||||
{ | |||||
//10秒防止重复刷卡 | |||||
if (Old.CreateTime.Subtract(DateTime.Now).TotalSeconds > 10d) | |||||
{ | |||||
return DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteCommand() > 0; | |||||
} | |||||
return false; | |||||
} | |||||
else | |||||
return DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteCommand() > 0; | |||||
} | |||||
/// <summary> | |||||
/// 获取当天消费前100条展示 | |||||
/// </summary> | |||||
/// <returns></returns> | |||||
public List<SaleLog> PullDaySaleLog() | |||||
{ | |||||
var Begin = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00")); | |||||
var End = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59")); | |||||
return DbContext.Context.Queryable<SaleLog>() | |||||
.Where(t => t.CreateTime >= Begin) | |||||
.Where(t => t.CreateTime < End) | |||||
.OrderByDescending(t => t.CreateTime).ToPageList(0, 10); | |||||
} | |||||
} | |||||
} |
@@ -1,19 +1,43 @@ | |||||
using HKCardOut.Helper; | using HKCardOut.Helper; | ||||
using HKCardOUT.Helper; | using HKCardOUT.Helper; | ||||
using HKCardOUT.Logic.Model; | |||||
using HKCardOUT.Logic.Service; | |||||
using Stylet; | using Stylet; | ||||
using StyletIoC; | |||||
using System; | using System; | ||||
using System.Collections.ObjectModel; | |||||
using System.Threading; | using System.Threading; | ||||
namespace HKCardOUT.ViewModels | namespace HKCardOUT.ViewModels | ||||
{ | { | ||||
public class RootViewModel : PropertyChangedBase | |||||
public class RootViewModel : Conductor<IScreen> | |||||
{ | { | ||||
public RootViewModel() | |||||
IContainer Container; | |||||
public RootViewModel(IContainer Container) | |||||
{ | { | ||||
this.Container = Container; | |||||
MainThread(); | MainThread(); | ||||
} | } | ||||
protected override void OnViewLoaded() | |||||
{ | |||||
Result = new ObservableCollection<SaleLog>(this.Container.Get<HKCore>().PullDaySaleLog()); | |||||
//ThreadManage.GetInstance().Start(() => | |||||
//{ | |||||
// Result = new ObservableCollection<SaleLog>(this.Container.Get<HKCore>().PullDaySaleLog()); | |||||
// Thread.Sleep(3000); | |||||
//}, "消费记录查询"); | |||||
} | |||||
#region 属性 | |||||
ObservableCollection<SaleLog> _Result; | |||||
public ObservableCollection<SaleLog> Result | |||||
{ | |||||
get => _Result; | |||||
set => SetAndNotify(ref _Result, value); | |||||
} | |||||
#endregion | |||||
#region 方法 | #region 方法 | ||||
private void MainThread() | private void MainThread() | ||||
{ | { | ||||
@@ -18,5 +18,25 @@ | |||||
<hc:Window.Background> | <hc:Window.Background> | ||||
<ImageBrush ImageSource="/HKResouces/背景.jpg" /> | <ImageBrush ImageSource="/HKResouces/背景.jpg" /> | ||||
</hc:Window.Background> | </hc:Window.Background> | ||||
<DataGrid | |||||
AutoGenerateColumns="False" | |||||
Background="Transparent" | |||||
ItemsSource="{Binding Result}"> | |||||
<DataGridTextColumn | |||||
Width="120" | |||||
Binding="{Binding CardNo}" | |||||
Header="卡号" /> | |||||
<DataGridTextColumn | |||||
Width="120" | |||||
Binding="{Binding Money}" | |||||
Header="金额" /> | |||||
<DataGridTextColumn | |||||
Width="120" | |||||
Binding="{Binding Location}" | |||||
Header="档口" /> | |||||
<DataGridTextColumn | |||||
Width="120" | |||||
Binding="{Binding CreateTime}" | |||||
Header="消费时间" /> | |||||
</DataGrid> | |||||
</hc:Window> | </hc:Window> |