Exemplo n.º 1
0
        public List <Product> MusicCDLoader()
        {
            List <Product> musiclist = new List <Product>();

            sqlConnection = new SqlConnection(connectionString);
            sqlConnection.Open();
            command       = new SqlCommand("SELECT * FROM [dbo].[MusicCd]", sqlConnection);
            sqlDataReader = command.ExecuteReader();
            MusicCD music;

            while (sqlDataReader.Read())
            {
                music             = new MusicCD("", "", 0);
                music.ID          = (string)sqlDataReader["Id"];
                music.Name        = (string)sqlDataReader["Name"];
                music.Singer      = (string)sqlDataReader["Singer"];
                music.Isbn        = (string)sqlDataReader["Isbn"];
                music.Price       = (double)sqlDataReader["Price"];
                music.ReleaseDate = (int)sqlDataReader["ReleaseDate"];
                music.Category    = MusicCD.GetMusicType((string)sqlDataReader["Type"].ToString().Trim()).ToString();
                music.Content     = (string)sqlDataReader["CdContent"];
                try
                {
                    music.Picture = Image.FromFile(Application.StartupPath + @"\Resources\" + music.ID.Trim() + ".jpg");
                }
                catch (Exception)
                {
                }
                musiclist.Add(music);
            }
            sqlConnection.Close();
            return(musiclist);
        }
 /// <summary>
 /// This function is Constructor.
 /// </summary>
 /// <param name="musicCD">This parameter is a list of MusicCD class.</param>
 /// <returns> This function does not return a value </returns>
 public MusicCdDesign(MusicCD musicCD)
 {
     InitializeComponent();
     this.musicCD     = musicCD;
     lblName.Text    += musicCD.Name;
     lblSinger.Text  += musicCD.Singer;
     lblType.Text    += musicCD.Type.ToString();
     lblPrice.Text   += musicCD.Price.ToString() + " ₺";
     picMusicCD.Image = this.musicCD.Image;
 }
Exemplo n.º 3
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.º 4
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);
     }
 }
 /// <summary>
 /// This function holds the music cd information and create listview item.
 /// </summary>
 /// <returns> This function does not return a value  </returns>
 private void ToListView()
 {
     foreach (Product product in StoreMainScreen.productList)
     {
         if (product is MusicCD)
         {
             MusicCD      musicCD     = (MusicCD)product;
             string       id          = musicCD.ID1;
             string       name        = musicCD.Name;
             string       price       = musicCD.Price.ToString();
             string       singer      = musicCD.Singer;
             string       type        = musicCD.Type.ToString();
             string[]     stringItems = { id, name, price, singer, type };
             ListViewItem item        = new ListViewItem(stringItems);
             listViewMusicCDs.Items.Add(item);
         }
     }
 }
        /// <summary>
        /// This function update selected music cd button click operation.
        /// This function is used to changed enabled.
        /// </summary>
        /// <returns> This function does not return a value  </returns>
        private void btnUpdateSelected_Click(object sender, EventArgs e)
        {
            Logger.GetLogger().WriteLog(LoginedCustomer.getInstance().User.Username, btnUpdateSelected.Text, DateTime.Now);
            if (selectedIndex == -1)
            {
                MessageBox.Show("Please select a book from list!");
                return;
            }
            panelAddMusicCD.Visible = true;
            selectedID = listViewMusicCDs.Items[selectedIndex].SubItems[0].Text;
            foreach (Product product in StoreMainScreen.productList)
            {
                if (product.ID1 == selectedID)
                {
                    MusicCD musicCD = (MusicCD)product;
                    pboxMusicCD.Image = musicCD.Image;
                    txtName.Text      = musicCD.Name;
                    txtID.Text        = musicCD.ID1;
                    txtPrice.Text     = musicCD.Price.ToString();
                    txtSinger.Text    = musicCD.Singer;
                    switch (musicCD.Type)
                    {
                    case MusicCD_Type.Romance:
                        cBoxType.SelectedIndex = 0;
                        break;

                    case MusicCD_Type.HardRock:
                        cBoxType.SelectedIndex = 1;
                        break;

                    case MusicCD_Type.Country:
                        cBoxType.SelectedIndex = 2;
                        break;

                    default:
                        break;
                    }
                }
            }
            btnAdd.Visible    = false;
            btnUpdate.Visible = true;
            txtID.Enabled     = false;
        }
