Exemplo n.º 1
0
        /// <summary>
        /// Populate homePanelList with the most popular
        /// items, afterwards we call BubbelSort to put them in
        /// the right order.
        /// </summary>
        public void PopulateHomePanelList()
        {
            foreach (Product p in cartPanelRef.GetProductList().OrderByDescending(x => x.interestPoints).ToList())
            {
                Product        tp           = new Product();
                List <Product> popularItems = new List <Product>();
                int            innerCounter = 0;
                foreach (Product item in cartPanelRef.GetProductList())
                {
                    if (item.type == p.type && item.stage1 == false &&
                        innerCounter < 3 && item.stage2 == false)
                    {
                        popularItems.Add(item);
                        item.stage1 = true;
                        innerCounter++;
                        p.totalPoints += item.interestPoints;
                    }
                    else if (popularItems.Count != 3 || item.stage1 == true)
                    {
                        continue;
                    }
                }
                if (popularItems.Count == 3)
                {
                    int foo = CalculateTotalInterestPoints(popularItems);
                    popularItems[0].totalPoints = foo;

                    mainProductList.Add(popularItems);
                }
                else
                {
                    p.stage2 = true;
                }
            }

            BubbleSort(mainProductList);

            // To set all the "stages" of our products back to false,
            // to prevent their interestPoints from being corrupted.
            foreach (Product item in cartPanelRef.GetProductList())
            {
                item.stage1 = false;
                item.stage2 = false;
                item.stage3 = false;
            }
        }
Exemplo n.º 2
0
        private void MyForm_IsClosed(object sender, EventArgs e)
        {
            List <string> lines = new List <string>();

            foreach (Product product in cart.GetProductList())
            {
                lines.Add(product.ToDatabaseCSV());
            }
            try
            {
                File.WriteAllLines("TextFile1.csv", lines);
            }
            catch
            {
                // If the program decides to crash, or something.
                File.WriteAllLines("TextFile1.csv", lines);
            }
        }
Exemplo n.º 3
0
        public MyForm()
        {
            this.MinimumSize = new Size(800, 500);
            this.Font        = new Font("Calibri", 12);
            this.FormClosed += MyForm_IsClosed;

            TableLayoutPanel mainPanel = new TableLayoutPanel
            {
                RowCount        = 2,
                Dock            = DockStyle.Fill,
                CellBorderStyle = TableLayoutPanelCellBorderStyle.Single,
                Padding         = new Padding(0),
            };

            mainPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 100));
            mainPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            this.Controls.Add(mainPanel);

            TableLayoutPanel topPanel = new TableLayoutPanel
            {
                ColumnCount     = 3,
                Dock            = DockStyle.Fill,
                CellBorderStyle = TableLayoutPanelCellBorderStyle.Single,
                BackColor       = Color.White,
                Margin          = new Padding(0),
            };

            topPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 100));
            topPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 30));
            topPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 100));
            mainPanel.Controls.Add(topPanel);

            Button storeButton = new Button
            {
                Name                  = "Store",
                BackgroundImage       = Image.FromFile("Icons/store.png"),
                BackgroundImageLayout = ImageLayout.Zoom,
                Dock                  = DockStyle.Fill,
                Margin                = new Padding(0)
            };

            storeButton.Click += ViewChangedButton_Click;
            topPanel.Controls.Add(storeButton);

            PictureBox headerPicture = new PictureBox
            {
                Dock        = DockStyle.Fill,
                Image       = Image.FromFile("Background/Header1.jpg"),
                SizeMode    = PictureBoxSizeMode.StretchImage,
                BorderStyle = BorderStyle.Fixed3D,
            };

            headerPicture.Click += HeaderPicture_Click;
            topPanel.Controls.Add(headerPicture);

            Button cartButton = new Button
            {
                Name                  = "Cart",
                BackgroundImage       = Image.FromFile("Icons/cart.png"),
                BackgroundImageLayout = ImageLayout.Zoom,
                Dock                  = DockStyle.Fill,
                Margin                = new Padding(0)
            };

            cartButton.Click += ViewChangedButton_Click;
            topPanel.Controls.Add(cartButton);

            cart  = new CartPanel();
            store = new StorePanel(cart);

            // Send store as parameter to homePanel to connect them so we
            // can display clicked product in the descriptionPanel in storePanel.
            home = new HomePanel(cart, store);

            mainPanel.Controls.Add(store, 0, 1);
            mainPanel.Controls.Add(cart, 0, 1);
            mainPanel.Controls.Add(home, 0, 1);
            cart.Hide();
            store.Hide();
            home.Select();
            store.PopulateStorePanel(cart.GetProductList());
        }
Exemplo n.º 4
0
        private void CreateTypeList()
        {
            List <Product> productList = cartPanelRef.GetProductList();

            typeList = productList.Select(x => x.type).Distinct().OrderBy(x => x).ToList();
        }