Esempio n. 1
0
        public override string[] printProperties(int ProductPlace)
        {
            Book         myBook = new Book();
            StreamReader readcustomerfile;

            readcustomerfile = File.OpenText(@"Products.txt");
            string[] properties = new string[6];
            string   info       = "";
            string   line;
            int      control = 0;
            int      first, last;

            while ((line = readcustomerfile.ReadLine()) != null)
            {
                control = line.IndexOf("ID : " + (100 + ProductPlace));
                if (control != -1)
                {
                    //Set ID To Book With Read Text File
                    first = line.IndexOf("ID : ") + "ID : ".Length;
                    last  = line.IndexOf(",Name");
                    info  = line.Substring(first, last - first);
                    myBook.setID(Convert.ToInt32(info));
                    properties[0] = myBook.getID().ToString();

                    //Set Name To Book With Read Text File
                    first = line.IndexOf("Name : ") + "Name : ".Length;
                    last  = line.IndexOf(",Price");
                    info  = line.Substring(first, last - first);
                    myBook.setName(info);
                    properties[1] = myBook.getName();


                    //Set Price To Book With Read Text File
                    first = line.IndexOf("Price : ") + "Price : ".Length;
                    last  = line.IndexOf(",ISBN");
                    info  = line.Substring(first, last - first);
                    myBook.setPrice(Convert.ToInt32(info));
                    properties[2] = myBook.getPrice().ToString();


                    //Set ISBN To Book With Read Text File
                    first = line.IndexOf("ISBN : ") + "ISBN : ".Length;
                    last  = line.IndexOf(",Author");
                    info  = line.Substring(first, last - first);
                    myBook.setISBN(Convert.ToInt32(info));
                    properties[3] = myBook.getISBN().ToString();


                    //Set Author To Book With Read Text File
                    first = line.IndexOf("Author : ") + "Author : ".Length;
                    last  = line.IndexOf(",Publisher");
                    info  = line.Substring(first, last - first);
                    myBook.setAuthor(info);
                    properties[4] = myBook.getAuthor();


                    //Set Publisher To Book With Read Text File
                    first = line.IndexOf("Publisher : ") + "Publisher : ".Length;
                    last  = line.Length;
                    info  = line.Substring(first, last - first);
                    myBook.setPublisher(info);
                    properties[5] = myBook.getPublisher();
                }
            }
            return(properties);
        }
Esempio n. 2
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();
                     }
                 }
             }
         }
     }
 }