Пример #1
0
 private void btnRemoveProduct_Click(object sender, EventArgs e)
 {
     if (cbRemovedProductQuantity.Text == "")
     {
         MessageBox.Show("Please Set Quantity!");
     }
     else
     {
         string[] properties;
         int      place = 0;
         for (int i = 0; i < listProducts.Items.Count; i++)
         {
             if (listProducts.Items[i].Selected == true)
             {
                 int newQuantity = 0;
                 if (Convert.ToInt32(listProducts.Items[i].SubItems[0].Text) > 100 && Convert.ToInt32(listProducts.Items[i].SubItems[0].Text) < 200)
                 {
                     properties = new string[PropertiesCountOfItem("Book")];
                     Book myBook = new Book();
                     place      = Convert.ToInt32(listProducts.Items[i].SubItems[0].Text) - 100;
                     properties = myBook.printProperties(place);
                     myBook.setID(Convert.ToInt32(properties[0]));
                     myBook.setName(properties[1]);
                     myBook.setPrice(Convert.ToInt32(properties[2]));
                     myBook.setISBN(Convert.ToInt32(properties[3]));
                     myBook.setAuthor(properties[4]);
                     myBook.setPublisher(properties[5]);
                     ItemToPurchase item = new ItemToPurchase(myBook, Convert.ToInt32(cbRemovedProductQuantity.Text));
                     myShoppingCart.removeProduct(item);
                     if (Convert.ToInt32(cbRemovedProductQuantity.Text) >= Convert.ToInt32(listProducts.Items[i].SubItems[3].Text))
                     {
                         listProducts.Items[i].Remove();
                     }
                     else
                     {
                         newQuantity = Convert.ToInt32(listProducts.Items[i].SubItems[3].Text) - Convert.ToInt32(cbRemovedProductQuantity.Text);
                         listProducts.Items[i].SubItems[3].Text = newQuantity.ToString();
                         listProducts.Refresh();
                     }
                 }
                 else if (Convert.ToInt32(listProducts.Items[i].SubItems[0].Text) > 200 && Convert.ToInt32(listProducts.Items[i].SubItems[0].Text) < 300)
                 {
                     properties = new string[PropertiesCountOfItem("Magazine")];
                     Magazine myMagazine = new Magazine();
                     place      = Convert.ToInt32(listProducts.Items[i].SubItems[0].Text) - 200;
                     properties = myMagazine.printProperties(place);
                     myMagazine.setID(Convert.ToInt32(properties[0]));
                     myMagazine.setName(properties[1]);
                     myMagazine.setPrice(Convert.ToInt32(properties[2]));
                     myMagazine.setissue(properties[3]);
                     myMagazine.setType(properties[4]);
                     ItemToPurchase item = new ItemToPurchase(myMagazine, Convert.ToInt32(cbRemovedProductQuantity.Text));
                     myShoppingCart.removeProduct(item);
                     if (Convert.ToInt32(cbRemovedProductQuantity.Text) >= Convert.ToInt32(listProducts.Items[i].SubItems[3].Text))
                     {
                         listProducts.Items[i].Remove();
                     }
                     else
                     {
                         newQuantity = Convert.ToInt32(listProducts.Items[i].SubItems[3].Text) - Convert.ToInt32(cbRemovedProductQuantity.Text);
                         listProducts.Items[i].SubItems[3].Text = newQuantity.ToString();
                         listProducts.Refresh();
                     }
                 }
                 else
                 {
                     properties = new string[PropertiesCountOfItem("MusicCD")];
                     MusicCD myMusicCD = new MusicCD();
                     place      = Convert.ToInt32(listProducts.Items[i].SubItems[0].Text) - 300;
                     properties = myMusicCD.printProperties(place);
                     myMusicCD.setID(Convert.ToInt32(properties[0]));
                     myMusicCD.setName(properties[1]);
                     myMusicCD.setPrice(Convert.ToInt32(properties[2]));
                     myMusicCD.setsinger(properties[3]);
                     myMusicCD.setType(properties[4]);
                     ItemToPurchase item = new ItemToPurchase(myMusicCD, Convert.ToInt32(cbRemovedProductQuantity.Text));
                     myShoppingCart.removeProduct(item);
                     if (Convert.ToInt32(cbRemovedProductQuantity.Text) >= Convert.ToInt32(listProducts.Items[i].SubItems[3].Text))
                     {
                         listProducts.Items[i].Remove();
                     }
                     else
                     {
                         newQuantity = Convert.ToInt32(listProducts.Items[i].SubItems[3].Text) - Convert.ToInt32(cbRemovedProductQuantity.Text);
                         listProducts.Items[i].SubItems[3].Text = newQuantity.ToString();
                         listProducts.Refresh();
                     }
                 }
             }
         }
     }
 }