在我的按钮单击代码中,如下所示,如果行值“数量”具有相同的 id,我想将其增加一,如果没有,则开始一个新行。我怎样才能做到这一点?
private void BProduct_Click(object sender, EventArgs e)
{
spGridRowClick.Visibility = Visibility.Hidden;
decimal Quantity;
decimal.TryParse(txtKeyPad.Text, out Quantity);
if (Quantity <= 1) Quantity = 1;
Button bt = (Button)sender;
productId =(int)bt.Tag;
BOneRestEntities db = new BOneRestEntities();
var results = from inv in db.Inventory
where inv.RecId == productId
select new
{
ProductId = inv.RecId,
inventoryName = inv.InventoryName,
Quantity,
Total = Quantity * inv.InventoryPrice
};
foreach (var x in results)
{
DataRow newRow = dt.NewRow();
newRow.SetField("inventoryName", x.inventoryName);
newRow.SetField("Quantity", x.Quantity);
newRow.SetField("Total", x.Total);
newRow.SetField("ProductId", x.ProductId);
dt.Rows.Add(newRow);
}
txtKeyPad.Clear();
gridCalculate.ItemsSource = dt;
gridCalculate.View.MoveNextRow();
TotalRow();
}