diff --git a/ENI2/App.xaml.cs b/ENI2/App.xaml.cs index 68e72e8f..24c2b9ae 100644 --- a/ENI2/App.xaml.cs +++ b/ENI2/App.xaml.cs @@ -11,13 +11,10 @@ using log4net; using System.Windows.Controls; using System.Windows.Input; using System; -using System.Net; using ENI2.LockingServiceReference; using ENI2.Util; using System.Threading; using System.Threading.Tasks; -using Microsoft.Office.Interop.Excel; -using System.Drawing.Drawing2D; namespace ENI2 { diff --git a/ENI2/Controls/MaerskListControl.xaml.cs b/ENI2/Controls/MaerskListControl.xaml.cs index 20e69a3b..a4d275b6 100644 --- a/ENI2/Controls/MaerskListControl.xaml.cs +++ b/ENI2/Controls/MaerskListControl.xaml.cs @@ -2,23 +2,23 @@ // Description: Request dbh ids for Maersk data lists // -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Windows; -using System.Windows.Controls; -using Microsoft.Win32; - using bsmd.database; -using ExcelDataReader; -using System.Collections.ObjectModel; +using ClosedXML.Excel; using ENI2.Excel; using ENI2.Locode; using ENI2.Util; + +using Microsoft.Win32; +using System; + +using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Diagnostics; +using System.IO; using System.Linq; using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; namespace ENI2.Controls { @@ -336,80 +336,72 @@ namespace ENI2.Controls }; if (ofd.ShowDialog() ?? false) { - FileStream stream; try { - stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read, FileShare.Read); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - using (IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream)) - { - List importData = new List(); - - bool isFirstRow = true; - int currentRow = 0; - bool imosAreOkay = true; - - try + using (var workbook = new XLWorkbook(ofd.FileName)) { - while (reader.Read()) + var worksheet = workbook.Worksheet(1); // Get first worksheet + var rows = worksheet.RangeUsed().RowsUsed().Skip(1); // Skip header row + + List importData = new List(); + + int currentRow = 1; // Start at 1 since we skip header + bool imosAreOkay = true; + + foreach (var row in rows) { currentRow++; - if (isFirstRow) - { - isFirstRow = false; // this must be a header row, skip - continue; - } - - if (reader.FieldCount < 13) + if (worksheet.RangeUsed().ColumnCount() < 13) { throw new InvalidDataException("Sheet must have 13 columns of data"); } MaerskData md = new MaerskData(); - if (!reader.IsDBNull(0)) + + if (!row.Cell(1).IsEmpty()) { - if (reader.GetFieldType(0) == typeof(DateTime)) + var cellValue = row.Cell(1).Value; + if (cellValue.IsDateTime) { - md.ETA = reader.GetDateTime(0); + var dateTime = cellValue.GetDateTime(); + md.ETA = dateTime; md.ColA = md.ETA.ToString(); } else { - md.ColA = reader.GetString(0); + md.ColA = row.Cell(1).GetString(); if (DateTime.TryParse(md.ColA, out DateTime aDateTime)) md.ETA = aDateTime; } } - if (!reader.IsDBNull(1)) md.ColB = reader.ReadAsString(1); - if (!reader.IsDBNull(2)) md.ColC = reader.ReadAsString(2); - if (!reader.IsDBNull(3)) md.ColD = reader.ReadAsString(3); - if (!reader.IsDBNull(4)) md.ColE = reader.ReadAsString(4); - if (!reader.IsDBNull(5)) md.ColF = reader.ReadAsString(5); - if (!reader.IsDBNull(6)) md.ColG = reader.ReadAsString(6); - if (!reader.IsDBNull(7)) md.ColH = reader.ReadAsString(7); - if (!reader.IsDBNull(8)) md.ColI = reader.ReadAsString(8); + + if (!row.Cell(2).IsEmpty()) md.ColB = row.Cell(2).GetString(); + if (!row.Cell(3).IsEmpty()) md.ColC = row.Cell(3).GetString(); + if (!row.Cell(4).IsEmpty()) md.ColD = row.Cell(4).GetString(); + if (!row.Cell(5).IsEmpty()) md.ColE = row.Cell(5).GetString(); + if (!row.Cell(6).IsEmpty()) md.ColF = row.Cell(6).GetString(); + if (!row.Cell(7).IsEmpty()) md.ColG = row.Cell(7).GetString(); + if (!row.Cell(8).IsEmpty()) md.ColH = row.Cell(8).GetString(); + if (!row.Cell(9).IsEmpty()) md.ColI = row.Cell(9).GetString(); + if (md.ColI != null) { if ((md.ColI.Contains("bremerhaven", StringComparison.OrdinalIgnoreCase) && this.PortLocode.Equals("DEWVN")) || (md.ColI.Contains("eurogate", StringComparison.OrdinalIgnoreCase) && this.PortLocode.Equals("DEBRV"))) throw new InvalidOperationException($"{md.ColI} found in import to {PortLocode}, this is probably an error. Aborting import"); } - if (!reader.IsDBNull(9)) md.ColJ = reader.ReadAsString(9); + + if (!row.Cell(10).IsEmpty()) md.ColJ = row.Cell(10).GetString(); if (md.ColJ == null) continue; if (!(md.ColJ.Equals("msk", StringComparison.OrdinalIgnoreCase) || md.ColJ.Equals("sgl", StringComparison.OrdinalIgnoreCase))) continue; // skip operator we are not interested in - if (!reader.IsDBNull(10)) md.ColK = reader.ReadAsString(10); - if (!reader.IsDBNull(11)) md.ColL = reader.ReadAsString(11); - if (!reader.IsDBNull(12)) md.ColM = reader.ReadAsString(12); - if (!reader.IsDBNull(13)) md.Remark = reader.ReadAsString(13); - - if(!md.ColF.IsNullOrEmpty()) + + if (!row.Cell(11).IsEmpty()) md.ColK = row.Cell(11).GetString(); + if (!row.Cell(12).IsEmpty()) md.ColL = row.Cell(12).GetString(); + if (!row.Cell(13).IsEmpty()) md.ColM = row.Cell(13).GetString(); + if (!row.Cell(14).IsEmpty()) md.Remark = row.Cell(14).GetString(); + + if (!md.ColF.IsNullOrEmpty()) { if (Int32.TryParse(md.ColF, out int imo)) { @@ -417,7 +409,7 @@ namespace ENI2.Controls { imosAreOkay = false; } - } + } else { imosAreOkay = false; @@ -435,71 +427,67 @@ namespace ENI2.Controls } importData.Add(md); - - if (isFirstRow) isFirstRow = false; } - } - catch (Exception ex) - { - MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error); - } - - if (imosAreOkay && importData.Count > 0) - { - busyControl.BusyState = Util.UIHelper.BusyStateEnum.BUSY; - - foreach (MaerskData md in importData) - { - if (this.maerskDataList.Contains(md)) - { - // update record with imported record - MaerskData foundData = this.maerskDataList.First((m) => (m.ColF != null) ? m.ColF.Equals(md.ColF) : (md.ColF == null) && - (m.ColG != null) ? m.ColG.Equals(md.ColG) : (md.ColG == null) && - (m.ColH != null) ? m.ColH.Equals(md.ColH) : (md.ColH == null)); - if ((foundData.MessageCore == null) || !(foundData.MessageCore.Cancelled ?? false)) - { - if (foundData.ETA.HasValue && ((foundData.ETA.Value - DateTime.Now).TotalSeconds > 0) && foundData.Update(md)) - foundData.Status = MaerskData.MDStatus.UPDATED; - } - } - else + if (imosAreOkay && importData.Count > 0) + { + busyControl.BusyState = Util.UIHelper.BusyStateEnum.BUSY; + + foreach (MaerskData md in importData) { - if (!md.ColM.IsNullOrEmpty()) + if (this.maerskDataList.Contains(md)) { - md.MessageCore = await DBManagerAsync.LoadCoreByVisitIdAsync(md.ColM); - if (md.MessageCore != null) + // update record with imported record + MaerskData foundData = this.maerskDataList.First((m) => (m.ColF != null) ? m.ColF.Equals(md.ColF) : (md.ColF == null) && + (m.ColG != null) ? m.ColG.Equals(md.ColG) : (md.ColG == null) && + (m.ColH != null) ? m.ColH.Equals(md.ColH) : (md.ColH == null)); + + if ((foundData.MessageCore == null) || !(foundData.MessageCore.Cancelled ?? false)) { - MaerskData existingMD = await DBManagerAsync.LoadMaerskDataForCoreAsync(md.MessageCore.Id.Value); - if(existingMD == null) - { - // we have a core but no MarskData for this import -> save it - md.MessageCoreId = (Guid) md.MessageCore.Id; - _ = DBManagerAsync.SaveAsync(md); - } - else - { - existingMD.Update(md); - _ = DBManagerAsync.SaveAsync(existingMD); - this.UpdateStatus(existingMD); - maerskDataList.Add(existingMD); - continue; // add existing instead of new one - } + if (foundData.ETA.HasValue && ((foundData.ETA.Value - DateTime.Now).TotalSeconds > 0) && foundData.Update(md)) + foundData.Status = MaerskData.MDStatus.UPDATED; } } + else + { + if (!md.ColM.IsNullOrEmpty()) + { + md.MessageCore = await DBManagerAsync.LoadCoreByVisitIdAsync(md.ColM); + if (md.MessageCore != null) + { + MaerskData existingMD = await DBManagerAsync.LoadMaerskDataForCoreAsync(md.MessageCore.Id.Value); + if (existingMD == null) + { + // we have a core but no MarskData for this import -> save it + md.MessageCoreId = (Guid)md.MessageCore.Id; + _ = DBManagerAsync.SaveAsync(md); + } + else + { + existingMD.Update(md); + _ = DBManagerAsync.SaveAsync(existingMD); + this.UpdateStatus(existingMD); + maerskDataList.Add(existingMD); + continue; // add existing instead of new one + } + } + } - this.UpdateStatus(md); - maerskDataList.Add(md); + this.UpdateStatus(md); + maerskDataList.Add(md); + } } - } - this.TimeFilterItemSource(); - busyControl.BusyState = Util.UIHelper.BusyStateEnum.NEUTRAL; + this.TimeFilterItemSource(); + busyControl.BusyState = Util.UIHelper.BusyStateEnum.NEUTRAL; - this.dataGridPOCores.Items.Refresh(); + this.dataGridPOCores.Items.Refresh(); + } } } - - stream.Close(); + catch (Exception ex) + { + MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error); + } } } diff --git a/ENI2/DetailViewControls/BorderPoliceDetailControl.xaml.cs b/ENI2/DetailViewControls/BorderPoliceDetailControl.xaml.cs index 7aecb28e..91608b6f 100644 --- a/ENI2/DetailViewControls/BorderPoliceDetailControl.xaml.cs +++ b/ENI2/DetailViewControls/BorderPoliceDetailControl.xaml.cs @@ -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 importCrew = new List(); + + 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 importCrew = new List(); - - 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 importCrew = new List(); + + 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 importCrew = new List(); - - 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 importPassenger = new List(); + + 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 importPassenger = new List(); - - 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 importPassenger = new List(); + + 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 importPassenger = new List(); - - 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 diff --git a/ENI2/DetailViewControls/MaritimeHealthDeclarationDetailControl.xaml.cs b/ENI2/DetailViewControls/MaritimeHealthDeclarationDetailControl.xaml.cs index d5d719b3..818b9b67 100644 --- a/ENI2/DetailViewControls/MaritimeHealthDeclarationDetailControl.xaml.cs +++ b/ENI2/DetailViewControls/MaritimeHealthDeclarationDetailControl.xaml.cs @@ -2,18 +2,16 @@ // Description: MDH Meldung Bearbeitungsseite // -using System; -using System.Collections.Generic; -using System.Windows; -using System.Windows.Controls; -using Microsoft.Win32; -using System.IO; - +using bsmd.database; +using ClosedXML.Excel; using ENI2.EditControls; using ENI2.Util; -using bsmd.database; - -using ExcelDataReader; +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.IO; +using System.Windows; +using System.Windows.Controls; namespace ENI2.DetailViewControls { @@ -283,86 +281,15 @@ namespace ENI2.DetailViewControls private void ButtonImportFromExcel_Click(object sender, RoutedEventArgs e) { - OpenFileDialog ofd = new OpenFileDialog + int cnt = Excel.ExcelLocalImportHelper.ImportLast30Days(this._mdh); + + if (cnt > 0) { - 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 (var reader = ExcelReaderFactory.CreateReader(stream)) - { - List importPoC30 = new List(); - - try - { - do - { - while (reader.Read()) - { - if (reader.FieldCount < 3) - { - throw new InvalidDataException("Sheet must have at least 3 Columns of data"); - } - PortOfCallLast30Days poc30 = new PortOfCallLast30Days(); - if (reader.IsDBNull(0) && reader.IsDBNull(1)) continue; - if (!reader.IsDBNull(0)) poc30.PortOfCallLast30DaysLocode = reader.GetString(0); - if (!reader.IsDBNull(1)) poc30.PortOfCallLast30DaysDateOfDeparture = reader.GetDateTime(1); - string boolString = ""; - if (!reader.IsDBNull(2)) boolString = reader.GetString(2); - poc30.PortOfCallLast30DaysCrewMembersJoined = (boolString.Equals("y", StringComparison.OrdinalIgnoreCase) || (boolString.Equals("yes", StringComparison.OrdinalIgnoreCase)) || - (boolString.Equals("j", StringComparison.OrdinalIgnoreCase))); - - if(reader.FieldCount > 3) - { - string allNewCrew = reader.GetString(3)?.Trim(); - if(!allNewCrew.IsNullOrEmpty()) - { - string[] crewNames = allNewCrew.Split(',', ';'); - for(int i=0;i 0) - { - this.dataGridPortOfCallLast30Days.Items.Refresh(); - this.SublistElementChanged(Message.NotificationClass.MDH); - MessageBox.Show(String.Format(Properties.Resources.textPoC30Imported, importPoC30.Count), Properties.Resources.textCaptionInformation, - MessageBoxButton.OK, MessageBoxImage.Information); - } - } - - stream.Close(); + this.dataGridPortOfCallLast30Days.Items.Refresh(); + this.SublistElementChanged(Message.NotificationClass.MDH); + MessageBox.Show(String.Format(Properties.Resources.textPoC30Imported, cnt), + Properties.Resources.textCaptionInformation, + MessageBoxButton.OK, MessageBoxImage.Information); } } diff --git a/ENI2/DetailViewControls/SecurityDetailControl.xaml.cs b/ENI2/DetailViewControls/SecurityDetailControl.xaml.cs index 28e45fb4..7bd57624 100644 --- a/ENI2/DetailViewControls/SecurityDetailControl.xaml.cs +++ b/ENI2/DetailViewControls/SecurityDetailControl.xaml.cs @@ -2,18 +2,17 @@ // Description: SEC Meldung Bearbeitungsseite // -using System.Windows; -using System.Windows.Controls; +using bsmd.database; +using ClosedXML.Excel; using ENI2.EditControls; using ENI2.Util; -using bsmd.database; - -using System.Windows.Data; -using System; using Microsoft.Win32; -using System.IO; -using ExcelDataReader; +using System; using System.Collections.Generic; +using System.IO; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; namespace ENI2.DetailViewControls { @@ -338,83 +337,14 @@ namespace ENI2.DetailViewControls private void buttonImportExcel_Click(object sender, RoutedEventArgs e) { - OpenFileDialog ofd = new OpenFileDialog + int importedCount = Excel.ExcelLocalImportHelper.ImportLast10PortFacilities(this._sec); + + if (importedCount > 0) { - 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 (var reader = ExcelReaderFactory.CreateReader(stream)) - { - List importL10C = new List(); - - try - { - do - { - int cnt = 0; - while (reader.Read() && (cnt < 10)) - { - if (((IExcelDataReader)reader).FieldCount < 8) - { - throw new InvalidDataException("Sheet must have 8 Columns of data"); - } - LastTenPortFacilitiesCalled l10c = new LastTenPortFacilitiesCalled(); - if (reader.IsDBNull(0) && reader.IsDBNull(1)) continue; - if (!reader.IsDBNull(0)) l10c.PortFacilityPortName = reader.GetString(0); - if (!reader.IsDBNull(2)) l10c.PortFacilityPortCountry = reader.GetString(2); - if (!reader.IsDBNull(3)) l10c.PortFacilityPortLoCode = reader.GetString(3); - object o = null; - if (!reader.IsDBNull(4)) o = reader.GetValue(4); - if(o != null) l10c.PortFacilityDateOfArrival = Convert.ToDateTime(o); - if (!reader.IsDBNull(5)) o = reader.GetValue(5); - if (o != null) l10c.PortFacilityDateOfDeparture = Convert.ToDateTime(o); - // if (!reader.IsDBNull(4)) l10c.PortFacilityDateOfArrival = reader.GetDateTime(4); - // if (!reader.IsDBNull(5)) l10c.PortFacilityDateOfDeparture = reader.GetDateTime(5); - if (!reader.IsDBNull(6)) o = reader.GetValue(6); - if (o != null) l10c.PortFacilityShipSecurityLevel = Convert.ToByte(o); - if (!reader.IsDBNull(7)) o = reader.GetValue(7); - int gisis = Convert.ToInt32(o); - if (!reader.IsDBNull(7)) l10c.PortFacilityGISISCode = gisis.ToString().PadLeft(4, '0'); - if (!reader.IsDBNull(8)) l10c.PortFacilitySecurityMattersToReport = reader.GetString(8); - if (l10c.PortFacilitySecurityMattersToReport.Equals("nil", StringComparison.CurrentCultureIgnoreCase)) - l10c.PortFacilitySecurityMattersToReport = null; - if (!reader.IsDBNull(9)) l10c.PortFacilityGISISCodeLocode = reader.GetString(9); - l10c.SEC = this._sec; - l10c.IsDirty = true; - l10c.Identifier = LastTenPortFacilitiesCalled.GetNewIdentifier(this._sec.LastTenPortFacilitesCalled); - this._sec.LastTenPortFacilitesCalled.Add(l10c); - importL10C.Add(l10c); - cnt++; - } - } while (reader.NextResult()); - } - catch (Exception ex) - { - MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error); - } - - if (importL10C.Count > 0) - { - this.dataGridLast10PortFacilities.Items.Refresh(); - this.SublistElementChanged(Message.NotificationClass.SEC); - MessageBox.Show(String.Format(Properties.Resources.textL10PImported, importL10C.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information); - } - } - - stream.Close(); + this.dataGridLast10PortFacilities.Items.Refresh(); + this.SublistElementChanged(Message.NotificationClass.SEC); + MessageBox.Show(String.Format(Properties.Resources.textL10PImported, importedCount), + Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information); } } diff --git a/ENI2/DetailViewControls/WasteDetailControl.xaml.cs b/ENI2/DetailViewControls/WasteDetailControl.xaml.cs index 6ba99603..d3fe3ea7 100644 --- a/ENI2/DetailViewControls/WasteDetailControl.xaml.cs +++ b/ENI2/DetailViewControls/WasteDetailControl.xaml.cs @@ -2,17 +2,17 @@ // Description: Detailansicht Müllmeldung // -using System.Linq; -using System.Collections.Generic; -using System.Windows; -using System.Windows.Controls; +using bsmd.database; +using ClosedXML.Excel; using ENI2.EditControls; using ENI2.Util; -using bsmd.database; -using ExcelDataReader; -using System.IO; -using System; using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Windows; +using System.Windows.Controls; namespace ENI2.DetailViewControls { @@ -483,100 +483,82 @@ namespace ENI2.DetailViewControls ofd.Filter = "Excel Files|*.xls;*.xlsx"; 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(3); // Skip first three rows + + List importWasteList = new List(); + + int cnt = 0; + object o = null; + + // Diese Funktion kann das "alte" Sheet Format nicht mehr einlesen! + + foreach (var row in rows) + { + if (cnt >= 35) break; // Maximum 35 rows + + if (worksheet.RangeUsed().ColumnCount() < 9) + { + throw new InvalidDataException("Sheet must have 9 Columns of data"); + } + + if (!row.Cell(2).IsEmpty()) o = row.Cell(2).Value; else o = null; + if ((o != null) && Int32.TryParse(o.ToString(), out int wasteType)) + { + Waste waste = _was.GetWasteForType(wasteType); + if (waste == null) + { + waste = new Waste(); + waste.WasteType = wasteType; + waste.WAS = this._was; + waste.IsDirty = true; + waste.Identifier = Waste.GetNewIdentifier(this._was.Waste); + this._was.Waste.Add(waste); + } + else + { + waste.IsDirty = true; + } + + if (!row.Cell(5).IsEmpty()) waste.WasteDescription = row.Cell(5).GetString(); + if (waste.WasteDescription.IsNullOrEmpty()) + waste.WasteDescription = "-"; + + if (!row.Cell(6).IsEmpty()) o = row.Cell(6).Value; else o = null; + if (o != null) waste.WasteDisposalAmount_MTQ = Convert.ToDouble(o); + + if (!row.Cell(7).IsEmpty()) o = row.Cell(7).Value; else o = null; + if (o != null) waste.WasteCapacity_MTQ = Convert.ToDouble(o); + + if (!row.Cell(8).IsEmpty()) o = row.Cell(8).Value; else o = null; + if (o != null) waste.WasteAmountRetained_MTQ = Convert.ToDouble(o); + + if (!row.Cell(9).IsEmpty()) waste.WasteDisposalPort = row.Cell(9).GetString().ToUpper(); + + if (!row.Cell(10).IsEmpty()) o = row.Cell(10).Value; else o = null; + if (o != null) waste.WasteAmountGeneratedTillNextPort_MTQ = Convert.ToDouble(o); + + importWasteList.Add(waste); + cnt++; + } + } + + if (importWasteList.Count > 0) + { + this.dataGridWaste.Items.Refresh(); + this.SublistElementChanged(Message.NotificationClass.WAS); + MessageBox.Show(String.Format(Properties.Resources.textWasteImported, importWasteList.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 importWasteList = new List(); - - try - { - do - { - // skip first three rows - reader.Read(); - reader.Read(); - reader.Read(); - - int cnt = 0; - object o = null; - - // Diese Funktion kann das "alte" Sheet Format nicht mehr einlesen! - - while (reader.Read() && (cnt < 35)) - { - if (reader.FieldCount < 9) - { - throw new InvalidDataException("Sheet must have 9 Columns of data"); - } - - if (!reader.IsDBNull(1)) o = reader.GetValue(1); else o = null; - if ((o != null) && Int32.TryParse(o.ToString(), out int wasteType)) - { - Waste waste = _was.GetWasteForType(wasteType); - if (waste == null) - { - waste = new Waste(); - waste.WasteType = wasteType; - waste.WAS = this._was; - waste.IsDirty = true; - waste.Identifier = Waste.GetNewIdentifier(this._was.Waste); - this._was.Waste.Add(waste); - } - else - { - waste.IsDirty = true; - } - - if (!reader.IsDBNull(4)) waste.WasteDescription = reader.GetString(4); - if (waste.WasteDescription.IsNullOrEmpty()) - waste.WasteDescription = "-"; - - if (!reader.IsDBNull(5)) o = reader.GetValue(5); else o = null; - if (o != null) waste.WasteDisposalAmount_MTQ = Convert.ToDouble(o); - - if (!reader.IsDBNull(6)) o = reader.GetValue(6); else o = null; - if (o != null) waste.WasteCapacity_MTQ = Convert.ToDouble(o); - - if (!reader.IsDBNull(7)) o = reader.GetValue(7); else o = null; - if (o != null) waste.WasteAmountRetained_MTQ = Convert.ToDouble(o); - - if (!reader.IsDBNull(8)) waste.WasteDisposalPort = reader.GetString(8).ToUpper(); - - if (!reader.IsDBNull(9)) o = reader.GetValue(9); else o = null; - if (o != null) waste.WasteAmountGeneratedTillNextPort_MTQ = Convert.ToDouble(o); - - importWasteList.Add(waste); - cnt++; - } - } - - } while (reader.NextResult()); - } - catch (Exception ex) - { - MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error); - } - - if (importWasteList.Count > 0) - { - this.dataGridWaste.Items.Refresh(); - this.SublistElementChanged(Message.NotificationClass.WAS); - MessageBox.Show(String.Format(Properties.Resources.textWasteImported, importWasteList.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information); - } - } - - stream.Close(); - } } diff --git a/ENI2/ENI2.csproj b/ENI2/ENI2.csproj index bf1e8e92..cd12f97a 100644 --- a/ENI2/ENI2.csproj +++ b/ENI2/ENI2.csproj @@ -9,7 +9,7 @@ Properties ENI2 ENI2 - v4.8 + v4.8.1 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 @@ -18,7 +18,7 @@ - eni2.publish\ + ENI2.publish\ true Web true @@ -36,8 +36,8 @@ 5.4.0.0 true publish.html - 7 - 7.2.12.7 + 2 + 7.2.13.2 false true true @@ -134,75 +134,92 @@ ..\code.ruleset - - packages\ExcelDataReader.3.8.0\lib\net462\ExcelDataReader.dll + + packages\ClosedXML.0.105.0\lib\netstandard2.0\ClosedXML.dll + + + packages\ClosedXML.Parser.2.0.0\lib\netstandard2.0\ClosedXML.Parser.dll + + + packages\DocumentFormat.OpenXml.3.3.0\lib\net46\DocumentFormat.OpenXml.dll + + + packages\DocumentFormat.OpenXml.Framework.3.3.0\lib\net46\DocumentFormat.OpenXml.Framework.dll + + + packages\ExcelNumberFormat.1.1.0\lib\net20\ExcelNumberFormat.dll packages\log4net.3.2.0\lib\net462\log4net.dll - - packages\Microsoft.Bcl.AsyncInterfaces.9.0.9\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + + packages\Microsoft.Bcl.AsyncInterfaces.10.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll - - packages\Microsoft.Bcl.Cryptography.9.0.9\lib\net462\Microsoft.Bcl.Cryptography.dll + + packages\Microsoft.Bcl.Cryptography.10.0.0\lib\net462\Microsoft.Bcl.Cryptography.dll - - packages\Microsoft.Extensions.DependencyInjection.9.0.9\lib\net462\Microsoft.Extensions.DependencyInjection.dll + + packages\Microsoft.Bcl.HashCode.6.0.0\lib\net462\Microsoft.Bcl.HashCode.dll - - packages\Microsoft.Extensions.DependencyInjection.Abstractions.9.0.9\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + packages\Microsoft.Extensions.DependencyInjection.10.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.dll - - packages\Microsoft.Extensions.Logging.9.0.9\lib\net462\Microsoft.Extensions.Logging.dll + + packages\Microsoft.Extensions.DependencyInjection.Abstractions.10.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll - - packages\Microsoft.Extensions.Logging.Abstractions.9.0.9\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll + + packages\Microsoft.Extensions.Logging.10.0.0\lib\net462\Microsoft.Extensions.Logging.dll - - packages\Microsoft.Extensions.Options.9.0.9\lib\net462\Microsoft.Extensions.Options.dll + + packages\Microsoft.Extensions.Logging.Abstractions.10.0.0\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll - - packages\Microsoft.Extensions.Primitives.9.0.9\lib\net462\Microsoft.Extensions.Primitives.dll + + packages\Microsoft.Extensions.Options.10.0.0\lib\net462\Microsoft.Extensions.Options.dll - - packages\Microsoft.Office.Interop.Excel.15.0.4795.1001\lib\net20\Microsoft.Office.Interop.Excel.dll - True + + packages\Microsoft.Extensions.Primitives.10.0.0\lib\net462\Microsoft.Extensions.Primitives.dll - - packages\PDFsharp-MigraDoc.6.2.2\lib\netstandard2.0\MigraDoc.DocumentObjectModel.dll + + packages\PDFsharp-MigraDoc.6.2.3\lib\netstandard2.0\MigraDoc.DocumentObjectModel.dll - - packages\PDFsharp-MigraDoc.6.2.2\lib\netstandard2.0\MigraDoc.Rendering.dll + + packages\PDFsharp-MigraDoc.6.2.3\lib\netstandard2.0\MigraDoc.Rendering.dll - - packages\PDFsharp-MigraDoc.6.2.2\lib\netstandard2.0\MigraDoc.RtfRendering.dll + + packages\PDFsharp-MigraDoc.6.2.3\lib\netstandard2.0\MigraDoc.RtfRendering.dll - - packages\PDFsharp.6.2.2\lib\netstandard2.0\PdfSharp.dll + + packages\PDFsharp.6.2.3\lib\netstandard2.0\PdfSharp.dll - - packages\PDFsharp.6.2.2\lib\netstandard2.0\PdfSharp.BarCodes.dll + + packages\PDFsharp.6.2.3\lib\netstandard2.0\PdfSharp.BarCodes.dll - - packages\PDFsharp.6.2.2\lib\netstandard2.0\PdfSharp.Charting.dll + + packages\PDFsharp.6.2.3\lib\netstandard2.0\PdfSharp.Charting.dll - - packages\PDFsharp.6.2.2\lib\netstandard2.0\PdfSharp.Cryptography.dll + + packages\PDFsharp.6.2.3\lib\netstandard2.0\PdfSharp.Cryptography.dll - - packages\PDFsharp.6.2.2\lib\netstandard2.0\PdfSharp.Quality.dll + + packages\PDFsharp.6.2.3\lib\netstandard2.0\PdfSharp.Quality.dll - - packages\PDFsharp.6.2.2\lib\netstandard2.0\PdfSharp.Shared.dll + + packages\PDFsharp.6.2.3\lib\netstandard2.0\PdfSharp.Shared.dll - - packages\PDFsharp.6.2.2\lib\netstandard2.0\PdfSharp.Snippets.dll + + packages\PDFsharp.6.2.3\lib\netstandard2.0\PdfSharp.Snippets.dll - - packages\PDFsharp.6.2.2\lib\netstandard2.0\PdfSharp.System.dll + + packages\PDFsharp.6.2.3\lib\netstandard2.0\PdfSharp.System.dll - - packages\PDFsharp.6.2.2\lib\netstandard2.0\PdfSharp.WPFonts.dll + + packages\PDFsharp.6.2.3\lib\netstandard2.0\PdfSharp.WPFonts.dll + + + packages\RBush.Signed.4.0.0\lib\net47\RBush.dll + + + packages\SixLabors.Fonts.1.0.0\lib\netstandard2.0\SixLabors.Fonts.dll @@ -214,12 +231,12 @@ packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.119.0\lib\net46\System.Data.SQLite.dll - - packages\System.Diagnostics.DiagnosticSource.9.0.9\lib\net462\System.Diagnostics.DiagnosticSource.dll + + packages\System.Diagnostics.DiagnosticSource.10.0.0\lib\net462\System.Diagnostics.DiagnosticSource.dll - - packages\System.Formats.Asn1.9.0.9\lib\net462\System.Formats.Asn1.dll + + packages\System.Formats.Asn1.10.0.0\lib\net462\System.Formats.Asn1.dll @@ -234,8 +251,8 @@ - - packages\System.Security.Cryptography.Pkcs.9.0.9\lib\net462\System.Security.Cryptography.Pkcs.dll + + packages\System.Security.Cryptography.Pkcs.10.0.0\lib\net462\System.Security.Cryptography.Pkcs.dll @@ -339,6 +356,7 @@ + diff --git a/ENI2/EditControls/EditRulesDialog.xaml b/ENI2/EditControls/EditRulesDialog.xaml index 63859dab..a306db64 100644 --- a/ENI2/EditControls/EditRulesDialog.xaml +++ b/ENI2/EditControls/EditRulesDialog.xaml @@ -9,7 +9,7 @@ xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" xmlns:p="clr-namespace:ENI2.Properties" mc:Ignorable="d" - Title="{x:Static p:Resources.textEditRules}" Height="402" Width="800" WindowStyle="SingleBorderWindow" Background="AliceBlue" Icon="/ENI2;component/Resources/mail_forward.png"> + Title="{x:Static p:Resources.textEditRules}" Height="402" Width="800" WindowStyle="SingleBorderWindow" Background="AliceBlue" Icon="/ENI2;component/Resources/mail_forward.png"> diff --git a/ENI2/EditControls/NewDGItemDialog.xaml b/ENI2/EditControls/NewDGItemDialog.xaml index 3a85d0ec..2d10c678 100644 --- a/ENI2/EditControls/NewDGItemDialog.xaml +++ b/ENI2/EditControls/NewDGItemDialog.xaml @@ -8,7 +8,7 @@ xmlns:p="clr-namespace:ENI2.Properties" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" mc:Ignorable="d" - Title="{x:Static p:Resources.textNewDGItem}" Height="350" Width="600" WindowStyle="SingleBorderWindow" Background="AliceBlue" ResizeMode="CanResize" + Title="{x:Static p:Resources.textNewDGItem}" Height="350" Width="600" WindowStyle="SingleBorderWindow" Background="AliceBlue" ResizeMode="CanResize" Icon="/ENI2;component/Resources/bullet_ball_yellow.ico" Loaded="EditWindowBase_Loaded"> diff --git a/ENI2/EditControls/NewWithIdDialog.xaml b/ENI2/EditControls/NewWithIdDialog.xaml index b195c189..0fb1a1fa 100644 --- a/ENI2/EditControls/NewWithIdDialog.xaml +++ b/ENI2/EditControls/NewWithIdDialog.xaml @@ -9,7 +9,7 @@ xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" mc:Ignorable="d" Title="{x:Static p:Resources.textNewWithId}" Height="220" Width="350" WindowStyle="SingleBorderWindow" Background="AliceBlue" ResizeMode="NoResize" Icon="/ENI2;component/Resources/id_card_add.ico"> - + diff --git a/ENI2/Excel/ExcelBase.cs b/ENI2/Excel/ExcelBase.cs index 3573d4cf..7c54a00d 100644 --- a/ENI2/Excel/ExcelBase.cs +++ b/ENI2/Excel/ExcelBase.cs @@ -1,13 +1,14 @@ // Copyright (c) 2017-today Informatikbüro Daniel Schick -// Base class excel (writer not yet implemented but eventually..) +// Base class excel access (named ranges, colorizing, etc.) using System; using System.Collections.Generic; -using Microsoft.Office.Interop.Excel; -using System.Runtime.InteropServices; +using ClosedXML.Excel; using log4net; using System.Globalization; using System.Text.RegularExpressions; +using System.Drawing; +using System.Linq; namespace ENI2.Excel { @@ -20,10 +21,8 @@ namespace ENI2.Excel protected CountryMode _countryMode = CountryMode.DE; - protected Workbooks _excelWorkbooks; - protected Workbook _workBook; - protected Application _excelApp; - protected Dictionary _nameDict; + protected XLWorkbook _workBook; + protected Dictionary _nameDict; protected ILog _log; #endregion Fields @@ -32,12 +31,7 @@ namespace ENI2.Excel public ExcelBase() { - _log = LogManager.GetLogger(this.GetType().Name); - - this._excelApp = new Application(); - this._excelApp.DisplayAlerts = false; - this._excelWorkbooks = _excelApp.Workbooks; } #endregion Construction @@ -46,9 +40,9 @@ namespace ENI2.Excel internal CountryMode Mode { get { return _countryMode; } } - internal Dictionary NameDict { get { return _nameDict; } } + internal Dictionary NameDict { get { return _nameDict; } } - internal Sheets Worksheets { get { return _workBook.Worksheets; } } + internal IXLWorksheets Worksheets { get { return _workBook?.Worksheets; } } #endregion @@ -56,17 +50,17 @@ namespace ENI2.Excel protected void InitNameFields() { - _nameDict = new Dictionary(); + _nameDict = new Dictionary(); int bookCnt = 0; - foreach (Name name in _workBook.Names) - { - string theValue = name.Value; - // Namensbezug: =SheetZelle. Leere Referenzen überspringen (kommt immer mal wieder vor!) - string nameKey = name.Name; + // Get workbook-level defined names + foreach (var definedName in _workBook.DefinedNames) + { + string nameKey = definedName.Name; try { + // Handle sheet-scoped names (Sheet1!Name format) if (nameKey.Contains("!")) nameKey = nameKey.Substring(nameKey.IndexOf('!') + 1); } @@ -76,33 +70,34 @@ namespace ENI2.Excel continue; } - if ((theValue != "=#REF!#REF!") && (theValue != "=#BEZUG!#BEZUG!")) + // Check if the defined name is valid (not a broken reference) + if (definedName.IsValid) { - _nameDict[nameKey] = name; + _nameDict[nameKey] = definedName; bookCnt++; } } - _log.DebugFormat("{0} named ranges found at Workbook level", bookCnt); + _log.DebugFormat("{0} defined names found at Workbook level", bookCnt); - - foreach (Worksheet ws in _workBook.Worksheets) + // Get worksheet-level defined names + foreach (var ws in _workBook.Worksheets) { int wsCnt = 0; - foreach (Name name in ws.Names) + foreach (var definedName in ws.DefinedNames) { - string theValue = name.Value; - // Namensbezug: =SheetZelle. Leere Referenzen überspringen (kommt immer mal wieder vor!) - if (!_nameDict.ContainsKey(name.Name)) + string nameKey = definedName.Name; + + if (!_nameDict.ContainsKey(nameKey)) { - if ((theValue != "=#REF!#REF!") && (theValue != "=#BEZUG!#BEZUG!")) + if (definedName.IsValid) { - _nameDict[name.Name] = name; + _nameDict[nameKey] = definedName; wsCnt++; } } } if (wsCnt > 0) - _log.DebugFormat("{0} named ranges found in Worksheet {1}", wsCnt, ws.Name); + _log.DebugFormat("{0} defined names found in Worksheet {1}", wsCnt, ws.Name); } } @@ -127,26 +122,39 @@ namespace ENI2.Excel { if (_nameDict.ContainsKey(lookup)) { - var val = _nameDict[lookup].RefersToRange.Value; - if (val is double) result = val; - if ((val is string) && (val.Length > 0)) - { - result = ParseAnyDouble(val); + var definedName = _nameDict[lookup]; + var ranges = definedName.Ranges; + var range = ranges.FirstOrDefault(); - if(result == null) - { - Match m = Regex.Match(val, "([0-9\\.\\,]+)([a-zA-Z]*)"); - if (m.Success) + if (range != null) + { + var cell = range.FirstCell(); + if (cell != null) + { + var cellValue = cell.Value; + + if (cellValue.IsNumber) { - result = ParseAnyDouble(m.Groups[1].Value); - } - } - } + result = cellValue.GetNumber(); + } + else if (cellValue.IsText) + { + string textVal = cellValue.GetText(); + if (!string.IsNullOrEmpty(textVal)) + { + result = ParseAnyDouble(textVal); - if ((result == null) && (val != null)) - { - double tmpDouble2 = val[1, 1]; - result = tmpDouble2; + if (result == null) + { + Match m = Regex.Match(textVal, "([0-9\\.\\,]+)([a-zA-Z]*)"); + if (m.Success) + { + result = ParseAnyDouble(m.Groups[1].Value); + } + } + } + } + } } } } @@ -159,17 +167,26 @@ namespace ENI2.Excel internal void Colorize(string lookup, int color) { - if(_nameDict.ContainsKey(lookup)) + if (_nameDict.ContainsKey(lookup)) { - var range = _nameDict[lookup].RefersToRange; - Colorize(range, color); + var definedName = _nameDict[lookup]; + var ranges = definedName.Ranges; + var range = ranges.FirstOrDefault(); + if (range != null) + { + Colorize(range, color); + } } } - internal void Colorize(Range range, int color) + internal void Colorize(IXLRange range, int color) { - range.Interior.Color = color; - range.Worksheet.Tab.Color = color; + // Convert int color to Color object + Color backgroundColor = Color.FromArgb(color); + range.Style.Fill.BackgroundColor = XLColor.FromColor(backgroundColor); + + // Set worksheet tab color + range.Worksheet.SetTabColor(XLColor.FromColor(backgroundColor)); } #endregion @@ -178,9 +195,7 @@ namespace ENI2.Excel public void Save(string path) { - this._workBook.SaveAs(path, XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, - Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); - this._workBook.Saved = true; + _workBook.SaveAs(path); } #endregion @@ -191,33 +206,20 @@ namespace ENI2.Excel { try { - if (this._workBook != null) + if (_workBook != null) { - this._workBook.Close(0); - _log.Debug("Close Worksheet"); - Marshal.ReleaseComObject(this._workBook); - } - - if (this._excelWorkbooks != null) - { - this._excelWorkbooks.Close(); - _log.Debug("Close Workbooks"); - Marshal.ReleaseComObject(this._excelWorkbooks); - } - if (this._excelApp != null) - { - _log.Debug("Quit Excel"); - this._excelApp.Quit(); - Marshal.ReleaseComObject(this._excelApp); + _log.Debug("Disposing Workbook"); + _workBook.Dispose(); + _workBook = null; } } - catch(Exception ex) + catch (Exception ex) { - _log.ErrorFormat("Exception disposing ExcelReader: {0}", ex.Message); + _log.ErrorFormat("Exception disposing ExcelBase: {0}", ex.Message); } } #endregion } -} +} \ No newline at end of file diff --git a/ENI2/Excel/ExcelComparer.cs b/ENI2/Excel/ExcelComparer.cs index a78a8e4d..6db1ae7e 100644 --- a/ENI2/Excel/ExcelComparer.cs +++ b/ENI2/Excel/ExcelComparer.cs @@ -4,8 +4,7 @@ using System; using System.IO; -using System.Drawing; -using Microsoft.Office.Interop.Excel; +using ClosedXML.Excel; namespace ENI2.Excel { @@ -17,173 +16,132 @@ namespace ENI2.Excel /// public static class ExcelComparer { - private static readonly int diffColor = ColorTranslator.ToOle(Color.FromArgb(150, 150, 255)); // blue + private static readonly XLColor diffColor = XLColor.FromArgb(150, 150, 255); // blue - private static bool GetSheetRange(Worksheet sheet, out int lastUsedRow, out int lastUsedColumn) + private static bool GetSheetRange(IXLWorksheet sheet, out int lastUsedRow, out int lastUsedColumn) { try { - // sheet.Columns.ClearFormats(); - // sheet.Rows.ClearFormats(); - Range usedRange = sheet.UsedRange; - lastUsedRow = usedRange.Rows.Count; - lastUsedColumn = usedRange.Columns.Count; - - /* - Range last = sheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell, Type.Missing); - Range range = sheet.get_Range("A1", last); - - lastUsedRow = last.Row; - lastUsedColumn = last.Column; - */ - - return true; + var usedRange = sheet.RangeUsed(); + if (usedRange != null) + { + lastUsedRow = usedRange.RowCount(); + lastUsedColumn = usedRange.ColumnCount(); + return true; + } + else + { + lastUsedColumn = 0; + lastUsedRow = 0; + return false; + } } - catch(Exception) + catch (Exception) { lastUsedColumn = 0; lastUsedRow = 0; return false; } - } - - private static string GetExcelColumnName(int columnNumber) - { - string columnName = ""; - - while (columnNumber > 0) - { - int modulo = (columnNumber - 1) % 26; - columnName = Convert.ToChar('A' + modulo) + columnName; - columnNumber = (columnNumber - modulo) / 26; - } - - return columnName; - } + } public static string Compare(string sourcePath, string targetPath, string comparisonFileName, out string errorMessage) - { + { errorMessage = ""; int counter = 0; try { - File.Copy(targetPath, comparisonFileName); - ExcelReader source = new ExcelReader(sourcePath, true, false); - ExcelReader comparison = new ExcelReader(comparisonFileName, false, false); + File.Copy(targetPath, comparisonFileName, true); - /* erste Variante Vergleich über Namen der Zellen - - // loop through named cells - foreach (string name in comparison.NameDict.Keys) + using (var sourceWorkbook = new XLWorkbook(sourcePath)) + using (var comparisonWorkbook = new XLWorkbook(comparisonFileName)) { - if (!source.NameDict.ContainsKey(name)) continue; - string sourceText = source.ReadText(name); - string targetText = comparison.ReadText(name); - - if (sourceText == null) + // Es werden Zellen der "used range" miteinander verglichen + foreach (var sourceSheet in sourceWorkbook.Worksheets) { - if (targetText != null) + IXLWorksheet targetSheet = null; + foreach (var sheet in comparisonWorkbook.Worksheets) { - comparison.Colorize(name, diffColor); - counter++; - } - } - else if (targetText == null) - { - if (sourceText != null) - { - comparison.Colorize(name, diffColor); - counter++; - } - } - else if ((sourceText != null) && (targetText != null)) - { - if (!sourceText.Equals(targetText)) - { - // turn cell blue - comparison.Colorize(name, diffColor); - counter++; - } - } - } - */ - - // Zweite Version durch alle Sheets werden Zellen der "used range" miteinander verglichen - - foreach(Worksheet sourceSheet in source.Worksheets) - { - Worksheet targetSheet = null; - foreach(Worksheet sheet in comparison.Worksheets) - { - if (sourceSheet.Name.Equals(sheet.Name)) - { - targetSheet = sheet; - break; - } - } - - if (targetSheet == null) continue; - System.Diagnostics.Trace.WriteLine(string.Format("Processing sheet {0}", targetSheet.Name)); - - if(GetSheetRange(sourceSheet, out int sourceRows, out int sourceCols) && GetSheetRange(targetSheet, out int targetRows, out int targetCols)) - { - // read source into 2 dim array - string rangeString = string.Format("A1:{0}{1}", GetExcelColumnName(Math.Max(sourceCols, targetCols)), Math.Max(sourceRows, targetRows)); - object[,] sourceArray = sourceSheet.get_Range(rangeString).Value; - // read target into 2 dim array - object[,] targetArray = targetSheet.get_Range(rangeString).Value; - - for (int rowidx = 1; rowidx <= Math.Max(sourceRows, targetRows); rowidx++) - { - for( int colidx = 1; colidx <= Math.Max(sourceCols, targetCols); colidx++) + if (sourceSheet.Name.Equals(sheet.Name)) { - string sourceText = null; - if(sourceArray[rowidx,colidx] != null) sourceText = sourceArray[rowidx,colidx].ToString(); - string targetText = null; - if(targetArray[rowidx,colidx] != null) targetText = targetArray[rowidx, colidx].ToString(); - - if (sourceText == null) - { - if (targetText != null) - { - string targetRangeName = string.Format("{0}{1}", GetExcelColumnName(colidx), rowidx); - comparison.Colorize(targetSheet.Range[targetRangeName], diffColor); - counter++; - } - } - else if (targetText == null) - { - if (sourceText != null) - { - string targetRangeName = string.Format("{0}{1}", GetExcelColumnName(colidx), rowidx); - comparison.Colorize(targetSheet.Range[targetRangeName], diffColor); - counter++; - } - } - else if ((sourceText != null) && (targetText != null)) - { - if (!sourceText.Equals(targetText)) - { - string targetRangeName = string.Format("{0}{1}", GetExcelColumnName(colidx), rowidx); - // turn cell blue - comparison.Colorize(targetSheet.Range[targetRangeName], diffColor); - counter++; - } - } - + targetSheet = sheet; + break; } } - } - else - { - errorMessage = "failed to get sheet ranges"; - } - } - comparison.Save(comparisonFileName); - source.Dispose(); - comparison.Dispose(); + if (targetSheet == null) continue; + System.Diagnostics.Trace.WriteLine(string.Format("Processing sheet {0}", targetSheet.Name)); + + if (GetSheetRange(sourceSheet, out int sourceRows, out int sourceCols) && GetSheetRange(targetSheet, out int targetRows, out int targetCols)) + { + int maxRows = Math.Max(sourceRows, targetRows); + int maxCols = Math.Max(sourceCols, targetCols); + + for (int rowidx = 1; rowidx <= maxRows; rowidx++) + { + for (int colidx = 1; colidx <= maxCols; colidx++) + { + string sourceText = null; + string targetText = null; + + // Get source cell value + if (rowidx <= sourceRows && colidx <= sourceCols) + { + var sourceCell = sourceSheet.Cell(rowidx, colidx); + if (!sourceCell.IsEmpty()) + { + sourceText = sourceCell.GetString(); + } + } + + // Get target cell value + if (rowidx <= targetRows && colidx <= targetCols) + { + var targetCell = targetSheet.Cell(rowidx, colidx); + if (!targetCell.IsEmpty()) + { + targetText = targetCell.GetString(); + } + } + + if (sourceText == null) + { + if (targetText != null) + { + var cellToHighlight = targetSheet.Cell(rowidx, colidx); + cellToHighlight.Style.Fill.BackgroundColor = diffColor; + counter++; + } + } + else if (targetText == null) + { + if (sourceText != null) + { + var cellToHighlight = targetSheet.Cell(rowidx, colidx); + cellToHighlight.Style.Fill.BackgroundColor = diffColor; + counter++; + } + } + else if ((sourceText != null) && (targetText != null)) + { + if (!sourceText.Equals(targetText)) + { + var cellToHighlight = targetSheet.Cell(rowidx, colidx); + cellToHighlight.Style.Fill.BackgroundColor = diffColor; + counter++; + } + } + } + } + } + else + { + errorMessage = "failed to get sheet ranges"; + } + } + + comparisonWorkbook.SaveAs(comparisonFileName); + } errorMessage = string.Format("{0} differences found", counter); } catch (Exception ex) @@ -193,6 +151,5 @@ namespace ENI2.Excel return comparisonFileName; } - } -} +} \ No newline at end of file diff --git a/ENI2/Excel/ExcelLocalImportHelper.cs b/ENI2/Excel/ExcelLocalImportHelper.cs new file mode 100644 index 00000000..84545948 --- /dev/null +++ b/ENI2/Excel/ExcelLocalImportHelper.cs @@ -0,0 +1,246 @@ +using bsmd.database; +using ClosedXML.Excel; +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.IO; +using System.Windows; + +namespace ENI2.Excel +{ + internal static class ExcelLocalImportHelper + { + + #region Last 10 Port Facilities Called Import from Excel + + public static int ImportLast10PortFacilities(SEC sec) + { + int cnt = 0; + + OpenFileDialog ofd = new OpenFileDialog + { + Filter = "Excel Files|*.xls;*.xlsx" + }; + + if (ofd.ShowDialog() ?? false) + { + try + { + using (var workbook = new XLWorkbook(ofd.FileName)) + { + var worksheet = workbook.Worksheet(1); + var rows = worksheet.RangeUsed().RowsUsed(); + int columnCount = worksheet.RangeUsed().ColumnCount(); + + // Check minimum columns upfront + if (columnCount < 8) + { + throw new InvalidDataException("Sheet must have at least 8 Columns of data"); + } + + List importL10C = new List(); + + + foreach (var row in rows) + { + if (cnt >= 10) break; // Maximum 10 rows + + // Skip empty rows + if (row.Cell(1).IsEmpty() && row.Cell(2).IsEmpty()) continue; + + LastTenPortFacilitiesCalled l10c = new LastTenPortFacilitiesCalled(); + + try + { + // Column 1: Port Name + if (!row.Cell(1).IsEmpty()) + l10c.PortFacilityPortName = row.Cell(1).GetString(); + + // Column 3: Country + if (!row.Cell(3).IsEmpty()) + l10c.PortFacilityPortCountry = row.Cell(3).GetString(); + + // Column 4: Locode + if (!row.Cell(4).IsEmpty()) + l10c.PortFacilityPortLoCode = row.Cell(4).GetString(); + + // Column 5: Arrival Date + if (!row.Cell(5).IsEmpty()) + { + l10c.PortFacilityDateOfArrival = row.Cell(5).GetDateTime(); + } + + // Column 6: Departure Date + if (!row.Cell(6).IsEmpty()) + { + l10c.PortFacilityDateOfDeparture = row.Cell(6).GetDateTime(); + } + + // Column 7: Security Level (byte) + if (!row.Cell(7).IsEmpty()) + { + l10c.PortFacilityShipSecurityLevel = row.Cell(7).GetValue(); + } + + // Column 8: GISIS Code + if (!row.Cell(8).IsEmpty()) + { + int gisis = row.Cell(8).GetValue(); + l10c.PortFacilityGISISCode = gisis.ToString().PadLeft(4, '0'); + } + + // Column 9: Security Matters (optional, can be beyond minimum columns) + if (columnCount >= 9 && !row.Cell(9).IsEmpty()) + { + l10c.PortFacilitySecurityMattersToReport = row.Cell(9).GetString(); + if (l10c.PortFacilitySecurityMattersToReport?.Equals("nil", StringComparison.OrdinalIgnoreCase) == true) + l10c.PortFacilitySecurityMattersToReport = null; + } + + // Column 10: GISIS Code Locode (optional, can be beyond minimum columns) + if (columnCount >= 10 && !row.Cell(10).IsEmpty()) + { + l10c.PortFacilityGISISCodeLocode = row.Cell(10).GetString(); + } + + l10c.SEC = sec; + l10c.IsDirty = true; + l10c.Identifier = LastTenPortFacilitiesCalled.GetNewIdentifier(sec.LastTenPortFacilitesCalled); + sec.LastTenPortFacilitesCalled.Add(l10c); + importL10C.Add(l10c); + cnt++; + } + catch (Exception ex) + { + throw new InvalidDataException($"Error processing row {row.RowNumber()}: {ex.Message}", ex); + } + } + } + } + catch (Exception ex) + { + MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, + MessageBoxButton.OK, MessageBoxImage.Error); + } + } + + return cnt; + } + + #endregion + + #region Last 30 days Import from Excel + + public static int ImportLast30Days(MDH mdh) + { + int cnt = 0; + + OpenFileDialog ofd = new OpenFileDialog + { + Filter = "Excel Files|*.xls;*.xlsx" + }; + + if (ofd.ShowDialog() ?? false) + { + try + { + using (var workbook = new XLWorkbook(ofd.FileName)) + { + var worksheet = workbook.Worksheet(1); + var rows = worksheet.RangeUsed().RowsUsed(); + int columnCount = worksheet.RangeUsed().ColumnCount(); + + List importPoC30 = new List(); + + foreach (var row in rows) + { + if (row.RowNumber() > worksheet.RangeUsed().RowCount()) break; + + if (columnCount < 3) + { + throw new InvalidDataException("Sheet must have at least 3 Columns of data"); + } + + PortOfCallLast30Days poc30 = new PortOfCallLast30Days(); + + if (row.Cell(1).IsEmpty() && row.Cell(2).IsEmpty()) continue; + + // Safer locode extraction + if (!row.Cell(1).IsEmpty()) + { + try + { + poc30.PortOfCallLast30DaysLocode = row.Cell(1).GetString(); + } + catch (Exception ex) + { + throw new InvalidDataException($"Invalid locode in row {row.RowNumber()}: {ex.Message}"); + } + } + + // Safer date extraction + if (!row.Cell(2).IsEmpty()) + { + try + { + poc30.PortOfCallLast30DaysDateOfDeparture = row.Cell(2).GetDateTime(); + } + catch (Exception ex) + { + throw new InvalidDataException($"Invalid date in row {row.RowNumber()}: {ex.Message}"); + } + } + + // Safer boolean extraction + string boolString = ""; + if (!row.Cell(3).IsEmpty()) + { + boolString = row.Cell(3).GetString()?.Trim() ?? ""; + } + poc30.PortOfCallLast30DaysCrewMembersJoined = ( + boolString.Equals("y", StringComparison.OrdinalIgnoreCase) || + boolString.Equals("yes", StringComparison.OrdinalIgnoreCase) || + boolString.Equals("j", StringComparison.OrdinalIgnoreCase)); + + // FIX: Check column count before accessing column 4 + if (columnCount >= 4) + { + string allNewCrew = row.Cell(4).IsEmpty() ? null : row.Cell(4).GetString()?.Trim(); + if (!allNewCrew.IsNullOrEmpty()) + { + string[] crewNames = allNewCrew.Split(',', ';'); + foreach (string crewName in crewNames) + { + string trimmedName = crewName.Trim(); + if (trimmedName.IsNullOrEmpty()) continue; + + PortOfCallLast30DaysCrewJoinedShip poc30Crew = new PortOfCallLast30DaysCrewJoinedShip + { + PortOfCallLast30DaysCrewJoinedShipName = trimmedName, + PortOfCallLast30Days = poc30 + }; + poc30.CrewJoinedShip.Add(poc30Crew); + } + } + } + + poc30.MDH = mdh; + mdh.PortOfCallLast30Days.Add(poc30); + importPoC30.Add(poc30); + } + } + } + catch (Exception ex) + { + MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, + MessageBoxButton.OK, MessageBoxImage.Error); + } + } + + return cnt; + } + + #endregion + + } +} diff --git a/ENI2/Excel/ExcelReader.cs b/ENI2/Excel/ExcelReader.cs index 8e32e24f..8a5c8edf 100644 --- a/ENI2/Excel/ExcelReader.cs +++ b/ENI2/Excel/ExcelReader.cs @@ -9,13 +9,12 @@ using bsmd.database; using ENI2.Locode; -using Microsoft.Office.Interop.Excel; +using ClosedXML.Excel; using System; using System.Collections.Generic; using System.Data; using System.Globalization; using System.Linq; -using System.Runtime.InteropServices; namespace ENI2.Excel { @@ -31,9 +30,9 @@ namespace ENI2.Excel internal Dictionary ImportValues { get; } = new Dictionary(); - public ExcelReader(string filePath, bool openReadonly = true, bool createNameFields = true) + public ExcelReader(string filePath, bool createNameFields = true) { - this._workBook = _excelWorkbooks.Open(filePath, 0, openReadonly, 5, "", "", false, XlPlatform.xlWindows, "", false, false, 0, false, false, false); + this._workBook = new XLWorkbook(filePath); if (createNameFields) this.InitNameFields(); @@ -69,16 +68,20 @@ namespace ENI2.Excel { try { - var val = _nameDict[lookup].RefersToRange.Value; - var val2 = _nameDict[lookup].RefersToRange.Value2; - if (val != null) - result = val.ToString().Trim(); - else if (val2 != null) - result = val2.ToString().Trim(); + var definedName = _nameDict[lookup]; + var range = definedName.Ranges.FirstOrDefault(); + if (range != null) + { + var cell = range.FirstCell(); + if (cell != null && !cell.Value.IsBlank) + { + result = cell.Value.ToString().Trim(); + } + } } - catch (COMException ex) + catch (Exception ex) { - _log.WarnFormat("COMException reading field {0}: {1}", lookup, ex.ErrorCode); + _log.WarnFormat("Exception reading field {0}: {1}", lookup, ex.Message); } } if (result != null) @@ -283,7 +286,7 @@ namespace ENI2.Excel } } return val; - } + } internal byte? ReadHullConfiguration(string lookup) { @@ -441,47 +444,61 @@ namespace ENI2.Excel if (_nameDict.ContainsKey(lookup)) { - var val = _nameDict[lookup].RefersToRange.Value; - if (val is DateTime) + var definedName = _nameDict[lookup]; + var range = definedName.Ranges.FirstOrDefault(); + if (range != null) { - date = val; - } - else if (val is double) - { - try + var cell = range.FirstCell(); + if (cell != null && !cell.Value.IsBlank) { - date = DateTime.FromOADate(val); + var cellValue = cell.Value; + + if (cellValue.IsDateTime) + { + date = cellValue.GetDateTime(); + } + else if (cellValue.IsNumber) + { + double numValue = 0; + try + { + numValue = cellValue.GetNumber(); + date = DateTime.FromOADate(numValue); + } + catch (ArgumentException) { /* .. */ } + + if (date == null) + { + CultureInfo provider = CultureInfo.InvariantCulture; + string dateString = numValue.ToString(); + const string format = "yyyyMMdd"; + if (DateTime.TryParseExact(dateString, format, provider, DateTimeStyles.None, out DateTime tmpDate)) + date = tmpDate; + } + } + else if (cellValue.IsText) + { + string textValue = cellValue.GetText(); + + if (DateTime.TryParse(textValue, out DateTime tmpDate)) + date = tmpDate; + + if (date == null) + { + string[] formats = { "d/M/yyyy", "dd/M/yyyy", "d/MM/yyyy", "dd/MM/yyyy", "d/MMM/yyyy", "dd/MMM/yyyy", "yyyy-MM-dd", "yyyy-mm-d", "dd-MM-yyyy" }; + if (DateTime.TryParseExact(textValue, formats, NumberFormatInfo.InvariantInfo, DateTimeStyles.None, out DateTime tmpDate2)) + date = tmpDate2; + } + + if (date == null) + { + CultureInfo en = CultureInfo.CreateSpecificCulture("en-US"); + string[] formats = { "d/M/yyyy", "dd/M/yyyy", "d/MM/yyyy", "dd/MM/yyyy", "d/MMM/yyyy", "dd/MMM/yyyy", "yyyy-MM-dd", "yyyy-mm-d", "dd-MM-yyyy" }; + if (DateTime.TryParseExact(textValue, formats, en, DateTimeStyles.None, out DateTime tmpDate3)) + date = tmpDate3; + } + } } - catch (ArgumentException) { /* .. */ } - if (date == null) - { - CultureInfo provider = CultureInfo.InvariantCulture; - string dateString = val.ToString(); - const string format = "yyyyMMdd"; - if (DateTime.TryParseExact(dateString, format, provider, DateTimeStyles.None, out DateTime tmpDate)) - date = tmpDate; - } - } - - if (date == null) - { - if (DateTime.TryParse(val, out DateTime tmpDate)) - date = tmpDate; - } - - if (date == null) - { - string[] formats = { "d/M/yyyy", "dd/M/yyyy", "d/MM/yyyy", "dd/MM/yyyy", "d/MMM/yyyy", "dd/MMM/yyyy", "yyyy-MM-dd", "yyyy-mm-d", "dd-MM-yyyy" }; - if (DateTime.TryParseExact(val, formats, NumberFormatInfo.InvariantInfo, DateTimeStyles.None, out DateTime tmpDate)) - date = tmpDate; - } - - if (date == null) - { - CultureInfo en = CultureInfo.CreateSpecificCulture("en-US"); - string[] formats = { "d/M/yyyy", "dd/M/yyyy", "d/MM/yyyy", "dd/MM/yyyy", "d/MMM/yyyy", "dd/MMM/yyyy", "yyyy-MM-dd", "yyyy-mm-d", "dd-MM-yyyy" }; - if (DateTime.TryParseExact(val, formats, en, DateTimeStyles.None, out DateTime tmpDate)) - return tmpDate; } if (date != null) @@ -532,61 +549,72 @@ namespace ENI2.Excel { if (_nameDict.ContainsKey(lookup)) { - var val = _nameDict[lookup].RefersToRange.Value; - if (val is DateTime) + var definedName = _nameDict[lookup]; + var range = definedName.Ranges.FirstOrDefault(); + if (range != null) { - result = val; - } - if (val is double) - { - try + var cell = range.FirstCell(); + if (cell != null && !cell.Value.IsBlank) { - result = DateTime.FromOADate(val); - } - catch (ArgumentException) { } + var cellValue = cell.Value; - if (result == null) - { - CultureInfo provider = CultureInfo.InvariantCulture; - string dateString = val.ToString(); - if (!dateString.Contains(":")) + if (cellValue.IsDateTime) { - const string format = "HHmm"; - if (DateTime.TryParseExact(dateString, format, provider, DateTimeStyles.None, out DateTime tmpDate)) - result = tmpDate; + result = cellValue.GetDateTime(); } - } - } + else if (cellValue.IsTimeSpan) + { + TimeSpan timespan = cellValue.GetTimeSpan(); + result = new DateTime(timespan.Ticks); + } + else if (cellValue.IsNumber) + { + double numValue = 0; + try + { + numValue = cellValue.GetNumber(); + result = DateTime.FromOADate(numValue); + } + catch (ArgumentException) { } - if (val is string @string) - { - if (@string.EndsWith("lt", StringComparison.OrdinalIgnoreCase)) - val = @string.Substring(0, @string.Length - 2).Trim(); - else - val = @string.Trim(); - } + if (result == null) + { + CultureInfo provider = CultureInfo.InvariantCulture; + string dateString = numValue.ToString(); + if (!dateString.Contains(":")) + { + const string format = "HHmm"; + if (DateTime.TryParseExact(dateString, format, provider, DateTimeStyles.None, out DateTime tmpDate)) + result = tmpDate; + } + } + } + else if (cellValue.IsText) + { + string textValue = cellValue.GetText(); - if (result == null) - { - if (DateTime.TryParseExact(val, "HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.NoCurrentDateDefault, out DateTime date)) - result = date; - } + if (textValue.EndsWith("lt", StringComparison.OrdinalIgnoreCase)) + textValue = textValue.Substring(0, textValue.Length - 2).Trim(); + else + textValue = textValue.Trim(); - if (result == null) - { - if (DateTime.TryParseExact(val, "HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.NoCurrentDateDefault, out DateTime date)) - result = date; - } + if (DateTime.TryParseExact(textValue, "HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.NoCurrentDateDefault, out DateTime date)) + result = date; - if ((result == null) && (val != null)) - { - CultureInfo provider = CultureInfo.InvariantCulture; - string dateString = val.ToString(); - if (!dateString.Contains(":")) - { - const string format = "HHmm"; - if (DateTime.TryParseExact(dateString, format, provider, DateTimeStyles.None, out DateTime tmpDate)) - result = tmpDate; + if (result == null) + { + if (DateTime.TryParseExact(textValue, "HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.NoCurrentDateDefault, out DateTime date2)) + result = date2; + } + + if (result == null && !textValue.Contains(":")) + { + CultureInfo provider = CultureInfo.InvariantCulture; + const string format = "HHmm"; + if (DateTime.TryParseExact(textValue, format, provider, DateTimeStyles.None, out DateTime tmpDate)) + result = tmpDate; + } + } } } } @@ -627,7 +655,7 @@ namespace ENI2.Excel { try { - Worksheet theWorkSheet = _workBook.Worksheets[sheetName]; + var theWorkSheet = _workBook.Worksheets.Worksheet(sheetName); return theWorkSheet != null; } catch (Exception) @@ -640,12 +668,13 @@ namespace ENI2.Excel { try { - Worksheet workSheet = (Worksheet)_workBook.Worksheets[sheetName]; - string result = workSheet.Range[range].Text.ToString(); + var workSheet = _workBook.Worksheets.Worksheet(sheetName); + var cell = workSheet.Range(range).FirstCell(); + string result = cell.Value.ToString(); if (!result.IsNullOrEmpty()) { result = result.Trim().Clean(); - if(maxLength.HasValue && result.Length > maxLength.Value) + if (maxLength.HasValue && result.Length > maxLength.Value) { result = result.Substring(0, maxLength.Value); } @@ -663,8 +692,9 @@ namespace ENI2.Excel { try { - Worksheet workSheet = (Worksheet)_workBook.Worksheets[sheetName]; - string result = workSheet.Range[row, col].Text.ToString(); + var workSheet = _workBook.Worksheets.Worksheet(sheetName); + var cell = workSheet.Cell(row, col); + string result = cell.Value.ToString(); if (!result.IsNullOrEmpty()) result = result.Trim().Clean(); return result; @@ -681,10 +711,11 @@ namespace ENI2.Excel { try { - Worksheet workSheet = (Worksheet)_workBook.Worksheets[sheetName]; - Range aRange = workSheet.Range[range]; + var workSheet = _workBook.Worksheets.Worksheet(sheetName); + var aRange = workSheet.Range(range); if (aRange != null) { + // TODO: Implement dropdown reading logic for ClosedXML } } catch (Exception e) @@ -713,26 +744,27 @@ namespace ENI2.Excel try { double? result = null; - Worksheet workSheet = (Worksheet)_workBook.Worksheets[sheetName]; - var val = workSheet.Range[range].Value; - if (val is double) result = val; - if (val is string) + var workSheet = _workBook.Worksheets.Worksheet(sheetName); + var cell = workSheet.Range(range).FirstCell(); + var cellValue = cell.Value; + + if (cellValue.IsNumber) { - if (double.TryParse(val, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, + result = cellValue.GetNumber(); + } + else if (cellValue.IsText) + { + string textValue = cellValue.GetText(); + if (double.TryParse(textValue, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture, out double tmpDouble)) result = tmpDouble; if (result == null) { - if (double.TryParse(val, out tmpDouble)) // current language style (==GER, mit , statt .) + if (double.TryParse(textValue, out tmpDouble)) // current language style (==GER, mit , statt .) result = tmpDouble; } } - if ((result == null) && (val != null)) - { - double tmpDouble2 = val[1, 1]; - result = tmpDouble2; - } return result; } catch (Exception e) @@ -747,7 +779,7 @@ namespace ENI2.Excel string dateString = ReadCellAsText(sheetName, range); if (dateString != null) { - string[] formats = { "yyyy/MM/dd HH:mm", "yyyy/MM/dd", "dd.MM.yyyy", "dd-MM-yyyy", "d/M/yyyy", "dd/M/yyyy", "d/MM/yyyy", "dd/MM/yyyy", "d/MMM/yyyy", "dd/MMM/yyyy", "yyyy-MM-dd", "yyyy-mm-d" }; + string[] formats = { "yyyy/MM/dd HH:mm", "yyyy/MM/dd", "dd.MM.yyyy", "dd-MM-yyyy", "d/M/yyyy", "dd/M/yyyy", "d/MM/yyyy", "dd/MM/yyyy", "d/MMM/yyyy", "dd/MMM/yyyy", "yyyy-MM-dd", "yyyy-MM-d", "dd.MM.yyyy HH:mm:ss", "dd.MM.yyyy HH:mm" }; if (DateTime.TryParseExact(dateString, formats, NumberFormatInfo.InvariantInfo, DateTimeStyles.None, out DateTime tmpDate)) return tmpDate; CultureInfo en = CultureInfo.CreateSpecificCulture("en-US"); @@ -759,7 +791,6 @@ namespace ENI2.Excel return null; } - #endregion Dakosy-specific functions } } \ No newline at end of file diff --git a/ENI2/Excel/ExcelSimpleWriter.cs b/ENI2/Excel/ExcelSimpleWriter.cs index 4f73552d..77f32bf4 100644 --- a/ENI2/Excel/ExcelSimpleWriter.cs +++ b/ENI2/Excel/ExcelSimpleWriter.cs @@ -1,12 +1,10 @@ -using System; +// Copyright (c) 2017- schick Informatik +// Description: Dumps Maersk data into a simple Excel file +// + +using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using Microsoft.Office.Interop.Excel; -using System.Runtime.InteropServices; - +using ClosedXML.Excel; using bsmd.database; namespace ENI2.Excel @@ -17,68 +15,58 @@ namespace ENI2.Excel { data.Sort(); - Application excelApp = new Application(); - excelApp.DisplayAlerts = false; - excelApp.Visible = false; - Workbook wb = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet); - - Worksheet ws = wb.Worksheets[1]; - - // Überschriften erste Zeile - ws.Cells[1, 1] = "ETA"; - ws.Cells[1, 2] = "ETD"; - ws.Cells[1, 3] = "Rotation name"; - ws.Cells[1, 4] = "Vessel code"; - ws.Cells[1, 5] = "Vessel name"; - ws.Cells[1, 6] = "IMO"; - ws.Cells[1, 7] = "Arr voy"; - ws.Cells[1, 8] = "Dep voy"; - ws.Cells[1, 9] = "Terminal name"; - ws.Cells[1, 10] = "Operator code"; - ws.Cells[1, 11] = "Pro arr"; - ws.Cells[1, 12] = "Pro dep"; - ws.Cells[1, 13] = "ID"; - ws.Cells[1, 14] = "Remark"; - - for (int i = 0; i < data.Count; i++) + using (var workbook = new XLWorkbook()) { - MaerskData md = data[i]; + var worksheet = workbook.Worksheets.Add("Sheet1"); - ws.Cells[i + 2, 1].NumberFormat = "TT/hh:mm"; - ws.Cells[i + 2, 1] = md.ColA; - ws.Cells[i + 2, 2].NumberFormat = "TT/hh:mm"; - ws.Cells[i + 2, 2] = md.ColB; - ws.Cells[i + 2, 3] = md.ColC; - ws.Cells[i + 2, 4] = md.ColD; - ws.Cells[i + 2, 5] = md.ColE; - ws.Cells[i + 2, 6] = md.ColF; - ws.Cells[i + 2, 7] = md.ColG; - ws.Cells[i + 2, 8] = md.ColH; - ws.Cells[i + 2, 9] = md.ColI; - ws.Cells[i + 2, 10] = md.ColJ; - ws.Cells[i + 2, 11] = md.ColK; - ws.Cells[i + 2, 12] = md.ColL; - ws.Cells[i + 2, 13] = md.ColM ; - ws.Cells[i + 2, 14] = md.Remark; + // Headers in first row + worksheet.Cell(1, 1).Value = "ETA"; + worksheet.Cell(1, 2).Value = "ETD"; + worksheet.Cell(1, 3).Value = "Rotation name"; + worksheet.Cell(1, 4).Value = "Vessel code"; + worksheet.Cell(1, 5).Value = "Vessel name"; + worksheet.Cell(1, 6).Value = "IMO"; + worksheet.Cell(1, 7).Value = "Arr voy"; + worksheet.Cell(1, 8).Value = "Dep voy"; + worksheet.Cell(1, 9).Value = "Terminal name"; + worksheet.Cell(1, 10).Value = "Operator code"; + worksheet.Cell(1, 11).Value = "Pro arr"; + worksheet.Cell(1, 12).Value = "Pro dep"; + worksheet.Cell(1, 13).Value = "ID"; + worksheet.Cell(1, 14).Value = "Remark"; - if((md.MessageCore != null) && (md.MessageCore.Cancelled ?? false)) + for (int i = 0; i < data.Count; i++) { - ws.Rows[i + 2].Font.Strikethrough = true; + MaerskData md = data[i]; + int row = i + 2; // Data starts from row 2 + + worksheet.Cell(row, 1).Value = md.ColA; + worksheet.Cell(row, 1).Style.NumberFormat.Format = "dd/hh:mm"; + + worksheet.Cell(row, 2).Value = md.ColB; + worksheet.Cell(row, 2).Style.NumberFormat.Format = "dd/hh:mm"; + + worksheet.Cell(row, 3).Value = md.ColC; + worksheet.Cell(row, 4).Value = md.ColD; + worksheet.Cell(row, 5).Value = md.ColE; + worksheet.Cell(row, 6).Value = md.ColF; + worksheet.Cell(row, 7).Value = md.ColG; + worksheet.Cell(row, 8).Value = md.ColH; + worksheet.Cell(row, 9).Value = md.ColI; + worksheet.Cell(row, 10).Value = md.ColJ; + worksheet.Cell(row, 11).Value = md.ColK; + worksheet.Cell(row, 12).Value = md.ColL; + worksheet.Cell(row, 13).Value = md.ColM; + worksheet.Cell(row, 14).Value = md.Remark; + + if ((md.MessageCore != null) && (md.MessageCore.Cancelled ?? false)) + { + worksheet.Row(row).Style.Font.Strikethrough = true; + } } + workbook.SaveAs(filename); } - - wb.SaveAs(filename, XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, - Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, - Type.Missing, Type.Missing); - wb.Saved = true; - wb.Close(0); - - Marshal.ReleaseComObject(ws); - Marshal.ReleaseComObject(wb); - - excelApp.Quit(); - Marshal.ReleaseComObject(excelApp); } } -} +} \ No newline at end of file diff --git a/ENI2/Excel/ExcelUtil.cs b/ENI2/Excel/ExcelUtil.cs index 003f25e7..99c4c2ea 100644 --- a/ENI2/Excel/ExcelUtil.cs +++ b/ENI2/Excel/ExcelUtil.cs @@ -1702,7 +1702,7 @@ namespace ENI2.Excel string s = reader.ReadCellAsText(sheetTitle, string.Format("J{0}", 54 + i)); // All invalid codes become "0000", Oct/25 - l10fc.PortFacilityGISISCode = (s != null) && Regex.IsMatch(s.Trim(), @"^\d{4}$") ? s.Trim() : "0000"; + l10fc.PortFacilityGISISCode = (s != null) && Regex.IsMatch(s.Trim(), @"^\d{1,4}$") ? s.Trim().PadLeft(4, '0') : "0000"; l10fc.PortFacilitySecurityMattersToReport = reader.ReadCellAsText(sheetTitle, string.Format("K{0}", 54 + i), 255); diff --git a/ENI2/Excel/ExcelWriter.cs b/ENI2/Excel/ExcelWriter.cs index cf3055fb..de1c3ab7 100644 --- a/ENI2/Excel/ExcelWriter.cs +++ b/ENI2/Excel/ExcelWriter.cs @@ -1,8 +1,8 @@ // Copyright (c) 2017- schick Informatik -// Description: +// Description: Writing excel files // -using Microsoft.Office.Interop.Excel; +using ClosedXML.Excel; using System; using System.Collections.Generic; using System.Data; @@ -26,10 +26,9 @@ namespace ENI2.Excel if (isRefSheet) filename = @"Excel\Reference_Sheet_DE.xlsx"; string refFilePath = System.IO.Path.Combine(Environment.CurrentDirectory, filename); - this._workBook = _excelWorkbooks.Open(refFilePath, 0, true, 5, "", "", false, XlPlatform.xlWindows, "", false, false, 0, false, false, false); + this._workBook = new XLWorkbook(refFilePath); this.InitNameFields(); - } #endregion @@ -44,7 +43,7 @@ namespace ENI2.Excel { try { - switch(message.MessageNotificationClass) + switch (message.MessageNotificationClass) { case Message.NotificationClass.AGNT: if (message.Elements[0] is AGNT agnt) this.WriteMessage(agnt); @@ -84,10 +83,10 @@ namespace ENI2.Excel break; case Message.NotificationClass.HAZA: this.WriteHAZ(message, true); - break; + break; case Message.NotificationClass.HAZD: this.WriteHAZ(message, false); - break; + break; case Message.NotificationClass.INFO: if (message.Elements[0] is INFO info) { @@ -192,11 +191,6 @@ namespace ENI2.Excel } - public void WriteMaerskList(List maerskList) - { - - } - #endregion #region private excel field writing @@ -242,7 +236,7 @@ namespace ENI2.Excel else if (property.PropertyType == typeof(Boolean?)) { object boolVal = property.GetValue(dbEntity); - if(boolVal != null) + if (boolVal != null) success = this.WriteBoolean(lookupNameAttribute.LookupName, boolVal); } else @@ -374,18 +368,21 @@ namespace ENI2.Excel #endregion + // [Rest of the methods remain exactly the same as they only call the base class methods] + // I'll include a few key ones to show the pattern, but the rest are identical... + #region CREW private void WriteCREW(Message crewMessage, bool isArrival, bool isRefSheet) { - + if (crewMessage.Elements.Count > 0) { WriteBoolean(string.Format("CREW{0}.NotificationSchengen", isArrival ? "" : "D"), ((CREW)crewMessage.Elements[0]).NotificationSchengen); WriteBoolean(string.Format("CREW{0}.NotificationPAX", isArrival ? "" : "D"), ((CREW)crewMessage.Elements[0]).NotificationPAX); - } + } - for(int i = 0; i 0) { WriteBoolean(string.Format("PAS{0}.NotificationSchengen", isArrival ? "" : "D"), ((PAS)pasMessage.Elements[0]).NotificationSchengen); WriteBoolean(string.Format("PAS{0}.NotificationPAX", isArrival ? "" : "D"), ((PAS)pasMessage.Elements[0]).NotificationPAX); - } + } for(int i = 0; i < Math.Min(pasMessage.NumberOfExcelRows, pasMessage.Elements.Count); i++) { @@ -1066,7 +1063,7 @@ namespace ENI2.Excel string tLen = string.Format("TOWD.TowageOnDepartureLengthOverall_MTR_{0}", i + 1); string tBeam = string.Format("TOWD.TowageOnDepartureBeam_MTR_{0}", i + 1); string tOp = string.Format("TOWD.TowageOnDepartureOperatorCompanyName_{0}", i + 1); - string tPoc = string.Format("TOWD.TowageOnDeparturePurposeOfCall_{0}", i + 1); + // string tPoc = string.Format("TOWD.TowageOnDeparturePurposeOfCall_{0}", i + 1); TOWD towd = towdMessage.Elements[i] as TOWD; @@ -1276,7 +1273,7 @@ namespace ENI2.Excel private void WriteGenderCode(string label, byte? gender) { - if(gender.HasValue) + if (gender.HasValue) { if (gender == 0) WriteText(label, "not known"); if (gender == 1) WriteText(label, "m"); @@ -1303,15 +1300,24 @@ namespace ENI2.Excel private bool WriteBoolean(string lookupName, object v) { bool result = _nameDict.ContainsKey(lookupName); - bool? b = (bool?) v; + bool? b = (bool?)v; try { if (result && b.HasValue) { - _nameDict[lookupName].RefersToRange.Value = b.Value ? "Y" : "N"; + var definedName = _nameDict[lookupName]; + var range = definedName.Ranges.FirstOrDefault(); + if (range != null) + { + var cell = range.FirstCell(); + if (cell != null) + { + cell.Value = b.Value ? "Y" : "N"; + } + } } } - catch(Exception) + catch (Exception) { System.Diagnostics.Trace.WriteLine(string.Format("Error writing {0} to excel, field missing", lookupName)); } @@ -1326,10 +1332,19 @@ namespace ENI2.Excel { if (result) { - _nameDict[lookupName].RefersToRange.Value = v; + var definedName = _nameDict[lookupName]; + var range = definedName.Ranges.FirstOrDefault(); + if (range != null) + { + var cell = range.FirstCell(); + if (cell != null) + { + cell.Value = ClosedXML.Excel.XLCellValue.FromObject(v); + } + } } } - catch(Exception) + catch (Exception) { System.Diagnostics.Trace.WriteLine(string.Format("Error writing {0} to excel, field missing", lookupName)); } @@ -1343,7 +1358,16 @@ namespace ENI2.Excel if (result) { - _nameDict[lookupName].RefersToRange.Value = v; + var definedName = _nameDict[lookupName]; + var range = definedName.Ranges.FirstOrDefault(); + if (range != null) + { + var cell = range.FirstCell(); + if (cell != null) + { + cell.Value = ClosedXML.Excel.XLCellValue.FromObject(v); + } + } } return result; @@ -1355,11 +1379,19 @@ namespace ENI2.Excel if (result) { - if(v != null) + if (v != null) { - _nameDict[lookupName].RefersToRange.Value = ((DateTime) v).ToLocalTime().ToOADate(); + var definedName = _nameDict[lookupName]; + var range = definedName.Ranges.FirstOrDefault(); + if (range != null) + { + var cell = range.FirstCell(); + if (cell != null) + { + cell.Value = ClosedXML.Excel.XLCellValue.FromObject(((DateTime)v).ToLocalTime()); + } + } } - } return result; @@ -1373,9 +1405,17 @@ namespace ENI2.Excel { if (v != null) { - _nameDict[lookupName].RefersToRange.Value = ((DateTime)v).ToLocalTime().ToShortTimeString(); + var definedName = _nameDict[lookupName]; + var range = definedName.Ranges.FirstOrDefault(); + if (range != null) + { + var cell = range.FirstCell(); + if (cell != null) + { + cell.Value = ((DateTime)v).ToLocalTime().ToString("HH:mm"); + } + } } - } return result; @@ -1386,4 +1426,4 @@ namespace ENI2.Excel #endregion } -} +} \ No newline at end of file diff --git a/ENI2/MainWindow.xaml b/ENI2/MainWindow.xaml index 5cfcc6b6..a7b8feea 100644 --- a/ENI2/MainWindow.xaml +++ b/ENI2/MainWindow.xaml @@ -10,9 +10,9 @@ xmlns:util="clr-namespace:ENI2.Util" xmlns:local="clr-namespace:ENI2" mc:Ignorable="d" - Title="ENI 2" - Height="{util:SettingBinding Height}" Width="{util:SettingBinding Width}" - Icon="Resources/logo_schwarz.ico" Loaded="Window_Loaded" Closing="Window_Closing" + Title="ENI 2" + Height="{util:SettingBinding Height}" Width="{util:SettingBinding Width}" + Icon="Resources/logo_schwarz.ico" Loaded="Window_Loaded" Closing="Window_Closing" SourceInitialized="Window_SourceInitialized"> diff --git a/ENI2/Properties/Settings.Designer.cs b/ENI2/Properties/Settings.Designer.cs index 6e0990e9..371adba4 100644 --- a/ENI2/Properties/Settings.Designer.cs +++ b/ENI2/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace ENI2.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.12.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.14.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/ENI2/Service References/LockingServiceReference/Reference.cs b/ENI2/Service References/LockingServiceReference/Reference.cs index 310941f9..e28d8634 100644 --- a/ENI2/Service References/LockingServiceReference/Reference.cs +++ b/ENI2/Service References/LockingServiceReference/Reference.cs @@ -117,7 +117,7 @@ namespace ENI2.LockingServiceReference { return this.CORRUPTFilesField; } set { - if ((ReferenceEquals(this.CORRUPTFilesField, value) != true)) { + if ((object.ReferenceEquals(this.CORRUPTFilesField, value) != true)) { this.CORRUPTFilesField = value; this.RaisePropertyChanged("CORRUPTFiles"); } @@ -143,7 +143,7 @@ namespace ENI2.LockingServiceReference { return this.IMPFilesField; } set { - if ((ReferenceEquals(this.IMPFilesField, value) != true)) { + if ((object.ReferenceEquals(this.IMPFilesField, value) != true)) { this.IMPFilesField = value; this.RaisePropertyChanged("IMPFiles"); } @@ -156,7 +156,7 @@ namespace ENI2.LockingServiceReference { return this.READYFilesField; } set { - if ((ReferenceEquals(this.READYFilesField, value) != true)) { + if ((object.ReferenceEquals(this.READYFilesField, value) != true)) { this.READYFilesField = value; this.RaisePropertyChanged("READYFiles"); } diff --git a/ENI2/SheetDisplayControls/CrewDepartureControl.xaml.cs b/ENI2/SheetDisplayControls/CrewDepartureControl.xaml.cs index 4719f84e..0f186fbd 100644 --- a/ENI2/SheetDisplayControls/CrewDepartureControl.xaml.cs +++ b/ENI2/SheetDisplayControls/CrewDepartureControl.xaml.cs @@ -3,9 +3,9 @@ // using bsmd.database; +using ClosedXML.Excel; using ENI2.EditControls; using ENI2.Util; -using ExcelDataReader; using Microsoft.Win32; using System; using System.Collections.Generic; @@ -126,72 +126,66 @@ namespace ENI2.SheetDisplayControls }; 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 importCrew = new List(); + + 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 importCrew = new List(); - - 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(); } } diff --git a/ENI2/SheetDisplayControls/CrewPreArrivalControl.xaml.cs b/ENI2/SheetDisplayControls/CrewPreArrivalControl.xaml.cs index 8678b30c..0bf4e98f 100644 --- a/ENI2/SheetDisplayControls/CrewPreArrivalControl.xaml.cs +++ b/ENI2/SheetDisplayControls/CrewPreArrivalControl.xaml.cs @@ -3,9 +3,9 @@ // using bsmd.database; +using ClosedXML.Excel; using ENI2.EditControls; using ENI2.Util; -using ExcelDataReader; using Microsoft.Win32; using System; using System.Collections.Generic; @@ -166,70 +166,65 @@ namespace ENI2.SheetDisplayControls }; 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 importCrew = new List(); + + 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._crewaMessage; + crew.IsDirty = true; + crew.Identifier = CREW.GetNewIdentifier(this._crewaMessage.Elements); + this._crewaMessage.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 importCrew = new List(); - - 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._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(); } } diff --git a/ENI2/SheetDisplayControls/PassengerDepartureControl.xaml.cs b/ENI2/SheetDisplayControls/PassengerDepartureControl.xaml.cs index 24ca2cfa..8e93f552 100644 --- a/ENI2/SheetDisplayControls/PassengerDepartureControl.xaml.cs +++ b/ENI2/SheetDisplayControls/PassengerDepartureControl.xaml.cs @@ -3,10 +3,10 @@ // using bsmd.database; +using ClosedXML.Excel; using ENI2.EditControls; using ENI2.Locode; using ENI2.Util; -using ExcelDataReader; using Microsoft.Win32; using System; using System.Collections.Generic; @@ -144,78 +144,71 @@ namespace ENI2.SheetDisplayControls }; 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 importPassenger = new List(); + + 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 importPassenger = new List(); - - 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(); } } diff --git a/ENI2/SheetDisplayControls/PassengerPreArrivalControl.xaml.cs b/ENI2/SheetDisplayControls/PassengerPreArrivalControl.xaml.cs index 5350b8c3..8beaa753 100644 --- a/ENI2/SheetDisplayControls/PassengerPreArrivalControl.xaml.cs +++ b/ENI2/SheetDisplayControls/PassengerPreArrivalControl.xaml.cs @@ -4,10 +4,10 @@ // using bsmd.database; +using ClosedXML.Excel; using ENI2.EditControls; using ENI2.Locode; using ENI2.Util; -using ExcelDataReader; using Microsoft.Win32; using System; using System.Collections.Generic; @@ -126,78 +126,71 @@ namespace ENI2.SheetDisplayControls }; 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 importPassenger = new List(); + + 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 importPassenger = new List(); - - 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(); } } diff --git a/ENI2/SheetDisplayControls/PortControl.xaml.cs b/ENI2/SheetDisplayControls/PortControl.xaml.cs index edd2f6e5..988fca9e 100644 --- a/ENI2/SheetDisplayControls/PortControl.xaml.cs +++ b/ENI2/SheetDisplayControls/PortControl.xaml.cs @@ -3,9 +3,10 @@ // using bsmd.database; +using ClosedXML.Excel; using ENI2.EditControls; -using ExcelDataReader; using Microsoft.Win32; + using System; using System.Collections.Generic; using System.Diagnostics; @@ -517,100 +518,83 @@ namespace ENI2.SheetDisplayControls ofd.Filter = "Excel Files|*.xls;*.xlsx"; 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(3); // Skip first three rows + + List importWasteList = new List(); + + int cnt = 0; + + // Diese Funktion kann das "alte" Sheet Format nicht mehr einlesen! + + foreach (var row in rows) + { + if (cnt >= 35) break; // Maximum 35 rows + + if (worksheet.RangeUsed().ColumnCount() < 9) + { + throw new InvalidDataException("Sheet must have 9 Columns of data"); + } + + object o = null; + + if (!row.Cell(2).IsEmpty()) o = row.Cell(2).Value; else o = null; + if ((o != null) && Int32.TryParse(o.ToString(), out int wasteType)) + { + Waste waste = _was.GetWasteForType(wasteType); + if (waste == null) + { + waste = new Waste(); + waste.WasteType = wasteType; + waste.WAS = this._was; + waste.IsDirty = true; + waste.Identifier = Waste.GetNewIdentifier(this._was.Waste); + this._was.Waste.Add(waste); + } + else + { + waste.IsDirty = true; + } + + if (!row.Cell(5).IsEmpty()) waste.WasteDescription = row.Cell(5).GetString(); + if (waste.WasteDescription.IsNullOrEmpty()) + waste.WasteDescription = "-"; + + if (!row.Cell(6).IsEmpty()) o = row.Cell(6).Value; else o = null; + if (o != null) waste.WasteDisposalAmount_MTQ = Convert.ToDouble(o); + + if (!row.Cell(7).IsEmpty()) o = row.Cell(7).Value; else o = null; + if (o != null) waste.WasteCapacity_MTQ = Convert.ToDouble(o); + + if (!row.Cell(8).IsEmpty()) o = row.Cell(8).Value; else o = null; + if (o != null) waste.WasteAmountRetained_MTQ = Convert.ToDouble(o); + + if (!row.Cell(9).IsEmpty()) waste.WasteDisposalPort = row.Cell(9).GetString().ToUpper(); + + if (!row.Cell(10).IsEmpty()) o = row.Cell(10).Value; else o = null; + if (o != null) waste.WasteAmountGeneratedTillNextPort_MTQ = Convert.ToDouble(o); + + importWasteList.Add(waste); + cnt++; + } + } + + if (importWasteList.Count > 0) + { + this.dataGridWaste.Items.Refresh(); + this.SublistElementChanged(Message.NotificationClass.WAS); + MessageBox.Show(String.Format(Properties.Resources.textWasteImported, importWasteList.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 importWasteList = new List(); - - try - { - do - { - // skip first three rows - reader.Read(); - reader.Read(); - reader.Read(); - - int cnt = 0; - object o = null; - - // Diese Funktion kann das "alte" Sheet Format nicht mehr einlesen! - - while (reader.Read() && (cnt < 35)) - { - if (reader.FieldCount < 9) - { - throw new InvalidDataException("Sheet must have 9 Columns of data"); - } - - if (!reader.IsDBNull(1)) o = reader.GetValue(1); else o = null; - if ((o != null) && Int32.TryParse(o.ToString(), out int wasteType)) - { - Waste waste = _was.GetWasteForType(wasteType); - if (waste == null) - { - waste = new Waste(); - waste.WasteType = wasteType; - waste.WAS = this._was; - waste.IsDirty = true; - waste.Identifier = Waste.GetNewIdentifier(this._was.Waste); - this._was.Waste.Add(waste); - } - else - { - waste.IsDirty = true; - } - - if (!reader.IsDBNull(4)) waste.WasteDescription = reader.GetString(4); - if (waste.WasteDescription.IsNullOrEmpty()) - waste.WasteDescription = "-"; - - if (!reader.IsDBNull(5)) o = reader.GetValue(5); else o = null; - if (o != null) waste.WasteDisposalAmount_MTQ = Convert.ToDouble(o); - - if (!reader.IsDBNull(6)) o = reader.GetValue(6); else o = null; - if (o != null) waste.WasteCapacity_MTQ = Convert.ToDouble(o); - - if (!reader.IsDBNull(7)) o = reader.GetValue(7); else o = null; - if (o != null) waste.WasteAmountRetained_MTQ = Convert.ToDouble(o); - - if (!reader.IsDBNull(8)) waste.WasteDisposalPort = reader.GetString(8).ToUpper(); - - if (!reader.IsDBNull(9)) o = reader.GetValue(9); else o = null; - if (o != null) waste.WasteAmountGeneratedTillNextPort_MTQ = Convert.ToDouble(o); - - importWasteList.Add(waste); - cnt++; - } - } - - } while (reader.NextResult()); - } - catch (Exception ex) - { - MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error); - } - - if (importWasteList.Count > 0) - { - this.dataGridWaste.Items.Refresh(); - this.SublistElementChanged(Message.NotificationClass.WAS); - MessageBox.Show(String.Format(Properties.Resources.textWasteImported, importWasteList.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information); - } - } - - stream.Close(); - } } diff --git a/ENI2/SheetDisplayControls/PreDepartureControl.xaml.cs b/ENI2/SheetDisplayControls/PreDepartureControl.xaml.cs index e7590828..d6f75f29 100644 --- a/ENI2/SheetDisplayControls/PreDepartureControl.xaml.cs +++ b/ENI2/SheetDisplayControls/PreDepartureControl.xaml.cs @@ -105,7 +105,7 @@ namespace ENI2.SheetDisplayControls private void PreDepartureControl_Loaded(object sender, RoutedEventArgs e) { // 4.1 - this.RegisterDoubleUpDownChange(this.doubleUpDownDraught, Message.NotificationClass.TIEFA); + this.RegisterDoubleUpDownChange(this.doubleUpDownDraught, Message.NotificationClass.TIEFD); // 4.2 this.RegisterIntegerUpDownChange(this.integerUpDownCrewMemberOnBoard, Message.NotificationClass.POBD); diff --git a/ENI2/SheetDisplayControls/VoyageControl.xaml.cs b/ENI2/SheetDisplayControls/VoyageControl.xaml.cs index be9d4eec..de641837 100644 --- a/ENI2/SheetDisplayControls/VoyageControl.xaml.cs +++ b/ENI2/SheetDisplayControls/VoyageControl.xaml.cs @@ -2,17 +2,16 @@ // Description: Display control of formsheet Tab 1. Voyage // -using System.Windows; - using bsmd.database; +using ClosedXML.Excel; using ENI2.EditControls; -using System.Windows.Controls; -using System; using ENI2.Util; -using System.Collections.Generic; -using ExcelDataReader; using Microsoft.Win32; +using System; +using System.Collections.Generic; using System.IO; +using System.Windows; +using System.Windows.Controls; namespace ENI2.SheetDisplayControls @@ -301,83 +300,14 @@ namespace ENI2.SheetDisplayControls private void buttonImportExcelLast10PortFacilities_Click(object sender, RoutedEventArgs e) { - OpenFileDialog ofd = new OpenFileDialog + int importedCount = Excel.ExcelLocalImportHelper.ImportLast10PortFacilities(this._sec); + + if (importedCount > 0) { - 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 (var reader = ExcelReaderFactory.CreateReader(stream)) - { - List importL10C = new List(); - - try - { - do - { - int cnt = 0; - while (reader.Read() && (cnt < 10)) - { - if (((IExcelDataReader)reader).FieldCount < 8) - { - throw new InvalidDataException("Sheet must have 8 Columns of data"); - } - LastTenPortFacilitiesCalled l10c = new LastTenPortFacilitiesCalled(); - if (reader.IsDBNull(0) && reader.IsDBNull(1)) continue; - if (!reader.IsDBNull(0)) l10c.PortFacilityPortName = reader.GetString(0); - if (!reader.IsDBNull(2)) l10c.PortFacilityPortCountry = reader.GetString(2); - if (!reader.IsDBNull(3)) l10c.PortFacilityPortLoCode = reader.GetString(3); - object o = null; - if (!reader.IsDBNull(4)) o = reader.GetValue(4); - if (o != null) l10c.PortFacilityDateOfArrival = Convert.ToDateTime(o); - if (!reader.IsDBNull(5)) o = reader.GetValue(5); - if (o != null) l10c.PortFacilityDateOfDeparture = Convert.ToDateTime(o); - // if (!reader.IsDBNull(4)) l10c.PortFacilityDateOfArrival = reader.GetDateTime(4); - // if (!reader.IsDBNull(5)) l10c.PortFacilityDateOfDeparture = reader.GetDateTime(5); - if (!reader.IsDBNull(6)) o = reader.GetValue(6); - if (o != null) l10c.PortFacilityShipSecurityLevel = Convert.ToByte(o); - if (!reader.IsDBNull(7)) o = reader.GetValue(7); - int gisis = Convert.ToInt32(o); - if (!reader.IsDBNull(7)) l10c.PortFacilityGISISCode = gisis.ToString().PadLeft(4, '0'); - if (!reader.IsDBNull(8)) l10c.PortFacilitySecurityMattersToReport = reader.GetString(8); - if (l10c.PortFacilitySecurityMattersToReport.Equals("nil", StringComparison.CurrentCultureIgnoreCase)) - l10c.PortFacilitySecurityMattersToReport = null; - if (!reader.IsDBNull(9)) l10c.PortFacilityGISISCodeLocode = reader.GetString(9); - l10c.SEC = this._sec; - l10c.IsDirty = true; - l10c.Identifier = LastTenPortFacilitiesCalled.GetNewIdentifier(this._sec.LastTenPortFacilitesCalled); - this._sec.LastTenPortFacilitesCalled.Add(l10c); - importL10C.Add(l10c); - cnt++; - } - } while (reader.NextResult()); - } - catch (Exception ex) - { - MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error); - } - - if (importL10C.Count > 0) - { - this.dataGridLast10PortFacilities.Items.Refresh(); - this.SublistElementChanged(Message.NotificationClass.SEC); - MessageBox.Show(String.Format(Properties.Resources.textL10PImported, importL10C.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information); - } - } - - stream.Close(); + this.dataGridLast10PortFacilities.Items.Refresh(); + this.SublistElementChanged(Message.NotificationClass.SEC); + MessageBox.Show(String.Format(Properties.Resources.textL10PImported, importedCount), + Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information); } } @@ -447,87 +377,16 @@ namespace ENI2.SheetDisplayControls private void buttonImportLast30DaysFromExcel_Click(object sender, RoutedEventArgs e) { - OpenFileDialog ofd = new OpenFileDialog + int cnt = Excel.ExcelLocalImportHelper.ImportLast30Days(this._mdh); + + if (cnt > 0) { - 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 (var reader = ExcelReaderFactory.CreateReader(stream)) - { - List importPoC30 = new List(); - - try - { - do - { - while (reader.Read()) - { - if (reader.FieldCount < 3) - { - throw new InvalidDataException("Sheet must have at least 3 Columns of data"); - } - PortOfCallLast30Days poc30 = new PortOfCallLast30Days(); - if (reader.IsDBNull(0) && reader.IsDBNull(1)) continue; - if (!reader.IsDBNull(0)) poc30.PortOfCallLast30DaysLocode = reader.GetString(0); - if (!reader.IsDBNull(1)) poc30.PortOfCallLast30DaysDateOfDeparture = reader.GetDateTime(1); - string boolString = ""; - if (!reader.IsDBNull(2)) boolString = reader.GetString(2); - poc30.PortOfCallLast30DaysCrewMembersJoined = (boolString.Equals("y", StringComparison.OrdinalIgnoreCase) || (boolString.Equals("yes", StringComparison.OrdinalIgnoreCase)) || - (boolString.Equals("j", StringComparison.OrdinalIgnoreCase))); - - if (reader.FieldCount > 3) - { - string allNewCrew = reader.GetString(3)?.Trim(); - if (!allNewCrew.IsNullOrEmpty()) - { - string[] crewNames = allNewCrew.Split(',', ';'); - for (int i = 0; i < crewNames.Length; i++) - { - string crewName = crewNames[i].Trim(); - if (crewName.IsNullOrEmpty()) continue; - PortOfCallLast30DaysCrewJoinedShip poc30Crew = new PortOfCallLast30DaysCrewJoinedShip(); - poc30Crew.PortOfCallLast30DaysCrewJoinedShipName = crewName; - poc30Crew.PortOfCallLast30Days = poc30; - poc30.CrewJoinedShip.Add(poc30Crew); - - } - } - } - - poc30.MDH = this._mdh; - this._mdh.PortOfCallLast30Days.Add(poc30); - importPoC30.Add(poc30); - } - } while (reader.NextResult()); - } - catch (Exception ex) - { - MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error); - } - - if (importPoC30.Count > 0) - { - this.dataGridPortOfCallLast30Days.Items.Refresh(); - this.SublistElementChanged(Message.NotificationClass.MDH); - MessageBox.Show(String.Format(Properties.Resources.textPoC30Imported, importPoC30.Count), Properties.Resources.textCaptionInformation, - MessageBoxButton.OK, MessageBoxImage.Information); - } - } - - stream.Close(); - } + this.dataGridPortOfCallLast30Days.Items.Refresh(); + this.SublistElementChanged(Message.NotificationClass.MDH); + MessageBox.Show(String.Format(Properties.Resources.textPoC30Imported, cnt), + Properties.Resources.textCaptionInformation, + MessageBoxButton.OK, MessageBoxImage.Information); + } } private void buttonImportPortOfItineraryFromSEC_Click(object sender, RoutedEventArgs e) diff --git a/ENI2/Util/Extensions.cs b/ENI2/Util/Extensions.cs index 79afbe12..606eaaa5 100644 --- a/ENI2/Util/Extensions.cs +++ b/ENI2/Util/Extensions.cs @@ -3,7 +3,7 @@ // using bsmd.database; -using ExcelDataReader; + using System; namespace ENI2.Util @@ -11,20 +11,6 @@ namespace ENI2.Util internal static class Extensions { - public static string ReadAsString(this IExcelDataReader reader, int index) - { - if (index >= reader.FieldCount) return null; - Type fieldType = reader.GetFieldType(index); - if (fieldType == null) return null; - if (fieldType == typeof(string)) - return reader.GetString(index).Clean(); - if (fieldType == typeof(DateTime)) - return reader.GetDateTime(index).ToString(); - if (fieldType == typeof(int)) - return reader.GetInt32(index).ToString(); - if (fieldType == typeof(double)) - return ((int)reader.GetDouble(index)).ToString(); - return null; - } + } } diff --git a/ENI2/packages.config b/ENI2/packages.config index a5639ee8..a8b21ac6 100644 --- a/ENI2/packages.config +++ b/ENI2/packages.config @@ -1,28 +1,34 @@  - + + + + + - - - - - - - - - - - + + + + + + + + + + + + + - - + + - + \ No newline at end of file diff --git a/bsmd.database/Properties/AssemblyProductInfo.cs b/bsmd.database/Properties/AssemblyProductInfo.cs index 0e0edb5b..19b3f3d5 100644 --- a/bsmd.database/Properties/AssemblyProductInfo.cs +++ b/bsmd.database/Properties/AssemblyProductInfo.cs @@ -2,6 +2,6 @@ [assembly: AssemblyCompany("schick Informatik")] [assembly: AssemblyProduct("BSMD NSW interface")] -[assembly: AssemblyInformationalVersion("7.2.12")] +[assembly: AssemblyInformationalVersion("7.2.13")] [assembly: AssemblyCopyright("Copyright © 2014-2025 schick Informatik")] [assembly: AssemblyTrademark("")] \ No newline at end of file diff --git a/bsmd.database/Properties/AssemblyProjectInfo.cs b/bsmd.database/Properties/AssemblyProjectInfo.cs index e7e744ee..9a544667 100644 --- a/bsmd.database/Properties/AssemblyProjectInfo.cs +++ b/bsmd.database/Properties/AssemblyProjectInfo.cs @@ -1,4 +1,4 @@ using System.Reflection; -[assembly: AssemblyVersion("7.2.12.*")] +[assembly: AssemblyVersion("7.2.13.*")]