fixed a number of small things and continued on Maersk

This commit is contained in:
Daniel Schick 2023-02-07 18:01:32 +01:00
parent 8862d8e83c
commit 1ab7641efe
9 changed files with 141 additions and 60 deletions

View File

@ -26,18 +26,24 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid Grid.Row="0"> <Grid Grid.Row="0">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="80" /> <ColumnDefinition Width="40" />
<ColumnDefinition Width="80" /> <ColumnDefinition Width="120" />
<ColumnDefinition Width="80" /> <ColumnDefinition Width="40" />
<ColumnDefinition Width="120" />
<ColumnDefinition Width="80" /> <ColumnDefinition Width="80" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="80" />
<ColumnDefinition Width="80" />
<ColumnDefinition Width="30" /> <ColumnDefinition Width="30" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Label Content="Calendar week" Grid.Column="0"/> <Label Content="From" Grid.Column="0" />
<Button x:Name="buttonLoad" Grid.Column="1" Content="Load" Margin="2" Click="buttonLoad_Click" /> <xctk:DateTimePicker x:Name="dateTimePickerFrom" Margin="2" Grid.Column="1" Format="ShortDate" />
<Button x:Name="buttonImport" Grid.Column="2" Margin="2" Content="Import" Click="buttonImport_Click" /> <Label Content="To" Grid.Column="2" />
<Button x:Name="buttonExport" Grid.Column="3" Margin="2" Content="Export" Click="buttonExport_Click" /> <xctk:DateTimePicker x:Name="dateTimePickerTo" Margin="2" Grid.Column="3" Format="ShortDate" />
<local:BusyControl x:Name="busyControl" Grid.Column="5" /> <Button x:Name="buttonLoad" Grid.Column="4" Content="Load" Margin="2" Click="buttonLoad_Click" />
<Button x:Name="buttonImport" Grid.Column="6" Margin="2" Content="Import" Click="buttonImport_Click" />
<Button x:Name="buttonExport" Grid.Column="7" Margin="2" Content="Export" Click="buttonExport_Click" />
<local:BusyControl x:Name="busyControl" Grid.Column="8" />
</Grid> </Grid>
<local:ENIDataGrid Grid.Row="1" Margin="2,8,2,2" x:Name="dataGridPOCores" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" <local:ENIDataGrid Grid.Row="1" Margin="2,8,2,2" x:Name="dataGridPOCores" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
SelectionMode="Single" AutoGenerateColumns="False" CellEditEnding="dataGridPOCores_CellEditEnding" CanUserAddRows="False"> SelectionMode="Single" AutoGenerateColumns="False" CellEditEnding="dataGridPOCores_CellEditEnding" CanUserAddRows="False">

View File

