From a0279733583b4ca54d6202245e95ef36cc211988 Mon Sep 17 00:00:00 2001 From: HuskyTeufel Date: Wed, 13 Apr 2022 11:51:37 +0200 Subject: [PATCH] =?UTF-8?q?AnlageIP=20adresse=20kann=20nun=20im=20Menu=20g?= =?UTF-8?q?e=C3=A4ndert=20werden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SanShared/Dongle.cs | 6 +- SanSystem/Einstellungen/ObjecteListSetting.cs | 4 +- SanSystem/Einstellungen/Settings.cs | 11 +- .../Einstellungen/SoftwareConfiguration.cs | 56 ++++++++ SanSystem/Global.cs | 4 +- SanSystem/Program.cs | 8 +- SanSystem/SanSystem.csproj | 10 ++ SanSystem/frmMain.Designer.cs | 30 +++-- SanSystem/frmMain.cs | 21 ++- SanSystem/frmSettings.Designer.cs | 85 +++++++++++++ SanSystem/frmSettings.cs | 43 +++++++ SanSystem/frmSettings.resx | 120 ++++++++++++++++++ 12 files changed, 378 insertions(+), 20 deletions(-) create mode 100644 SanSystem/Einstellungen/SoftwareConfiguration.cs create mode 100644 SanSystem/frmSettings.Designer.cs create mode 100644 SanSystem/frmSettings.cs create mode 100644 SanSystem/frmSettings.resx diff --git a/SanShared/Dongle.cs b/SanShared/Dongle.cs index 30bfa7f..e9f3bb4 100644 --- a/SanShared/Dongle.cs +++ b/SanShared/Dongle.cs @@ -28,6 +28,7 @@ namespace SanShared this.FirmCode = 103086; this.ProductCode = ProductCode; #else + return; this.FirmCode = 10; this.ProductCode = 1; #endif @@ -101,6 +102,9 @@ namespace SanShared public void CleanDongle() { +#if DEBUG + return; +#endif cmApi.CmRelease(hcmse); } @@ -142,7 +146,7 @@ namespace SanShared public bool IsLicensed(byte neededMask) { -#if LAPTOP +#if DEBUG return true; #else uint DongleFeature = GetFeatureMap(); diff --git a/SanSystem/Einstellungen/ObjecteListSetting.cs b/SanSystem/Einstellungen/ObjecteListSetting.cs index 9dee389..6a90b97 100644 --- a/SanSystem/Einstellungen/ObjecteListSetting.cs +++ b/SanSystem/Einstellungen/ObjecteListSetting.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; +using System.Net; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -18,7 +20,7 @@ namespace SanSystem.Einstellungen try { - result = getConfiguration(dataGridViewColumn.HeaderText); + result = (int)getConfiguration(dataGridViewColumn.HeaderText); } catch(Exception ) { diff --git a/SanSystem/Einstellungen/Settings.cs b/SanSystem/Einstellungen/Settings.cs index da930c7..185e0a9 100644 --- a/SanSystem/Einstellungen/Settings.cs +++ b/SanSystem/Einstellungen/Settings.cs @@ -11,7 +11,8 @@ namespace SanSystem.Einstellungen { abstract class Settings : IDisposable { - protected Dictionary configuration = new Dictionary(); + protected Dictionary configuration = new Dictionary(); + const string pfad = "Settings"; @@ -30,15 +31,15 @@ namespace SanSystem.Einstellungen else { string input = File.ReadAllText(modPath); - configuration = (Dictionary)JsonConvert.DeserializeObject(input, typeof(Dictionary)); + configuration = (Dictionary)JsonConvert.DeserializeObject(input, typeof(Dictionary)); } } - protected int getConfiguration(string keyName, int retry = 0) + protected long getConfiguration(string keyName, int retry = 0) { if (retry >= 3) throw new Exception("Fehler, zuviele versuche"); - int result = -1; + long result = -1; if(!configuration.TryGetValue(keyName,out result)) { configuration.Add(keyName, 20); @@ -53,7 +54,7 @@ namespace SanSystem.Einstellungen } } - protected void setConfig(string keyName, int value) + protected void setConfig(string keyName, long value) { configuration[keyName] = value; } diff --git a/SanSystem/Einstellungen/SoftwareConfiguration.cs b/SanSystem/Einstellungen/SoftwareConfiguration.cs new file mode 100644 index 0000000..e2f0294 --- /dev/null +++ b/SanSystem/Einstellungen/SoftwareConfiguration.cs @@ -0,0 +1,56 @@ +using System; + +namespace SanSystem.Einstellungen +{ + class SoftwareConfiguration : Settings + { + long IPToLong(string addr) + { + System.Net.IPAddress ip; + if (System.Net.IPAddress.TryParse(addr, out ip)) + return (((long)ip.GetAddressBytes()[0] << 24) | ((int)ip.GetAddressBytes()[1] << 16) | ((int)ip.GetAddressBytes()[2] << 8) | ip.GetAddressBytes()[3]); + else return 0; + } + + string LongToIP(long addr) + { + System.Net.IPAddress tmpIp; + if (System.Net.IPAddress.TryParse(addr.ToString(), out tmpIp)) + { + return tmpIp.ToString(); + /*try + { + Byte[] bytes = tmpIp.GetAddressBytes(); + long addrs = (long)BitConverter.ToInt32(bytes, 0); + return new System.Net.IPAddress(addrs).ToString(); + } + */ + //catch (Exception e) { return e.Message; } + } + else return String.Empty; + } + + internal void SetAnlageIP(string text) + { + setConfig("ANLAGEIP",IPToLong(text)); + } + + public SoftwareConfiguration() : base("SoftwareConfiguration") + { + + } + + public string GetAnlageIP() + { + long ip = getConfiguration("ANLAGEIP"); + if (ip <= 0) throw new Exception("Something went wrong"); + return LongToIP(ip); + } + + public override void InitDevValues() + { + configuration.Add("ANLAGEIP", IPToLong("192.168.2.248")); + + } + } +} diff --git a/SanSystem/Global.cs b/SanSystem/Global.cs index eac87bc..d932861 100644 --- a/SanSystem/Global.cs +++ b/SanSystem/Global.cs @@ -1,6 +1,7 @@ using KlassenBIB; using Microsoft.Win32; using SanShared; +using SanSystem.Einstellungen; using System; using System.Collections.Generic; using System.Diagnostics; @@ -185,11 +186,12 @@ namespace SanSystem { Ping pingSender = new Ping(); PingOptions options = new PingOptions(); + SoftwareConfiguration softwareConfiguration = new SoftwareConfiguration(); string data = "aaaaaaaaaaaaa"; byte[] buffer = Encoding.ASCII.GetBytes(data); int timeout = 20; - PingReply reply = pingSender.Send("192.168.2.248", timeout, buffer, options); + PingReply reply = pingSender.Send(softwareConfiguration.GetAnlageIP(), timeout, buffer, options); return reply.Status == IPStatus.Success; } diff --git a/SanSystem/Program.cs b/SanSystem/Program.cs index 229342f..d33be8a 100644 --- a/SanSystem/Program.cs +++ b/SanSystem/Program.cs @@ -24,6 +24,7 @@ namespace SanSystem MessageBox.Show("Bitte nur 1 Instanz starten der Software!", "", MessageBoxButtons.OK, MessageBoxIcon.Hand); Environment.Exit(1); } +#if !DEBUG using (Dongle dongle = new Dongle(60)) { if (dongle.CheckDongleVorhanden()) @@ -40,7 +41,12 @@ namespace SanSystem MessageBox.Show("Sorry es wurde kein Dongle gefunden!"); Application.Exit(); } - } +#else + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new frmMain()); +#endif } + } } diff --git a/SanSystem/SanSystem.csproj b/SanSystem/SanSystem.csproj index 5d76bbf..a635b35 100644 --- a/SanSystem/SanSystem.csproj +++ b/SanSystem/SanSystem.csproj @@ -109,6 +109,7 @@ + Form @@ -218,6 +219,12 @@ frmSelectNewSan.cs + + Form + + + frmSettings.cs + Form @@ -319,6 +326,9 @@ frmSelectNewSan.cs + + frmSettings.cs + frmStrassenList.cs diff --git a/SanSystem/frmMain.Designer.cs b/SanSystem/frmMain.Designer.cs index 6781c02..74167b4 100644 --- a/SanSystem/frmMain.Designer.cs +++ b/SanSystem/frmMain.Designer.cs @@ -38,6 +38,7 @@ this.stammdatenImportierenToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.auftraggeberToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.prefixSuffixToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.exportFürBüroErstellenToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.speichernToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.massenstatistikToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.projektordnerÖffnenToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -51,7 +52,7 @@ this.toolstrip_gesamtLiner = new System.Windows.Forms.ToolStripStatusLabel(); this.toolstrip_messages = new System.Windows.Forms.ToolStripStatusLabel(); this.update = new UpdateLib.Updater(); - this.exportFürBüroErstellenToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.configuration = new System.Windows.Forms.ToolStripMenuItem(); this.mainmenu.SuspendLayout(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -67,10 +68,11 @@ this.projektordnerÖffnenToolStripMenuItem, this.toolStripMenuItem1, this.imprägnierberichteToolStripMenuItem, - this.berichteToolStripMenuItem}); + this.berichteToolStripMenuItem, + this.configuration}); this.mainmenu.Location = new System.Drawing.Point(0, 0); this.mainmenu.Name = "mainmenu"; - this.mainmenu.Size = new System.Drawing.Size(813, 29); + this.mainmenu.Size = new System.Drawing.Size(921, 29); this.mainmenu.TabIndex = 1; this.mainmenu.Text = "menuStrip1"; // @@ -122,6 +124,13 @@ this.prefixSuffixToolStripMenuItem.Text = "Prefix / Suffix"; this.prefixSuffixToolStripMenuItem.Click += new System.EventHandler(this.PrefixSuffixToolStripMenuItem_Click); // + // exportFürBüroErstellenToolStripMenuItem + // + this.exportFürBüroErstellenToolStripMenuItem.Name = "exportFürBüroErstellenToolStripMenuItem"; + this.exportFürBüroErstellenToolStripMenuItem.Size = new System.Drawing.Size(254, 26); + this.exportFürBüroErstellenToolStripMenuItem.Text = "Export für Büro erstellen"; + this.exportFürBüroErstellenToolStripMenuItem.Click += new System.EventHandler(this.exportFürBüroErstellenToolStripMenuItem_Click); + // // speichernToolStripMenuItem // this.speichernToolStripMenuItem.Name = "speichernToolStripMenuItem"; @@ -187,7 +196,7 @@ this.toolstrip_messages}); this.statusStrip1.Location = new System.Drawing.Point(0, 431); this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Size = new System.Drawing.Size(813, 22); + this.statusStrip1.Size = new System.Drawing.Size(921, 22); this.statusStrip1.TabIndex = 3; this.statusStrip1.Text = "statusStrip1"; // @@ -214,18 +223,18 @@ // this.update.UpdateUrl = "http://home.cosysda.de/sanverwaltung/UpdateInfo.dat"; // - // exportFürBüroErstellenToolStripMenuItem + // configuration // - this.exportFürBüroErstellenToolStripMenuItem.Name = "exportFürBüroErstellenToolStripMenuItem"; - this.exportFürBüroErstellenToolStripMenuItem.Size = new System.Drawing.Size(254, 26); - this.exportFürBüroErstellenToolStripMenuItem.Text = "Export für Büro erstellen"; - this.exportFürBüroErstellenToolStripMenuItem.Click += new System.EventHandler(this.exportFürBüroErstellenToolStripMenuItem_Click); + this.configuration.Name = "configuration"; + this.configuration.Size = new System.Drawing.Size(118, 25); + this.configuration.Text = "Configuration"; + this.configuration.Click += new System.EventHandler(this.configuration_Click); // // frmMain // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(813, 453); + this.ClientSize = new System.Drawing.Size(921, 453); this.Controls.Add(this.statusStrip1); this.Controls.Add(this.mainmenu); this.IsMdiContainer = true; @@ -267,6 +276,7 @@ private UpdateLib.Updater update; private System.Windows.Forms.ToolStripStatusLabel toolstrip_messages; private System.Windows.Forms.ToolStripMenuItem exportFürBüroErstellenToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem configuration; } } diff --git a/SanSystem/frmMain.cs b/SanSystem/frmMain.cs index 73e0369..450209c 100644 --- a/SanSystem/frmMain.cs +++ b/SanSystem/frmMain.cs @@ -154,6 +154,8 @@ namespace SanSystem private void FrmProjektList_FormClosed(object sender, FormClosedEventArgs e) { + showauftraggeberform(); + toolStripStatus_projekt_Label.Text = Global.Instance.ProjektNummer; Form[] openedWindows = this.MdiChildren; foreach(Form form in openedWindows) @@ -225,7 +227,18 @@ namespace SanSystem private void auftraggeberToolStripMenuItem_Click(object sender, EventArgs e) { - if(Datenbank.Instance.loadedProjekt.Auftraggeber == null) + showauftraggeberform(); + } + + private void showauftraggeberform() + { + if (Datenbank.Instance.loadedProjekt == null) + { + MessageBox.Show("Es wurde kein Projekt geladen"); + return; + } + + if (Datenbank.Instance.loadedProjekt.Auftraggeber == null) { Auftraggeber auftraggeber = new Auftraggeber(); Datenbank.Instance.TeufelDB.Auftraggeber.Add(auftraggeber); @@ -377,5 +390,11 @@ namespace SanSystem await export.ContinueWith(task => MessageBox.Show("Büro export abgeschlossen")); } + + private void configuration_Click(object sender, EventArgs e) + { + frmSettings frmSettings = new frmSettings(); + frmSettings.ShowDialog(); + } } } diff --git a/SanSystem/frmSettings.Designer.cs b/SanSystem/frmSettings.Designer.cs new file mode 100644 index 0000000..031a165 --- /dev/null +++ b/SanSystem/frmSettings.Designer.cs @@ -0,0 +1,85 @@ +namespace SanSystem +{ + partial class frmSettings + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.txt_anlageIP = new System.Windows.Forms.TextBox(); + this.btn_save = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(197, 20); + this.label1.TabIndex = 0; + this.label1.Text = "IP Adresse von der Anlage"; + // + // txt_anlageIP + // + this.txt_anlageIP.Location = new System.Drawing.Point(233, 6); + this.txt_anlageIP.Name = "txt_anlageIP"; + this.txt_anlageIP.Size = new System.Drawing.Size(253, 26); + this.txt_anlageIP.TabIndex = 1; + // + // btn_save + // + this.btn_save.Location = new System.Drawing.Point(12, 125); + this.btn_save.Name = "btn_save"; + this.btn_save.Size = new System.Drawing.Size(377, 146); + this.btn_save.TabIndex = 2; + this.btn_save.Text = "Speichern"; + this.btn_save.UseVisualStyleBackColor = true; + this.btn_save.Click += new System.EventHandler(this.btn_save_Click); + // + // frmSettings + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1200, 692); + this.Controls.Add(this.btn_save); + this.Controls.Add(this.txt_anlageIP); + this.Controls.Add(this.label1); + this.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.Name = "frmSettings"; + this.Text = "Einstellungen"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox txt_anlageIP; + private System.Windows.Forms.Button btn_save; + } +} \ No newline at end of file diff --git a/SanSystem/frmSettings.cs b/SanSystem/frmSettings.cs new file mode 100644 index 0000000..1d40ce8 --- /dev/null +++ b/SanSystem/frmSettings.cs @@ -0,0 +1,43 @@ +using SanSystem.Einstellungen; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SanSystem +{ + public partial class frmSettings : Form + { + SoftwareConfiguration softwareConfiguration = null; + public frmSettings() + { + InitializeComponent(); + softwareConfiguration = new SoftwareConfiguration(); + + txt_anlageIP.Text = softwareConfiguration.GetAnlageIP(); + } + + void makeBindings() + { + + } + + void speichern() + { + softwareConfiguration.SetAnlageIP(txt_anlageIP.Text); + + } + + private void btn_save_Click(object sender, EventArgs e) + { + speichern(); + softwareConfiguration.SaveSettings(); + this.Close(); + } + } +} diff --git a/SanSystem/frmSettings.resx b/SanSystem/frmSettings.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SanSystem/frmSettings.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file