This commit is contained in:
Daniel Schick 2023-02-05 11:14:07 +01:00
parent 2e91da8f3b
commit 5f28c8c7ea
8 changed files with 154 additions and 24 deletions

View File

@ -0,0 +1,14 @@
<UserControl x:Class="ENI2.Controls.BusyControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:p="clr-namespace:ENI2.Properties"
xmlns:util="clr-namespace:ENI2.Util"
xmlns:local="clr-namespace:ENI2.Controls"
mc:Ignorable="d"
d:DesignHeight="28" d:DesignWidth="28">
<Grid>
<Image Source="../Resources/bullet_ball_grey.png" x:Name="imageBall" />
</Grid>
</UserControl>

View File

@ -0,0 +1,44 @@
// Copyright (c) 2023- schick Informatik
//
// Description: Idea to have a simple control that shows if the application is busy or not using a simple icon
// that will be set according to a state
//
using ENI2.Util;
using System.Windows.Controls;
namespace ENI2.Controls
{
/// <summary>
/// Interaction logic for BusyControl.xaml
/// </summary>
public partial class BusyControl : UserControl
{
UIHelper.BusyStateEnum _busyState = UIHelper.BusyStateEnum.NEUTRAL;
public BusyControl()
{
InitializeComponent();
}
public UIHelper.BusyStateEnum BusyState
{
set
{
_busyState = value;
//Dispatcher.Invoke(() =>
//{
switch (_busyState)
{
case UIHelper.BusyStateEnum.NEUTRAL: imageBall.Source = Properties.Resources.bullet_ball_grey.CreateBitmapSource(); break;
case UIHelper.BusyStateEnum.BUSY: imageBall.Source = Properties.Resources.bullet_ball_yellow.CreateBitmapSource(); break;
case UIHelper.BusyStateEnum.FAIL: imageBall.Source = Properties.Resources.bullet_ball_red.CreateBitmapSource(); break;
case UIHelper.BusyStateEnum.SUCCESS: imageBall.Source = Properties.Resources.bullet_ball_green.CreateBitmapSource(); break;
}
//});
}
get => _busyState;
}
}
}

View File

@ -24,12 +24,21 @@
<RowDefinition Height="28" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Label Content="Calendar week" />
<Label Content="Type" />
<Button x:Name="buttonImport" Margin="2" Content="Import" Width="70" />
<Button x:Name="buttonExport" Margin="2" Content="Export" Width="70" />
</StackPanel>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80" />
<ColumnDefinition Width="80" />
<ColumnDefinition Width="80" />
<ColumnDefinition Width="80" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="30" />
</Grid.ColumnDefinitions>
<Label Content="Calendar week" Grid.Column="0"/>
<Button x:Name="buttonLoad" Grid.Column="1" Content="Load" Margin="2" Click="buttonLoad_Click" />
<Button x:Name="buttonImport" Grid.Column="2" Margin="2" Content="Import" Click="buttonImport_Click" />
<Button x:Name="buttonExport" Grid.Column="3" Margin="2" Content="Export" Click="buttonExport_Click" />
<local:BusyControl x:Name="busyControl" Grid.Column="5" />
</Grid>
<local:ENIDataGrid Grid.Row="1" Margin="2,8,2,2" x:Name="dataGridPOCores" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
SelectionMode="Single" AutoGenerateColumns="False" CellEditEnding="dataGridPOCores_CellEditEnding" CanUserAddRows="False">
<DataGrid.Columns>

View File

@ -111,24 +111,17 @@ namespace ENI2.Controls
private void PerformSearch()
{
this.dataGridPOCores.ItemsSource = null;
this.filteredResult.Clear();
// TODO: Da diese Suche hier so unfassbar lahmarschig ist wäre es günstig (zukünftig für das gesamte ENI),
// wenn die Abfrage asynchron stattfinden würde. Man muss nur irgendwie den Anwender bei Laune halten so dass
// er merkt, da passiert noch was. Eventuell mit einem "spinning" Icon. Aber der Rest bleibt aktiv.
this.filteredResult.Clear();
Dictionary<MessageCore.SearchFilterType, string> filterDict = new Dictionary<MessageCore.SearchFilterType, string>();
DateTime start = DateTime.Now; // bsmd.database.Util.FirstDateOfWeekISO8601(DateTime.Now.Year, (int)this.doubleUpDownCalendarWeek.Value);
DateTime end = start.Add(new TimeSpan(6, 23, 59, 59));
// Die Suche findet in einem erweiterten Intervall statt, da später wenn möglich nach ATA gefiltert wird
uint from = start.Subtract(new TimeSpan(10, 0, 0, 0)).ToUniversalTime().ToUnixTimeStamp();
uint to = end.Add(new TimeSpan(5, 0, 0, 0)).ToUniversalTime().ToUnixTimeStamp();
filterDict.Add(MessageCore.SearchFilterType.FILTER_ETA, string.Format("{0}:{1}", from.ToString() ?? "", to.ToString() ?? ""));
Util.UIHelper.SetBusyState();
filterDict.Add(MessageCore.SearchFilterType.FILTER_ETA, string.Format("{0}:{1}", from.ToString() ?? "", to.ToString() ?? ""));
// suche auslösen
this.searchResult = DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).GetMessageCoresWithFilters(filterDict);
@ -181,6 +174,26 @@ namespace ENI2.Controls
}
#endregion
#region button event handler
private void buttonLoad_Click(object sender, RoutedEventArgs e)
{
Util.UIHelper.SetBusyState();
this.PerformSearch();
}
private void buttonImport_Click(object sender, RoutedEventArgs e)
{
}
private void buttonExport_Click(object sender, RoutedEventArgs e)
{
}
#endregion
}
}

View File

@ -218,6 +218,9 @@
<Compile Include="..\bsmd.ExcelReadService\LocodeDB.cs">
<Link>Locode\LocodeDB.cs</Link>
</Compile>
<Compile Include="Controls\BusyControl.xaml.cs">
<DependentUpon>BusyControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\ClosableTabItem.cs" />
<Compile Include="Controls\ConditionGroupControl.xaml.cs">
<DependentUpon>ConditionGroupControl.xaml</DependentUpon>
@ -453,6 +456,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\BusyControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\ConditionGroupControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@ -31,7 +31,7 @@ namespace ENI2.EditControls
#region Drag&Drop event handler
private async void imageSource_Drop(object sender, DragEventArgs e)
private void imageSource_Drop(object sender, DragEventArgs e)
{
string[] files = (string[]) e.Data.GetData(DataFormats.FileDrop);
if (files != null)

View File

@ -5,10 +5,12 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using bsmd.database;
@ -20,6 +22,15 @@ namespace ENI2.Util
private static bool isBusy;
private static readonly Random r = new Random();
public enum BusyStateEnum
{
NEUTRAL,
BUSY,
FAIL,
SUCCESS
}
public static void SetBusyState()
{
@ -28,15 +39,16 @@ namespace ENI2.Util
private static void SetBusyState(bool busy)
{
if(busy != isBusy)
{
isBusy = busy;
Mouse.OverrideCursor = isBusy ? Cursors.Wait : null;
Mouse.OverrideCursor = isBusy ? Cursors.Wait : null;
}
if(isBusy)
{
new DispatcherTimer(TimeSpan.FromSeconds(0), DispatcherPriority.ApplicationIdle, dispatcherTimer_Tick, Application.Current.Dispatcher);
_ = new DispatcherTimer(TimeSpan.FromSeconds(0), DispatcherPriority.ApplicationIdle, dispatcherTimer_Tick, Application.Current.Dispatcher);
}
}
@ -44,13 +56,13 @@ namespace ENI2.Util
{
if (sender is DispatcherTimer timer)
{
SetBusyState(false);
SetBusyState(false);
timer.Stop();
}
}
public static bool IsModal(this Window window)
{
{
return (bool)typeof(Window).GetField("_showingAsDialog", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(window);
}
@ -59,6 +71,38 @@ namespace ENI2.Util
return Color.FromRgb((byte) r.Next(150, 255), (byte) r.Next(150, 255), (byte) r.Next(150, 255));
}
public static BitmapSource CreateBitmapSource(this System.Drawing.Bitmap bitmap)
{
if (bitmap == null)
throw new ArgumentNullException("bitmap");
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
System.Drawing.Imaging.BitmapData bitmapData = bitmap.LockBits(rect,
System.Drawing.Imaging.ImageLockMode.ReadWrite,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
try
{
var size = rect.Width * rect.Height * 4;
return BitmapSource.Create(
bitmap.Width,
bitmap.Height,
bitmap.HorizontalResolution,
bitmap.VerticalResolution,
PixelFormats.Bgra32,
null,
bitmapData.Scan0,
size,
bitmapData.Stride);
}
finally
{
bitmap.UnlockBits(bitmapData);
}
}
public static void SetMessageIcons(List<Message> messages)
{
foreach (Message aMessage in messages)
@ -159,6 +203,5 @@ namespace ENI2.Util
}
}
}
}
}

View File

@ -1537,7 +1537,7 @@ namespace bsmd.database
cmd.Connection = this._con;
// Stopwatch sw = new Stopwatch();
// sw.Start();
reader = cmd.ExecuteReader();
reader = cmd.ExecuteReader();
// sw.Stop();
// _log.DebugFormat("{1}ms: {0}", cmd.CommandText, sw.ElapsedMilliseconds);