234 lines
7.3 KiB
C#
234 lines
7.3 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Tidstagning
|
|
{
|
|
public partial class MainUI : Form
|
|
{
|
|
delegate void SetTextCallback(string text);
|
|
BindingList<Entry> entries = new BindingList<Entry>
|
|
{
|
|
|
|
};
|
|
ResultList? liste;
|
|
Relay? horn;
|
|
Procedure startprocedure = new Procedure();
|
|
|
|
public MainUI(bool ShowConfig = false)
|
|
{
|
|
InitializeComponent();
|
|
System.IO.StreamReader deltager_handle = new System.IO.StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/Tidstagning/" + "Deltager.txt");
|
|
string? deltager;
|
|
while ((deltager = deltager_handle.ReadLine()) != null)
|
|
{
|
|
string[] dele = deltager.Split(',');
|
|
entries.Add(new Entry(dele[0], dele[1]));
|
|
}
|
|
deltager_handle.Dispose();
|
|
|
|
foreach (string port in Relay.GetPorts())
|
|
{
|
|
comboComport.Items.Add(port);
|
|
}
|
|
|
|
checkStartProcedure.Checked = Properties.Settings.Default.AutoStartProcedure;
|
|
numericSignalLength.Value = (decimal)Properties.Settings.Default.SignalLength;
|
|
|
|
string comport = Properties.Settings.Default.ComPort;
|
|
int index = comboComport.Items.IndexOf(comport);
|
|
if (index == -1)
|
|
{
|
|
comboComport.SelectedIndex = 0;
|
|
}
|
|
else
|
|
{
|
|
comboComport.SelectedIndex = index;
|
|
}
|
|
|
|
buttonConfig.Visible = ShowConfig;
|
|
|
|
}
|
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
grid.DataSource = entries;
|
|
}
|
|
|
|
public void LogAppend(string text)
|
|
{
|
|
if (this.txtDebug.InvokeRequired)
|
|
{
|
|
SetTextCallback d = new SetTextCallback(LogAppend);
|
|
this.Invoke(d, new object[] { text });
|
|
}
|
|
else
|
|
{
|
|
this.txtDebug.AppendText(text);
|
|
}
|
|
}
|
|
|
|
private void grid_Click(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (!btnStop.Enabled)
|
|
return;
|
|
|
|
if (e.RowIndex >= 0 && e.ColumnIndex == grid.Columns["DNF"].Index)
|
|
{
|
|
entries[e.RowIndex].DNF();
|
|
if(liste is not null)
|
|
liste.WriteDNF(entries[e.RowIndex]);
|
|
|
|
grid.ClearSelection();
|
|
grid.CurrentCell = null;
|
|
entries.RemoveAt(e.RowIndex);
|
|
}
|
|
if (e.RowIndex >= 0 && e.ColumnIndex == grid.Columns["Complete"].Index)
|
|
{
|
|
entries[e.RowIndex].Complete();
|
|
if(liste is not null)
|
|
liste.WriteComplete(entries[e.RowIndex]);
|
|
|
|
grid.ClearSelection();
|
|
grid.CurrentCell = null;
|
|
entries.RemoveAt(e.RowIndex);
|
|
|
|
if(horn is not null)
|
|
horn.Sound((uint)numericSignalLength.Value);
|
|
}
|
|
grid.Refresh();
|
|
}
|
|
|
|
private void btnStart_Click(object sender, EventArgs e)
|
|
{
|
|
if (txtHeader.Text == "")
|
|
{
|
|
MessageBox.Show("Udfyld løbs titel");
|
|
return;
|
|
}
|
|
liste = new ResultList(txtHeader.Text, this);
|
|
liste.WriteHeader(txtHeader.Text);
|
|
btnStart.Enabled = false;
|
|
btnStop.Enabled = true;
|
|
checkStartProcedure.Enabled = false;
|
|
flowLayoutPanelConfiguration.Enabled = false;
|
|
if (checkStartProcedure.Checked)
|
|
{
|
|
liste.Write("Automatisk Start Procedure er aktiv.");
|
|
if(horn is not null)
|
|
startprocedure.setObjects(horn, liste);
|
|
}
|
|
else
|
|
{
|
|
liste.Write("Manuel start procedure");
|
|
}
|
|
|
|
}
|
|
|
|
private void btnStop_Click(object sender, EventArgs e)
|
|
{
|
|
btnStop.Enabled = false;
|
|
btnStart.Enabled = true;
|
|
if (liste is not null)
|
|
{
|
|
liste.WriteFooter();
|
|
liste.Close();
|
|
}
|
|
checkStartProcedure.Enabled = true;
|
|
flowLayoutPanelConfiguration.Enabled = true;
|
|
}
|
|
|
|
private void buttonHelp_Click(object sender, EventArgs e)
|
|
{
|
|
AboutBox aboutbox = new AboutBox();
|
|
aboutbox.Show();
|
|
}
|
|
|
|
private void btnTest_Click(object sender, EventArgs e)
|
|
{
|
|
if(horn is not null)
|
|
horn.Sound((uint)numericSignalLength.Value);
|
|
}
|
|
|
|
private void Clock_Tick(object sender, EventArgs e)
|
|
{
|
|
lblClock.Text = DateTime.Now.ToString("HH:mm:ss");
|
|
if (checkStartProcedure.Checked)
|
|
{
|
|
textStartProcedure.Text = startprocedure.TextualRepresentation();
|
|
}
|
|
}
|
|
|
|
private void comboComport_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (comboComport is not null && comboComport.Items.Count != 0 && comboComport.SelectedItem is not null)
|
|
{
|
|
horn = new Relay(comboComport.SelectedItem.ToString());
|
|
Properties.Settings.Default.ComPort = comboComport.SelectedItem.ToString();
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
}
|
|
|
|
private void checkStartProcedure_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
startprocedure.Clear();
|
|
textStartProcedure.Visible = checkStartProcedure.Checked;
|
|
if (checkStartProcedure.Checked)
|
|
{
|
|
startprocedure.ReadFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/Tidstagning/" + "Startprocedure.txt");
|
|
}
|
|
|
|
Properties.Settings.Default.AutoStartProcedure = checkStartProcedure.Checked;
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
|
|
private void grid_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (e.RowIndex > -1)
|
|
{
|
|
try
|
|
{
|
|
grid.Rows[e.RowIndex].Selected = true;
|
|
grid.Rows[e.RowIndex].Height = 60;
|
|
grid.CurrentCell = grid.Rows[e.RowIndex].Cells[e.ColumnIndex];
|
|
if (btnStop.Enabled)
|
|
{
|
|
grid.Focus();
|
|
}
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
|
|
private void grid_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (e.RowIndex > -1)
|
|
{
|
|
try
|
|
{
|
|
grid.Rows[e.RowIndex].Selected = false;
|
|
grid.Rows[e.RowIndex].Height = 30;
|
|
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
|
|
}
|
|
|
|
private void buttonConfig_Click(object sender, EventArgs e)
|
|
{
|
|
ConfigUI configui = new ConfigUI();
|
|
configui.ShowDialog();
|
|
}
|
|
|
|
private void numericSignalLength_ValueChanged(object sender, EventArgs e)
|
|
{
|
|
startprocedure.adjustSignalLength((uint)numericSignalLength.Value);
|
|
Properties.Settings.Default.SignalLength = (uint)numericSignalLength.Value;
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
}
|
|
}
|