2017-04-06 157 views
0

我有一个GridView,显示我的客户试图购买的所有产品。我想用一个DELIVER ALL按钮从我的库存中扣除所有产品。什么是最好的方式来做到这一点?C# - 用一个按钮更新多个库存

gvOrderDetails(样表)

Order # || Product ID || Product Name || Quantity || DELIVER Buttons 

    1 ||  1  || Sample Item 1 || 10 || DELIVER 

    1 ||  2  || Sample Item 2 || 20 || DELIVER 

    1 ||  3  || Sample Item 3 || 30 || DELIVER 

下面是对GridView

void DeductFromInventory() 
    { 
     con.Open(); 
     SqlCommand cmd = new SqlCommand(); 
     cmd.Connection = con; 
     cmd.CommandText = "UPDATE Products SET Quantity = Quantity - " + gvOrderDetails.SelectedRow.Cells[3].Text + " WHERE [email protected]"; 
     cmd.Parameters.AddWithValue("@ProductID", gvOrderDetails.SelectedRow.Cells[1].Text); 
     cmd.ExecuteNonQuery(); 
     con.Close(); 
    } 

protected void gvOrderDetails_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    DeductFromInventory(); 
} 
+0

每当用户选择不同的行时,您是从库存中扣除的? – msitt

回答

0

里面的按钮

  1. 添加一个复选框,单击事件我对于传送按钮的代码列到你的gridview。
  2. 将gridview数据传递给数据表。
  3. 扫描数据表[例如。使用循环]过滤如果复选框被选中[布尔/位]
  4. 更新,如果选中,不,如果不选中。
相关问题