This commit is contained in:
thuannd88
2024-09-05 15:58:31 +07:00
parent acfa22a83a
commit 7e927dfcc9
10 changed files with 220 additions and 20 deletions
+52
View File
@@ -12,6 +12,8 @@ using System.Text.Json.Serialization;
using Newtonsoft.Json;
using System.Threading.Tasks;
using Serilog;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace SafeBagDE70.API
{
@@ -99,7 +101,37 @@ namespace SafeBagDE70.API
return bSuccess;
}
public static async Task<List<AeonMallCustomer>> GetAeonMallCustomers(int tenantId)
{
try
{
var url = URL + "GetAeonMallCustomers?tenantId="+tenantId;
HttpClientHandler clientHandler = new HttpClientHandler();
clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
// Pass the handler to httpclient(from you are calling api)
HttpClient client = new HttpClient(clientHandler);
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
string jsonResponse = await response.Content.ReadAsStringAsync();
var tenants = JsonConvert.DeserializeObject<List<AeonMallCustomer>>(jsonResponse);
return tenants;
}
else
{
Log.Error($"Error: {response.StatusCode}");
return null;
}
}
catch (Exception ex)
{
Log.Fatal($"Exception: {ex.Message}");
return null;
}
}
private static string GetMACAddress()
@@ -130,6 +162,26 @@ namespace SafeBagDE70.API
}
}
public class AeonMallCustomer
{
public long Id { get; set; }
public DateTime CreationTime { get; set; }
public long? CreatorUserId { get; set; }
public long? DeleterUserId { get; set; }
public DateTime? DeletionTime { get; set; }
public bool IsDeleted { get; set; }
public DateTime? LastModificationTime { get; set; }
public long? LastModifierUserId { get; set; }
public int? TenantId { get; set; }
public string? Cards { get; set; }
public string? TenantCode { get; set; }
public string? TenantName { get; set; }
public string? TenantShortName { get; set; }
public string? OpenningDate { get; set; }
public string? Note { get; set; }
public string? Type { get; set; }
public string? TimeTag { get; set; }
}
}
+1 -1
View File
@@ -46,7 +46,7 @@
Margin="10"
Click="DashboardButton_Click"/>
<Button
Content="Quản lý vận hành"
Content="Quản lý người dùng"
HorizontalAlignment="Stretch"
Height="40"
Margin="10"
+3 -1
View File
@@ -22,11 +22,13 @@ namespace SafeBagDE70.Admin
{
LogViewerUC loguc;
AdminConfigurationUC configuration;
UserManageUC userManage;
public AdminWindow()
{
InitializeComponent();
loguc= new LogViewerUC();
configuration = new AdminConfigurationUC();
userManage=new UserManageUC();
this.MainContentControl.Content = loguc;
this.Loaded += AdminWindow_Loaded;
}
@@ -43,7 +45,7 @@ namespace SafeBagDE70.Admin
private void UserManagementButton_Click(object sender, RoutedEventArgs e)
{
this.MainContentControl.Content = userManage;
}
private void DashboardButton_Click(object sender, RoutedEventArgs e)
+16
View File
@@ -0,0 +1,16 @@
<UserControl x:Class="SafeBagDE70.Admin.UserManageUC"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SafeBagDE70.Admin"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<StackPanel>
<TextBlock Text="Realtime Logs" FontSize="20" Margin="10"/>
<ListView x:Name="LogListView" Height="500" Margin="10"/>
<Button Content="Get Users" Width="200" Margin="10" x:Name="btnGetUsers" Click="btnGetUsers_Click"/>
</StackPanel>
</Grid>
</UserControl>
+69
View File
@@ -0,0 +1,69 @@
using Microsoft.Extensions.Logging;
using SafeBagDE70.API;
using SafeBagDE70.Model;
using Serilog;
using Serilog.Core;
using Serilog.Events;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;
namespace SafeBagDE70.Admin
{
/// <summary>
/// Interaction logic for LogViewerUC.xaml
/// </summary>
public partial class UserManageUC : UserControl
{
private ObservableCollection<string> _logItems = new ObservableCollection<string>();
public UserManageUC()
{
InitializeComponent();
}
private void LogInfoButton_Click(object sender, RoutedEventArgs e)
{
}
private async void btnGetUsers_Click(object sender, RoutedEventArgs e)
{
var amCustomers= await APIModels.GetAeonMallCustomers(5);
using(var context = new CDMDbContext())
{
var customers = context.Customers;
context.Customers.RemoveRange(customers);
context.SaveChanges();
foreach (var amCustomer in amCustomers)
{
var customer = new Customer
{
AccountNumber = amCustomer.TenantCode,
AccountHolder = amCustomer.TenantName,
TenantName = amCustomer.TenantShortName,
TenantCode = amCustomer.TenantCode,
PinCode = amCustomer.TenantCode,
UpdatedTime = DateTime.Now,
};
customers.Add(customer);
}
context.SaveChanges();
}
}
}
}
+4
View File
@@ -69,6 +69,10 @@ namespace SafeBagDE70
.CreateLogger();
AppData.CDMPort = configuration["SerialPort:CDMPort"];
AppData.SensorPort = configuration["SerialPort:SensorPort"];
var maxNotes = int.Parse("0"+configuration["CDM:MaxNotes"]);
if(maxNotes > 0)
AppData.MaxNotes = maxNotes;
StateMachineConfig = new StateMachineConfig();
configuration.GetSection("StateMachine").Bind(StateMachineConfig);
Log.Information("START APP");
+23 -10
View File
@@ -29,20 +29,27 @@ namespace SafeBagDE70
public static ObservableCollection<string> logCollection = new ObservableCollection<string>();
public static ListView logListView = null;
public static int MaxLogCount = 500;
public static int MaxNotes = 300;
public static DeviceStatus? DeviceStatus = null;
public static void Init()
{
customerAccounts = new List<CustomerAccount>{
new CustomerAccount{Name="NGUYỄN ĐÌNH THUẬN",CustomerId="HUE_0000000001",QRCode="HUE_0000000001",PINCode="H0001" },
new CustomerAccount{Name="HOÀNG VĂN HIỆP",CustomerId="HUE_0000000002",QRCode="HUE_0000000002",PINCode="H0002" },
new CustomerAccount{Name="PHẠM NGỌC HƯNG",CustomerId="HUE_0000000003",QRCode="HUE_0000000003",PINCode="H0003" },
new CustomerAccount{Name="AMHUE-ESTELLETEST",CustomerId="00DZAMHUE0004",QRCode="00DZAMHUE0004",PINCode="H0004" },
new CustomerAccount{Name="AMHUE-ECCOTEST",CustomerId="00DZAMHUE0005",QRCode="00DZAMHUE0005",PINCode="H0005" },
new CustomerAccount{Name="AMHUE-ALDOTEST",CustomerId="00DZAMHUE0006",QRCode="00DZAMHUE0006",PINCode="H0006" },
new CustomerAccount{Name="AMHUE-MLBTEST",CustomerId="00DZAMHUE0007",QRCode="00DZAMHUE0007",PINCode="H0007" },
new CustomerAccount{Name="AMHUE-PEDROTEST",CustomerId="00DZAMHUE0008",QRCode="00DZAMHUE0008",PINCode="H0008" }
customerAccounts = new List<CustomerAccount>();
using (var context = new CDMDbContext())
{
var customers = context.Customers;
foreach(var customer in customers)
{
var ca = new CustomerAccount
{
Name = customer.TenantName,
CustomerId = customer.AccountNumber,
QRCode = customer.AccountNumber,
PINCode = customer.PinCode
};
customerAccounts.Add(ca);
}
}
CurrentCustomerAccount = customerAccounts[0];
CDMSTATE=new CDMSTATE();
DeviceStatus = new DeviceStatus
@@ -107,9 +114,14 @@ namespace SafeBagDE70
AppData.CDMSTATE.IsRejectPocketFull = data[3] & 0x40;
AppData.CDMSTATE.IsNotesInRejectPocket = data[3] & 0x10;
AppData.CDMSTATE.IsNotesInHopper = data[3] & 0x01;
if (data[0] == 0x40 && data[1] == 0x07 && data[2] == 0x41)
AppData.CDMSTATE.IsError = 0;
else
AppData.CDMSTATE.IsError = 1;
AppData.CDMSTATE.RequestTime = DateTime.Now;
AppData.CDMSTATE.UpdateCDMStatus(cCmdRsp.recv_dat);
}
}
@@ -258,6 +270,7 @@ namespace SafeBagDE70
public int IsRejectPocketFull = 0;
public int IsNotesInRejectPocket = 0;
public int IsNotesInHopper = 0;
public int IsError = 0;
public RecvData? RecvDat = null;
public byte GetSR1()
{
+34 -4
View File
@@ -591,7 +591,6 @@ namespace SafeBagDE70
private bool DoCountStart()
{
bool bSuccess = true;
printerFlag = false;
string currentMethod = MethodBase.GetCurrentMethod().Name;
try
@@ -620,6 +619,14 @@ namespace SafeBagDE70
AutoSerialGet();
bIsCounted = true;
Log.Information("After AutoCount: " + GetShortInforFromCountItems());
var state=GetCDMState();
if (state.IsError>0)
{
string str = "ĐÃ XẢY RA LỖI TRONG QUÁ TRÌNH NỘP TIỀN";
Log.Information(str);
DoCheck();
EndSession(COUNTINGSTATE.FULLIFSTORE, str);
}
});
@@ -835,7 +842,7 @@ namespace SafeBagDE70
//Debug.WriteLine(quantityStored);
var previousCassetData = AppData.GetCassetteData();
if(CheckPreStoreValid(previousCassetData,300,sessions))
if(CheckPreStoreValid(previousCassetData, AppData.MaxNotes, sessions))
{
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_STORESTART);
bSuccess = WaitUntilCountReady(10);
@@ -1028,18 +1035,41 @@ namespace SafeBagDE70
if (AppData.CurrentCustomerAccount != null)
{
var strTransactionCode = AppData.CurrentCustomerAccount.TransactionCode;
strNotify = strTransactionCode + "\r\n" + strNotify;
strNotify = "MÃ GD: "+strTransactionCode + "\r\n" + strNotify;
}
if(strMessage!=null)
{
strNotify += strMessage;
}
Dispatcher.Invoke(() =>
{
mainWindow.ShowInformationScreen(strNotify, false, false);
});
ResetSessions();
StartWelcomeTimer();
}
else if(strMessage!=null)
{
var strNotify = "";
if (AppData.CurrentCustomerAccount != null)
{
var strTransactionCode = AppData.CurrentCustomerAccount.TransactionCode;
strNotify = "MÃ GD: "+strTransactionCode + "\r\n" + strNotify;
}
if (strMessage != null)
{
strNotify += strMessage;
}
Dispatcher.Invoke(() =>
{
mainWindow.ShowInformationScreen(strNotify, false, false);
});
ResetSessions();
StartWelcomeTimer();
}
else
{
mainWindow.ShowWelcomeScreen();
@@ -1171,7 +1201,7 @@ namespace SafeBagDE70
var shopName = AppData.CurrentCustomerAccount.Name;
var shopCode = AppData.CurrentCustomerAccount.CustomerId;
var tradingCode = AppData.CurrentCustomerAccount.TransactionCode;// "TRA04052024CDM";
var storeAccountNumber = 686868686688;
var storeAccountNumber = AppData.CurrentCustomerAccount.CustomerId;
var currentTime = DateTime.Now;
var printDocument = new PrintDocument();
+11
View File
@@ -12,6 +12,7 @@ namespace SafeBagDE70.Model
internal class CDMDbContext:DbContext
{
public DbSet<History> Histories { get; set; }
public DbSet<Customer> Customers { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Server=.\\SQLEXPRESS;Database=CDMLOCAL;User Id=cdm;Password=Navis@123;Trusted_Connection=False;TrustServerCertificate=True");
@@ -35,4 +36,14 @@ namespace SafeBagDE70.Model
public string Status { get; set; }
}
public class Customer
{
public int Id { get; set; }
public string? TenantName { get; set; }
public string? TenantCode { get; set; }
public string? AccountNumber { get; set; }
public string? AccountHolder { get; set; }
public string? PinCode { get; set; }
public DateTime? UpdatedTime { get; set; }
}
}
+3
View File
@@ -14,6 +14,9 @@
"CDMPort": "COM4",
"SensorPort": "COM3"
},
"CDM": {
"MaxNotes": 300
},
"StateMachine": {
"States": [
"Start",