@ -14,6 +14,7 @@ using Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using bsmd.database; using bsmd.database;
using ExcelDataReader;
namespace ENI2.Controls namespace ENI2.Controls
{ {
@ -36,6 +37,8 @@ namespace ENI2.Controls
{ {
InitializeComponent(); InitializeComponent();
Loaded += POList_Loaded; Loaded += POList_Loaded;
this.dateTimePickerFrom.Value = DateTime.Today.AddDays(-14);
this.dateTimePickerTo.Value = DateTime.Today.AddDays(14);
} }
#endregion #endregion
@ -115,64 +118,27 @@ namespace ENI2.Controls
Dictionary<MessageCore.SearchFilterType, string> filterDict = new Dictionary<MessageCore.SearchFilterType, string>(); Dictionary<MessageCore.SearchFilterType, string> filterDict = new Dictionary<MessageCore.SearchFilterType, string>();
DateTime start = DateTime.Now; // bsmd.database.Util.FirstDateOfWeekISO8601(DateTime.Now.Year, (int)this.doubleUpDownCalendarWeek.Value); // Die Suche findet in dem eingestellten Intervall statt
DateTime end = start.Add(new TimeSpan(6, 23, 59, 59)); uint from = this.dateTimePickerFrom.Value.Value.ToUniversalTime().ToUnixTimeStamp();
uint to = this.dateTimePickerTo.Value.Value.ToUniversalTime().ToUnixTimeStamp();
// Die Suche findet in einem erweiterten Intervall statt, da später wenn möglich nach ATA gefiltert wird
uint from = start.Subtract(new TimeSpan(10, 0, 0, 0)).ToUniversalTime().ToUnixTimeStamp();
uint to = end.Add(new TimeSpan(5, 0, 0, 0)).ToUniversalTime().ToUnixTimeStamp();
filterDict.Add(MessageCore.SearchFilterType.FILTER_ETA, string.Format("{0}:{1}", from.ToString() ?? "", to.ToString() ?? "")); filterDict.Add(MessageCore.SearchFilterType.FILTER_ETA, string.Format("{0}:{1}", from.ToString() ?? "", to.ToString() ?? ""));
// eingeschränkt auf flags
filterDict.Add(MessageCore.SearchFilterType.FILTER_FLAG_EQ, "0");
// suche auslösen // suche auslösen
this.searchResult = DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).GetMessageCoresWithFilters(filterDict); this.searchResult = DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).GetMessageCoresWithFilters(filterDict);
// alle anderen Häfen weg // alle anderen Häfen weg
this.searchResult.RemoveAll(item => (item.PoC == null) || (!item.PoC.Equals("DEBRV") && !item.PoC.Equals("DEWHV") && !item.PoC.Equals("DEWVN"))); this.searchResult.RemoveAll(item => (item.PoC == null) || (!item.PoC.Equals("DEBRV") && !item.PoC.Equals("DEWHV") && !item.PoC.Equals("DEWVN")));
// rückwärts iterieren um nach ETA und ATA zu filtern // sortieren nach ETA (kombiniert)
if (this.searchResult.Count > 0) searchResult.Sort((x, y) => DateTime.Compare(x.ETADisplay ?? DateTime.MaxValue, y.ETADisplay ?? DateTime.MaxValue));
{
for (int i = this.searchResult.Count - 1; i >= 0; i--)
{
MessageCore messageCore = this.searchResult[i];
if (messageCore.ATA.HasValue)
{
if ((messageCore.ATA.Value < start) || (messageCore.ATA.Value > end))
{
this.searchResult.RemoveAt(i);
}
else
{
if(!messageCore.POATA.HasValue)
{
messageCore.POATA = messageCore.ATA;
messageCore.IsDirty = true;
// this.buttonSaveChanges.IsEnabled = true;
}
}
}
else
{
if ((messageCore.ETA.Value < start) || (messageCore.ETA.Value > end)) this.searchResult.RemoveAt(i);
}
}
}
searchResult.Sort((x, y) => DateTime.Compare(x.ATA ?? DateTime.MaxValue, y.ATA ?? DateTime.MaxValue));
this.dataGridPOCores.SelectedItem = null; this.dataGridPOCores.SelectedItem = null;
this.filteredResult.AddRange(searchResult); this.filteredResult.AddRange(searchResult);
this.dataGridPOCores.ItemsSource = this.filteredResult; this.dataGridPOCores.ItemsSource = this.filteredResult;
} }
private List<MessageCore> GetNextNDayCoresFromList(List<MessageCore> cores, int numDays = 3)
{
List<MessageCore> result = new List<MessageCore>();
result.AddRange(cores.FindAll(x => (x.ETADisplay.Value - DateTime.Now).TotalHours < (numDays * 24)));
return result;
}
#endregion #endregion
#region button event handler #region button event handler
@ -185,7 +151,75 @@ namespace ENI2.Controls
private void buttonImport_Click(object sender, RoutedEventArgs e) private void buttonImport_Click(object sender, RoutedEventArgs e)
{ {
OpenFileDialog ofd = new OpenFileDialog
{
Filter = "Excel Files|*.xls;*.xlsx"
};
if (ofd.ShowDialog() ?? false)
{
FileStream stream;
try
{
stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
using (IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream))
{
List<MessageCore> importCores = new List<MessageCore>();
try
{
do
{
while (reader.Read())
{
if (reader.FieldCount < 13)
{
throw new InvalidDataException("Sheet must have 13 columns of data");
}
MessageCore core = new MessageCore();
if (reader.IsDBNull(0) && reader.IsDBNull(1)) continue;
/*
if (!reader.IsDBNull(0)) crew.CrewMemberLastName = reader.GetString(0).Clean();
if (crew.CrewMemberLastName.Equals("Family Name") || (crew.CrewMemberLastName.Trim().Length == 0)) continue;
if (!reader.IsDBNull(1)) crew.CrewMemberFirstName = reader.GetString(1).Clean();
if (!reader.IsDBNull(2)) crew.CrewMemberGender = GlobalStructures.ParseGender(reader.GetString(2));
if (!reader.IsDBNull(3)) crew.CrewMemberDuty = reader.GetString(3).Clean();
if (!reader.IsDBNull(4)) crew.CrewMemberNationality = reader.GetString(4).Substring(0, 2).ToUpper();
if (!reader.IsDBNull(5)) crew.CrewMemberPlaceOfBirth = reader.GetString(5).Clean();
if (!reader.IsDBNull(6)) crew.CrewMemberCountryOfBirth = reader.GetString(6).Substring(0, 2).ToUpper();
if (!reader.IsDBNull(7)) crew.CrewMemberDateOfBirth = reader.GetDateTime(7);
if (!reader.IsDBNull(8)) crew.CrewMemberIdentityDocumentType = GlobalStructures.ReadIdentityDocumentType(reader.GetString(8));
if (!reader.IsDBNull(9)) crew.CrewMemberIdentityDocumentId = this.getValueAsString(reader, 9).Clean();
if (!reader.IsDBNull(10)) crew.CrewMemberIdentityDocumentIssuingState = reader.GetString(10).Substring(0, 2).ToUpper();
if (!reader.IsDBNull(11)) crew.CrewMemberIdentityDocumentExpiryDate = reader.GetDateTime(11);
if (!reader.IsDBNull(12)) crew.CrewMemberVisaNumber = this.getValueAsString(reader, 12).Clean();
*/
importCores.Add(core);
}
} while (reader.NextResult());
}
catch (Exception ex)
{
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
}
// we only want cores for the next 3 days
if (importCores.Count > 0)
{
}
}
stream.Close();
}
} }
private void buttonExport_Click(object sender, RoutedEventArgs e) private void buttonExport_Click(object sender, RoutedEventArgs e)

