예제 #1
0
        private void CreateAndListForMagazine(ListView listview)
        {
            CreatorProduct myProduct = new CreatorProduct();
            int            count     = ItemCount("Magazine") + ItemCount("Book") + ItemCount("MusicCD");

            Product[] myProducts = new Product[count];
            string[]  properties = new string[PropertiesCountOfItem("Magazine")];
            int       place      = 1;

            for (int i = 0; i < ItemCount("Magazine"); i++)
            {
                myProducts[i] = myProduct.FactoryMethod(ProductType.Magazine);
                properties    = myProducts[i].printProperties(place);
                string[] row  = { properties[0], properties[1], properties[2], properties[3], properties[4] };
                var      line = new ListViewItem(row);
                listview.Items.Add(line);
                place++;
            }

            listview.View          = View.Details;
            listview.GridLines     = true;
            listview.FullRowSelect = true;
            listview.Columns.Add("ID", 30);
            listview.Columns.Add("Name", 80);
            listview.Columns.Add("Price", 40);
            listview.Columns.Add("Issue", 100);
            listview.Columns.Add("Type", 100);
        }
예제 #2
0
        private void btnAddProduct_Click_1(object sender, EventArgs e)
        {
            if (cbProductQuantity.Text == "")
            {
                MessageBox.Show("Please Set Quantity!");
            }
            else
            {
                CreatorProduct myProduct = new CreatorProduct();
                string[]       myArray   = new string[2];
                myArray = ProductTypeControl();



                if (myArray[0] == "Book")
                {
                    Product myBook = myProduct.FactoryMethod(ProductType.Book);
                    myBook.setID(Convert.ToInt32(listBook.Items[Convert.ToInt32(myArray[1])].SubItems[0].Text));
                    myBook.setName(listBook.Items[Convert.ToInt32(myArray[1])].SubItems[1].Text);
                    myBook.setPrice(Convert.ToInt32(listBook.Items[Convert.ToInt32(myArray[1])].SubItems[2].Text));
                    ItemToPurchase item = new ItemToPurchase(myBook, Convert.ToInt32(cbProductQuantity.Text));
                    myShoppingCart.addProduct(item);
                    string[] row  = myShoppingCart.printProducts(item);
                    var      line = new ListViewItem(row);
                    listProducts.Items.Add(line);
                }
                else if (myArray[0] == "MusicCD")
                {
                    Product myMusicCD = myProduct.FactoryMethod(ProductType.MusicCD);
                    myMusicCD.setID(Convert.ToInt32(listMusicCD.Items[Convert.ToInt32(myArray[1])].SubItems[0].Text));
                    myMusicCD.setName(listMusicCD.Items[Convert.ToInt32(myArray[1])].SubItems[1].Text);
                    myMusicCD.setPrice(Convert.ToInt32(listMusicCD.Items[Convert.ToInt32(myArray[1])].SubItems[2].Text));
                    ItemToPurchase item = new ItemToPurchase(myMusicCD, Convert.ToInt32(cbProductQuantity.Text));
                    myShoppingCart.addProduct(item);
                    string[] row  = myShoppingCart.printProducts(item);
                    var      line = new ListViewItem(row);
                    listProducts.Items.Add(line);
                }
                else if (myArray[0] == "Magazine")
                {
                    Product myMagazine = myProduct.FactoryMethod(ProductType.Magazine);
                    myMagazine.setID(Convert.ToInt32(listMagazine.Items[Convert.ToInt32(myArray[1])].SubItems[0].Text));
                    myMagazine.setName(listMagazine.Items[Convert.ToInt32(myArray[1])].SubItems[1].Text);
                    myMagazine.setPrice(Convert.ToInt32(listMagazine.Items[Convert.ToInt32(myArray[1])].SubItems[2].Text));
                    ItemToPurchase item = new ItemToPurchase(myMagazine, Convert.ToInt32(cbProductQuantity.Text));
                    myShoppingCart.addProduct(item);
                    string[] row  = myShoppingCart.printProducts(item);
                    var      line = new ListViewItem(row);
                    listProducts.Items.Add(line);
                }
            }
        }