From 5cd5632ca7370b1c30c5e98a1108df89e444d3f9 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Mon, 19 Dec 2022 09:43:15 +0100 Subject: [PATCH] weiteres Arbeiten an der Speicherung der Alarm Strukturen --- AIS/AISAdmin/AISAdmin.csproj | 5 ++ AIS/AISAdmin/Main.Designer.cs | 38 +++++++------- AIS/AISAdmin/Main.cs | 55 +++++++++++++++++++- AIS/bsmd.AIS2Service/AIS_SQLiteStorage.cs | 6 +-- AIS/bsmd.AIS2Service/MonitorZone.cs | 24 ++++----- AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj | 10 ++-- AIS/bsmd.AIS2Service/packages.config | 6 +-- 7 files changed, 101 insertions(+), 43 deletions(-) diff --git a/AIS/AISAdmin/AISAdmin.csproj b/AIS/AISAdmin/AISAdmin.csproj index a8ecd403..1dd8d2dd 100644 --- a/AIS/AISAdmin/AISAdmin.csproj +++ b/AIS/AISAdmin/AISAdmin.csproj @@ -16,6 +16,11 @@ + + + + + diff --git a/AIS/AISAdmin/Main.Designer.cs b/AIS/AISAdmin/Main.Designer.cs index 2597507c..fb5bc81d 100644 --- a/AIS/AISAdmin/Main.Designer.cs +++ b/AIS/AISAdmin/Main.Designer.cs @@ -37,7 +37,7 @@ this.groupBoxZones = new System.Windows.Forms.GroupBox(); this.checkBoxZoneActive = new System.Windows.Forms.CheckBox(); this.buttonSaveZone = new System.Windows.Forms.Button(); - this.textBox2 = new System.Windows.Forms.TextBox(); + this.textBoxZone = new System.Windows.Forms.TextBox(); this.buttonDeleteZone = new System.Windows.Forms.Button(); this.buttonEditZone = new System.Windows.Forms.Button(); this.buttonImportZone = new System.Windows.Forms.Button(); @@ -45,7 +45,7 @@ this.buttonZoneUp = new System.Windows.Forms.Button(); this.listBoxZones = new System.Windows.Forms.ListBox(); this.groupBoxAssignments = new System.Windows.Forms.GroupBox(); - this.textBox1 = new System.Windows.Forms.TextBox(); + this.textBoxGroup = new System.Windows.Forms.TextBox(); this.buttonSaveGroup = new System.Windows.Forms.Button(); this.groupBoxZones.SuspendLayout(); this.SuspendLayout(); @@ -67,6 +67,7 @@ this.comboBoxGroup.Name = "comboBoxGroup"; this.comboBoxGroup.Size = new System.Drawing.Size(137, 23); this.comboBoxGroup.TabIndex = 1; + this.comboBoxGroup.SelectedIndexChanged += new System.EventHandler(this.comboBoxGroup_SelectedIndexChanged); // // buttonNewGroup // @@ -104,7 +105,7 @@ // this.groupBoxZones.Controls.Add(this.checkBoxZoneActive); this.groupBoxZones.Controls.Add(this.buttonSaveZone); - this.groupBoxZones.Controls.Add(this.textBox2); + this.groupBoxZones.Controls.Add(this.textBoxZone); this.groupBoxZones.Controls.Add(this.buttonDeleteZone); this.groupBoxZones.Controls.Add(this.buttonEditZone); this.groupBoxZones.Controls.Add(this.buttonImportZone); @@ -139,13 +140,13 @@ this.buttonSaveZone.UseVisualStyleBackColor = true; this.buttonSaveZone.Click += new System.EventHandler(this.buttonSaveZone_Click); // - // textBox2 + // textBoxZone // - this.textBox2.Location = new System.Drawing.Point(525, 27); - this.textBox2.Name = "textBox2"; - this.textBox2.ReadOnly = true; - this.textBox2.Size = new System.Drawing.Size(202, 23); - this.textBox2.TabIndex = 9; + this.textBoxZone.Location = new System.Drawing.Point(525, 27); + this.textBoxZone.Name = "textBoxZone"; + this.textBoxZone.ReadOnly = true; + this.textBoxZone.Size = new System.Drawing.Size(202, 23); + this.textBoxZone.TabIndex = 9; // // buttonDeleteZone // @@ -220,13 +221,13 @@ this.groupBoxAssignments.TabStop = false; this.groupBoxAssignments.Text = "Assignments"; // - // textBox1 + // textBoxGroup // - this.textBox1.Location = new System.Drawing.Point(335, 11); - this.textBox1.Name = "textBox1"; - this.textBox1.ReadOnly = true; - this.textBox1.Size = new System.Drawing.Size(160, 23); - this.textBox1.TabIndex = 7; + this.textBoxGroup.Location = new System.Drawing.Point(335, 11); + this.textBoxGroup.Name = "textBoxGroup"; + this.textBoxGroup.ReadOnly = true; + this.textBoxGroup.Size = new System.Drawing.Size(160, 23); + this.textBoxGroup.TabIndex = 7; // // buttonSaveGroup // @@ -245,7 +246,7 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); this.Controls.Add(this.buttonSaveGroup); - this.Controls.Add(this.textBox1); + this.Controls.Add(this.textBoxGroup); this.Controls.Add(this.groupBoxAssignments); this.Controls.Add(this.groupBoxZones); this.Controls.Add(this.buttonDeleteGroup); @@ -257,6 +258,7 @@ this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "Main"; this.Text = "AIS Admin"; + this.Load += new System.EventHandler(this.Main_Load); this.groupBoxZones.ResumeLayout(false); this.groupBoxZones.PerformLayout(); this.ResumeLayout(false); @@ -276,10 +278,10 @@ private ListBox listBoxZones; private Button buttonZoneDown; private Button buttonZoneUp; - private TextBox textBox1; + private TextBox textBoxGroup; private Button buttonSaveGroup; private Button buttonSaveZone; - private TextBox textBox2; + private TextBox textBoxZone; private Button buttonDeleteZone; private Button buttonEditZone; private Button buttonImportZone; diff --git a/AIS/AISAdmin/Main.cs b/AIS/AISAdmin/Main.cs index 51c0faa7..f27a5565 100644 --- a/AIS/AISAdmin/Main.cs +++ b/AIS/AISAdmin/Main.cs @@ -1,7 +1,14 @@ +using bsmd.AIS2Service; + namespace AISAdmin { + public partial class Main : Form { + private AIS_SQLiteStorage? _storage; + private List? _monitorGroups; + private List? _monitorZones; + public Main() { InitializeComponent(); @@ -39,7 +46,8 @@ namespace AISAdmin private void buttonNewGroup_Click(object sender, EventArgs e) { - + this.textBoxGroup.ReadOnly = false; + this.buttonSaveGroup.Enabled = true; } private void buttonEditGroup_Click(object sender, EventArgs e) @@ -54,7 +62,52 @@ namespace AISAdmin private void buttonSaveGroup_Click(object sender, EventArgs e) { + if(this.textBoxGroup.Text != null) + { + string groupName = this.textBoxGroup.Text.Trim(); + if(groupName.Length > 0) + { + MonitorGroup mg = new MonitorGroup(-1, groupName); + if(_storage.Save(mg)) + { + this._monitorGroups?.Add(mg); + this.comboBoxGroup.SelectedItem = mg; + } + } + } + this.buttonSaveGroup.Enabled = false; + this.textBoxGroup.ReadOnly = true; + } + private void Main_Load(object sender, EventArgs e) + { + _storage = new AIS_SQLiteStorage(null); + _monitorGroups = _storage.LoadGroups(); + _monitorZones = _storage.LoadMonitorZones(); + this.comboBoxGroup.DataSource = _monitorGroups; + this.comboBoxGroup.DisplayMember = "Name"; + } + + private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e) + { + MonitorGroup mGroup = (MonitorGroup) this.comboBoxGroup.SelectedItem; + if (mGroup != null) + { + this.textBoxGroup.Text = mGroup.Name; + List groupZones = new List(); + foreach(MonitorZone mZone in _monitorZones) + { + if (mZone.MonitorGroupId == mGroup.Id) + groupZones.Add(mZone); + } + groupZones.Sort(); + this.listBoxZones.DataSource = groupZones; + } + else + { + this.listBoxZones.DataSource = null; + this.textBoxGroup.ResetText(); + } } } } \ No newline at end of file diff --git a/AIS/bsmd.AIS2Service/AIS_SQLiteStorage.cs b/AIS/bsmd.AIS2Service/AIS_SQLiteStorage.cs index df5a93a6..831bb217 100644 --- a/AIS/bsmd.AIS2Service/AIS_SQLiteStorage.cs +++ b/AIS/bsmd.AIS2Service/AIS_SQLiteStorage.cs @@ -16,7 +16,7 @@ namespace bsmd.AIS2Service /// past track. It is just intended to function as a "saving the state" of the AIS situation. /// Attention: Alarm zones / alarms are also stored here. This might or might not be such a great idea. /// - internal class AIS_SQLiteStorage : IAISThread + public class AIS_SQLiteStorage : IAISThread { #region Fields @@ -504,11 +504,11 @@ namespace bsmd.AIS2Service } } - public int GetLastInsertId() + public long GetLastInsertId() { string sql = "SELECT last_insert_rowid()"; SQLiteCommand cmd = new SQLiteCommand(sql, _connection); - int lastID = (Int32)cmd.ExecuteScalar(); + long lastID = (long) cmd.ExecuteScalar(); return lastID; } diff --git a/AIS/bsmd.AIS2Service/MonitorZone.cs b/AIS/bsmd.AIS2Service/MonitorZone.cs index b28437e2..b94a25bb 100644 --- a/AIS/bsmd.AIS2Service/MonitorZone.cs +++ b/AIS/bsmd.AIS2Service/MonitorZone.cs @@ -17,14 +17,14 @@ namespace bsmd.AIS2Service public class DBEntity { - protected int _id; // PK from database + protected long _id; // PK from database - public DBEntity(int id) + public DBEntity(long id) { _id = id; } - public int Id { get { return _id; } set { _id = value; } } + public long Id { get { return _id; } set { _id = value; } } } @@ -43,7 +43,7 @@ namespace bsmd.AIS2Service #region Construction - public MonitorGroup(int id, string name) : base( id ) + public MonitorGroup(long id, string name) : base( id ) { _name = name; } @@ -76,7 +76,7 @@ namespace bsmd.AIS2Service #region Construction - public MonitorZone(int id, string name) : base (id) + public MonitorZone(long id, string name) : base (id) { _name = name; } @@ -95,7 +95,7 @@ namespace bsmd.AIS2Service public int Sequence { get; set; } - public int MonitorGroupId { get; set; } + public long MonitorGroupId { get; set; } #endregion @@ -130,13 +130,13 @@ namespace bsmd.AIS2Service public class GeoPoint : DBEntity { - public GeoPoint(int id) : base (id) + public GeoPoint(long id) : base (id) {} public double Lat { get; set; } public double Lon { get; set; } - public int MonitorZoneId { get; set; } + public long MonitorZoneId { get; set; } } #endregion @@ -146,7 +146,7 @@ namespace bsmd.AIS2Service public class MonitorAssignment : DBEntity { - public MonitorAssignment(int id) : base(id) + public MonitorAssignment(long id) : base(id) {} [Flags] @@ -157,9 +157,7 @@ namespace bsmd.AIS2Service EXIT = 2, PASSTHROUGH = 4, // outside - enter - inside - exit - outside LEAVE_AND_RETURN = 8 // inside - exit - outside - enter - inside - } - - public int Id { get { return _id; } } + } public int MMSI { get; set; } @@ -175,7 +173,7 @@ namespace bsmd.AIS2Service { private readonly MonitorAssignment _assignment; - public Alarm(int id, MonitorAssignment assignment) : base(id) { _assignment = assignment; } + public Alarm(long id, MonitorAssignment assignment) : base(id) { _assignment = assignment; } public MonitorAssignment Assignment { get { return _assignment; } } diff --git a/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj b/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj index 8506f25b..8904470b 100644 --- a/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj +++ b/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj @@ -48,7 +48,7 @@ packages\Microsoft.Owin.Hosting.4.2.2\lib\net45\Microsoft.Owin.Hosting.dll - packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll + packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll packages\Owin.1.0\lib\net40\Owin.dll @@ -57,8 +57,8 @@ - - packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.116.0\lib\net46\System.Data.SQLite.dll + + packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.117.0\lib\net46\System.Data.SQLite.dll @@ -156,11 +156,11 @@ - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + \ No newline at end of file diff --git a/AIS/bsmd.AIS2Service/packages.config b/AIS/bsmd.AIS2Service/packages.config index c1bc6dff..df65db26 100644 --- a/AIS/bsmd.AIS2Service/packages.config +++ b/AIS/bsmd.AIS2Service/packages.config @@ -10,8 +10,8 @@ - + - - + + \ No newline at end of file