/// <summary> /// 功能描述 : 删除[tblDictionary]表的记录 /// 创建者 : Auto Generator /// 创建日期 : 2009-04-29 /// 修改者 : /// 修改日期 : /// 修改原因 : /// </summary> /// <param name="iPK">需要删除的记录的PK主键值</param> /// <returns>true / false</returns> public bool Delete(int iPK) { try { usp_tblDictionary_Delete uspDelete = new usp_tblDictionary_Delete(); uspDelete.fldAutoID = iPK; int iResult = uspDelete.ExecNoQuery(1); if (iResult > 0) { return(true); } else { throw new Exception("删除记录失败,未找到对应的记录"); } } catch (DBOpenException e) { throw new DeleteException("打开数据库连接失败", "RuletblDictionary", "Delete", iPK.ToString()); } catch (DBQueryException e) { throw new DeleteException("执行Sql语句失败", "RuletblDictionary", "Delete", iPK.ToString()); } catch (Exception e) { throw new DeleteException(e.Message, "RuletblDictionary", "Delete", iPK.ToString()); } }
/// <summary> /// 功能描述 : 同时删除[tblDictionary]表的多条记录 /// 创建者 : 张春 /// 创建日期 : 2009-04-30 /// 修改者 : /// 修改日期 : /// 修改原因 : /// </summary> /// <param name="arrPK">要删除的主键ID列表</param> /// <returns></returns> public bool DeleteMany(List <int> arrPK) { using (SqlConnection conn = new SqlConnection(DataAccessConfig.ConnString_LAP)) { conn.Open(); using (SqlTransaction tran = conn.BeginTransaction()) { try { for (int i = 0; i < arrPK.Count; i++) { usp_tblDictionary_Delete_ParentID dicPDelete = new usp_tblDictionary_Delete_ParentID(); dicPDelete.fldParentID = arrPK[i]; dicPDelete.ExecNoQuery(conn, tran); usp_tblDictionary_Delete dicDelete = new usp_tblDictionary_Delete(); dicDelete.fldAutoID = arrPK[i]; int iResult = dicDelete.ExecNoQuery(conn, tran); if (iResult <= 0) { throw new Exception("删除记录失败,未找到对应的记录"); } } tran.Commit(); return(true); } catch (DBOpenException e) { throw new DeleteException("打开数据库连接失败", "RuletblDictionary", "DeleteMany", ""); } catch (DBQueryException e) { throw new DeleteException("执行Sql语句失败", "RuletblDictionary", "DeleteMany", ""); } catch (DBException e) { throw new DeleteException("写入数据库失败", "RuletblDictionary", "DeleteMany", ""); } catch (Exception e) { tran.Rollback(); throw new DeleteException(e.Message, "RuletblDictionary", "DeleteMany", ""); } } } }