157 lines
5.8 KiB
C#
157 lines
5.8 KiB
C#
// Copyright (c) 2017 Informatibüro Daniel Schick
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
|
|
using Xceed.Wpf.Toolkit;
|
|
|
|
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.Text = string.Empty;
|
|
dateTimePickerETATo.Text = string.Empty;
|
|
this.dataGrid.ItemsSource = null;
|
|
}
|
|
|
|
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.Text.IsNullOrEmpty())
|
|
{
|
|
from = this.dateTimePickerETAFrom.Value.Value.ToUnixTimeStamp();
|
|
}
|
|
if(!this.dateTimePickerETATo.Text.IsNullOrEmpty())
|
|
{
|
|
DateTime toTime = this.dateTimePickerETATo.Value.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);
|
|
|
|
// 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.Value != null) && (this.dateTimePickerETATo.Value != null) &&
|
|
this.dateTimePickerETATo.Value.Value < this.dateTimePickerETAFrom.Value.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
|
|
|
|
}
|
|
}
|