Speichern von Assignments, auch Zuordnung aus der Target Liste jetzt möglich!

This commit is contained in:
Daniel Schick 2022-12-30 10:12:03 +01:00
parent e0ef9d582a
commit 4c6dd5f287
7 changed files with 98 additions and 11 deletions

View File

@ -49,6 +49,11 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
@ -58,4 +63,11 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project>

15
AIS/AISAdmin/App.config Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="AISAdmin.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<AISAdmin.Properties.Settings>
<setting name="SQLiteDBConnectionString" serializeAs="String">
<value>Data Source=E:\temp\ais.db;Version=3;</value>
</setting>
</AISAdmin.Properties.Settings>
</applicationSettings>
</configuration>

View File

@ -232,12 +232,12 @@
this.listBoxTargets.ItemHeight = 15;
this.listBoxTargets.Location = new System.Drawing.Point(401, 37);
this.listBoxTargets.Name = "listBoxTargets";
this.listBoxTargets.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
this.listBoxTargets.Size = new System.Drawing.Size(369, 154);
this.listBoxTargets.TabIndex = 7;
//
// buttonAssignSelectedTarget
//
this.buttonAssignSelectedTarget.Enabled = false;
this.buttonAssignSelectedTarget.Image = global::AISAdmin.Properties.Resources.arrow_left_green;
this.buttonAssignSelectedTarget.Location = new System.Drawing.Point(358, 111);
this.buttonAssignSelectedTarget.Name = "buttonAssignSelectedTarget";
@ -248,7 +248,6 @@
//
// buttonDeleteAssignment
//
this.buttonDeleteAssignment.Enabled = false;
this.buttonDeleteAssignment.Image = global::AISAdmin.Properties.Resources.delete;
this.buttonDeleteAssignment.Location = new System.Drawing.Point(358, 74);
this.buttonDeleteAssignment.Name = "buttonDeleteAssignment";
@ -271,7 +270,6 @@
//
this.listBoxAssignment.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.listBoxAssignment.Enabled = false;
this.listBoxAssignment.FormattingEnabled = true;
this.listBoxAssignment.ItemHeight = 15;
this.listBoxAssignment.Location = new System.Drawing.Point(6, 37);

View File

@ -112,7 +112,7 @@ namespace AISAdmin
private async void Main_Load(object sender, EventArgs e)
{
_storage = new AIS_SQLiteStorage(null);
_storage = new AIS_SQLiteStorage(Properties.Settings.Default.SQLiteDBConnectionString);
_monitorGroups = new BindingList<MonitorGroup>(_storage.LoadGroups());
List<MonitorZone> zones = _storage.LoadMonitorZones();
foreach(MonitorGroup mg in _monitorGroups)
@ -135,6 +135,8 @@ namespace AISAdmin
this._allTargets.Add(allTargets[mmsi]);
this._allTargets.Sort();
this.listBoxTargets.DataSource = this._allTargets;
if (this._allTargets.Count > 0)
this.listBoxTargets.Enabled = true;
}
private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e)
@ -226,8 +228,7 @@ namespace AISAdmin
private void buttonAssignSelectedTarget_Click(object sender, EventArgs e)
{
AIS_Target? target = (AIS_Target)this.listBoxTargets.SelectedItem;
if(target != null)
foreach (AIS_Target target in this.listBoxTargets.SelectedItems)
{
this.AddOrUpdateAssignmentForAllGroupZones(target.MMSI, MonitorAssignment.ZoneMonitorType.ENTER);
}

View File

@ -0,0 +1,35 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace AISAdmin.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.4.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("Data Source=E:\\temp\\ais.db;Version=3;")]
public string SQLiteDBConnectionString {
get {
return ((string)(this["SQLiteDBConnectionString"]));
}
}
}
}

View File

@ -0,0 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="AISAdmin.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="SQLiteDBConnectionString" Type="System.String" Scope="Application">
<Value Profile="(Default)">Data Source=E:\temp\ais.db;Version=3;</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -38,6 +38,12 @@ namespace bsmd.AIS2Service
_connection.Open();
}
public AIS_SQLiteStorage(string connectionString)
{
_connection = new SQLiteConnection(connectionString);
_connection.Open();
}
#endregion
#region public methods
@ -323,11 +329,22 @@ namespace bsmd.AIS2Service
public bool Save(MonitorAssignment assignment)
{
if (assignment == null) return false;
string saveGeoPointString = $"INSERT INTO zone_assignment (mmsi, monitor_zone_id, type) VALUES ({assignment.MMSI}, {assignment.MonitorZoneId}, {(int) assignment.MonitorType})";
SQLiteCommand cmd = new SQLiteCommand(saveGeoPointString, _connection);
int insertedRows = cmd.ExecuteNonQuery();
cmd.Dispose();
return insertedRows == 1;
if (assignment.Id <= 0) // insert
{
string saveAssignmentString = $"INSERT INTO zone_assignment (mmsi, monitor_zone_id, type) VALUES ({assignment.MMSI}, {assignment.MonitorZoneId}, {(int)assignment.MonitorType})";
SQLiteCommand cmd = new SQLiteCommand(saveAssignmentString, _connection);
int insertedRows = cmd.ExecuteNonQuery();
cmd.Dispose();
return insertedRows == 1;
}
else // update
{
string saveAssignmentString = $"UPDATE zone_assignment SET type = {(int) assignment.MonitorType} WHERE id = {assignment.Id}";
SQLiteCommand cmd = new SQLiteCommand(saveAssignmentString, _connection);
int updatedRows = cmd.ExecuteNonQuery();
cmd.Dispose();
return updatedRows == 1;
}
}
public List<MonitorAssignment> LoadAssignmentsForZone(long zoneId)