Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi Team

I have a form uses dropdown, combox box(Compartment and Purpose). Now the logic should be this if Truck full(taken from Compartment dropdown selection) and Purpose(Leaving Finished Product dropdown selection), they must validate for both TopSeal and BottomSeal.

What I have tried:

XML
<pre><Label x:Name="lblPurpose" Content="Purpose:" HorizontalAlignment="Left" Margin="12,141,0,0" VerticalAlignment="Top" Width="93" HorizontalContentAlignment="Right" Background="#FFE3E3E3" FontWeight="SemiBold" BorderThickness="1" BorderBrush="#FFBEBEBE"/>
        <ComboBox x:Name="cbxPurpose" HorizontalAlignment="Left" Margin="110,142,0,0" VerticalAlignment="Top" Width="119" Height="27"/>
        <Label x:Name="lblCompartment" Content="Compartment:" HorizontalAlignment="Left" Margin="12,171,0,0" VerticalAlignment="Top" Width="93" HorizontalContentAlignment="Right" Background="#FFE3E3E3" FontWeight="SemiBold" BorderThickness="1" BorderBrush="#FFBEBEBE"/>
        <ComboBox x:Name="cbxCompartment" IsEnabled="True" IsEditable="True" HorizontalAlignment="Left" Margin="110,170,0,0" VerticalAlignment="Top" Width="119" Height="26"/>



C#
<pre>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;
                }

                if (cbxCompartment.SelectedItem != null && cbxCompartment.SelectedItem.ToString() == "truck-empty")
                {
                    if (string.IsNullOrEmpty(txtRTopSeal.Text))
                    {
                        MessageBox.Show("TopSeal cannot be empty when truck is empty", "Validation Error");
                        txtRTopSeal.Focus();
                        return;
                    }
                }

                ReturnDelivery retDelivery = new ReturnDelivery();
                retDelivery.Comment = txtComment.Text;
                retDelivery.Customer = cbxCustomer.Text;
                retDelivery.Product = cbxProduct.Text;
                retDelivery.Productweight = Convert.ToInt32(txtReturnWeight.Text);
                retDelivery.Purpose = Convert.ToInt32(cbxPurpose.SelectedValue);
                retDelivery.Ticket = Convert.ToInt32(txtTicketNu.Text);
                retDelivery.Trip = Convert.ToInt32(txtTripsheetNo.Text);
                var tickets = Managers.ReturnDeliveryManager.InsertReturnDelivery(retDelivery);
                ClearFields();
                MessageBox.Show("Return has been successfully saved");
               
            }
        }
Posted
Comments
OriginalGriff 6-May-24 1:03am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.

1 solution

To be honest, the code you have is attempting to do too much in a none-WPF recommended way. If I were you, I would look to use binding on your form so that you can simplify your code. That's your first hint - look at how to convert this to use binding.

If you must use the code the way you have it, you might want something like this:
C#
string purpose = cbxPurpose.SelectedItem?.ToString();
string compartment = cbxCompartment.SelectedItem?.ToString();

if (compartment == "Truck Full" && purpose == "Leaving Finished Product")
{
  // Validate top and bottom seal...
}
As there's no indication where TopSeal or BottomSeal could possibly come from, I can't help any more I'm afraid. As OriginalGriff says, we can't see your screen so if you don't provide full information, our ability to help will be limited.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900