修改listBox组件属性:可以选中多个板坯号
选中板坯列表,在界面上点击删除按钮,触发删除方法deleteList:
private void deleteList()
{
ListBox.SelectedIndexCollection sic = listBoxProducts.SelectedIndices;//得到选择的Item的下标if (sic.Count == 0)
return;
else
{
// 将选择的Item放入list中
List<string> list = new List<string>();
for (int i = 0; i < sic.Count; i++)
{
int a = sic[i];
list.Add(listBoxProducts.Items[a].ToString());}
List<string> listDelete = new List<string>();
StringBuilder cmdstr = new StringBuilder("");foreach (var item in list)
{
DeleteProductData(item, ref cmdstr, ref listDelete);
}
DBHandle.DeleteBatchDataToDB(listDelete);
}
}
DeleteProductData=》具体从数据库中删除数据
private void DeleteProductData(string _id, ref StringBuilder cmdstr, ref List<string> list)
{
// delete data.
string cmdDelete = "delete from PRODUCT_PDI where PRODUCT_ID = '" + _id + "' ";
cmdstr.Append(cmdDelete);
list.Add(cmdstr.ToString());
cmdstr.Clear();cmdDelete = "delete from PRODUCT_IDPLAN where PRODUCT_ID = '" + _id + "' ";
cmdstr.Append(cmdDelete);
list.Add(cmdstr.ToString());
cmdstr.Clear();cmdDelete = "delete from PRODUCT_CHEM where PRODUCT_ID = '" + _id + "' ";
cmdstr.Append(cmdDelete);
list.Add(cmdstr.ToString());
cmdstr.Clear();cmdDelete = "delete from SETUPDATAL1 where PRODUCT_ID = '" + _id + "' ";
cmdstr.Append(cmdDelete);
list.Add(cmdstr.ToString());
cmdstr.Clear();
}