diff --git a/ENI-2/ENI2/ENI2/MainWindow.xaml.cs b/ENI-2/ENI2/ENI2/MainWindow.xaml.cs index c4480b1d..24edc984 100644 --- a/ENI-2/ENI2/ENI2/MainWindow.xaml.cs +++ b/ENI-2/ENI2/ENI2/MainWindow.xaml.cs @@ -258,27 +258,23 @@ namespace ENI2 { efMode = true; logoImage.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/ef_logo.png")); - } + } + Microsoft.Win32.SystemEvents.SessionEnded += SystemEvents_SessionEnded; + } + + private void SystemEvents_SessionEnded(object sender, Microsoft.Win32.SessionEndedEventArgs e) + { + this.UnlockOpenCores(); } private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { - try - { - // unlock all cores - foreach (ClosableTabItem tabItem in this.lockedCores.Keys) - { - App.LockingServiceClient.Unlock(lockedCores[tabItem], this.userEntity.Id.Value); - } - } - catch(Exception ex) - { - _log.ErrorFormat("LockingService.Unlock: {0}", ex.Message); - } + this.UnlockOpenCores(); DBManager.Instance.Disconnect(); Properties.Settings.Default.MainWindowPlacement = this.GetPlacement(); Properties.Settings.Default.Save(); + Microsoft.Win32.SystemEvents.SessionEnded -= SystemEvents_SessionEnded; } private void Window_SourceInitialized(object sender, EventArgs e) @@ -329,7 +325,11 @@ namespace ENI2 e.CanExecute = true; - } + } + + #endregion + + #region window control events private void buttonNewTransitIdClick(object sender, RoutedEventArgs e) { @@ -538,7 +538,27 @@ namespace ENI2 this.Close(); } - #endregion + #endregion + + #region private methods + + private void UnlockOpenCores() + { + try + { + // unlock all cores + foreach (ClosableTabItem tabItem in this.lockedCores.Keys) + { + App.LockingServiceClient.Unlock(lockedCores[tabItem], this.userEntity.Id.Value); + } + } + catch (Exception ex) + { + _log.ErrorFormat("LockingService.Unlock: {0}", ex.Message); + } + } + + #endregion } } diff --git a/Stundensheet.xlsx b/Stundensheet.xlsx index 1d2748ed..1109b1ee 100644 Binary files a/Stundensheet.xlsx and b/Stundensheet.xlsx differ diff --git a/nsw/Source/SQL/Update_To_5.2.sql b/nsw/Source/SQL/Update_To_5.2.sql new file mode 100644 index 00000000..0a3cba52 --- /dev/null +++ b/nsw/Source/SQL/Update_To_5.2.sql @@ -0,0 +1,10 @@ +CREATE TABLE [dbo].[MessageHistory] +( + [Id] UNIQUEIDENTIFIER NOT NULL PRIMARY KEY, + [ReportingPartyId] UNIQUEIDENTIFIER NULL, + [EntityId] UNIQUEIDENTIFIER NOT NULL, + [EntityType] NVARCHAR(100) NOT NULL, + [EntityName] NVARCHAR(50) NULL, + [EntityValues] NVARCHAR(MAX) NULL, + [Timestamp] DATETIME NOT NULL DEFAULT GETDATE() +) diff --git a/nsw/Source/bsmd.database/DBManager.cs b/nsw/Source/bsmd.database/DBManager.cs index e4bd52c8..f9980963 100644 --- a/nsw/Source/bsmd.database/DBManager.cs +++ b/nsw/Source/bsmd.database/DBManager.cs @@ -569,7 +569,8 @@ namespace bsmd.database entity.PrepareSave(cmd); int queryResult = this.PerformNonQuery(cmd); this.LogNonQueryResult(cmd.CommandText, queryResult); - + this.CreateEntityHistoryEntry(entity); + if (this._closeConnectionAfterUse) this.Disconnect(); } @@ -622,7 +623,7 @@ namespace bsmd.database SqlCommand cmd = new SqlCommand(); core.PrepareSave(cmd); int queryResult = this.PerformNonQuery(cmd); - this.LogNonQueryResult(cmd.CommandText, queryResult); + this.LogNonQueryResult(cmd.CommandText, queryResult); if (this._closeConnectionAfterUse) this.Disconnect(); } @@ -710,6 +711,19 @@ namespace bsmd.database } } + private void CreateEntityHistoryEntry(DatabaseEntity entity) + { + // switch(entity.) + // 1. prüfen ob für das Objekt ein Historieneintrag angelegt werden soll + + // 2. falls ja Objekt serialisieren + + // 3. MessageHistory Element speichern + // (das könnte auch in einem Background Thread passieren, da der Wert erst irgendwann gelesen wird und aktuell nicht relevant ist) + + } + + #region CreateMessage() /// @@ -758,6 +772,8 @@ namespace bsmd.database #endregion + #region LoadDependingLists + /// /// Loads inner lists / collections /// @@ -1022,6 +1038,10 @@ namespace bsmd.database } + #endregion + + #region Error / Violation + internal void LoadErrorList(Message message) { MessageError aMessageError = new MessageError(); @@ -1055,6 +1075,42 @@ namespace bsmd.database message.SystemErrorList.Add(sError); } + internal Dictionary LoadErrorTexts() + { + SqlCommand cmd = new SqlCommand(); + cmd.CommandText = "SELECT ErrorCode, ErrorText FROM ErrorText"; + SqlDataReader reader = this.PerformCommand(cmd); + Dictionary result = new Dictionary(); + while (reader.Read()) + { + int errorCode = reader.GetInt32(0); + string errorText = reader.GetString(1); + result[errorCode] = errorText; + } + reader.Close(); + return result; + } + + internal Dictionary LoadViolationTexts() + { + SqlCommand cmd = new SqlCommand(); + cmd.CommandText = "SELECT ViolationCode, ViolationText FROM ViolationText"; + SqlDataReader reader = this.PerformCommand(cmd); + Dictionary result = new Dictionary(); + while (reader.Read()) + { + int violationCode = reader.GetInt32(0); + string violationText = reader.GetString(1); + result[violationCode] = violationText; + } + reader.Close(); + return result; + } + + #endregion + + #region Convenience loading functions + internal void LoadCustomer(MessageCore core) { if (core.CustomerId.HasValue) @@ -1155,37 +1211,7 @@ namespace bsmd.database reader.Close(); } - internal Dictionary LoadErrorTexts() - { - SqlCommand cmd = new SqlCommand(); - cmd.CommandText = "SELECT ErrorCode, ErrorText FROM ErrorText"; - SqlDataReader reader = this.PerformCommand(cmd); - Dictionary result = new Dictionary(); - while (reader.Read()) - { - int errorCode = reader.GetInt32(0); - string errorText = reader.GetString(1); - result[errorCode] = errorText; - } - reader.Close(); - return result; - } - - internal Dictionary LoadViolationTexts() - { - SqlCommand cmd = new SqlCommand(); - cmd.CommandText = "SELECT ViolationCode, ViolationText FROM ViolationText"; - SqlDataReader reader = this.PerformCommand(cmd); - Dictionary result = new Dictionary(); - while (reader.Read()) - { - int violationCode = reader.GetInt32(0); - string violationText = reader.GetString(1); - result[violationCode] = violationText; - } - reader.Close(); - return result; - } + #endregion #region DB access methods diff --git a/nsw/Source/bsmd.database/DatabaseEntity.cs b/nsw/Source/bsmd.database/DatabaseEntity.cs index 5a214bbb..e7110245 100644 --- a/nsw/Source/bsmd.database/DatabaseEntity.cs +++ b/nsw/Source/bsmd.database/DatabaseEntity.cs @@ -14,15 +14,22 @@ using System.Linq; using System.Collections.Generic; using System.Reflection; using System.Text.RegularExpressions; +using System.Xml.Serialization; +using System.IO; +using log4net; namespace bsmd.database { + [XmlInclude(typeof(Message))] + [XmlInclude(typeof(MessageCore))] + [XmlInclude(typeof(AGNT))] public abstract class DatabaseEntity : IMessageParagraph, IEquatable, ICloneable { protected Guid? id; protected string tablename; private Guid instance_id = Guid.NewGuid(); // Comparison id in case entity has not been saved + private static readonly ILog _log = LogManager.GetLogger(typeof(DatabaseEntity)); #region delegate / events // Ein etwas hakeliger Mechanismus, damit ein abhängiges Projekt (ReportGenerator) die Werte ersetzen kann ohne dass die ganze Logik @@ -360,5 +367,33 @@ namespace bsmd.database #endregion + #region Serialization + + public static DatabaseEntity Deserialize(string serializedClass) + { + + + } + + public string Serialize() + { + using (StringWriter sw = new StringWriter()) + { + try + { + XmlSerializer serializer = new XmlSerializer(this.GetType()); + serializer.Serialize(sw, this); + return sw.ToString(); + } + catch (Exception ex) + { + _log.ErrorFormat("Serialization failed: {0}", ex.Message); + } + } + return null; + } + + #endregion + } } diff --git a/nsw/Source/bsmd.database/MessageHistory.cs b/nsw/Source/bsmd.database/MessageHistory.cs new file mode 100644 index 00000000..ec27cc9b --- /dev/null +++ b/nsw/Source/bsmd.database/MessageHistory.cs @@ -0,0 +1,33 @@ +// Copyright (c) 2015-2017 schick Informatik +// Description: + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace bsmd.database +{ + public class MessageHistory + { + + #region Properties + + public Guid? ReportingPartyId { get; set; } + + ReportingParty CreatedBy { get; set; } + + public Guid EntityId { get; private set; } + + public string EntityType { get; private set; } + + public string EntityName { get; private set; } + + public string EntityValues { get; private set; } + + public DateTime Created { get; private set; } + + #endregion + + } +} diff --git a/nsw/Source/bsmd.database/bsmd.database.csproj b/nsw/Source/bsmd.database/bsmd.database.csproj index e32e1790..7db99649 100644 --- a/nsw/Source/bsmd.database/bsmd.database.csproj +++ b/nsw/Source/bsmd.database/bsmd.database.csproj @@ -76,6 +76,7 @@ +