Example #1
0
 //*****************************************************
 //Procudure: Volume
 // Checks for exsiting Cylinder and uses volume from that
 // otherwise it creates a new instance and show a message
 // box with the calculated Volume.
 //*****************************************************
 private void btnVolume_Click(object sender, EventArgs e)
 {
     if (rdoCircle.Checked)
     {
         txtError.Text = "Circles do not have volume.";
     }
     else
     {
         if (txtRadius.Text.Trim().Length > 0 && txtHeight.Text.Trim().Length > 0)
         {
             decimal decRad;
             decimal decHgt;
             if (Cylinder == null)
             {
                 try
                 {
                     decHgt   = Convert.ToDecimal(txtHeight.Text);
                     decRad   = Convert.ToDecimal(txtRadius.Text);
                     Cylinder = new clsCylinder(decRad, decHgt);
                 }
                 catch (Exception ex)
                 {
                     txtError.Text = "Radius and Height must be numeric." + ex.Message;
                 }
             }
             else if (Cylinder.Height != Convert.ToDecimal(txtHeight.Text) || Cylinder.Radius != Convert.ToDecimal(txtRadius.Text))
             {
                 try
                 {
                     decHgt   = Convert.ToDecimal(txtHeight.Text);
                     decRad   = Convert.ToDecimal(txtRadius.Text);
                     Cylinder = new clsCylinder(decRad, decHgt);
                 }
                 catch (Exception ex)
                 {
                     txtError.Text = "Radius and Height must be numeric." + ex.Message;
                 }
             }
             else
             {
                 MessageBox.Show(Cylinder.Volume().ToString());
             }
             btnArea.Enabled          = true;
             btnCircumference.Enabled = true;
             btnDefinition.Enabled    = true;
             btnDispose.Enabled       = true;
             btnVolume.Enabled        = true;
             //MessageBox.Show(Cylinder.Volume().ToString());
             txtVolume.Text = Cylinder.Volume().ToString();
         }
         else
         {
             txtError.Text = "Radius and Height must be greater then zero.";
         }
     }
 }
Example #2
0
        //**************************************
        //Procedure: Dispose
        //**************************************

        private void DisposeForm()
        {
            rdoCircle.Checked = true;
            txtVolume.Clear();
            txtArea.Clear();
            txtCircumference.Clear();
            txtHeight.Clear();
            txtRadius.Clear();
            btnDefinition.Enabled = false;
            btnVolume.Enabled     = false;
            btnDispose.Enabled    = false;
            txtError.Text         = "";
            Circles  = null;
            Cylinder = null;
        }
Example #3
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            if (rdoCircle.Checked)
            {
                if (txtRadius.Text.Trim().Length > 0)
                {
                    decimal decRad;
                    if (Circles == null)
                    {
                        try
                        {
                            decRad  = Convert.ToDecimal(txtRadius.Text);
                            Circles = new clsCircle(decRad);
                        }
                        catch (Exception ex)
                        {
                            txtError.Text = "Radius must be numeric." + ex.Message;
                        }
                    }
                    else
                    {
                        txtError.Text = "Circle already exists.";
                    }
                    btnArea.Enabled          = true;
                    btnCircumference.Enabled = true;
                    btnDefinition.Enabled    = true;
                    btnDispose.Enabled       = true;
                    txtCircumference.Text    = Circles.Circumference().ToString();
                    txtArea.Text             = Circles.Area().ToString();
                }
                else
                {
                    txtError.Text = "Radius must be greater then zero.";
                }
            }
            else
            {
                if (txtRadius.Text.Trim().Length > 0 && txtHeight.Text.Trim().Length > 0)
                {
                    decimal decRad;
                    decimal decHgt;

                    if (Cylinder == null)
                    {
                        try
                        {
                            decHgt   = Convert.ToDecimal(txtHeight.Text);
                            decRad   = Convert.ToDecimal(txtRadius.Text);
                            Cylinder = new clsCylinder(decRad, decHgt);
                        }
                        catch (Exception ex)
                        {
                            txtError.Text = "Radius and Height must be numeric." + ex.Message;
                        }
                    }
                    else
                    {
                        txtError.Text = "Cylinder already exists.";
                    }
                    btnArea.Enabled          = true;
                    btnCircumference.Enabled = true;
                    btnDefinition.Enabled    = true;
                    btnDispose.Enabled       = true;
                    btnVolume.Enabled        = true;
                    txtCircumference.Text    = Cylinder.Circumference().ToString();
                    txtArea.Text             = Cylinder.Area().ToString();
                    txtVolume.Text           = Cylinder.Volume().ToString();
                }
                else
                {
                    txtError.Text = "Radius and Height must be greater then zero.";
                }
            }
        }