Added ref to ClosedXML lib and replaced usage of ExcelDataReader in PAS/CREW manual import
This commit is contained in:
parent
7a002abf63
commit
dbf15539d9
@ -123,6 +123,10 @@
|
||||
<assemblyIdentity name="System.Security.Cryptography.Pkcs" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-9.0.0.9" newVersion="9.0.0.9" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.6.0" newVersion="4.1.6.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
|
||||
@ -11,7 +11,7 @@ using System.Windows.Controls;
|
||||
using ENI2.EditControls;
|
||||
using ENI2.Util;
|
||||
using ENI2.Locode;
|
||||
using ExcelDataReader;
|
||||
using ClosedXML.Excel;
|
||||
using bsmd.database;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Linq;
|
||||
@ -1049,72 +1049,67 @@ namespace ENI2.DetailViewControls
|
||||
};
|
||||
if (ofd.ShowDialog() ?? false)
|
||||
{
|
||||
FileStream stream;
|
||||
try
|
||||
{
|
||||
stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);
|
||||
using (var workbook = new XLWorkbook(ofd.FileName))
|
||||
{
|
||||
var worksheet = workbook.Worksheet(1); // Get first worksheet
|
||||
var rows = worksheet.RangeUsed().RowsUsed().Skip(1); // Skip header row if present
|
||||
|
||||
List<CREW> importCrew = new List<CREW>();
|
||||
|
||||
foreach (var row in rows)
|
||||
{
|
||||
if (row.RowNumber() > worksheet.RangeUsed().RowCount()) break;
|
||||
|
||||
// Check if we have at least 13 columns
|
||||
if (worksheet.RangeUsed().ColumnCount() < 13)
|
||||
{
|
||||
throw new InvalidDataException("Sheet must have 13 columns of data");
|
||||
}
|
||||
|
||||
CREW crew = new CREW();
|
||||
|
||||
// Check if first two cells are empty
|
||||
if (row.Cell(1).IsEmpty() && row.Cell(2).IsEmpty()) continue;
|
||||
|
||||
if (!row.Cell(1).IsEmpty()) crew.CrewMemberLastName = row.Cell(1).GetString().Clean();
|
||||
if (crew.CrewMemberLastName?.Equals("Family Name") == true || string.IsNullOrWhiteSpace(crew.CrewMemberLastName)) continue;
|
||||
|
||||
if (!row.Cell(2).IsEmpty()) crew.CrewMemberFirstName = row.Cell(2).GetString().Clean();
|
||||
if (!row.Cell(3).IsEmpty()) crew.CrewMemberGender = GlobalStructures.ParseGender(row.Cell(3).GetString());
|
||||
if (!row.Cell(4).IsEmpty()) crew.CrewMemberDuty = row.Cell(4).GetString().Clean();
|
||||
if (!row.Cell(5).IsEmpty()) crew.CrewMemberNationality = row.Cell(5).GetString().Substring(0, 2).ToUpper();
|
||||
if (!row.Cell(6).IsEmpty()) crew.CrewMemberPlaceOfBirth = row.Cell(6).GetString().Clean();
|
||||
if (!row.Cell(7).IsEmpty()) crew.CrewMemberCountryOfBirth = row.Cell(7).GetString().Substring(0, 2).ToUpper();
|
||||
if (!row.Cell(8).IsEmpty()) crew.CrewMemberDateOfBirth = row.Cell(8).GetDateTime();
|
||||
if (!row.Cell(9).IsEmpty()) crew.CrewMemberIdentityDocumentType = GlobalStructures.ReadIdentityDocumentType(row.Cell(9).GetString());
|
||||
if (!row.Cell(10).IsEmpty()) crew.CrewMemberIdentityDocumentId = row.Cell(10).GetString().Clean();
|
||||
if (!row.Cell(11).IsEmpty()) crew.CrewMemberIdentityDocumentIssuingState = row.Cell(11).GetString().Substring(0, 2).ToUpper();
|
||||
if (!row.Cell(12).IsEmpty()) crew.CrewMemberIdentityDocumentExpiryDate = row.Cell(12).GetDateTime();
|
||||
if (!row.Cell(13).IsEmpty()) crew.CrewMemberVisaNumber = row.Cell(13).GetString().Clean();
|
||||
|
||||
crew.MessageHeader = this._crewMessage;
|
||||
crew.IsDirty = true;
|
||||
crew.Identifier = CREW.GetNewIdentifier(this._crewMessage.Elements);
|
||||
this._crewMessage.Elements.Add(crew);
|
||||
importCrew.Add(crew);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
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 = reader.ReadAsString(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 = reader.ReadAsString(12).Clean();
|
||||
|
||||
crew.MessageHeader = this._crewMessage;
|
||||
crew.IsDirty = true;
|
||||
crew.Identifier = CREW.GetNewIdentifier(this._crewMessage.Elements);
|
||||
this._crewMessage.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonImportExcelCrewDeparture_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
@ -1124,74 +1119,68 @@ namespace ENI2.DetailViewControls
|
||||
};
|
||||
if (ofd.ShowDialog() ?? false)
|
||||
{
|
||||
FileStream stream;
|
||||
try
|
||||
{
|
||||
stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);
|
||||
using (var workbook = new XLWorkbook(ofd.FileName))
|
||||
{
|
||||
var worksheet = workbook.Worksheet(1); // Get first worksheet
|
||||
var rows = worksheet.RangeUsed().RowsUsed().Skip(1); // Skip header row if present
|
||||
|
||||
List<CREWD> importCrew = new List<CREWD>();
|
||||
|
||||
foreach (var row in rows)
|
||||
{
|
||||
if (row.RowNumber() > worksheet.RangeUsed().RowCount()) break;
|
||||
|
||||
// Check if we have at least 13 columns
|
||||
if (worksheet.RangeUsed().ColumnCount() < 13)
|
||||
{
|
||||
throw new InvalidDataException("Sheet must have 13 columns of data");
|
||||
}
|
||||
|
||||
CREWD crew = new CREWD();
|
||||
crew.IsDeparture = true;
|
||||
|
||||
// Check if first two cells are empty
|
||||
if (row.Cell(1).IsEmpty() && row.Cell(2).IsEmpty()) continue;
|
||||
|
||||
if (!row.Cell(1).IsEmpty()) crew.CrewMemberLastName = row.Cell(1).GetString().Clean();
|
||||
if (crew.CrewMemberLastName?.Equals("Family Name") == true || string.IsNullOrWhiteSpace(crew.CrewMemberLastName)) continue;
|
||||
|
||||
if (!row.Cell(2).IsEmpty()) crew.CrewMemberFirstName = row.Cell(2).GetString().Clean();
|
||||
if (!row.Cell(3).IsEmpty()) crew.CrewMemberGender = GlobalStructures.ParseGender(row.Cell(3).GetString());
|
||||
if (!row.Cell(4).IsEmpty()) crew.CrewMemberDuty = row.Cell(4).GetString().Clean();
|
||||
if (!row.Cell(5).IsEmpty()) crew.CrewMemberNationality = row.Cell(5).GetString().Substring(0, 2).ToUpper();
|
||||
if (!row.Cell(6).IsEmpty()) crew.CrewMemberPlaceOfBirth = row.Cell(6).GetString().Clean();
|
||||
if (!row.Cell(7).IsEmpty()) crew.CrewMemberCountryOfBirth = row.Cell(7).GetString().Substring(0, 2).ToUpper();
|
||||
if (!row.Cell(8).IsEmpty()) crew.CrewMemberDateOfBirth = row.Cell(8).GetDateTime();
|
||||
if (!row.Cell(9).IsEmpty()) crew.CrewMemberIdentityDocumentType = GlobalStructures.ReadIdentityDocumentType(row.Cell(9).GetString());
|
||||
if (!row.Cell(10).IsEmpty()) crew.CrewMemberIdentityDocumentId = row.Cell(10).GetString().Clean();
|
||||
if (!row.Cell(11).IsEmpty()) crew.CrewMemberIdentityDocumentIssuingState = row.Cell(11).GetString().Substring(0, 2).ToUpper();
|
||||
if (!row.Cell(12).IsEmpty()) crew.CrewMemberIdentityDocumentExpiryDate = row.Cell(12).GetDateTime();
|
||||
if (!row.Cell(13).IsEmpty()) crew.CrewMemberVisaNumber = row.Cell(13).GetString().Clean();
|
||||
|
||||
crew.MessageHeader = this._crewdMessage;
|
||||
crew.IsDirty = true;
|
||||
crew.Identifier = CREWD.GetNewIdentifier(this._crewdMessage.Elements);
|
||||
this._crewdMessage.Elements.Add(crew);
|
||||
importCrew.Add(crew);
|
||||
}
|
||||
|
||||
if (importCrew.Count > 0)
|
||||
{
|
||||
this.dataGridCrewListDeparture.Items.Refresh();
|
||||
this.SublistElementChanged(Message.NotificationClass.CREWD);
|
||||
MessageBox.Show(String.Format(Properties.Resources.textCrewImported, importCrew.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
using (IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream))
|
||||
{
|
||||
List<CREWD> importCrew = new List<CREWD>();
|
||||
|
||||
try
|
||||
{
|
||||
do
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader.FieldCount < 13)
|
||||
{
|
||||
throw new InvalidDataException("Sheet must have 13 columns of data");
|
||||
}
|
||||
CREWD crew = new CREWD();
|
||||
crew.IsDeparture = true;
|
||||
|
||||
if (reader.IsDBNull(0) && reader.IsDBNull(1)) continue;
|
||||
if (!reader.IsDBNull(0)) crew.CrewMemberLastName = reader.GetString(0);
|
||||
if (crew.CrewMemberLastName.Equals("Family Name") || (crew.CrewMemberLastName.Trim().Length == 0)) continue;
|
||||
if (!reader.IsDBNull(1)) crew.CrewMemberFirstName = reader.GetString(1);
|
||||
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);
|
||||
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 = reader.ReadAsString(9);
|
||||
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 = reader.ReadAsString(12);
|
||||
|
||||
crew.MessageHeader = this._crewdMessage;
|
||||
crew.IsDirty = true;
|
||||
crew.Identifier = CREWD.GetNewIdentifier(this._crewdMessage.Elements);
|
||||
this._crewdMessage.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.dataGridCrewListDeparture.Items.Refresh();
|
||||
this.SublistElementChanged(Message.NotificationClass.CREWD);
|
||||
MessageBox.Show(String.Format(Properties.Resources.textCrewImported, importCrew.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
|
||||
stream.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonImportExcelPassenger_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
@ -1201,80 +1190,73 @@ namespace ENI2.DetailViewControls
|
||||
};
|
||||
if (ofd.ShowDialog() ?? false)
|
||||
{
|
||||
FileStream stream;
|
||||
try
|
||||
{
|
||||
stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);
|
||||
using (var workbook = new XLWorkbook(ofd.FileName))
|
||||
{
|
||||
var worksheet = workbook.Worksheet(1);
|
||||
var rows = worksheet.RangeUsed().RowsUsed().Skip(1); // Skip header row if present
|
||||
|
||||
List<PAS> importPassenger = new List<PAS>();
|
||||
|
||||
foreach (var row in rows)
|
||||
{
|
||||
if (row.RowNumber() > worksheet.RangeUsed().RowCount()) break;
|
||||
|
||||
if (worksheet.RangeUsed().ColumnCount() < 17)
|
||||
{
|
||||
throw new InvalidDataException("Sheet must have 17 columns of data");
|
||||
}
|
||||
|
||||
PAS pas = new PAS();
|
||||
|
||||
if (row.Cell(1).IsEmpty() && row.Cell(2).IsEmpty()) continue;
|
||||
|
||||
if (!row.Cell(1).IsEmpty()) pas.PassengerLastName = row.Cell(1).GetString().Clean();
|
||||
if (pas.PassengerLastName?.Equals("Family Name") == true || string.IsNullOrWhiteSpace(pas.PassengerLastName)) continue;
|
||||
|
||||
if (!row.Cell(2).IsEmpty()) pas.PassengerFirstName = row.Cell(2).GetString().Clean();
|
||||
if (!row.Cell(3).IsEmpty()) pas.PassengerGender = GlobalStructures.ParseGender(row.Cell(3).GetString());
|
||||
if (!row.Cell(4).IsEmpty()) pas.PassengerPortOfEmbarkation = row.Cell(4).GetString().Clean();
|
||||
if (LocodeDB.PortNameFromLocode(pas.PassengerPortOfEmbarkation) == null)
|
||||
pas.PassengerPortOfEmbarkation = null;
|
||||
if (!row.Cell(5).IsEmpty()) pas.PassengerPortOfDisembarkation = row.Cell(5).GetString().Clean();
|
||||
if (LocodeDB.PortNameFromLocode(pas.PassengerPortOfDisembarkation) == null)
|
||||
pas.PassengerPortOfDisembarkation = null;
|
||||
if (!row.Cell(6).IsEmpty()) pas.PassengerInTransit = GlobalStructures.ReadBoolean(row.Cell(6).GetString());
|
||||
if (!row.Cell(7).IsEmpty()) pas.PassengerNationality = row.Cell(7).GetString().Substring(0, 2).ToUpper();
|
||||
if (!row.Cell(8).IsEmpty()) pas.PassengerPlaceOfBirth = row.Cell(8).GetString().Clean();
|
||||
if (!row.Cell(9).IsEmpty()) pas.PassengerCountryOfBirth = row.Cell(9).GetString().Substring(0, 2).ToUpper().Clean();
|
||||
if (!row.Cell(10).IsEmpty()) pas.PassengerDateOfBirth = row.Cell(10).GetDateTime();
|
||||
if (!row.Cell(11).IsEmpty()) pas.PassengerIdentityDocumentType = GlobalStructures.ReadIdentityDocumentType(row.Cell(11).GetString());
|
||||
if (!row.Cell(12).IsEmpty()) pas.PassengerIdentityDocumentId = row.Cell(12).GetString().Clean();
|
||||
if (!row.Cell(13).IsEmpty()) pas.PassengerIdentityDocumentIssuingState = row.Cell(13).GetString().Substring(0, 2).ToUpper();
|
||||
if (!row.Cell(14).IsEmpty()) pas.PassengerIdentityDocumentExpiryDate = row.Cell(14).GetDateTime();
|
||||
if (!row.Cell(15).IsEmpty()) pas.PassengerVisaNumber = row.Cell(15).GetString().Clean();
|
||||
if (!row.Cell(16).IsEmpty()) pas.EmergencyCare = row.Cell(16).GetString().Clean();
|
||||
if (!row.Cell(17).IsEmpty()) pas.EmergencyContactNumber = row.Cell(17).GetString().Clean();
|
||||
|
||||
pas.MessageHeader = this._pasMessage;
|
||||
pas.IsDirty = true;
|
||||
pas.Identifier = PAS.GetNewIdentifier(this._pasMessage.Elements);
|
||||
this._pasMessage.Elements.Add(pas);
|
||||
importPassenger.Add(pas);
|
||||
}
|
||||
|
||||
if (importPassenger.Count > 0)
|
||||
{
|
||||
this.dataGridPassengerList.Items.Refresh();
|
||||
this.SublistElementChanged(Message.NotificationClass.PASA);
|
||||
MessageBox.Show(String.Format(Properties.Resources.textPassengerImported, importPassenger.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
using (var reader = ExcelReaderFactory.CreateReader(stream))
|
||||
{
|
||||
List<PAS> importPassenger = new List<PAS>();
|
||||
|
||||
try
|
||||
{
|
||||
do
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (((IExcelDataReader)reader).FieldCount < 17)
|
||||
{
|
||||
throw new InvalidDataException("Sheet must have 17 columns of data");
|
||||
}
|
||||
|
||||
PAS pas = new PAS();
|
||||
if (reader.IsDBNull(0) && reader.IsDBNull(1)) continue;
|
||||
if (!reader.IsDBNull(0)) pas.PassengerLastName = reader.GetValue(0).ToString().Clean();
|
||||
if (pas.PassengerLastName.Equals("Family Name") || (pas.PassengerLastName.Trim().Length == 0)) continue;
|
||||
if (!reader.IsDBNull(1)) pas.PassengerFirstName = reader.GetValue(1).ToString().Clean();
|
||||
if (!reader.IsDBNull(2)) pas.PassengerGender = GlobalStructures.ParseGender(reader.GetString(2));
|
||||
if (!reader.IsDBNull(3)) pas.PassengerPortOfEmbarkation = reader.GetString(3).Clean();
|
||||
if (LocodeDB.PortNameFromLocode(pas.PassengerPortOfEmbarkation) == null)
|
||||
pas.PassengerPortOfEmbarkation = null;
|
||||
if (!reader.IsDBNull(4)) pas.PassengerPortOfDisembarkation = reader.GetString(4).Clean();
|
||||
if (LocodeDB.PortNameFromLocode(pas.PassengerPortOfDisembarkation) == null)
|
||||
pas.PassengerPortOfDisembarkation = null;
|
||||
if (!reader.IsDBNull(5)) pas.PassengerInTransit = GlobalStructures.ReadBoolean(reader.GetString(5));
|
||||
if (!reader.IsDBNull(6)) pas.PassengerNationality = reader.GetString(6).Substring(0, 2).ToUpper();
|
||||
if (!reader.IsDBNull(7)) pas.PassengerPlaceOfBirth = reader.GetString(7).Clean();
|
||||
if (!reader.IsDBNull(8)) pas.PassengerCountryOfBirth = reader.GetString(8).Substring(0, 2).ToUpper().Clean();
|
||||
if (!reader.IsDBNull(9)) pas.PassengerDateOfBirth = reader.GetDateTime(9);
|
||||
if (!reader.IsDBNull(10)) pas.PassengerIdentityDocumentType = GlobalStructures.ReadIdentityDocumentType(reader.GetString(10));
|
||||
if (!reader.IsDBNull(11)) pas.PassengerIdentityDocumentId = reader.ReadAsString(11).Clean();
|
||||
if (!reader.IsDBNull(12)) pas.PassengerIdentityDocumentIssuingState = reader.GetString(12).Substring(0, 2).ToUpper();
|
||||
if (!reader.IsDBNull(13)) pas.PassengerIdentityDocumentExpiryDate = reader.GetDateTime(13);
|
||||
if (!reader.IsDBNull(14)) pas.PassengerVisaNumber = reader.ReadAsString(14).Clean();
|
||||
if (!reader.IsDBNull(15)) pas.EmergencyCare = reader.GetString(15).Clean();
|
||||
if (!reader.IsDBNull(16)) pas.EmergencyContactNumber = reader.ReadAsString(16).Clean();
|
||||
|
||||
pas.MessageHeader = this._pasMessage;
|
||||
pas.IsDirty = true;
|
||||
pas.Identifier = PAS.GetNewIdentifier(this._pasMessage.Elements);
|
||||
this._pasMessage.Elements.Add(pas);
|
||||
importPassenger.Add(pas);
|
||||
}
|
||||
} while (reader.NextResult());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
if (importPassenger.Count > 0)
|
||||
{
|
||||
this.dataGridPassengerList.Items.Refresh();
|
||||
this.SublistElementChanged(Message.NotificationClass.PASA);
|
||||
MessageBox.Show(String.Format(Properties.Resources.textPassengerImported, importPassenger.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
stream.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonImportExcelPassengerDeparture_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
@ -1284,80 +1266,73 @@ namespace ENI2.DetailViewControls
|
||||
};
|
||||
if (ofd.ShowDialog() ?? false)
|
||||
{
|
||||
FileStream stream;
|
||||
try
|
||||
{
|
||||
stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);
|
||||
using (var workbook = new XLWorkbook(ofd.FileName))
|
||||
{
|
||||
var worksheet = workbook.Worksheet(1);
|
||||
var rows = worksheet.RangeUsed().RowsUsed().Skip(1); // Skip header row if present
|
||||
|
||||
List<PASD> importPassenger = new List<PASD>();
|
||||
|
||||
foreach (var row in rows)
|
||||
{
|
||||
if (row.RowNumber() > worksheet.RangeUsed().RowCount()) break;
|
||||
|
||||
if (worksheet.RangeUsed().ColumnCount() < 17)
|
||||
{
|
||||
throw new InvalidDataException("Sheet must have 17 columns of data");
|
||||
}
|
||||
|
||||
PASD pas = new PASD();
|
||||
|
||||
if (row.Cell(1).IsEmpty() && row.Cell(2).IsEmpty()) continue;
|
||||
|
||||
if (!row.Cell(1).IsEmpty()) pas.PassengerLastName = row.Cell(1).GetString().Clean();
|
||||
if (pas.PassengerLastName?.Equals("Family Name") == true || string.IsNullOrWhiteSpace(pas.PassengerLastName)) continue;
|
||||
|
||||
if (!row.Cell(2).IsEmpty()) pas.PassengerFirstName = row.Cell(2).GetString().Clean();
|
||||
if (!row.Cell(3).IsEmpty()) pas.PassengerGender = GlobalStructures.ParseGender(row.Cell(3).GetString());
|
||||
if (!row.Cell(4).IsEmpty()) pas.PassengerPortOfEmbarkation = row.Cell(4).GetString().Clean();
|
||||
if (LocodeDB.PortNameFromLocode(pas.PassengerPortOfEmbarkation) == null)
|
||||
pas.PassengerPortOfEmbarkation = null;
|
||||
if (!row.Cell(5).IsEmpty()) pas.PassengerPortOfDisembarkation = row.Cell(5).GetString().Clean();
|
||||
if (LocodeDB.PortNameFromLocode(pas.PassengerPortOfDisembarkation) == null)
|
||||
pas.PassengerPortOfDisembarkation = null;
|
||||
if (!row.Cell(6).IsEmpty()) pas.PassengerInTransit = GlobalStructures.ReadBoolean(row.Cell(6).GetString());
|
||||
if (!row.Cell(7).IsEmpty()) pas.PassengerNationality = row.Cell(7).GetString().Substring(0, 2).ToUpper();
|
||||
if (!row.Cell(8).IsEmpty()) pas.PassengerPlaceOfBirth = row.Cell(8).GetString().Clean();
|
||||
if (!row.Cell(9).IsEmpty()) pas.PassengerCountryOfBirth = row.Cell(9).GetString().Substring(0, 2).ToUpper();
|
||||
if (!row.Cell(10).IsEmpty()) pas.PassengerDateOfBirth = row.Cell(10).GetDateTime();
|
||||
if (!row.Cell(11).IsEmpty()) pas.PassengerIdentityDocumentType = GlobalStructures.ReadIdentityDocumentType(row.Cell(11).GetString());
|
||||
if (!row.Cell(12).IsEmpty()) pas.PassengerIdentityDocumentId = row.Cell(12).GetString().Clean();
|
||||
if (!row.Cell(13).IsEmpty()) pas.PassengerIdentityDocumentIssuingState = row.Cell(13).GetString().Substring(0, 2).ToUpper();
|
||||
if (!row.Cell(14).IsEmpty()) pas.PassengerIdentityDocumentExpiryDate = row.Cell(14).GetDateTime();
|
||||
if (!row.Cell(15).IsEmpty()) pas.PassengerVisaNumber = row.Cell(15).GetString().Clean();
|
||||
if (!row.Cell(16).IsEmpty()) pas.EmergencyCare = row.Cell(16).GetString().Clean();
|
||||
if (!row.Cell(17).IsEmpty()) pas.EmergencyContactNumber = row.Cell(17).GetString().Clean();
|
||||
|
||||
pas.MessageHeader = this._pasdMessage;
|
||||
pas.IsDirty = true;
|
||||
pas.Identifier = PASD.GetNewIdentifier(this._pasdMessage.Elements);
|
||||
this._pasdMessage.Elements.Add(pas);
|
||||
importPassenger.Add(pas);
|
||||
}
|
||||
|
||||
if (importPassenger.Count > 0)
|
||||
{
|
||||
this.dataGridPassengerListDeparture.Items.Refresh();
|
||||
this.SublistElementChanged(Message.NotificationClass.PASD);
|
||||
MessageBox.Show(String.Format(Properties.Resources.textPassengerImported, importPassenger.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
using (var reader = ExcelReaderFactory.CreateReader(stream))
|
||||
{
|
||||
List<PASD> importPassenger = new List<PASD>();
|
||||
|
||||
try
|
||||
{
|
||||
do
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (((IExcelDataReader)reader).FieldCount < 17)
|
||||
{
|
||||
throw new InvalidDataException("Sheet must have 17 columns of data");
|
||||
}
|
||||
|
||||
PASD pas = new PASD();
|
||||
if (reader.IsDBNull(0) && reader.IsDBNull(1)) continue;
|
||||
if (!reader.IsDBNull(0)) pas.PassengerLastName = reader.GetValue(0).ToString();
|
||||
if (pas.PassengerLastName.Equals("Family Name") || (pas.PassengerLastName.Trim().Length == 0)) continue;
|
||||
if (!reader.IsDBNull(1)) pas.PassengerFirstName = reader.GetValue(1).ToString();
|
||||
if (!reader.IsDBNull(2)) pas.PassengerGender = GlobalStructures.ParseGender(reader.GetString(2));
|
||||
if (!reader.IsDBNull(3)) pas.PassengerPortOfEmbarkation = reader.GetString(3);
|
||||
if (LocodeDB.PortNameFromLocode(pas.PassengerPortOfEmbarkation) == null)
|
||||
pas.PassengerPortOfEmbarkation = null;
|
||||
if (!reader.IsDBNull(4)) pas.PassengerPortOfDisembarkation = reader.GetString(4);
|
||||
if (LocodeDB.PortNameFromLocode(pas.PassengerPortOfDisembarkation) == null)
|
||||
pas.PassengerPortOfDisembarkation = null;
|
||||
if (!reader.IsDBNull(5)) pas.PassengerInTransit = GlobalStructures.ReadBoolean(reader.GetString(5));
|
||||
if (!reader.IsDBNull(6)) pas.PassengerNationality = reader.GetString(6).Substring(0, 2).ToUpper();
|
||||
if (!reader.IsDBNull(7)) pas.PassengerPlaceOfBirth = reader.GetString(7);
|
||||
if (!reader.IsDBNull(8)) pas.PassengerCountryOfBirth = reader.GetString(8).Substring(0, 2).ToUpper();
|
||||
if (!reader.IsDBNull(9)) pas.PassengerDateOfBirth = reader.GetDateTime(9);
|
||||
if (!reader.IsDBNull(10)) pas.PassengerIdentityDocumentType = GlobalStructures.ReadIdentityDocumentType(reader.GetString(10));
|
||||
if (!reader.IsDBNull(11)) pas.PassengerIdentityDocumentId = reader.ReadAsString(11);
|
||||
if (!reader.IsDBNull(12)) pas.PassengerIdentityDocumentIssuingState = reader.GetString(12).Substring(0, 2).ToUpper();
|
||||
if (!reader.IsDBNull(13)) pas.PassengerIdentityDocumentExpiryDate = reader.GetDateTime(13);
|
||||
if (!reader.IsDBNull(14)) pas.PassengerVisaNumber = reader.ReadAsString(14);
|
||||
if (!reader.IsDBNull(15)) pas.EmergencyCare = reader.GetString(15);
|
||||
if (!reader.IsDBNull(16)) pas.EmergencyContactNumber = reader.ReadAsString(16);
|
||||
|
||||
pas.MessageHeader = this._pasMessage;
|
||||
pas.IsDirty = true;
|
||||
pas.Identifier = PASD.GetNewIdentifier(this._pasdMessage.Elements);
|
||||
this._pasdMessage.Elements.Add(pas);
|
||||
importPassenger.Add(pas);
|
||||
}
|
||||
} while (reader.NextResult());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
if (importPassenger.Count > 0)
|
||||
{
|
||||
this.dataGridPassengerListDeparture.Items.Refresh();
|
||||
this.SublistElementChanged(Message.NotificationClass.PASD);
|
||||
MessageBox.Show(String.Format(Properties.Resources.textPassengerImported, importPassenger.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
stream.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -134,9 +134,24 @@
|
||||
<CodeAnalysisRuleSet>..\code.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ClosedXML, Version=0.105.0.0, Culture=neutral, PublicKeyToken=fd1eb21b62ae805b, processorArchitecture=MSIL">
|
||||
<HintPath>packages\ClosedXML.0.105.0\lib\netstandard2.0\ClosedXML.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ClosedXML.Parser, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1d5f7376574c51ec, processorArchitecture=MSIL">
|
||||
<HintPath>packages\ClosedXML.Parser.2.0.0\lib\netstandard2.0\ClosedXML.Parser.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DocumentFormat.OpenXml, Version=3.1.1.0, Culture=neutral, PublicKeyToken=8fb06cb64d019a17, processorArchitecture=MSIL">
|
||||
<HintPath>packages\DocumentFormat.OpenXml.3.1.1\lib\net46\DocumentFormat.OpenXml.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DocumentFormat.OpenXml.Framework, Version=3.1.1.0, Culture=neutral, PublicKeyToken=8fb06cb64d019a17, processorArchitecture=MSIL">
|
||||
<HintPath>packages\DocumentFormat.OpenXml.Framework.3.1.1\lib\net46\DocumentFormat.OpenXml.Framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ExcelDataReader, Version=3.8.0.0, Culture=neutral, PublicKeyToken=93517dbe6a4012fa, processorArchitecture=MSIL">
|
||||
<HintPath>packages\ExcelDataReader.3.8.0\lib\net462\ExcelDataReader.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ExcelNumberFormat, Version=1.1.0.0, Culture=neutral, PublicKeyToken=23c6f5d73be07eca, processorArchitecture=MSIL">
|
||||
<HintPath>packages\ExcelNumberFormat.1.1.0\lib\net20\ExcelNumberFormat.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="log4net, Version=3.2.0.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>packages\log4net.3.2.0\lib\net462\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
@ -146,6 +161,9 @@
|
||||
<Reference Include="Microsoft.Bcl.Cryptography, Version=9.0.0.9, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.Bcl.Cryptography.9.0.9\lib\net462\Microsoft.Bcl.Cryptography.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Bcl.HashCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.Bcl.HashCode.1.1.1\lib\net461\Microsoft.Bcl.HashCode.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=9.0.0.9, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.Extensions.DependencyInjection.9.0.9\lib\net462\Microsoft.Extensions.DependencyInjection.dll</HintPath>
|
||||
</Reference>
|
||||
@ -204,6 +222,12 @@
|
||||
<Reference Include="PdfSharp.WPFonts, Version=6.2.2.0, Culture=neutral, PublicKeyToken=f94615aa0424f9eb, processorArchitecture=MSIL">
|
||||
<HintPath>packages\PDFsharp.6.2.2\lib\netstandard2.0\PdfSharp.WPFonts.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RBush, Version=4.0.0.0, Culture=neutral, PublicKeyToken=c77e27b81f4d0187, processorArchitecture=MSIL">
|
||||
<HintPath>packages\RBush.Signed.4.0.0\lib\net47\RBush.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SixLabors.Fonts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d998eea7b14cab13, processorArchitecture=MSIL">
|
||||
<HintPath>packages\SixLabors.Fonts.1.0.0\lib\netstandard2.0\SixLabors.Fonts.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Buffers.4.6.1\lib\net462\System.Buffers.dll</HintPath>
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="ClosedXML" version="0.105.0" targetFramework="net48" />
|
||||
<package id="ClosedXML.Parser" version="2.0.0" targetFramework="net48" />
|
||||
<package id="DocumentFormat.OpenXml" version="3.1.1" targetFramework="net48" />
|
||||
<package id="DocumentFormat.OpenXml.Framework" version="3.1.1" targetFramework="net48" />
|
||||
<package id="ExcelDataReader" version="3.8.0" targetFramework="net48" />
|
||||
<package id="ExcelNumberFormat" version="1.1.0" targetFramework="net48" />
|
||||
<package id="Extended.Wpf.Toolkit" version="5.0.0" targetFramework="net48" />
|
||||
<package id="log4net" version="3.2.0" targetFramework="net48" />
|
||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="9.0.9" targetFramework="net48" />
|
||||
<package id="Microsoft.Bcl.Cryptography" version="9.0.9" targetFramework="net48" />
|
||||
<package id="Microsoft.Bcl.HashCode" version="1.1.1" targetFramework="net48" />
|
||||
<package id="Microsoft.Extensions.DependencyInjection" version="9.0.9" targetFramework="net48" />
|
||||
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="9.0.9" targetFramework="net48" />
|
||||
<package id="Microsoft.Extensions.Logging" version="9.0.9" targetFramework="net48" />
|
||||
@ -14,6 +20,8 @@
|
||||
<package id="Microsoft.Office.Interop.Excel" version="15.0.4795.1001" targetFramework="net48" />
|
||||
<package id="PDFsharp" version="6.2.2" targetFramework="net48" />
|
||||
<package id="PDFsharp-MigraDoc" version="6.2.2" targetFramework="net48" />
|
||||
<package id="RBush.Signed" version="4.0.0" targetFramework="net48" />
|
||||
<package id="SixLabors.Fonts" version="1.0.0" targetFramework="net48" />
|
||||
<package id="Stub.System.Data.SQLite.Core.NetFramework" version="1.0.119.0" targetFramework="net48" />
|
||||
<package id="System.Buffers" version="4.6.1" targetFramework="net48" />
|
||||
<package id="System.Data.SQLite.Core" version="1.0.119.0" targetFramework="net48" />
|
||||
|
||||
Loading…
Reference in New Issue
Block a user