Ejemplo n.º 1
0
        private void loadPanel()
        {
            tea01Entities2 db        = new tea01Entities2();
            var            resources = db.Resources;

            panel.Controls.Clear();
            panel.FlowDirection = FlowDirection.LeftToRight;
            listCheckbox        = new List <checkBoxBunifuCustom>();

            foreach (var resource in resources)
            {
                checkBoxBunifuCustom checkBox = new checkBoxBunifuCustom();
                buttonBunifuCustom   button   = new buttonBunifuCustom();
                Label           label         = new Label();
                FlowLayoutPanel subPanel      = new FlowLayoutPanel();

                label.Text       = "0";
                checkBox.idItem  = resource.ResourceId;
                button.idItem    = resource.ResourceId;
                button.Text      = resource.ResourceName;
                button.Size      = new Size(193, 30);
                checkBox.Checked = false;
                checkBox.amount  = 0;

                checkBox.MouseClick += (s, e) => {
                    if (checkBox.Checked == true)
                    {
                        checkBox.Checked = true;
                        string value = "0";
                        if (DialogCustom.InputBox("Input", "Nhập vào số lượng:", ref value) == DialogResult.OK)
                        {
                            checkBox.amount = Convert.ToInt32(value);
                            label.Text      = (checkBox.amount).ToString();

                            if (checkBox.amount == 0)
                            {
                                checkBox.Checked = false;
                            }
                        }
                    }
                    else
                    {
                        checkBox.Checked = false;
                        checkBox.amount  = 0;
                        label.Text       = (checkBox.amount).ToString();
                    }
                };

                listCheckbox.Add(checkBox);

                subPanel.FlowDirection = FlowDirection.LeftToRight;
                subPanel.Controls.Add(checkBox);
                subPanel.Controls.Add(label);
                subPanel.Controls.Add(button);

                panel.Controls.Add(subPanel);
            }
        }
Ejemplo n.º 2
0
        private void loadPanelForTopping()
        {
            tea01Entities2 db               = new tea01Entities2();
            var            resources        = db.Resources;
            var            topping          = db.Toppings.Find(gridViewListTopping.CurrentRow.Cells[0].Value);
            var            topping_Resource = topping.Topping_Resource;

            panel.Controls.Clear();
            panel.FlowDirection = FlowDirection.LeftToRight;
            listCheckbox        = new List <checkBoxBunifuCustom>();

            foreach (var resource in resources)
            {
                checkBoxBunifuCustom checkBox = new checkBoxBunifuCustom();
                buttonBunifuCustom   button   = new buttonBunifuCustom();
                Label           label         = new Label();
                FlowLayoutPanel subPanel      = new FlowLayoutPanel();

                label.Text       = "0";
                checkBox.idItem  = resource.ResourceId;
                button.idItem    = resource.ResourceId;
                button.Text      = resource.ResourceName;
                button.Size      = new Size(193, 30);
                checkBox.Checked = false;
                checkBox.amount  = 0;

                // Update checkbox for drink

                if (topping_Resource.Where(u => u.ResourceId == resource.ResourceId).FirstOrDefault() != null)
                {
                    checkBox.Checked = true;
                    checkBox.amount  = (int)topping_Resource.Where(u => u.ResourceId == resource.ResourceId).First().Amount;

                    label.Text = (checkBox.amount).ToString();
                }

                checkBox.MouseClick += (s, e) => {
                    if (checkBox.Checked == true)
                    {
                        checkBox.Checked = true;
                        string value = "0";
                        if (DialogCustom.InputBox("Input", "Nhập vào số lượng:", ref value) == DialogResult.OK)
                        {
                            checkBox.amount = Convert.ToInt32(value);
                            label.Text      = (checkBox.amount).ToString();

                            if (checkBox.amount == 0)
                            {
                                checkBox.Checked = false;
                            }
                        }
                    }
                    else
                    {
                        checkBox.Checked = false;
                        checkBox.amount  = 0;
                        label.Text       = (checkBox.amount).ToString();
                    }
                };

                listCheckbox.Add(checkBox);

                subPanel.FlowDirection = FlowDirection.LeftToRight;
                subPanel.Controls.Add(checkBox);
                subPanel.Controls.Add(label);
                subPanel.Controls.Add(button);

                panel.Controls.Add(subPanel);
            }
        }