2
I am creating a form to perform a registration for a product license.
This form is used to record which solution a customer has.
In the form to add a product just select product and the client.
I am having difficulty to elaborate the logic of loading the form that leaves marked "checked" the products that this customer already owns.
My initial idea and make two queries that return one DataTable, the first consultation the existing products, the second brings the products that the customer has .
First Consultation
SELECT id, nome
FROM produto
Second Consultation
SELECT produto_id
FROM licenca
JOIN produto on produto_id = produto.id
join pessoa on pessoa.id = cliente_id
where cliente_id = @id
So on loading it during loop will make the comparison leaving marked the ones he already owns .
foreach (DataRow row in ProdutosCLiente.Rows)
{
int id = (int)row["produto_id"];
GridProduto.Rows[id].Cells[0].Value = CheckState.Checked;
}
Can anyone tell me what would be the correct way to reference the values that will be filled in? I’m having trouble referencing during the loop.
Can you post a base of your Product and Customer model? In Datagrid only go product data, right?
– Jéf Bueno
I edited the question showing the query SQL , on the grid are displayed only the solution names. First the user selects the customer sets the initial and final license date and then selects the product.
– stringnome
Take a look at my answer, I edited it showing a way you can do what you need with just one query, without using loops and the like.
– Marciano.Andrade