UpdateIdentifierTool zu Verbesserung der Wiederherstellungslogik

This commit is contained in:
Daniel Schick 2019-05-27 12:59:29 +00:00
parent 974817a443
commit bcc2234040
19 changed files with 311 additions and 63 deletions

View File

@ -10,6 +10,7 @@ using ENI2.Util;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System;
using System.Collections.Generic;
namespace ENI2.DetailViewControls
{
@ -342,7 +343,7 @@ namespace ENI2.DetailViewControls
// are you sure dialog is in base class
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(marpol);
this.haz.MARPOLPositions.Remove(marpol);
DatabaseEntity.ResetIdentifiers(haz.MARPOLPositions);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(haz.MARPOLPositions));
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.dataGridMARPOLItems.Items.Refresh();
}
@ -423,7 +424,7 @@ namespace ENI2.DetailViewControls
// are you sure dialog is in base class
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(imsbc);
this.haz.IMSBCPositions.Remove(imsbc);
DatabaseEntity.ResetIdentifiers(haz.IMSBCPositions);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(haz.IMSBCPositions));
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.dataGridIMSBCItems.Items.Refresh();
}
@ -503,7 +504,7 @@ namespace ENI2.DetailViewControls
// are you sure dialog is in base class
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(igc);
this.haz.IGCPositions.Remove(igc);
DatabaseEntity.ResetIdentifiers(haz.IGCPositions);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(haz.IGCPositions));
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.dataGridIGCItems.Items.Refresh();
}
@ -582,7 +583,7 @@ namespace ENI2.DetailViewControls
// are you sure dialog is in base class
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(ibc);
this.haz.IBCPositions.Remove(ibc);
DatabaseEntity.ResetIdentifiers(haz.IBCPositions);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(haz.IBCPositions));
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.dataGridIBCItems.Items.Refresh();
}
@ -661,7 +662,7 @@ namespace ENI2.DetailViewControls
// are you sure dialog is in base class
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(imdg);
this.haz.IMDGPositions.Remove(imdg);
DatabaseEntity.ResetIdentifiers(haz.IMDGPositions);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(haz.IMDGPositions));
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.dataGridIMDGItems.Items.Refresh();
}

View File

@ -8,7 +8,7 @@ using System.Windows.Controls;
using ENI2.EditControls;
using ENI2.Util;
using bsmd.database;
using System.Collections.Generic;
namespace ENI2.DetailViewControls
{
@ -306,7 +306,7 @@ namespace ENI2.DetailViewControls
// are you sure dialog is in base class
_mdh.SanitaryMeasuresDetails.Remove(smd);
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(smd);
DatabaseEntity.ResetIdentifiers(_mdh.SanitaryMeasuresDetails);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(_mdh.SanitaryMeasuresDetails));
this.SublistElementChanged(Message.NotificationClass.MDH);
this.dataGridSanitaryMeasures.Items.Refresh();
}
@ -380,7 +380,7 @@ namespace ENI2.DetailViewControls
// are you sure dialog is in base class
_mdh.InfectedAreas.Remove(ia);
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(ia);
DatabaseEntity.ResetIdentifiers(_mdh.InfectedAreas);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(_mdh.InfectedAreas));
this.SublistElementChanged(Message.NotificationClass.MDH);
this.dataGridInfectedAreas.Items.Refresh();
}
@ -455,7 +455,7 @@ namespace ENI2.DetailViewControls
_mdh.PortOfCallLast30Days.Remove(poc30d);
poc30d.DeleteElements();
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(poc30d);
DatabaseEntity.ResetIdentifiers(_mdh.PortOfCallLast30Days);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(_mdh.PortOfCallLast30Days));
this.SublistElementChanged(Message.NotificationClass.MDH);
this.dataGridPortOfCallLast30Days.Items.Refresh();
}

View File

