Example #1
0
        private void GenerateTopButtons(int vendorID)
        {
            ButtonsFlowPanel.Controls.Clear();
            //Querying Database for Item Types
            string    SQLQuery = ($@"SELECT MIN(Category)
                                FROM items
                                WHERE vendorID = {vendorID}
                                GROUP BY Category");
            DataTable QueryResults = DAL.ExecCommand(SQLQuery);

            //Initializing a List & Adding item Types to it.
            List <string> vendorItemTypes = new List <string>();

            foreach (DataRow Record in QueryResults.Rows)
            {
                vendorItemTypes.Add(Record[0].ToString());
            }

            //Initializing Property Variables
            Size  ButtonSize     = new Size(172, 56);
            Point buttonLocation = new Point(0, 0);
            Font  buttonFont     = new Font("Nirmala UI", 14, FontStyle.Regular);

            //Creating & Adding Button Control to User Control
            foreach (string Item in vendorItemTypes)
            {
                Button ItemTypeButton = GenControls.AddButton(Item, Item, buttonLocation, buttonFont, Color.Black, Color.White, ButtonSize, false);
                ItemTypeButton.Click += new EventHandler(PanelButtonClicked);
                ButtonsFlowPanel.Controls.Add(ItemTypeButton);
            }
        }
Example #2
0
        private void GenerateItems(int vendorID, string itemType)
        {
            #region Initiaizling Variables & DataTable

            int    ItemAmount;
            string ItemID, ItemType, ItemName, ItemDescription, ItemPrice, imageLoc;

            string SQLCommand = ($"SELECT * FROM items WHERE vendorID = {vendorID} AND Category = '{itemType}'");

            DataTable ItemResults = DAL.ExecCommand(SQLCommand);
            ItemAmount = ItemResults.Rows.Count;

            #endregion Initiaizling Variables & DataTable

            #region Initiaizling Common Variables for Dynamic Controls

            //Size & Location Variables
            Size EmptySize   = new Size(0, 0);
            Size PanelSize   = new Size(678, 133);
            Size DescSize    = new Size(434, 78);
            Size PicBoxSize  = new Size(124, 97);
            Size ButtonSize  = new Size(25, 31);
            Size TextBoxSize = new Size(29, 22);

            Point EmptyLoc      = new Point(0, 0);
            Point TitleLoc      = new Point(278, 10);
            Point DescLoc       = new Point(141, 41);
            Point PriceLoc      = new Point(594, 22);
            Point PicBoxLoc     = new Point(6, 22);
            Point RemoveItemLoc = new Point(584, 53);
            Point ItemAmountLoc = new Point(609, 55);
            Point AddItemLoc    = new Point(639, 53);

            Font TitleFont  = new Font("Nirmala UI", 12, FontStyle.Regular);
            Font ButtonFont = new Font("Nirmala UI", 12, FontStyle.Bold);
            Font PriceFont  = new Font("Nirmala UI", 14, FontStyle.Regular);

            Color BlackColour       = Color.Black;
            Color WhiteColour       = Color.White;
            Color TransparentColour = Color.Transparent;
            Color DimGrayColour     = Color.DimGray;

            #endregion Initiaizling Common Variables for Dynamic Controls

            #region Iterating Through DataTable

            //Getting Data From Table & Creating Controls
            foreach (DataRow Item in ItemResults.Rows)
            {
                #region Getting Item Information

                ItemID          = Item[0].ToString();
                ItemName        = Item[2].ToString();
                ItemType        = Item[3].ToString();
                ItemDescription = Item[4].ToString();
                ItemPrice       = Item[5].ToString();
                imageLoc        = Item[6].ToString();

                #endregion Getting Item Information

                #region Creating Dynamic Item Controls

                Panel ItemPanel = GenControls.AddPanel(ItemName, Color.White, PanelSize);

                Label      TitleLabel     = GenControls.AddLabel(ItemName + "Title", ItemName, TitleLoc, TitleFont, BlackColour, TransparentColour, EmptySize, true);
                Label      DescLabel      = GenControls.AddLabel(ItemName + "Desc", ItemDescription, DescLoc, TitleFont, Color.DarkGray, TransparentColour, DescSize, false);
                Label      PriceLabel     = GenControls.AddLabel(ItemName + "Price", "£" + ItemPrice, PriceLoc, PriceFont, Color.Maroon, Color.Transparent, EmptySize, true);
                Button     RemoveButton   = GenControls.AddButton(ItemName + "Remove", "-", RemoveItemLoc, ButtonFont, DimGrayColour, WhiteColour, ButtonSize, false);
                TextBox    ItemAmountTBox = GenControls.AddTextBox(ItemName, "0", ItemID, ItemAmountLoc, TitleFont, BlackColour, WhiteColour, TextBoxSize);
                Button     AddButton      = GenControls.AddButton(ItemName + "Add", "+", AddItemLoc, ButtonFont, DimGrayColour, WhiteColour, ButtonSize, false);
                PictureBox ItemPictureBox = GenControls.AddPictureBox(ItemName, PicBoxLoc, PicBoxSize);

                ItemPictureBox.ImageLocation = ImageHandler.GetImage(ImageTypes.Item, imageLoc);

                #endregion Creating Dynamic Item Controls

                #region Adding to Form & Setting Event Handlers

                Control[] PanelControls = new Control[] { TitleLabel, DescLabel, PriceLabel, RemoveButton, ItemAmountTBox, AddButton, ItemPictureBox };

                foreach (Control CurrentItemControl in PanelControls)
                {
                    ItemPanel.Controls.Add(CurrentItemControl);
                }

                RemoveButton.Click         += new EventHandler(ItemDecreased);
                AddButton.Click            += new EventHandler(ItemIncreased);
                ItemAmountTBox.TextChanged += new EventHandler(ItemAmountChanged);
                ItemsFlowPanel.Controls.Add(ItemPanel);

                #endregion Adding to Form & Setting Event Handlers
            }

            #endregion Iterating Through DataTable
        }