ソースを参照

Add project files.

gregory 3 年 前
コミット
52c90d9eb7

+ 25 - 0
crusherScanner.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.1.32328.378
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "crusherScanner", "crusherScanner\crusherScanner.csproj", "{594D7995-6E4A-44E5-AC36-4E3F544EFF58}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{594D7995-6E4A-44E5-AC36-4E3F544EFF58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{594D7995-6E4A-44E5-AC36-4E3F544EFF58}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{594D7995-6E4A-44E5-AC36-4E3F544EFF58}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{594D7995-6E4A-44E5-AC36-4E3F544EFF58}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {4F75C36E-39CD-4A7C-94C8-6EF7EAB39C53}
+	EndGlobalSection
+EndGlobal

BIN
crusherScanner/0d28e7dc-5024-45b7-81f8-bb1c48fe484d.ico


+ 57 - 0
crusherScanner/CustomTypes.cs

@@ -0,0 +1,57 @@
+namespace crusherScanner
+{
+    public struct Samples
+    {
+        public string Sid;
+        public string Job;
+        public bool Pyrite;
+        public bool Plastic;
+        public bool Manganese;
+        public bool HammerOil;
+        public bool scanned;
+    }
+
+    public struct Scan
+    {
+        public string barcode; // Original scanned barcode.
+        public string sampleType; // Null, RCA, RCB, etc.
+        public bool isInLims; // Does this sample exist in LIMS.
+        public string message; // Reply message to the user.
+        public bool messageState; // Is the reply message good or an error.
+        public int BufferCount; // Count of how many samples in memory cache.
+        public bool Contaminated; // Does this sample contain Contaminates.
+        public bool SampleNotFound; // Unable to find this sample in job files.
+        public int JobTotal; // Total number of samples in the job.
+        public int JobCount; // Number of samples scanned in the job.
+        public Samples sampleData; // Sample details ie. contaminates, job, etc.
+    }
+
+    public struct Settings
+    {
+        public string PrepmasterMagazineSerial { get; set; }
+        public string OreDefInFile { get; set; }
+        public string OreDefOutFile { get; set; }
+        public string OreDefWorkFile { get; set; }
+        public int CrusherNo { get; set; }
+        public string OutputFormat { get; set; }
+        public string OreDefTypes { get; set; }
+        public bool LimsConnection { get; set; }
+        public string LimsConnString { get; set; }
+        public bool PrepmasterConnection { get; set; }
+    }
+
+    public struct Logs
+    {
+        public DateTime dateStamp;
+        public string logLevel;
+        public string message;
+    }
+
+    enum LogLevel
+    {
+        Error = 0,
+        Warning = 1,
+        Information = 2
+    }
+    
+}

+ 90 - 0
crusherScanner/FileAccess.cs

