diff --git a/.gitignore b/.gitignore index 380d1fc..5b198ec 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ BarcodeSimulator/bin BarcodeSimulator/obj BarcodeSimulator.Tests/bin BarcodeSimulator.Tests/obj +/.vs/BarcodeSimulator +/.vs diff --git a/BarcodeSimulator.Tests/BarcodeSimulator.Tests.csproj b/BarcodeSimulator.Tests/BarcodeSimulator.Tests.csproj index 9da00fe..119cb04 100644 --- a/BarcodeSimulator.Tests/BarcodeSimulator.Tests.csproj +++ b/BarcodeSimulator.Tests/BarcodeSimulator.Tests.csproj @@ -1,110 +1,17 @@ - - + + - Debug - AnyCPU - - - 2.0 - {7513FB40-6034-4002-B434-603E57CDCF44} - Library - Properties - BarcodeSimulator.Tests - BarcodeSimulator.Tests - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + net48 + false + true - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - x64 - prompt - true - true - - - bin\x64\Release\ - TRACE - true - pdbonly - x64 - prompt - true - true - - - true - bin\x86\Debug\ - DEBUG;TRACE - full - x86 - prompt - true - true - - - bin\x86\Release\ - TRACE - true - pdbonly - x86 - prompt - true - true - - - - ..\packages\NUnit.2.6.0.12054\lib\nunit.framework.dll - - - - 3.5 - - - - - False - - - - - - + - + + - - {CF8A1048-009D-4892-9BDC-94864C2A4D57} - BarcodeSimulator - + - - + \ No newline at end of file diff --git a/BarcodeSimulator.Tests/packages.config b/BarcodeSimulator.Tests/packages.config index eec7bad..70abd2f 100644 --- a/BarcodeSimulator.Tests/packages.config +++ b/BarcodeSimulator.Tests/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/BarcodeSimulator.sln b/BarcodeSimulator.sln index 3e3b429..a260fa8 100644 --- a/BarcodeSimulator.sln +++ b/BarcodeSimulator.sln @@ -8,32 +8,17 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 - Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CF8A1048-009D-4892-9BDC-94864C2A4D57}.Debug|Any CPU.ActiveCfg = Debug|x86 - {CF8A1048-009D-4892-9BDC-94864C2A4D57}.Debug|Any CPU.Build.0 = Debug|x86 - {CF8A1048-009D-4892-9BDC-94864C2A4D57}.Debug|x64.ActiveCfg = Debug|x64 - {CF8A1048-009D-4892-9BDC-94864C2A4D57}.Debug|x86.ActiveCfg = Debug|x86 - {CF8A1048-009D-4892-9BDC-94864C2A4D57}.Release|Any CPU.ActiveCfg = Release|x86 - {CF8A1048-009D-4892-9BDC-94864C2A4D57}.Release|Any CPU.Build.0 = Release|x86 - {CF8A1048-009D-4892-9BDC-94864C2A4D57}.Release|x64.ActiveCfg = Release|x64 - {CF8A1048-009D-4892-9BDC-94864C2A4D57}.Release|x86.ActiveCfg = Release|x86 + {CF8A1048-009D-4892-9BDC-94864C2A4D57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CF8A1048-009D-4892-9BDC-94864C2A4D57}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CF8A1048-009D-4892-9BDC-94864C2A4D57}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CF8A1048-009D-4892-9BDC-94864C2A4D57}.Release|Any CPU.Build.0 = Release|Any CPU {7513FB40-6034-4002-B434-603E57CDCF44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7513FB40-6034-4002-B434-603E57CDCF44}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7513FB40-6034-4002-B434-603E57CDCF44}.Debug|x64.ActiveCfg = Debug|x64 - {7513FB40-6034-4002-B434-603E57CDCF44}.Debug|x64.Build.0 = Debug|x64 - {7513FB40-6034-4002-B434-603E57CDCF44}.Debug|x86.ActiveCfg = Debug|x86 - {7513FB40-6034-4002-B434-603E57CDCF44}.Debug|x86.Build.0 = Debug|x86 {7513FB40-6034-4002-B434-603E57CDCF44}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7513FB40-6034-4002-B434-603E57CDCF44}.Release|x64.ActiveCfg = Release|x64 - {7513FB40-6034-4002-B434-603E57CDCF44}.Release|x64.Build.0 = Release|x64 - {7513FB40-6034-4002-B434-603E57CDCF44}.Release|x86.ActiveCfg = Release|x86 - {7513FB40-6034-4002-B434-603E57CDCF44}.Release|x86.Build.0 = Release|x86 + {7513FB40-6034-4002-B434-603E57CDCF44}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BarcodeSimulator/BarcodeSimulator.csproj b/BarcodeSimulator/BarcodeSimulator.csproj index 674e973..93272ed 100644 --- a/BarcodeSimulator/BarcodeSimulator.csproj +++ b/BarcodeSimulator/BarcodeSimulator.csproj @@ -1,103 +1,16 @@ - - + + - Debug - x86 - 8.0.30703 - 2.0 - {CF8A1048-009D-4892-9BDC-94864C2A4D57} WinExe - Properties - BarcodeSimulator - BarcodeSimulator - v4.0 - Client - 512 - - - x86 - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - x86 - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - + net48 + true + false + true Barcode-Scanner.ico - - BarcodeSimulator.Program - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - x64 - prompt - false - false - - - bin\x64\Release\ - TRACE - true - pdbonly - x64 - prompt - false - false - + - - - - - - + - - - - Form - - - BarcodeSimulatorControl.cs - - - - - - BarcodeSimulatorControl.cs - - - - - - - - IF $(ConfigurationName) == Debug rake bump:build - - - - - - + \ No newline at end of file diff --git a/BarcodeSimulator/BarcodeSimulatorControl.Designer.cs b/BarcodeSimulator/BarcodeSimulatorControl.Designer.cs index 27a2687..e65428a 100644 --- a/BarcodeSimulator/BarcodeSimulatorControl.Designer.cs +++ b/BarcodeSimulator/BarcodeSimulatorControl.Designer.cs @@ -36,6 +36,10 @@ private void InitializeComponent() { this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.itemsGroupBox = new System.Windows.Forms.GroupBox(); + this.label5 = new System.Windows.Forms.Label(); + this.RandomLengthTextBox = new System.Windows.Forms.TextBox(); + this.AddRandomButton = new System.Windows.Forms.Button(); + this.ClearButton = new System.Windows.Forms.Button(); this.newCodeTypeLabel = new System.Windows.Forms.Label(); this.configurationGroupBox = new System.Windows.Forms.GroupBox(); ((System.ComponentModel.ISupportInitialize)(this.delayNumeric)).BeginInit(); @@ -50,32 +54,24 @@ private void InitializeComponent() { 0, 0, 0}); - this.delayNumeric.Location = new System.Drawing.Point(79, 27); + this.delayNumeric.Location = new System.Drawing.Point(105, 33); + this.delayNumeric.Margin = new System.Windows.Forms.Padding(4); this.delayNumeric.Maximum = new decimal(new int[] { 1000, 0, 0, 0}); - this.delayNumeric.Minimum = new decimal(new int[] { - 50, - 0, - 0, - 0}); this.delayNumeric.Name = "delayNumeric"; - this.delayNumeric.Size = new System.Drawing.Size(120, 20); + this.delayNumeric.Size = new System.Drawing.Size(160, 22); this.delayNumeric.TabIndex = 1; - this.delayNumeric.Value = new decimal(new int[] { - 50, - 0, - 0, - 0}); // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(6, 29); + this.label1.Location = new System.Drawing.Point(8, 36); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(55, 13); + this.label1.Size = new System.Drawing.Size(69, 16); this.label1.TabIndex = 1; this.label1.Text = "Key Delay"; // @@ -83,10 +79,11 @@ private void InitializeComponent() { // this.newStringTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.newStringTextBox.Location = new System.Drawing.Point(9, 43); + this.newStringTextBox.Location = new System.Drawing.Point(12, 53); + this.newStringTextBox.Margin = new System.Windows.Forms.Padding(4); this.newStringTextBox.MaxLength = 50; this.newStringTextBox.Name = "newStringTextBox"; - this.newStringTextBox.Size = new System.Drawing.Size(162, 20); + this.newStringTextBox.Size = new System.Drawing.Size(329, 22); this.newStringTextBox.TabIndex = 3; this.newStringTextBox.TextChanged += new System.EventHandler(this.newStringTextBox_TextChanged); this.newStringTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.newStringTextBox_KeyDown); @@ -94,36 +91,40 @@ private void InitializeComponent() { // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(6, 56); + this.label2.Location = new System.Drawing.Point(8, 69); + this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(41, 13); + this.label2.Size = new System.Drawing.Size(50, 16); this.label2.TabIndex = 4; this.label2.Text = "Hotkey"; // // hotkeyTextBox // - this.hotkeyTextBox.Location = new System.Drawing.Point(79, 53); + this.hotkeyTextBox.Location = new System.Drawing.Point(105, 65); + this.hotkeyTextBox.Margin = new System.Windows.Forms.Padding(4); this.hotkeyTextBox.Name = "hotkeyTextBox"; this.hotkeyTextBox.ReadOnly = true; - this.hotkeyTextBox.Size = new System.Drawing.Size(120, 20); + this.hotkeyTextBox.Size = new System.Drawing.Size(159, 22); this.hotkeyTextBox.TabIndex = 5; this.hotkeyTextBox.TabStop = false; // // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(6, 27); + this.label3.Location = new System.Drawing.Point(8, 33); + this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(54, 13); + this.label3.Size = new System.Drawing.Size(68, 16); this.label3.TabIndex = 11; this.label3.Text = "Add Code"; // // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(6, 82); + this.label4.Location = new System.Drawing.Point(8, 101); + this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(51, 13); + this.label4.Size = new System.Drawing.Size(60, 16); this.label4.TabIndex = 12; this.label4.Text = "End With"; // @@ -131,9 +132,10 @@ private void InitializeComponent() { // this.endsWithComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.endsWithComboBox.FormattingEnabled = true; - this.endsWithComboBox.Location = new System.Drawing.Point(78, 79); + this.endsWithComboBox.Location = new System.Drawing.Point(104, 97); + this.endsWithComboBox.Margin = new System.Windows.Forms.Padding(4); this.endsWithComboBox.Name = "endsWithComboBox"; - this.endsWithComboBox.Size = new System.Drawing.Size(121, 21); + this.endsWithComboBox.Size = new System.Drawing.Size(160, 24); this.endsWithComboBox.TabIndex = 2; // // itemsListView @@ -146,11 +148,13 @@ private void InitializeComponent() { this.columnHeader1, this.columnHeader2}); this.itemsListView.FullRowSelect = true; + this.itemsListView.HideSelection = false; this.itemsListView.HoverSelection = true; - this.itemsListView.Location = new System.Drawing.Point(9, 69); + this.itemsListView.Location = new System.Drawing.Point(12, 85); + this.itemsListView.Margin = new System.Windows.Forms.Padding(4); this.itemsListView.MultiSelect = false; this.itemsListView.Name = "itemsListView"; - this.itemsListView.Size = new System.Drawing.Size(231, 179); + this.itemsListView.Size = new System.Drawing.Size(421, 240); this.itemsListView.TabIndex = 13; this.itemsListView.UseCompatibleStateImageBehavior = false; this.itemsListView.View = System.Windows.Forms.View.Details; @@ -171,23 +175,71 @@ private void InitializeComponent() { this.itemsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.itemsGroupBox.Controls.Add(this.label5); + this.itemsGroupBox.Controls.Add(this.RandomLengthTextBox); + this.itemsGroupBox.Controls.Add(this.AddRandomButton); + this.itemsGroupBox.Controls.Add(this.ClearButton); this.itemsGroupBox.Controls.Add(this.newCodeTypeLabel); this.itemsGroupBox.Controls.Add(this.itemsListView); this.itemsGroupBox.Controls.Add(this.label3); this.itemsGroupBox.Controls.Add(this.newStringTextBox); - this.itemsGroupBox.Location = new System.Drawing.Point(12, 136); + this.itemsGroupBox.Location = new System.Drawing.Point(16, 167); + this.itemsGroupBox.Margin = new System.Windows.Forms.Padding(4); this.itemsGroupBox.Name = "itemsGroupBox"; - this.itemsGroupBox.Size = new System.Drawing.Size(254, 264); + this.itemsGroupBox.Padding = new System.Windows.Forms.Padding(4); + this.itemsGroupBox.Size = new System.Drawing.Size(453, 396); this.itemsGroupBox.TabIndex = 14; this.itemsGroupBox.TabStop = false; this.itemsGroupBox.Text = "Barcodes"; // + // label5 + // + this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(222, 344); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(98, 16); + this.label5.TabIndex = 18; + this.label5.Text = "Random length"; + // + // RandomLengthTextBox + // + this.RandomLengthTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.RandomLengthTextBox.Location = new System.Drawing.Point(222, 366); + this.RandomLengthTextBox.Name = "RandomLengthTextBox"; + this.RandomLengthTextBox.Size = new System.Drawing.Size(95, 22); + this.RandomLengthTextBox.TabIndex = 17; + this.RandomLengthTextBox.Text = "10"; + // + // AddRandomButton + // + this.AddRandomButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.AddRandomButton.Location = new System.Drawing.Point(93, 366); + this.AddRandomButton.Name = "AddRandomButton"; + this.AddRandomButton.Size = new System.Drawing.Size(113, 23); + this.AddRandomButton.TabIndex = 16; + this.AddRandomButton.Text = "Add Random"; + this.AddRandomButton.UseVisualStyleBackColor = true; + this.AddRandomButton.Click += new System.EventHandler(this.AddRandomButton_Click); + // + // ClearButton + // + this.ClearButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.ClearButton.Location = new System.Drawing.Point(10, 366); + this.ClearButton.Name = "ClearButton"; + this.ClearButton.Size = new System.Drawing.Size(75, 23); + this.ClearButton.TabIndex = 15; + this.ClearButton.Text = "Clear"; + this.ClearButton.UseVisualStyleBackColor = true; + this.ClearButton.Click += new System.EventHandler(this.ClearButton_Click); + // // newCodeTypeLabel // this.newCodeTypeLabel.AutoSize = true; - this.newCodeTypeLabel.Location = new System.Drawing.Point(177, 46); + this.newCodeTypeLabel.Location = new System.Drawing.Point(236, 57); + this.newCodeTypeLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.newCodeTypeLabel.Name = "newCodeTypeLabel"; - this.newCodeTypeLabel.Size = new System.Drawing.Size(0, 13); + this.newCodeTypeLabel.Size = new System.Drawing.Size(0, 16); this.newCodeTypeLabel.TabIndex = 14; // // configurationGroupBox @@ -200,21 +252,24 @@ private void InitializeComponent() { this.configurationGroupBox.Controls.Add(this.label1); this.configurationGroupBox.Controls.Add(this.label4); this.configurationGroupBox.Controls.Add(this.hotkeyTextBox); - this.configurationGroupBox.Location = new System.Drawing.Point(12, 12); + this.configurationGroupBox.Location = new System.Drawing.Point(16, 15); + this.configurationGroupBox.Margin = new System.Windows.Forms.Padding(4); this.configurationGroupBox.Name = "configurationGroupBox"; - this.configurationGroupBox.Size = new System.Drawing.Size(254, 118); + this.configurationGroupBox.Padding = new System.Windows.Forms.Padding(4); + this.configurationGroupBox.Size = new System.Drawing.Size(453, 145); this.configurationGroupBox.TabIndex = 15; this.configurationGroupBox.TabStop = false; this.configurationGroupBox.Text = "Configuration"; // // BarcodeSimulatorControl // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(280, 408); + this.ClientSize = new System.Drawing.Size(487, 573); this.Controls.Add(this.configurationGroupBox); this.Controls.Add(this.itemsGroupBox); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.Margin = new System.Windows.Forms.Padding(4); this.Name = "BarcodeSimulatorControl"; this.Text = "Barcode Simulator"; this.Load += new System.EventHandler(this.BarcodeSimulatorControl_Load); @@ -243,6 +298,10 @@ private void InitializeComponent() { private System.Windows.Forms.GroupBox itemsGroupBox; private System.Windows.Forms.GroupBox configurationGroupBox; private System.Windows.Forms.Label newCodeTypeLabel; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox RandomLengthTextBox; + private System.Windows.Forms.Button AddRandomButton; + private System.Windows.Forms.Button ClearButton; } } diff --git a/BarcodeSimulator/BarcodeSimulatorControl.cs b/BarcodeSimulator/BarcodeSimulatorControl.cs index 5dc1f2b..4c93ff1 100644 --- a/BarcodeSimulator/BarcodeSimulatorControl.cs +++ b/BarcodeSimulator/BarcodeSimulatorControl.cs @@ -1,26 +1,40 @@ using System; using System.ComponentModel; using System.Diagnostics; +using System.IO; using System.Linq; +using System.Runtime.InteropServices.ComTypes; +using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; +using static System.Net.Mime.MediaTypeNames; +using static System.Windows.Forms.DataFormats; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace BarcodeSimulator { public partial class BarcodeSimulatorControl : Form { + private string FilePath { get; set; } = @".\BarcodeSimulator.txt"; public BarcodeSimulatorControl() { InitializeComponent(); + LoadItems(); + } + + protected override void OnClosing(CancelEventArgs e) + { + SaveItems(); + base.OnClosing(e); } private void BarcodeSimulatorControl_Load(object sender, EventArgs e) { // setup a new Hotkey to watch for Windows+Z // this could/should be configurable on the form - var hk = new Hotkey(Keys.Z, shift: false, control: false, alt: false, windows: true); + var hk = new Hotkey(Keys.Z, shift: true, control: true, alt: false, windows: false); hk.Pressed += HotkeyPressed; hk.Register(this); @@ -38,7 +52,7 @@ private void BarcodeSimulatorControl_Load(object sender, EventArgs e) private void SetupToolTips() { - var tt = new ToolTip {InitialDelay = 500, ReshowDelay = 500, ShowAlways = true}; + var tt = new System.Windows.Forms.ToolTip { InitialDelay = 500, ReshowDelay = 500, ShowAlways = true}; tt.SetToolTip(delayNumeric, "Delay in milliseconds between each keypress when sending a barcode."); tt.SetToolTip(hotkeyTextBox, "Activation key sequence. Press " + hotkeyTextBox.Text + " to send the next barcode."); @@ -63,6 +77,7 @@ private void HotkeyPressed(object sender, HandledEventArgs e) var s = GetNextCode(); // do the delayed key sending in a separate thread so we don't hang the window + Thread.Sleep(1000); ThreadStart starter = () => StartSending(s, (int) delayNumeric.Value, endKey); var t = new Thread(starter) { Name = "Sending keys " + s }; t.Start(); @@ -73,10 +88,14 @@ private static void StartSending(string text, int delay, Keys endKey = Keys.None foreach (var s in text.Select(character => character.ToString())) { - Debug.WriteLine("{0} Sending text '{1}'", DateTime.Now.ToString("HH:mm:ss.fff"), s); + Debug.WriteLine("{0} Sending text '{1}' with delay of '{2}'", DateTime.Now.ToString("HH:mm:ss.fff"), s, delay); + //SendKeys.SendWait(s); SendKeys.SendWait(s); SendKeys.Flush(); - Thread.Sleep(delay); + if (delay > 0) + { + Thread.Sleep(delay); + } } // if configured, send an 'end' key to signal that we're at the end of the barcode @@ -84,7 +103,7 @@ private static void StartSending(string text, int delay, Keys endKey = Keys.None SendKeys.SendWait("{" + Enum.GetName(typeof (Keys), endKey) + "}"); // beep! - System.Media.SystemSounds.Beep.Play(); + //System.Media.SystemSounds.Beep.Play(); } /// @@ -130,11 +149,17 @@ private void newStringTextBox_KeyDown(object sender, KeyEventArgs e) var code = newStringTextBox.Text; - + AddCode(code); + + newStringTextBox.Clear(); + + SaveItems(); + } + + private void AddCode(string code) + { itemsListView.Items.Add(new ListViewItem(new[] { code, Barcode.GetTypeName(code) })); itemsListView.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); - - newStringTextBox.Clear(); } /// @@ -170,5 +195,54 @@ private void newStringTextBox_TextChanged(object sender, EventArgs e) newCodeTypeLabel.Text = type; } + + private void ClearButton_Click(object sender, EventArgs e) + { + itemsListView.Items.Clear(); + } + + private void AddRandomButton_Click(object sender, EventArgs e) + { + // Add a random number itemsListView whose length is controlled by the value of the RandomLengthTextBox text box + + var random = new Random(); + var randomLength = Convert.ToInt32(RandomLengthTextBox.Text); + var randomString = new string(Enumerable.Repeat("0123456789", randomLength).Select(s => s[random.Next(s.Length)]).ToArray()); + + itemsListView.Items.Add(new ListViewItem(new[] { randomString, Barcode.GetTypeName(randomString) })); + } + + private void SaveItems() + { + using (StreamWriter writer = new StreamWriter(FilePath)) + { + foreach (ListViewItem item in itemsListView.Items) + { + writer.WriteLine(item.Text); + } + } + } + + private void LoadItems() + { + if (File.Exists(FilePath)) + { + itemsListView.Items.Clear(); + + using (StreamReader reader = new StreamReader(FilePath)) + { + string line; + while ((line = reader.ReadLine()) != null) + { + AddCode(line); + } + } + } + } + + + + + } } diff --git a/BarcodeSimulator/app.config b/BarcodeSimulator/app.config new file mode 100644 index 0000000..3e0e37c --- /dev/null +++ b/BarcodeSimulator/app.config @@ -0,0 +1,3 @@ + + +