| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- 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();
- }
- }
- }
- }
|