/// <summary>
 /// This function  holds the magazine's information.
 /// </summary>
 /// <param name="_name">The _name string hold the product name.</param>
 /// <param name="_id">The _id string hold the product id.</param>
 /// <param name="_price">The _price value hold the product price.</param>
 /// <param name="_issue">The _issue string hold the product issue.</param>
 /// <param name="_type">The _type Magazine_Type hold the product type.</param>
 /// <param name="_image">The _image hold the product image.</param>
 /// <returns> This function does not return a value </returns>
 public MagazineFactory(string _name, string _id, double _price, string _issue, Magazine_Type _type, Image _image)
 {
     this.name  = _name;
     this.id    = _id;
     this.price = _price;
     this.issue = _issue;
     this.type  = _type;
     this.image = _image;
 }
Example #2
0
        /// <summary>
        /// This function add magazine 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 (pboxMagazine.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 = ".";
            Magazine_Type type = Magazine_Type.Actual;

            switch (cBoxType.SelectedIndex)
            {
            case 1:
                type = Magazine_Type.Computer;
                break;

            case 2:
                type = Magazine_Type.News;
                break;

            case 3:
                type = Magazine_Type.Sport;
                break;

            case 4:
                type = Magazine_Type.Technology;
                break;

            default:
                break;
            }
            Creator c = new MagazineFactory(txtName.Text, txtID.Text, Convert.ToDouble(txtPrice.Text, provider),
                                            txtIssue.Text, type, pboxMagazine.Image);

            string[]     lvItem = { txtID.Text, txtName.Text, txtPrice.Text, txtIssue.Text, cBoxType.Text };
            ListViewItem item   = new ListViewItem(lvItem);

            listViewMagazines.Items.Add(item);
            StoreMainScreen.productList.Add(c.FactoryMethod());
            UtilSave.Save(c.FactoryMethod());
            MessageBox.Show("Added succesfully!");
            listViewMagazines.Refresh();
            panelAddMagazine.Visible = false;
        }
Example #3
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());
            }
        }
Example #4
0
        /// <summary>
        /// This function update magazine 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 (pboxMagazine.Image == null)
            {
                MessageBox.Show("Please select an image.");
                return;
            }
            NumberFormatInfo provider = new NumberFormatInfo();

            provider.NumberDecimalSeparator = ".";
            Magazine_Type type = Magazine_Type.Actual;

            switch (cBoxType.SelectedIndex)
            {
            case 1:
                type = Magazine_Type.Computer;
                break;

            case 2:
                type = Magazine_Type.News;
                break;

            case 3:
                type = Magazine_Type.Sport;
                break;

            case 4:
                type = Magazine_Type.Technology;
                break;

            default:
                break;
            }
            Creator c = new MagazineFactory(txtName.Text, txtID.Text, Convert.ToDouble(txtPrice.Text, provider),
                                            txtIssue.Text, type, pboxMagazine.Image);

            string[]     lvItem = { txtID.Text, txtName.Text, txtPrice.Text, txtIssue.Text, cBoxType.Text };
            ListViewItem item   = new ListViewItem(lvItem);

            for (int i = 0; i < listViewMagazines.Items.Count; i++)
            {
                if (listViewMagazines.Items[i].SubItems[0].Text == selectedID)
                {
                    listViewMagazines.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!");
            panelAddMagazine.Visible = false;
            selectedIndex            = -1;
        }