170 lines
6.0 KiB
C#
170 lines
6.0 KiB
C#
using bsmd.AIS2Service;
|
|
using System.ComponentModel;
|
|
|
|
namespace AISAdmin
|
|
{
|
|
|
|
public partial class Main : Form
|
|
{
|
|
private AIS_SQLiteStorage? _storage;
|
|
private BindingList<MonitorGroup>? _monitorGroups = new();
|
|
private MonitorGroup? _currentGroup;
|
|
|
|
public Main()
|
|
{
|
|
InitializeComponent();
|
|
_currentGroup = null;
|
|
}
|
|
|
|
private void buttonZoneUp_Click(object sender, EventArgs e)
|
|
{
|
|
MonitorZone mz = (MonitorZone)this.listBoxZones.SelectedItem;
|
|
int i = this.listBoxZones.SelectedIndex;
|
|
BindingList<MonitorZone> zones = (BindingList<MonitorZone>)this.listBoxZones.DataSource;
|
|
if (mz != null && (i > 0))
|
|
{
|
|
MonitorZone prevZone = zones[i - 1];
|
|
mz.Sequence -= 1;
|
|
prevZone.Sequence += 1;
|
|
zones[i - 1] = mz;
|
|
zones[i] = prevZone;
|
|
this.listBoxZones.SelectedIndex = i - 1;
|
|
}
|
|
}
|
|
|
|
private void buttonZoneDown_Click(object sender, EventArgs e)
|
|
{
|
|
MonitorZone mz = (MonitorZone)this.listBoxZones.SelectedItem;
|
|
int i = this.listBoxZones.SelectedIndex;
|
|
BindingList<MonitorZone> zones = (BindingList<MonitorZone>) this.listBoxZones.DataSource;
|
|
if (mz != null && (i < (zones.Count - 1)))
|
|
{
|
|
MonitorZone nextZone = zones[i + 1];
|
|
mz.Sequence += 1;
|
|
nextZone.Sequence -= 1;
|
|
zones[i + 1] = mz;
|
|
zones[i] = nextZone;
|
|
this.listBoxZones.SelectedIndex = i + 1;
|
|
}
|
|
}
|
|
|
|
private void buttonImportZone_Click(object sender, EventArgs e)
|
|
{
|
|
using OpenFileDialog ofd = new();
|
|
ofd.Filter = "Google Earth KML files (*.kml)|*.kml|All files (*.*)|*.*";
|
|
ofd.RestoreDirectory = true;
|
|
ofd.Multiselect = false;
|
|
if (ofd.ShowDialog() == DialogResult.OK)
|
|
{
|
|
_monitorGroups = new BindingList<MonitorGroup>(MonitorGroup.LoadGroups(ofd.FileName));
|
|
this.comboBoxGroup.DataSource = _monitorGroups;
|
|
if (_monitorGroups.Count > 0)
|
|
this.comboBoxGroup.SelectedIndex = 0;
|
|
this.buttonSaveGroup.Enabled = _monitorGroups.Count > 0;
|
|
this.listBoxZones.Enabled = _monitorGroups.Count > 0;
|
|
}
|
|
}
|
|
|
|
private void buttonEditZone_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void buttonDeleteZone_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void buttonNewGroup_Click(object sender, EventArgs e)
|
|
{
|
|
this.textBoxGroup.ReadOnly = false;
|
|
this.buttonSaveGroup.Enabled = true;
|
|
_currentGroup = new MonitorGroup(-1, "");
|
|
this.textBoxGroup.ResetText();
|
|
}
|
|
|
|
private void buttonDeleteGroup_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void buttonSaveGroup_Click(object sender, EventArgs e)
|
|
{
|
|
// save everything
|
|
foreach(MonitorGroup mg in this._monitorGroups)
|
|
{
|
|
this._storage?.Save(mg);
|
|
foreach(MonitorZone mz in mg.Zones)
|
|
{
|
|
if (mz.MonitorGroupId < 1) mz.MonitorGroupId = mg.Id;
|
|
this._storage?.Save(mz);
|
|
|
|
foreach(GeoPoint vertex in mz.Vertices)
|
|
{
|
|
if(vertex.MonitorZoneId < 1) vertex.MonitorZoneId = mz.Id;
|
|
this._storage?.Save(vertex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Main_Load(object sender, EventArgs e)
|
|
{
|
|
_storage = new AIS_SQLiteStorage(null);
|
|
_monitorGroups = new BindingList<MonitorGroup>(_storage.LoadGroups());
|
|
List<MonitorZone> zones = _storage.LoadMonitorZones();
|
|
foreach(MonitorGroup mg in _monitorGroups)
|
|
{
|
|
foreach(MonitorZone mz in zones)
|
|
{
|
|
if (mz.MonitorGroupId == mg.Id)
|
|
mg.Zones.Add(mz);
|
|
}
|
|
}
|
|
this.comboBoxGroup.DataSource = _monitorGroups;
|
|
this.comboBoxGroup.DisplayMember = "Name";
|
|
if (_monitorGroups.Count > 0)
|
|
this.comboBoxGroup.SelectedIndex = 0;
|
|
this.buttonSaveGroup.Enabled = _monitorGroups.Count > 0;
|
|
this.listBoxZones.Enabled = _monitorGroups.Count > 0;
|
|
}
|
|
|
|
private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
_currentGroup = (MonitorGroup) this.comboBoxGroup.SelectedItem;
|
|
if (_currentGroup != null)
|
|
{
|
|
_currentGroup.Zones.Sort();
|
|
this.listBoxZones.DataSource = new BindingList<MonitorZone>(_currentGroup.Zones);
|
|
}
|
|
else
|
|
{
|
|
this.listBoxZones.DataSource = null;
|
|
this.textBoxGroup.ResetText();
|
|
this.buttonSaveGroup.Enabled = false;
|
|
this.textBoxGroup.ReadOnly = true;
|
|
}
|
|
this.buttonZoneDown.Enabled = (this._currentGroup != null) && (this._currentGroup.Zones.Count > 1);
|
|
this.buttonZoneUp.Enabled = (this._currentGroup != null) && (this._currentGroup.Zones.Count > 1);
|
|
}
|
|
|
|
private void checkBoxZoneActive_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
MonitorZone mz = (MonitorZone)this.listBoxZones.SelectedItem;
|
|
if (mz != null)
|
|
{
|
|
mz.Active = this.checkBoxZoneActive.Checked;
|
|
}
|
|
}
|
|
|
|
private void listBoxZones_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
MonitorZone mz = (MonitorZone) this.listBoxZones.SelectedItem;
|
|
if(mz != null)
|
|
{
|
|
this.checkBoxZoneActive.Checked = mz.Active;
|
|
this.textBoxZone.Text = mz.Name;
|
|
}
|
|
}
|
|
}
|
|
} |