@ -3,6 +3,7 @@
//
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
@ -118,7 +119,7 @@ namespace ENI2.DetailViewControls
// are you sure dialog is in base class
_noa_nod.CallPurposes.Remove(cp);
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(cp);
DatabaseEntity.ResetIdentifiers(_noa_nod.CallPurposes);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(_noa_nod.CallPurposes));
this.SublistElementChanged(Message.NotificationClass.NOA_NOD);
this.dataGridCallPurposes.Items.Refresh();
}

View File

@ -334,7 +334,7 @@ namespace ENI2.DetailViewControls
if (ofd.ShowDialog() ?? false)
{
FileStream stream = null;
FileStream stream;
try
{
stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);

View File

@ -165,8 +165,8 @@ namespace ENI2.DetailViewControls
{
// are you sure dialog is in base class
_was.Waste.Remove(waste);
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(waste);
DatabaseEntity.ResetIdentifiers(_was.Waste);
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(waste);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(_was.Waste));
this.SublistElementChanged(Message.NotificationClass.WAS);
this.dataGridWaste.Items.Refresh();
}
@ -242,7 +242,7 @@ namespace ENI2.DetailViewControls
ofd.Filter = "Excel Files|*.xls;*.xlsx";
if (ofd.ShowDialog() ?? false)
{
FileStream stream = null;
FileStream stream;
try
{
stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);

View File

@ -16,7 +16,8 @@
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<enictrl:ENIDataGrid Grid.Row="0" Grid.Column="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
SelectionMode="Single" AutoGenerateColumns="False" Margin="5,5,5,0" x:Name="dataGridMessageHistories" MouseDoubleClick="DataGridViolations_MouseDoubleClick">
SelectionMode="Single" AutoGenerateColumns="False" Margin="5,5,5,0" x:Name="dataGridMessageHistories"
MouseDoubleClick="DataGridViolations_MouseDoubleClick" CanUserAddRows="False">
<DataGrid.Columns>
<DataGridTextColumn Header="{x:Static p:Resources.textType}" Binding="{Binding EntityName}" IsReadOnly="True" Width="0.05*" />
<DataGridTextColumn Header="{x:Static p:Resources.textTimestamp}" Binding="{Binding Created}" IsReadOnly="True" Width="0.1*" />

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="UpdateIdentifierTool.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<applicationSettings>
<UpdateIdentifierTool.Properties.Settings>
<setting name="ConnectionString" serializeAs="String">
<value>Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=E:\DATA\DB\NSW.MDF;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False</value>
</setting>
</UpdateIdentifierTool.Properties.Settings>
</applicationSettings>
</configuration>

View File

@ -0,0 +1,69 @@
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using bsmd.database;
using System.Text.RegularExpressions;
namespace UpdateIdentifierTool
{
static class Program
{
static void Main(string[] args)
{
try
{
SqlConnection con = new SqlConnection(Properties.Settings.Default.ConnectionString);
con.Open();
Console.WriteLine();
Console.Write("LOAD..");
// alles message histories laden...
string query = "SELECT Id, ReportingPartyId, EntityId, EntityType, EntityName, EntityValues, Timestamp, Identifier FROM MessageHistory ORDER BY Timestamp";
SqlCommand cmd = new SqlCommand(query, con);
IDataReader reader = cmd.ExecuteReader();
List<MessageHistory> allHistories = MessageHistory.LoadList(reader);
reader.Close();
string updateString = "UPDATE MessageHistory SET Identifier = @IDENTIFIER WHERE ID = @ID";
SqlCommand updateCmd = new SqlCommand(updateString, con);
SqlParameter p1 = new SqlParameter("@IDENTIFIER", SqlDbType.Int);
SqlParameter p2 = new SqlParameter("@ID", SqlDbType.UniqueIdentifier);
updateCmd.Parameters.Add(p1);
updateCmd.Parameters.Add(p2);
int cnt = 0;
foreach(MessageHistory mh in allHistories)
{
object o = mh.CreateObjectFromValues();
if(o is ISublistElement)
{
string identString = ((ISublistElement)o).Identifier;
Regex re = new Regex(@"\d+");
Match m = re.Match(identString);
if (m.Success)
{
mh.Identifier = Int32.Parse(m.Value);
p1.Value = mh.Identifier;
p2.Value = mh.Id;
updateCmd.ExecuteNonQuery();
}
}
double percentage = 100 * (double) cnt / (double) allHistories.Count;
Console.Write("\b\b\b\b\b\b");
Console.Write("{0:0.###}", percentage);
cnt++;
}
Console.WriteLine();
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("UpdateIdentifierTool")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UpdateIdentifierTool")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a30955c4-8580-4c51-8622-053c7ae52d77")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,37 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace UpdateIdentifierTool.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=E:\\DATA\\DB\\NSW.MDF;Integrated " +
"Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;Appl" +
"icationIntent=ReadWrite;MultiSubnetFailover=False")]
public string ConnectionString {
get {
return ((string)(this["ConnectionString"]));
}
}
}
}

