Added sheet / logic part 6 CREW arrival

This commit is contained in:
Daniel Schick 2025-01-29 14:29:26 +01:00
parent daf20a49b3
commit 579e704a1b
10 changed files with 1218 additions and 687 deletions

View File

@ -181,6 +181,7 @@ namespace ENI2
this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.text3PreArrival, MessageGroupControlType = typeof(PreArrivalControl), ImagePath = "Resources/arrow_down_right_red.png" }); this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.text3PreArrival, MessageGroupControlType = typeof(PreArrivalControl), ImagePath = "Resources/arrow_down_right_red.png" });
this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.text4PreDeparture, MessageGroupControlType = typeof(PreDepartureControl), ImagePath = "Resources/arrow_up_right_green.png" }); this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.text4PreDeparture, MessageGroupControlType = typeof(PreDepartureControl), ImagePath = "Resources/arrow_up_right_green.png" });
this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.text5ShipData, MessageGroupControlType = typeof(ShipDataControl), ImagePath = "Resources/containership.png" }); this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.text5ShipData, MessageGroupControlType = typeof(ShipDataControl), ImagePath = "Resources/containership.png" });
this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.text6CrewDataOnArrival, MessageGroupControlType = typeof(CrewPreArrivalControl), ImagePath = "Resources/arrival_worker.png" });
} }
this.listBoxMessages.ItemsSource = this._listBoxList; this.listBoxMessages.ItemsSource = this._listBoxList;

View File

@ -493,6 +493,9 @@
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<DependentUpon>Reference.svcmap</DependentUpon> <DependentUpon>Reference.svcmap</DependentUpon>
</Compile> </Compile>
<Compile Include="SheetDisplayControls\CrewPreArrivalControl.xaml.cs">
<DependentUpon>CrewPreArrivalControl.xaml</DependentUpon>
</Compile>
<Compile Include="SheetDisplayControls\PortControl.xaml.cs"> <Compile Include="SheetDisplayControls\PortControl.xaml.cs">
<DependentUpon>PortControl.xaml</DependentUpon> <DependentUpon>PortControl.xaml</DependentUpon>
</Compile> </Compile>
@ -817,6 +820,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon> <DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Page Include="SheetDisplayControls\CrewPreArrivalControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SheetDisplayControls\PortControl.xaml"> <Page Include="SheetDisplayControls\PortControl.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
@ -969,6 +976,10 @@
<Resource Include="Resources\exit.png" /> <Resource Include="Resources\exit.png" />
<Resource Include="Resources\document_exchange.png" /> <Resource Include="Resources\document_exchange.png" />
<Resource Include="ILLink\ILLink.Descriptors.LibraryBuild.xml" /> <Resource Include="ILLink\ILLink.Descriptors.LibraryBuild.xml" />
<Resource Include="Resources\arrival_user.png" />
<Resource Include="Resources\arrival_worker.png" />
<Resource Include="Resources\departure_user.png" />
<Resource Include="Resources\departure_worker.png" />
<Content Include="x64\SQLite.Interop.dll"> <Content Include="x64\SQLite.Interop.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>

View File

