Fix save and restore state

This commit is contained in:
Daniel Schick 2025-09-11 09:18:15 +02:00
parent fa460ec8e4
commit 012cbc4d6d
2 changed files with 49 additions and 35 deletions

View File

@ -4,23 +4,13 @@
using bsmd.database.EasyPeasy;
using ENI2.Util;
using Microsoft.Office.Interop.Excel;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
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;
using System.Xml;
using System.Xml.Serialization;
@ -39,18 +29,16 @@ namespace ENI2.Controls
InitializeComponent();
}
private void DataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
public void SaveState()
{
if (e.Key == Key.V && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
try
{
if (Clipboard.ContainsText())
{
var text = Clipboard.GetText();
PasteGoodsItems(text);
e.Handled = true;
}
EasyPeasyState.Save(_vm);
}
}
catch { }
}
#region button event handler
private void buttonClear_Click(object sender, RoutedEventArgs e)
{
@ -98,6 +86,28 @@ namespace ENI2.Controls
}
}
private void buttonImport_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "XML file|*.xml";
ofd.RestoreDirectory = true;
ofd.Multiselect = false;
if (ofd.ShowDialog() == true)
{
using (var fs = File.OpenRead(ofd.FileName))
{
var ser = new XmlSerializer(typeof(ProofRequest));
_vm = (ProofRequest)ser.Deserialize(fs);
this.DataContext = _vm;
}
}
}
#endregion
#region loaded/unloaded event handler
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
_vm = EasyPeasyState.LoadOrCreate();
@ -121,6 +131,23 @@ namespace ENI2.Controls
catch { }
}
#endregion
#region cut & paste logic
private void DataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.V && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
{
if (Clipboard.ContainsText())
{
var text = Clipboard.GetText();
PasteGoodsItems(text);
e.Handled = true;
}
}
}
private void PasteGoodsItems(string text)
{
if (_vm?.ProofInformationT2LT2LF?.GoodsShipmentForT2LT2LF == null) return;
@ -173,23 +200,8 @@ namespace ENI2.Controls
return res.ToArray();
}
private void buttonImport_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "XML file|*.xml";
ofd.RestoreDirectory = true;
ofd.Multiselect = false;
#endregion
if (ofd.ShowDialog() == true)
{
using (var fs = File.OpenRead(ofd.FileName))
{
var ser = new XmlSerializer(typeof(ProofRequest));
_vm = (ProofRequest)ser.Deserialize(fs);
this.DataContext = _vm;
}
}
}
}
}

View File

@ -386,6 +386,8 @@ namespace ENI2
Properties.Settings.Default.MainWindowPlacement = this.GetPlacement();
Properties.Settings.Default.Save();
Microsoft.Win32.SystemEvents.SessionEnded -= SystemEvents_SessionEnded;
if (easyPeasyControl != null)
easyPeasyControl.SaveState();
}
private void Window_SourceInitialized(object sender, EventArgs e)