-Display weight againt trolley selection and add time out on GetTrolleyApi()
parent
4fc58d4f4d
commit
cbe589b123
Binary file not shown.
|
@ -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.";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@ namespace WindowsFormsApp1
|
|||
private Label siteTextBox;
|
||||
private BackgroundWorker bgWorker;
|
||||
private System.Windows.Forms.Timer scanTimer;
|
||||
// Dictionary to store trolley weights
|
||||
Dictionary<int, int> trolleyWeights = new Dictionary<int, int>();
|
||||
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 = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>mchCT4FFpI0ZZUkeK14AGp7wO3vdL9uZJWjO1kUBBr4=</dsig:DigestValue>
|
||||
<dsig:DigestValue>wme4xw6ewP2pF4fqmYop8GD0nCotYV7FTKLJZ3ny544=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
|
Binary file not shown.
|
@ -439,14 +439,14 @@
|
|||
</dependentAssembly>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="UWS.exe" size="378856">
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="UWS.exe" size="380904">
|
||||
<assemblyIdentity name="UWS" version="1.0.0.0" language="neutral" processorArchitecture="x86" />
|
||||
<hash>
|
||||
<dsig:Transforms>
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>9JvM6iTXpiQtjdM0VZCU0lto7/XfxbF2DRTB2fEBMWI=</dsig:DigestValue>
|
||||
<dsig:DigestValue>5WJzKe3F7LNaie5Bbn3hsqnK+eeerdkFy7wED9FIsxo=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -14,7 +14,7 @@
|
|||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>mchCT4FFpI0ZZUkeK14AGp7wO3vdL9uZJWjO1kUBBr4=</dsig:DigestValue>
|
||||
<dsig:DigestValue>wme4xw6ewP2pF4fqmYop8GD0nCotYV7FTKLJZ3ny544=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -439,14 +439,14 @@
|
|||
</dependentAssembly>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="UWS.exe" size="378856">
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="UWS.exe" size="380904">
|
||||
<assemblyIdentity name="UWS" version="1.0.0.0" language="neutral" processorArchitecture="x86" />
|
||||
<hash>
|
||||
<dsig:Transforms>
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>9JvM6iTXpiQtjdM0VZCU0lto7/XfxbF2DRTB2fEBMWI=</dsig:DigestValue>
|
||||
<dsig:DigestValue>5WJzKe3F7LNaie5Bbn3hsqnK+eeerdkFy7wED9FIsxo=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue