// Copyright (c) 2023 schick Informatik // Description: Terminals have all different fields so a different dialog // using BreCalClient.misc.Model; 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.Shapes; namespace BreCalClient { /// /// Interaction logic for EditTimesTerminalControl.xaml /// public partial class EditTimesTerminalControl : Window, IEditTimesControl { public EditTimesTerminalControl() { InitializeComponent(); } #region Properties public Times Times { get; set; } = new(); public List Berths { get; set; } #endregion #region event handler private void Window_Loaded(object sender, RoutedEventArgs e) { this.comboBoxBerth.ItemsSource = this.Berths; this.CopyToControls(); } private void contextMenuItemClearOperationStart_Click(object sender, RoutedEventArgs e) { this.datePickerOperationStart.Value = null; } private void contextMenuItemClearOperationEnd_Click(object sender, RoutedEventArgs e) { this.datePickerOperationEnd.Value = null; } private void contextMenuItemBerth_Click(object sender, RoutedEventArgs e) { this.comboBoxBerth.SelectedIndex -= 1; } private void buttonOK_Click(object sender, RoutedEventArgs e) { this.CopyToModel(); this.DialogResult = true; this.Close(); } private void buttonCancel_Click(object sender, RoutedEventArgs e) { this.DialogResult = false; this.Close(); } #endregion #region private methods private void CopyToModel() { switch(this.comboBoxPierside.SelectedIndex) { case 0: this.Times.PierSide = true; break; case 1: this.Times.PierSide= false; break; default: this.Times.PierSide = null; break; } this.Times.OperationsStart = this.datePickerOperationStart.Value; this.Times.OperationsEnd = this.datePickerOperationEnd.Value; this.Times.BerthId = (this.comboBoxBerth.SelectedItem != null) ? ((Berth)this.comboBoxBerth.SelectedItem).Id : null; this.Times.Remarks = this.textBoxRemarks.Text.Trim(); this.Times.BerthInfo = this.textBoxBerthRemarks.Text.Trim(); } private void CopyToControls() { this.datePickerOperationStart.Value = this.Times.OperationsStart; this.datePickerOperationEnd.Value = this.Times.OperationsEnd; if(this.Times.PierSide == null) { this.comboBoxPierside.SelectedIndex = -1; } else this.comboBoxPierside.SelectedIndex = (this.Times.PierSide ?? false) ? 0 : 1; this.comboBoxBerth.SelectedValue = this.Times.BerthId; this.textBoxRemarks.Text = this.Times.Remarks; this.textBoxBerthRemarks.Text = this.Times.BerthInfo; } #endregion } }