Forum Discussion

gcizman2024's avatar
gcizman2024
Copper Contributor
May 07, 2024

How to prevent selected values from dropdown in wpf forms?

Hi Team

 

i Team

How do i prevent other values when selected from the combo-box(comp1, comp2, comp2, truck-full, truck-return etc and these are queried from database as Dataset for them to filtered) if they are selected they must not gett into this if statement. Only required compartment(truck-empty) purpose('Leaving-Finished Product') must be the only onces get executed. The current code seem to be doing slight but not 100% percent being correct. Let me share this method below;

 

 

private void btnSaveTicket_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtFullWeight.Text == "" || txtFullWeight.Text == "0")
                {
                    MessageBox.Show("Capture weight before saving");
                    Managers.WeighbridgeLogManager.InsertWBInfoLog("Capture weight before saving", "");
                    return;
                }
                if (cbxCompartment.SelectedIndex == 0)
                {
                    MessageBox.Show("Please select a Compartment", "No compartment selected");
                    Managers.WeighbridgeLogManager.InsertWBInfoLog("Please select a Compartment", "");
                    return;
                }
                if (cbxCustomer.SelectedIndex == 0)
                {
                    MessageBox.Show("Please select a Customer", "No customer selected");
                    Managers.WeighbridgeLogManager.InsertWBInfoLog("Please select a customer", "");
                    return;
                }
                if (cbxProduct.SelectedIndex == 0)
                {
                    MessageBox.Show("Please select a Product", "No product selected");
                    Managers.WeighbridgeLogManager.InsertWBInfoLog("Please select a product", "");
                    return;
                }


                if (txtBinsSelected.Text == "")
                {
                    MessageBox.Show("Please select a Bin", "No Bin selected");
                    Managers.WeighbridgeLogManager.InsertWBInfoLog("Please select a Bin", "");
                    return;
                }
                if (comboPurpose.SelectedIndex == 0)
                {
                    MessageBox.Show("Please select a Purpose", "No purpose selected");
                    Managers.WeighbridgeLogManager.InsertWBInfoLog("Please select a purpose", "");
                    return;
                }
                //if (comboPurpose.Text.ToUpper() != "SELECT A PURPOSE")
                //{
                    if (txtFullWeight.Text == "")
                    {
                        MessageBox.Show("Please capture weight", "No Weight entered");
                        Managers.WeighbridgeLogManager.InsertWBInfoLog("Please capture weight", "");
                        return;
                    }


                // Check if the compartment selected is "truck-empty" and the purpose is "Leaving-Finished Product"
                if (cbxCompartment.SelectedItem != null &&
                    string.Equals(cbxCompartment.SelectedItem.ToString(), "truck-empty", StringComparison.OrdinalIgnoreCase) &&
                    cbxPurpose.SelectedItem != null &&
                    string.Equals(cbxPurpose.SelectedItem.ToString(), "Leaving-Finished Product", StringComparison.OrdinalIgnoreCase))
                { 
                }
                    // Check if both TopSeal and BottomSeal are empty
                    if (string.IsNullOrEmpty(txtTopSeal.Text.Trim()))
                    {
                        MessageBox.Show("TopSeal cannot be empty when the truck is empty and the purpose is Leaving-Finished Product", "Validation Error");
                        txtTopSeal.Focus();
                        return;
                    }

                    if (string.IsNullOrEmpty(txtBottomSeal.Text.Trim()))
                    {
                        MessageBox.Show("BottomSeal cannot be empty when the truck is empty and the purpose is Leaving-Finished Product", "Validation Error");
                        txtBottomSeal.Focus();
                        return;
                    }
                

            

                presenter.SaveTicket();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
                Managers.WeighbridgeLogManager.InsertWBErrorLog(ex.Message, TripSheetNo.ToString() == "" ? "" : TripSheetNo.ToString(), ex.StackTrace, ex.InnerException == null ? "" : ex.InnerException.ToString());
                return;
            }

        }
No RepliesBe the first to reply

Resources