I have struggled with ObjectQuery
, but then I found out that it is only used in earlier versions of Visual Studio. I don't know what to use and how to use it in Visual Studio 2017. Can somebody help!? As you can see I'm using Entity Framework. I have read something about query but I don't know it is possible to use something else then that.
namespace POSsytemFlamenca
{
public partial class LaFlamencaPSO : Form
{
private BindingList<TblProduct> products = new BindingList<TblProduct>();
private FlamencaProEntities1 cse = new FlamencaProEntities1();
public LaFlamencaPSO()
{
InitializeComponent();
listProductChosen.DataSource = products;
listProductChosen.DisplayMember = "Description";
CreateTabbedPanel();
AddProductsToTabbedPanel();
}
private void AddProductsToTabbedPanel()
{
int i = 1;
foreach (TabPage tp in tabControl1.TabPages)
{
// this is the problem
ObjectQuery<TblProduct> filteredproduct = new ObjectQuery<TblProduct>("SELECT VALUE P FROM TblProducts AS P WHERE P.ProductType = " + i.ToString(), cse);
FlowLayoutPanel flp = new FlowLayoutPanel();
flp.Dock = DockStyle.Fill;
foreach (TblProduct tprod in filteredproduct)
{
Button b = new Button();
b.Size = new Size(100, 100);
b.Text = tprod.Description;
flp.Controls.Add(b);
}
tp.Controls.Add(flp);
i++;
}
}
private void CreateTabbedPanel()
{
foreach (TblProductType pt in cse.TblProductTypes)
{
tabControl1.TabPages.Add(pt.ProductType.ToString(), pt.Description);
}
}
private void button1_Click(object sender, EventArgs e)
{
TblProduct p = new TblProduct() { Description = "Product A",
Price = 1.99M };
products.Add(p);
}
private void FormtListItem(object sender, ListControlConvertEventArgs e)
{
string currentDescription = ((TblProduct)e.ListItem).Description;
string currentPrice = string.Format("{0:C}",((TblProduct)e.ListItem).Price);
string curretDescriptionPadded = currentDescription.PadRight(30);
e.Value = curretDescriptionPadded + currentPrice;
}
}
}