View File

@ -11,7 +11,7 @@ Copyright (c) 2017 schick Informatik
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:p="clr-namespace:ENI2.Properties" xmlns:p="clr-namespace:ENI2.Properties"
mc:Ignorable="d" mc:Ignorable="d"
Title="{x:Static p:Resources.textLadg}" Height="246" Width="900" WindowStyle="SingleBorderWindow" Background="AliceBlue"> Title="{x:Static p:Resources.textLadg}" Height="300" Width="900" WindowStyle="SingleBorderWindow" Background="AliceBlue">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="28" /> <RowDefinition Height="28" />

View File

@ -289,6 +289,15 @@ namespace ENI2.Excel
if (val.IndexOf("sbt", StringComparison.OrdinalIgnoreCase) >= 0) result = 1; if (val.IndexOf("sbt", StringComparison.OrdinalIgnoreCase) >= 0) result = 1;
if (val.IndexOf("single", StringComparison.OrdinalIgnoreCase) >= 0) result = 0; if (val.IndexOf("single", StringComparison.OrdinalIgnoreCase) >= 0) result = 0;
if (val.IndexOf("double", StringComparison.OrdinalIgnoreCase) >= 0) result = 2; if (val.IndexOf("double", StringComparison.OrdinalIgnoreCase) >= 0) result = 2;
if (!result.HasValue)
{
if (int.TryParse(val, out int parsed))
{
if ((parsed < 4) && (parsed > 0))
result = (byte)parsed;
}
}
} }
if (!result.HasValue) if (!result.HasValue)
@ -347,6 +356,15 @@ namespace ENI2.Excel
if (val.IndexOf("full", StringComparison.OrdinalIgnoreCase) >= 0) result = 0; if (val.IndexOf("full", StringComparison.OrdinalIgnoreCase) >= 0) result = 0;
if (val.IndexOf("empty", StringComparison.OrdinalIgnoreCase) >= 0) result = 1; if (val.IndexOf("empty", StringComparison.OrdinalIgnoreCase) >= 0) result = 1;
if (val.IndexOf("inerted", StringComparison.OrdinalIgnoreCase) >= 0) result = 2; if (val.IndexOf("inerted", StringComparison.OrdinalIgnoreCase) >= 0) result = 2;
if (!result.HasValue)
{
if (int.TryParse(val, out int parsed))
{
if ((parsed < 4) && (parsed > 0))
result = (byte)parsed;
}
}
} }
if (!result.HasValue) if (!result.HasValue)

