/// <summary> /// 删除事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_Delete_Click(object sender, EventArgs e) { try { string strmessagebox = ""; string Operationlog = ""; strCarTypeName = ""; strCarType_ID = ""; alist = new ArrayList(); if (btn_Delete.Enabled) { btn_Delete.Enabled = false; } if (dgv_Information.SelectedRows.Count > 0)//判断是否选中行 { if (MessageBox.Show("删除将会把关联删除,确定要删除吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { int count = dgv_Information.SelectedRows.Count; //遍历 for (int i = 0; i < count; i++) { if (dgv_Information.SelectedRows[i].Cells["CarType_ID"].Value != null) { strCarType_ID += dgv_Information.SelectedRows[i].Cells["CarType_ID"].Value.ToString(); strCarTypeName += dgv_Information.SelectedRows[i].Cells["CarType_Name"].Value.ToString(); if (i < count - 1) { strCarType_ID += ","; } alist.Add(CommonalityEntity.GetInt(dgv_Information.SelectedRows[i].Cells["CarType_ID"].Value.ToString())); } if (JudgeCarTypeUseMethod())//判断当前要操作的车辆类型是否正在使用 { DCCarManagementDataContext db = new DCCarManagementDataContext(); // Expression<Func<CarType, bool>> funCarType = n => alist.Contains(n.CarType_ID); Expression <Func <CarType, bool> > funCarType = n => alist.ToArray().Contains(n.CarType_ID); if (LinQBaseDao.ADD_Delete_UpdateMethod <CarType>(db, 2, null, funCarType, null, true, null)) { strmessagebox = "成功删除车辆类型"; Operationlog = String.Format("删除车辆类型:{0}", strCarTypeName); CommonalityEntity.WriteLogData("删除", Operationlog, CommonalityEntity.USERNAME); } else { strmessagebox = "删除车辆类型失败"; } } else { strmessagebox = "该车辆类型正在使用不能删除"; } if (strmessagebox != "") { MessageBox.Show(strmessagebox, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } } catch (Exception err) { CommonalityEntity.WriteTextLog("CarTypeForm.btn_Delete_Click()"); } finally { btn_Delete.Enabled = true; pc = new PageControl(); SelectMethod();//更新数据 } }