From 28141470dad455455346877f540685c17770e528 Mon Sep 17 00:00:00 2001 From: Husky Date: Sun, 12 Aug 2018 11:15:31 +0200 Subject: [PATCH] =?UTF-8?q?Es=20wird=20=C3=BCberpr=C3=BCft=20auf=20den=20D?= =?UTF-8?q?atenbank=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/Database.csproj | 4 +++ Database/Datenbank.cs | 12 +++++++- .../DataBaseVersionMismatchException.cs | 28 +++++++++++++++++++ SanShared/SanShared.csproj | 1 + SanSystem/frmMain.cs | 12 ++++++-- 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 SanShared/Exceptions/DataBaseVersionMismatchException.cs diff --git a/Database/Database.csproj b/Database/Database.csproj index c7eabe5..e68fd1a 100644 --- a/Database/Database.csproj +++ b/Database/Database.csproj @@ -53,6 +53,10 @@ {c82bd650-466b-403f-bed9-2b1660771f54} KlassenBIB + + {c949087e-20e1-4a17-b021-faead363c1d8} + SanShared + diff --git a/Database/Datenbank.cs b/Database/Datenbank.cs index 0147ea9..e409062 100644 --- a/Database/Datenbank.cs +++ b/Database/Datenbank.cs @@ -10,6 +10,7 @@ using System.Diagnostics; using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.SharpZipLib.Core; using KlassenBIB; +using SanShared.Exceptions; namespace Database { @@ -40,7 +41,16 @@ namespace Database if (File.Exists(filepath)) { File.Copy(filepath, string.Format("{0}_{1}_{2}.bak", filepath,DateTime.Now.ToShortDateString(),DateTime.Now.Ticks)); - loadedProjekt = XamlServices.Load(filepath) as KlassenBIB.Projekt; + try + { + loadedProjekt = XamlServices.Load(filepath) as KlassenBIB.Projekt; + } + catch(XamlObjectWriterException ex) + { + string msg = ex.Message; + if (msg.ToLower().Contains("kann nicht festgelegt werden")) + throw new DataBaseVersionMismatchException(); + } } else loadedProjekt = new KlassenBIB.Projekt(); diff --git a/SanShared/Exceptions/DataBaseVersionMismatchException.cs b/SanShared/Exceptions/DataBaseVersionMismatchException.cs new file mode 100644 index 0000000..a04f7a1 --- /dev/null +++ b/SanShared/Exceptions/DataBaseVersionMismatchException.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace SanShared.Exceptions +{ + public class DataBaseVersionMismatchException : Exception + { + public DataBaseVersionMismatchException() + { + } + + public DataBaseVersionMismatchException(string message) : base(message) + { + } + + public DataBaseVersionMismatchException(string message, Exception innerException) : base(message, innerException) + { + } + + protected DataBaseVersionMismatchException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } +} diff --git a/SanShared/SanShared.csproj b/SanShared/SanShared.csproj index a790043..d7dc0b8 100644 --- a/SanShared/SanShared.csproj +++ b/SanShared/SanShared.csproj @@ -42,6 +42,7 @@ + diff --git a/SanSystem/frmMain.cs b/SanSystem/frmMain.cs index b9dcb6d..bb18266 100644 --- a/SanSystem/frmMain.cs +++ b/SanSystem/frmMain.cs @@ -1,6 +1,7 @@ using Database; using FluentFTP; using KlassenBIB; +using SanShared.Exceptions; using SchnittstelleImporter; using System; using System.Collections.Generic; @@ -31,8 +32,15 @@ namespace SanSystem //Global.Instance. if (!Directory.Exists(Global.Instance.Projektpfad)) Directory.CreateDirectory(Global.Instance.Projektpfad); - Datenbank.Instance.LoadProjekt(Global.Instance.ProjektNummer, Global.Instance.Projektpfad);// Path.Combine(Global.Instance.Projektpfad,"18-850.xaml")); - + try + { + Datenbank.Instance.LoadProjekt(Global.Instance.ProjektNummer, Global.Instance.Projektpfad);// Path.Combine(Global.Instance.Projektpfad,"18-850.xaml")); + } + catch(DataBaseVersionMismatchException) + { + MessageBox.Show("Database version mistmatch\nProgramm wird beendet"); + Environment.Exit(0); + } //Datenbank.Instance.CreateProjekt(""); this.Width = Screen.PrimaryScreen.WorkingArea.Width;