Example #1
0
        /// <summary>
        /// This function add book button click operation.
        /// This function is used to add product list and save for util function.
        /// </summary>
        /// <returns> This function does not return a value  </returns>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Logger.GetLogger().WriteLog(LoginedCustomer.getInstance().User.Username, btnAdd.Text, DateTime.Now);
            if (!isBlank())
            {
                MessageBox.Show("Please fill all blanks!");
                return;
            }
            else if (pboxBook.Image == null)
            {
                MessageBox.Show("Please select an image.");
                return;
            }
            else if (isExist())
            {
                MessageBox.Show("Please change product ID! It's already taken.");
                return;
            }
            NumberFormatInfo provider = new NumberFormatInfo();

            provider.NumberDecimalSeparator = ".";
            Creator c = new BookFactory(txtName.Text, txtID.Text, Convert.ToDouble(txtPrice.Text, provider), txtISBN.Text, txtAuthor.Text,
                                        txtPublisher.Text, Convert.ToInt32(txtPages.Text), pboxBook.Image);

            string[]     lvItem = { txtID.Text, txtName.Text, txtPrice.Text, txtISBN.Text, txtAuthor.Text, txtPublisher.Text, txtPages.Text };
            ListViewItem item   = new ListViewItem(lvItem);

            listViewBooks.Items.Add(item);
            StoreMainScreen.productList.Add(c.FactoryMethod());
            UtilSave.Save(c.FactoryMethod());
            MessageBox.Show("Added succesfully!");
            listViewBooks.Refresh();
            panelAddBook.Visible = false;
        }
Example #2
0
        /// <summary>
        /// This function update book button click operation.
        /// This function is used to update product list and update for util function.
        /// </summary>
        /// <returns> This function does not return a value  </returns>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            Logger.GetLogger().WriteLog(LoginedCustomer.getInstance().User.Username, btnUpdate.Text, DateTime.Now);
            if (!isBlank())
            {
                MessageBox.Show("Please fill all blanks!");
                return;
            }
            else if (pboxBook.Image == null)
            {
                MessageBox.Show("Please select an image.");
                return;
            }
            NumberFormatInfo provider = new NumberFormatInfo();

            provider.NumberDecimalSeparator = ".";
            Creator c = new BookFactory(txtName.Text, txtID.Text, Convert.ToDouble(txtPrice.Text, provider), txtISBN.Text, txtAuthor.Text,
                                        txtPublisher.Text, Convert.ToInt32(txtPages.Text), pboxBook.Image);

            string[]     lvItem = { txtID.Text, txtName.Text, txtPrice.Text, txtISBN.Text, txtAuthor.Text, txtPublisher.Text, txtPages.Text };
            ListViewItem item   = new ListViewItem(lvItem);

            for (int i = 0; i < listViewBooks.Items.Count; i++)
            {
                if (listViewBooks.Items[i].SubItems[0].Text == selectedID)
                {
                    listViewBooks.Items[i] = item;
                    break;
                }
            }
            for (int i = 0; i < StoreMainScreen.productList.Count; i++)
            {
                if (StoreMainScreen.productList[i].ID1 == selectedID)
                {
                    StoreMainScreen.productList[i] = c.FactoryMethod();
                    break;
                }
            }
            UtilUpdate.Update(c.FactoryMethod());
            MessageBox.Show("Updated Succesfully!");
            panelAddBook.Visible = false;
            selectedIndex        = -1;
        }
Example #3
0
        /// <summary>
        ///  This function loads the elements of the ShoppingCard.xml file.
        /// </summary>
        /// <param name="shoppingCardList">This parameter is a list of ShoppingCard class.</param>
        /// <returns> This function does not return a value  </returns>
        public static void Load(List <ShoppingCard> shoppingCardList)
        {
            if (!File.Exists(@"data/ShoppingCard.xml"))
            {
                XmlTextWriter writer = new XmlTextWriter(@"data/ShoppingCard.xml", System.Text.Encoding.UTF8);
                writer.WriteStartDocument(true);
                writer.Formatting  = Formatting.Indented;
                writer.Indentation = 2;
                writer.WriteStartElement("ShoppingCards");
                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Close();
                return;
            }
            XDocument        xDoc = XDocument.Load(@"data/ShoppingCard.xml");
            XElement         shoppingCardRootElement = xDoc.Root;
            NumberFormatInfo info = new NumberFormatInfo();

            info.NumberDecimalSeparator = ".";
            foreach (XElement shoppingCard in shoppingCardRootElement.Elements())
            {
                string      customerID = shoppingCard.FirstAttribute.Value;
                double      amount     = Convert.ToDouble(shoppingCard.Element("PaymentAmount").Value, info);
                PaymentType type       = PaymentType.cash;
                if (shoppingCard.Element("PaymentType").Value == "creditcard")
                {
                    type = PaymentType.creditcard;
                }
                List <ItemToPurchase> tempitemsToPurchase = new List <ItemToPurchase>();
                XElement itemToPurchaseRootElement        = shoppingCard.Element("ItemToPurchaseList");
                foreach (XElement item in itemToPurchaseRootElement.Elements())
                {
                    ItemToPurchase itemToPurchase = new ItemToPurchase();
                    string         classType      = item.FirstAttribute.Value;
                    string         ID             = item.Element("id").Value;
                    string         name           = item.Element("name").Value;
                    double         price          = Convert.ToDouble(item.Element("price").Value, info);
                    Image          image          = UtilConvert.Base64ToImage(item.Element("image").Value);
                    Creator        c;
                    if (classType == "Book")
                    {
                        c = new BookFactory(name, ID, price, "", "", "", 0, image);
                        itemToPurchase.Product = c.FactoryMethod();
                    }
                    else if (classType == "Magazine")
                    {
                        c = new MagazineFactory(name, ID, price, "", Magazine_Type.Actual, image);
                        itemToPurchase.Product = c.FactoryMethod();
                    }
                    else
                    {
                        c = new MusicCdFactory(name, ID, price, "", MusicCD_Type.Country, image);
                        itemToPurchase.Product = c.FactoryMethod();
                    }
                    itemToPurchase.Quantity = Int32.Parse(item.Element("quantity").Value);
                    tempitemsToPurchase.Add(itemToPurchase);
                }
                ShoppingCard shoppCard = new ShoppingCard();
                shoppCard.itemsToPurchase = tempitemsToPurchase;
                shoppCard.PaymentAmount   = amount;
                shoppCard.CustomerID      = customerID;
                shoppCard.Type            = type;
                shoppingCardList.Add(shoppCard);
            }
        }
