//删除 private void button8_Click(object sender, EventArgs e) { if (dgv_Data.SelectedRows.Count <= 0) { MessageBox.Show("没有要删除的记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (MessageBox.Show("删除之后信息将不能恢复,是否确认删除?", "提示:", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { List <String> lists = new List <string>(); for (int i = 0; i < dgv_Data.SelectedRows.Count; i++) { string id = Convert.ToString(dgv_Data.SelectedRows[i].Cells[0].Value); if (bll.IsHaveChild(id)) { lists.Clear(); MessageBox.Show("要删除的货位下有子货位,请删除子货位后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); break; } else { if (bll.IsInUse(id)) //货位被使用 { lists.Clear(); MessageBox.Show("该信息被使用,不能删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); break; } else { lists.Add(id); } } } if (lists.Count > 0) { if (bll.Delete(lists)) { foreach (string tempid in lists) { deleteNode(this.treeView1.Nodes[0], tempid); } querryList(); } else { MessageBox.Show("信息删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception) { MessageBox.Show("与数据库连接失败,请查看网络连接是否正常。如不能解决请与网络管理员联系!", "严重错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }