240 lines
7.0 KiB
C#
240 lines
7.0 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;
|
|
|
|
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();
|
|
|
|
startprocedure = new Procedure();
|
|
System.IO.StreamReader procedure_handle = new System.IO.StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/Tidstagning/" + "Startprocedure.txt");
|
|
string line;
|
|
while ((line = procedure_handle.ReadLine()) != null)
|
|
{
|
|
startprocedure.addEntry(line);
|
|
}
|
|
procedure_handle.Dispose();
|
|
|
|
|
|
foreach(string port in Relay.GetPorts()) {
|
|
comboComport.Items.Add(port);
|
|
}
|
|
|
|
comboSoundTime.SelectedIndex = 3;
|
|
if (comboComport.Items.Count != 0)
|
|
{
|
|
comboComport.SelectedIndex = 0;
|
|
}
|
|
}
|
|
|
|
|
|
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 (btnMoveUp.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.Set(0x00, 0x01);
|
|
countdowntimer.Interval = int.Parse(comboSoundTime.SelectedItem.ToString());
|
|
countdowntimer.Start();
|
|
|
|
}
|
|
grid.Refresh();
|
|
|
|
}
|
|
|
|
private void btnMoveUp_Click(object sender, EventArgs e)
|
|
{
|
|
if (grid.SelectedRows.Count == 1)
|
|
{
|
|
int idx = grid.SelectedRows[0].Index;
|
|
if (idx == 0)
|
|
return;
|
|
Entry entry = entries[idx];
|
|
entries.Remove(entry);
|
|
entries.Insert(idx - 1, entry);
|
|
grid.ClearSelection();
|
|
|
|
grid.Rows[idx - 1].Selected = true;
|
|
}
|
|
}
|
|
|
|
private void btnMoveDown_Click(object sender, EventArgs e)
|
|
{
|
|
if (grid.SelectedRows.Count == 1)
|
|
{
|
|
int idx = grid.SelectedRows[0].Index;
|
|
if (idx == grid.Rows.Count - 1 )
|
|
return;
|
|
Entry entry = entries[idx];
|
|
entries.Remove(entry);
|
|
entries.Insert(idx + 1, entry);
|
|
grid.ClearSelection();
|
|
grid.Rows[idx + 1].Selected = true;
|
|
}
|
|
}
|
|
|
|
private void btnAutoStart_Click(object sender, EventArgs e)
|
|
{
|
|
if (txtHeader.Text == "")
|
|
{
|
|
|
|
MessageBox.Show("Udfyld løbs titel");
|
|
return;
|
|
}
|
|
liste = new ResultList("Resultat", this);
|
|
liste.WriteHeader(txtHeader.Text);
|
|
btnAutoStart.Enabled = false;
|
|
btnStop.Enabled = true;
|
|
if (comboComport.Items.Count != 0)
|
|
{
|
|
horn = new Relay(comboComport.SelectedItem.ToString());
|
|
}
|
|
if (checkStartProcedure.Checked)
|
|
{
|
|
startprocedure.setObjects(horn, liste);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void btnStop_Click(object sender, EventArgs e)
|
|
{
|
|
btnStop.Enabled = false;
|
|
|
|
horn.Close();
|
|
|
|
liste.Write("Nedtælling stoppet");
|
|
|
|
countdowntimer.Stop();
|
|
|
|
}
|
|
|
|
private void timer_Tick(object sender, EventArgs e)
|
|
{
|
|
countdowntimer.Stop();
|
|
horn.Set(0x00, 0x00);
|
|
}
|
|
|
|
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 Form1_HelpButtonClicked(object sender, CancelEventArgs e)
|
|
{
|
|
AboutBox aboutbox = new AboutBox();
|
|
aboutbox.Show();
|
|
|
|
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
AboutBox aboutbox = new AboutBox();
|
|
aboutbox.Show();
|
|
}
|
|
|
|
private void btnTest_Click(object sender, EventArgs e)
|
|
{
|
|
if (!btnStop.Enabled)
|
|
return;
|
|
|
|
horn.Set(0x00, 0x01);
|
|
countdowntimer.Interval = int.Parse(comboSoundTime.SelectedItem.ToString());
|
|
countdowntimer.Start();
|
|
}
|
|
|
|
private void btnEditList_Click(object sender, EventArgs e)
|
|
{
|
|
if (btnMoveUp.Enabled)
|
|
{
|
|
btnEditList.Text = "Rediger";
|
|
btnMoveUp.Enabled = false;
|
|
btnMoveDown.Enabled = false;
|
|
}
|
|
else
|
|
{
|
|
btnEditList.Text = "Aktiv";
|
|
btnMoveUp.Enabled = true;
|
|
btnMoveDown.Enabled = true;
|
|
}
|
|
}
|
|
|
|
private void Clock_Tick(object sender, EventArgs e)
|
|
{
|
|
lblClock.Text = DateTime.Now.ToString("HH:mm:ss");
|
|
}
|
|
}
|
|
}
|