Change Init Users

This commit is contained in:
Nguyen Dinh Thuan
2024-09-11 16:06:27 +07:00
parent b8d7056e42
commit 409d942352
6 changed files with 132 additions and 45 deletions
+1 -2
View File
@@ -8,9 +8,8 @@
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800">
<Grid> <Grid>
<StackPanel> <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"/> <Button Content="Get Users" Width="200" Margin="10" x:Name="btnGetUsers" Click="btnGetUsers_Click"/>
<Label x:Name="lblStatus"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
</UserControl> </UserControl>
+26 -18
View File
@@ -40,29 +40,37 @@ namespace SafeBagDE70.Admin
private async void btnGetUsers_Click(object sender, RoutedEventArgs e) private async void btnGetUsers_Click(object sender, RoutedEventArgs e)
{ {
var amCustomers= await APIModels.GetAeonMallCustomers(AppData.TenantId); try
using(var context = new CDMDbContext())
{ {
var customers = context.Customers; var amCustomers = await APIModels.GetAeonMallCustomers(AppData.TenantId);
context.Customers.RemoveRange(customers); using (var context = new CDMDbContext())
context.SaveChanges();
foreach (var amCustomer in amCustomers)
{ {
var customer = new Customer var customers = context.Customers;
context.Customers.RemoveRange(customers);
context.SaveChanges();
foreach (var amCustomer in amCustomers)
{ {
AccountNumber = amCustomer.TenantCode, var customer = new Customer
AccountHolder = amCustomer.TenantName, {
TenantName = amCustomer.TenantShortName, AccountNumber = amCustomer.TenantCode,
TenantCode = amCustomer.TenantCode, AccountHolder = amCustomer.TenantName,
PinCode = amCustomer.TenantCode, TenantName = amCustomer.TenantShortName,
UpdatedTime = DateTime.Now, TenantCode = amCustomer.TenantCode,
}; PinCode = amCustomer.TenantCode,
customers.Add(customer); UpdatedTime = DateTime.Now,
};
customers.Add(customer);
}
context.SaveChanges();
} }
context.SaveChanges(); lblStatus.Foreground = new SolidColorBrush(Colors.Green);
lblStatus.Content = "Updated customers: " + amCustomers.Count;
}
catch(Exception ex)
{
lblStatus.Foreground = new SolidColorBrush(Colors.Red);
lblStatus.Content= ex.Message;
} }
} }
} }
+72
View File
@@ -84,6 +84,78 @@ namespace SafeBagDE70
System.Windows.MessageBox.Show(ex.Message); System.Windows.MessageBox.Show(ex.Message);
} }
} }
private static void LoadConfig2()
{
try
{
AppData.CurrentVersion = Assembly.GetExecutingAssembly().GetName().Version;
VKeyboard.Listen<System.Windows.Controls.TextBox>(e => e.Text);
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
InitLogger(configuration);
AppData.CDMPort = configuration["SerialPort:CDMPort"];
AppData.SensorPort = configuration["SerialPort:SensorPort"];
AppData.BaseURL = configuration["Device:BaseURL"];
AppData.TenantId = int.Parse("0" + configuration["Device:TenantId"]);
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");
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
}
}
private static void InitLogger(IConfigurationRoot configuration)
{
var logPath = configuration["Serilog:WriteTo:0:Args:path"];
var rollingIntervalSetting = configuration["Serilog:WriteTo:0:Args:rollingInterval"];
// Ensure the path is relative to the application's directory
var resolvedLogPath = Path.IsPathRooted(logPath)
? logPath
: Path.Combine(AppDomain.CurrentDomain.BaseDirectory, logPath);
// Parse the rollingInterval from string to enum
RollingInterval rollingInterval = Enum.TryParse(rollingIntervalSetting, out RollingInterval interval)
? interval
: RollingInterval.Day; // Default to 'Day' if parsing fails
// Ensure the directory exists
var logDirectory = Path.GetDirectoryName(resolvedLogPath);
if (!Directory.Exists(logDirectory))
{
Directory.CreateDirectory(logDirectory);
}
// Configure Serilog to write logs to the resolved log path
Log.Logger = new LoggerConfiguration()
.WriteTo.File(
path: resolvedLogPath,
rollingInterval: rollingInterval
)
.WriteTo.Sink(new RealTimeLogSink())
.CreateLogger();
try
{
Log.Information("Application Starting...");
// Your application code here
}
catch (Exception ex)
{
Log.Fatal(ex, "Application failed to start.");
}
finally
{
Log.CloseAndFlush();
}
}
private void LoadDualScreens() private void LoadDualScreens()
{ {
try try
+13 -8
View File
@@ -39,6 +39,7 @@ namespace SafeBagDE70
{ {
try try
{ {
InitUsers();
CDMSTATE = new CDMSTATE(); CDMSTATE = new CDMSTATE();
DeviceStatus = new DeviceStatus DeviceStatus = new DeviceStatus
{ {
@@ -51,12 +52,10 @@ namespace SafeBagDE70
Notes = "", Notes = "",
OtherError = 0, OtherError = 0,
}; };
InitUsers();
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Fatal(ex, "AppInit"); Log.Fatal(ex, "AppInit: "+ex.Message);
} }
} }
@@ -85,12 +84,18 @@ namespace SafeBagDE70
public static CDMSTATE? CDMSTATE = null; public static CDMSTATE? CDMSTATE = null;
private static DateTime CutOffTime = new DateTime(1, 1, 1, 12, 0, 0); // 12:00 noon as cut-off time private static DateTime CutOffTime = new DateTime(1, 1, 1, 12, 0, 0); // 12:00 noon as cut-off time
public static string GetNumberPartFromMerchantCode(string merchantCode)
{
if (merchantCode == null) return "";
var match = Regex.Match(merchantCode, @"\d+$");
string merchantCode_part = match.Value;
return merchantCode_part;
}
public static void CreateNewTransactionCode() public static void CreateNewTransactionCode()
{ {
DateTime transactionDateTime = DateTime.Now; DateTime transactionDateTime = DateTime.Now;
var match = Regex.Match(CurrentCustomerAccount.CustomerId, @"\d+$"); string merchantCode_part = GetNumberPartFromMerchantCode(CurrentCustomerAccount.CustomerId);
string merchantCode_part = match.Value;
// Adjust transaction date if it's past cut-off time (12:00 noon) // Adjust transaction date if it's past cut-off time (12:00 noon)
DateTime prevadjustedDate = CurrentCustomerAccount.TransactionTime.Hour >= CutOffTime.Hour ? transactionDateTime.Date : transactionDateTime.Date.AddDays(-1); DateTime prevadjustedDate = CurrentCustomerAccount.TransactionTime.Hour >= CutOffTime.Hour ? transactionDateTime.Date : transactionDateTime.Date.AddDays(-1);
@@ -142,7 +147,7 @@ namespace SafeBagDE70
AppData.CDMSTATE.IsNotesInHopper = data[3] & 0x01; AppData.CDMSTATE.IsNotesInHopper = data[3] & 0x01;
AppData.CDMSTATE.IsStackerFull = (data[2] == 0x43?1:0); AppData.CDMSTATE.IsStackerFull = (data[2] == 0x43?1:0);
if (data[0] == 0x40 && data[1] == 0x07) if (data[0] == 0x40 && (data[1] == 0x07 || data[1]==0x09))
AppData.CDMSTATE.IsError = 0; AppData.CDMSTATE.IsError = 0;
else else
AppData.CDMSTATE.IsError = 1; AppData.CDMSTATE.IsError = 1;
@@ -351,8 +356,8 @@ namespace SafeBagDE70
if (RecvDat.leng > 18) if (RecvDat.leng > 18)
{ {
var dat = RecvDat.dat; var dat = RecvDat.dat;
strStatus += "S1: "+ AppData.cCmdRsp.GetD1Summary(dat[17]); strStatus += "S1: "+ AppData.cCmdRsp.GetS1Summary(dat[17]);
strStatus += "\r\nS2: " + AppData.cCmdRsp.GetD2Summary(dat[18]); strStatus += "\r\nS2: " + AppData.cCmdRsp.GetS2Summary(dat[18]);
} }
} }
return strStatus; return strStatus;
+19 -16
View File
@@ -317,15 +317,18 @@ namespace SafeBagDE70
public void InitLvCountItems() public void InitLvCountItems()
{ {
if (lvCount.Items.Count == 11) { Dispatcher.Invoke(() =>
foreach(var item in lvCountItems)
{
item.Quantity = "0";
}
}
else
{ {
lvCountItems = new ObservableCollection<LvCountItem>() if (lvCount.Items.Count == 11)
{
foreach (var item in lvCountItems)
{
item.Quantity = "0";
}
}
else
{
lvCountItems = new ObservableCollection<LvCountItem>()
{ {
new LvCountItem{Name = "500",Quantity = "0"}, new LvCountItem{Name = "500",Quantity = "0"},
new LvCountItem{Name = "1000",Quantity = "0"}, new LvCountItem{Name = "1000",Quantity = "0"},
@@ -339,11 +342,9 @@ namespace SafeBagDE70
new LvCountItem{Name = "500000",Quantity = "0"}, new LvCountItem{Name = "500000",Quantity = "0"},
new LvCountItem{Name = "Tổng",Quantity = "0",Value="0"}, new LvCountItem{Name = "Tổng",Quantity = "0",Value="0"},
}; };
} }
lvCount.ItemsSource = lvCountItems;
});
lvCount.ItemsSource = lvCountItems;
//lvCountItems[0].Quantity = "10"; //lvCountItems[0].Quantity = "10";
} }
int prevPrinterStatus = -1; int prevPrinterStatus = -1;
@@ -1293,8 +1294,10 @@ namespace SafeBagDE70
var currentTime = DateTime.Now; var currentTime = DateTime.Now;
var printDocument = new PrintDocument(); var printDocument = new PrintDocument();
System.Drawing.Image LogoAeonMall = System.Drawing.Image.FromFile("Logo\\logoAeonmall.png"); var strLogoAM= System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logo\\logoAeonmall.png");
System.Drawing.Image LogoVietin = System.Drawing.Image.FromFile("Logo\\logoVietin.png"); var strLogoVietin = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logo\\logoVietin.png");
System.Drawing.Image LogoAeonMall = System.Drawing.Image.FromFile(strLogoAM);
System.Drawing.Image LogoVietin = System.Drawing.Image.FromFile(strLogoVietin);
printDocument.PrinterSettings.PrinterName = "CUSTOM K80"; printDocument.PrinterSettings.PrinterName = "CUSTOM K80";
printDocument.PrintPage += (sender, e) => printDocument.PrintPage += (sender, e) =>
@@ -1334,7 +1337,7 @@ namespace SafeBagDE70
e.Graphics.DrawString("Tên Gian hàng: " + shopName, new Font("Arial", fontSize), System.Drawing.Brushes.Black, new PointF(50, lineSpace * 5 + 65)); e.Graphics.DrawString("Tên Gian hàng: " + shopName, new Font("Arial", fontSize), System.Drawing.Brushes.Black, new PointF(50, lineSpace * 5 + 65));
e.Graphics.DrawString("Số tài khoản gian hàng: " + storeAccountNumber, new Font("Arial", fontSize), System.Drawing.Brushes.Black, new PointF(50, lineSpace * 6 + 65)); e.Graphics.DrawString("Số tài khoản gian hàng: " + storeAccountNumber, new Font("Arial", fontSize), System.Drawing.Brushes.Black, new PointF(50, lineSpace * 6 + 65));
e.Graphics.DrawString("Nội dung giao dịch: Nop doanh so tien mat_", new Font("Arial", fontSize), System.Drawing.Brushes.Black, new PointF(50, lineSpace * 7 + 65)); e.Graphics.DrawString("Nội dung giao dịch: Nop doanh so tien mat_", new Font("Arial", fontSize), System.Drawing.Brushes.Black, new PointF(50, lineSpace * 7 + 65));
e.Graphics.DrawString(shopCode, new Font("Arial", fontSize), System.Drawing.Brushes.Black, new PointF(50, lineSpace * 8 + 65)); e.Graphics.DrawString(AppData.GetNumberPartFromMerchantCode(shopCode), new Font("Arial", fontSize), System.Drawing.Brushes.Black, new PointF(50, lineSpace * 8 + 65));
e.Graphics.DrawString("Số tiền nộp: " + lvCountItems[10].Value, new Font("Arial", fontSize), System.Drawing.Brushes.Black, new PointF(50, lineSpace * 9 + 65)); e.Graphics.DrawString("Số tiền nộp: " + lvCountItems[10].Value, new Font("Arial", fontSize), System.Drawing.Brushes.Black, new PointF(50, lineSpace * 9 + 65));
e.Graphics.DrawString("*****Xin cám ơn*****", new Font("Arial", 7), System.Drawing.Brushes.Black, new PointF(120, lineSpace * 10 + 65)); e.Graphics.DrawString("*****Xin cám ơn*****", new Font("Arial", 7), System.Drawing.Brushes.Black, new PointF(120, lineSpace * 10 + 65));
// To send raw ESC/POS commands, you'd typically use e.Graphics.DrawString() with the command string, // To send raw ESC/POS commands, you'd typically use e.Graphics.DrawString() with the command string,
+1 -1
View File
@@ -12,7 +12,7 @@ namespace SafeBagDE70.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.9.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));