@ -1181,6 +1181,15 @@ namespace ENI2.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to 6. Crew data on arrival.
/// </summary>
public static string text6CrewDataOnArrival {
get {
return ResourceManager.GetString("text6CrewDataOnArrival", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to About ENI-2. /// Looks up a localized string similar to About ENI-2.
/// </summary> /// </summary>
@ -6019,5 +6028,45 @@ namespace ENI2.Properties {
return ((System.Drawing.Bitmap)(obj)); return ((System.Drawing.Bitmap)(obj));
} }
} }
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
public static System.Drawing.Bitmap arrival_user {
get {
object obj = ResourceManager.GetObject("arrival_user", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
public static System.Drawing.Bitmap arrival_worker {
get {
object obj = ResourceManager.GetObject("arrival_worker", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
public static System.Drawing.Bitmap departure_user {
get {
object obj = ResourceManager.GetObject("departure_user", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
public static System.Drawing.Bitmap departure_worker {
get {
object obj = ResourceManager.GetObject("departure_worker", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
} }
} }

View File

@ -586,6 +586,18 @@
<data name="user_edit" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="user_edit" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\user_edit.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\user_edit.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="arrival_user" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\arrival_user.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="arrival_worker" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\arrival_worker.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="departure_user" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\departure_user.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="departure_worker" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\departure_worker.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="textSave" xml:space="preserve"> <data name="textSave" xml:space="preserve">
<value>Save</value> <value>Save</value>
</data> </data>
@ -2077,4 +2089,7 @@
<data name="textShipEmail" xml:space="preserve"> <data name="textShipEmail" xml:space="preserve">
<value>Ship e-mail</value> <value>Ship e-mail</value>
</data> </data>
<data name="text6CrewDataOnArrival" xml:space="preserve">
<value>6. Crew data on arrival</value>
</data>
</root> </root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -0,0 +1,66 @@
<src:DetailBaseControl xmlns:src="clr-namespace:ENI2"
x:Class="ENI2.SheetDisplayControls.CrewPreArrivalControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:p="clr-namespace:ENI2.Properties"
xmlns:enictrl="clr-namespace:ENI2.Controls"
xmlns:util="clr-namespace:ENI2.Util"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:local="clr-namespace:ENI2.SheetDisplayControls"
mc:Ignorable="d"
d:DesignHeight="1450" d:DesignWidth="800">
<GroupBox Name="portCallGroupBox" Header="{x:Static p:Resources.text6CrewDataOnArrival}">
<ScrollViewer PreviewMouseWheel="ScrollViewer_PreviewMouseWheel">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".35*"/>
<ColumnDefinition Width=".65*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="36" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="8" />
<RowDefinition Height="28" />
<RowDefinition Height="480" />
</Grid.RowDefinitions>
<Label HorizontalContentAlignment="Right" Grid.Row="0" Grid.Column="0" Content="{x:Static p:Resources.textNameMaster}" Name="label_nameMaster" Margin="0,0,10,0"/>
<TextBox Grid.Row="0" Grid.Column="1" Name="textBox_NameMaster" MaxLength="100" Margin="2" Text="{Binding NameOfMaster, Converter={util:TrimStringConverter}}" VerticalContentAlignment="Center" />
<Label Name="labelCrewNotificationSchengen" Content="{x:Static p:Resources.textNotificationSchengen}" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right"/>
<CheckBox Name="checkBoxCrewNotificationSchengen" Grid.Row="1" Grid.Column="1" IsThreeState="False" VerticalAlignment="Center" Margin="10,0,0,0" Click="checkBoxCrewNotificationSchengen_Click"/>
<Label Name="labelCrewNotificationPAX" Content="{x:Static p:Resources.textNotificationPAX}" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" />
<CheckBox Name="checkBoxCrewNotificationPAX" IsThreeState="False" VerticalAlignment="Center" Margin="10,0,0,0" Click="checkBoxCrewNotificationPAX_Click" Grid.Row="2" Grid.Column="1"/>
<Button Name="buttonImportExcelCrew" Grid.Row="4" Content="{x:Static p:Resources.textImportFromExcel}" Margin="2,2,10,2" Width="120" HorizontalAlignment="Right" VerticalAlignment="Center" Background="Transparent" Click="buttonImportExcelCrew_Click" />
<StackPanel Grid.Row="4" Grid.Column="1" Orientation="Horizontal">
<TextBlock Margin="20, 0, 0, 0" Name="textBlockNumCrewEntries" FontWeight="Bold" Text="{Binding Elements.Count}" VerticalAlignment="Center"/>
<Label Name="labelCrewEntryCount" Content="{x:Static p:Resources.textEntries}" />
<Button Name="buttonDeleteAllCrewA" Margin="2" Content="{x:Static p:Resources.textDeleteAllEntries}" Background="Transparent" Click="buttonDeleteAllCrewA_Click"/>
</StackPanel>
<enictrl:ENIDataGrid Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" x:Name="dataGridCrewList" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
AutoGenerateColumns="False" Margin="0,5,0,0">
<DataGrid.Columns>
<DataGridTextColumn Header="" Binding="{Binding Identifier}" IsReadOnly="True" />
<DataGridTextColumn Header="{x:Static p:Resources.textLastName}" Binding="{Binding CrewMemberLastName, Mode=TwoWay}" IsReadOnly="True" Width="0.1*" />
<DataGridTextColumn Header="{x:Static p:Resources.textFirstName}" Binding="{Binding CrewMemberFirstName, Mode=TwoWay}" IsReadOnly="True" Width="0.1*" />
<DataGridTextColumn Header="{x:Static p:Resources.textGender}" Binding="{Binding CrewMemberGenderDisplay}" IsReadOnly="True" Width="0.1*" />
<DataGridTextColumn Header="{x:Static p:Resources.textCrewFunctionOnBoard}" Binding="{Binding CrewMemberDuty, Mode=TwoWay}" IsReadOnly="True" Width="0.1*" />
<DataGridTextColumn Header="{x:Static p:Resources.textNationality}" Binding="{Binding CrewMemberNationality, Mode=TwoWay}" IsReadOnly="True" Width="0.1*" />
<DataGridTextColumn Header="{x:Static p:Resources.textPlaceOfBirth}" Binding="{Binding CrewMemberPlaceOfBirth, Mode=TwoWay}" IsReadOnly="True" Width="0.1*" />
<DataGridTextColumn Header="{x:Static p:Resources.textCountryOfBirth}" Binding="{Binding CrewMemberCountryOfBirth, Mode=TwoWay}" IsReadOnly="True" Width="0.1*" />
<DataGridTextColumn Header="{x:Static p:Resources.textDateOfBirth}" Binding="{Binding CrewMemberDateOfBirth, Mode=TwoWay, StringFormat=\{0:dd.MM.yyyy\}}" IsReadOnly="True" Width="0.1*" />
<DataGridTextColumn Header="{x:Static p:Resources.textIdDocType}" Binding="{Binding CrewMemberIdentityDocumentTypeDisplay}" IsReadOnly="True" Width="0.1*" />
<DataGridTextColumn Header="{x:Static p:Resources.textIdDocNumber}" Binding="{Binding CrewMemberIdentityDocumentId, Mode=TwoWay}" IsReadOnly="True" Width="0.1*" />
<DataGridTextColumn Header="{x:Static p:Resources.textDocumentIssuingState}" Binding="{Binding CrewMemberIdentityDocumentIssuingState, Mode=TwoWay}" IsReadOnly="True" Width="0.1*" />
<DataGridTextColumn Header="{x:Static p:Resources.textDocumentExpiryDate}" Binding="{Binding CrewMemberIdentityDocumentExpiryDate, Mode=TwoWay, StringFormat=\{0:dd.MM.yyyy\}}" IsReadOnly="True" Width="0.1*" />
<DataGridTextColumn Header="{x:Static p:Resources.textVisaNumber}" Binding="{Binding CrewMemberVisaNumber, Mode=TwoWay}" IsReadOnly="True" Width="0.1*" />
<!--<DataGridTextColumn Header="{x:Static p:Resources.textEffects}" Binding="{Binding Effects, Mode=TwoWay}" IsReadOnly="True" Width="0.1*" />-->
</DataGrid.Columns>
</enictrl:ENIDataGrid>
</Grid>
</ScrollViewer>
</GroupBox>
</src:DetailBaseControl>

View File

@ -0,0 +1,389 @@
// Copyright (c) 2025 - schick Informatik
// Description: Display control of formsheet Tab 6. Crew data arrival
//
using bsmd.database;
using ENI2.EditControls;
using ENI2.Util;
using ExcelDataReader;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace ENI2.SheetDisplayControls
{
/// <summary>
/// Interaction logic for CrewPreArrivalControl.xaml
/// </summary>
public partial class CrewPreArrivalControl : DetailBaseControl
{
#region Fields
private NAME _name;
private Message _crewaMessage;
private Message _crewdMessage;
#endregion
#region Construction
public CrewPreArrivalControl()
{
InitializeComponent();
this.Loaded += CrewPreArrivalControl_Loaded;
}
#endregion
#region public override
public override void Initialize()
{
base.Initialize();
foreach (Message aMessage in this.Messages)
{
if (aMessage.MessageNotificationClass == Message.NotificationClass.NAME) { this._name = aMessage.Elements[0] as NAME; this.ControlMessages.Add(aMessage); }
if (aMessage.MessageNotificationClass == Message.NotificationClass.CREWA) { this._crewaMessage = aMessage; this.ControlMessages.Add(aMessage); }
if (aMessage.MessageNotificationClass == Message.NotificationClass.CREWD) { this._crewdMessage = aMessage; this.ControlMessages.Add(aMessage); }
}
this.textBox_NameMaster.DataContext = _name;
#region init CREWA
if (this._crewaMessage == null)
{
this._crewaMessage = this.Core.CreateMessage(Message.NotificationClass.CREWA);
this.Messages.Add(this._crewaMessage);
}
this.dataGridCrewList.Initialize();
this.dataGridCrewList.ItemsSource = this._crewaMessage.Elements;
this.dataGridCrewList.AddingNewItem += DataGridCrewList_AddingNewItem;
this.dataGridCrewList.EditRequested += DataGridCrewList_EditRequested;
this.dataGridCrewList.DeleteRequested += DataGridCrewList_DeleteRequested;
this.dataGridCrewList.CreateRequested += DataGridCrewList_CreateRequested;
this.dataGridCrewList.RefreshGrid += DataGridCrewList_RefreshGrid;
this.dataGridCrewList.MultiEditRequested += DataGridCrewList_MultiEditRequested;
if (this._crewaMessage.Elements.Count > 0)
{
this.checkBoxCrewNotificationSchengen.IsChecked = ((CREW)this._crewaMessage.Elements[0]).NotificationSchengen;
this.checkBoxCrewNotificationPAX.IsChecked = ((CREW)this._crewaMessage.Elements[0]).NotificationPAX;
}
// extra menu copy to CREWD
{
this.dataGridCrewList.ContextMenu.Items.Add(new Separator());
MenuItem copyCREWAItem = new MenuItem();
copyCREWAItem.Header = Properties.Resources.textCopyToCREWD;
copyCREWAItem.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/documents.png")) };
copyCREWAItem.Click += CopyCREWAItem_Click;
this.dataGridCrewList.ContextMenu.Items.Add(copyCREWAItem);
}
#endregion
}
#endregion
#region event handler
private void CopyCREWAItem_Click(object sender, RoutedEventArgs e)
{
if (this.dataGridCrewList.SelectedItems != null)
{
foreach (CREW crewa in this.dataGridCrewList.SelectedItems)
{
CREWD crewd = new CREWD();
crewd.MessageHeader = this._crewdMessage;
crewd.CopyFromCREW(crewa);
crewd.IsDeparture = true;
crewd.Identifier = DatabaseEntity.GetNewIdentifier(this._crewdMessage.Elements);
this._crewdMessage.Elements.Add(crewd);
this.SublistElementChanged(Message.NotificationClass.CREWD);
}
}
}
private void CrewPreArrivalControl_Loaded(object sender, RoutedEventArgs e)
{
this.RegisterTextboxChange(this.textBox_NameMaster, Message.NotificationClass.NAME);
}
private async void buttonDeleteAllCrewA_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show(Properties.Resources.textConfimDeleteAllEntries, Properties.Resources.textConfirmation, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
{
foreach (CREW crewa in this._crewaMessage.Elements.Cast<CREW>())
{
await DBManagerAsync.DeleteAsync(crewa);
}
this._crewaMessage.Elements.Clear();
this.dataGridCrewList.Items.Refresh();
this.SublistElementChanged(Message.NotificationClass.CREWA);
}
}
private void checkBoxCrewNotificationSchengen_Click(object sender, RoutedEventArgs e)
{
foreach (CREW crew in _crewaMessage.Elements.Cast<CREW>())
{
crew.NotificationSchengen = checkBoxCrewNotificationSchengen.IsChecked;
}
this.SublistElementChanged(Message.NotificationClass.CREWA);
}
private void checkBoxCrewNotificationPAX_Click(object sender, RoutedEventArgs e)
{
foreach (CREW crew in _crewaMessage.Elements.Cast<CREW>())
{
crew.NotificationPAX = checkBoxCrewNotificationPAX.IsChecked;
}
this.SublistElementChanged(Message.NotificationClass.CREWA);
}
private void buttonImportExcelCrew_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog
{
Filter = "Excel Files|*.xls;*.xlsx"
};
if (ofd.ShowDialog() ?? false)
{
FileStream stream;
try
{
stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
using (IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream))
{
List<CREW> importCrew = new List<CREW>();
try
{
do
{
while (reader.Read())
{
if (reader.FieldCount < 13)
{
throw new InvalidDataException("Sheet must have 13 columns of data");
}
CREW crew = new CREW();
if (reader.IsDBNull(0) && reader.IsDBNull(1)) continue;
if (!reader.IsDBNull(0)) crew.CrewMemberLastName = reader.GetString(0).Clean();
if (crew.CrewMemberLastName.Equals("Family Name") || (crew.CrewMemberLastName.Trim().Length == 0)) continue;
if (!reader.IsDBNull(1)) crew.CrewMemberFirstName = reader.GetString(1).Clean();
if (!reader.IsDBNull(2)) crew.CrewMemberGender = GlobalStructures.ParseGender(reader.GetString(2));
if (!reader.IsDBNull(3)) crew.CrewMemberDuty = reader.GetString(3).Clean();
if (!reader.IsDBNull(4)) crew.CrewMemberNationality = reader.GetString(4).Substring(0, 2).ToUpper();
if (!reader.IsDBNull(5)) crew.CrewMemberPlaceOfBirth = reader.GetString(5).Clean();
if (!reader.IsDBNull(6)) crew.CrewMemberCountryOfBirth = reader.GetString(6).Substring(0, 2).ToUpper();
if (!reader.IsDBNull(7)) crew.CrewMemberDateOfBirth = reader.GetDateTime(7);
if (!reader.IsDBNull(8)) crew.CrewMemberIdentityDocumentType = GlobalStructures.ReadIdentityDocumentType(reader.GetString(8));
if (!reader.IsDBNull(9)) crew.CrewMemberIdentityDocumentId = this.getValueAsString(reader, 9).Clean();
if (!reader.IsDBNull(10)) crew.CrewMemberIdentityDocumentIssuingState = reader.GetString(10).Substring(0, 2).ToUpper();
if (!reader.IsDBNull(11)) crew.CrewMemberIdentityDocumentExpiryDate = reader.GetDateTime(11);
if (!reader.IsDBNull(12)) crew.CrewMemberVisaNumber = this.getValueAsString(reader, 12).Clean();
crew.MessageHeader = this._crewaMessage;
crew.IsDirty = true;
crew.Identifier = CREW.GetNewIdentifier(this._crewaMessage.Elements);
this._crewaMessage.Elements.Add(crew);
importCrew.Add(crew);
}
} while (reader.NextResult());
}
catch (Exception ex)
{
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
}
if (importCrew.Count > 0)
{
this.dataGridCrewList.Items.Refresh();
this.SublistElementChanged(Message.NotificationClass.CREWA);
MessageBox.Show(String.Format(Properties.Resources.textCrewImported, importCrew.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information);
}
}
stream.Close();
}
}
#endregion
#region crew grid arrival
private void DataGridCrewList_CreateRequested()
{
EditCREWDialog ecd = new EditCREWDialog
{
CREW = new CREW()
};
ecd.CREW.Identifier = CREW.GetNewIdentifier(_crewaMessage.Elements);
ecd.CREW.MessageHeader = this._crewaMessage;
ecd.AddClicked += () =>
{
ecd.CopyValuesToEntity();
if (!this._crewaMessage.Elements.Contains(ecd.CREW))
{
this._crewaMessage.Elements.Add(ecd.CREW);
this.CheckCREWA();
}
this.dataGridCrewList.Items.Refresh();
ecd.CREW = new CREW
{
MessageHeader = this._crewaMessage,
Identifier = CREW.GetNewIdentifier(_crewaMessage.Elements)
};
this.SublistElementChanged(Message.NotificationClass.CREWA);
};
if (ecd.ShowDialog() ?? false)
{
if (!this._crewaMessage.Elements.Contains(ecd.CREW))
{
_crewaMessage.Elements.Add(ecd.CREW);
this.CheckCREWA();
}
this.dataGridCrewList.Items.Refresh();
this.SublistElementChanged(Message.NotificationClass.CREWA);
}
}
private void DataGridCrewList_DeleteRequested(DatabaseEntity obj)
{
if (obj is CREW crew)
{
// are you sure dialog is in base class
_crewaMessage.Elements.Remove(crew);
DBManager.Instance.Delete(crew);
}
}
private void DataGridCrewList_RefreshGrid()
{
DatabaseEntity.ResetIdentifiers(_crewaMessage.Elements);
this.SublistElementChanged(Message.NotificationClass.CREWA);
this.dataGridCrewList.Items.Refresh();
}
private void DataGridCrewList_EditRequested(DatabaseEntity obj)
{
EditCREWDialog ecd = new EditCREWDialog
{
CREW = obj as CREW
};
ecd.AddClicked += () =>
{
ecd.CopyValuesToEntity();
if (!_crewaMessage.Elements.Contains(ecd.CREW))
{
_crewaMessage.Elements.Add(ecd.CREW);
this.CheckCREWA();
}
this.dataGridCrewList.Items.Refresh();
ecd.CREW = new CREW
{
Identifier = CREW.GetNewIdentifier(_crewaMessage.Elements),
MessageHeader = _crewaMessage
};
this.SublistElementChanged(Message.NotificationClass.CREWA);
};
if (ecd.ShowDialog() ?? false)
{
if (!_crewaMessage.Elements.Contains(ecd.CREW))
{
_crewaMessage.Elements.Add(ecd.CREW);
this.CheckCREWA();
}
ecd.CREW.IsDirty = true;
this.dataGridCrewList.Items.Refresh();
this.SublistElementChanged(Message.NotificationClass.CREWA);
}
}
private void DataGridCrewList_AddingNewItem(object sender, AddingNewItemEventArgs e)
{
this.DataGridCrewList_CreateRequested();
}
private void DataGridCrewList_MultiEditRequested(List<DatabaseEntity> databaseEntities)
{
List<CREW> crewList = new List<CREW>();
foreach (CREW acrew in databaseEntities.Cast<CREW>())
crewList.Add(acrew);
// write common values of all CREW entities to template entity
CREW crew = CREW.CreateCommon(crewList);
EditCREWDialog dialog = new EditCREWDialog();
dialog.CREW = crew;
dialog.AddVisible = false;
if (dialog.ShowDialog() ?? false)
{
// write back changed values from crew to all entities and mark them as changed
CREW.WriteTemplateToList(crew, crewList);
this.SublistElementChanged(Message.NotificationClass.CREWA);
this.dataGridCrewList.Items.Refresh();
}
}
#endregion
#region private methods
private string getValueAsString(IExcelDataReader reader, int index)
{
Type fieldType = reader.GetFieldType(index);
if (fieldType == null) return null;
if (fieldType == typeof(double))
return reader.GetDouble(index).ToString();
if (fieldType == typeof(int))
return reader.GetInt32(index).ToString();
return reader.GetString(index);
}
private void CheckCREWA()
{
if (this._crewaMessage.Elements.Count == 0) return;
CREW firstCREW = this._crewaMessage.Elements[0] as CREW;
if (this._crewaMessage.Elements.Count == 1)
{
firstCREW.NotificationSchengen = true;
this.checkBoxCrewNotificationSchengen.IsChecked = true;
}
else
{
for (int i = 1; i < this._crewaMessage.Elements.Count; i++)
{
((CREW)this._crewaMessage.Elements[i]).NotificationSchengen = firstCREW.NotificationSchengen;
}
}
}
#endregion
}
}