diff --git a/.vs/Utopia Weight Scale/v16/.suo b/.vs/Utopia Weight Scale/v16/.suo index 5daa0db..a092cd9 100644 Binary files a/.vs/Utopia Weight Scale/v16/.suo and b/.vs/Utopia Weight Scale/v16/.suo differ diff --git a/WindowsFormsApp1/DataAccessObject .cs b/WindowsFormsApp1/DataAccessObject .cs index e98736c..4d74d5e 100644 --- a/WindowsFormsApp1/DataAccessObject .cs +++ b/WindowsFormsApp1/DataAccessObject .cs @@ -10,6 +10,7 @@ using System.Net; using System.Net.Http; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms; using static UWS.BusinessLayer; namespace UWS @@ -408,20 +409,16 @@ namespace UWS { using (HttpClient _httpClient = new HttpClient()) { - + _httpClient.Timeout = TimeSpan.FromSeconds(30); // Set timeout to 30 seconds - // If no payload is required, you can send an empty POST request by passing an empty StringContent - var content = new StringContent(string.Empty, Encoding.UTF8, "application/json"); - - // Send the POST request + // Send the GET request var response = await _httpClient.GetAsync(urlTrolley); // Check the status of the response if (response.IsSuccessStatusCode) { - // Return the response content as string - string responseString = await response.Content.ReadAsStringAsync(); - return responseString; + // Return the response content as a string + return await response.Content.ReadAsStringAsync(); } else { @@ -431,15 +428,23 @@ namespace UWS } } } + catch (TaskCanceledException ex) when (ex.CancellationToken.IsCancellationRequested == false) + { + // Timeout occurred + MessageBox.Show("Request timed out. Please check your internet connection and try again.", "Timeout", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return "Error: Request timed out."; + } catch (HttpRequestException httpEx) { - // Handle HTTP-specific exceptions - return $"HttpRequestException: {httpEx.Message}"; + // Timeout occurred + MessageBox.Show("Request timed out. Please check your internet connection and try again.", "Timeout", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return "Error: Request timed out."; } catch (Exception ex) { - // Handle general exceptions - return $"Exception: {ex.Message}"; + // Timeout occurred + MessageBox.Show("Request timed out. Please check your internet connection and try again.", "Timeout", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return "Error: Request timed out."; } } diff --git a/WindowsFormsApp1/WeighingForm.Designer.cs b/WindowsFormsApp1/WeighingForm.Designer.cs index 3e16112..d102e0e 100644 --- a/WindowsFormsApp1/WeighingForm.Designer.cs +++ b/WindowsFormsApp1/WeighingForm.Designer.cs @@ -33,6 +33,7 @@ namespace WindowsFormsApp1 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WeighingForm)); this.lbl_weight = new System.Windows.Forms.Label(); this.panel2 = new System.Windows.Forms.Panel(); + this.txt_weight = new System.Windows.Forms.TextBox(); this.cb_transporter = new System.Windows.Forms.ComboBox(); this.lbl_trnsporter = new System.Windows.Forms.Label(); this.chk_box = new System.Windows.Forms.CheckBox(); @@ -134,6 +135,15 @@ namespace WindowsFormsApp1 this.panel2.TabIndex = 5; this.panel2.Visible = false; // + // txt_weight + // + this.txt_weight.Enabled = false; + this.txt_weight.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.txt_weight.Location = new System.Drawing.Point(278, 38); + this.txt_weight.Name = "txt_weight"; + this.txt_weight.Size = new System.Drawing.Size(82, 29); + this.txt_weight.TabIndex = 31; + // // cb_transporter // this.cb_transporter.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; @@ -743,8 +753,9 @@ namespace WindowsFormsApp1 this.cb_trolley.FormattingEnabled = true; this.cb_trolley.Location = new System.Drawing.Point(105, 36); this.cb_trolley.Name = "cb_trolley"; - this.cb_trolley.Size = new System.Drawing.Size(255, 32); + this.cb_trolley.Size = new System.Drawing.Size(167, 32); this.cb_trolley.TabIndex = 28; + this.cb_trolley.SelectedIndexChanged += new System.EventHandler(this.cb_trolley_SelectedIndexChanged); // // lbl_trolly // @@ -775,6 +786,7 @@ namespace WindowsFormsApp1 this.BackgroundImage = global::UWS.Properties.Resources.BG; this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.ClientSize = new System.Drawing.Size(734, 515); + this.Controls.Add(this.txt_weight); this.Controls.Add(this.lbl_com); this.Controls.Add(this.lbl_trolly); this.Controls.Add(this.cb_trolley); @@ -878,6 +890,7 @@ namespace WindowsFormsApp1 private System.Windows.Forms.Label lbl_trnsporter; private System.Windows.Forms.ComboBox cb_transporter; private System.Windows.Forms.Label lbl_com; + private System.Windows.Forms.TextBox txt_weight; } } diff --git a/WindowsFormsApp1/WeighingForm.cs b/WindowsFormsApp1/WeighingForm.cs index 228a6a7..5d95f02 100644 --- a/WindowsFormsApp1/WeighingForm.cs +++ b/WindowsFormsApp1/WeighingForm.cs @@ -39,6 +39,8 @@ namespace WindowsFormsApp1 private Label siteTextBox; private BackgroundWorker bgWorker; private System.Windows.Forms.Timer scanTimer; + // Dictionary to store trolley weights + Dictionary trolleyWeights = new Dictionary(); public WeighingForm(Int32 userId) { InitializeComponent(); @@ -331,19 +333,34 @@ namespace WindowsFormsApp1 var selectItem = new { id = 0, code = "SELECT" }; items.Insert(0, selectItem); // Add at the 0th index of the existing items list - // Invoke UI updates on the main thread Invoke((Action)(() => { - // Bind the ComboBox to the 'code' (displayed) and 'id' (value) properties - cb_trolley.DataSource = items - .Select(item => new { id = (int)item.id, code = (string)item.code }) // Ensure the mapping to `id` and `code` + // Convert response into a list with 'id' and 'code' for binding, include "SELECT" + var trolleyList = items + .Select(item => new { id = (int)item.id, code = (string)item.code }) .ToList(); - cb_trolley.DisplayMember = "code"; // Display the 'code' value - cb_trolley.ValueMember = "id"; // Use the 'id' as the value + // Populate the dictionary with weights (including "SELECT" with ID 0) + foreach (var item in items) + { + // Ensure we do not add "SELECT" (id = 0) to trolleyWeights + if ((int)item.id != 0) + { + trolleyWeights[(int)item.id] = (int)item.weight; + } + } - // Select the "SELECT" item (index 0) + // Bind ComboBox with all items + cb_trolley.DataSource = trolleyList; + cb_trolley.DisplayMember = "code"; // Display the trolley code + cb_trolley.ValueMember = "id"; // Use 'id' as the value + + // Set default selection to "SELECT" cb_trolley.SelectedIndex = 0; + + // Attach event handler for selection change + cb_trolley.SelectedIndexChanged += cb_trolley_SelectedIndexChanged; + SetupSearchableComboBox(cb_trolley); })); } @@ -386,11 +403,11 @@ namespace WindowsFormsApp1 } catch (JsonReaderException jsonEx) { - MessageBox.Show($"JSON Parsing Error: {jsonEx.Message}"); + //MessageBox.Show($"JSON Parsing Error: {jsonEx.Message}"); } catch (Exception ex) { - MessageBox.Show($"Error: {ex.Message}"); + // MessageBox.Show($"Error: {ex.Message}"); } } private void BgWorker_DoWork(object sender, DoWorkEventArgs e) @@ -1328,5 +1345,29 @@ namespace WindowsFormsApp1 } } } + + private void cb_trolley_SelectedIndexChanged(object sender, EventArgs e) + { + if (cb_trolley.SelectedValue != null) + { + // Ensure the selected value is converted to an integer + if (int.TryParse(cb_trolley.SelectedValue.ToString(), out int selectedId)) + { + if (selectedId != 0 && trolleyWeights.ContainsKey(selectedId)) + { + txt_weight.Text = trolleyWeights[selectedId].ToString(); + } + else + { + txt_weight.Text = ""; // Clear textbox for "SELECT" + } + } + else + { + txt_weight.Text = ""; + } + } + } + } } diff --git a/WindowsFormsApp1/bin/Debug/UWS.application b/WindowsFormsApp1/bin/Debug/UWS.application index f185961..358692f 100644 --- a/WindowsFormsApp1/bin/Debug/UWS.application +++ b/WindowsFormsApp1/bin/Debug/UWS.application @@ -14,7 +14,7 @@ - mchCT4FFpI0ZZUkeK14AGp7wO3vdL9uZJWjO1kUBBr4= + wme4xw6ewP2pF4fqmYop8GD0nCotYV7FTKLJZ3ny544= diff --git a/WindowsFormsApp1/bin/Debug/UWS.exe b/WindowsFormsApp1/bin/Debug/UWS.exe index 6799370..86dfd6b 100644 Binary files a/WindowsFormsApp1/bin/Debug/UWS.exe and b/WindowsFormsApp1/bin/Debug/UWS.exe differ diff --git a/WindowsFormsApp1/bin/Debug/UWS.exe.manifest b/WindowsFormsApp1/bin/Debug/UWS.exe.manifest index 6717cab..1d29fef 100644 --- a/WindowsFormsApp1/bin/Debug/UWS.exe.manifest +++ b/WindowsFormsApp1/bin/Debug/UWS.exe.manifest @@ -439,14 +439,14 @@ - + - 9JvM6iTXpiQtjdM0VZCU0lto7/XfxbF2DRTB2fEBMWI= + 5WJzKe3F7LNaie5Bbn3hsqnK+eeerdkFy7wED9FIsxo= diff --git a/WindowsFormsApp1/bin/Debug/UWS.pdb b/WindowsFormsApp1/bin/Debug/UWS.pdb index 8bc78ce..9bffee1 100644 Binary files a/WindowsFormsApp1/bin/Debug/UWS.pdb and b/WindowsFormsApp1/bin/Debug/UWS.pdb differ diff --git a/WindowsFormsApp1/bin/Debug/app.publish/UWS.exe b/WindowsFormsApp1/bin/Debug/app.publish/UWS.exe index db332b2..0b292ea 100644 Binary files a/WindowsFormsApp1/bin/Debug/app.publish/UWS.exe and b/WindowsFormsApp1/bin/Debug/app.publish/UWS.exe differ diff --git a/WindowsFormsApp1/obj/Debug/UWS.application b/WindowsFormsApp1/obj/Debug/UWS.application index f185961..358692f 100644 --- a/WindowsFormsApp1/obj/Debug/UWS.application +++ b/WindowsFormsApp1/obj/Debug/UWS.application @@ -14,7 +14,7 @@ - mchCT4FFpI0ZZUkeK14AGp7wO3vdL9uZJWjO1kUBBr4= + wme4xw6ewP2pF4fqmYop8GD0nCotYV7FTKLJZ3ny544= diff --git a/WindowsFormsApp1/obj/Debug/UWS.csproj.GenerateResource.cache b/WindowsFormsApp1/obj/Debug/UWS.csproj.GenerateResource.cache index 481cc2b..a3c12cc 100644 Binary files a/WindowsFormsApp1/obj/Debug/UWS.csproj.GenerateResource.cache and b/WindowsFormsApp1/obj/Debug/UWS.csproj.GenerateResource.cache differ diff --git a/WindowsFormsApp1/obj/Debug/UWS.exe b/WindowsFormsApp1/obj/Debug/UWS.exe index 6799370..86dfd6b 100644 Binary files a/WindowsFormsApp1/obj/Debug/UWS.exe and b/WindowsFormsApp1/obj/Debug/UWS.exe differ diff --git a/WindowsFormsApp1/obj/Debug/UWS.exe.manifest b/WindowsFormsApp1/obj/Debug/UWS.exe.manifest index 6717cab..1d29fef 100644 --- a/WindowsFormsApp1/obj/Debug/UWS.exe.manifest +++ b/WindowsFormsApp1/obj/Debug/UWS.exe.manifest @@ -439,14 +439,14 @@ - + - 9JvM6iTXpiQtjdM0VZCU0lto7/XfxbF2DRTB2fEBMWI= + 5WJzKe3F7LNaie5Bbn3hsqnK+eeerdkFy7wED9FIsxo= diff --git a/WindowsFormsApp1/obj/Debug/UWS.pdb b/WindowsFormsApp1/obj/Debug/UWS.pdb index 8bc78ce..9bffee1 100644 Binary files a/WindowsFormsApp1/obj/Debug/UWS.pdb and b/WindowsFormsApp1/obj/Debug/UWS.pdb differ