View File

@ -0,0 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="UpdateIdentifierTool.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="ConnectionString" Type="System.String" Scope="Application">
<Value Profile="(Default)">Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=E:\DATA\DB\NSW.MDF;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A30955C4-8580-4C51-8622-053C7AE52D77}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>UpdateIdentifierTool</RootNamespace>
<AssemblyName>UpdateIdentifierTool</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\bsmd.database\bsmd.database.csproj">
<Project>{19945af2-379b-46a5-b27a-303b5ec1d557}</Project>
<Name>bsmd.database</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -15,6 +15,7 @@ using System.Diagnostics;
using Newtonsoft.Json;
using log4net;
using System.Reflection;
using System.Text.RegularExpressions;
namespace bsmd.database
{
@ -772,7 +773,15 @@ namespace bsmd.database
mh.EntityValues = JsonConvert.SerializeObject(entity);
if (ReportingParty.CurrentReportingParty != null)
mh.ReportingPartyId = ReportingParty.CurrentReportingParty.Id.Value;
if (entity is ISublistElement)
{
string stringIdentifier = ((ISublistElement)entity).Identifier;
Regex re = new Regex(@"\d+");
Match m = re.Match(stringIdentifier);
if (m.Success)
mh.Identifier = Int32.Parse(m.Value);
}
// 3. MessageHistory Element speichern
// TODO: das könnte auch in einem Background Thread passieren, da der Wert erst irgendwann gelesen wird und aktuell nicht relevant ist
SqlCommand cmd = new SqlCommand();

View File

@ -16,16 +16,6 @@ namespace bsmd.database
public class HAZ : DatabaseEntity, ISublistContainer
{
#region Fields
private ObservableCollection<DatabaseEntity> imdgPositions = new ObservableCollection<DatabaseEntity>();
private ObservableCollection<DatabaseEntity> ibcPositions = new ObservableCollection<DatabaseEntity>();
private ObservableCollection<DatabaseEntity> igcPositions = new ObservableCollection<DatabaseEntity>();
private ObservableCollection<DatabaseEntity> imsbcPositions = new ObservableCollection<DatabaseEntity>();
private ObservableCollection<DatabaseEntity> marpolPositions = new ObservableCollection<DatabaseEntity>();
#endregion
public HAZ()
{ }
@ -71,16 +61,16 @@ namespace bsmd.database
[ENI2Validation]
[MaxLength(64)]
public string DPGContactPhone { get; set; }
public ObservableCollection<DatabaseEntity> IMDGPositions { get { return this.imdgPositions; } }
public ObservableCollection<DatabaseEntity> IBCPositions { get { return this.ibcPositions; } }
public ObservableCollection<DatabaseEntity> IGCPositions { get { return this.igcPositions; } }
public ObservableCollection<IMDGPosition> IMDGPositions { get; private set; } = new ObservableCollection<IMDGPosition>();
public ObservableCollection<DatabaseEntity> IMSBCPositions { get { return this.imsbcPositions; } }
public ObservableCollection<IBCPosition> IBCPositions { get; private set; } = new ObservableCollection<IBCPosition>();
public ObservableCollection<DatabaseEntity> MARPOLPositions { get { return this.marpolPositions; } }
public ObservableCollection<IGCPosition> IGCPositions { get; private set; } = new ObservableCollection<IGCPosition>();
public ObservableCollection<IMSBCPosition> IMSBCPositions { get; private set; } = new ObservableCollection<IMSBCPosition>();
public ObservableCollection<MARPOL_Annex_I_Position> MARPOLPositions { get; private set; } = new ObservableCollection<MARPOL_Annex_I_Position>();
// selektor HAZA / HAZD
[ENI2Validation]
@ -558,11 +548,11 @@ namespace bsmd.database
{
HAZ haz = this.MemberwiseClone() as HAZ;
haz.id = null;
haz.imdgPositions = new ObservableCollection<DatabaseEntity>();
haz.ibcPositions = new ObservableCollection<DatabaseEntity>();
haz.igcPositions = new ObservableCollection<DatabaseEntity>();
haz.imsbcPositions = new ObservableCollection<DatabaseEntity>();
haz.marpolPositions = new ObservableCollection<DatabaseEntity>();
haz.IMDGPositions = new ObservableCollection<IMDGPosition>();
haz.IBCPositions = new ObservableCollection<IBCPosition>();
haz.IGCPositions = new ObservableCollection<IGCPosition>();
haz.IMSBCPositions = new ObservableCollection<IMSBCPosition>();
haz.MARPOLPositions = new ObservableCollection<MARPOL_Annex_I_Position>();
foreach (IMDGPosition imdgPosition in this.IMDGPositions)
{

View File

@ -25,13 +25,13 @@ namespace bsmd.database
#region Properties
public ObservableCollection<DatabaseEntity> PortOfCallLast30Days { get; private set; } = new ObservableCollection<DatabaseEntity>();
public ObservableCollection<PortOfCallLast30Days> PortOfCallLast30Days { get; private set; } = new ObservableCollection<PortOfCallLast30Days>();
public ObservableCollection<DatabaseEntity> SanitaryMeasuresDetails { get; private set; } = new ObservableCollection<DatabaseEntity>();
public ObservableCollection<SanitaryMeasuresDetail> SanitaryMeasuresDetails { get; private set; } = new ObservableCollection<SanitaryMeasuresDetail>();
public ObservableCollection<DatabaseEntity> StowawaysJoiningLocations { get; private set; } = new ObservableCollection<DatabaseEntity>();
public ObservableCollection<StowawaysJoiningLocation> StowawaysJoiningLocations { get; private set; } = new ObservableCollection<StowawaysJoiningLocation>();
public ObservableCollection<DatabaseEntity> InfectedAreas { get; private set; } = new ObservableCollection<DatabaseEntity>();
public ObservableCollection<InfectedArea> InfectedAreas { get; private set; } = new ObservableCollection<InfectedArea>();
[ShowReport]
[Validation1(ValidationCode.NOT_NULL)]
@ -630,10 +630,10 @@ namespace bsmd.database
{
MDH mdh = this.MemberwiseClone() as MDH;
mdh.id = null;
mdh.InfectedAreas = new ObservableCollection<DatabaseEntity>();
mdh.PortOfCallLast30Days = new ObservableCollection<DatabaseEntity>();
mdh.SanitaryMeasuresDetails = new ObservableCollection<DatabaseEntity>();
mdh.StowawaysJoiningLocations = new ObservableCollection<DatabaseEntity>();
mdh.InfectedAreas = new ObservableCollection<InfectedArea>();
mdh.PortOfCallLast30Days = new ObservableCollection<PortOfCallLast30Days>();
mdh.SanitaryMeasuresDetails = new ObservableCollection<SanitaryMeasuresDetail>();
mdh.StowawaysJoiningLocations = new ObservableCollection<StowawaysJoiningLocation>();
foreach (InfectedArea ia in this.InfectedAreas)
{

View File

@ -36,6 +36,8 @@ namespace bsmd.database
public DateTime Created { get; private set; }
public int Identifier { get; set; }
/// <summary>
/// ENI Grid helper property
/// </summary>
@ -56,7 +58,7 @@ namespace bsmd.database
internal static string GetLoadCommand()
{
return "SELECT Id, ReportingPartyId, EntityId, EntityType, EntityName, EntityValues, Timestamp FROM MessageHistory WHERE EntityId=@ENTITYID ORDER BY Timestamp";
return "SELECT Id, ReportingPartyId, EntityId, EntityType, EntityName, EntityValues, Timestamp, Identifier FROM MessageHistory WHERE EntityId = @ENTITYID ORDER BY Timestamp, Identifier";
}
public object CreateObjectFromValues()
@ -104,14 +106,18 @@ namespace bsmd.database
}
// Elemente nach dem ausgewählten Element hinzufügen (wenn sie zur gleichen Gruppe gehören)
indexIdentifier = myIdentifier;
for(int tmpIndex = selIndex + 1; (indexIdentifier != 1) && (tmpIndex < tmpList.Count); tmpIndex++)
if ((tmpList.Count - 1) > selIndex)
{
DatabaseEntity nextEntity = tmpList[tmpIndex].CreateObjectFromValues() as DatabaseEntity;
DatabaseEntity nextEntity = tmpList[selIndex + 1].CreateObjectFromValues() as DatabaseEntity;
indexIdentifier = Int32.Parse(((ISublistElement)nextEntity).Identifier);
tmpResult.AddLast(nextEntity);
}
for (int tmpIndex = selIndex + 2; (indexIdentifier != 1) && (tmpIndex < tmpList.Count); tmpIndex++)
{
tmpResult.AddLast(nextEntity);
nextEntity = tmpList[tmpIndex].CreateObjectFromValues() as DatabaseEntity;
indexIdentifier = Int32.Parse(((ISublistElement)nextEntity).Identifier);
}
}
}
return new List<DatabaseEntity>(tmpResult);
@ -135,9 +141,10 @@ namespace bsmd.database
scmd.Parameters.AddWithValue("@P4", this.EntityName);
scmd.Parameters.AddWithValue("@P5", this.EntityValues);
scmd.Parameters.AddWithValue("@P6", DateTime.Now);
scmd.Parameters.AddWithValue("@P7", this.Identifier);
cmd.CommandText = string.Format("INSERT INTO {0} (Id, ReportingPartyId, EntityId, EntityType, " +
"EntityName, EntityValues, Timestamp) VALUES (@ID, @P1, @P2, @P3, @P4, @P5, @P6)", this.Tablename);
"EntityName, EntityValues, Timestamp, Identifier) VALUES (@ID, @P1, @P2, @P3, @P4, @P5, @P6, @P7)", this.Tablename);
}
public void PrepareDelete(IDbCommand cmd)
@ -147,7 +154,7 @@ namespace bsmd.database
scmd.Parameters.AddWithValue("@ID", this.Id);
}
internal static List<MessageHistory> LoadList(IDataReader reader)
public static List<MessageHistory> LoadList(IDataReader reader)
{
List<MessageHistory> result = new List<MessageHistory>();
@ -161,6 +168,7 @@ namespace bsmd.database
if (!reader.IsDBNull(4)) mh.EntityName = reader.GetString(4);
if (!reader.IsDBNull(5)) mh.EntityValues = reader.GetString(5);
if (!reader.IsDBNull(6)) mh.Created = reader.GetDateTime(6);
if (!reader.IsDBNull(7)) mh.Identifier = reader.GetInt32(7);
result.Add(mh);
}

