diff --git a/ZKuP/AddCardUser.xaml b/ZKuP/AddCardUser.xaml index 1c65db6..5f9490c 100644 --- a/ZKuP/AddCardUser.xaml +++ b/ZKuP/AddCardUser.xaml @@ -1,27 +1,35 @@ - + Title="Kartenbenutzer" MinHeight="450" Height="450" Width="594" Loaded="Window_Loaded" LocationChanged="Window_LocationChanged"> - + + + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - + + + + + @@ -84,7 +93,7 @@ - + + + + + @@ -375,9 +412,17 @@ - - - - - + + + + + - - - - + - - - + @@ -405,7 +399,7 @@ - + @@ -415,216 +409,229 @@ - - - - - - - + + + diff --git a/ZKuP/MainWindow.xaml.cs b/ZKuP/MainWindow.xaml.cs index 57233e3..9b9dd7b 100644 --- a/ZKuP/MainWindow.xaml.cs +++ b/ZKuP/MainWindow.xaml.cs @@ -1,39 +1,33 @@ -using Renci.SshNet.Messages; +using ColorHelper; +using ControlzEx.Standard; +using FuzzySharp; +using MahApps.Metro.Controls; +using Microsoft.Toolkit.Uwp.Notifications; +using MySql.Data.MySqlClient; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; using System.DirectoryServices.AccountManagement; using System.IO; using System.Linq; using System.Runtime.CompilerServices; -using System.Security.Permissions; using System.Security.Principal; using System.Text; +using System.Text.RegularExpressions; using System.Threading; 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.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; -using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Threading; -using MahApps.Metro.Controls; -using Microsoft.Toolkit.Uwp.Notifications; -using System.Diagnostics; -using MySql.Data.MySqlClient; -using System.Xml.Linq; -using FuzzySharp; +using Windows.UI.Composition; using Process = System.Diagnostics.Process; -using System.Collections; -using System.Diagnostics.Eventing.Reader; -using ColorHelper; -using System.Text.RegularExpressions; -using Windows.Devices.PointOfService; namespace ZKuP { @@ -49,12 +43,15 @@ namespace ZKuP PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } - + public const string Version = "5.0.5.8"; public static Roles LoggedInRole { get; private set; } = Roles.None; -#if !DEBUG + + +//#warning No Release, Tabellen vertauscht +#if DEBUG + public static string table { get; } = "zkupTestEnv";// +#elif !DEBUG public static string table { get; } = "zkup"; -#elif DEBUG - public static string table { get; } = "zkupTestEnv"; #endif public string NoToolTip { get; } = "Doppelklick um Ankunft zu Bestätigen"; @@ -72,6 +69,14 @@ namespace ZKuP set { parkEmailUsers = value; OnPropertyChanged(); } } + private DataTable fzgAnmeldungEmailUsers = new DataTable("FzgAnmeldungEmailUsers"); + public DataTable FzgAnmeldungEmailUsers + { + get { return fzgAnmeldungEmailUsers; } + set { fzgAnmeldungEmailUsers = value; OnPropertyChanged(); } + } + + DataTable overv = new DataTable("Overview"); DataTable todayFirm = new DataTable("TodayFirm"); @@ -83,25 +88,35 @@ namespace ZKuP DispatcherTimer reloadTimerHinweis = new DispatcherTimer(); DispatcherTimer checkUpdateTimer = new DispatcherTimer(); DispatcherTimer connTimer = new DispatcherTimer(); + DispatcherTimer ausfahrtTimer = new DispatcherTimer(); RoutedCommand resetWindow; RoutedCommand skullWindow; int maxBikes = 24; - + bool ReadyToSavePosition = false; public MainWindow() { InitializeComponent(); + Startup(); + } + + private async void Startup() + { AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); - //this.WindowState = WindowState.Normal; + await CheckConnection(true); - cbShowParkcardToAccept.IsChecked = Properties.Settings.Default.ShowParkcardAccept; + cbShowParkcardToAccept.IsChecked = Settings.GetSettingBool("ShowParkcardAccept"); - if ((Properties.Settings.Default.Width + Properties.Settings.Default.Left) >= System.Windows.SystemParameters.PrimaryScreenWidth) CenterWindowOnScreen(this); - if ((Properties.Settings.Default.Height + Properties.Settings.Default.Top) >= System.Windows.SystemParameters.PrimaryScreenHeight) CenterWindowOnScreen(this); + lblVersion.Text = "Version " + Version; + + + + //if ((Settings.GetSettingDouble("Width") + Settings.GetSettingDouble("Left")) >= System.Windows.SystemParameters.PrimaryScreenWidth) CenterWindowOnScreen(this); + //if ((Settings.GetSettingDouble("Height") + Settings.GetSettingDouble("Top")) >= System.Windows.SystemParameters.PrimaryScreenHeight) CenterWindowOnScreen(this); if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\ZKuPUpdater.exe") || File.GetLastWriteTime(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\ZKuPUpdater.exe") != File.GetLastWriteTime(@"\\mhb00swfs003v.fv-werke.db.de\GLW99\ZKuP\ZKuPUpdater.exe")) { @@ -115,7 +130,9 @@ namespace ZKuP CheckWorkingDir(); CheckVersion(); - CheckConnection(); + CheckMaintenance(); + CheckNotification(); + resetWindow = new RoutedCommand(); resetWindow.InputGestures.Add(new KeyGesture(Key.R, ModifierKeys.Control)); @@ -144,7 +161,7 @@ namespace ZKuP try { var newVersion = new Version(File.ReadAllText(@"\\mhb00swfs003v.fv-werke.db.de\GLW99\ZKuP\Version.txt")); - var oldVersion = new Version(lblVersion.Text.Split(' ')[1]); + var oldVersion = new Version(Version); var result = newVersion.CompareTo(oldVersion); if (result >= 1) @@ -192,7 +209,7 @@ namespace ZKuP private void CheckForNewVersion() { var newVersion = new Version(File.ReadAllText(@"\\mhb00swfs003v.fv-werke.db.de\GLW99\ZKuP\Version.txt")); - var oldVersion = new Version(lblVersion.Text.Split(' ')[1]); + var oldVersion = new Version(Version); var result = newVersion.CompareTo(oldVersion); if (result >= 1) @@ -220,26 +237,117 @@ namespace ZKuP return; } } - else updateAlreadyAsked = true; + else updateAlreadyAsked = true; + } } - } + + + private void CheckNotification() + { + if (LoggedInRole != Roles.None) + { + var path = @"\\mhb00swfs003v.fv-werke.db.de\GLW99\ZKuP\Notification.txt"; + + var text = File.ReadAllText(path).Split('|')[0]; + + bool repeat = false; + if (text.EndsWith("|true")) repeat = true; + + if (text.Length > 0) + { + if (!Settings.GetSettingBool("HinweisShown")) MessageBox.Show(text, "Hinweis", MessageBoxButton.OK, MessageBoxImage.Stop); + if (!repeat) Settings.WriteSetting("HinweisShown", true); + } + else Settings.WriteSetting("HinweisShown", false); + } + } + + private void CheckMaintenance() + { + var path = @"\\mhb00swfs003v.fv-werke.db.de\GLW99\ZKuP\Maintenance.txt"; + + var text = File.ReadAllText(path); + if (text.Length > 0) + { + MessageBox.Show(text + "\n\nDie Anwendung wird jetzt wieder geschlossen!", "Wartungsarbeiten", MessageBoxButton.OK, MessageBoxImage.Stop); + Application.Current.Shutdown(); + } + } + private async void Window_Loaded(object sender, RoutedEventArgs e) { await Task.Run(() => AuthenticateUser()); +//#if !DEBUG + Helper.CheckIfMultipleInstances(); +//#endif + double maxheight = this.ActualHeight - 120 - 191; double actualheight = this.ActualHeight - 120 - gridBackground.RowDefinitions[1].Height.Value; if (actualheight <= 191) gridBackground.RowDefinitions[1].Height = new GridLength(maxheight); //gridSpinner.Visibility = Visibility.Collapsed; + Helper.width = this.MinWidth; + Helper.height = this.MinHeight; + connTimer.Interval = TimeSpan.FromSeconds(2); connTimer.Tick += ConnTimer_Tick; connTimer.Start(); + + Helper.CheckScale(this); + Helper.CheckWindowIsInScreenSpace(this); + } + #region Check if Window was moved and released + private const int WM_ENTERSIZEMOVE = 0x0231; + private const int WM_EXITSIZEMOVE = 0x0232; + + private Point _startPosition; + private Size _startSize; + + + protected override void OnSourceInitialized(EventArgs e) + { + base.OnSourceInitialized(e); + HwndSource source = (HwndSource)PresentationSource.FromVisual(this); + source.AddHook(WndProc); + } + + private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) + { + switch (msg) + { + case WM_ENTERSIZEMOVE: + _startPosition = new Point(Left, Top); + _startSize = new Size(Width, Height); + break; + + case WM_EXITSIZEMOVE: + bool sizeChanged = Width != _startSize.Width || Height != _startSize.Height; + bool positionChanged = Left != _startPosition.X || Top != _startPosition.Y; + + if (positionChanged && !sizeChanged) + { + OnWindowMoveFinished(); + } + break; + } + + return IntPtr.Zero; + } + + private void OnWindowMoveFinished() + { + Helper.CheckScale(this); + } + #endregion + + + private async void AuthenticateUser() { if (!SQL.CheckDeviceConnection()) @@ -270,7 +378,7 @@ namespace ZKuP await Dispatcher.BeginInvoke(new Action(() => pgLoad.Value = 15)); auth = await SQL.ReadSingleValueAsync($"SELECT EXISTS(SELECT * FROM {MainWindow.table}.users WHERE `Username` = '{Environment.UserName}')"); - await Dispatcher.BeginInvoke(new Action(() => SQL.WriteSQL($"REPLACE INTO {MainWindow.table}.apptracker (Username, Version, LastLogin) VALUES ('{Environment.UserName}', '{lblVersion.Text.Split(' ')[1]}', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')"))); + await Dispatcher.BeginInvoke(new Action(() => SQL.WriteSQL($"REPLACE INTO {MainWindow.table}.apptracker (Username, Version, LastLogin) VALUES ('{Environment.UserName}', '{Version}', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')"))); await Dispatcher.BeginInvoke(new Action(() => pgLoad.Value = 20)); @@ -284,7 +392,7 @@ namespace ZKuP //CheckVersion(); await Dispatcher.BeginInvoke(new Action(() => { - var res = MessageBox.Show($"Ihr User {Environment.UserName} ist nicht zum Zugriff berechtigt\n\nMöchten Sie einen Besucher erstellen, eine Parkkarte beantragen oder eine Werksführung buchen?", "Zugriff verweigert", MessageBoxButton.YesNo, MessageBoxImage.Warning); + var res = MessageBox.Show($"Ihr User {Helper.InsertSpaceBeforeUpperCase(Environment.UserName)} ist nicht zum Zugriff berechtigt\n\nMöchten Sie einen Parkausweis beantragen, einen McFit User erstellen oder eine Werksführung buchen?", "Zugriff verweigert", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (res == MessageBoxResult.Yes) { @@ -325,34 +433,22 @@ namespace ZKuP case "5": OrganisatorStart(); break; + case "6": + M2_AMStart(); + break; default: BesucherCreateStart(); break; } + + this.Title = "ZKuP - " + Version + "\tRolle: " + LoggedInRole.ToString().Replace("_", " "); + })); - var beInfos = await SQL.ReadListStringTwoColumns($"SELECT flaeche, bereich FROM {MainWindow.table}.`be-belegung`"); - await Dispatcher.BeginInvoke(new Action(() => + //var beInfos = await SQL.ReadListStringTwoColumns($"SELECT flaeche, bereich FROM {MainWindow.table}.`be-belegung`"); + await Dispatcher.BeginInvoke(new Action(async () => { - //foreach (TextBlock tb in Helper.FindVisualChildren(BE).Where(p => p.Tag != null)) - //{ - // if (tb.Tag.ToString() != "0") - // { - // StackPanel sp = new StackPanel(); - - // string ort = beInfos.Where(p => p.StartsWith(tb.Tag.ToString())).First().Split(';')[1]; - - // var img = new BitmapImage(new Uri(@"pack://application:,,,/" - // + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name - // + ";component/" - // + $"Assets/BE{tb.Tag.ToString()}.png", UriKind.Absolute)); - - // sp.Children.Add(new TextBlock() { Text = $"BE-Fläche {tb.Tag.ToString()} - {ort}", FontWeight = FontWeights.Bold }); - // sp.Children.Add(new Image() { Source = img, Width = img.Width / 1.5, Height = img.Height / 1.5 }); - - // tb.ToolTip = sp; - // } - //} + var ausgegebenAn = await SQL.ReadDictionary2($"SELECT p.parkplatznr, f.Name FROM {MainWindow.table}.parkplaetze p LEFT JOIN {MainWindow.table}.firmen f ON f.idFirmen = p.firma", 0, 1); foreach (TextBlock tb in Helper.FindVisualChildren(BE))//.Where(p => p.Tag == null)) { @@ -369,7 +465,14 @@ namespace ZKuP sp.Children.Add(new TextBlock() { Text = $"Parkplatz {tb.Text.PadLeft(2,'0')}", FontWeight = FontWeights.Bold }); sp.Children.Add(new Image() { Source = img, Width = img.Width, Height = img.Height }); + + var x = ausgegebenAn.TryGetValue(parkplatz, out string y); + if (ausgegebenAn.ContainsKey(parkplatz) && x && !string.IsNullOrWhiteSpace(y)) + sp.Children.Add(new TextBlock() { Text = $"Ausgegeben an {y}" }); + tb.ToolTip = sp; + ToolTipService.SetInitialShowDelay(tb, 100); + ToolTipService.SetBetweenShowDelay(tb, 100); } } })); @@ -410,7 +513,35 @@ namespace ZKuP dgOverview.Items.SortDescriptions.Add(new SortDescription("Zutritt", ListSortDirection.Descending)); dgOverview.Items.Refresh(); - gridSpinner.Visibility = Visibility.Collapsed; + //var gif = XamlAnimatedGif.AnimationBehavior.GetAnimator(imgLoading); + //if (gif != null) + //{ + // gif.Pause(); + //} + //imgLoading.Visibility = Visibility.Collapsed; + + this.Height = Settings.GetSettingDouble("Height"); + this.Width = Settings.GetSettingDouble("Width"); + this.Left = Settings.GetSettingDouble("Left"); + this.Top = Settings.GetSettingDouble("Top"); + + var ws = Settings.GetSetting("WindowState"); + this.WindowState = ws == "" ? WindowState.Normal : (WindowState)ws; + + //double ratio = Settings.GetSettingDouble("ColumnRatio"); + + // Gespeicherte Werte laden + double col1Width = Settings.GetSettingDouble("LeftColumn"); + double col2Width = Settings.GetSettingDouble("RightColumn"); + + // Column-Breiten setzen + gridToday.ColumnDefinitions[0].Width = new GridLength(col1Width, GridUnitType.Star); + gridToday.ColumnDefinitions[2].Width = new GridLength(col2Width, GridUnitType.Star); + // Index 1 ist der GridSplitter mit Auto-Breite + + + ReadyToSavePosition = true; + gridSpinner.Visibility = Visibility.Hidden; @@ -418,9 +549,9 @@ namespace ZKuP reloadTimer.Tick += ReloadTimer_Tick; reloadTimer.Start(); - reloadTimerHinweis.Interval = TimeSpan.FromSeconds(10); - reloadTimerHinweis.Tick += ReloadTimerHinweis_Tick; - reloadTimerHinweis.Start(); + //reloadTimerHinweis.Interval = TimeSpan.FromSeconds(10); + //reloadTimerHinweis.Tick += ReloadTimerHinweis_Tick; + //reloadTimerHinweis.Start(); checkUpdateTimer.Interval = TimeSpan.FromMinutes(5); checkUpdateTimer.Tick += CheckUpdateTimer_Tick; @@ -429,7 +560,7 @@ namespace ZKuP - if (LoggedInRole == Roles.Admin && Properties.Settings.Default.ShowParkcardAccept) + if ((LoggedInRole == Roles.Admin || LoggedInRole == Roles.M2_AM) && Settings.GetSettingBool("ShowParkcardAccept")) { if (SQL.RowExists("parkausweise", "Genehmigt", "0").Result == true) { @@ -441,7 +572,7 @@ namespace ZKuP } } } - else if (LoggedInRole == Roles.Admin && Properties.Settings.Default.ShowParkcardPrint) + else if ((LoggedInRole == Roles.Admin || LoggedInRole == Roles.M2_AM) && Settings.GetSettingBool("ShowParkcardPrint")) { if (SQL.RowExists("parkausweise", "Genehmigt = '1' AND Gedruckt", "0").Result == true) { @@ -456,6 +587,12 @@ namespace ZKuP })); } + + Dispatcher.Invoke(() => Helper.FindVisualChildren @@ -348,6 +348,18 @@ + +