Quellcode durchsuchen

刷卡端

Lishi
xxe vor 2 Jahren
Ursprung
Commit
c12fd60526
9 geänderte Dateien mit 161 neuen und 8 gelöschten Zeilen
  1. +5
    -0
      HKCardOUT/Bootstrapper.cs
  2. +0
    -3
      HKCardOUT/HKCardOUT.csproj
  3. +1
    -1
      HKCardOUT/Helper/DataBus.cs
  4. +22
    -0
      HKCardOUT/Logic/BaseEntity.cs
  5. +8
    -0
      HKCardOUT/Logic/DbContext.cs
  6. +29
    -0
      HKCardOUT/Logic/Model/SaleLog.cs
  7. +48
    -0
      HKCardOUT/Logic/Service/HKCore.cs
  8. +27
    -3
      HKCardOUT/ViewModels/RootViewModel.cs
  9. +21
    -1
      HKCardOUT/Views/RootView.xaml

+ 5
- 0
HKCardOUT/Bootstrapper.cs Datei anzeigen

@@ -8,6 +8,9 @@ using Microsoft.Extensions.Configuration;
using HKCardOUT.Helper;
using HKCardOUT.QuartzUtil.Job;
using HKCardOUT.QuartzUtil;
using HKCardOUT.Logic;
using HKCardOUT.Logic.Service;
using ImTools;

namespace HKCardOUT
{
@@ -23,6 +26,7 @@ namespace HKCardOUT

protected override void ConfigureIoC(IStyletIoCBuilder builder)
{
builder.Bind<HKCore>().ToSelf();
}

/// <summary>
@@ -34,6 +38,7 @@ namespace HKCardOUT
DataBus.ConnectionString = configer.GetConnectionString("Sqlite");
DataBus.Cron = configer["Cron"];
DataBus.SaasRoute = configer["SaasRoute"];
DbContext.InitTable();
base.Configure();
}



+ 0
- 3
HKCardOUT/HKCardOUT.csproj Datei anzeigen

@@ -39,9 +39,6 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Logic\Model\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HKLog\HKLog.csproj" />
</ItemGroup>


+ 1
- 1
HKCardOUT/Helper/DataBus.cs Datei anzeigen

@@ -17,7 +17,7 @@ namespace HKCardOUT.Helper
set
{
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;


+ 22
- 0
HKCardOUT/Logic/BaseEntity.cs Datei anzeigen

@@ -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;
}
}
}

+ 8
- 0
HKCardOUT/Logic/DbContext.cs Datei anzeigen

@@ -3,6 +3,7 @@ using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
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);
}
}
}

+ 29
- 0
HKCardOUT/Logic/Model/SaleLog.cs Datei anzeigen

@@ -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; }
}
}

+ 48
- 0
HKCardOUT/Logic/Service/HKCore.cs Datei anzeigen

@@ -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);
}
}
}

+ 27
- 3
HKCardOUT/ViewModels/RootViewModel.cs Datei anzeigen

@@ -1,19 +1,43 @@
using HKCardOut.Helper;
using HKCardOUT.Helper;
using HKCardOUT.Logic.Model;
using HKCardOUT.Logic.Service;
using Stylet;
using StyletIoC;
using System;
using System.Collections.ObjectModel;
using System.Threading;

namespace HKCardOUT.ViewModels
{
public class RootViewModel : PropertyChangedBase
public class RootViewModel : Conductor<IScreen>
{
public RootViewModel()
IContainer Container;
public RootViewModel(IContainer Container)
{
this.Container = Container;
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 方法
private void MainThread()
{


+ 21
- 1
HKCardOUT/Views/RootView.xaml Datei anzeigen

@@ -18,5 +18,25 @@
<hc:Window.Background>
<ImageBrush ImageSource="/HKResouces/背景.jpg" />
</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>

Laden…
Abbrechen
Speichern