C#linq - 带动态按钮和标签的动态tabcontrol

时间:2017-05-18 08:11:38

标签: c# linq

我有以下数据库:Db。 我想创建一个销售点。 我想为每个db.category添加一个选项卡,在每个选项卡中我想为每个db.product添加一个标签,并且在同一标签行中我希望每个db.size都有一个按钮,其值为按钮值= db.price。 谁能帮助我呢?

        using (var db = new GelatoProjectDBEntities())
        {

            var prodotti = (from x in db.ProductsLists
                            select new { x.Id, x.Category, x.Product, x.Size, x.Price}
                            ).ToArray();

            var categories = (from x in prodotti
                              select x.Category)
                              .Distinct();
            var products = (from x in prodotti
                            select x.Product)
                            .Distinct();
            var sizes = (from x in prodotti
                         select x.Size);

            foreach (var category in categories)
            {
                TabPage TabProduct = new TabPage(category);
                TabProduct.BackColor = System.Drawing.Color.White;
                foreach (var product in prodotti.Where(x => x.Category == category).Distinct())
                {
                    var label = new Label();
                    label.Text = product.Product;
                    label.Location=new Point(posXlabel, posYlabel);
                    TabProduct.Controls.Add(label);

                    foreach (var size in prodotti.Where(x => x.Product == product.ToString()))
                    {
                        var button = new Button();
                        button.Text = product.Size;
                        button.Size = new Size(100, 50);
                        button.Location = new Point(posXbutton, posYbutton);
                        button.BackColor = System.Drawing.Color.LightGray;
                        button.Click += Button_Click;
                        TabProduct.Controls.Add(button);
                        posXbutton = posXbutton + gapXbutton;
                    }
                }
                posYbutton = posYbutton + gapYbutton;
                tabControl1.TabPages.Add(TabProduct);
            }
        }

0 个答案:

没有答案