Fixed import to l10ports visited and last30 days and centralized this code at ExcelLocalImportHelper.
In the future, I should refactor all the other places as well
This commit is contained in:
parent
d5d5be67e7
commit
1a89c204c9
@ -281,81 +281,17 @@ namespace ENI2.DetailViewControls
|
||||
|
||||
private void ButtonImportFromExcel_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
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); // Get first worksheet
|
||||
var rows = worksheet.RangeUsed().RowsUsed(); // Get all rows with data
|
||||
int cnt = Excel.ExcelLocalImportHelper.ImportLast30Days(this._mdh);
|
||||
|
||||
List<PortOfCallLast30Days> importPoC30 = new List<PortOfCallLast30Days>();
|
||||
|
||||
foreach (var row in rows)
|
||||
{
|
||||
if (row.RowNumber() > worksheet.RangeUsed().RowCount()) break;
|
||||
|
||||
if (worksheet.RangeUsed().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;
|
||||
|
||||
if (!row.Cell(1).IsEmpty()) poc30.PortOfCallLast30DaysLocode = row.Cell(1).GetString();
|
||||
if (!row.Cell(2).IsEmpty()) poc30.PortOfCallLast30DaysDateOfDeparture = row.Cell(2).GetDateTime();
|
||||
|
||||
string boolString = "";
|
||||
if (!row.Cell(3).IsEmpty()) boolString = row.Cell(3).GetString();
|
||||
poc30.PortOfCallLast30DaysCrewMembersJoined = (boolString.Equals("y", StringComparison.OrdinalIgnoreCase) ||
|
||||
(boolString.Equals("yes", StringComparison.OrdinalIgnoreCase)) ||
|
||||
(boolString.Equals("j", StringComparison.OrdinalIgnoreCase)));
|
||||
|
||||
if (worksheet.RangeUsed().ColumnCount() > 3)
|
||||
{
|
||||
string allNewCrew = row.Cell(4).IsEmpty() ? null : row.Cell(4).GetString()?.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);
|
||||
}
|
||||
|
||||
if (importPoC30.Count > 0)
|
||||
if (cnt > 0)
|
||||
{
|
||||
this.dataGridPortOfCallLast30Days.Items.Refresh();
|
||||
this.SublistElementChanged(Message.NotificationClass.MDH);
|
||||
MessageBox.Show(String.Format(Properties.Resources.textPoC30Imported, importPoC30.Count), Properties.Resources.textCaptionInformation,
|
||||
MessageBox.Show(String.Format(Properties.Resources.textPoC30Imported, cnt),
|
||||
Properties.Resources.textCaptionInformation,
|
||||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -337,80 +337,14 @@ namespace ENI2.DetailViewControls
|
||||
|
||||
private void buttonImportExcel_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OpenFileDialog ofd = new OpenFileDialog
|
||||
{
|
||||
Filter = "Excel Files|*.xls;*.xlsx"
|
||||
};
|
||||
int importedCount = Excel.ExcelLocalImportHelper.ImportLast10PortFacilities(this._sec);
|
||||
|
||||
if (ofd.ShowDialog() ?? false)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var workbook = new XLWorkbook(ofd.FileName))
|
||||
{
|
||||
var worksheet = workbook.Worksheet(1); // Get first worksheet
|
||||
var rows = worksheet.RangeUsed().RowsUsed(); // Get all rows with data
|
||||
|
||||
List<LastTenPortFacilitiesCalled> importL10C = new List<LastTenPortFacilitiesCalled>();
|
||||
|
||||
int cnt = 0;
|
||||
foreach (var row in rows)
|
||||
{
|
||||
if (cnt >= 10) break; // Maximum 10 rows
|
||||
|
||||
if (worksheet.RangeUsed().ColumnCount() < 8)
|
||||
{
|
||||
throw new InvalidDataException("Sheet must have 8 Columns of data");
|
||||
}
|
||||
|
||||
LastTenPortFacilitiesCalled l10c = new LastTenPortFacilitiesCalled();
|
||||
|
||||
if (row.Cell(1).IsEmpty() && row.Cell(2).IsEmpty()) continue;
|
||||
|
||||
if (!row.Cell(1).IsEmpty()) l10c.PortFacilityPortName = row.Cell(1).GetString();
|
||||
if (!row.Cell(3).IsEmpty()) l10c.PortFacilityPortCountry = row.Cell(3).GetString();
|
||||
if (!row.Cell(4).IsEmpty()) l10c.PortFacilityPortLoCode = row.Cell(4).GetString();
|
||||
|
||||
object o = null;
|
||||
if (!row.Cell(5).IsEmpty()) o = row.Cell(5).Value;
|
||||
if (o != null) l10c.PortFacilityDateOfArrival = Convert.ToDateTime(o);
|
||||
|
||||
if (!row.Cell(6).IsEmpty()) o = row.Cell(6).Value;
|
||||
if (o != null) l10c.PortFacilityDateOfDeparture = Convert.ToDateTime(o);
|
||||
|
||||
if (!row.Cell(7).IsEmpty()) o = row.Cell(7).Value;
|
||||
if (o != null) l10c.PortFacilityShipSecurityLevel = Convert.ToByte(o);
|
||||
|
||||
if (!row.Cell(8).IsEmpty()) o = row.Cell(8).Value;
|
||||
int gisis = Convert.ToInt32(o);
|
||||
if (!row.Cell(8).IsEmpty()) l10c.PortFacilityGISISCode = gisis.ToString().PadLeft(4, '0');
|
||||
|
||||
if (!row.Cell(9).IsEmpty()) l10c.PortFacilitySecurityMattersToReport = row.Cell(9).GetString();
|
||||
if (l10c.PortFacilitySecurityMattersToReport?.Equals("nil", StringComparison.CurrentCultureIgnoreCase) == true)
|
||||
l10c.PortFacilitySecurityMattersToReport = null;
|
||||
|
||||
if (!row.Cell(10).IsEmpty()) l10c.PortFacilityGISISCodeLocode = row.Cell(10).GetString();
|
||||
|
||||
l10c.SEC = this._sec;
|
||||
l10c.IsDirty = true;
|
||||
l10c.Identifier = LastTenPortFacilitiesCalled.GetNewIdentifier(this._sec.LastTenPortFacilitesCalled);
|
||||
this._sec.LastTenPortFacilitesCalled.Add(l10c);
|
||||
importL10C.Add(l10c);
|
||||
cnt++;
|
||||
}
|
||||
|
||||
if (importL10C.Count > 0)
|
||||
if (importedCount > 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
MessageBox.Show(String.Format(Properties.Resources.textL10PImported, importedCount),
|
||||
Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -36,8 +36,8 @@
|
||||
<MinimumRequiredVersion>5.4.0.0</MinimumRequiredVersion>
|
||||
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
|
||||
<WebPage>publish.html</WebPage>
|
||||
<ApplicationRevision>1</ApplicationRevision>
|
||||
<ApplicationVersion>7.2.13.1</ApplicationVersion>
|
||||
<ApplicationRevision>2</ApplicationRevision>
|
||||
<ApplicationVersion>7.2.13.2</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<CreateDesktopShortcut>true</CreateDesktopShortcut>
|
||||
<PublishWizardCompleted>true</PublishWizardCompleted>
|
||||
@ -356,6 +356,7 @@
|
||||
<Compile Include="Excel\DakosyUtil.cs" />
|
||||
<Compile Include="Excel\ExcelBase.cs" />
|
||||
<Compile Include="Excel\ExcelComparer.cs" />
|
||||
<Compile Include="Excel\ExcelLocalImportHelper.cs" />
|
||||
<Compile Include="Excel\ExcelManager.cs" />
|
||||
<Compile Include="Excel\ExcelReader.cs" />
|
||||
<Compile Include="Excel\ExcelSimpleWriter.cs" />
|
||||
|
||||
246
ENI2/Excel/ExcelLocalImportHelper.cs
Normal file
246
ENI2/Excel/ExcelLocalImportHelper.cs
Normal file
@ -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<LastTenPortFacilitiesCalled> importL10C = new List<LastTenPortFacilitiesCalled>();
|
||||
|
||||
|
||||
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<byte>();
|
||||
}
|
||||
|
||||
// Column 8: GISIS Code
|
||||
if (!row.Cell(8).IsEmpty())
|
||||
{
|
||||
int gisis = row.Cell(8).GetValue<int>();
|
||||
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<PortOfCallLast30Days> importPoC30 = new List<PortOfCallLast30Days>();
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
}
|
||||
@ -300,80 +300,14 @@ namespace ENI2.SheetDisplayControls
|
||||
|
||||
private void buttonImportExcelLast10PortFacilities_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OpenFileDialog ofd = new OpenFileDialog
|
||||
{
|
||||
Filter = "Excel Files|*.xls;*.xlsx"
|
||||
};
|
||||
int importedCount = Excel.ExcelLocalImportHelper.ImportLast10PortFacilities(this._sec);
|
||||
|
||||
if (ofd.ShowDialog() ?? false)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var workbook = new XLWorkbook(ofd.FileName))
|
||||
{
|
||||
var worksheet = workbook.Worksheet(1); // Get first worksheet
|
||||
var rows = worksheet.RangeUsed().RowsUsed(); // Get all rows with data
|
||||
|
||||
List<LastTenPortFacilitiesCalled> importL10C = new List<LastTenPortFacilitiesCalled>();
|
||||
|
||||
int cnt = 0;
|
||||
foreach (var row in rows)
|
||||
{
|
||||
if (cnt >= 10) break; // Maximum 10 rows
|
||||
|
||||
if (worksheet.RangeUsed().ColumnCount() < 8)
|
||||
{
|
||||
throw new InvalidDataException("Sheet must have 8 Columns of data");
|
||||
}
|
||||
|
||||
LastTenPortFacilitiesCalled l10c = new LastTenPortFacilitiesCalled();
|
||||
|
||||
if (row.Cell(1).IsEmpty() && row.Cell(2).IsEmpty()) continue;
|
||||
|
||||
if (!row.Cell(1).IsEmpty()) l10c.PortFacilityPortName = row.Cell(1).GetString();
|
||||
if (!row.Cell(3).IsEmpty()) l10c.PortFacilityPortCountry = row.Cell(3).GetString();
|
||||
if (!row.Cell(4).IsEmpty()) l10c.PortFacilityPortLoCode = row.Cell(4).GetString();
|
||||
|
||||
object o = null;
|
||||
if (!row.Cell(5).IsEmpty()) o = row.Cell(5).Value;
|
||||
if (o != null) l10c.PortFacilityDateOfArrival = Convert.ToDateTime(o);
|
||||
|
||||
if (!row.Cell(6).IsEmpty()) o = row.Cell(6).Value;
|
||||
if (o != null) l10c.PortFacilityDateOfDeparture = Convert.ToDateTime(o);
|
||||
|
||||
if (!row.Cell(7).IsEmpty()) o = row.Cell(7).Value;
|
||||
if (o != null) l10c.PortFacilityShipSecurityLevel = Convert.ToByte(o);
|
||||
|
||||
if (!row.Cell(8).IsEmpty()) o = row.Cell(8).Value;
|
||||
int gisis = Convert.ToInt32(o);
|
||||
if (!row.Cell(8).IsEmpty()) l10c.PortFacilityGISISCode = gisis.ToString().PadLeft(4, '0');
|
||||
|
||||
if (!row.Cell(9).IsEmpty()) l10c.PortFacilitySecurityMattersToReport = row.Cell(9).GetString();
|
||||
if (l10c.PortFacilitySecurityMattersToReport?.Equals("nil", StringComparison.CurrentCultureIgnoreCase) == true)
|
||||
l10c.PortFacilitySecurityMattersToReport = null;
|
||||
|
||||
if (!row.Cell(10).IsEmpty()) l10c.PortFacilityGISISCodeLocode = row.Cell(10).GetString();
|
||||
|
||||
l10c.SEC = this._sec;
|
||||
l10c.IsDirty = true;
|
||||
l10c.Identifier = LastTenPortFacilitiesCalled.GetNewIdentifier(this._sec.LastTenPortFacilitesCalled);
|
||||
this._sec.LastTenPortFacilitesCalled.Add(l10c);
|
||||
importL10C.Add(l10c);
|
||||
cnt++;
|
||||
}
|
||||
|
||||
if (importL10C.Count > 0)
|
||||
if (importedCount > 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
MessageBox.Show(String.Format(Properties.Resources.textL10PImported, importedCount),
|
||||
Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
|
||||
@ -443,81 +377,17 @@ namespace ENI2.SheetDisplayControls
|
||||
|
||||
private void buttonImportLast30DaysFromExcel_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
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); // Get first worksheet
|
||||
var rows = worksheet.RangeUsed().RowsUsed(); // Get all rows with data
|
||||
int cnt = Excel.ExcelLocalImportHelper.ImportLast30Days(this._mdh);
|
||||
|
||||
List<PortOfCallLast30Days> importPoC30 = new List<PortOfCallLast30Days>();
|
||||
|
||||
foreach (var row in rows)
|
||||
{
|
||||
if (row.RowNumber() > worksheet.RangeUsed().RowCount()) break;
|
||||
|
||||
if (worksheet.RangeUsed().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;
|
||||
|
||||
if (!row.Cell(1).IsEmpty()) poc30.PortOfCallLast30DaysLocode = row.Cell(1).GetString();
|
||||
if (!row.Cell(2).IsEmpty()) poc30.PortOfCallLast30DaysDateOfDeparture = row.Cell(2).GetDateTime();
|
||||
|
||||
string boolString = "";
|
||||
if (!row.Cell(3).IsEmpty()) boolString = row.Cell(3).GetString();
|
||||
poc30.PortOfCallLast30DaysCrewMembersJoined = (boolString.Equals("y", StringComparison.OrdinalIgnoreCase) ||
|
||||
(boolString.Equals("yes", StringComparison.OrdinalIgnoreCase)) ||
|
||||
(boolString.Equals("j", StringComparison.OrdinalIgnoreCase)));
|
||||
|
||||
if (worksheet.RangeUsed().ColumnCount() > 3)
|
||||
{
|
||||
string allNewCrew = row.Cell(4).IsEmpty() ? null : row.Cell(4).GetString()?.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);
|
||||
}
|
||||
|
||||
if (importPoC30.Count > 0)
|
||||
if (cnt > 0)
|
||||
{
|
||||
this.dataGridPortOfCallLast30Days.Items.Refresh();
|
||||
this.SublistElementChanged(Message.NotificationClass.MDH);
|
||||
MessageBox.Show(String.Format(Properties.Resources.textPoC30Imported, importPoC30.Count), Properties.Resources.textCaptionInformation,
|
||||
MessageBox.Show(String.Format(Properties.Resources.textPoC30Imported, cnt),
|
||||
Properties.Resources.textCaptionInformation,
|
||||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonImportPortOfItineraryFromSEC_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user