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_;
|
||||
/// <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_;
|
||||
/// <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_;
|
||||
/// <inheritdoc/>
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="200"/>
|
||||
<ColumnDefinition Width="5"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
|
@ -25,7 +26,7 @@
|
|||
</Grid.RowDefinitions>
|
||||
|
||||
<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"
|
||||
ItemsSource="{Binding TimeItems}" SelectedItem="{Binding SelectedTimeItem}">
|
||||
<ListBox.ContextMenu>
|
||||
|
@ -63,12 +64,22 @@
|
|||
<Setter Property="ContentTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate DataType="{x:Type domain:TimeItem}">
|
||||
<DataTemplate.Resources>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Margin" Value="2"/>
|
||||
</Style>
|
||||
</DataTemplate.Resources>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{Binding Description}"/>
|
||||
<TextBlock Text="{Binding From,StringFormat=g}" HorizontalAlignment="Right"/>
|
||||
<TextBlock Text="{Binding Till,StringFormat=g}" HorizontalAlignment="Right"/>
|
||||
<TextBlock Text="{Binding CostUnit}"/>
|
||||
<TextBlock Text="{Binding ItemType}"/>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
||||
<TextBlock Text="{Binding Description}"/>
|
||||
<TextBlock Text=" - "/>
|
||||
<TextBlock Text="{Binding CostUnit}"/>
|
||||
</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>
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
|
@ -109,8 +120,10 @@
|
|||
</ListBox.ItemContainerStyle>
|
||||
</ListBox>
|
||||
</DockPanel>
|
||||
|
||||
<GridSplitter Grid.Column="1" ResizeBehavior="PreviousAndNext" ResizeDirection="Columns" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
|
||||
|
||||
<ContentControl Grid.Column="1" Margin="5" Content="{Binding SelectedTimeItem}">
|
||||
<ContentControl Grid.Column="2" Margin="5" Content="{Binding SelectedTimeItem}">
|
||||
<ContentControl.ContentTemplate>
|
||||
<DataTemplate DataType="{x:Type domain:TimeItem}">
|
||||
<Grid>
|
||||
|
@ -145,13 +158,13 @@
|
|||
</Grid.Resources>
|
||||
|
||||
<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:"/>
|
||||
<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:"/>
|
||||
<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:"/>
|
||||
<ComboBox Grid.Column="1" Grid.Row="3" DisplayMemberPath="Value" SelectedValuePath="Key"
|
||||
|
|
|
@ -12,6 +12,13 @@ namespace TimeScheduler.ViewModel
|
|||
class MainViewModel : NotifyableObject
|
||||
{
|
||||
#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>
|
||||
public MainViewModel() : this(new Domain.Impl.FileDomain()) { Refresh(); }
|
||||
|
||||
|
@ -21,32 +28,105 @@ namespace TimeScheduler.ViewModel
|
|||
{
|
||||
Provider = provider;
|
||||
|
||||
// Elementliste aufbauen
|
||||
TimeItems = new ObservableCollection<ITimeItem>();
|
||||
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();
|
||||
|
||||
// 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>
|
||||
protected IDomain Provider { get; private set; }
|
||||
#endregion
|
||||
|
||||
#region Eigenschaften
|
||||
private DateTime currentDate_ = DateTime.Now.Date;
|
||||
public DateTime CurrentDate
|
||||
private DateTime selectedDate_ = DateTime.Now.Date;
|
||||
/// <summary>Beinhaltet den selektierten Tag</summary>
|
||||
public DateTime SelectedDate
|
||||
{
|
||||
get { return currentDate_; }
|
||||
get { return selectedDate_; }
|
||||
set
|
||||
{
|
||||
if (SetField(ref currentDate_, value))
|
||||
RefreshForDate(currentDate_);
|
||||
if (SetField(ref selectedDate_, value))
|
||||
RefreshForDate(selectedDate_);
|
||||
}
|
||||
}
|
||||
|
||||
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); } }
|
||||
|
||||
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); } }
|
||||
|
||||
private ObservableCollection<ITimeItem> timeItems_;
|
||||
|
@ -77,7 +157,18 @@ namespace TimeScheduler.ViewModel
|
|||
ItemTypes = it;
|
||||
|
||||
// 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)
|
||||
{
|
||||
|
@ -119,6 +210,8 @@ namespace TimeScheduler.ViewModel
|
|||
public ICommand DeleteCommand { get; private set; }
|
||||
private void Delete() { TimeItems.Remove(SelectedTimeItem); }
|
||||
public bool CanDelete() { return SelectedTimeItem != null; }
|
||||
|
||||
private void Save() { if (lastTimeItem_ != null) { lastTimeItem_.Till = DateTime.Now; } }
|
||||
#endregion
|
||||
|
||||
#region Hilfsfunktionen
|
||||
|
|
Loading…
Reference in a new issue