Exemplo n.º 1
0
        /// <summary>
        /// This function save elements of the ProductList.xml file.
        /// </summary>
        /// <param name="product">This parameter is a object of Product class.</param>
        /// <returns> This function does not return a value </returns>
        public static void Save(Product product)
        {
            XDocument xDoc              = XDocument.Load(@"data/ProductList.xml");
            XElement  rootElement       = xDoc.Root;
            XElement  newElementProduct = new XElement("Product");

            if (product is Book)
            {
                Book       temp         = (Book)product;
                XAttribute attClassType = new XAttribute("Class", "Book");
                XAttribute attID        = new XAttribute("ID", temp.ID1);
                XElement   name         = new XElement("Name", temp.Name);
                XElement   price        = new XElement("Price", temp.Price);
                XElement   image        = new XElement("Image", UtilConvert.ImageToBase64(temp.Image, temp.Image.RawFormat));
                XElement   isbn         = new XElement("ISBN", temp.ISBN1);
                XElement   author       = new XElement("Author", temp.Author);
                XElement   publisher    = new XElement("Publisher", temp.Publisher);
                XElement   pages        = new XElement("Pages", temp.Pages);
                newElementProduct.Add(attClassType, attID, name, price, image, isbn, author, publisher, pages);
                rootElement.Add(newElementProduct);
                xDoc.Save(@"data/ProductList.xml");
                return;
            }
            else if (product is Magazine)
            {
                Magazine   temp         = (Magazine)product;
                XAttribute attClassType = new XAttribute("Class", "Magazine");
                XAttribute attID        = new XAttribute("ID", temp.ID1);
                XElement   name         = new XElement("Name", temp.Name);
                XElement   price        = new XElement("Price", temp.Price);
                XElement   image        = new XElement("Image", UtilConvert.ImageToBase64(temp.Image, temp.Image.RawFormat));
                XElement   issue        = new XElement("Issue", temp.Issue);
                XElement   magazineType = new XElement("MagazineType", temp.Type);
                newElementProduct.Add(attClassType, attID, name, price, image, issue, magazineType);
                rootElement.Add(newElementProduct);
                xDoc.Save(@"data/ProductList.xml");
                return;
            }
            else
            {
                MusicCD    temp         = (MusicCD)product;
                XAttribute attClassType = new XAttribute("Class", "MusicCD");
                XAttribute attID        = new XAttribute("ID", temp.ID1);
                XElement   name         = new XElement("Name", temp.Name);
                XElement   price        = new XElement("Price", temp.Price);
                XElement   image        = new XElement("Image", UtilConvert.ImageToBase64(temp.Image, temp.Image.RawFormat));
                XElement   singer       = new XElement("Singer", temp.Singer);
                XElement   musicCDType  = new XElement("MusicCDType", temp.Type);
                newElementProduct.Add(attClassType, attID, name, price, image, singer, musicCDType);
                rootElement.Add(newElementProduct);
                xDoc.Save(@"data/ProductList.xml");
                return;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// This function update elements of the ProductList.xml file.
 /// </summary>
 /// <param name="product">This parameter is a object of Product class.</param>
 /// <returns> This function does not return a value </returns>
 public static void Update(Product product)
 {
     try
     {
         XDocument xDoc        = XDocument.Load(@"data/ProductList.xml");
         XElement  rootElement = xDoc.Root;
         foreach (XElement item in rootElement.Elements())
         {
             if (item.Attribute("ID").Value == product.ID1)
             {
                 if (product is Book)
                 {
                     Book temp = (Book)product;
                     item.Element("Name").Value      = temp.Name;
                     item.Element("Price").Value     = temp.Price.ToString();
                     item.Element("Image").Value     = UtilConvert.ImageToBase64(temp.Image, temp.Image.RawFormat);
                     item.Element("ISBN").Value      = temp.ISBN1;
                     item.Element("Author").Value    = temp.Author;
                     item.Element("Publisher").Value = temp.Publisher;
                     item.Element("Pages").Value     = temp.Pages.ToString();
                     xDoc.Save(@"data/ProductList.xml");
                     return;
                 }
                 else if (product is Magazine)
                 {
                     Magazine temp = (Magazine)product;
                     item.Element("Name").Value         = temp.Name;
                     item.Element("Price").Value        = temp.Price.ToString();
                     item.Element("Image").Value        = UtilConvert.ImageToBase64(temp.Image, temp.Image.RawFormat);
                     item.Element("Issue").Value        = temp.Issue;
                     item.Element("MagazineType").Value = temp.Type.ToString();
                     xDoc.Save(@"data/ProductList.xml");
                     return;
                 }
                 else
                 {
                     MusicCD temp = (MusicCD)product;
                     item.Element("Name").Value        = temp.Name;
                     item.Element("Price").Value       = temp.Price.ToString();
                     item.Element("Image").Value       = UtilConvert.ImageToBase64(temp.Image, temp.Image.RawFormat);
                     item.Element("Singer").Value      = temp.Singer;
                     item.Element("MusicCDType").Value = temp.Type.ToString();
                     xDoc.Save(@"data/ProductList.xml");
                     return;
                 }
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// This function save elements of the MyOrders.xml file.
 /// </summary>
 /// <param name="shoppingCard">This parameter is a object of ShoppingCard class.</param>
 /// <returns> This function does not return a value </returns>
 public static void SaveOrder(ShoppingCard shoppingCard)
 {
     try
     {
         XDocument  xDoc                      = XDocument.Load(@"data/MyOrders.xml");
         XElement   rootElement               = xDoc.Root;
         XElement   newElementOrder           = new XElement("Order");
         XAttribute OrderAttribute            = new XAttribute("CustomerID", shoppingCard.CustomerID);
         XAttribute orderID                   = new XAttribute("OrderID", (shoppingCard.OID).ToString());
         XElement   PaymentAmount             = new XElement("PaymentAmount", shoppingCard.PaymentAmount);
         XElement   PaymentType               = new XElement("PaymentType", shoppingCard.Type);
         XElement   OrderStatus               = new XElement("OrderStatus", shoppingCard.Status);
         XElement   CargoAmount               = new XElement("CargoAmount", shoppingCard.CargoAmount);
         XElement   ItemToPurchaseListElement = new XElement("ItemToPurchaseList");
         for (int i = 0; i < shoppingCard.itemsToPurchase.Count; i++)
         {
             XElement   newElementItemToPurchase = new XElement("ItemToPurchase");
             XAttribute classType;
             XElement   ID    = new XElement("id", shoppingCard.itemsToPurchase[i].Product.ID1);
             XElement   name  = new XElement("name", shoppingCard.itemsToPurchase[i].Product.Name);
             XElement   price = new XElement("price", shoppingCard.itemsToPurchase[i].Product.Price);
             XElement   image = new XElement("image", UtilConvert.ImageToBase64(shoppingCard.itemsToPurchase[i].Product.Image,
                                                                                shoppingCard.itemsToPurchase[i].Product.Image.RawFormat));
             XElement quantity = new XElement("quantity", shoppingCard.itemsToPurchase[i].Quantity);
             if (shoppingCard.itemsToPurchase[i].Product is Book)
             {
                 classType = new XAttribute("classType", "Book");
             }
             else if (shoppingCard.itemsToPurchase[i].Product is Magazine)
             {
                 classType = new XAttribute("classType", "Magazine");
             }
             else
             {
                 classType = new XAttribute("classType", "MusicCD");
             }
             newElementItemToPurchase.Add(classType, ID, name, price, image, quantity);
             ItemToPurchaseListElement.Add(newElementItemToPurchase);
         }
         newElementOrder.Add(OrderAttribute, orderID, PaymentAmount, PaymentType, OrderStatus, CargoAmount, ItemToPurchaseListElement);
         rootElement.Add(newElementOrder);
         xDoc.Save(@"data/MyOrders.xml");
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// This function save elements of the ShoppingCard.xml file.
        /// </summary>
        /// <param name="shoppingCard">This parameter is a object of ShoppingCard class.</param>
        /// <param name="i">This parameter  hold a last element.</param>
        /// <returns> This function does not return a value </returns>
        public static void Save(ShoppingCard shoppingCard, int i)
        {
            i--;
            XDocument xDoc = XDocument.Load(@"data/ShoppingCard.xml");
            XElement  shoppingCardRootElement = xDoc.Root;

            foreach (XElement Card in shoppingCardRootElement.Elements())
            {
                if (Card.Attribute("CustomerID").Value == shoppingCard.CustomerID)
                {
                    Card.Element("PaymentAmount").Value = shoppingCard.PaymentAmount.ToString();
                    XElement   newElementItemToPurchase = new XElement("ItemToPurchase");
                    XAttribute classType;
                    XElement   ID    = new XElement("id", shoppingCard.itemsToPurchase[i].Product.ID1);
                    XElement   name  = new XElement("name", shoppingCard.itemsToPurchase[i].Product.Name);
                    XElement   price = new XElement("price", shoppingCard.itemsToPurchase[i].Product.Price);
                    XElement   image = new XElement("image", UtilConvert.ImageToBase64(shoppingCard.itemsToPurchase[i].Product.Image,
                                                                                       shoppingCard.itemsToPurchase[i].Product.Image.RawFormat));
                    XElement quantity = new XElement("quantity", shoppingCard.itemsToPurchase[i].Quantity);
                    if (shoppingCard.itemsToPurchase[i].Product is Book)
                    {
                        classType = new XAttribute("classType", "Book");
                    }
                    else if (shoppingCard.itemsToPurchase[i].Product is Magazine)
                    {
                        classType = new XAttribute("classType", "Magazine");
                    }
                    else
                    {
                        classType = new XAttribute("classType", "MusicCD");
                    }
                    newElementItemToPurchase.Add(classType, ID, name, price, image, quantity);
                    Card.Element("ItemToPurchaseList").Add(newElementItemToPurchase);
                }
                xDoc.Save(@"data/ShoppingCard.xml");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// This function signup button click operation.
        /// This function is used to sign up application.
        /// </summary>
        /// <returns> This function does not return a value  </returns>
        private void btnSignUp_Click(object sender, EventArgs e)
        {
            Logger.GetLogger().WriteLog("Unknown user", btnSignUp.Text, DateTime.Now);
            if (!IsEmptyTextbox())
            {
                MessageBox.Show("You have to fill all fields.");
                return;
            }
            else if (!IsValidEmail(txtMail.Text))
            {
                MessageBox.Show("You can't use this mail adress." + Environment.NewLine + "Ex: [email protected]");
                return;
            }
            foreach (Customer item in OceanBookStore.customerList)
            {
                if (item.Username == txtUsername.Text)
                {
                    MessageBox.Show("This username is already taken.");
                    return;
                }
            }
            string   hashedPassword = UtilConvert.ComputeSha256Hash(txtPassword.Text);
            Customer customer       = new Customer(txtName.Text, txtAddress.Text, txtMail.Text, txtUsername.Text,
                                                   hashedPassword, UtilSave.registrationNo.ToString());

            Customer.SaveCustomer(customer);
            OceanBookStore.customerList.Add(customer);
            ShoppingCard shoppingCard = new ShoppingCard();

            shoppingCard.CustomerID = customer.CustomerId;
            UtilSave.Save(shoppingCard);
            StoreMainScreen.shoppingCards.Add(shoppingCard);
            MessageBox.Show("Your account was created!");
            RefreshForm();
            this.Hide();
            OceanBookStore.loginScreen.Show();
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///  This function loads the elements of the ProductList.xml file.
        /// </summary>
        /// <param name="productList">This parameter is a list of Product class.</param>
        /// <returns> This function does not return a value  </returns>
        public static void Load(List <Product> productList)
        {
            if (!File.Exists(@"data/ProductList.xml"))
            {
                XmlTextWriter writer = new XmlTextWriter(@"data/ProductList.xml", System.Text.Encoding.UTF8);
                writer.WriteStartDocument(true);
                writer.Formatting  = Formatting.Indented;
                writer.Indentation = 2;
                writer.WriteStartElement("Products");
                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Close();
                return;
            }
            XDocument xDoc        = XDocument.Load(@"data/ProductList.xml");
            XElement  rootElement = xDoc.Root;

            foreach (XElement product in rootElement.Elements())
            {
                Creator          c;
                string           classType = product.FirstAttribute.Value;
                NumberFormatInfo info      = new NumberFormatInfo();
                info.NumberDecimalSeparator = ".";
                string name  = product.Element("Name").Value;
                string id    = product.LastAttribute.Value;
                double price = Convert.ToDouble(product.Element("Price").Value, info);
                Image  image = UtilConvert.Base64ToImage(product.Element("Image").Value);
                if (classType == "Book")
                {
                    string isbn      = product.Element("ISBN").Value;
                    string author    = product.Element("Author").Value;
                    string publisher = product.Element("Publisher").Value;
                    int    pages     = Convert.ToInt32(product.Element("Pages").Value);
                    c = new BookFactory(name, id, price, isbn, author, publisher, pages, image);
                }
                else if (classType == "Magazine")
                {
                    string        issue = product.Element("Issue").Value;
                    Magazine_Type type  = Magazine_Type.Actual;
                    switch (product.Element("MagazineType").Value)
                    {
                    case "Computer":
                        type = Magazine_Type.Computer;
                        break;

                    case "News":
                        type = Magazine_Type.News;
                        break;

                    case "Sport":
                        type = Magazine_Type.Sport;
                        break;

                    case "Technology":
                        type = Magazine_Type.Technology;
                        break;

                    default:
                        break;
                    }
                    c = new MagazineFactory(name, id, price, issue, type, image);
                }
                else
                {
                    string       singer = product.Element("Singer").Value;
                    MusicCD_Type type   = MusicCD_Type.Country;
                    switch (product.Element("MusicCDType").Value)
                    {
                    case "HardRock":
                        type = MusicCD_Type.HardRock;
                        break;

                    case "Romance":
                        type = MusicCD_Type.Romance;
                        break;

                    default:
                        break;
                    }
                    c = new MusicCdFactory(name, id, price, singer, type, image);
                }
                productList.Add(c.FactoryMethod());
            }
        }