109 lines
2.6 KiB
C#
109 lines
2.6 KiB
C#
using charger_gui.operations;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
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.Windows.Threading;
|
|
|
|
namespace charger_gui
|
|
{
|
|
/// <summary>
|
|
/// Логика взаимодействия для MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
private UpdateWorker worker;
|
|
private Logger log;
|
|
MainWindowViewModel model;
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
log = new Logger("charger.log");
|
|
model = new MainWindowViewModel();
|
|
DataContext = model;
|
|
worker = new UpdateWorker(model);
|
|
}
|
|
|
|
private void Ports_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
worker.SetPort(Ports.SelectedItem.ToString());
|
|
}
|
|
|
|
private void LampButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (model.CurrentOperation != null)
|
|
{
|
|
model.CurrentOperation.Cancel();
|
|
}
|
|
model.CurrentOperation = null;
|
|
model.IsLampOn = !model.IsLampOn;
|
|
}
|
|
|
|
private void FlipChargeButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (model.CurrentOperation != null)
|
|
{
|
|
model.CurrentOperation.Cancel();
|
|
}
|
|
model.CurrentOperation = null;
|
|
model.IsCharging = !model.IsCharging;
|
|
}
|
|
|
|
private void CalibrateButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (model.CurrentOperation != null)
|
|
{
|
|
model.CurrentOperation.Cancel();
|
|
}
|
|
model.CurrentOperation = new CalibrateOperation(log, model);
|
|
model.CurrentOperation.Start();
|
|
}
|
|
|
|
private void DischargeButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (model.CurrentOperation != null)
|
|
{
|
|
model.CurrentOperation.Cancel();
|
|
}
|
|
model.CurrentOperation = new DischargeOperation(log, model);
|
|
model.CurrentOperation.Start();
|
|
}
|
|
|
|
private void ChargeButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (model.CurrentOperation != null)
|
|
{
|
|
model.CurrentOperation.Cancel();
|
|
}
|
|
model.CurrentOperation = new ChargeOperation(log, model);
|
|
model.CurrentOperation.Start();
|
|
}
|
|
private void TrainButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (model.CurrentOperation != null)
|
|
{
|
|
model.CurrentOperation.Cancel();
|
|
}
|
|
model.CurrentOperation = new TrainOperation(log, model, model.TrainDuration);
|
|
model.CurrentOperation.Start();
|
|
}
|
|
|
|
protected override void OnClosed(EventArgs e)
|
|
{
|
|
base.OnClosed(e);
|
|
Environment.Exit(0);
|
|
}
|
|
}
|
|
}
|