From f7e3042daac27a90623fe744fe45ef026d09a916 Mon Sep 17 00:00:00 2001 From: Husky Date: Sat, 14 Jul 2018 12:25:47 +0200 Subject: [PATCH] Man kann jetzt die einstellungen speichern --- SanSystem/Einstellungen/ObjecteListSetting.cs | 26 ++++++++++ SanSystem/Einstellungen/Settings.cs | 49 +++++++++++++++++++ SanSystem/Global.cs | 48 ++++++++++++++++-- SanSystem/SanSystem.csproj | 5 ++ SanSystem/frmMain.cs | 3 +- SanSystem/frmObjekteList.Designer.cs | 2 + SanSystem/frmObjekteList.cs | 16 ++++++ SanSystem/packages.config | 1 + 8 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 SanSystem/Einstellungen/ObjecteListSetting.cs create mode 100644 SanSystem/Einstellungen/Settings.cs diff --git a/SanSystem/Einstellungen/ObjecteListSetting.cs b/SanSystem/Einstellungen/ObjecteListSetting.cs new file mode 100644 index 0000000..0b603fd --- /dev/null +++ b/SanSystem/Einstellungen/ObjecteListSetting.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SanSystem.Einstellungen +{ + class ObjecteListSetting : Settings + { + public ObjecteListSetting() : base("ObjecteList") { } + + public override void InitDevValues() + { + // Hausnummer + // Von punkt + // Bis punkt + // Haltungslänge + + configuration.Add("Hausnummer", 40); + configuration.Add("VonPunkt", 100); + configuration.Add("BisPunkt", 100); + configuration.Add("Haltungslaenge", 40); + } + } +} diff --git a/SanSystem/Einstellungen/Settings.cs b/SanSystem/Einstellungen/Settings.cs new file mode 100644 index 0000000..2a5fce4 --- /dev/null +++ b/SanSystem/Einstellungen/Settings.cs @@ -0,0 +1,49 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SanSystem.Einstellungen +{ + abstract class Settings : IDisposable + { + public Dictionary configuration = new Dictionary(); + + const string pfad = "Settings"; + + string modPath = ""; + public Settings(string module) + { + string modname = string.Format("{0}.set", module); + + modPath = Path.Combine(pfad, modname); + if (!Directory.Exists(pfad)) Directory.CreateDirectory(pfad); + if(!File.Exists(modPath)) + { + InitDevValues(); + SaveSettings(); + } + else + { + string input = File.ReadAllText(modPath); + configuration = (Dictionary)JsonConvert.DeserializeObject(input, typeof(Dictionary)); + } + } + + public abstract void InitDevValues(); + + public virtual void SaveSettings() + { + string ser = JsonConvert.SerializeObject(configuration); + File.WriteAllText(modPath, ser); + } + + public void Dispose() + { + SaveSettings(); + } + } +} diff --git a/SanSystem/Global.cs b/SanSystem/Global.cs index 1bb94ce..c4a6824 100644 --- a/SanSystem/Global.cs +++ b/SanSystem/Global.cs @@ -1,4 +1,5 @@ -using SanShared; +using Microsoft.Win32; +using SanShared; using System; using System.Collections.Generic; using System.IO; @@ -12,9 +13,24 @@ namespace SanSystem { public static readonly Global instance = new Global(); + const string userroot = "HKEY_CURRENT_USER\\Software"; + const string firmkey = "Cosysda"; + const string subkey = "SanManager"; const string speicherpfad_to_projekts = "projekte"; - string projektpfad = "18-850"; + string projektpfad = "18-850"; + + public string ProjektNummer + { + get + { + return projektpfad; + } + set + { + projektpfad = value; + } + } public string Projektpfad { get @@ -34,12 +50,24 @@ namespace SanSystem void LadeRegistry() { - string userroot = "HKEY_CURRENT_USER\\Software"; - string firmkey = "Cosysda"; - string subkey = "SanManager"; + string keyName = userroot + "\\" + firmkey + "\\" + subkey; + string lastProjektNummer = ""; + try + { + lastProjektNummer = Registry.GetValue(keyName, "LastProjekt", "").ToString(); + ProjektNummer = lastProjektNummer; + } + catch + { } + } + + void SpeicherInRegistry() + { + string keyName = userroot + "\\" + firmkey + "\\" + subkey; + Registry.SetValue(keyName, "LastProjekt", ProjektNummer); } @@ -48,5 +76,15 @@ namespace SanSystem { language = Language.Language.GetLanguage(Language.BUILTINLANGUAGES.GERMAN); } + + public Global() + { + LadeRegistry(); + } + + ~Global() + { + SpeicherInRegistry(); + } } } diff --git a/SanSystem/SanSystem.csproj b/SanSystem/SanSystem.csproj index d398d5c..cf8257b 100644 --- a/SanSystem/SanSystem.csproj +++ b/SanSystem/SanSystem.csproj @@ -38,6 +38,9 @@ ..\packages\Ionic.Zip.1.9.1.8\lib\Ionic.Zip.dll + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + False ..\3rdPackage\Syncfusion.Chart.Base.dll @@ -65,6 +68,8 @@ + + Form diff --git a/SanSystem/frmMain.cs b/SanSystem/frmMain.cs index 40ecabf..6c014dd 100644 --- a/SanSystem/frmMain.cs +++ b/SanSystem/frmMain.cs @@ -22,9 +22,10 @@ namespace SanSystem { InitializeComponent(); + //Global.Instance. if (!Directory.Exists(Global.Instance.Projektpfad)) Directory.CreateDirectory(Global.Instance.Projektpfad); - Datenbank.Instance.LoadProjekt("18-850", Global.Instance.Projektpfad);// Path.Combine(Global.Instance.Projektpfad,"18-850.xaml")); + Datenbank.Instance.LoadProjekt(Global.Instance.ProjektNummer, Global.Instance.Projektpfad);// Path.Combine(Global.Instance.Projektpfad,"18-850.xaml")); //Datenbank.Instance.CreateProjekt(""); diff --git a/SanSystem/frmObjekteList.Designer.cs b/SanSystem/frmObjekteList.Designer.cs index d3c28a8..9bfcc12 100644 --- a/SanSystem/frmObjekteList.Designer.cs +++ b/SanSystem/frmObjekteList.Designer.cs @@ -55,6 +55,7 @@ // dGObjekte // this.dGObjekte.AllowUserToOrderColumns = true; + this.dGObjekte.AllowUserToResizeRows = false; this.dGObjekte.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dGObjekte.Location = new System.Drawing.Point(10, 77); this.dGObjekte.Margin = new System.Windows.Forms.Padding(2); @@ -243,6 +244,7 @@ this.Name = "frmObjekteList"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "frmObjekteList"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmObjekteList_FormClosing); this.Load += new System.EventHandler(this.frmObjekteList_Load); ((System.ComponentModel.ISupportInitialize)(this.dGObjekte)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.strasseBindingSource)).EndInit(); diff --git a/SanSystem/frmObjekteList.cs b/SanSystem/frmObjekteList.cs index 35765fb..c1eaa02 100644 --- a/SanSystem/frmObjekteList.cs +++ b/SanSystem/frmObjekteList.cs @@ -1,5 +1,6 @@ using Database; using KlassenBIB; +using SanSystem.Einstellungen; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -17,6 +18,7 @@ namespace SanSystem { private List inspektionsobjekte; + ObjecteListSetting objecteListSetting = new ObjecteListSetting(); private void loadObjekte(string streetname) { @@ -192,6 +194,11 @@ namespace SanSystem dGObjekte.Columns["Objektbezeichnung"].Visible = false; dGObjekte.Columns["Haltunggemessen"].Visible = false; dGObjekte.Columns["Bemerkung"].Visible = false; + + dGObjekte.Columns["Hausnummer"].Width = objecteListSetting.configuration["Hausnummer"]; + dGObjekte.Columns["VonPunkt"].Width = objecteListSetting.configuration["VonPunkt"]; + dGObjekte.Columns["BisPunkt"].Width = objecteListSetting.configuration["BisPunkt"]; + dGObjekte.Columns["Haltungslaenge"].Width = objecteListSetting.configuration["Haltungslaenge"]; //dGObjekte.Columns["Sanierung"].Visible = false; } @@ -199,5 +206,14 @@ namespace SanSystem { CheckEntries(); } + + private void frmObjekteList_FormClosing(object sender, FormClosingEventArgs e) + { + objecteListSetting.configuration["Hausnummer"] = dGObjekte.Columns["Hausnummer"].Width; + objecteListSetting.configuration["VonPunkt"] = dGObjekte.Columns["VonPunkt"].Width; + objecteListSetting.configuration["BisPunkt"] = dGObjekte.Columns["BisPunkt"].Width; + objecteListSetting.configuration["Haltungslaenge"] = dGObjekte.Columns["Haltungslaenge"].Width; + objecteListSetting.SaveSettings(); + } } } diff --git a/SanSystem/packages.config b/SanSystem/packages.config index 9351d06..b736f10 100644 --- a/SanSystem/packages.config +++ b/SanSystem/packages.config @@ -2,4 +2,5 @@ + \ No newline at end of file