Example #1
0
 private void btnSell_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.tbNameSalesperson.Text == "")
         {
             MessageBox.Show("Please, type a name for the salesperson");
         }
         else
         {
             Candy c;
             if (rbMixedCandy.Checked)
             {
                 c = new MixedCandy(this.tbNameSalesperson.Text,
                                    this.pricePerKilogramMixedCandy,
                                    Convert.ToInt32(this.tbWeightOfLollipops.Text),
                                    Convert.ToInt32(this.tbWeightOfChewingGums.Text),
                                    Convert.ToInt32(this.tbWeightOfGummyDrops.Text));
             }
             else
             {
                 c = new PackedCandy(this.tbNameSalesperson.Text,
                                     this.namesPackedCandy[this.lbPackedCandy.SelectedIndex],
                                     this.pricesPackedCandy[this.lbPackedCandy.SelectedIndex],
                                     Convert.ToInt32(this.tbNumberOfBags.Text));
             }
             this.myStore.AddCandy(c);
         }
     }
     catch (FormatException) { MessageBox.Show("Please, type a number"); }
     catch (IndexOutOfRangeException) { MessageBox.Show("Select a packed candy first"); }
 }
Example #2
0
 private void btnSell_Click(object sender, EventArgs e)
 {
     //todo, assignment 3
     try
     {
         if (tbNameSalesperson.Text == "")
         {
             MessageBox.Show("Enter a salesman name.");
         }
         else
         {
             Candy candy = null;
             if (rbPackedCandy.Checked)
             {
                 if (Convert.ToInt32(tbNumberOfBags.Text) < 1)
                 {
                     MessageBox.Show("You should enter a number at least equal to 1");
                 }
                 else
                 {
                     candy = new PackedCandy(tbNameSalesperson.Text, namesPackedCandy[lbPackedCandy.SelectedIndex], pricesPackedCandy[lbPackedCandy.SelectedIndex], Convert.ToInt32(tbNumberOfBags.Text));
                 }
             }
             else
             {
                 candy = new MixedCandy(tbNameSalesperson.Text, pricePerKilogramMixedCandy, Convert.ToInt32(tbWeightOfLollipops.Text), Convert.ToInt32(tbWeightOfChewingGums.Text), Convert.ToInt32(tbWeightOfGummyDrops.Text));
             }
             myStore.AddCandy(candy);
         }
     }
     catch (FormatException)
     {
         if (rbPackedCandy.Checked)
         {
             if (tbNumberOfBags.Text == "")
             {
                 tbNumberOfBags.Text = "1";
                 MessageBox.Show("You have to buy at least one bag.");
             }
         }
         else if (tbWeightOfLollipops.Text == "" || tbWeightOfChewingGums.Text == "" || tbWeightOfGummyDrops.Text == "")
         {
             MessageBox.Show("Enter a valid weight of all the three candies.");
         }
         else
         {
             MessageBox.Show("Invalid input format!");
         }
     }
     catch (IndexOutOfRangeException)
     {
         MessageBox.Show("You didn't select a candy!");
     }
 }