Compare commits

...

5 Commits

Author SHA1 Message Date
3511bf1c7e Static code analysis 2022-11-03 21:58:32 +01:00
a12e02736c Formatting 2022-11-03 20:35:45 +01:00
643bda1dec VS2022 solution file 2022-10-07 22:57:38 +02:00
588ecab69f Reduced unneeded files 2022-10-07 22:33:54 +02:00
05b01a1642 Now builds without About box 2022-10-07 22:24:46 +02:00
11 changed files with 92 additions and 171 deletions

34
MainUI.Designer.cs generated
View File

@ -31,7 +31,6 @@
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainUI));
this.btnTest = new System.Windows.Forms.Button();
this.buttonHelp = new System.Windows.Forms.Button();
this.txtDebug = new System.Windows.Forms.TextBox();
this.panel1 = new System.Windows.Forms.Panel();
this.textStartProcedure = new System.Windows.Forms.TextBox();
@ -41,9 +40,9 @@
this.txtHeader = new System.Windows.Forms.TextBox();
this.grid = new System.Windows.Forms.DataGridView();
this.Complete = new System.Windows.Forms.DataGridViewButtonColumn();
this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.DNF = new System.Windows.Forms.DataGridViewButtonColumn();
this.entryBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.txtLog = new System.Windows.Forms.TableLayoutPanel();
this.lblClock = new System.Windows.Forms.Label();
this.flowLayoutPanelConfiguration = new System.Windows.Forms.FlowLayoutPanel();
@ -74,17 +73,6 @@
this.btnTest.UseVisualStyleBackColor = true;
this.btnTest.Click += new System.EventHandler(this.btnTest_Click);
//
// buttonHelp
//
this.buttonHelp.Location = new System.Drawing.Point(4, 61);
this.buttonHelp.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.buttonHelp.Name = "buttonHelp";
this.buttonHelp.Size = new System.Drawing.Size(88, 27);
this.buttonHelp.TabIndex = 14;
this.buttonHelp.Text = "Hjælp mm.";
this.buttonHelp.UseVisualStyleBackColor = true;
this.buttonHelp.Click += new System.EventHandler(this.buttonHelp_Click);
//
// txtDebug
//
this.txtDebug.Dock = System.Windows.Forms.DockStyle.Fill;
@ -186,7 +174,6 @@
this.grid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.grid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Complete,
this.nameDataGridViewTextBoxColumn,
this.DNF});
this.txtLog.SetColumnSpan(this.grid, 2);
this.grid.DataSource = this.entryBindingSource;
@ -218,13 +205,6 @@
this.Complete.ReadOnly = true;
this.Complete.Text = "Mål";
//
// nameDataGridViewTextBoxColumn
//
this.nameDataGridViewTextBoxColumn.DataPropertyName = "SailNumber";
this.nameDataGridViewTextBoxColumn.HeaderText = "Sejlnummer";
this.nameDataGridViewTextBoxColumn.Name = "nameDataGridViewTextBoxColumn";
this.nameDataGridViewTextBoxColumn.ReadOnly = true;
//
// DNF
//
this.DNF.HeaderText = "DNF";
@ -233,9 +213,12 @@
this.DNF.Text = "Udgået";
this.DNF.UseColumnTextForButtonValue = true;
//
// entryBindingSource
// nameDataGridViewTextBoxColumn
//
this.entryBindingSource.DataSource = typeof(Tidstagning.Entry);
this.nameDataGridViewTextBoxColumn.DataPropertyName = "SailNumber";
this.nameDataGridViewTextBoxColumn.HeaderText = "Sejlnummer";
this.nameDataGridViewTextBoxColumn.Name = "nameDataGridViewTextBoxColumn";
this.nameDataGridViewTextBoxColumn.Width = 198;
//
// txtLog
//
@ -282,7 +265,6 @@
this.flowLayoutPanelConfiguration.Controls.Add(this.label1);
this.flowLayoutPanelConfiguration.Controls.Add(this.comboComport);
this.flowLayoutPanelConfiguration.Controls.Add(this.label2);
this.flowLayoutPanelConfiguration.Controls.Add(this.buttonHelp);
this.flowLayoutPanelConfiguration.Controls.Add(this.buttonConfig);
this.flowLayoutPanelConfiguration.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanelConfiguration.Location = new System.Drawing.Point(4, 635);
@ -355,7 +337,7 @@
//
// buttonConfig
//
this.buttonConfig.Location = new System.Drawing.Point(100, 61);
this.buttonConfig.Location = new System.Drawing.Point(4, 61);
this.buttonConfig.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.buttonConfig.Name = "buttonConfig";
this.buttonConfig.Size = new System.Drawing.Size(105, 27);
@ -383,6 +365,7 @@
this.Name = "MainUI";
this.Text = "Tidstagning";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainUI_FormClosed);
this.Load += new System.EventHandler(this.Form1_Load);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
@ -401,7 +384,6 @@
private System.Windows.Forms.BindingSource entryBindingSource;
private System.Windows.Forms.Button btnTest;
private System.Windows.Forms.Button buttonHelp;
private System.Windows.Forms.TextBox txtDebug;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button btnStart;

