Esempio n. 1
0
        /**
         * A list of allMusicCDs in the MusicCDsClass' getAllMusicCDsFromDB() function is created.
         * musicCDsUserControls is created from the  MusicCDUserControl.
         * The size of musicCDsUserControls is up to the length of allMusicCDs.
         */
        private void populateMusicCDsViewInHomePage()
        {
            List <MusicCDsClass> allMusicCDs = MusicCDsClass.getAllMusicCDsFromDB();

            MusicCDUserControl[] musicCDsUserControls = new MusicCDUserControl[allMusicCDs.Count];

            if (flpHomePage.Controls.Count > 0)
            {
                flpHomePage.Controls.Clear();
            }

            int i = 0;

            foreach (var item in allMusicCDs)
            {
                musicCDsUserControls[i]               = new MusicCDUserControl();
                musicCDsUserControls[i].musicCDID     = item.id;
                musicCDsUserControls[i].musicCDName   = item.name;
                musicCDsUserControls[i].musicCDPrice  = item.price;
                musicCDsUserControls[i].musicCDSinger = item.singer;
                musicCDsUserControls[i].stock         = item.stock;
                musicCDsUserControls[i].picture       = item.cover_page_picture;
                flpHomePage.Controls.Add(musicCDsUserControls[i]);
                i++;
            }
        }
Esempio n. 2
0
        /**
         * musicCDsList created from MusicCDsClass
         * this function reads musicCDs items in database
         * and add in musicCDsList
         * @return musicCDsList
         */
        public static List <MusicCDsClass> getAllMusicCDsFromDB()
        {
            List <MusicCDsClass> musicCDsList = new List <MusicCDsClass>();
            DatabaseHelperClass  dbHelper     = DatabaseHelperClass.Instance; //SINGLETON PATTERN

            SqlConnection connection = dbHelper.getConnection();
            SqlCommand    command    = new SqlCommand("SELECT * FROM MusicCDsTable", connection);

            SqlDataReader readMusicCDs = command.ExecuteReader();

            if (readMusicCDs != null)
            {
                while (readMusicCDs.Read())
                {
                    MusicCDsClass musicCDs = new MusicCDsClass();
                    musicCDs.id                 = readMusicCDs["id"].ToString();
                    musicCDs.name               = readMusicCDs["name"].ToString();
                    musicCDs.price              = Convert.ToDouble(readMusicCDs["price"]);
                    musicCDs.singer             = readMusicCDs["singer"].ToString();
                    musicCDs.stock              = Convert.ToInt32(readMusicCDs["stock"]);
                    musicCDs.cover_page_picture = readMusicCDs["picture"].ToString();
                    musicCDsList.Add(musicCDs);
                }
            }

            return(musicCDsList);
        }
Esempio n. 3
0
        /** @ brief adds the purchased musicCDs to the shopping cart
         * create a book from MusicCDsClass
         * and item added shoppingcartclass
         */

        private void btnMusicCDsAddToCart_Click(object sender, EventArgs e)
        {
            MusicCDsClass musicCDs = new MusicCDsClass();

            musicCDs = MusicCDsClass.getAMusicCDsFromDB(musicCDID);
            ShoppingCartClass.addProduct(new ItemToPurchaseClass(musicCDs, Convert.ToInt32(Math.Round(nudQuantity.Value, 0))));
            System.Windows.Forms.Form f = System.Windows.Forms.Application.OpenForms["BookShopForm"];
            int quantity = 0;

            foreach (var item in ShoppingCartClass.itemsToPurchase)
            {
                quantity += item.quantity;
            }
            ((BookShopForm)f).lblShoppinCartValue.Text = quantity.ToString();
            MessageBox.Show("Added to cart.", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Esempio n. 4
0
        private void btnUpdateMusicCDs_Click(object sender, EventArgs e)
        {
            MusicCDsClass music = new MusicCDsClass(txtMusicName.Text, txtMusicCDsId.Text, Convert.ToDouble(txtMusicPrice.Text), Convert.ToInt32(txtMusicCDsStock.Text), txtMusicSinger.Text, txtMusicType.Text, txtMusicCDsImage.Text);
            //bool affected = dbHelper.updateAProductAtDB(music);
            AdminUserClass adminOps = AdminUserClass.Instance;
            bool           affected = adminOps.updateProduct(music);

            if (!affected)
            {
                MessageBox.Show("Error not successful");
            }
            else
            {
                MessageBox.Show("Music CDs updated successfully", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                clearMusicCDsControl();
            }
        }
Esempio n. 5
0
        /**this function read a musicCDs item in a database
         * @param string id
         * @return musicCDs
         */
        public static MusicCDsClass getAMusicCDsFromDB(string id)
        {
            DatabaseHelperClass dbHelper   = DatabaseHelperClass.Instance; //SINGLETON PATTERN
            SqlConnection       connection = dbHelper.getConnection();
            SqlCommand          command    = new SqlCommand("SELECT * FROM MusicCDsTable where id=@id", connection);

            command.Parameters.AddWithValue("@id", Convert.ToInt32(id));
            SqlDataReader readMusicCDs = command.ExecuteReader();
            MusicCDsClass musicCDs     = new MusicCDsClass();

            if (readMusicCDs != null)
            {
                while (readMusicCDs.Read())
                {
                    musicCDs.id                 = readMusicCDs["id"].ToString();
                    musicCDs.name               = readMusicCDs["name"].ToString();
                    musicCDs.price              = Convert.ToDouble(readMusicCDs["price"]);
                    musicCDs.singer             = readMusicCDs["singer"].ToString();
                    musicCDs.stock              = Convert.ToInt32(readMusicCDs["stock"]);
                    musicCDs.cover_page_picture = readMusicCDs["picture"].ToString();
                }
            }
            return(musicCDs);
        }