196 lines
6.2 KiB
C#
196 lines
6.2 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Tidstagning
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
delegate void SetTextCallback(string text);
|
|
BindingList<Entry> entries = new BindingList<Entry> {
|
|
|
|
};
|
|
ResultList liste;
|
|
Relay horn;
|
|
Procedure startprocedure = new Procedure();
|
|
|
|
int OldRow = 0;
|
|
public Form1()
|
|
{
|
|
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();
|
|
|
|
comboSoundTime.SelectedIndex = 0;
|
|
|
|
foreach (string port in Relay.GetPorts()) {
|
|
comboComport.Items.Add(port);
|
|
}
|
|
|
|
checkStartProcedure.Checked = Properties.Settings.Default.AutoStartProcedure;
|
|
|
|
string comport = Properties.Settings.Default.ComPort;
|
|
int index = comboComport.Items.IndexOf(comport);
|
|
if (index == -1)
|
|
{
|
|
comboComport.SelectedIndex = 0;
|
|
}
|
|
else
|
|
{
|
|
comboComport.SelectedIndex = index;
|
|
}
|
|
}
|
|
|
|
|
|
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();
|
|
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();
|
|
liste.WriteComplete(entries[e.RowIndex]);
|
|
|
|
grid.ClearSelection();
|
|
grid.CurrentCell = null;
|
|
entries.RemoveAt(e.RowIndex);
|
|
|
|
horn.Sound(int.Parse(comboSoundTime.SelectedItem.ToString()));
|
|
}
|
|
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;
|
|
comboComport.Enabled = false;
|
|
comboSoundTime.Enabled = false;
|
|
if (checkStartProcedure.Checked)
|
|
{
|
|
liste.Write("Automatisk Start Procedure er aktiv.");
|
|
startprocedure.setObjects(horn, liste);
|
|
}
|
|
else
|
|
{
|
|
liste.Write("Manuel start procedure");
|
|
}
|
|
|
|
}
|
|
|
|
private void btnStop_Click(object sender, EventArgs e)
|
|
{
|
|
btnStop.Enabled = false;
|
|
btnStart.Enabled = true;
|
|
liste.WriteFooter();
|
|
liste.Close();
|
|
checkStartProcedure.Enabled = true;
|
|
comboComport.Enabled = true;
|
|
comboSoundTime.Enabled = true;
|
|
startprocedure.Clear();
|
|
}
|
|
|
|
private void grid_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
DataGridView.HitTestInfo hti = grid.HitTest(e.X, e.Y);
|
|
if (hti.RowIndex >= 0 && hti.RowIndex != OldRow)
|
|
{
|
|
if (grid.Rows.Count > OldRow)
|
|
{
|
|
grid.Rows[OldRow].Selected = false;
|
|
grid.Rows[OldRow].Height = 30;
|
|
}
|
|
grid.Rows[hti.RowIndex].Selected = true;
|
|
grid.Rows[hti.RowIndex].Height = 60;
|
|
OldRow = hti.RowIndex;
|
|
}
|
|
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
AboutBox aboutbox = new AboutBox();
|
|
aboutbox.Show();
|
|
}
|
|
|
|
private void btnTest_Click(object sender, EventArgs e)
|
|
{
|
|
horn.Sound(int.Parse(comboSoundTime.SelectedItem.ToString()));
|
|
}
|
|
|
|
private void Clock_Tick(object sender, EventArgs e)
|
|
{
|
|
lblClock.Text = DateTime.Now.ToString("HH:mm:ss");
|
|
textStartProcedure.Text = startprocedure.TextualRepresentation();
|
|
}
|
|
|
|
private void comboSoundTime_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
startprocedure.adjustSignalLength(int.Parse(comboSoundTime.SelectedItem.ToString()));
|
|
}
|
|
|
|
private void comboComport_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (comboComport.Items.Count != 0)
|
|
{
|
|
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();
|
|
if (checkStartProcedure.Checked)
|
|
{
|
|
startprocedure.ReadFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/Tidstagning/" + "Startprocedure.txt");
|
|
}
|
|
|
|
Properties.Settings.Default.AutoStartProcedure = checkStartProcedure.Checked;
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
}
|
|
}
|