Example #4
0
        /// <summary>
        ///  This function loads the elements of the MyOrders.xml file.
        /// </summary>
        /// <param name="OrderList">This parameter is a list of ShoppingCard class.</param>
        /// <returns> This function does not return a value  </returns>
        public static void LoadOrder(List <ShoppingCard> OrderList)
        {
            if (!File.Exists(@"data/MyOrders.xml"))
            {
                XmlTextWriter writer = new XmlTextWriter(@"data/MyOrders.xml", System.Text.Encoding.UTF8);
                writer.WriteStartDocument(true);
                writer.Formatting  = Formatting.Indented;
                writer.Indentation = 2;
                writer.WriteStartElement("Orders");
                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Close();
                return;
            }
            XDocument        xDoc             = XDocument.Load(@"data/MyOrders.xml");
            XElement         OrderRootElement = xDoc.Root;
            NumberFormatInfo info             = new NumberFormatInfo();

            info.NumberDecimalSeparator = ".";
            foreach (XElement order in OrderRootElement.Elements())
            {
                string      customerID = order.FirstAttribute.Value;
                double      amount     = Convert.ToDouble(order.Element("PaymentAmount").Value, info);
                PaymentType type       = PaymentType.cash;
                if (order.Element("PaymentType").Value == "creditcard")
                {
                    type = PaymentType.creditcard;
                }
                else if (order.Element("PaymentType").Value == "transfer")
                {
                    type = PaymentType.transfer;
                }
                OrderStatus orderStatus = OrderStatus.canceled;
                if (order.Element("OrderStatus").Value == "received")
                {
                    orderStatus = OrderStatus.received;
                }
                else if (order.Element("OrderStatus").Value == "shipped")
                {
                    orderStatus = OrderStatus.shipped;
                }
                else if (order.Element("OrderStatus").Value == "waitForShip")
                {
                    orderStatus = OrderStatus.waitForShip;
                }
                int cargoamount = Convert.ToInt32(order.Element("CargoAmount").Value);
                int oid         = Convert.ToInt32(order.LastAttribute.Value);
                List <ItemToPurchase> tempitemsToPurchase = new List <ItemToPurchase>();
                XElement itemToPurchaseRootElement        = order.Element("ItemToPurchaseList");
                foreach (XElement item in itemToPurchaseRootElement.Elements())
                {
                    ItemToPurchase itemToPurchase = new ItemToPurchase();
                    string         id             = item.Element("id").Value;
                    string         name           = item.Element("name").Value;
                    double         price          = Convert.ToDouble(item.Element("price").Value, info);
                    int            quantity       = Convert.ToInt32(item.Element("quantity").Value);
                    Image          image          = UtilConvert.Base64ToImage(item.Element("image").Value);
                    Creator        c;
                    if (item.FirstAttribute.Value == "Book")
                    {
                        c = new BookFactory(name, id, price, "", "", "", 0, image);
                        itemToPurchase.Product  = c.FactoryMethod();
                        itemToPurchase.Quantity = quantity;
                        tempitemsToPurchase.Add(itemToPurchase);
                    }
                    else if (item.FirstAttribute.Value == "Magazine")
                    {
                        c = new MagazineFactory(name, id, price, "", Magazine_Type.Actual, image);
                        itemToPurchase.Product  = c.FactoryMethod();
                        itemToPurchase.Quantity = quantity;
                        tempitemsToPurchase.Add(itemToPurchase);
                    }
                    else
                    {
                        c = new MusicCdFactory(name, id, price, "", MusicCD_Type.Country, image);
                        itemToPurchase.Product  = c.FactoryMethod();
                        itemToPurchase.Quantity = quantity;
                        tempitemsToPurchase.Add(itemToPurchase);
                    }
                }
                ShoppingCard _order = new ShoppingCard();
                _order.itemsToPurchase = tempitemsToPurchase;
                _order.PaymentAmount   = amount;
                _order.CustomerID      = customerID;
                _order.Type            = type;
                _order.Status          = orderStatus;
                _order.CargoAmount     = cargoamount;
                _order.OID             = oid;
                OrderList.Add(_order);
            }
        }