Xóa các file ko còn dùng

This commit is contained in:
Nguyen Dinh Thuan
2024-09-21 06:49:25 +07:00
parent c30007c15f
commit cc2560cb3a
13 changed files with 0 additions and 1610 deletions
-44
View File
@@ -1,44 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SafeBagDE70
{
static public class DE70Commands
{
//public static string ReadyToCountResponse = "40 07 41 00 01 00 00 00 00 00 00 10 00";
public static string CountingResponse = "40 09 41 01 01 00 00 00 00 00 00 10 00";
public static string ExceptionResponse = "40 07 41 10 10 01 00 00 00 00 00 00 10 10 00 00";
public static string DESenseResponse1 = "40 04 41 00 00 00 00 00 00 00 00 10 00 00 00 00 01 70 00";
public static string DESenseResponse2 = "40 04 41 00 00 00 00 00 00 00 00 10 00 00 01 00 02 70 00 ";
public static string DESenseResponse3 = "40 04 41 00 00 00 00 00 00 00 00 10 00 00 02 00 03 70 00 ";
public static string DESenseResponse4 = "40 04 41 00 00 00 00 00 00 00 00 10 00 00 03 00 04 70 00 ";
public static string DESenseResponse5 = "40 04 41 00 00 00 00 00 00 00 00 10 00 00 04 00 05 70 00 ";
public static string DESenseResponse0 = "40 04 41 00 00 00 00 00 00 00 00 10 00 00 05 00 00 70 00 ";
public static string[] DESenseSatisfyResponse = { "40 04 41 00 00 00 00 00 00 00 00 10 00 00 05 00 05 70 00",
"40 04 41 00 00 00 00 00 00 00 00 10 00 00 04 00 04 70 00",
"40 04 41 00 00 00 00 00 00 00 00 10 00 00 03 00 03 70 00",
"40 04 41 00 00 00 00 00 00 00 00 10 00 00 02 00 02 70 00",
"40 04 41 00 00 00 00 00 00 00 00 10 00 00 01 00 01 70 00",
"40 04 41 00 00 00 00 00 00 00 00 10 00 00 00 00 00 70 00" };
//public static byte[] CountStartCmd= new byte[] { 0x10, 0x02, 0x30, 0x30, 0x31, 0x73, 0x10, 0x03, 0x41 };
//public static byte[] DESenseCmd = new byte[] { 0x10, 0x02, 0x30, 0x30, 0x31, 0x60, 0x10, 0x03, 0x52 };
//public static byte[] UnlockCmd = new byte[] { 0x10, 0x02, 0x30, 0x30, 0x31, 0x71, 0x10, 0x03, 0x43 };
//public static byte[] CancelCmd = new byte[] { 0x10, 0x02, 0x30, 0x30, 0x31, 0x76, 0x10, 0x03, 0x44 };
//public static byte[] StoreStartCmd = new byte[] { 0x10, 0x02, 0x30, 0x30, 0x31, 0x75, 0x10, 0x03, 0x47 };
public static byte[] LockCmd = new byte[] { 0x10, 0x02, 0x30, 0x31, 0x33, 0x70, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, 0x00, 0x10, 0x03, 0x48 };
//Event data fix
public static byte[] EventDataFixed_01_Cmd = new byte[] { 0x10, 0x02, 0x30, 0x30, 0x33, 0x65, 0x00, 0x01, 0x10, 0x03, 0x54 };
public static byte[] EventDataFixed_02_Cmd = new byte[] { 0x10, 0x02, 0x30, 0x30, 0x33, 0x65, 0x00, 0x02, 0x10, 0x03, 0x57 };
public static byte[] EventDataFixed_03_Cmd = new byte[] { 0x10, 0x02, 0x30, 0x30, 0x33, 0x65, 0x00, 0x03, 0x10, 0x03, 0x56 };
public static byte[] EventDataFixed_04_Cmd = new byte[] { 0x10, 0x02, 0x30, 0x30, 0x33, 0x65, 0x00, 0x04, 0x10, 0x03, 0x51 };
public static byte[] EventDataFixed_05_Cmd = new byte[] { 0x10, 0x02, 0x30, 0x30, 0x33, 0x65, 0x00, 0x05, 0x10, 0x03, 0x50 };
public static byte[] EventDataFixed_00_Cmd = new byte[] { 0x10, 0x02, 0x30, 0x30, 0x33, 0x65, 0x00, 0x00, 0x10, 0x03, 0x55 };
}
}
-6
View File
@@ -108,12 +108,6 @@
<Compile Update="MaintainanceUC.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="old\PinCodeWindow.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="old\QRCodeZebraWindow.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="WelcomeUC.xaml.cs">
<SubType>Code</SubType>
</Compile>
-69
View File
@@ -1,69 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace SafeBagDE70.old
{
public class KeyModel
{
public enum MapType : uint
{
MAPVK_VK_TO_VSC = 0x0,
MAPVK_VSC_TO_VK = 0x1,
MAPVK_VK_TO_CHAR = 0x2,
MAPVK_VSC_TO_VK_EX = 0x3,
}
[DllImport("user32.dll")]
public static extern int ToUnicode(
uint wVirtKey,
uint wScanCode,
byte[] lpKeyState,
[Out, MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 4)]
StringBuilder pwszBuff,
int cchBuff,
uint wFlags);
[DllImport("user32.dll")]
public static extern bool GetKeyboardState(byte[] lpKeyState);
[DllImport("user32.dll")]
public static extern uint MapVirtualKey(uint uCode, MapType uMapType);
public static char GetCharFromKey(Key key)
{
char ch = ' ';
int virtualKey = KeyInterop.VirtualKeyFromKey(key);
byte[] keyboardState = new byte[256];
GetKeyboardState(keyboardState);
uint scanCode = MapVirtualKey((uint)virtualKey, MapType.MAPVK_VK_TO_VSC);
StringBuilder stringBuilder = new StringBuilder(2);
int result = ToUnicode((uint)virtualKey, scanCode, keyboardState, stringBuilder, stringBuilder.Capacity, 0);
switch (result)
{
case -1:
break;
case 0:
break;
case 1:
{
ch = stringBuilder[0];
break;
}
default:
{
ch = stringBuilder[0];
break;
}
}
return ch;
}
}
}
-121
View File
@@ -1,121 +0,0 @@
<hc:Window x:Class="SafeBagDE70.MainUserWindow"
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:SafeBagDE70"
xmlns:hc="https://handyorg.github.io/handycontrol"
WindowState="Maximized"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d"
ShowNonClientArea="False"
Background="#9edaf7"
Title="MainWindow" Height="600" Width="810">
<Border BorderThickness="1" BorderBrush="Gray" Margin="10">
<Grid x:Name="gridMainPanel">
<!--<ContentControl x:Name="MainContent" />-->
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Border BorderThickness="0" BorderBrush="Gray">
<StackPanel Grid.Row="0" hc:BorderElement.Circular="True">
<Label Content="Vietinbank"
Background="Transparent"
Foreground="#1d619b"
BorderThickness="0"
FontWeight="Bold"
FontSize="30"
Height="50"/>
<Label HorizontalAlignment="Center"
x:Name="lblUser"
Background="Transparent"
Foreground="White"
BorderThickness="0"
FontSize="20"
FontWeight="Bold"
Height="50"/>
<Border BorderThickness="1" BorderBrush="Gray">
<Separator BorderThickness="2" BorderBrush="Gray"/>
</Border>
</StackPanel>
</Border>
<Grid Grid.Row="1" x:Name="gridMain" VerticalAlignment="Center" Margin="5" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="100"/>
<RowDefinition Height="100"/>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<Button Grid.Row="0" HorizontalAlignment="Stretch" Content="BẮT ĐẦU" x:Name="btnStart" Click="btnStart_Click" FontSize="30" Height="80" />
<Button Grid.Row="1" HorizontalAlignment="Stretch" Content="KẾT THÚC" x:Name="btnEnd" Click="btnEnd_Click" FontSize="30" Height="80"/>
<Button Grid.Row="2" HorizontalAlignment="Stretch" Content="KT LẤY TÚI" x:Name="btnCollect" Click="btnCollect_Click" FontSize="30" Height="80"/>
</Grid>
<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="100"/>
<RowDefinition Height="100"/>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<Button Grid.Row="0" HorizontalAlignment="Stretch" Content="NỘP TIỀN" x:Name="btnCountStart" Click="btnCountStart_Click" FontSize="30" Height="80"/>
<Button Grid.Row="1" HorizontalAlignment="Stretch" Content="KIỂM TRA" x:Name="btnCheck" Click="btnCheck_Click" FontSize="30" Height="80"/>
<Button Grid.Row="2" HorizontalAlignment="Stretch" Content="LƯU TRỮ" x:Name="btnStoreStart" Click="btnStoreStart_Click" FontSize="30" Height="80" />
</Grid>
<Grid Grid.Column="1">
<ListView HorizontalAlignment="Center" FontSize="30" Width="600" x:Name="lvCount" Style="{StaticResource ListViewBaseStyle}">
<ListView.View>
<GridView>
<GridViewColumn Header="Mệnh giá"
DisplayMemberBinding="{Binding Name}"
Width="200"/>
<GridViewColumn Header="Số lượng"
DisplayMemberBinding="{Binding Quantity}"
Width="200"/>
<GridViewColumn Header="Thành tiền"
DisplayMemberBinding="{Binding Value}"
Width="200"/>
</GridView>
</ListView.View>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Padding" Value="0"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="BorderBrush" Value="Gray"/>
<Setter Property="BorderThickness" Value="0,0,0,1"/>
</Style>
</ListView.ItemContainerStyle>
</ListView>
</Grid>
</Grid>
<Border Grid.Row="1" x:Name="panelError" Visibility="Collapsed" VerticalAlignment="Center" HorizontalAlignment="Center">
<StackPanel>
<hc:HighlightTextBlock x:Name="lblError" Text="Error" Foreground="Red" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<Button HorizontalAlignment="Stretch" Content="KT LẤY TÚI" x:Name="btnCollect2" Click="btnCollect_Click" Visibility="Collapsed" FontSize="30" Height="80"/>
</StackPanel>
</Border>
<StackPanel Grid.Row="2">
<Separator BorderThickness="2" BorderBrush="Gray"/>
<Label Height="40" x:Name="lblStatus" Background="Transparent" BorderThickness="0" Foreground="Red" FontSize="20" Content="Trạng thái"/>
</StackPanel>
</Grid>
</Border>
</hc:Window>
-804
View File
@@ -1,804 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Channels;
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;
using System.Xml.Serialization;
using System.Windows.Threading;
using System.Diagnostics;
using System.Collections.ObjectModel;
using SafeBagDE70.Model;
using HandyControl.Tools;
using System.Drawing.Printing;
using System.Drawing;
using static HandyControl.Tools.Interop.InteropValues;
using SafeBagDE70.API;
using Newtonsoft.Json;
using System.IO;
using System.Reflection;
using DE70_CMDv2;
using System.Configuration;
namespace SafeBagDE70
{ //Summary
public partial class MainUserWindow : HandyControl.Controls.Window
{
SerialPort serialPortDE70 = new SerialPort();
SerialPort serialPortSensor= new SerialPort();
List<CountSession> sessions = new List<CountSession>();
ObservableCollection<LvCountItem> lvCountItems = new ObservableCollection<LvCountItem>();
private DispatcherTimer timer;
private DispatcherTimer sensorTimer;
int countTimer = 0;
CCmdRsp cCmdRsp = null;
bool bInitialized = false;
public MainUserWindow()
{
//Need to update: auto detect COM Port
try
{
InitializeComponent();
//string queuePath = ConfigurationManager.AppSettings["SensorPort"].ToString();
AppData.Init();
//this.gridMain.IsEnabled = false;
InitApp();
}
catch (Exception ex)
{
ShowError("LỖI CỔNG KẾT NỐI, VUI LÒNG KIỂM TRA LẠI CỔNG KẾT NỐI");
//MessageBox.Show("Cổng đang mở, kiểm tra lại cổng kết nối");
//this.Close();
}
}
public void InitApp()
{
LoginUsingQRCode();
panelError.Visibility = Visibility.Collapsed;
serialPortDE70.ReadBufferSize = 4096;
serialPortDE70.WriteBufferSize = 4096;
cCmdRsp = new CCmdRsp(serialPortDE70);
serialPortDE70.PortName = AppData.CDMPort;
serialPortDE70.BaudRate = 9600;
serialPortDE70.Parity = Parity.Even;
serialPortDE70.DataBits = 8;
serialPortDE70.StopBits = StopBits.One;
serialPortSensor.PortName = AppData.SensorPort;
serialPortSensor.BaudRate = 9600;
serialPortSensor.Parity = Parity.None;
serialPortSensor.DataBits = 8;
serialPortSensor.StopBits = StopBits.One;
//Subscrible to the DataReveied event
serialPortDE70.Open();
serialPortSensor.Open();
bInitialized = InitSession();
timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 10); //10 seconds
timer.Tick += Timer_Tick;
timer.Start();
sensorTimer = new DispatcherTimer();
sensorTimer.Interval = new TimeSpan(0, 0, 1); //10 seconds
sensorTimer.Tick += SensorTimer_Tick;
sensorTimer.Start();
}
public void ShutdownApp()
{
try
{
if (serialPortDE70.IsOpen)
serialPortDE70.Close();
if (serialPortSensor.IsOpen)
serialPortSensor.Close();
if (timer != null)
{
timer.Tick -= Timer_Tick;
timer.Stop();
}
if (sensorTimer != null)
{
sensorTimer.Tick -= SensorTimer_Tick;
sensorTimer.Stop();
}
}
catch (Exception ex)
{
}
}
public void SetStep(int step)
{
switch(step)
{
case 0:
btnStart.IsEnabled = true;
btnCheck.IsEnabled = false;
btnCountStart.IsEnabled = false;
btnStoreStart.IsEnabled = false;
btnEnd.IsEnabled = false;
break;
case 1:
btnStart.IsEnabled = false;
btnCheck.IsEnabled = false;
btnCountStart.IsEnabled = true;
btnStoreStart.IsEnabled = false;
btnEnd.IsEnabled =false;
break;
case 2:
btnStart.IsEnabled = false;
btnCheck.IsEnabled = true;
btnCountStart.IsEnabled = true;
btnStoreStart.IsEnabled = true;
btnEnd.IsEnabled = false;
break;
case 3:
btnStart.IsEnabled = false;
btnCheck.IsEnabled = true;
btnCountStart.IsEnabled = true;
btnStoreStart.IsEnabled = true;
btnEnd.IsEnabled = true;
break;
}
}
public void InitSessionCount()
{
lvCountItems.Clear();
lvCountItems.Add(new LvCountItem
{
Name = "500",
Quantity = "0"
});
lvCountItems.Add(new LvCountItem
{
Name = "1000",
Quantity = "0"
});
lvCountItems.Add(new LvCountItem
{
Name = "2000",
Quantity = "0"
});
lvCountItems.Add(new LvCountItem
{
Name = "5000",
Quantity = "0"
});
lvCountItems.Add(new LvCountItem
{
Name = "10000",
Quantity = "0"
});
lvCountItems.Add(new LvCountItem
{
Name = "20000",
Quantity = "0"
});
lvCountItems.Add(new LvCountItem
{
Name = "50000",
Quantity = "0"
});
lvCountItems.Add(new LvCountItem
{
Name = "100000",
Quantity = "0"
});
lvCountItems.Add(new LvCountItem
{
Name = "200000",
Quantity = "0"
});
lvCountItems.Add(new LvCountItem
{
Name = "500000",
Quantity = "0"
});
lvCountItems.Add(new LvCountItem
{
Name = "Tổng",
Quantity = "0"
});
lvCountItems[10].Quantity = "0";
lvCountItems[10].Value = "0";
lvCount.ItemsSource = lvCountItems;
//lvCountItems[0].Quantity = "10";
}
public long maxQuantitySheet = 10000;
public int quantityStored = 0;
public int totalAllDenominations = 0;
public int posDenomi;
public bool printerFlag = false;
public static string? recvDataString;
public int[] TempQuantity = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
public int[] TempNote = new int[5] { 0, 0, 0, 0, 0 };
public int[] Notes = new int[5] { 0, 0, 0, 0, 0 };
private void SensorTimer_Tick(object? sender, EventArgs e)
{
timer.IsEnabled = false;
int state = 0;
if (serialPortSensor.IsOpen==true)
{
serialPortSensor.Write(new byte[] { (byte)'S', 13, 10 }, 0, 3);
var buffer = new byte[16];
int n = serialPortSensor.Read(buffer, 0, buffer.Length);
for (int i = 1; i < n - 1; i++)
{
if ((buffer[i] == 13) && (buffer[i + 1] == 10))
{
state = buffer[i - 1]-48;
if(bInitialized)
{
if (state != 0)
gridMain.IsEnabled = false;
else
gridMain.IsEnabled = true;
}
switch (state)
{
case 0:
lblStatus.Content = "Két: đóng, Túi: đóng";
break;
case 1:
lblStatus.Content = "Két: đóng, Túi: đã bị lấy ra";
break;
case 2:
lblStatus.Content = "Két: mở, Túi: đóng";
break;
case 3:
lblStatus.Content = "Két: mở, Túi: đã bị lấy ra";
break;
}
break;
}
}
}
timer.IsEnabled = true;
}
private void Timer_Tick(object? sender, EventArgs e)
{
timer.IsEnabled = false;
APIModels.SendHealthCheck();
timer.IsEnabled = true;
}
public int UpdateTotalQuantity()
{
int total = 0;
foreach (var item in lvCountItems)
{
if (item.Name != "Tổng")
{
int quantity = 0;
if (int.TryParse(item.Quantity, out quantity))
{
total += quantity;
}
}
}
return total;
}
public int AutoSerialGet(SerialPort serialPort)
{
int ret;
ushort seri_num = 0;
ushort get_num = 0;
bool endflg = false;
while (true)
{
ret = cCmdRsp.SendSerialSense();
if (ret == Constants.E_OK)
{
ret = cCmdRsp.GetSerialNum(out seri_num);
if (ret == Constants.E_OK)
{
// Serial number acquisition
if (cCmdRsp.ChkCntEnd())
{
endflg = true;
Debug.WriteLine("END FLAG: "+cCmdRsp.recv_dat.dat[1]);
}
Debug.WriteLine("START");
Debug.WriteLine($"Num Serial: {seri_num}");
while (get_num < seri_num)
{
get_num++;
ret = cCmdRsp.SendGetSerial(get_num);
switch (cCmdRsp.recv_dat.dat[18])
{
case 0x00: TempNote[0] ++; Notes[0] += TempNote[0]; break;
case 0x02:
//TempNote[1] ++;
switch (cCmdRsp.recv_dat.dat[17])
{
case 0x00: TempQuantity[0]++; break;
case 0x01: TempQuantity[1]++; break;
case 0x02: TempQuantity[2]++; break;
case 0x03: TempQuantity[3]++; break;
case 0x04: TempQuantity[4]++; break;
case 0x05: TempQuantity[5]++; break;
case 0x06: TempQuantity[6]++; break;
case 0x07: TempQuantity[7]++; break;
case 0x08: TempQuantity[8]++; break;
case 0x09: TempQuantity[9]++; break;
}
break;
case 0x03: TempNote[2] ++; Notes[2] += TempNote[2]; break;
case 0x0b: TempNote[3] ++; Notes[3] += TempNote[3]; break;
case 0x0c: TempNote[4] ++; Notes[4] += TempNote[4]; break;
}
}
Debug.WriteLine("END");
//Debug.WriteLine("Ellapsed Time: " + timeSpan.TotalSeconds);
if (endflg)
{
break;
}
}
else
{
Debug.WriteLine("END GET SERIAL: "+ret);
break;
}
}
else
{
Debug.WriteLine("END SEND SERIAL: "+ret);
break;
}
}
return 0;
}
public void btnCountStart_Click(object sender, RoutedEventArgs e)
{
printerFlag = false;
string currentMethod = MethodBase.GetCurrentMethod().Name;
try
{
serialPortDE70.DiscardInBuffer();
serialPortDE70.DiscardOutBuffer();
LogAction(currentMethod, null);
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_CNTSTART);
//var recvData = DE70_CMD.SendxxCmd((byte)CMD_BYTE.CMD_DE_CNTSTART, serialPort);
//Thread.Sleep(20000);
if (cCmdRsp.recv_dat != null && cCmdRsp.recv_dat.dat[2] != 43) { }
do
{
serialPortDE70.DiscardInBuffer();
serialPortDE70.DiscardOutBuffer();
cCmdRsp.SendXXCmd((byte)Command.CMD_SENSE);
}
while (cCmdRsp.recv_dat != null && cCmdRsp.recv_dat.dat[1] == 0x09); //SR2 = 0x09 : Counting Status
//SR3 = 0x43 : Stacker full
AutoSerialGet(serialPortDE70);
if (sessions == null || sessions.Count == 0)
{
double tempSum = 0;
for (int i = 0; i < 10; i++)
{
lvCountItems[i].Quantity = TempQuantity[9 - i].ToString();
tempSum += lvCountItems[i].getValue();
}
lvCountItems[10].Quantity = UpdateTotalQuantity().ToString();
lvCountItems[10].Value = tempSum.ToString();
}
else
{
InitSessionCount();
double sum = 0;
for (int i = 0; i < 10; i++)
{
int a = 0;
for (int j = 0; j < sessions.Count; j++)
{
a += sessions[j].QuantityDenomi[9 - i];
}
a += TempQuantity[9 - i];
lvCountItems[i].Quantity = a.ToString();
sum += lvCountItems[i].getValue();
}
//Update amount of money
lvCountItems[10].Quantity = UpdateTotalQuantity().ToString();
lvCountItems[10].Value = sum.ToString();
}
SetStep(2);
}
catch (Exception ex)
{
LogException(currentMethod, ex.ToString());
}
}
private void btnCheck_Click(object sender, RoutedEventArgs e)
{
string currentMethod = MethodBase.GetCurrentMethod().Name;
try
{
serialPortDE70.DiscardInBuffer();
serialPortDE70.DiscardOutBuffer();
LogAction(currentMethod, null);
Array.Clear(TempQuantity, 0, TempQuantity.Length);
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_CANCEL);
double sumStored;
//TempNote[1] = 0;
if (sessions != null)
{
sumStored = 0;
for (int i = 0; i < 10; i++)
{
int a = 0;
for (int j = 0; j < sessions.Count; j++)
{
a += sessions[j].QuantityDenomi[9 - i];
//quantityStored += lvCountItems[i].getQuantity();
}
lvCountItems[i].Quantity = a.ToString();
sumStored += lvCountItems[i].getValue();
}
lvCountItems[10].Quantity = UpdateTotalQuantity().ToString();
lvCountItems[10].Value = sumStored.ToString();
}
else
{
InitSessionCount();
}
}
catch (Exception ex)
{
LogException(currentMethod, ex.ToString());
}
}
private void btnStoreStart_Click(object sender, RoutedEventArgs e)
{
printerFlag = true;
string currentMethod = MethodBase.GetCurrentMethod().Name;
try
{
serialPortDE70.DiscardInBuffer();
serialPortDE70.DiscardOutBuffer();
LogAction(currentMethod, null);
sessions.Add(new CountSession());
sessions[sessions.Count - 1].QuantityDenomi = (int[])TempQuantity.Clone();
quantityStored = UpdateTotalQuantity();
Debug.WriteLine(quantityStored);
Array.Clear(TempQuantity, 0, TempQuantity.Length);
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_STORESTART);
SetStep(3);
}
catch (Exception ex)
{
LogException(currentMethod, ex.ToString());
}
}
private void btnStart_Click(object sender, RoutedEventArgs e)
{
string currentMethod = MethodBase.GetCurrentMethod().Name;
InitSession();
try
{
serialPortDE70.DiscardInBuffer();
serialPortDE70.DiscardOutBuffer();
LogAction(currentMethod, null);
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_SENSE);
var recvData = cCmdRsp.recv_dat;
if (recvData.dat[14] == recvData.dat[16])
{
cCmdRsp.SendLock();
}
else
{
cCmdRsp.SendEventFix(recvData.dat[16]);
cCmdRsp.SendLock();
}
SetStep(1);
}
catch (Exception ex)
{
LogException(currentMethod, ex.ToString());
}
}
private void btnEnd_Click(object sender, RoutedEventArgs e)
{
string currentMethod = MethodBase.GetCurrentMethod().Name;
try
{
LogAction(currentMethod, null);
serialPortDE70.DiscardInBuffer();
serialPortDE70.DiscardOutBuffer();
//SendData2Server
var data2Send = new CountingData2Send
{
Sessions = sessions,
MachineId = null,
UserId = AppData.CurrentCustomerAccount.CustomerId,
MachineTime = DateTime.Now.ToString("yyyyMMddHHmmss"),
RejectNotes = Notes[0],
GenuineNotes = quantityStored,
UnfitNotes = Notes[2],
CounterfeitNotes = Notes[3],
SuspendNotes = Notes[4]
};
var str = JsonConvert.SerializeObject(data2Send);
APIModels.SendCountingData(data2Send);
//Reset all and ready to next session
if(printerFlag == true)
{
PrintReceipt();
printerFlag = false;
}
InitSession();
//Debug.WriteLine("Reject Note: " + Notes[0] );
//Debug.WriteLine("Genuine note stored: " + quantityStored);
//Debug.WriteLine("Unfit note: " + Notes[2]);
//Debug.WriteLine("Counterfeit: " + Notes[3]);
//Debug.WriteLine("Suspend: " + Notes[4]);
}
catch (Exception ex)
{
LogException(currentMethod, ex.ToString());
}
LoginUsingQRCode();
}
private void ShowError(string strError)
{
gridMain.IsEnabled = false;
btnCollect2.Visibility=Visibility.Collapsed;
panelError.Visibility = Visibility.Visible;
lblError.Text = strError;
}
private bool InitSession()
{
try
{
//Check status
cCmdRsp.SendDeSense();
var data = cCmdRsp.recv_dat.dat;
int IsCassetteFull=data[17] & 0x08;
if(IsCassetteFull != 0)
{
ShowError("TÚI ĐẦY, ĐỀ NGHỊ LẤY TÚI TRƯỚC KHI TIẾP TỤC THAO TÁC");
btnCollect2.Visibility=Visibility.Visible;
return false;
}
else
{
InitSessionCount();
sessions.Clear();
Array.Clear(TempNote, 0, TempNote.Length);
Array.Clear(Notes, 0, Notes.Length);
quantityStored = 0;
maxQuantitySheet = 0;
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_UNLOCK);
SetStep(0);
return true;
}
}
catch(Exception ex)
{
LogException("InitSession", ex.ToString());
}
return false;
}
private void PrintReceipt()
{
var shopName = AppData.CurrentCustomerAccount.Name;
var shopCode = AppData.CurrentCustomerAccount.CustomerId;
var tradingCode = "TRA04052024CDM";
var storeAccountNumber = 686868686688;
var currentTime = DateTime.Now;
var printDocument = new PrintDocument();
printDocument.PrinterSettings.PrinterName = "CUSTOM K80";
printDocument.PrintPage += (sender, e) =>
{
e.Graphics.DrawString("Biên nhận nộp tiền", new Font("Arial", 15), System.Drawing.Brushes.Black, new PointF(80, 10));
e.Graphics.DrawString("Mã máy CDM: ", new Font("Arial", 9), System.Drawing.Brushes.Black, new PointF(50, 60));
e.Graphics.DrawString("Batch no: ", new Font("Arial", 9), System.Drawing.Brushes.Black, new PointF(50, 90));
e.Graphics.DrawString("Thời gian GD: " + currentTime.ToString("dd/MM/yyyy HH:mm:ss"), new Font("Arial", 9), System.Drawing.Brushes.Black, new PointF(50, 120));
e.Graphics.DrawString("Mã GD: " + tradingCode, new Font("Arial", 9), System.Drawing.Brushes.Black, new PointF(50, 150));
e.Graphics.DrawString("Mã gian hàng: " + shopCode, new Font("Arial", 9), System.Drawing.Brushes.Black, new PointF(50, 180));
e.Graphics.DrawString("Tên gian hàng: " + shopName, new Font("Arial", 9), System.Drawing.Brushes.Black, new PointF(50, 210));
e.Graphics.DrawString("STK gian hàng: " + storeAccountNumber, new Font("Arial", 9), System.Drawing.Brushes.Black, new PointF(50, 240));
e.Graphics.DrawString("Số tiền nộp: " + lvCountItems[10].Value, new Font("Arial", 9), System.Drawing.Brushes.Black, new PointF(50, 270));
e.Graphics.DrawString("*****Xin cám ơn******", new Font("Arial", 9), System.Drawing.Brushes.Black, new PointF(100, 300));
// To send raw ESC/POS commands, you'd typically use e.Graphics.DrawString() with the command string,
// or for more complex scenarios, directly manipulate the byte stream sent to the printer.
};
printDocument.Print();
}
public void LogAction(string strAction, string? strData)
{
if (strData != null) strData = "Data: " + strData;
File.AppendAllText("log.txt", "\r\n" + DateTime.Now.ToString("yyyyMMddHHmmss: ") +
"Action: " + strAction + " " + strData);
}
public void LogException(string strAction, string? strData)
{
if (strData != null) strData = "Data: " + strData;
File.AppendAllText("logException.txt", "\r\n" + DateTime.Now.ToString("yyyyMMddHHmmss: ") +
"Action: " + strAction + " " + strData);
}
private void LoginUsingQRCode()
{
var wnd = new WelcomeWindow();
wnd.ShowDialog();
lblUser.Content = "";
//var wnd = new QRCodeZebraWindow();
//wnd.ShowDialog();
if (wnd.DialogResult == true)
{
var strQR = wnd.QRCodeContent;
var strPincode = wnd.PinCode;
if (AppData.customerAccounts!=null)
{
CustomerAccount? cca = null;
if(strQR!=null)
{
cca = AppData.customerAccounts.Where(x => x.QRCode == strQR).FirstOrDefault();
}
else if(strPincode!=null)
{
strPincode = strPincode.ToUpper();
cca = AppData.customerAccounts.Where(x => x.PINCode == strPincode).FirstOrDefault();
}
if (cca != null)
{
AppData.CurrentCustomerAccount = cca;
lblUser.Content = $"Xin chào khách hàng: {cca.Name} (Gian hàng {cca.CustomerId})";
}
else
{
MessageBox.Show("QRCode không đúng, vui lòng thử lại");
LoginUsingQRCode();
}
}
}
}
private void btnLoginByPINCode_Click(object sender, RoutedEventArgs e)
{
var wnd = new PinCodeWindow();
wnd.ShowDialog();
}
private void btnCollect_Click(object sender, RoutedEventArgs e)
{
cCmdRsp.SendDeSense();
Thread.Sleep(1000);
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_UNLOCK);
Thread.Sleep(1000);
cCmdRsp.SendDeSense();
Thread.Sleep(1000);
//Event fix
var recvData = cCmdRsp.recv_dat;
if (recvData.dat[14] == recvData.dat[16])
{
cCmdRsp.SendLock();
}
else
{
cCmdRsp.SendEventFix(recvData.dat[16]);
cCmdRsp.SendLock();
}
var currentMode = cCmdRsp.GetLockParam().mode;
cCmdRsp.GetLockParam().mode = Mode.MODE_COLLECTION;
cCmdRsp.SendLock();
Thread.Sleep(10000);
cCmdRsp.SendDeSense();
Thread.Sleep(1000);
recvData = cCmdRsp.recv_dat;
if (recvData.dat[14] != recvData.dat[16])
{
ShowError("Khởi tạo bộ đếm thành công");
ShutdownApp();
InitApp();
}
//Thread.Sleep(5000);
//cCmdRsp.GetLockParam().mode = currentMode;
//cCmdRsp.SendLock();
}
}
}
-21
View File
@@ -1,21 +0,0 @@
<hc:Window
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:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:SafeBagDE70"
x:Class="SafeBagDE70.PinCodeWindow"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d"
ShowNonClientArea="False"
Title="QRCodeWindow" Height="400" Width="600">
<Grid>
<StackPanel VerticalAlignment="Center">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Nhập PINCODE của bạn" FontSize="30"/>
<hc:TextBox HorizontalAlignment="Center" Height="50" Width="200" Margin="10"/>
<Button x:Name="btnOK" Content="OK" Width="100" Height="50" Margin="10"/>
</StackPanel>
</Grid>
</hc:Window>
-65
View File
@@ -1,65 +0,0 @@
using SafeBagDE70.old;
using System;
using System.Collections.Generic;
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.Shapes;
using System.Windows.Threading;
namespace SafeBagDE70
{
/// <summary>
/// Interaction logic for QRCodeWindow.xaml
/// </summary>
public partial class PinCodeWindow : HandyControl.Controls.Window
{
private DispatcherTimer timer;
int countTimer = 0;
public string QRCodeContent = null;
public PinCodeWindow()
{
InitializeComponent();
this.KeyDown += QRCodeWindow_KeyDown;
this.Loaded += QRCodeWindow_Loaded;
}
private void QRCodeWindow_Loaded(object sender, RoutedEventArgs e)
{
Keyboard.Focus(this);
timer = new DispatcherTimer();
// Set the timer interval to 1 second
timer.Interval = TimeSpan.FromMilliseconds(100);
// Define the event handler that's called each time the timer elapses
timer.Tick += Timer_Tick;
// Start the timer
timer.Start();
}
private void Timer_Tick(object sender, EventArgs e)
{
countTimer++;
if (QRCodeContent!=null && countTimer == 5)
{
// DialogResult = true;
// this.Close();
//finish
}
}
private void QRCodeWindow_KeyDown(object sender, KeyEventArgs e)
{
QRCodeContent += KeyModel.GetCharFromKey(e.Key);
countTimer = 0;
}
}
}
-20
View File
@@ -1,20 +0,0 @@
<hc:Window
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:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:SafeBagDE70"
x:Class="SafeBagDE70.QRCodeWindow"
WindowStartupLocation="CenterScreen"
ShowNonClientArea="False"
mc:Ignorable="d"
Title="QRCodeWindow" Height="400" Width="600">
<Grid>
<StackPanel VerticalAlignment="Center">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Đưa QR Code của bạn vào đầu đọc" FontSize="30"/>
<hc:LoadingCircle VerticalAlignment="Bottom" Width="50" Height="50" Margin="10"/>
</StackPanel>
</Grid>
</hc:Window>
-65
View File
@@ -1,65 +0,0 @@
using SafeBagDE70.old;
using System;
using System.Collections.Generic;
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.Shapes;
using System.Windows.Threading;
namespace SafeBagDE70
{
/// <summary>
/// Interaction logic for QRCodeWindow.xaml
/// </summary>
public partial class QRCodeWindow : HandyControl.Controls.Window
{
private DispatcherTimer timer;
int countTimer = 0;
public string QRCodeContent = null;
public QRCodeWindow()
{
InitializeComponent();
this.KeyDown += QRCodeWindow_KeyDown;
this.Loaded += QRCodeWindow_Loaded;
}
private void QRCodeWindow_Loaded(object sender, RoutedEventArgs e)
{
Keyboard.Focus(this);
timer = new DispatcherTimer();
// Set the timer interval to 1 second
timer.Interval = TimeSpan.FromMilliseconds(100);
// Define the event handler that's called each time the timer elapses
timer.Tick += Timer_Tick;
// Start the timer
timer.Start();
}
private void Timer_Tick(object sender, EventArgs e)
{
countTimer++;
if (QRCodeContent!=null && countTimer == 5)
{
DialogResult = true;
this.Close();
//finish
}
}
private void QRCodeWindow_KeyDown(object sender, KeyEventArgs e)
{
QRCodeContent += KeyModel.GetCharFromKey(e.Key);
countTimer = 0;
}
}
}
-20
View File
@@ -1,20 +0,0 @@
<hc:Window
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:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:SafeBagDE70"
x:Class="SafeBagDE70.QRCodeZebraWindow"
WindowStartupLocation="CenterScreen"
ShowNonClientArea="False"
mc:Ignorable="d"
Title="QRCodeWindow" Height="400" Width="600">
<Grid>
<StackPanel VerticalAlignment="Center">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Đưa QR Code của bạn vào đầu đọc" FontSize="30"/>
<hc:LoadingCircle VerticalAlignment="Bottom" Width="50" Height="50" Margin="10"/>
</StackPanel>
</Grid>
</hc:Window>
-100
View File
@@ -1,100 +0,0 @@
using CoreScanner;
using SafeBagDE70.Model;
using System;
using System.Collections.Generic;
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.Shapes;
using System.Windows.Threading;
using System.Xml;
namespace SafeBagDE70
{
/// <summary>
/// Interaction logic for QRCodeWindow.xaml
/// </summary>
public partial class QRCodeZebraWindow : HandyControl.Controls.Window
{
public string QRCodeContent = null;
public CCoreScannerClass cCoreScannerClass;
public QRCodeZebraWindow()
{
InitializeComponent();
Init();
}
public void Init()
{
try
{
// Instantiate CoreScanner Class
cCoreScannerClass = new CCoreScannerClass();
// Call Open API
short[] scannerTypes = new short[1]; // Scanner Types you are interested in
scannerTypes[0] = 1; // 1 for all scanner types
short numberOfScannerTypes = 1; // Size of the scannerTypes array
int status; // Extended API return code
cCoreScannerClass.Open(0, scannerTypes, numberOfScannerTypes, out status);
// Subscribe for barcode events in cCoreScannerClass
cCoreScannerClass.BarcodeEvent += new _ICoreScannerEvents_BarcodeEventEventHandler(OnBarcodeEvent);
// Let's subscribe for events
int opcode = 1001; // Method for Subscribe events
string outXML; // XML Output
string inXML = "<inArgs>" +
"<cmdArgs>" +
"<arg-int>1</arg-int>" + // Number of events you want to subscribe
"<arg-int>1</arg-int>" + // Comma separated event IDs
"</cmdArgs>" +
"</inArgs>";
cCoreScannerClass.ExecCommand(opcode, ref inXML, out outXML, out status);
}
catch (Exception exp)
{
Console.WriteLine("Something wrong please check... " + exp.Message);
}
}
private void OnBarcodeEvent(short eventType, ref string pscanData)
{
string xmlString = pscanData;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlString);
XmlNode rawDataNode = xmlDoc.SelectSingleNode("//datalabel");
string rawDataHex = rawDataNode.InnerText.Trim();
QRCodeContent = HexStringToString(rawDataHex);
this.Dispatcher.Invoke(() =>
{
cCoreScannerClass.BarcodeEvent -= new _ICoreScannerEvents_BarcodeEventEventHandler(OnBarcodeEvent);
DialogResult = true;
this.Close();
});
}
static string HexStringToString(string hexString)
{
string[] hexValues = hexString.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
byte[] bytes = new byte[hexValues.Length];
for (int i = 0; i < hexValues.Length; i++)
{
bytes[i] = Convert.ToByte(hexValues[i], 16);
}
return Encoding.ASCII.GetString(bytes);
}
}
}
-65
View File
@@ -1,65 +0,0 @@
<hc:Window x:Class="SafeBagDE70.WelcomeWindow"
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:SafeBagDE70"
xmlns:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d"
ShowInTaskbar="False"
ShowNonClientArea="False"
IsFullScreen="True"
Topmost="True"
WindowStartupLocation="CenterScreen"
Title="WelcomeWindow" Height="600" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="4*"/>
<RowDefinition Height="4*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Top Section -->
<StackPanel Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0">
<Image Source="icon/logo.ico" Width="200" Height="200" Margin="0,10,0,10" Stretch="UniformToFill"/>
<TextBlock Text="Xin chào! Hãy lựa chọn hình thức đăng nhập để tiếp tục" FontSize="24" FontWeight="Bold" TextAlignment="Center"/>
</StackPanel>
<!-- Middle Section -->
<Grid Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button hc:IconElement.Geometry="{StaticResource FullScreenGeometry}" Grid.Column="0" Grid.Row="0" x:Name="btnQRCodeLogin" Content="QR CODE" Width="200" Height="100" Margin="0,0,10,0" FontSize="20" FontWeight="Bold" Click="btnQRCodeLogin_Click"/>
<Button Grid.Column="2" Grid.Row="0" x:Name="btnPinCodeLogin" Content="PIN CODE" Width="200" Height="100" Margin="10,0,0,0" Click="PinCodeButton_Click" FontSize="20" FontWeight="Bold"/>
<StackPanel Grid.ColumnSpan="3" Grid.Row="1" HorizontalAlignment="Center" Visibility="Collapsed" x:Name="PinCodePanel">
<PasswordBox x:Name="PinCodeBox" Width="300" Height="60" FontSize="20" HorizontalContentAlignment="Center" Margin="0,10,0,0"/>
<TextBlock Text="Quên mã PIN?" Foreground="Blue" TextDecorations="Underline" Cursor="Hand" Margin="0,5,0,0" MouseLeftButtonUp="ForgotPin_Click"/>
<Button Content="Đăng nhập" Width="200" Height="40" Margin="0,10,0,0" Click="LoginButton_Click"/>
<Label x:Name="lblPincodeError" Background="Transparent" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Red" />
</StackPanel>
<StackPanel Grid.ColumnSpan="3" Grid.Row="1" HorizontalAlignment="Center" Visibility="Collapsed" x:Name="QrCodePanel">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Đưa QR Code của bạn vào đầu đọc" FontSize="20"/>
<hc:LoadingCircle Background="Transparent" VerticalAlignment="Bottom" Width="50" Height="50" Margin="10"/>
<Label x:Name="lblQRcodeError" Background="Transparent" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Red" />
</StackPanel>
</Grid>
<!-- Bottom Section -->
<StackPanel Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="TRỢ GIÚP" Foreground="Blue" TextDecorations="Underline" Cursor="Hand" MouseLeftButtonUp="Help_Click"/>
</StackPanel>
</Grid>
</hc:Window>
-210
View File
@@ -1,210 +0,0 @@
using CoreScanner;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Automation;
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;
using System.Xml;
namespace SafeBagDE70
{
/// <summary>
/// Interaction logic for WelcomeWindow.xaml
/// </summary>
public partial class WelcomeWindow : HandyControl.Controls.Window
{
public string? QRCodeContent = null;
public string? PinCode = null;
public bool IsAuthenticated = false;
public CCoreScannerClass? cCoreScannerClass=null;
public WelcomeWindow()
{
InitializeComponent();
InitQRCodeScanner();
}
private void LoginButton_Click(object sender, RoutedEventArgs e)
{
string pin = PinCodeBox.Password;
if (ValidatePin(pin))
{
PinCode=PinCodeBox.Password.ToString();
if (AppData.customerAccounts != null)
{
CustomerAccount? cca = null;
if (PinCode != null)
{
var strPincode = PinCode.ToUpper();
cca = AppData.customerAccounts.Where(x => x.PINCode == strPincode).FirstOrDefault();
}
if (cca != null)
{
DialogResult = true;
this.Close();
}
else
{
lblPincodeError.Content = "PINCODE không đúng, vui lòng thử lại";
}
}
}
else
{
MessageBox.Show("Invalid PIN. Please try again.");
}
}
private void ForgotPin_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Forgot PIN clicked.");
}
private void Help_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Help clicked.");
}
private bool ValidatePin(string pin)
{
return true;
}
private async void PinCodeButton_Click(object sender, RoutedEventArgs e)
{
var onScreenKeyboardProcess = new ProcessStartInfo("osk.exe")
{
UseShellExecute = true
};
Process.Start(onScreenKeyboardProcess);
try
{
//var progFiles = @"C:\Program Files\Common Files\Microsoft Shared\ink";
//var keyboardPath = System.IO.Path.Combine(progFiles, "TabTip.exe");
//Process.Start(keyboardPath);
// AutomationElement.FromHandle(-1);
// string keyboardPath = @"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe";
// Process.Start(keyboardPath);
//await Launcher.LaunchUriAsync(new Uri("ms-inputapp://"));
//var onScreenKeyboardProcess = new ProcessStartInfo(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe")
//{
// UseShellExecute = true
//};
//Process.Start(onScreenKeyboardProcess);
QrCodePanel.Visibility = Visibility.Collapsed;
PinCodePanel.Visibility = Visibility.Visible;
cCoreScannerClass.BarcodeEvent -= new _ICoreScannerEvents_BarcodeEventEventHandler(OnBarcodeEvent);
}
catch {
}
}
private void btnQRCodeLogin_Click(object sender, RoutedEventArgs e)
{
PinCodePanel.Visibility = Visibility.Collapsed;
QrCodePanel.Visibility=Visibility.Visible;
cCoreScannerClass.BarcodeEvent += new _ICoreScannerEvents_BarcodeEventEventHandler(OnBarcodeEvent);
}
public void InitQRCodeScanner()
{
try
{
// Instantiate CoreScanner Class
cCoreScannerClass = new CCoreScannerClass();
// Call Open API
short[] scannerTypes = new short[1]; // Scanner Types you are interested in
scannerTypes[0] = 1; // 1 for all scanner types
short numberOfScannerTypes = 1; // Size of the scannerTypes array
int status; // Extended API return code
cCoreScannerClass.Open(0, scannerTypes, numberOfScannerTypes, out status);
// Subscribe for barcode events in cCoreScannerClass
// Let's subscribe for events
int opcode = 1001; // Method for Subscribe events
string outXML; // XML Output
string inXML = "<inArgs>" +
"<cmdArgs>" +
"<arg-int>1</arg-int>" + // Number of events you want to subscribe
"<arg-int>1</arg-int>" + // Comma separated event IDs
"</cmdArgs>" +
"</inArgs>";
cCoreScannerClass.ExecCommand(opcode, ref inXML, out outXML, out status);
}
catch (Exception exp)
{
Console.WriteLine("Something wrong please check... " + exp.Message);
}
}
private void OnBarcodeEvent(short eventType, ref string pscanData)
{
string xmlString = pscanData;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlString);
XmlNode rawDataNode = xmlDoc.SelectSingleNode("//datalabel");
string rawDataHex = rawDataNode.InnerText.Trim();
QRCodeContent = HexStringToString(rawDataHex);
this.Dispatcher.Invoke(() =>
{
if (AppData.customerAccounts != null)
{
CustomerAccount? cca = null;
if (QRCodeContent != null)
{
cca = AppData.customerAccounts.Where(x => x.QRCode == QRCodeContent).FirstOrDefault();
}
if (cca != null)
{
cCoreScannerClass.BarcodeEvent -= new _ICoreScannerEvents_BarcodeEventEventHandler(OnBarcodeEvent);
DialogResult = true;
this.Close();
}
else
{
lblQRcodeError.Content = "QRCODE không đúng, vui lòng thử lại";
}
}
});
}
static string HexStringToString(string hexString)
{
string[] hexValues = hexString.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
byte[] bytes = new byte[hexValues.Length];
for (int i = 0; i < hexValues.Length; i++)
{
bytes[i] = Convert.ToByte(hexValues[i], 16);
}
return Encoding.ASCII.GetString(bytes);
}
}
}