View File

@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows.Forms;
namespace Tidstagning
@ -7,18 +8,15 @@ namespace Tidstagning
public partial class MainUI : Form
{
delegate void SetTextCallback(string text);
BindingList<Entry> entries = new BindingList<Entry>
{
};
readonly BindingList<Entry> entries = new() { };
ResultList? liste;
Relay horn = new Relay();
Procedure startprocedure = new Procedure();
readonly Relay horn = new();
readonly Procedure startprocedure = new();
public MainUI(bool ShowConfig = false)
{
InitializeComponent();
System.IO.StreamReader deltager_handle = new System.IO.StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/Tidstagning/" + "Deltager.txt");
System.IO.StreamReader deltager_handle = new(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/Tidstagning/" + "Deltager.txt");
string? deltager;
while ((deltager = deltager_handle.ReadLine()) != null)
{
@ -60,7 +58,7 @@ namespace Tidstagning
{
if (this.txtDebug.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(LogAppend);
SetTextCallback d = new(LogAppend);
this.Invoke(d, new object[] { text });
}
else
@ -101,7 +99,7 @@ namespace Tidstagning
private void btnStart_Click(object sender, EventArgs e)
{
if (txtHeader.Text == "")
if (txtHeader.Text.Trim().Length == 0)
{
MessageBox.Show("Udfyld løbs titel");
return;
@ -136,13 +134,6 @@ namespace Tidstagning
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)
{
horn.Sound((uint)Properties.Settings.Default.SignalLength);
@ -150,7 +141,7 @@ namespace Tidstagning
private void Clock_Tick(object sender, EventArgs e)
{
lblClock.Text = DateTime.Now.ToString("HH:mm:ss");
lblClock.Text = DateTime.Now.ToString("HH:mm:ss", new CultureInfo("da-DK"));
if (checkStartProcedure.Checked)
{
textStartProcedure.Text = startprocedure.TextualRepresentation();
@ -194,7 +185,8 @@ namespace Tidstagning
grid.Focus();
}
}
catch { }
catch(InvalidOperationException)
{ }
}
}
@ -208,7 +200,7 @@ namespace Tidstagning
grid.Rows[e.RowIndex].Height = 30;
}
catch
catch(InvalidOperationException)
{ }
}
@ -216,8 +208,10 @@ namespace Tidstagning
private void buttonConfig_Click(object sender, EventArgs e)
{
ConfigUI configui = new ConfigUI();
configui.ShowDialog();
using (ConfigUI configui = new())
{
configui.ShowDialog();
}
}
private void numericSignalLength_ValueChanged(object sender, EventArgs e)
@ -226,5 +220,14 @@ namespace Tidstagning
Properties.Settings.Default.SignalLength = (uint)numericSignalLength.Value;
Properties.Settings.Default.Save();
}
private void MainUI_FormClosed(object sender, FormClosedEventArgs e)
{
if (liste is not null)
{
liste.Close();
}
}
}
}

