254 lines
10 KiB
C#
254 lines
10 KiB
C#
// Copyright (c) 2017 schick Informatik
|
|
// Description: Basisklasse für die Detailansichten. Hier sollten Dinge wie Validierung etc. abgehandelt werden
|
|
//
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Controls;
|
|
|
|
using bsmd.database;
|
|
using System.Windows.Media.Imaging;
|
|
using System.ComponentModel;
|
|
using System.Windows.Data;
|
|
|
|
namespace ENI2
|
|
{
|
|
public class DetailBaseControl : UserControl
|
|
{
|
|
|
|
#region Fields
|
|
|
|
protected bool _initialized = false;
|
|
|
|
private DependencyPropertyDescriptor _dpTextBox;
|
|
private DependencyPropertyDescriptor _dpDateTimePicker;
|
|
private DependencyPropertyDescriptor _dpDatePicker;
|
|
private DependencyPropertyDescriptor _dpLocode;
|
|
private DependencyPropertyDescriptor _dpCheckbox;
|
|
private DependencyPropertyDescriptor _dpComboboxIndex;
|
|
private DependencyPropertyDescriptor _dpComboboxValue;
|
|
private DependencyPropertyDescriptor _dpNumericUpdown;
|
|
private DependencyPropertyDescriptor _dpIntUpdown;
|
|
private Dictionary<Object, Message.NotificationClass> _controlClassDict = new Dictionary<object, Message.NotificationClass>();
|
|
private Dictionary<Message.NotificationClass, Message> _typeMessageDict = new Dictionary<Message.NotificationClass, Message>();
|
|
private List<Message> _controlMessages = new List<Message>();
|
|
|
|
#endregion
|
|
|
|
#region enum
|
|
|
|
protected enum LocodeState
|
|
{
|
|
UNKNOWN,
|
|
INVALID,
|
|
OK,
|
|
AMBIGUOUS
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region events
|
|
|
|
/// <summary>
|
|
/// Mit diesem event kann ein Listenelement den programmatischen Sprung auf ein anderes Listenelement auslösen
|
|
/// (das wird zunächst nur vom Overview -> Auswahl Meldeklasse verwendet)
|
|
/// </summary>
|
|
public event Action<int> JumpToListElementRequest;
|
|
|
|
/// <summary>
|
|
/// Mit diesem Event kann ein Listen-Element einen Reload der gesamten Anmeldung auslösen (ob das so eine tolle Idee ist.)
|
|
/// </summary>
|
|
public event Action RequestReload;
|
|
|
|
/// <summary>
|
|
/// Eine in der Detailansicht enthaltene Meldeklasse hat sich geändert
|
|
/// </summary>
|
|
public event Action<Message.NotificationClass> NotificationClassChanged;
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// Core to be edited
|
|
/// </summary>
|
|
public MessageCore Core { get; set; }
|
|
|
|
/// <summary>
|
|
/// all messages for this core
|
|
/// </summary>
|
|
public List<Message> Messages { get; set; }
|
|
|
|
/// <summary>
|
|
/// particular messages that are edited on this page
|
|
/// </summary>
|
|
public List<Message> ControlMessages { get { return this._controlMessages; } }
|
|
|
|
public Guid UserId { get; set; } // TODO: Ersetzen mit der User-Entity
|
|
|
|
public bool LockedByOtherUser { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region public methods
|
|
|
|
public virtual void Initialize() {
|
|
|
|
_dpTextBox = DependencyPropertyDescriptor.FromProperty(TextBox.TextProperty, typeof(TextBox));
|
|
_dpDateTimePicker = DependencyPropertyDescriptor.FromProperty(Xceed.Wpf.Toolkit.DateTimePicker.ValueProperty, typeof(Xceed.Wpf.Toolkit.DateTimePicker));
|
|
_dpDatePicker = DependencyPropertyDescriptor.FromProperty(DatePicker.SelectedDateProperty, typeof(DatePicker));
|
|
_dpLocode = DependencyPropertyDescriptor.FromProperty(Controls.LocodeControl.LocodeValueProperty, typeof(Controls.LocodeControl));
|
|
_dpCheckbox = DependencyPropertyDescriptor.FromProperty(CheckBox.IsCheckedProperty, typeof(CheckBox));
|
|
_dpComboboxIndex = DependencyPropertyDescriptor.FromProperty(ComboBox.SelectedIndexProperty, typeof(ComboBox));
|
|
_dpComboboxValue = DependencyPropertyDescriptor.FromProperty(ComboBox.SelectedValueProperty, typeof(ComboBox));
|
|
_dpNumericUpdown = DependencyPropertyDescriptor.FromProperty(Xceed.Wpf.Toolkit.DoubleUpDown.ValueProperty, typeof(Xceed.Wpf.Toolkit.DoubleUpDown));
|
|
_dpIntUpdown = DependencyPropertyDescriptor.FromProperty(Xceed.Wpf.Toolkit.IntegerUpDown.ValueProperty, typeof(Xceed.Wpf.Toolkit.IntegerUpDown));
|
|
|
|
|
|
foreach(Message message in this.Messages)
|
|
{
|
|
_typeMessageDict[message.MessageNotificationClass] = message;
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region protected methods
|
|
|
|
protected virtual void OnJumpToListElementRequest(int index)
|
|
{
|
|
this.JumpToListElementRequest?.Invoke(index);
|
|
}
|
|
|
|
protected virtual void OnRequestReload()
|
|
{
|
|
this.RequestReload?.Invoke();
|
|
}
|
|
|
|
#region event handling for control content changes (signal dirty etc)
|
|
|
|
protected void RegisterTextboxChange(TextBox textBox, Message.NotificationClass notificationClass)
|
|
{
|
|
this._dpTextBox.AddValueChanged(textBox, this.controlContentChanged);
|
|
this._controlClassDict[textBox] = notificationClass;
|
|
}
|
|
|
|
protected void RegisterDateTimePickerChange(Xceed.Wpf.Toolkit.DateTimePicker dateTimePicker, Message.NotificationClass notificationClass)
|
|
{
|
|
this._dpDateTimePicker.AddValueChanged(dateTimePicker, this.controlContentChanged);
|
|
this._controlClassDict[dateTimePicker] = notificationClass;
|
|
}
|
|
|
|
protected void RegisterDatePickerChange(DatePicker datePicker, Message.NotificationClass notificationClass)
|
|
{
|
|
this._dpDatePicker.AddValueChanged(datePicker, this.controlContentChanged);
|
|
this._controlClassDict[datePicker] = notificationClass;
|
|
}
|
|
|
|
protected void RegisterLocodeChange(Controls.LocodeControl locodeControl, Message.NotificationClass notificationClass)
|
|
{
|
|
this._dpLocode.AddValueChanged(locodeControl, this.controlContentChanged);
|
|
this._controlClassDict[locodeControl] = notificationClass;
|
|
}
|
|
|
|
protected void RegisterCheckboxChange(CheckBox checkBox, Message.NotificationClass notificationClass)
|
|
{
|
|
this._dpCheckbox.AddValueChanged(checkBox, this.controlContentChanged);
|
|
this._controlClassDict[checkBox] = notificationClass;
|
|
}
|
|
|
|
protected void RegisterComboboxIndexChange(ComboBox comboBox, Message.NotificationClass notificationClass)
|
|
{
|
|
this._dpComboboxIndex.AddValueChanged(comboBox, this.controlContentChanged);
|
|
this._controlClassDict[comboBox] = notificationClass;
|
|
}
|
|
|
|
protected void RegisterComboboxValueChange(ComboBox comboBox, Message.NotificationClass notificationClass)
|
|
{
|
|
this._dpComboboxValue.AddValueChanged(comboBox, this.controlContentChanged);
|
|
this._controlClassDict[comboBox] = notificationClass;
|
|
}
|
|
|
|
protected void RegisterDoubleUpDownChange(Xceed.Wpf.Toolkit.DoubleUpDown doubleUpDown, Message.NotificationClass notificationClass)
|
|
{
|
|
this._dpNumericUpdown.AddValueChanged(doubleUpDown, this.controlContentChanged);
|
|
this._controlClassDict[doubleUpDown] = notificationClass;
|
|
}
|
|
|
|
protected void RegisterIntegerUpDownChange(Xceed.Wpf.Toolkit.IntegerUpDown intUpDown, Message.NotificationClass notificationClass)
|
|
{
|
|
this._dpIntUpdown.AddValueChanged(intUpDown, this.controlContentChanged);
|
|
this._controlClassDict[intUpDown] = notificationClass;
|
|
}
|
|
|
|
protected void SublistElementChanged(Message.NotificationClass notificationClass)
|
|
{
|
|
if (_typeMessageDict.ContainsKey(notificationClass))
|
|
{
|
|
if (!_typeMessageDict[notificationClass].IsDirty)
|
|
{
|
|
if (!_typeMessageDict[notificationClass].IsDirty)
|
|
{
|
|
_typeMessageDict[notificationClass].IsDirty = true;
|
|
// signal this notification class changed..
|
|
this.NotificationClassChanged?.Invoke(notificationClass);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void controlContentChanged(object ctrl, EventArgs args)
|
|
{
|
|
if (this._controlClassDict.ContainsKey(ctrl))
|
|
{
|
|
Message.NotificationClass notificationClass = this._controlClassDict[ctrl];
|
|
this.SublistElementChanged(notificationClass);
|
|
}
|
|
else
|
|
{
|
|
System.Diagnostics.Trace.WriteLine("no notification class registered for control!!");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region combobox content filtering
|
|
|
|
protected void ComboBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
|
|
{
|
|
ComboBox cmb = sender as ComboBox;
|
|
if (cmb == null) return;
|
|
CollectionView itemsViewOriginal = (CollectionView)CollectionViewSource.GetDefaultView(cmb.ItemsSource);
|
|
|
|
itemsViewOriginal.Filter = ((o) =>
|
|
{
|
|
bool result = false;
|
|
if (String.IsNullOrEmpty(cmb.Text))
|
|
{
|
|
result = true;
|
|
}
|
|
else if (o is string)
|
|
{
|
|
if (((string)o).Contains(cmb.Text, StringComparison.OrdinalIgnoreCase)) result = true;
|
|
}
|
|
else if (o is System.Collections.Generic.KeyValuePair<string, string>)
|
|
{
|
|
if (((System.Collections.Generic.KeyValuePair<string, string>)o).Value.StartsWith(cmb.Text, StringComparison.OrdinalIgnoreCase))
|
|
result = true;
|
|
}
|
|
return result;
|
|
});
|
|
|
|
itemsViewOriginal.Refresh();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
}
|
|
|