Hi Team
I have small issue, when trying to debug it i dont see the values. perhaps my logic is when user select dropdown(compartment-full-truck) and purpose(leaving finished product) these must validate if topseal and bottomseal are empty otherwsise truck must not move at all until these are met. Below is my logic. So what the code is doing, it does hit the debug and if statement but its not getting into this logic need some help.
// back end className
private void btnSaveReturn_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(txtTicketNu.Text))
{
MessageBox.Show("Please select a ticket");
return;
}
//if(rdbtn1.Is checked){
//update farm/ product
//
//}else
//if(rdbtn2.Is checked){
//update replacements
//
//}else
if (chkFarmName.IsChecked == true)
{
// MessageBox.Show("Customer, Product AND Replacement Seals can ONLY be updated", "WARNING");
var ticket = Managers.WeighbridgeTicketManager.GetWeighBridgeTicketPK(txtTicketNu.Text);
ticket.Customer = cbxCustomer.Text;
ticket.Product = cbxProduct.Text;
ticket.ReplacementTopSeal = txtRTopSeal.Text;
ticket.ReplacementBottomSeal = txtRBottomSeal.Text;
Managers.WeighbridgeTicketManager.UpdateTripsheetCustomer(ticket);
presenter.PopulateGrid(txtTripsheetNo.Text);
MessageBox.Show("Ticket " + TicketNumber + " updated successfully.", "Ticket Update");
ClearFields();
}
else
{
if (string.IsNullOrEmpty(txtReturnWeight.Text))
{
MessageBox.Show("Please enter compartment weight");
return;
}
if (cbxPurpose.SelectedIndex == 0)
{
MessageBox.Show("Please select a purpose");
return;
}
Console.WriteLine("Selected compartment: " + (cbxCompartment.SelectedItem != null ? cbxCompartment.SelectedItem.ToString() : "null"));
Console.WriteLine("Selected purpose: " + (cbxPurpose.SelectedItem != null ? cbxPurpose.SelectedItem.ToString() : "null"));
if (cbxCompartment.SelectedItem != null && cbxCompartment.SelectedItem.ToString() == "truck-full"
& cbxPurpose.SelectedItem != null && cbxPurpose.SelectedItem.ToString()== "Leaving Finished Product")
{
// Validate top seal
if (string.IsNullOrEmpty(txtRTopSeal.Text))
{
MessageBox.Show("TopSeal cannot be empty when truck is full", "Validation Error");
txtRTopSeal.Focus();
return;
}
// Validate bottom seal
if (string.IsNullOrEmpty(txtRBottomSeal.Text))
{
MessageBox.Show("BottomSeal cannot be empty when truck is full", "Validation Error");
txtRBottomSeal.Focus();
return;
}
}
Naimish MakwanaPosted May 7, 2024, 7:14 AM
From your code, it seems like you are correctly checking if the
cbxCompartmentis “truck-full” andcbxPurposeis “Leaving Finished Product”. If these conditions are met, you are validating whethertxtRTopSealandtxtRBottomSealare not empty.However, you mentioned that the code is not getting into this logic. This could be due to a few reasons:
Mismatch in the condition values: Ensure that the values you are checking in the if condition (“truck-full” and “Leaving Finished Product”) exactly match the values in the dropdown. These checks are case-sensitive.
Dropdown values not being set: The selected item might not be getting set in the dropdown. You can check this by debugging and inspecting the
SelectedItemproperty of the dropdowns.Empty fields: The
txtRTopSealandtxtRBottomSealfields might be empty when the validation is happening. You can add debug statements to check their values as well.Thanks
Guest UserPosted May 6, 2024, 8:07 PM
Hi Jayray
The issue still persist, when debugging it only sees the if statement but not getting into topseal and bottom seal when its empty, when compartment(truck-empty) is selected its not validating these fields.
Jayraj ChhayaPosted May 6, 2024, 7:44 AM
Based on the provided code snippet, it seems that the logic for validating the topseal and bottomseal fields is not being executed correctly. Here are a few suggestions to help resolve the issue:
Make sure that the event handler
btnSaveReturn_Clickis properly wired up to the button's click event in the XAML code. Double-check that theClickattribute of the button is set tobtnSaveReturn_Click.Check if the conditions for the if statement are being met. Verify that the selected values of the
cbxCompartmentandcbxPurposedropdowns are correctly matching the expected values ("truck-full" and "Leaving Finished Product" respectively).Ensure that the
txtRTopSealandtxtRBottomSealtextboxes are correctly bound to their respective properties in the XAML code. Double-check thex:Nameattributes of these textboxes and make sure they match the property names used in the code-behind.Consider using the
SelectedItemproperty instead ofSelectedItem.ToString()when comparing the selected values of the dropdowns. This will ensure that the comparison is done correctly.Jignesh KumarPosted May 6, 2024, 7:38 AM
Hello,
Have you checked both dropdown values in If condition,
"truck-full" and "Leaving Finished Product" , these values are case sensitive and space also matters, so check while comparing both combo box values in if condition.
check values for : cbxCompartment.SelectedItem.ToString(), cbxPurpose.SelectedItem.ToString()
Solution: You can convert all values to ToLower()
Example: cbxCompartment.SelectedItem.ToString().ToLower() == "leaving finished product"
Jithu ThomasPosted May 6, 2024, 7:32 AM
It seems like your code is attempting to validate whether the top seal and bottom seal fields are empty when a specific combination of values is selected from the dropdowns (`cbxCompartment` and `cbxPurpose`). However, you mentioned that the logic is not behaving as expected.
1. You're checking if `cbxCompartment.SelectedItem` is equal to "truck-full" and `cbxPurpose.SelectedItem` is equal to "Leaving Finished Product".
2. If this condition is met, you're checking whether `txtRTopSeal.Text` and `txtRBottomSeal.Text` are empty.
First, let's confirm whether the condition to enter the if statement is being met. You can add debug statements or breakpoints to verify this.
If the condition is indeed met, then you should check if the code within the if statement is executed. Again, debug statements or breakpoints can help here.
If the condition isn't being met, ensure that the values in the dropdowns and the logic are correct. You can print out the selected values for debugging purposes.
Additionally, check if the event handler `btnSaveReturn_Click` is correctly wired up to the button click event.
If you've confirmed that the condition is being met and the code within the if statement is not executing, then there might be some other issue within the logic or with the control flow of your application. In that case, further investigation would be needed, potentially including reviewing other parts of your code.