Nochmal etwas umgestalltet und automatische Zeitaktualisierung eingebaut
This commit is contained in:
parent
a922563849
commit
0147753ff6
3 changed files with 142 additions and 18 deletions
|
@ -75,11 +75,29 @@ namespace TimeScheduler.Domain.Impl
|
||||||
|
|
||||||
private DateTime from_;
|
private DateTime from_;
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public DateTime From { get { return from_; } set { SetField(ref from_, value); } }
|
public DateTime From
|
||||||
|
{
|
||||||
|
get { return from_; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (SetField(ref from_, value.Subtract(TimeSpan.FromMinutes(value.Minute % 15))))
|
||||||
|
if (From > Till)
|
||||||
|
Till = From;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private DateTime till_;
|
private DateTime till_;
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public DateTime Till { get { return till_; } set { SetField(ref till_, value); } }
|
public DateTime Till
|
||||||
|
{
|
||||||
|
get { return till_; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (SetField(ref till_, value.Subtract(TimeSpan.FromMinutes(value.Minute % 15))))
|
||||||
|
if (Till < From)
|
||||||
|
From = Till;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int costUnit_;
|
private int costUnit_;
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="200"/>
|
<ColumnDefinition Width="200"/>
|
||||||
|
<ColumnDefinition Width="5"/>
|
||||||
<ColumnDefinition/>
|
<ColumnDefinition/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
|
@ -25,7 +26,7 @@
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<DockPanel Grid.Column="0">
|
<DockPanel Grid.Column="0">
|
||||||
<DatePicker DockPanel.Dock="Top" Margin="5" SelectedDate="{Binding Path=CurrentDate}"/>
|
<DatePicker DockPanel.Dock="Top" Margin="5" SelectedDate="{Binding Path=SelectedDate}"/>
|
||||||
<ListBox x:Name="lbTimeElements" Margin="5" HorizontalContentAlignment="Stretch"
|
<ListBox x:Name="lbTimeElements" Margin="5" HorizontalContentAlignment="Stretch"
|
||||||
ItemsSource="{Binding TimeItems}" SelectedItem="{Binding SelectedTimeItem}">
|
ItemsSource="{Binding TimeItems}" SelectedItem="{Binding SelectedTimeItem}">
|
||||||
<ListBox.ContextMenu>
|
<ListBox.ContextMenu>
|
||||||
|
@ -63,12 +64,22 @@
|
||||||
<Setter Property="ContentTemplate">
|
<Setter Property="ContentTemplate">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<DataTemplate DataType="{x:Type domain:TimeItem}">
|
<DataTemplate DataType="{x:Type domain:TimeItem}">
|
||||||
|
<DataTemplate.Resources>
|
||||||
|
<Style TargetType="TextBlock">
|
||||||
|
<Setter Property="Margin" Value="2"/>
|
||||||
|
</Style>
|
||||||
|
</DataTemplate.Resources>
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<TextBlock Text="{Binding Description}"/>
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
||||||
<TextBlock Text="{Binding From,StringFormat=g}" HorizontalAlignment="Right"/>
|
<TextBlock Text="{Binding Description}"/>
|
||||||
<TextBlock Text="{Binding Till,StringFormat=g}" HorizontalAlignment="Right"/>
|
<TextBlock Text=" - "/>
|
||||||
<TextBlock Text="{Binding CostUnit}"/>
|
<TextBlock Text="{Binding CostUnit}"/>
|
||||||
<TextBlock Text="{Binding ItemType}"/>
|
</StackPanel>
|
||||||
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||||
|
<TextBlock Text="{Binding From,StringFormat=t}" HorizontalAlignment="Right"/>
|
||||||
|
<TextBlock Text=" - "/>
|
||||||
|
<TextBlock Text="{Binding Till,StringFormat=t}" HorizontalAlignment="Right"/>
|
||||||
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</Setter.Value>
|
</Setter.Value>
|
||||||
|
@ -110,7 +121,9 @@
|
||||||
</ListBox>
|
</ListBox>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
|
|
||||||
<ContentControl Grid.Column="1" Margin="5" Content="{Binding SelectedTimeItem}">
|
<GridSplitter Grid.Column="1" ResizeBehavior="PreviousAndNext" ResizeDirection="Columns" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
|
||||||
|
|
||||||
|
<ContentControl Grid.Column="2" Margin="5" Content="{Binding SelectedTimeItem}">
|
||||||
<ContentControl.ContentTemplate>
|
<ContentControl.ContentTemplate>
|
||||||
<DataTemplate DataType="{x:Type domain:TimeItem}">
|
<DataTemplate DataType="{x:Type domain:TimeItem}">
|
||||||
<Grid>
|
<Grid>
|
||||||
|
@ -145,13 +158,13 @@
|
||||||
</Grid.Resources>
|
</Grid.Resources>
|
||||||
|
|
||||||
<TextBlock Grid.Column="0" Grid.Row="0" Text="Beschreibung:"/>
|
<TextBlock Grid.Column="0" Grid.Row="0" Text="Beschreibung:"/>
|
||||||
<TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Path=Description}"/>
|
<TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Path=Description,UpdateSourceTrigger=PropertyChanged}"/>
|
||||||
|
|
||||||
<TextBlock Grid.Column="0" Grid.Row="1" Text="Von:"/>
|
<TextBlock Grid.Column="0" Grid.Row="1" Text="Von:"/>
|
||||||
<DatePickerTextBox Grid.Column="1" Grid.Row="1" Text="{Binding From,StringFormat=g}"/>
|
<DatePickerTextBox Grid.Column="1" Grid.Row="1" Text="{Binding From,StringFormat=g,UpdateSourceTrigger=PropertyChanged}"/>
|
||||||
|
|
||||||
<TextBlock Grid.Column="0" Grid.Row="2" Text="Bis:"/>
|
<TextBlock Grid.Column="0" Grid.Row="2" Text="Bis:"/>
|
||||||
<DatePickerTextBox Grid.Column="1" Grid.Row="2" Text="{Binding Till,StringFormat=g}"/>
|
<DatePickerTextBox Grid.Column="1" Grid.Row="2" Text="{Binding Till,StringFormat=g,UpdateSourceTrigger=PropertyChanged}"/>
|
||||||
|
|
||||||
<TextBlock Grid.Column="0" Grid.Row="3" Text="Kostenstelle:"/>
|
<TextBlock Grid.Column="0" Grid.Row="3" Text="Kostenstelle:"/>
|
||||||
<ComboBox Grid.Column="1" Grid.Row="3" DisplayMemberPath="Value" SelectedValuePath="Key"
|
<ComboBox Grid.Column="1" Grid.Row="3" DisplayMemberPath="Value" SelectedValuePath="Key"
|
||||||
|
|
|
@ -12,6 +12,13 @@ namespace TimeScheduler.ViewModel
|
||||||
class MainViewModel : NotifyableObject
|
class MainViewModel : NotifyableObject
|
||||||
{
|
{
|
||||||
#region Konstruktion
|
#region Konstruktion
|
||||||
|
/// <summary>aktuelles Ele</summary>
|
||||||
|
private ITimeItem lastTimeItem_;
|
||||||
|
/// <summary>Element, das noch undefinierten Zeitraum speichert</summary>
|
||||||
|
private ITimeItem undefinedItem_;
|
||||||
|
/// <summary>Zyklische Aktuallisierung</summary>
|
||||||
|
private System.Timers.Timer timer_;
|
||||||
|
|
||||||
/// <summary>Standard-Konstruktor</summary>
|
/// <summary>Standard-Konstruktor</summary>
|
||||||
public MainViewModel() : this(new Domain.Impl.FileDomain()) { Refresh(); }
|
public MainViewModel() : this(new Domain.Impl.FileDomain()) { Refresh(); }
|
||||||
|
|
||||||
|
@ -21,32 +28,105 @@ namespace TimeScheduler.ViewModel
|
||||||
{
|
{
|
||||||
Provider = provider;
|
Provider = provider;
|
||||||
|
|
||||||
|
// Elementliste aufbauen
|
||||||
TimeItems = new ObservableCollection<ITimeItem>();
|
TimeItems = new ObservableCollection<ITimeItem>();
|
||||||
TimeItems.CollectionChanged += TimeItems_CollectionChanged;
|
TimeItems.CollectionChanged += TimeItems_CollectionChanged;
|
||||||
|
var view = System.Windows.Data.CollectionViewSource.GetDefaultView(TimeItems);
|
||||||
|
view.SortDescriptions.Add(new System.ComponentModel.SortDescription("From", System.ComponentModel.ListSortDirection.Ascending));
|
||||||
|
|
||||||
|
// Ereignis zum autmoatisierten speichern konsumieren
|
||||||
|
Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
|
||||||
|
Microsoft.Win32.SystemEvents.SessionEnded += SystemEvents_SessionEnded;
|
||||||
|
Microsoft.Win32.SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
|
||||||
|
|
||||||
|
// Kommandos erzeugen
|
||||||
CreateCommands();
|
CreateCommands();
|
||||||
|
|
||||||
|
// Zyklischer Timer aufbauen
|
||||||
|
timer_ = new System.Timers.Timer(10000);
|
||||||
|
timer_.Elapsed += Timer_Elapsed;
|
||||||
|
timer_.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
switch (e.Mode)
|
||||||
|
{
|
||||||
|
case Microsoft.Win32.PowerModes.Resume: break;
|
||||||
|
case Microsoft.Win32.PowerModes.StatusChange: break;
|
||||||
|
case Microsoft.Win32.PowerModes.Suspend:
|
||||||
|
// Beim wechseln in Suspend, ein neues Element erzeugen, wenn das vorhergehende lang genug ist
|
||||||
|
Save();
|
||||||
|
if (lastTimeItem_ != null)
|
||||||
|
if ((lastTimeItem_.Till - lastTimeItem_.From) > TimeSpan.FromMinutes(15))
|
||||||
|
{
|
||||||
|
var newItem = Provider.NewItem();
|
||||||
|
newItem.From = lastTimeItem_.Till;
|
||||||
|
TimeItems.Add(newItem);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exc) { }
|
||||||
|
}
|
||||||
|
private void SystemEvents_SessionEnded(object sender, Microsoft.Win32.SessionEndedEventArgs e) { Save(); }
|
||||||
|
private void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
switch (e.Reason)
|
||||||
|
{
|
||||||
|
case Microsoft.Win32.SessionSwitchReason.ConsoleConnect: break;
|
||||||
|
case Microsoft.Win32.SessionSwitchReason.ConsoleDisconnect: break;
|
||||||
|
case Microsoft.Win32.SessionSwitchReason.RemoteConnect: break;
|
||||||
|
case Microsoft.Win32.SessionSwitchReason.RemoteDisconnect: break;
|
||||||
|
case Microsoft.Win32.SessionSwitchReason.SessionLogon: break;
|
||||||
|
case Microsoft.Win32.SessionSwitchReason.SessionLogoff: break;
|
||||||
|
case Microsoft.Win32.SessionSwitchReason.SessionLock:
|
||||||
|
// Beim Sperren, eine neue Session beginnen
|
||||||
|
Save();
|
||||||
|
if (lastTimeItem_ != null)
|
||||||
|
if ((lastTimeItem_.Till - lastTimeItem_.From) >= TimeSpan.FromMinutes(15))
|
||||||
|
{
|
||||||
|
var newItem = Provider.NewItem();
|
||||||
|
newItem.From = lastTimeItem_.Till;
|
||||||
|
TimeItems.Add(newItem);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Microsoft.Win32.SessionSwitchReason.SessionUnlock: break;
|
||||||
|
case Microsoft.Win32.SessionSwitchReason.SessionRemoteControl: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exc) { }
|
||||||
|
}
|
||||||
|
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { Save(); }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>Datenbeschaffer</summary>
|
/// <summary>Datenbeschaffer</summary>
|
||||||
protected IDomain Provider { get; private set; }
|
protected IDomain Provider { get; private set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Eigenschaften
|
#region Eigenschaften
|
||||||
private DateTime currentDate_ = DateTime.Now.Date;
|
private DateTime selectedDate_ = DateTime.Now.Date;
|
||||||
public DateTime CurrentDate
|
/// <summary>Beinhaltet den selektierten Tag</summary>
|
||||||
|
public DateTime SelectedDate
|
||||||
{
|
{
|
||||||
get { return currentDate_; }
|
get { return selectedDate_; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (SetField(ref currentDate_, value))
|
if (SetField(ref selectedDate_, value))
|
||||||
RefreshForDate(currentDate_);
|
RefreshForDate(selectedDate_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<int, string> costUnits_;
|
private Dictionary<int, string> costUnits_;
|
||||||
|
/// <summary>Liste der vorhanden Kostenstellen</summary>
|
||||||
public Dictionary<int, string> CostUnits { get { return costUnits_; } private set { SetField(ref costUnits_, value); } }
|
public Dictionary<int, string> CostUnits { get { return costUnits_; } private set { SetField(ref costUnits_, value); } }
|
||||||
|
|
||||||
private Dictionary<TimeItemType, string> itemTypes_;
|
private Dictionary<TimeItemType, string> itemTypes_;
|
||||||
|
/// <summary>Liste der vorhanden Typen von TimeItem</summary>
|
||||||
public Dictionary<TimeItemType, string> ItemTypes { get { return itemTypes_; } private set { SetField(ref itemTypes_, value); } }
|
public Dictionary<TimeItemType, string> ItemTypes { get { return itemTypes_; } private set { SetField(ref itemTypes_, value); } }
|
||||||
|
|
||||||
private ObservableCollection<ITimeItem> timeItems_;
|
private ObservableCollection<ITimeItem> timeItems_;
|
||||||
|
@ -77,7 +157,18 @@ namespace TimeScheduler.ViewModel
|
||||||
ItemTypes = it;
|
ItemTypes = it;
|
||||||
|
|
||||||
// Andere Daten ermitteln
|
// Andere Daten ermitteln
|
||||||
RefreshForDate(CurrentDate);
|
RefreshForDate(SelectedDate);
|
||||||
|
|
||||||
|
// Letztes Element ermitteln, auf dem weiter gelaufen wird
|
||||||
|
var lastItem = TimeItems.OrderByDescending(x => x.From).FirstOrDefault();
|
||||||
|
if (lastItem == null || lastItem.From.Date != SelectedDate.Date)
|
||||||
|
{// Wenn keines gefunden wurde oder keins für den heutigen Tag gefunden wurde, dann eins neu erzeugen
|
||||||
|
lastItem = Provider.NewItem();
|
||||||
|
lastItem.From = DateTime.Now;
|
||||||
|
TimeItems.Add(lastItem);
|
||||||
|
}
|
||||||
|
// und abspeichern
|
||||||
|
lastTimeItem_ = lastItem;
|
||||||
}
|
}
|
||||||
private void RefreshForDate(DateTime date)
|
private void RefreshForDate(DateTime date)
|
||||||
{
|
{
|
||||||
|
@ -119,6 +210,8 @@ namespace TimeScheduler.ViewModel
|
||||||
public ICommand DeleteCommand { get; private set; }
|
public ICommand DeleteCommand { get; private set; }
|
||||||
private void Delete() { TimeItems.Remove(SelectedTimeItem); }
|
private void Delete() { TimeItems.Remove(SelectedTimeItem); }
|
||||||
public bool CanDelete() { return SelectedTimeItem != null; }
|
public bool CanDelete() { return SelectedTimeItem != null; }
|
||||||
|
|
||||||
|
private void Save() { if (lastTimeItem_ != null) { lastTimeItem_.Till = DateTime.Now; } }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Hilfsfunktionen
|
#region Hilfsfunktionen
|
||||||
|
|
Loading…
Reference in a new issue