View File

@ -34,7 +34,7 @@ namespace bsmd.database
private bool _closeConnectionAfterUse = false; private bool _closeConnectionAfterUse = false;
private readonly List<string> truncatedFieldCollection = new List<string>(); private readonly List<string> truncatedFieldCollection = new List<string>();
private Dictionary<Type, string> messageHistoryTypeDict; private Dictionary<Type, string> messageHistoryTypeDict;
private SemaphoreSlim _asyncSemaphore = new SemaphoreSlim(1); private readonly SemaphoreSlim _asyncSemaphore = new SemaphoreSlim(1);
#endregion #endregion

View File

@ -606,6 +606,11 @@ namespace bsmd.database
(this.PlaceOfIssue.IsNullOrEmpty() || !this.DateOfIssue.HasValue)) (this.PlaceOfIssue.IsNullOrEmpty() || !this.DateOfIssue.HasValue))
violations.Add(RuleEngine.CreateViolation(ValidationCode.V765, "Cert. Place or Date of issue missing", null, this.Title, null, this.Tablename)); violations.Add(RuleEngine.CreateViolation(ValidationCode.V765, "Cert. Place or Date of issue missing", null, this.Title, null, this.Tablename));
if( (!this.ValidSanitaryControlExemptionOrCertificateOnBoard.HasValue || (this.ValidSanitaryControlExemptionOrCertificateOnBoard.Value == false)) &&
((!this.PlaceOfIssue.IsNullOrEmpty()) || this.DateOfIssue.HasValue))
violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Check sanitary control exemption or certificate", null, this.Title, null, this.Tablename));
if ((this.InfectedAreaVisited ?? false) && this.InfectedAreas.IsNullOrEmpty()) if ((this.InfectedAreaVisited ?? false) && this.InfectedAreas.IsNullOrEmpty())
violations.Add(RuleEngine.CreateViolation(ValidationCode.V766, "Infected area date or port missing", null, this.Title, null, this.Tablename)); violations.Add(RuleEngine.CreateViolation(ValidationCode.V766, "Infected area date or port missing", null, this.Title, null, this.Tablename));

View File

@ -85,7 +85,9 @@ namespace bsmd.database
FILTER_ETA, FILTER_ETA,
FILTER_TICKETNO, FILTER_TICKETNO,
FILTER_LATESTIDS, FILTER_LATESTIDS,
FILTER_CREATEDBY FILTER_CREATEDBY,
FILTER_FLAG_EQ,
FILTER_FLAG_NEQ
} }
[Flags] [Flags]
@ -692,6 +694,22 @@ namespace bsmd.database
((SqlCommand)cmd).Parameters.AddWithValue("@DRPID", searchDict[key]); ((SqlCommand)cmd).Parameters.AddWithValue("@DRPID", searchDict[key]);
break; break;
} }
case SearchFilterType.FILTER_FLAG_EQ:
{
sb.Append(" MessageCore.Flags = @FLAG ");
int flag = 0;
int.TryParse(searchDict[key], out flag);
((SqlCommand)cmd).Parameters.AddWithValue("@FLAG", flag);
break;
}
case SearchFilterType.FILTER_FLAG_NEQ:
{
sb.Append(" MessageCore.Flags <> @FLAG ");
int flag = 0;
int.TryParse(searchDict[key], out flag);
((SqlCommand)cmd).Parameters.AddWithValue("@FLAG", flag);
break;
}
} }
if (!moreThanOne) moreThanOne = true; if (!moreThanOne) moreThanOne = true;
} }

Binary file not shown.