using bsmd.AIS2Service; using System.ComponentModel; namespace AISAdmin { public partial class Main : Form { private AIS_SQLiteStorage? _storage; private BindingList? _monitorGroups = new BindingList(); private BindingList? _monitorZones; private MonitorGroup? _currentGroup; public Main() { InitializeComponent(); _currentGroup = null; } private void buttonZoneUp_Click(object sender, EventArgs e) { } private void buttonZoneDown_Click(object sender, EventArgs e) { } private void buttonImportZone_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Filter = "Google Earth KML files (*.kml)|*.kml|All files (*.*)|*.*"; ofd.RestoreDirectory = true; ofd.Multiselect = true; if (ofd.ShowDialog() == DialogResult.OK) { for (int i = 0, seq = this._monitorGroups.Count; i < ofd.FileNames.Length; i++, seq++) { MonitorZone mz = MonitorZone.ImportFromKML(ofd.FileNames[i]); if(mz != null) { mz.MonitorGroupId = this._currentGroup.Id; mz.Sequence = seq; _storage.Save(mz); foreach(GeoPoint gp in mz.Vertices) { gp.MonitorZoneId = mz.Id; _storage.Save(gp); } } } } } } private void buttonEditZone_Click(object sender, EventArgs e) { } private void buttonDeleteZone_Click(object sender, EventArgs e) { } private void buttonSaveZone_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) { if(this.textBoxGroup.Text != null) { string groupName = this.textBoxGroup.Text.Trim(); if(groupName.Length > 0) { _currentGroup.Name = groupName; if(_storage.Save(_currentGroup)) { if ((bool)!(_monitorGroups?.Contains(_currentGroup))) this._monitorGroups.Add(_currentGroup); this.comboBoxGroup.SelectedItem = _currentGroup; } } } } private void Main_Load(object sender, EventArgs e) { _storage = new AIS_SQLiteStorage(null); _monitorGroups = new BindingList(_storage.LoadGroups()); _monitorZones = new BindingList(_storage.LoadMonitorZones()); this.comboBoxGroup.DataSource = _monitorGroups; this.comboBoxGroup.DisplayMember = "Name"; if (_monitorGroups.Count > 0) this.comboBoxGroup.SelectedIndex = 0; } private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e) { _currentGroup = (MonitorGroup) this.comboBoxGroup.SelectedItem; if (_currentGroup != null) { this.textBoxGroup.Text = _currentGroup.Name; List groupZones = new List(); foreach(MonitorZone mZone in _monitorZones) { if (mZone.MonitorGroupId == _currentGroup.Id) groupZones.Add(mZone); } groupZones.Sort(); this.listBoxZones.DataSource = groupZones; } else { this.listBoxZones.DataSource = null; this.textBoxGroup.ResetText(); this.buttonSaveGroup.Enabled = false; this.textBoxGroup.ReadOnly = true; } } } }