View File

@ -35,7 +35,7 @@ namespace bsmd.database
public DateTime? ETDFromPortOfCall { get; set; }
[Validation1(ValidationCode.LIST_EMPTY)]
public ObservableCollection<DatabaseEntity> CallPurposes { get; } = new ObservableCollection<DatabaseEntity>();
public ObservableCollection<CallPurpose> CallPurposes { get; } = new ObservableCollection<CallPurpose>();
[ShowReport]
[Validation2(ValidationCode.NOT_NULL)]

View File

@ -28,7 +28,7 @@ namespace bsmd.database
[JsonIgnore]
public MDH MDH { get; set; }
public List<DatabaseEntity> CrewJoinedShip { get; private set; } = new List<DatabaseEntity>();
public List<PortOfCallLast30DaysCrewJoinedShip> CrewJoinedShip { get; private set; } = new List<PortOfCallLast30DaysCrewJoinedShip>();
[ShowReport]
[Validation2(ValidationCode.LOCODE)]
[MaxLength(5)]
@ -116,7 +116,7 @@ namespace bsmd.database
this.CrewJoinedShip.Clear();
// add existing and new crew
this.CrewJoinedShip.AddRange(foundList);
DatabaseEntity.ResetIdentifiers(this.CrewJoinedShip);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(this.CrewJoinedShip));
}
}
}
@ -273,7 +273,7 @@ namespace bsmd.database
{
PortOfCallLast30Days p30 = this.MemberwiseClone() as PortOfCallLast30Days;
p30.id = null;
p30.CrewJoinedShip = new List<DatabaseEntity>();
p30.CrewJoinedShip = new List<PortOfCallLast30DaysCrewJoinedShip>();
foreach (PortOfCallLast30DaysCrewJoinedShip p30Crew in this.CrewJoinedShip)
{

View File

@ -65,9 +65,9 @@ namespace bsmd.database
[ENI2Validation]
public bool? ConfirmationOfSufficiency { get; set; }
public ObservableCollection<DatabaseEntity> Waste { get; private set; } = new ObservableCollection<DatabaseEntity>();
public ObservableCollection<Waste> Waste { get; private set; } = new ObservableCollection<Waste>();
public ObservableCollection<DatabaseEntity> WasteDisposalServiceProvider { get; private set; } = new ObservableCollection<DatabaseEntity>();
public ObservableCollection<WasteDisposalServiceProvider> WasteDisposalServiceProvider { get; private set; } = new ObservableCollection<WasteDisposalServiceProvider>();
/// <summary>
/// Hilfsproperty, um eine kommaseparierte Liste von WasteDisposalServiceProvider (analog ANSW) im ENI-2 anzuzeigen,
@ -137,7 +137,8 @@ namespace bsmd.database
// add existing and new providers
foreach(WasteDisposalServiceProvider wdsp in foundList)
this.WasteDisposalServiceProvider.Add(wdsp);
DatabaseEntity.ResetIdentifiers(this.WasteDisposalServiceProvider);
List<DatabaseEntity> tmpList = new List<DatabaseEntity>(this.WasteDisposalServiceProvider);
DatabaseEntity.ResetIdentifiers(tmpList);
}
}
}
@ -490,8 +491,8 @@ namespace bsmd.database
{
WAS was = this.MemberwiseClone() as WAS;
was.id = null;
was.Waste = new ObservableCollection<DatabaseEntity>();
was.WasteDisposalServiceProvider = new ObservableCollection<DatabaseEntity>();
was.Waste = new ObservableCollection<Waste>();
was.WasteDisposalServiceProvider = new ObservableCollection<WasteDisposalServiceProvider>();
foreach (Waste waste in this.Waste)
{