@@ -0,0 +1,90 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace crusherScanner
+{
+    internal class FileAccess
+    {
+
+
+        public static HashSet<Samples> GetOreDefData(HashSet<Samples> samples,string barcode)
+        {
+            string[] DataDirs = new string[2] { Properties.Settings.Default.OreDefWorkFile, Properties.Settings.Default.OreDefInFile };
+
+            try
+            {
+                foreach (var DataDir in DataDirs)
+                {
+                    if (Directory.Exists(DataDir))
+                    {
+                        var jobFiles = Directory.EnumerateFiles(DataDir, "ML??????.csv", SearchOption.TopDirectoryOnly);
+                        foreach (var jobFile in jobFiles)
+                        {
+                            bool sampleFound;
+                            (samples, sampleFound) = ReadCSV(barcode, jobFile, samples);
+                            if (sampleFound)
+                            {
+                                return samples;
+                            }
+                        }
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show("An error occurred." + Environment.NewLine + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+            }
+            return samples;
+        }
+
+        private static (HashSet<Samples>,bool) ReadCSV(string barcode, string CsvFile, HashSet<Samples> samples)
+        {
+            bool BarcodeFound = false;
+            string[] RawSampleData = new string[1] { "" };
+            string[] lines = File.ReadAllLines(CsvFile);
+
+            foreach (var line in lines)
+            {
+                if (line.Contains('\u002C'))
+                {
+                    RawSampleData = line.Split('\u002C');
+                }
+
+                if (RawSampleData.Length == 9)
+                {
+                    Samples sample = new();
+                    if (RawSampleData[0] == barcode)
+                    {
+                        BarcodeFound = true;
+                    }
+                    if (RawSampleData[0] != "SAMPLEID")
+                    {
+                        sample.Sid = RawSampleData[0];
+                        sample.Job = RawSampleData[1];
+                        if (RawSampleData[2] == "PYRITE")
+                        {
+                            sample.Pyrite = true;
+                        }
+                        if (RawSampleData[3] == "PLASTIC")
+                        {
+                            sample.Plastic = true;
+                        }
+                        if (RawSampleData[4] == "MANGANESE")
+                        {
+                            sample.Manganese = true;
+                        }
+                        if (RawSampleData[5] == "HAMMEROIL")
+                        {
+                            sample.HammerOil = true;
+                        }
+                        samples.Add(sample);
+                    }
+                }
+            }
+            return (samples,BarcodeFound);
+        }
+    }
+}

+ 471 - 0
crusherScanner/Form1.Designer.cs

@@ -0,0 +1,471 @@
+namespace crusherScanner
+{
+    partial class Form1
+    {
+        /// <summary>
+        ///  Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        ///  Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        ///  Required method for Designer support - do not modify
+        ///  the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.components = new System.ComponentModel.Container();
+            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
+            this.TextBox1 = new System.Windows.Forms.TextBox();
+            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
+            this.menuToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
+            this.importToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.exportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
+            this.purgeToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
+            this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
+            this.logsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.openCurrentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.openDirectoryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.purgeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
+            this.reinitializeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.reinitializeSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.testSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
+            this.ExitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
+            this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
+            this.label1 = new System.Windows.Forms.Label();
+            this.label2 = new System.Windows.Forms.Label();
+            this.label3 = new System.Windows.Forms.Label();
+            this.label4 = new System.Windows.Forms.Label();
+            this.label5 = new System.Windows.Forms.Label();
+            this.Timer1 = new System.Windows.Forms.Timer(this.components);
+            this.label6 = new System.Windows.Forms.Label();
+            this.label7 = new System.Windows.Forms.Label();
+            this.statusStrip1 = new System.Windows.Forms.StatusStrip();
+            this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
+            this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel();
+            this.toolStripStatusLabel3 = new System.Windows.Forms.ToolStripStatusLabel();
+            this.toolStripStatusLabel4 = new System.Windows.Forms.ToolStripStatusLabel();
+            this.toolStripStatusLabel5 = new System.Windows.Forms.ToolStripStatusLabel();
+            this.toolStripStatusLabel7 = new System.Windows.Forms.ToolStripStatusLabel();
+            this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar();
+            this.label8 = new System.Windows.Forms.Label();
+            this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
+            this.menuStrip1.SuspendLayout();
+            this.statusStrip1.SuspendLayout();
+            this.SuspendLayout();
+            // 
+            // TextBox1
+            // 
+            this.TextBox1.Font = new System.Drawing.Font("Segoe UI", 34F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+            this.TextBox1.Location = new System.Drawing.Point(279, 214);
+            this.TextBox1.Name = "TextBox1";
+            this.TextBox1.PlaceholderText = "Scan Barcode here!";
+            this.TextBox1.Size = new System.Drawing.Size(706, 98);
+            this.TextBox1.TabIndex = 0;
+            this.TextBox1.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.TextBox1_PreviewKeyDown);
+            // 
+            // menuStrip1
+            // 
+            this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
+            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.menuToolStripMenuItem});
+            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
+            this.menuStrip1.Name = "menuStrip1";
+            this.menuStrip1.Size = new System.Drawing.Size(1708, 33);
+            this.menuStrip1.TabIndex = 1;
+            this.menuStrip1.Text = "menuStrip1";
+            // 
+            // menuToolStripMenuItem
+            // 
+            this.menuToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.settingsToolStripMenuItem,
+            this.toolStripSeparator2,
+            this.logsToolStripMenuItem,
+            this.toolStripSeparator3,
+            this.reinitializeToolStripMenuItem,
+            this.toolStripSeparator4,
+            this.ExitToolStripMenuItem});
+            this.menuToolStripMenuItem.Name = "menuToolStripMenuItem";
+            this.menuToolStripMenuItem.Size = new System.Drawing.Size(73, 29);
+            this.menuToolStripMenuItem.Text = "Menu";
+            // 
+            // settingsToolStripMenuItem
+            // 
+            this.settingsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.editToolStripMenuItem,
+            this.toolStripSeparator1,
+            this.importToolStripMenuItem,
+            this.exportToolStripMenuItem,
+            this.toolStripSeparator5,
+            this.purgeToolStripMenuItem1});
+            this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem";
+            this.settingsToolStripMenuItem.Size = new System.Drawing.Size(195, 34);
+            this.settingsToolStripMenuItem.Text = "Settings";
+            // 
+            // editToolStripMenuItem
+            // 
+            this.editToolStripMenuItem.Name = "editToolStripMenuItem";
+            this.editToolStripMenuItem.Size = new System.Drawing.Size(169, 34);
+            this.editToolStripMenuItem.Text = "Edit";
+            this.editToolStripMenuItem.Click += new System.EventHandler(this.EditToolStripMenuItem_Click);
+            // 
+            // toolStripSeparator1
+            // 
+            this.toolStripSeparator1.Name = "toolStripSeparator1";
+            this.toolStripSeparator1.Size = new System.Drawing.Size(166, 6);
+            // 
+            // importToolStripMenuItem
+            // 
+            this.importToolStripMenuItem.Name = "importToolStripMenuItem";
+            this.importToolStripMenuItem.Size = new System.Drawing.Size(169, 34);
+            this.importToolStripMenuItem.Text = "Import";
+            this.importToolStripMenuItem.Click += new System.EventHandler(this.ImportToolStripMenuItem_Click);
+            // 
+            // exportToolStripMenuItem
+            // 
+            this.exportToolStripMenuItem.Name = "exportToolStripMenuItem";
+            this.exportToolStripMenuItem.Size = new System.Drawing.Size(169, 34);
+            this.exportToolStripMenuItem.Text = "Export";
+            this.exportToolStripMenuItem.Click += new System.EventHandler(this.ExportToolStripMenuItem_Click);
+            // 
+            // toolStripSeparator5
+            // 
+            this.toolStripSeparator5.Name = "toolStripSeparator5";
+            this.toolStripSeparator5.Size = new System.Drawing.Size(166, 6);
+            // 
+            // purgeToolStripMenuItem1
+            // 
+            this.purgeToolStripMenuItem1.Name = "purgeToolStripMenuItem1";
+            this.purgeToolStripMenuItem1.Size = new System.Drawing.Size(169, 34);
+            this.purgeToolStripMenuItem1.Text = "Purge";
+            this.purgeToolStripMenuItem1.Click += new System.EventHandler(this.PurgeToolStripMenuItem1_Click);
+            // 
+            // toolStripSeparator2
+            // 
+            this.toolStripSeparator2.Name = "toolStripSeparator2";
+            this.toolStripSeparator2.Size = new System.Drawing.Size(192, 6);
+            // 
+            // logsToolStripMenuItem
+            // 
+            this.logsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.openCurrentToolStripMenuItem,
+            this.openDirectoryToolStripMenuItem,
+            this.purgeToolStripMenuItem});
+            this.logsToolStripMenuItem.Name = "logsToolStripMenuItem";
+            this.logsToolStripMenuItem.Size = new System.Drawing.Size(195, 34);
+            this.logsToolStripMenuItem.Text = "Logs";
+            // 
+            // openCurrentToolStripMenuItem
+            // 
+            this.openCurrentToolStripMenuItem.Name = "openCurrentToolStripMenuItem";
+            this.openCurrentToolStripMenuItem.Size = new System.Drawing.Size(233, 34);
+            this.openCurrentToolStripMenuItem.Text = "Open current";
+            // 
+            // openDirectoryToolStripMenuItem
+            // 
+            this.openDirectoryToolStripMenuItem.Name = "openDirectoryToolStripMenuItem";
+            this.openDirectoryToolStripMenuItem.Size = new System.Drawing.Size(233, 34);
+            this.openDirectoryToolStripMenuItem.Text = "Open directory";
+            // 
+            // purgeToolStripMenuItem
+            // 
+            this.purgeToolStripMenuItem.Name = "purgeToolStripMenuItem";
+            this.purgeToolStripMenuItem.Size = new System.Drawing.Size(233, 34);
+            this.purgeToolStripMenuItem.Text = "Purge";
+            // 
+            // toolStripSeparator3
+            // 
+            this.toolStripSeparator3.Name = "toolStripSeparator3";
+            this.toolStripSeparator3.Size = new System.Drawing.Size(192, 6);
+            // 
+            // reinitializeToolStripMenuItem
+            // 
+            this.reinitializeToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.reinitializeSettingsToolStripMenuItem,
+            this.testSettingsToolStripMenuItem});
+            this.reinitializeToolStripMenuItem.Name = "reinitializeToolStripMenuItem";
+            this.reinitializeToolStripMenuItem.Size = new System.Drawing.Size(195, 34);
+            this.reinitializeToolStripMenuItem.Text = "Reinitialize";
+            // 
+            // reinitializeSettingsToolStripMenuItem
+            // 
+            this.reinitializeSettingsToolStripMenuItem.Name = "reinitializeSettingsToolStripMenuItem";
+            this.reinitializeSettingsToolStripMenuItem.Size = new System.Drawing.Size(262, 34);
+            this.reinitializeSettingsToolStripMenuItem.Text = "Reinitialize settings";
+            this.reinitializeSettingsToolStripMenuItem.Click += new System.EventHandler(this.ReinitializeSettingsToolStripMenuItem_Click);
+            // 
+            // testSettingsToolStripMenuItem
+            // 
+            this.testSettingsToolStripMenuItem.Name = "testSettingsToolStripMenuItem";
+            this.testSettingsToolStripMenuItem.Size = new System.Drawing.Size(262, 34);
+            this.testSettingsToolStripMenuItem.Text = "Test settings";
+            // 
+            // toolStripSeparator4
+            // 
+            this.toolStripSeparator4.Name = "toolStripSeparator4";
+            this.toolStripSeparator4.Size = new System.Drawing.Size(192, 6);
+            // 
+            // ExitToolStripMenuItem
+            // 
+            this.ExitToolStripMenuItem.Name = "ExitToolStripMenuItem";
+            this.ExitToolStripMenuItem.Size = new System.Drawing.Size(195, 34);
+            this.ExitToolStripMenuItem.Text = "Exit";
+            this.ExitToolStripMenuItem.Click += new System.EventHandler(this.ExitToolStripMenuItem_Click);
+            // 
+            // openFileDialog1
+            // 
+            this.openFileDialog1.FileName = "openFileDialog1";
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.BackColor = System.Drawing.Color.Lime;
+            this.label1.Font = new System.Drawing.Font("Segoe UI", 34F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+            this.label1.Location = new System.Drawing.Point(279, 315);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(219, 91);
+            this.label1.TabIndex = 2;
+            this.label1.Text = "label1";
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.BackColor = System.Drawing.Color.Fuchsia;
+            this.label2.Font = new System.Drawing.Font("Segoe UI", 34F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+            this.label2.Location = new System.Drawing.Point(279, 406);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(219, 91);
+            this.label2.TabIndex = 3;
+            this.label2.Text = "label2";
+            // 
+            // label3
+            // 
+            this.label3.AutoSize = true;
+            this.label3.BackColor = System.Drawing.Color.Orange;
+            this.label3.Font = new System.Drawing.Font("Segoe UI", 34F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+            this.label3.Location = new System.Drawing.Point(279, 497);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(219, 91);
+            this.label3.TabIndex = 4;
+            this.label3.Text = "label3";
+            // 
+            // label4
+            // 
+            this.label4.AutoSize = true;
+            this.label4.BackColor = System.Drawing.Color.Blue;
+            this.label4.Font = new System.Drawing.Font("Segoe UI", 34F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+            this.label4.ForeColor = System.Drawing.Color.White;
+            this.label4.Location = new System.Drawing.Point(279, 588);
+            this.label4.Name = "label4";
+            this.label4.Size = new System.Drawing.Size(219, 91);
+            this.label4.TabIndex = 5;
+            this.label4.Text = "label4";
+            // 
+            // label5
+            // 
+            this.label5.AutoSize = true;
+            this.label5.BackColor = System.Drawing.Color.Maroon;
+            this.label5.Font = new System.Drawing.Font("Segoe UI", 34F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+            this.label5.ForeColor = System.Drawing.Color.White;
+            this.label5.Location = new System.Drawing.Point(279, 679);
+            this.label5.Name = "label5";
+            this.label5.Size = new System.Drawing.Size(219, 91);
+            this.label5.TabIndex = 6;
+            this.label5.Text = "label5";
+            // 
+            // Timer1
+            // 
+            this.Timer1.Enabled = true;
+            this.Timer1.Interval = 1000;
+            this.Timer1.Tick += new System.EventHandler(this.Timer1_Tick);
+            // 
+            // label6
+            // 
+            this.label6.AutoSize = true;
+            this.label6.Font = new System.Drawing.Font("Segoe UI", 35F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+            this.label6.Location = new System.Drawing.Point(759, 102);
+            this.label6.Name = "label6";
+            this.label6.Size = new System.Drawing.Size(226, 93);
+            this.label6.TabIndex = 7;
+            this.label6.Text = "label6";
+            // 
+            // label7
+            // 
+            this.label7.AutoSize = true;
+            this.label7.Font = new System.Drawing.Font("Segoe UI", 35F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+            this.label7.Location = new System.Drawing.Point(76, 102);
+            this.label7.Name = "label7";
+            this.label7.Size = new System.Drawing.Size(226, 93);
+            this.label7.TabIndex = 8;
+            this.label7.Text = "label7";
+            // 
+            // statusStrip1
+            // 
+            this.statusStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
+            this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.toolStripStatusLabel1,
+            this.toolStripStatusLabel2,
+            this.toolStripStatusLabel3,
+            this.toolStripStatusLabel4,
+            this.toolStripStatusLabel5,
+            this.toolStripStatusLabel7,
+            this.toolStripProgressBar1});
+            this.statusStrip1.Location = new System.Drawing.Point(0, 1128);
+            this.statusStrip1.Name = "statusStrip1";
+            this.statusStrip1.Size = new System.Drawing.Size(1708, 32);
+            this.statusStrip1.TabIndex = 9;
+            this.statusStrip1.Text = "statusStrip1";
+            // 
+            // toolStripStatusLabel1
+            // 
+            this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
+            this.toolStripStatusLabel1.Size = new System.Drawing.Size(165, 25);
+            this.toolStripStatusLabel1.Text = "Samples in buffer : ";
+            // 
+            // toolStripStatusLabel2
+            // 
+            this.toolStripStatusLabel2.Name = "toolStripStatusLabel2";
+            this.toolStripStatusLabel2.Size = new System.Drawing.Size(179, 25);
+            this.toolStripStatusLabel2.Text = "toolStripStatusLabel2";
+            // 
+            // toolStripStatusLabel3
+            // 
+            this.toolStripStatusLabel3.Name = "toolStripStatusLabel3";
+            this.toolStripStatusLabel3.Size = new System.Drawing.Size(62, 25);
+            this.toolStripStatusLabel3.Text = "          ";
+            // 
+            // toolStripStatusLabel4
+            // 
+            this.toolStripStatusLabel4.Name = "toolStripStatusLabel4";
+            this.toolStripStatusLabel4.Size = new System.Drawing.Size(181, 25);
+            this.toolStripStatusLabel4.Text = "Samples Remaining : ";
+            // 
+            // toolStripStatusLabel5
+            // 
+            this.toolStripStatusLabel5.Name = "toolStripStatusLabel5";
+            this.toolStripStatusLabel5.Size = new System.Drawing.Size(179, 25);
+            this.toolStripStatusLabel5.Text = "toolStripStatusLabel5";
+            // 
+            // toolStripStatusLabel7
+            // 
+            this.toolStripStatusLabel7.Name = "toolStripStatusLabel7";
+            this.toolStripStatusLabel7.Size = new System.Drawing.Size(212, 25);
+            this.toolStripStatusLabel7.Text = "Current Job completion : ";
+            // 
+            // toolStripProgressBar1
+            // 
+            this.toolStripProgressBar1.Name = "toolStripProgressBar1";
+            this.toolStripProgressBar1.Size = new System.Drawing.Size(300, 24);
+            this.toolStripProgressBar1.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
+            // 
+            // label8
+            // 
+            this.label8.AutoSize = true;
+            this.label8.Font = new System.Drawing.Font("Segoe UI", 50F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+            this.label8.Location = new System.Drawing.Point(152, 788);
+            this.label8.Name = "label8";
+            this.label8.Size = new System.Drawing.Size(321, 133);
+            this.label8.TabIndex = 10;
+            this.label8.Text = "label8";
+            // 
+            // backgroundWorker1
+            // 
+            this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
+            this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted);
+            // 
+            // Form1
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(1708, 1160);
+            this.Controls.Add(this.label8);
+            this.Controls.Add(this.statusStrip1);
+            this.Controls.Add(this.label7);
+            this.Controls.Add(this.label6);
+            this.Controls.Add(this.label5);
+            this.Controls.Add(this.label4);
+            this.Controls.Add(this.label3);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.label1);
+            this.Controls.Add(this.TextBox1);
+            this.Controls.Add(this.menuStrip1);
+            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
+            this.MainMenuStrip = this.menuStrip1;
+            this.Name = "Form1";
+            this.Text = "Crusher Scanner";
+            this.Load += new System.EventHandler(this.Form1_Load);
+            this.menuStrip1.ResumeLayout(false);
+            this.menuStrip1.PerformLayout();
+            this.statusStrip1.ResumeLayout(false);
+            this.statusStrip1.PerformLayout();
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private TextBox TextBox1;
+        private MenuStrip menuStrip1;
+        private ToolStripMenuItem menuToolStripMenuItem;
+        private ToolStripMenuItem settingsToolStripMenuItem;
+        private ToolStripMenuItem editToolStripMenuItem;
+        private ToolStripSeparator toolStripSeparator1;
+        private ToolStripMenuItem importToolStripMenuItem;
+        private ToolStripMenuItem exportToolStripMenuItem;
+        private ToolStripSeparator toolStripSeparator2;
+        private ToolStripMenuItem logsToolStripMenuItem;
+        private ToolStripMenuItem openCurrentToolStripMenuItem;
+        private ToolStripMenuItem openDirectoryToolStripMenuItem;
+        private ToolStripMenuItem purgeToolStripMenuItem;
+        private ToolStripSeparator toolStripSeparator3;
+        private ToolStripMenuItem reinitializeToolStripMenuItem;
+        private ToolStripSeparator toolStripSeparator4;
+        private ToolStripMenuItem ExitToolStripMenuItem;
+        private ToolStripMenuItem reinitializeSettingsToolStripMenuItem;
+        private ToolStripMenuItem testSettingsToolStripMenuItem;
+        private ToolStripSeparator toolStripSeparator5;
+        private ToolStripMenuItem purgeToolStripMenuItem1;
+        private SaveFileDialog saveFileDialog1;
+        private OpenFileDialog openFileDialog1;
+        private Label label1;
+        private Label label2;
+        private Label label3;
+        private Label label4;
+        private Label label5;
+        private System.Windows.Forms.Timer Timer1;
+        private Label label6;
+        private Label label7;
+        private StatusStrip statusStrip1;
+        private ToolStripStatusLabel toolStripStatusLabel1;
+        private ToolStripStatusLabel toolStripStatusLabel2;
+        private ToolStripStatusLabel toolStripStatusLabel3;
+        private ToolStripStatusLabel toolStripStatusLabel7;
+        private ToolStripProgressBar toolStripProgressBar1;
+        private Label label8;
+        private System.ComponentModel.BackgroundWorker backgroundWorker1;
+        private ToolStripStatusLabel toolStripStatusLabel4;
+        private ToolStripStatusLabel toolStripStatusLabel5;
+    }
+}

+ 233 - 0
crusherScanner/Form1.cs

@@ -0,0 +1,233 @@
+namespace crusherScanner
+{
+    public partial class Form1 : Form
+    {
+        private static ProgramFunctions? dataCore;
+        private static int counter = 0;
+
+        public Form1()
+        {
+            InitializeComponent();
+        }
+
+        private void Form1_Load(object sender, EventArgs e)
+        {
+            TextBox1.Enabled = false;
+            toolStripStatusLabel5.Text = "";
+            toolStripStatusLabel2.Text = "0";
+            label8.Text = "";
+            label7.Text = "";
+            label6.Text = "";
+            label5.Hide();
+            label4.Hide();
+            label3.Hide();
+            label2.Hide();
+            label1.Hide();
+            WindowState = FormWindowState.Maximized;
+            //TopMost = true;
+            dataCore = new ProgramFunctions();
+            TextBox1.Enabled = true;
+            TextBox1.Focus();
+        }
+
+        private void TextBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
+        {
+            Scan scanned = new();
+            scanned.BufferCount = -1;
+            counter = 2;
+            scanned.barcode = TextBox1.Text.Trim();
+            if (e.KeyValue == 13 && dataCore != null)
+            {
+                scanned = ProgramFunctions.StartChecks(scanned);
+                if(scanned.sampleData.Job != null)
+                {
+                    backgroundWorker1.RunWorkerAsync(scanned);
+                }
+                TextBox1.Text = "";
+                
+                if (scanned.sampleData.HammerOil)
+                {
+                    label5.Text = $"Sample {scanned.barcode} contains Hammer Oil";
+                    BackColor = Color.Maroon;
+                    label5.Show();
+                }
+                else
+                {
+                    label5.Hide();
+                }
+                if (scanned.sampleData.Manganese)
+                {
+                    label4.Text = $"Sample {scanned.barcode} contains Manganese";
+                    BackColor = Color.Blue;
+                    label4.Show();
+                }
+                else
+                {
+                    label4.Hide();
+                }
+                if (scanned.sampleData.Plastic)
+                {
+                    label3.Text = $"Sample {scanned.barcode} contains Plastic";
+                    BackColor = Color.Orange;
+                    label3.Show();
+                }
+                else
+                {
+                    label3.Hide();
+                }
+                if (scanned.sampleData.Pyrite)
+                {
+                    label2.Text = $"Sample {scanned.barcode} contains Pyrite";
+                    BackColor = Color.Fuchsia;
+                    label2.Show();
+                }
+                else
+                {
+                    label2.Hide();
+                }
+                if (!scanned.Contaminated)
+                {
+                    label1.Text = scanned.message;
+                    label1.Show();
+                }
+                else
+                {
+                    label1.Hide();
+                }
+                if (scanned.sampleData.Job != null)
+                {
+                    label8.Text = $"Job in progress : {scanned.sampleData.Job}";
+                }
+                else
+                {
+                    label8.Text = "";
+                }
+                if (scanned.BufferCount != -1)
+                {
+                    toolStripStatusLabel2.Text = scanned.BufferCount.ToString();
+                }
+            }
+        }
+
+        private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
+        {
+            this.Close();
+        }
+
+        #region SettingsHandlers
+
+        private void EditToolStripMenuItem_Click(object sender, EventArgs e)
+        {
+            SettingsDialog dlg = new();
+            dlg.ShowDialog();
+            dlg.Dispose();
+        }
+
+        private void PurgeToolStripMenuItem1_Click(object sender, EventArgs e)
+        {
+            DialogResult result = MessageBox.Show("Are you sure you would like to purge all setings?", "Clear settings.", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
+            if(result == DialogResult.Yes)
+            {
+                Properties.Settings.Default.Reset();
+                MessageBox.Show("Settings purged.", "Clear settings.");
+            }
+        }
+
+        /// <summary>
+        ///  Import settings from JSON file.
+        /// </summary>
+        private void ImportToolStripMenuItem_Click(object sender, EventArgs e)
+        {
+            openFileDialog1.DefaultExt = "json";
+            openFileDialog1.Filter = "Json files (*.json)|*.json";
+            openFileDialog1.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
+            openFileDialog1.ShowDialog();
+            string configFile = openFileDialog1.FileName;
+            try
+            {
+                if(configFile=="" && File.Exists(configFile) && dataCore != null)
+                {
+                    ProgramFunctions.ImportConfigFile();
+                }
+                else if(File.Exists(configFile) && dataCore != null)
+                {
+                    ProgramFunctions.ImportConfigFile(configFile);
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show("An error occurred." + Environment.NewLine + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+            }
+        }
+
+        /// <summary>
+        ///  Export settings to JSON file.
+        /// </summary>
+        private void ExportToolStripMenuItem_Click(object sender, EventArgs e)
+        {
+            saveFileDialog1.DefaultExt = "json";
+            saveFileDialog1.Filter = "Json files (*.json)|*.json";
+            saveFileDialog1.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
+            saveFileDialog1.ShowDialog();
+            string configFile = saveFileDialog1.FileName;
+            try
+            {
+                if(configFile == "" && dataCore != null)
+                {
+                    ProgramFunctions.ExportConfigFile();
+                }
+                else if (dataCore != null)
+                {
+                    ProgramFunctions.ExportConfigFile(configFile);
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show("An error occurred." + Environment.NewLine + ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
+            }
+        }
+        #endregion
+
+        private void ReinitializeSettingsToolStripMenuItem_Click(object sender, EventArgs e)
+        {
+            Application.Restart();
+        }
+
+        private void Timer1_Tick(object sender, EventArgs e)
+        {
+            DateTime now = DateTime.Now;
+            label6.Text = now.ToShortTimeString();
+            label7.Text = now.ToShortDateString();
+            if (counter <= 0)
+            {
+                BackColor = SystemColors.Control;
+                counter = 2;
+            }
+            else if(BackColor.Name != "Control")
+            {
+                counter--;
+            }
+             
+        }
+
+        private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
+        {
+            if (e.Argument!=null)
+            {
+                WorkingDirControl.UpdateWorkingDir(e);
+            }
+        }
+
+        private void backgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
+        {
+            Scan scan;
+            if (e.Result != null)
+            {
+                scan = (Scan)e.Result;
+                toolStripProgressBar1.Maximum = scan.JobTotal;
+                toolStripProgressBar1.Value = scan.JobCount;
+                toolStripStatusLabel5.Text = (scan.JobTotal - (int)scan.JobCount).ToString();
+            }
+        }
+    }
+}

+ 99 - 0
crusherScanner/Form1.resx

@@ -0,0 +1,99 @@
+<root>
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+  <metadata name="saveFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>363, 17</value>
+  </metadata>
+  <metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>551, 17</value>
+  </metadata>
+  <metadata name="Timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>745, 17</value>
+  </metadata>
+  <metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>859, 17</value>
+  </metadata>
+  <metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>1017, 17</value>
+  </metadata>
+  <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+  <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+    <value>
+        AAABAAEAEBAAAAAAIACpAwAAFgAAAIlQTkcNChoKAAAADUlIRFIAAAAPAAAAEAgGAAAAyVYlBAAAA3BJ
+        REFUeJwt091rW2UAx/Hf8zznnLydk8R0W2j6YreFrm7aykA7xM2tbLjagfhynFU2RSxOqcMb2YTREtYL
+        laJ4JQh6obgLKzgqbDfVUdfpRtVaK9SlsWvaupC0yUlO0+Q0eZ7zeDG//8Dn6ksAENxLjo4OdniZ+ryE
+        fLK8UdkVMIIRVVM3VQXTmsczfuqV4c8IIWIYoAnAJcPDwzSRSLifjJ69SBh9R1WYbtsOVFWF5qEQdQHO
+        7wm1Wm3i3NsvmDTSUxwaGqI0kUi4H304+IVh+C9ASj2XKwnuum5A90jbKsMuVWRh3XaTf69yviWP9g+M
+        fCulbAMA8vEHg/2+gPdSpbJVJwTK4j93Sev9zVAowZUrP2M1k8XTfU8gczePcMTgl7+/phStck9pc/Ma
+        BcUbQghXVRm17QpxqnXYpU38MZNEMGTgeO8h6KEQclYJRsggL7/4lHvyuWMdAEBdiS7OXVq2q6yQK0Nl
+        GpLJO8itFdASi6Kwlselr8dxou8QpAv55VfjNLW0HAMAyigJ8rpAOrUGZ7MOURPIZi107d+D5tYdKKwX
+        ETQMbDkVMCpJW1sLwEm7lJJQzt2KlS+DUYbF9ArW1i1si0Sg6z7YxRL0gIHTr55AtCkKn5+S1waeQbRp
+        exchRCo1h087lfphCeFWnS02n1pC7+HHwOsCjlODbvigaBT+gI66A7JRLMjuA/saY40NjyiKRt/3+zxH
+        bi+kQSkFFxxT07Po39kLp8qhG34sp7JYTa9jfj5FvB5VUMqCG8XKKQIAFy8MfFrMl8+MjU+IUFBnc/N3
+        sLO1EQ937hEP7o1jcWGF/Tg1jVzekoRAKEwh4bDxCzFNk731zV7yw7vLlxeSK31/3U5haSUDwQVCIR2P
+        7t+HqZuzsEplMApIAK4LaCoDBYAjJMGlK9+s1bjj83pK4ZDuUErBuTs5O5e66jhb0FQmVUVZ01Rl1u/R
+        bnk09XP8PwbxejWcfLYn2747drP3aHfW69GceDweDIcMdD6wOxOLNrjvnT3dCQCMUgAANU2TApBD514/
+        Xq3W9KamaHckEtrBhVAs61/dKtok3t6ceagjThqbGo6dP//SfY8fPKgAYHRsbMwFgBu//nnr+k8zB3R/
+        YGR5KTMVNgLf5fPVEiEEu5pbJrZvi+R//y05MjeTPjM5OclN08R/s4eJCdHODUcAAAAASUVORK5CYII=
+</value>
+  </data>
+</root>

+ 69 - 0
crusherScanner/JsonHandler.cs

@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Text.Json;
+using System.Text.Json.Serialization.Metadata;
+
+namespace crusherScanner
+{
+    internal class JsonHandler
+    {
+        private string filePath;
+        private bool isSettingsFile;
+        public Settings settings;
+        public List<Logs>? log;
+
+        /// <summary>
+        /// Open or create a JSON file.
+        /// </summary>
+        /// <param name="filePath">Path to where the file is located or should be created.</param>
+        /// <param name="isSettingsfile">Is this a settings file? or a log file.</param>
+        public JsonHandler(string filePath,bool isSettingsfile)
+        {
+            this.filePath = filePath;
+            this.isSettingsFile = isSettingsfile;
+
+            if (isSettingsfile)
+            {
+                if (File.Exists(filePath))
+                {
+                    string fileData = File.ReadAllText(filePath);
+                    settings = JsonSerializer.Deserialize<Settings>(fileData);
+                }
+                else
+                {
+                    settings = new Settings();
+                }
+            }
+            else
+            {
+                if (File.Exists(filePath))
+                {
+                    string fileData = File.ReadAllText(filePath);
+                    log = JsonSerializer.Deserialize<List<Logs>>(fileData);
+                }
+                else
+                {
+                    log = new List<Logs>();
+                }
+            }
+        }
+
+        public void Save()
+        {
+            string fileData;
+            if (isSettingsFile)
+            {
+                fileData = JsonSerializer.Serialize(settings);
+            }
+            else
+            {
+                fileData = JsonSerializer.Serialize(log);
+            }
+            File.WriteAllText(filePath, fileData);
+        }
+
+    }
+}

+ 32 - 0
crusherScanner/LimsAccess.cs

@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace crusherScanner
+{
+    internal class LimsAccess
+    {
+        /// <summary>
+        ///  Check if barcode is found in LIMS samples.
+        /// </summary>
+        /// <param name="barcode">Barcode as string to check LIMS for.</param>
+        public static Scan IsInLims(Scan barcode)
+        {
+            //TODO: Actully check LIMS for sample ID.
+            barcode.isInLims = true;
+            return barcode;
+            //https://www.guru99.com/c-sharp-access-database.html#:~:text=Code%20Explanation%3A-%201%20The%20first%20step%20is%20to,connection%20to%20the%20database.%20...%20More%20items...%20
+            //string connetionString;
+            //SqlConnection cnn;
+            //connetionString = @"Data Source=WIN-50GP30FGO75;Initial Catalog=Demodb;User ID=sa;Password=demol23";
+            //cnn = new SqlConnection(connetionString);
+            //cnn.Open();
+            //MessageBox.Show("Connection Open  !");
+            //cnn.Close();
+            //or
+            //https://dax.tips/2020/08/24/using-visual-studio-code-to-query-power-bi/
+        }
+    }
+}

+ 43 - 0
crusherScanner/Logging.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace crusherScanner
+{
+    internal class Logging
+    {
+
+        private static readonly string LocalLogDir = Environment.SpecialFolder.LocalApplicationData.ToString() + "\\crusherScanner";
+
+        public void Append()
+        {
+
+        }
+
+        public void OpenInTextEditor()
+        {
+
+        }
+
+        public void OpenLogDirectory()
+        {
+            Process.Start(LocalLogDir);
+        }
+
+        public static void PurgeLogs()
+        {
+            DialogResult result = MessageBox.Show("Are you sure you want to delete ALL logs?","Purge Logs",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation);
+            if (result == DialogResult.Yes)
+            {
+                var logs = Directory.EnumerateFiles(LocalLogDir);
+                foreach (var log in logs)
+                {
+                    File.Delete(log);
+                }
+            }
+        }
+    }
+}

+ 76 - 0
crusherScanner/OreDefData.cs

@@ -0,0 +1,76 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace crusherScanner
+{
+    internal class OreDefData
+    {
+        private static HashSet<Samples> SampleDataCache = new();
+
+        /// <summary>
+        /// Check if this sample has a prefix that need checking.
+        /// </summary>
+        /// <param name="scanned">Scan object data.</param>
+        /// <returns>False on error. True on success.</returns>
+        public static Scan CheckSampleType(Scan scanned)
+        {
+            string[] OreDefTypesArray;
+            string OreDefTypes = Properties.Settings.Default.OreDefTypes;
+
+            if (OreDefTypes.Contains(','))
+            {
+                OreDefTypesArray = OreDefTypes.Split(',');
+                for (int i = 0; i < OreDefTypesArray.Length; i++)
+                {
+                    if (scanned.barcode.Contains(OreDefTypesArray[i]))
+                    {
+                        scanned.sampleType = OreDefTypesArray[i];
+                        return scanned;
+                    }
+                }
+            }
+            else
+            {
+                MessageBox.Show("OreDef prefix must be a comma seperated list.","Error");
+                scanned.sampleType = "Error!";
+            }
+            return scanned;
+        }
+
+        public static Scan CheckContaminates(Scan scanned)
+        {
+            scanned.sampleData = new();
+            
+            if (SampleDataCache.Count == 0)
+            {
+                SampleDataCache = FileAccess.GetOreDefData(SampleDataCache,scanned.barcode);
+            }
+            scanned.BufferCount = SampleDataCache.Count;
+            for (int i = 0; i < 2; i++)
+            {
+                foreach (var Sample in SampleDataCache)
+                {
+                    if (scanned.barcode == Sample.Sid)
+                    {
+                        scanned.sampleData = Sample;
+                        if (Sample.HammerOil || Sample.Manganese || Sample.Plastic || Sample.Pyrite)
+                        {
+                            scanned.Contaminated = true;
+                            return scanned;
+                        }
+                        return scanned;
+                    }
+                }
+                SampleDataCache = FileAccess.GetOreDefData(SampleDataCache,scanned.barcode);
+                scanned.BufferCount = SampleDataCache.Count;
+            }
+            scanned.SampleNotFound = true;
+            return scanned;
+        }
+
+
+    }
+}

+ 17 - 0
crusherScanner/Program.cs

@@ -0,0 +1,17 @@
+namespace crusherScanner
+{
+    internal static class Program
+    {
+        /// <summary>
+        ///  The main entry point for the application.
+        /// </summary>
+        [STAThread]
+        static void Main()
+        {
+            // To customize application configuration such as set high DPI settings or default font,
+            // see https://aka.ms/applicationconfiguration.
+            ApplicationConfiguration.Initialize();
+            Application.Run(new Form1());
+        }
+    }
+}

+ 150 - 0
crusherScanner/ProgramFunctions.cs

@@ -0,0 +1,150 @@
+using System;
+using System.Collections.Generic;
+using System.Data.SqlClient;
+using System.Linq;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+
+namespace crusherScanner
+{
+    public class ProgramFunctions
+    {
+        private static string lastBarcodeScanned = "";
+        public static bool ready = false;
+
+        #region Contructor
+
+        public ProgramFunctions()
+        {
+            Settings tmp = new();
+            tmp.CrusherNo = 1;
+            tmp.OreDefInFile = "te";
+            SettingsHandler.CheckSettings(tmp);
+            // no initial configuration present
+            if (Properties.Settings.Default.OreDefInFile == "")
+            {
+                if (File.Exists("config.json"))
+                {
+                    MessageBox.Show("No configuration stored,\nloading configuration from 'config.json'","Settings",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
+                    JsonHandler conf = new("config.json", true);
+                    //ImportConfigFile("config.json");
+                }
+                else
+                {
+                    MessageBox.Show("No configuration stored,\nYou will need to enter settings manually.\nThe settings will open now.", "Settings", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+                    SettingsDialog dlg = new();
+                    dlg.ShowDialog();
+                    dlg.Dispose();
+                }
+            }
+            //TODO check if settings are ok to use before setting ready.
+
+        }
+
+        #endregion
+
+        #region Main logic
+
+        public static Scan StartChecks(Scan scanned)
+        {
+            scanned.messageState = true;
+            scanned = LimsAccess.IsInLims(scanned);
+            if (!scanned.isInLims) // Check if this sample exists in LIMS
+            {
+                scanned.messageState = false;
+                scanned.message = $"Sample {scanned.barcode} does not seem to be in LIMS.";
+                return scanned;
+            }
+
+            scanned = OreDefData.CheckSampleType(scanned);
+            if (scanned.sampleType == "Error!") // Check if sample prefix needs checking
+            {
+                scanned.messageState = false;
+                scanned.message = "Unable to check sample due to a configuration issue.";
+                return scanned;
+            }
+
+            if(scanned.sampleType == null) //sample is NOT an OreDef sample
+            {
+                scanned.message = $"Sample {scanned.barcode} is not an OreDef sample.";
+                SerialAccess.SendToPrepmaster(scanned.barcode);
+                lastBarcodeScanned = scanned.barcode;
+                return scanned;
+            }
+
+            scanned = OreDefData.CheckContaminates(scanned);
+            if (!scanned.Contaminated && !scanned.SampleNotFound) // No contamnination and SID found
+            {
+                scanned.message = $"Sample {scanned.barcode} is good to go.";
+                SerialAccess.SendToPrepmaster(scanned.barcode);
+                lastBarcodeScanned = scanned.barcode;
+                return scanned;
+            }
+            else if (scanned.Contaminated && !scanned.SampleNotFound) // Contaminated sample found
+            {
+                scanned.message = "";
+                if (lastBarcodeScanned == scanned.barcode)
+                {
+                    SerialAccess.SendToPrepmaster(scanned.barcode);
+                }
+                lastBarcodeScanned = scanned.barcode;
+                return scanned;
+            }
+            else // Sample not found in job lists.
+            {
+                scanned.messageState = false;
+                scanned.message = $"Sample {scanned.barcode} is not found in job lists.";
+                return scanned;
+            }
+            
+            
+        }
+
+        #endregion
+
+        #region Settings functions
+
+        public static void ImportConfigFile(string configFile = "config.json")
+        {
+            string data = File.ReadAllText(configFile);
+            using JsonDocument doc = JsonDocument.Parse(data);
+            JsonElement root = doc.RootElement;
+
+            var config = root;
+
+            Properties.Settings.Default.CrusherNo = (int)config.GetProperty("CrusherNo").GetInt32();
+            Properties.Settings.Default.PrepmasterMagazineSerial = config.GetProperty("Serial").ToString();
+            Properties.Settings.Default.OreDefInFile = config.GetProperty("OreDefInFile").ToString();
+            Properties.Settings.Default.OreDefWorkFile = config.GetProperty("OreDefWorkFile").ToString();
+            Properties.Settings.Default.OreDefOutFile = config.GetProperty("OreDefOutFile").ToString();
+            Properties.Settings.Default.OutputFormat = config.GetProperty("OutputFormat").ToString();
+            Properties.Settings.Default.Save();
+        }
+
+        /// <summary>
+        ///  Export a Json configuration file.
+        /// </summary>
+        /// <param name="configFile">File path and file name to save the config file to.</param>
+        public static void ExportConfigFile(string configFile = "config.json")
+        {
+            using var ms = new MemoryStream();
+            using var writer = new Utf8JsonWriter(ms);
+
+            writer.WriteStartObject();
+            writer.WriteNumber("CrusherNo", Properties.Settings.Default.CrusherNo);
+            writer.WriteString("Serial", Properties.Settings.Default.PrepmasterMagazineSerial);
+            writer.WriteString("OreDefInFile", Properties.Settings.Default.OreDefInFile);
+            writer.WriteString("OreDefWorkFile", Properties.Settings.Default.OreDefWorkFile);
+            writer.WriteString("OreDefOutFile", Properties.Settings.Default.OreDefOutFile);
+            writer.WriteString("OutputFormat", Properties.Settings.Default.OutputFormat);
+            writer.WriteEndObject();
+            writer.Flush();
+            string json = Encoding.UTF8.GetString(ms.ToArray());
+            File.WriteAllText(configFile, json);
+        }
+
+        #endregion
+
+    }
+}

+ 146 - 0
crusherScanner/Properties/Settings.Designer.cs

@@ -0,0 +1,146 @@
+//------------------------------------------------------------------------------
+// <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 crusherScanner.Properties {
+    
+    
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.1.0.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("COM1,9600,Parity.None,8,StopBits.One")]
+        public string PrepmasterMagazineSerial {
+            get {
+                return ((string)(this["PrepmasterMagazineSerial"]));
+            }
+            set {
+                this["PrepmasterMagazineSerial"] = value;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
+        public string OreDefInFile {
+            get {
+                return ((string)(this["OreDefInFile"]));
+            }
+            set {
+                this["OreDefInFile"] = value;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
+        public string OreDefOutFile {
+            get {
+                return ((string)(this["OreDefOutFile"]));
+            }
+            set {
+                this["OreDefOutFile"] = value;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
+        public string OreDefWorkFile {
+            get {
+                return ((string)(this["OreDefWorkFile"]));
+            }
+            set {
+                this["OreDefWorkFile"] = value;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("1")]
+        public int CrusherNo {
+            get {
+                return ((int)(this["CrusherNo"]));
+            }
+            set {
+                this["CrusherNo"] = value;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("JSON")]
+        public string OutputFormat {
+            get {
+                return ((string)(this["OutputFormat"]));
+            }
+            set {
+                this["OutputFormat"] = value;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("RCA, RCB, RCC")]
+        public string OreDefTypes {
+            get {
+                return ((string)(this["OreDefTypes"]));
+            }
+            set {
+                this["OreDefTypes"] = value;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("False")]
+        public bool LimsConnection {
+            get {
+                return ((bool)(this["LimsConnection"]));
+            }
+            set {
+                this["LimsConnection"] = value;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
+        public string LimsConnString {
+            get {
+                return ((string)(this["LimsConnString"]));
+            }
+            set {
+                this["LimsConnString"] = value;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("False")]
+        public bool PrepmasterConnection {
+            get {
+                return ((bool)(this["PrepmasterConnection"]));
+            }
+            set {
+                this["PrepmasterConnection"] = value;
+            }
+        }
+    }
+}

+ 36 - 0
crusherScanner/Properties/Settings.settings

@@ -0,0 +1,36 @@
+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="crusherScanner.Properties" GeneratedClassName="Settings">
+  <Profiles />
+  <Settings>
+    <Setting Name="PrepmasterMagazineSerial" Type="System.String" Scope="User">
+      <Value Profile="(Default)">COM1,9600,Parity.None,8,StopBits.One</Value>
+    </Setting>
+    <Setting Name="OreDefInFile" Type="System.String" Scope="User">
+      <Value Profile="(Default)" />
+    </Setting>
+    <Setting Name="OreDefOutFile" Type="System.String" Scope="User">
+      <Value Profile="(Default)" />
+    </Setting>
+    <Setting Name="OreDefWorkFile" Type="System.String" Scope="User">
+      <Value Profile="(Default)" />
+    </Setting>
+    <Setting Name="CrusherNo" Type="System.Int32" Scope="User">
+      <Value Profile="(Default)">1</Value>
+    </Setting>
+    <Setting Name="OutputFormat" Type="System.String" Scope="User">
+      <Value Profile="(Default)">JSON</Value>
+    </Setting>
+    <Setting Name="OreDefTypes" Type="System.String" Scope="User">
+      <Value Profile="(Default)">RCA, RCB, RCC</Value>
+    </Setting>
+    <Setting Name="LimsConnection" Type="System.Boolean" Scope="User">
+      <Value Profile="(Default)">False</Value>
+    </Setting>
+    <Setting Name="LimsConnString" Type="System.String" Scope="User">
+      <Value Profile="(Default)" />
+    </Setting>
+    <Setting Name="PrepmasterConnection" Type="System.Boolean" Scope="User">
+      <Value Profile="(Default)">False</Value>
+    </Setting>
+  </Settings>
+</SettingsFile>

+ 7 - 0
crusherScanner/Properties/launchSettings.json

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

+ 24 - 0
crusherScanner/SerialAccess.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace crusherScanner
+{
+    internal class SerialAccess
+    {
+        //Serial stuff
+        //https://www.c-sharpcorner.com/UploadFile/eclipsed4utoo/communicating-with-serial-port-in-C-Sharp/
+
+        public static void SendToPrepmaster(string barcode)
+        {
+            if(barcode != "" || !Properties.Settings.Default.PrepmasterConnection)
+            {
+                MessageBox.Show($"The crusher flap would\nhave just opened to\naccept sample {barcode}","Crusher Input");
+            }
+            return;
+        }
+
+    }
+}

+ 28 - 0
crusherScanner/Settings.cs

@@ -0,0 +1,28 @@
+namespace crusherScanner.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.
+        }
+    }
+}

+ 271 - 0
crusherScanner/SettingsDialog.Designer.cs

@@ -0,0 +1,271 @@
+namespace crusherScanner
+{
+    partial class SettingsDialog
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SettingsDialog));
+            this.label1 = new System.Windows.Forms.Label();
+            this.label2 = new System.Windows.Forms.Label();
+            this.label3 = new System.Windows.Forms.Label();
+            this.label4 = new System.Windows.Forms.Label();
+            this.label5 = new System.Windows.Forms.Label();
+            this.label6 = new System.Windows.Forms.Label();
+            this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
+            this.textBox1 = new System.Windows.Forms.TextBox();
+            this.textBox2 = new System.Windows.Forms.TextBox();
+            this.textBox3 = new System.Windows.Forms.TextBox();
+            this.textBox4 = new System.Windows.Forms.TextBox();
+            this.comboBox1 = new System.Windows.Forms.ComboBox();
+            this.button1 = new System.Windows.Forms.Button();
+            this.button2 = new System.Windows.Forms.Button();
+            this.button3 = new System.Windows.Forms.Button();
+            this.button4 = new System.Windows.Forms.Button();
+            this.button5 = new System.Windows.Forms.Button();
+            this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
+            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
+            this.SuspendLayout();
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Location = new System.Drawing.Point(40, 50);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(142, 25);
+            this.label1.TabIndex = 0;
+            this.label1.Text = "Crusher Number";
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Location = new System.Drawing.Point(40, 100);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(116, 25);
+            this.label2.TabIndex = 1;
+            this.label2.Text = "Serial Output";
+            // 
+            // label3
+            // 
+            this.label3.AutoSize = true;
+            this.label3.Location = new System.Drawing.Point(40, 150);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(176, 25);
+            this.label3.TabIndex = 2;
+            this.label3.Text = "Ore Def Input Folder";
+            // 
+            // label4
+            // 
+            this.label4.AutoSize = true;
+            this.label4.Location = new System.Drawing.Point(40, 200);
+            this.label4.Name = "label4";
+            this.label4.Size = new System.Drawing.Size(201, 25);
+            this.label4.TabIndex = 3;
+            this.label4.Text = "Ore Def Working Folder";
+            // 
+            // label5
+            // 
+            this.label5.AutoSize = true;
+            this.label5.Location = new System.Drawing.Point(40, 250);
+            this.label5.Name = "label5";
+            this.label5.Size = new System.Drawing.Size(191, 25);
+            this.label5.TabIndex = 4;
+            this.label5.Text = "Ore Def Output Folder";
+            // 
+            // label6
+            // 
+            this.label6.AutoSize = true;
+            this.label6.Location = new System.Drawing.Point(40, 300);
+            this.label6.Name = "label6";
+            this.label6.Size = new System.Drawing.Size(131, 25);
+            this.label6.TabIndex = 5;
+            this.label6.Text = "Output Format";
+            // 
+            // numericUpDown1
+            // 
+            this.numericUpDown1.Location = new System.Drawing.Point(298, 48);
+            this.numericUpDown1.Maximum = new decimal(new int[] {
+            3,
+            0,
+            0,
+            0});
+            this.numericUpDown1.Minimum = new decimal(new int[] {
+            1,
+            0,
+            0,
+            0});
+            this.numericUpDown1.Name = "numericUpDown1";
+            this.numericUpDown1.Size = new System.Drawing.Size(239, 31);
+            this.numericUpDown1.TabIndex = 6;
+            this.numericUpDown1.Value = new decimal(new int[] {
+            1,
+            0,
+            0,
+            0});
+            // 
+            // textBox1
+            // 
+            this.textBox1.Location = new System.Drawing.Point(298, 97);
+            this.textBox1.Name = "textBox1";
+            this.textBox1.Size = new System.Drawing.Size(239, 31);
+            this.textBox1.TabIndex = 7;
+            // 
+            // textBox2
+            // 
+            this.textBox2.Location = new System.Drawing.Point(298, 147);
+            this.textBox2.Name = "textBox2";
+            this.textBox2.Size = new System.Drawing.Size(200, 31);
+            this.textBox2.TabIndex = 8;
+            // 
+            // textBox3
+            // 
+            this.textBox3.Location = new System.Drawing.Point(298, 197);
+            this.textBox3.Name = "textBox3";
+            this.textBox3.Size = new System.Drawing.Size(200, 31);
+            this.textBox3.TabIndex = 9;
+            // 
+            // textBox4
+            // 
+            this.textBox4.Location = new System.Drawing.Point(298, 247);
+            this.textBox4.Name = "textBox4";
+            this.textBox4.Size = new System.Drawing.Size(200, 31);
+            this.textBox4.TabIndex = 10;
+            // 
+            // comboBox1
+            // 
+            this.comboBox1.FormattingEnabled = true;
+            this.comboBox1.Items.AddRange(new object[] {
+            "JSON",
+            "CSV"});
+            this.comboBox1.Location = new System.Drawing.Point(298, 297);
+            this.comboBox1.Name = "comboBox1";
+            this.comboBox1.Size = new System.Drawing.Size(239, 33);
+            this.comboBox1.TabIndex = 11;
+            // 
+            // button1
+            // 
+            this.button1.Location = new System.Drawing.Point(502, 145);
+            this.button1.Name = "button1";
+            this.button1.Size = new System.Drawing.Size(35, 34);
+            this.button1.TabIndex = 12;
+            this.button1.Text = "...";
+            this.button1.UseVisualStyleBackColor = true;
+            this.button1.Click += new System.EventHandler(this.button1_Click);
+            // 
+            // button2
+            // 
+            this.button2.Location = new System.Drawing.Point(502, 195);
+            this.button2.Name = "button2";
+            this.button2.Size = new System.Drawing.Size(35, 34);
+            this.button2.TabIndex = 13;
+            this.button2.Text = "...";
+            this.button2.UseVisualStyleBackColor = true;
+            this.button2.Click += new System.EventHandler(this.button2_Click);
+            // 
+            // button3
+            // 
+            this.button3.Location = new System.Drawing.Point(502, 245);
+            this.button3.Name = "button3";
+            this.button3.Size = new System.Drawing.Size(35, 34);
+            this.button3.TabIndex = 14;
+            this.button3.Text = "...";
+            this.button3.UseVisualStyleBackColor = true;
+            this.button3.Click += new System.EventHandler(this.button3_Click);
+            // 
+            // button4
+            // 
+            this.button4.Location = new System.Drawing.Point(40, 355);
+            this.button4.Name = "button4";
+            this.button4.Size = new System.Drawing.Size(160, 34);
+            this.button4.TabIndex = 15;
+            this.button4.Text = "Discard && Exit";
+            this.button4.UseVisualStyleBackColor = true;
+            this.button4.Click += new System.EventHandler(this.button4_Click);
+            // 
+            // button5
+            // 
+            this.button5.Location = new System.Drawing.Point(377, 355);
+            this.button5.Name = "button5";
+            this.button5.Size = new System.Drawing.Size(160, 34);
+            this.button5.TabIndex = 16;
+            this.button5.Text = "Save && Exit";
+            this.button5.UseVisualStyleBackColor = true;
+            this.button5.Click += new System.EventHandler(this.button5_Click);
+            // 
+            // SettingsDialog
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(559, 403);
+            this.Controls.Add(this.button5);
+            this.Controls.Add(this.button4);
+            this.Controls.Add(this.button3);
+            this.Controls.Add(this.button2);
+            this.Controls.Add(this.button1);
+            this.Controls.Add(this.comboBox1);
+            this.Controls.Add(this.textBox4);
+            this.Controls.Add(this.textBox3);
+            this.Controls.Add(this.textBox2);
+            this.Controls.Add(this.textBox1);
+            this.Controls.Add(this.numericUpDown1);
+            this.Controls.Add(this.label6);
+            this.Controls.Add(this.label5);
+            this.Controls.Add(this.label4);
+            this.Controls.Add(this.label3);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.label1);
+            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
+            this.Name = "SettingsDialog";
+            this.Text = "SettingsDialog";
+            this.Load += new System.EventHandler(this.SettingsDialog_Load);
+            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private Label label1;
+        private Label label2;
+        private Label label3;
+        private Label label4;
+        private Label label5;
+        private Label label6;
+        private NumericUpDown numericUpDown1;
+        private TextBox textBox1;
+        private TextBox textBox2;
+        private TextBox textBox3;
+        private TextBox textBox4;
+        private ComboBox comboBox1;
+        private Button button1;
+        private Button button2;
+        private Button button3;
+        private Button button4;
+        private Button button5;
+        private FolderBrowserDialog folderBrowserDialog1;
+    }
+}

+ 111 - 0
crusherScanner/SettingsDialog.cs

@@ -0,0 +1,111 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace crusherScanner
+{
+    public partial class SettingsDialog : Form
+    {
+        public SettingsDialog()
+        {
+            InitializeComponent();
+        }
+
+        /// <summary>
+        ///  Save and Exit.
+        /// </summary>
+        private void button5_Click(object sender, EventArgs e)
+        {
+            Properties.Settings.Default.CrusherNo = (int)numericUpDown1.Value;
+            Properties.Settings.Default.PrepmasterMagazineSerial = textBox1.Text;
+            Properties.Settings.Default.OreDefInFile = textBox2.Text;
+            Properties.Settings.Default.OreDefWorkFile = textBox3.Text;
+            Properties.Settings.Default.OreDefOutFile = textBox4.Text;
+            Properties.Settings.Default.OutputFormat = comboBox1.Text;
+            Properties.Settings.Default.Save();
+            Close();
+        }
+
+        private void SettingsDialog_Load(object sender, EventArgs e)
+        {
+            numericUpDown1.Value = Properties.Settings.Default.CrusherNo;
+            textBox1.Text = Properties.Settings.Default.PrepmasterMagazineSerial;
+            textBox2.Text = Properties.Settings.Default.OreDefInFile;
+            textBox3.Text = Properties.Settings.Default.OreDefWorkFile;
+            textBox4.Text = Properties.Settings.Default.OreDefOutFile;
+            comboBox1.Text = Properties.Settings.Default.OutputFormat;
+        }
+
+        /// <summary>
+        ///  Discard and exit.
+        /// </summary>
+        private void button4_Click(object sender, EventArgs e)
+        {
+            this.Close();
+        }
+
+        /// <summary>
+        ///  OreDef input file dir.
+        /// </summary>
+        private void button1_Click(object sender, EventArgs e)
+        {
+            string returnPath = FolderBrowser(textBox2.Text);
+            if (returnPath != "")
+            {
+                textBox2.Text = returnPath;
+            }
+        }
+
+        /// <summary>
+        ///  OreDef working file dir.
+        /// </summary>
+        private void button2_Click(object sender, EventArgs e)
+        {
+            string returnPath = FolderBrowser(textBox3.Text);
+            if (returnPath != "")
+            {
+                textBox3.Text = returnPath;
+            }
+        }
+
+        /// <summary>
+        ///  OreDef output file dir.
+        /// </summary>
+        private void button3_Click(object sender, EventArgs e)
+        {
+            string returnPath = FolderBrowser(textBox4.Text);
+            if (returnPath != "")
+            {
+                textBox4.Text = returnPath;
+            }
+        }
+
+        /// <summary>
+        ///  Dynamic folder dialog.
+        /// </summary>
+        private string FolderBrowser(string path)
+        {
+            folderBrowserDialog1.Reset();
+            if (path != "")
+            {
+                //folderBrowserDialog1.InitialDirectory = path;
+                folderBrowserDialog1.SelectedPath = path;
+            }
+            DialogResult result = folderBrowserDialog1.ShowDialog();
+            if (result == DialogResult.OK)
+            {
+                return folderBrowserDialog1.SelectedPath;
+            }
+            else
+            {
+                return "";
+            }
+        }
+    }
+}

+ 84 - 0
crusherScanner/SettingsDialog.resx

@@ -0,0 +1,84 @@
+<root>
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+  <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+  <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+    <value>
+        AAABAAEAEBAAAAAAIACpAwAAFgAAAIlQTkcNChoKAAAADUlIRFIAAAAPAAAAEAgGAAAAyVYlBAAAA3BJ
+        REFUeJwt091rW2UAx/Hf8zznnLydk8R0W2j6YreFrm7aykA7xM2tbLjagfhynFU2RSxOqcMb2YTREtYL
+        laJ4JQh6obgLKzgqbDfVUdfpRtVaK9SlsWvaupC0yUlO0+Q0eZ7zeDG//8Dn6ksAENxLjo4OdniZ+ryE
+        fLK8UdkVMIIRVVM3VQXTmsczfuqV4c8IIWIYoAnAJcPDwzSRSLifjJ69SBh9R1WYbtsOVFWF5qEQdQHO
+        7wm1Wm3i3NsvmDTSUxwaGqI0kUi4H304+IVh+C9ASj2XKwnuum5A90jbKsMuVWRh3XaTf69yviWP9g+M
+        fCulbAMA8vEHg/2+gPdSpbJVJwTK4j93Sev9zVAowZUrP2M1k8XTfU8gczePcMTgl7+/phStck9pc/Ma
+        BcUbQghXVRm17QpxqnXYpU38MZNEMGTgeO8h6KEQclYJRsggL7/4lHvyuWMdAEBdiS7OXVq2q6yQK0Nl
+        GpLJO8itFdASi6Kwlselr8dxou8QpAv55VfjNLW0HAMAyigJ8rpAOrUGZ7MOURPIZi107d+D5tYdKKwX
+        ETQMbDkVMCpJW1sLwEm7lJJQzt2KlS+DUYbF9ArW1i1si0Sg6z7YxRL0gIHTr55AtCkKn5+S1waeQbRp
+        exchRCo1h087lfphCeFWnS02n1pC7+HHwOsCjlODbvigaBT+gI66A7JRLMjuA/saY40NjyiKRt/3+zxH
+        bi+kQSkFFxxT07Po39kLp8qhG34sp7JYTa9jfj5FvB5VUMqCG8XKKQIAFy8MfFrMl8+MjU+IUFBnc/N3
+        sLO1EQ937hEP7o1jcWGF/Tg1jVzekoRAKEwh4bDxCzFNk731zV7yw7vLlxeSK31/3U5haSUDwQVCIR2P
+        7t+HqZuzsEplMApIAK4LaCoDBYAjJMGlK9+s1bjj83pK4ZDuUErBuTs5O5e66jhb0FQmVUVZ01Rl1u/R
+        bnk09XP8PwbxejWcfLYn2747drP3aHfW69GceDweDIcMdD6wOxOLNrjvnT3dCQCMUgAANU2TApBD514/
+        Xq3W9KamaHckEtrBhVAs61/dKtok3t6ceagjThqbGo6dP//SfY8fPKgAYHRsbMwFgBu//nnr+k8zB3R/
+        YGR5KTMVNgLf5fPVEiEEu5pbJrZvi+R//y05MjeTPjM5OclN08R/s4eJCdHODUcAAAAASUVORK5CYII=
+</value>
+  </data>
+</root>

+ 199 - 0
crusherScanner/SettingsHandler.cs

@@ -0,0 +1,199 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.IO.Ports;
+
+namespace crusherScanner
+{
+    internal class SettingsHandler
+    {
+        public void PutSettingsInternal(Settings settings)
+        {
+
+        }
+
+        public Settings GetSettingsInternal()
+        {
+            //TODO: Fix this
+            return new Settings();
+        }
+
+        /// <summary>
+        /// Check the settings given are sane.
+        /// </summary>
+        /// <param name="settings">Settings to check.</param>
+        /// <returns>True for sane, false if not.</returns>
+        public static bool CheckSettings(Settings settings)
+        {
+            bool settingsCheckPassed = true;
+            string replyMessage = "";
+
+
+            if (settings.CrusherNo == 0)
+            {
+                replyMessage += "Crusher No must be a value between 1 and 3.\n";
+                settingsCheckPassed = false;
+            }
+
+            if (settings.PrepmasterConnection)
+            {
+                if (settings.PrepmasterMagazineSerial == "" || settings.PrepmasterMagazineSerial == null)
+                {
+                    replyMessage += "Prepmaster Magazine Serial details are blank, Please enter valid serial details or set Prepmaster Connection to false.\n";
+                    settingsCheckPassed = false;
+                }
+                else
+                {
+                    //TODO check serial connection details.
+                    CheckSerial(settings.PrepmasterMagazineSerial);
+                }
+            }
+            else
+            {
+                replyMessage += "Prepmaster Connection is set to false, SID's will not be sent to the crusher input.\n";
+            }
+
+            if (settings.LimsConnection)
+            {
+                if (settings.LimsConnString == "" || settings.LimsConnString == null)
+                {
+                    replyMessage += "LIMS connection details are blank, Please enter valid database connection details or set LIMS Connection to false.\n";
+                    settingsCheckPassed = false;
+                }
+                else
+                {
+                    //TODO check LIMS connection details.
+                }
+            }
+            else
+            {
+                replyMessage += "LIMS Connection is set to false, SID's will not be checked if they have been registered in LIMS.\n";
+            }
+
+            if (settings.OreDefInFile == "" || settings.OreDefInFile == null)
+            {
+                replyMessage += "Ore Def input folder is not set, Please select a directory where the Ore Def input files can be found.\n";
+                settingsCheckPassed = false;
+            }
+            else
+            {
+                if(settings.OreDefInFile == settings.OreDefWorkFile)
+                {
+                    replyMessage += "Ore Def input folder and Ore Def working folder cannot be the same directory.\n";
+                    settingsCheckPassed = false;
+                }
+                if (settings.OreDefInFile == settings.OreDefOutFile)
+                {
+                    replyMessage += "Ore Def input folder and Ore Def output folder cannot be the same directory.\n";
+                    settingsCheckPassed = false;
+                }
+                if (!Directory.Exists(settings.OreDefInFile))
+                {
+                    replyMessage += $"Ore Def input folder is not accessable ({settings.OreDefInFile}).\n";
+                    settingsCheckPassed = false;
+                }
+            }
+
+            if (settings.OreDefWorkFile == "" || settings.OreDefWorkFile == null)
+            {
+                replyMessage += "Ore Def working folder is not set, Please select a directory where the Ore Def working files can be stored\\shared.\n";
+                settingsCheckPassed = false;
+            }
+            else
+            {
+                if (settings.OreDefWorkFile == settings.OreDefOutFile)
+                {
+                    replyMessage += "Ore Def working folder and Ore Def output folder cannot be the same directory.\n";
+                    settingsCheckPassed = false;
+                }
+                if (!Directory.Exists(settings.OreDefWorkFile))
+                {
+                    replyMessage += $"Ore Def working folder is not accessable ({settings.OreDefWorkFile}).\n";
+                    settingsCheckPassed = false;
+                }
+            }
+
+            if (settings.OreDefOutFile == "" || settings.OreDefOutFile == null)
+            {
+                replyMessage += "Ore Def output folder is not set, Please select a directory where the Ore Def output files can be stored.\n";
+                settingsCheckPassed = false;
+            }
+            else
+            {
+                if (!Directory.Exists(settings.OreDefOutFile))
+                {
+                    replyMessage += $"Ore Def output folder is not accessable ({settings.OreDefOutFile}).\n";
+                    settingsCheckPassed = false;
+                }
+            }
+            
+            if (settings.OreDefTypes == "" || settings.OreDefTypes == null)
+            {
+                replyMessage += "Ore Def barcode prefix's are not set, Please enter a barcode prefix for Ore Def samples (comma delimited for multiples).\n";
+                settingsCheckPassed = false;
+            }
+            
+            if (settings.OutputFormat == "" || settings.OutputFormat == null)
+            {
+                replyMessage += "Ore Def output format not set, Please enter a format for Ore Def output files (default is CSV).\n";
+                settingsCheckPassed = false;
+            }
+
+            if (settingsCheckPassed)
+            {
+                MessageBox.Show(replyMessage,"Settings check",MessageBoxButtons.OK,MessageBoxIcon.Information);
+            }
+            else
+            {
+                MessageBox.Show(replyMessage, "Settings check", MessageBoxButtons.OK, MessageBoxIcon.Error);
+            }
+            return settingsCheckPassed;
+        }
+
+        private static (bool,string) CheckSerial(string serialSetup)
+        {
+            string[] comPorts = { "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM10", "COM11", "COM12", "COM13", "COM14", "COM15", "COM16" };
+            string[] BaudRate = { "300", "600", "1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200", "230400", "460800", "921600"};
+            string[] Parity = { "Parity.None", "Parity.Odd", "Parity.Even", "Parity.Mark", "Parity.Space" };
+            string[] DataBits = { "5", "6", "7", "8" };
+            string[] StopBits = { "StopBits.None", "StopBits.One", "StopBits.Two", "StopBits.OnePointFive" };
+            
+            //COM1,9600,Parity.None,8,StopBits.One
+            if (serialSetup.Contains(','))
+            {
+                string[] serialConfig = serialSetup.Split(',');
+
+                if (serialConfig.Length>4)
+                {
+                    return (Validate(serialConfig[4], StopBits), "");
+                }
+
+                return (Validate(serialSetup, comPorts), "");
+            }
+            else
+            {
+                return (Validate(serialSetup,comPorts),"");
+            }
+        }
+
+        private static bool Validate(string value, string[] acceptable)
+        {
+            foreach (var item in acceptable)
+            {
+                if(value == item)
+                {
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        private static void CheckLims(string limsSetup)
+        {
+
+        }
+
+    }
+}

+ 128 - 0
crusherScanner/WorkingDirControl.cs

@@ -0,0 +1,128 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace crusherScanner
+{
+    internal class WorkingDirControl
+    {
+        /// <summary>
+        /// Update sample as scanned in the working directory.
+        /// </summary>
+        /// <param name="scanData">Sample data containing Job and Barcode.</param>
+        public static void UpdateWorkingDir(System.ComponentModel.DoWorkEventArgs e)
+        {
+            if (e.Argument == null)
+            {
+                return;
+            }
+            Scan scanData = (Scan)e.Argument;
+            string[] DataDirs = new string[2] { Properties.Settings.Default.OreDefWorkFile, Properties.Settings.Default.OreDefInFile };
+            string? JobFile = GetJobFilePath(scanData, DataDirs);
+            if (JobFile != null)
+            {
+                if (JobFile.Contains(DataDirs[0]))
+                {
+                    scanData = updateSampleInJobFile(scanData, JobFile);
+                }
+                else
+                {
+                    try
+                    {
+                        File.Move($"{DataDirs[1]}\\{scanData.sampleData.Job}.csv", $"{DataDirs[0]}\\{scanData.sampleData.Job}.csv");
+                        scanData = updateSampleInJobFile(scanData, $"{DataDirs[0]}\\{scanData.sampleData.Job}.csv");
+                    }
+                    catch (Exception)
+                    {
+                        
+                    }
+                }
+                e.Result = scanData;
+            }
+            else
+            {
+                e.Result = scanData; // This shouldn't happen.
+            }
+        }
+
+        /// <summary>
+        /// Is the currently scanned sample's job in the working directory.
+        /// </summary>
+        /// <param name="scanData">Sample data containing Job and Barcode.</param>
+        private static string? GetJobFilePath(Scan scanData,string[] DataDirs)
+        {
+            try
+            {
+                foreach (var DataDir in DataDirs)
+                {
+                    if (Directory.Exists(DataDir))
+                    {
+                        var jobFiles = Directory.EnumerateFiles(DataDir, "ML??????.csv", SearchOption.TopDirectoryOnly);
+                        foreach (var jobFile in jobFiles)
+                        {
+                            if (jobFile.Contains(scanData.sampleData.Job))
+                            {
+                                return jobFile;
+                            }
+                        }
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show("An error occurred." + Environment.NewLine + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+            }
+            return null;
+        }
+
+        private static Scan updateSampleInJobFile(Scan scanData, string DataFile)
+        {
+            List<string> fileLines = new();
+            using FileStream OreDefWorkingFile = new(DataFile, FileMode.Open, System.IO.FileAccess.ReadWrite, FileShare.None);
+            {
+                using StreamReader Reader = new(OreDefWorkingFile);
+                {
+                    var line = Reader.ReadLine();
+                    while (line != null)
+                    {                       
+                        if (line != null && line.Contains('\u002C'))
+                        {
+                            scanData.JobTotal++;
+                            string[] CSV = line.Split('\u002C');
+                            if(CSV[0] == scanData.sampleData.Sid)
+                            {
+                                CSV[8] = scanData.sampleData.Sid;
+                                fileLines.Add(string.Join('\u002C', CSV));
+                            }
+                            else
+                            {
+                                fileLines.Add(line);
+                            }
+                            if(CSV[8] != "")
+                            {
+                                scanData.JobCount++;
+                            }
+                        }
+                        line = Reader.ReadLine();
+                    }
+                }
+                
+                OreDefWorkingFile.Position = 0;
+                using StreamWriter writer = new(OreDefWorkingFile);
+                {
+                    foreach (var line in fileLines)
+                    {
+                        writer.WriteLine(line);
+                    }
+                }
+                writer.Close();
+            }
+            scanData.JobCount--; // Compensate for the file header
+            scanData.JobTotal--; // Compensate for the file header
+            return scanData;
+        }
+
+    }
+}

+ 47 - 0
crusherScanner/crusherScanner.csproj

@@ -0,0 +1,47 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>WinExe</OutputType>
+    <TargetFramework>net6.0-windows</TargetFramework>
+    <Nullable>enable</Nullable>
+    <UseWindowsForms>true</UseWindowsForms>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <SignAssembly>False</SignAssembly>
+    <ApplicationIcon>0d28e7dc-5024-45b7-81f8-bb1c48fe484d.ico</ApplicationIcon>
+  </PropertyGroup>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+    <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
+    <NoWarn>1701;1702</NoWarn>
+  </PropertyGroup>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
+    <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
+    <NoWarn>1701;1702</NoWarn>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <Content Include="0d28e7dc-5024-45b7-81f8-bb1c48fe484d.ico" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
+    <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>