I'm busy working on an Orders project, but I'm a bit stuck where I am now. I have a Products DGV and a Basket DGV. Initially, when an order is placed I write to 3 tables in my database which was tricky but that all works fine.
What I'm having a bit of trouble with now is:
Once an order is placed and for some reason the order needs to be edited, I want to select only the new items in the Basket DGV.
For clarity, when the Order form loads (for edit) the basket DGV gets populated with the items that were originally selected for that order. I'm a bit stuck here because I'm not too sure how to select only the newly added items for the order.
Lets say the order had 8 items and I add 2 more, the basket DGV would now have 10 items. I don't want to loop through the DGV again and rewrite all the values in the DGV back to my database. That's what's happening now. There WERE 8 items, now after the edit, there are 18 (the 8 original and the 10 [8 + 2] from the edit).
Is there a way to get ONLY the 2 new items?
I've thinking about using a boolean flag to check if the product already exists in the basket, but I'm not too sure how to say, in code 'if the product exists, ignore it and select only the products that weren't there'.
I have the following to populate my basket DGV for the edit part:
Expand|Select|Wrap|Line Numbers
- void populatedgvBasketForEdit()
- {
- dgvBasket.Rows.Clear();
- Hashtable columns = new Hashtable();
- initialAvailableStock();
- DataSet ds = new DataSet();
- ds = orderMethods.populateBasketDGVForEdit(ds, _orderNumber);
- columns.Add("ProductID", "INT:0");
- columns.Add("ProductName", "STRING:1");
- columns.Add("QuantityOrdered", "INT:2");
- orderMethods.populateBasketDGV(ds, dgvBasket, columns, _orderNumber);
- }
Any suggestions?
Please let me know if I need to post more code. I use quite a lot of loops to achieve the desired results...
Thanks