Exemplo n.º 7
0
 public MusicForm(MusicCD musicCD)
 {
     this.musicCD = musicCD;
     InitializeComponent();
     this.Text           = musicCD.Name;
     txtName.Text        = musicCD.Name;
     txtSinger.Text      = musicCD.Singer;
     txtCategory.Text    = musicCD.Category;
     txtPrice.Text       = musicCD.Price + " TL";
     pbMusic.Image       = musicCD.Picture;
     txtIsbn.Text        = musicCD.Isbn;
     txtReleaseYear.Text = musicCD.ReleaseDate.ToString();
     pbMusic.SizeMode    = PictureBoxSizeMode.StretchImage;
     txtCounter.Text     = "1";
     string[] contentText = musicCD.Content.Split(',');
     for (int i = 0; i < contentText.Length; i++)
     {
         txtContent.Text += contentText[i] + Environment.NewLine;
     }
 }
        public static Product createProduct(ProductType pType, string id, string name, double price)
        {
            Product product = null;

            switch (pType)
            {
            case ProductType.Book:
                product = new Book(id, name, price);
                break;

            case ProductType.Magazine:
                product = new Magazine(id, name, price);
                break;

            case ProductType.MusicCD:
                product = new MusicCD(id, name, price);
                break;

            default:
                break;
            }
            return(product);
        }
Exemplo n.º 9
0
        public MusicCdPanel(MusicCD musicCd)
        {
            this.musicCD     = musicCd;
            this.BackColor   = Color.FromArgb(160, 0, 190, 190);
            this.Size        = new Size(290, 190);
            this.BorderStyle = BorderStyle.None;

            Picture                       = new PictureBox();
            Picture.Size                  = new Size(105, 160);
            Picture.BackgroundImage       = musicCd.Picture;
            Picture.BackgroundImageLayout = ImageLayout.Zoom;
            Picture.BackColor             = Color.Transparent;

            Show_Details                       = new PictureBox();
            Show_Details.Size                  = new Size(32, 32);
            Show_Details.BackgroundImage       = Properties.Resources.loupe;
            Show_Details.BackgroundImageLayout = ImageLayout.Stretch;
            Show_Details.Cursor                = Cursors.Hand;
            Show_Details.BackColor             = Color.Transparent;
            Show_Details.Click                += new EventHandler(panelClick);

            name           = new Label();
            name.AutoSize  = true;
            name.Text      = musicCd.Name;
            name.BackColor = Color.Transparent;
            name.TextAlign = ContentAlignment.MiddleLeft;
            name.ForeColor = Color.White;
            name.Font      = new Font("Calibri", (float)13);
            this.Controls.Add(name);

            Singer           = new Label();
            Singer.AutoSize  = true;
            Singer.Text      = musicCd.Singer;
            Singer.BackColor = Color.Transparent;
            Singer.ForeColor = Color.White;
            Singer.Font      = new Font("Calibri", (float)12);
            this.Controls.Add(Singer);

            Type           = new Label();
            Type.AutoSize  = true;
            Type.Text      = musicCd.Category;
            Type.BackColor = Color.Transparent;
            Type.Font      = new Font("Calibri", (float)10);
            Type.ForeColor = Color.White;
            this.Controls.Add(Type);

            Price           = new Label();
            Price.AutoSize  = true;
            Price.Text      = musicCd.Price + " TL";
            Price.BackColor = Color.Transparent;
            Price.Font      = new Font("Calibri", (float)11.25);
            Price.ForeColor = Color.White;
            this.Controls.Add(Price);

            Add_Cart                       = new PictureBox();
            Add_Cart.Size                  = new Size(32, 32);
            Add_Cart.BackgroundImage       = Properties.Resources.showDetails;
            Add_Cart.BackgroundImageLayout = ImageLayout.Stretch;
            Add_Cart.Cursor                = Cursors.Hand;
            Add_Cart.BackColor             = Color.Transparent;
            Add_Cart.Click                += new EventHandler(addCart);

            this.Controls[0].Location = new Point(125, 20);  // Name label
            this.Controls[0].BringToFront();
            this.Controls[1].Location = new Point(125, 50);  // Singer label
            this.Controls[1].BringToFront();
            this.Controls[2].Location = new Point(125, 80);  // Type label
            this.Controls[2].BringToFront();
            this.Controls[3].Location = new Point(125, 110); //  Price label
            this.Controls[3].BringToFront();
            this.Controls.Add(Picture);
            this.Controls[4].Location = new Point(10, 15);   //Picturebox
            this.Controls.Add(Show_Details);
            this.Controls[5].Location = new Point(175, 140); //Magnifier image
            this.Controls.Add(Add_Cart);
            this.Controls[6].Location = new Point(225, 140); //Add to cart image
        }