- Speichern - Locking (noch nicht funktional) - Visit-Id anfordern (noch nicht funktional) - neuer Splashscreen
168 lines
6.4 KiB
C#
168 lines
6.4 KiB
C#
// Copyright (c) 2017 Informatibüro Daniel Schick
|
|
// Description: Haupteinstiegsmaske ENI-2: Suche
|
|
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
|
|
using bsmd.database;
|
|
|
|
namespace ENI2
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for SucheControl.xaml
|
|
/// </summary>
|
|
public partial class SucheControl : UserControl
|
|
{
|
|
|
|
private List<MessageCore> anmeldungen = new List<MessageCore>();
|
|
|
|
#region Construction
|
|
|
|
public SucheControl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#endregion
|
|
|
|
public event MessageCore.MessageCoreSelectedHandler MessageCoreSelected;
|
|
|
|
#region event handler searching
|
|
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
// Eingabefelder und Ergebnis löschen
|
|
textBoxHafen.Text = string.Empty;
|
|
textBoxId.Text = string.Empty;
|
|
textBoxIMO.Text = string.Empty;
|
|
textBoxName.Text = string.Empty;
|
|
textBoxTicketNr.Text = string.Empty;
|
|
dateTimePickerETAFrom.SelectedDate = null;
|
|
dateTimePickerETATo.SelectedDate = null;
|
|
this.dataGrid.ItemsSource = null;
|
|
this.searchResultLabel.Content = "";
|
|
}
|
|
|
|
private void buttonSuche_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
// filter auswerten
|
|
Dictionary<MessageCore.SearchFilterType, string> filterDict = new Dictionary<MessageCore.SearchFilterType, string>();
|
|
if (!this.textBoxHafen.Text.Trim().IsNullOrEmpty())
|
|
filterDict.Add(MessageCore.SearchFilterType.FILTER_PORT, this.textBoxHafen.Text.Trim());
|
|
if (!this.textBoxId.Text.Trim().IsNullOrEmpty())
|
|
filterDict.Add(MessageCore.SearchFilterType.FILTER_ID, this.textBoxId.Text.Trim());
|
|
if (!this.textBoxIMO.Text.Trim().IsNullOrEmpty())
|
|
filterDict.Add(MessageCore.SearchFilterType.FILTER_IMO, this.textBoxIMO.Text.Trim());
|
|
if (!this.textBoxName.Text.Trim().IsNullOrEmpty())
|
|
filterDict.Add(MessageCore.SearchFilterType.FILTER_SHIPNAME, this.textBoxName.Text.Trim());
|
|
if (!this.textBoxTicketNr.Text.Trim().IsNullOrEmpty())
|
|
filterDict.Add(MessageCore.SearchFilterType.FILTER_TICKETNO, this.textBoxTicketNr.Text.Trim());
|
|
|
|
uint? from = null, to = null;
|
|
if(this.dateTimePickerETAFrom.SelectedDate.HasValue)
|
|
{
|
|
from = this.dateTimePickerETAFrom.SelectedDate.Value.ToUnixTimeStamp();
|
|
}
|
|
if(this.dateTimePickerETATo.SelectedDate.HasValue)
|
|
{
|
|
DateTime toTime = this.dateTimePickerETATo.SelectedDate.Value.Add(new TimeSpan(23, 59, 59)); // search till the end of the "to" day (no time selection)
|
|
to = toTime.ToUnixTimeStamp();
|
|
}
|
|
|
|
if (from.HasValue || to.HasValue)
|
|
filterDict.Add(MessageCore.SearchFilterType.FILTER_ETA, string.Format("{0}:{1}", from?.ToString() ?? "", to?.ToString() ?? ""));
|
|
|
|
// suche auslösen
|
|
this.anmeldungen = DBManager.Instance.GetMessageCoresWithFilters(filterDict);
|
|
|
|
if (App.UserId.HasValue)
|
|
{
|
|
// "locks" dazu abfragen
|
|
LockingServiceReference.CoreLock[] coreLocks = App.LockingServiceClient.GetLocks();
|
|
Dictionary<Guid, bool?> coreLockUpdateDict = new Dictionary<Guid, bool?>();
|
|
for (int i = 0; i < coreLocks.Length; i++)
|
|
{
|
|
bool lockState = coreLocks[i].UserId.Equals(App.UserId.Value);
|
|
coreLockUpdateDict[coreLocks[i].CoreId] = lockState;
|
|
}
|
|
|
|
foreach (MessageCore core in this.anmeldungen)
|
|
if (coreLockUpdateDict.ContainsKey(core.Id.Value))
|
|
core.Locked = coreLockUpdateDict[core.Id.Value];
|
|
|
|
}
|
|
|
|
// ergebnis anzeigen
|
|
this.dataGrid.ItemsSource = this.anmeldungen;
|
|
this.searchResultLabel.Content = (this.anmeldungen.Count > 0) ? string.Format("{0} results found.", this.anmeldungen.Count) : "no results";
|
|
|
|
}
|
|
|
|
private void etaValueChanged(object sender, EventArgs args)
|
|
{
|
|
bool valid = true;
|
|
if ((this.dateTimePickerETAFrom.SelectedDate.HasValue) && (this.dateTimePickerETATo.SelectedDate.HasValue) &&
|
|
this.dateTimePickerETATo.SelectedDate.Value < this.dateTimePickerETAFrom.SelectedDate.Value)
|
|
valid = false;
|
|
|
|
this.dateTimePickerETAFrom.Background = valid ? SystemColors.ControlBrush : Brushes.Red;
|
|
this.dateTimePickerETATo.Background = valid ? SystemColors.ControlBrush : Brushes.Red;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Selection event handling
|
|
|
|
private void DisplayCore(MessageCore core)
|
|
{
|
|
if (core != null)
|
|
{
|
|
this.OnMessageCoreSelected(core);
|
|
}
|
|
}
|
|
|
|
protected void OnMessageCoreSelected(MessageCore aMessageCore)
|
|
{
|
|
if ((this.MessageCoreSelected != null) && (aMessageCore != null))
|
|
{
|
|
this.MessageCoreSelected(aMessageCore);
|
|
}
|
|
}
|
|
|
|
private void dataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
|
{
|
|
if (sender != null)
|
|
{
|
|
DataGrid grid = sender as DataGrid;
|
|
if ((grid != null) && (grid.SelectedItems != null) && (grid.SelectedItems.Count == 1))
|
|
{
|
|
DataGridRow dgr = grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) as DataGridRow;
|
|
MessageCore selectedCore = grid.SelectedItem as MessageCore;
|
|
this.DisplayCore(selectedCore);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void dataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if ((e.Key == Key.Return) || (e.Key == Key.Enter))
|
|
{
|
|
MessageCore selectedCore = dataGrid.SelectedItem as MessageCore;
|
|
this.DisplayCore(selectedCore);
|
|
}
|
|
else
|
|
{
|
|
base.OnPreviewKeyDown(e);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|