View File

@ -1,6 +1,9 @@
using System.Collections.Generic;
using System.Diagnostics;
using System;
using Timer = System.Threading.Timer;
using System.Globalization;
namespace Tidstagning
{
class Procedure
@ -11,7 +14,7 @@ namespace Tidstagning
uint signalLength = 500;
Timer? delayTimer;
Int16 idx = 0;
int idx;
public Procedure()
{
@ -36,9 +39,9 @@ namespace Tidstagning
{
try
{
signaler.Add(DateTime.Parse(input_filtered));
signaler.Add(DateTime.Parse(input_filtered, new CultureInfo("da-DK")));
}
catch
catch(ArgumentNullException)
{
Debug.WriteLine("Failed to parse: " + input);
}
@ -65,7 +68,7 @@ namespace Tidstagning
{
t += " ";
}
t += signal.ToString() + "\r\n";
t += signal.ToString(new CultureInfo("da-DK")) + "\r\n";
}
}
return t;
@ -115,7 +118,8 @@ namespace Tidstagning
}
if (log is not null)
{
log.Write("Næste signal: " + alertTime.ToString(@"HH\:mm\:ss") + " Om: " + timeToGo.ToString(@"hh\:mm\:ss"));
;
log.Write("Næste signal: " + alertTime.ToString(@"HH\:mm\:ss", new CultureInfo("da-DK")) + " Om: " + timeToGo.ToString(@"hh\:mm\:ss", new CultureInfo("da-DK")));
}
delayTimer = new Timer(x =>
{

View File

@ -1,7 +1,7 @@
using System;
using CommandLine;
using System.Collections.Generic;
using CommandLine;
using System.Windows.Forms;
using System;
[assembly: CLSCompliant(false)]
namespace Tidstagning
{

View File

@ -12,7 +12,7 @@ namespace Tidstagning.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.3.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

View File

@ -1,7 +0,0 @@
{
"profiles": {
"Tidstagning": {
"commandName": "Project"
}
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO.Ports;
using System.Threading;
@ -16,7 +17,7 @@ namespace Tidstagning
public bool output_on;
};
Queue<SignalSpec> signals = new Queue<SignalSpec>();
bool processing_queue = false;
bool processing_queue;
public Relay()
{
@ -36,7 +37,7 @@ namespace Tidstagning
com.Open();
return true;
}
catch
catch (ArgumentException)
{
return false;
}
@ -67,7 +68,7 @@ namespace Tidstagning
return;
}
Debug.WriteLine("Requesting horn for: " + time.ToString() + "ms");
Debug.WriteLine("Requesting horn for: " + time.ToString(new CultureInfo("da-DK")) + "ms");
SignalSpec on_signal;
on_signal.duration = time;
on_signal.output_on = true;

View File

@ -1,8 +1,10 @@
using System;
using System.Globalization;
using System.IO;
namespace Tidstagning
{
class ResultList
class ResultList : IDisposable
{
System.IO.StreamWriter filehandle_log;
System.IO.StreamWriter filehandle_results;
@ -11,12 +13,12 @@ namespace Tidstagning
public ResultList(string filename, Tidstagning.MainUI log_object)
{
filename = MakeSafeFilename(filename, '_');
filehandle_log = new System.IO.StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/Tidstagning/" + filename + "_" + DateTime.Now.ToString(" dd-MM-yyyy HH-mm-ss") + ".txt");
filehandle_results = new System.IO.StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/Tidstagning/" + filename + "_" + DateTime.Now.ToString(" dd-MM-yyyy HH-mm-ss") + ".csv");
filehandle_log = new System.IO.StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/Tidstagning/" + filename + "_" + DateTime.Now.ToString(" dd-MM-yyyy HH-mm-ss", new CultureInfo("da-DK")) + ".txt");
filehandle_results = new System.IO.StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/Tidstagning/" + filename + "_" + DateTime.Now.ToString(" dd-MM-yyyy HH-mm-ss", new CultureInfo("da-DK")) + ".csv");
parentForm = log_object;
}
private string MakeSafeFilename(string filename, char replaceChar)
private static string MakeSafeFilename(string filename, char replaceChar)
{
foreach (char c in System.IO.Path.GetInvalidFileNameChars())
{
@ -30,7 +32,7 @@ namespace Tidstagning
this.racenumber = header;
Write("----------------------------");
Write(header);
Write("Løb startet den: " + DateTime.Now.ToString());
Write("Løb startet den: " + DateTime.Now.ToString(new CultureInfo("da-DK")));
Write("----------------------------");
WriteCSV("RaceNo,SailNo,Finish,Code,");
}
@ -39,19 +41,19 @@ namespace Tidstagning
public void WriteFooter()
{
Write("----------------------------");
Write("Løb afsluttet den: " + DateTime.Now.ToString());
Write("Løb afsluttet den: " + DateTime.Now.ToString(new CultureInfo("da-DK")));
Write("----------------------------");
}
public void WriteComplete(Entry Boat)
{
Write("Fuldført! - " + Boat.Name + " - " + Boat.Completed_Time.ToString());
WriteCSV(this.racenumber + "," + Boat.SailNumber + "," + Boat.Completed_Time.ToString("HH:mm:ss") + ", ,");
Write("Fuldført! - " + Boat.Name + " - " + Boat.Completed_Time.ToString(new CultureInfo("da-DK")));
WriteCSV(this.racenumber + "," + Boat.SailNumber + "," + Boat.Completed_Time.ToString("HH:mm:ss", new CultureInfo("da-DK")) + ", ,");
}
public void WriteDNF(Entry Boat)
{
Write("Udgået! - " + Boat.Name + " - " + Boat.Completed_Time.ToString());
Write("Udgået! - " + Boat.Name + " - " + Boat.Completed_Time.ToString(new CultureInfo("da-DK")));
WriteCSV(this.racenumber + "," + Boat.SailNumber + "," + "00:00:00,DNC,");
}
@ -71,8 +73,15 @@ namespace Tidstagning
public void Close()
{
filehandle_log.Close();
filehandle_log.Dispose();
filehandle_results.Close();
filehandle_results.Dispose();
}
public void Dispose()
{
this.Close();
}
}
}

62
Settings.Designer.cs generated
View File

@ -1,62 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Tidstagning {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.3.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("N/A")]
public string ComPort {
get {
return ((string)(this["ComPort"]));
}
set {
this["ComPort"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool AutoStartProcedure {
get {
return ((bool)(this["AutoStartProcedure"]));
}
set {
this["AutoStartProcedure"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("500")]
public uint SignalLength {
get {
return ((uint)(this["SignalLength"]));
}
set {
this["SignalLength"] = value;
}
}
}
}

View File

@ -1,33 +0,0 @@
namespace Tidstagning.Properties
{
// This class allows you to handle specific events on the settings class:
// The SettingChanging event is raised before a setting's value is changed.
// The PropertyChanged event is raised after a setting's value is changed.
// The SettingsLoaded event is raised after the setting values are loaded.
// The SettingsSaving event is raised before the setting values are saved.
internal sealed partial class Settings
{
public Settings()
{
// // To add event handlers for saving and changing settings, uncomment the lines below:
//
// this.SettingChanging += this.SettingChangingEventHandler;
//
// this.SettingsSaving += this.SettingsSavingEventHandler;
//
}
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e)
{
// Add code to handle the SettingChangingEvent event here.
}
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e)
{
// Add code to handle the SettingsSaving event here.
}
}
}

View File

@ -5,7 +5,16 @@
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>true</ImplicitUsings>
<ImplicitUsings>false</ImplicitUsings>
<StartupObject>Tidstagning.Program</StartupObject>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Configurations>Release</Configurations>
<AnalysisLevel>latest-all</AnalysisLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<Optimize>False</Optimize>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
@ -13,4 +22,19 @@
<PackageReference Include="System.IO.Ports" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project>