none
How do I call an event handler such as "Click" to a completely different object methods conditional statement? RRS feed

  • Question

  • First, This is my first post. So I apologize for any undoing of postings.
    Also, I am still learning to code. Along with learning C# as a language. My syntax knowledge is limited. 

    I need help trying to call the data from various objects in my windows form application to be used to generate the final result. 

    Right now I have it coded so that they all respond to the calculate button. But I cant quite seem to get this to recall the actual selection the end user made. It just simply calculates and displays every potential result for each bag type, for reach shipping rate. @_@


    I have no Idea what syntax's to use to call the click events from 1(Combobox to select the bag type), 2(radiobutton), 2A(RadioButton2), 2B (RadioButton3) to use in my Calculate button.  Furthermore I do not know how to convert an event to a bool for an If loop to be created for my calculate button.

    My current If loop code is as follows:

     if (this.AmountSelected.Value > 0)
                {
                    //convert the NumaricupDown value to an int for use for all the nested ifs.
                    Convert.ToInt32(this.AmountSelected.Value);

                    // times the price per bag by the amount selected and provide a new variable of reference to call



                    if (Fullbeaded1 < Bb1)
                    {

                        MessageBox.Show("The Total Price with Standard Shipping is" + (StandardPriceTotal1));
                    }
                    if (Bb1 < Fullbeaded1)
                    {

                        MessageBox.Show("The Total Price with Standard Shipping is" + (StandardPriceTotal2));
                    }

                    if (NPD1 < Bb1)
                    {

                        MessageBox.Show("The Total Price with Standard Shipping is" + (StandardPriceTotal3));
                    }
                    if (Fr1 < NPD1)
                    {

                        MessageBox.Show("The Total Price with Standard Shipping is" + (StandardPriceTotal4));
                    }
                    if (FB1 < Fr1)
                    {

                        MessageBox.Show("The Total Price with Standard Shipping is" + (StandardPriceTotal5));
                    }
                    if (P1 < FB1)
                    {

                        MessageBox.Show("The Total Price with Standard Shipping is" + (StandardPriceTotal6));
                    }

                  
                else
                {
                       
                        if (this.AmountSelected.Value > 0)
                        {
                            Convert.ToInt32(this.AmountSelected.Value);
                        }
                        if (Fullbeaded1 < Bb1)
                        {
                            MessageBox.Show("the Total Price with Three Day shipping is" + (TDtotal));
                        }



                        if (Bb1 < Fullbeaded1)
                        {

                            MessageBox.Show("the Total Price with Three Day shipping is" + (TDtotal2));
                        }

                        if (NPD1 < Bb1)
                        {

                            MessageBox.Show("the Total Price with Three Day shipping is" + (TDtotal3));
                        }
                        if (Fr1 < NPD1)
                        {
                            this.AmountSelected.Value = 0;
                            MessageBox.Show("the Total Price with Three Day shipping is" + (TDtotal4));
                        }
                        if (FB1 < Fr1)
                        {
                            this.AmountSelected.Value = 0;
                            MessageBox.Show("the Total Price with Three Day shipping is" + (TDtotal5));
                        }
                        if (P1 < FB1)
                        {
                            this.AmountSelected.Value = 0;
                            MessageBox.Show("the Total Price with Three Day shipping is" + (TDtotal6));
                        }
                    }
                }

    //Prior to the loop.

     public void Calc_button_On_Click(object sender, EventArgs e)
            {
                // set shipping rates 
                // standard shipping 
                decimal StandardShipping = .05m;

                decimal Bagfd = 50;
                decimal Bagbeaded = 45;
                decimal BagNPD = 40;
                decimal BagFr = 25;
                decimal BagFB = 30;
                decimal BagP = 20;
                // times the price per bag by the amount selected and provide a new variable of reference to call

                // matrix moved to if



                // set new variable to call and run this with the new variable set for the total price - shipping formula)

                decimal Fullbeaded1 = Bagfd * this.AmountSelected.Value;
                decimal Bb1 = Bagbeaded * this.AmountSelected.Value;
                decimal NPD1 = BagNPD * this.AmountSelected.Value;
                decimal Fr1 = BagFr * this.AmountSelected.Value;
                decimal FB1 = BagFB * this.AmountSelected.Value;
                decimal P1 = BagP * this.AmountSelected.Value;


                // Three day shipping
                decimal Threeday = .07m;

                decimal TDtotal = Fullbeaded1 + (Fullbeaded1 * Threeday);
                decimal TDtotal2 = Bb1 + (Bb1 * Threeday);
                decimal TDtotal3 = NPD1 + (NPD1 * Threeday);
                decimal TDtotal4 = Fr1 + (Fr1 * Threeday);
                decimal TDtotal5 = FB1 + (FB1 * Threeday);
                decimal TDtotal6 = P1 + (P1 * Threeday);
                //Three day solutions are the TDtotal - TDtotal6 series 

                // Overnight shipping 
                decimal OvernightV = .10m;

                decimal ON = Fullbeaded1 + (Fullbeaded1 * OvernightV);
                decimal ON2 = Bb1 + (Bb1 * OvernightV);
                decimal ON3 = NPD1 + (NPD1 * OvernightV);
                decimal ON4 = Fr1 + (Fr1 * OvernightV);
                decimal ON5 = FB1 + (FB1 * OvernightV);
                decimal ON6 = P1 + (P1 * OvernightV);
                // overnight solutions are the ON - ON6 series 
                //setting local fields variables

                Object RBStandard = true;

                Object RBOverNight = true;

                this.AmountSelected.Value = 0;
                
                bool RBThreeDay;
                bool RBSstandard;

                //Provide nested ifs a matrix of reference
                decimal StandardPriceTotal1 = Fullbeaded1 + (Fullbeaded1 * StandardShipping);
                decimal StandardPriceTotal2 = Bb1 + (Bb1 * StandardShipping);
                decimal StandardPriceTotal3 = NPD1 + (NPD1 * StandardShipping);
                decimal StandardPriceTotal4 = Fr1 + (Fr1 * StandardShipping);
                decimal StandardPriceTotal5 = FB1 + (FB1 * StandardShipping);
                decimal StandardPriceTotal6 = P1 + (P1 * StandardShipping);

    Tuesday, October 10, 2017 12:27 AM

All replies


  • Hi Wren Ryiuu,

    >>I have no Idea what syntax's to use to call the click events from 1(Combobox to select the bag type), 2(radiobutton), 2A(RadioButton2), 2B (RadioButton3) to use in my Calculate button. 

    You can use some Events to call Calc_button_On_Click envet.

         public void Calc_button_On_Click(object sender, EventArgs e)
            {
               //Do some data operations
            }
    
            //Combobox
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                Calc_button_On_Click(sender , e);
            }
    
            //RadioButton
            private void radioButton1_EnabledChanged(object sender, EventArgs e)
            {
                Calc_button_On_Click(sender, e);
            }
    


    >> Furthermore I do not know how to convert an event to a bool for an If loop to be created for my calculate button.

    You can try the following way to convert an event to a bool.

            public bool calculateFuction(string par1)
            {
                bool result = false;
                if (par1 == "")
                {
                    return result = true;
                }
                //....if
                return result;
            }
    

    If I have any misunderstanding, you can include all necessary code snippets for anyone else to be able to reproduce your issue from scratch along with a detailed description about the results including any exception messages.

    Best Regards,

    Yohann Lu



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Fei HuModerator Wednesday, October 11, 2017 11:50 AM
    Wednesday, October 11, 2017 2:53 AM
    Moderator