Add project files.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
using VirtualKeyboard.Wpf.Types;
|
||||
using VirtualKeyboard.Wpf.Views;
|
||||
|
||||
namespace VirtualKeyboard.Wpf.Converters
|
||||
{
|
||||
class KeyboardTypeConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var type = (KeyboardType)value;
|
||||
switch (type)
|
||||
{
|
||||
case KeyboardType.Alphabet: return new AlphabetView();
|
||||
case KeyboardType.Special: return new SpecialCharactersView();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
using Custom.CuCustomWndAPI;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
using SafeBagDE70.Admin;
|
||||
using SafeBagDE70.Model;
|
||||
using SafeBagDE70.StateMachine;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Forms;
|
||||
using VirtualKeyboard.Wpf;
|
||||
|
||||
namespace SafeBagDE70
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : System.Windows.Application
|
||||
{
|
||||
public static StateMachineConfig StateMachineConfig { get; private set; }
|
||||
private static Mutex mutex;
|
||||
public App()
|
||||
{
|
||||
}
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
|
||||
CheckInstance();
|
||||
LoadConfig();
|
||||
LoadDualScreens();
|
||||
}
|
||||
private static void CheckInstance()
|
||||
{
|
||||
bool isNewInstance;
|
||||
string mutexName = "9f5b55c9-c6eb-443a-8e28-027defa46fb5";
|
||||
|
||||
mutex = new Mutex(true, mutexName, out isNewInstance);
|
||||
|
||||
if (!isNewInstance)
|
||||
{
|
||||
// If an instance is already running, exit the application
|
||||
System.Windows.MessageBox.Show("Ứng dụng đã khởi chạy");
|
||||
System.Windows.Application.Current.Shutdown();
|
||||
return;
|
||||
}
|
||||
}
|
||||
private static void LoadConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
AppData.CurrentVersion = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
VKeyboard.Listen<System.Windows.Controls.TextBox>(e => e.Text);
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build();
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(configuration)
|
||||
.WriteTo.Sink(new RealTimeLogSink(AppData.logCollection))
|
||||
.CreateLogger();
|
||||
AppData.CDMPort = configuration["SerialPort:CDMPort"];
|
||||
AppData.SensorPort = configuration["SerialPort:SensorPort"];
|
||||
StateMachineConfig = new StateMachineConfig();
|
||||
configuration.GetSection("StateMachine").Bind(StateMachineConfig);
|
||||
Log.Information("START APP");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Windows.MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
private void LoadDualScreens()
|
||||
{
|
||||
// Create instances of the windows you want to open
|
||||
var mainWindow = new MainWindow();
|
||||
|
||||
// Show both windows
|
||||
mainWindow.Show();
|
||||
|
||||
// Get all available screens
|
||||
var screens = Screen.AllScreens;
|
||||
|
||||
// Open the Main Window on the primary screen
|
||||
var primaryScreen = screens.FirstOrDefault(s => s.Primary) ?? screens.First();
|
||||
PositionWindowOnScreen(mainWindow, primaryScreen);
|
||||
mainWindow.Show();
|
||||
|
||||
// Open the Secondary Window on the secondary screen, if available
|
||||
if (screens.Length > 1)
|
||||
{
|
||||
var adminWindow = new AdminWindow(); // Replace this with your actual window class
|
||||
adminWindow.Show();
|
||||
var secondaryScreen = screens.First(s => !s.Primary);
|
||||
PositionWindowOnScreen(adminWindow, secondaryScreen);
|
||||
adminWindow.Show();
|
||||
}
|
||||
}
|
||||
|
||||
private void PositionWindowOnScreen(Window window, Screen screen)
|
||||
{
|
||||
// Convert screen bounds to WPF units (96 DPI)
|
||||
var screenLeft = screen.WorkingArea.Left / (double)Screen.PrimaryScreen.WorkingArea.Width * SystemParameters.PrimaryScreenWidth;
|
||||
var screenTop = screen.WorkingArea.Top / (double)Screen.PrimaryScreen.WorkingArea.Height * SystemParameters.PrimaryScreenHeight;
|
||||
|
||||
// Set window position and state
|
||||
window.WindowStartupLocation = WindowStartupLocation.Manual;
|
||||
window.Left = screenLeft;
|
||||
window.Top = screenTop;
|
||||
window.Width = screen.WorkingArea.Width;
|
||||
window.Height = screen.WorkingArea.Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
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;
|
||||
|
||||
namespace SafeBagDE70
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
///
|
||||
|
||||
//public class CountSession
|
||||
//{
|
||||
// public int[] QuantityDenomi { get; set; }
|
||||
// public int[] SumDenomi { get; set; }
|
||||
|
||||
//}
|
||||
public partial class MainWindow : HandyControl.Controls.Window
|
||||
{
|
||||
private WelcomeUC _welcomeUC;
|
||||
private DepositUC _depositUC;
|
||||
private CollectionUC _collectionUC;
|
||||
private InformationUC _informationUC;
|
||||
private ErrorUC _errorUC;
|
||||
private UserControl _currentUC;
|
||||
private UserControl _prevUC;
|
||||
private TimeoutUC _timeoutUC;
|
||||
private object objLock = new object();
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += MainWindow_Loaded;
|
||||
|
||||
}
|
||||
|
||||
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
AppData.Init();
|
||||
if (_welcomeUC == null) _welcomeUC = new WelcomeUC();
|
||||
if (_collectionUC == null) _collectionUC = new CollectionUC();
|
||||
if (_informationUC == null) _informationUC = new InformationUC();
|
||||
if (_errorUC == null) _errorUC = new ErrorUC();
|
||||
if (_depositUC == null) _depositUC = new DepositUC();
|
||||
if (_timeoutUC == null) _timeoutUC = new TimeoutUC();
|
||||
|
||||
gridMain.Children.Add(_welcomeUC);
|
||||
gridMain.Children.Add(_depositUC);
|
||||
gridMain.Children.Add(_collectionUC);
|
||||
gridMain.Children.Add(_informationUC);
|
||||
gridMain.Children.Add(_errorUC);
|
||||
gridMain.Children.Add(_timeoutUC);
|
||||
|
||||
ShowWelcomeScreen();
|
||||
}
|
||||
|
||||
public void HideAll()
|
||||
{
|
||||
lock(objLock)
|
||||
{
|
||||
foreach (var item in gridMain.Children)
|
||||
{
|
||||
if (item != null)
|
||||
(item as UserControl).Visibility = Visibility.Hidden;
|
||||
}
|
||||
_collectionUC.Visibility = Visibility.Hidden;
|
||||
_informationUC.Visibility = Visibility.Hidden;
|
||||
_errorUC.Visibility = Visibility.Hidden;
|
||||
_depositUC.Visibility = Visibility.Hidden;
|
||||
_welcomeUC.Visibility = Visibility.Hidden;
|
||||
}
|
||||
|
||||
}
|
||||
public void ShowInformationScreen(string strInfor)
|
||||
{
|
||||
_prevUC = _currentUC;
|
||||
_currentUC = _informationUC;
|
||||
HideAll();
|
||||
_informationUC.Visibility = Visibility.Visible;
|
||||
_informationUC.ShowInfor(strInfor);
|
||||
|
||||
}
|
||||
public void ShowErrorScreen(string strError)
|
||||
{
|
||||
_prevUC = _currentUC;
|
||||
_currentUC = _errorUC;
|
||||
HideAll();
|
||||
_errorUC.Visibility = Visibility.Visible;
|
||||
_errorUC.ShowInfor(strError);
|
||||
}
|
||||
public void ShowWelcomeScreen()
|
||||
{
|
||||
_prevUC = _currentUC;
|
||||
_currentUC = _welcomeUC;
|
||||
HideAll();
|
||||
_welcomeUC.Visibility = Visibility.Visible;
|
||||
}
|
||||
public void ShowDepositScreen()
|
||||
{
|
||||
_prevUC = _currentUC;
|
||||
_currentUC = _depositUC;
|
||||
HideAll();
|
||||
_depositUC.Visibility = Visibility.Visible;
|
||||
//_depositUC.EndTransaction();
|
||||
_depositUC.InitTransaction();
|
||||
}
|
||||
public void ShowCollectionScreen()
|
||||
{
|
||||
_prevUC = _currentUC;
|
||||
_currentUC = _collectionUC;
|
||||
HideAll();
|
||||
_collectionUC.Visibility = Visibility.Visible;
|
||||
}
|
||||
public void ShowTimeoutScreen()
|
||||
{
|
||||
_prevUC = _currentUC;
|
||||
|
||||
HideAll();
|
||||
_timeoutUC.Visibility = Visibility.Visible;
|
||||
}
|
||||
public void BackScreen()
|
||||
{
|
||||
HideAll();
|
||||
_prevUC.Visibility = Visibility.Visible;
|
||||
_currentUC = _prevUC;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user