/// <summary> /// 删除预案条例 /// </summary> /// <param name="id"></param> public bool DeletePlanRegulationById(int id) { bool result = false; mapContext.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);//创建事务 try { int aresult = mapContext.Delete("DeletePlanRegulationById", id); if (aresult > 0) { ServRegulationFileModel RegulationFile = mapContext.QueryForObject <ServRegulationFileModel>("GetRegulationFileByRegId", id); int bresult = mapContext.Delete("DeletePlanRegulationFileById", id); if (bresult > 0) { int file_id = RegulationFile.file_id; int cresult = mapContext.Delete("DeletePlanFileInfoById", file_id); if (cresult > 0) { result = true; mapContext.CommitTransaction();//提交事务 return(result); } else { mapContext.RollBackTransaction();//事务回滚 return(result); } } else { mapContext.RollBackTransaction();//事务回滚 return(result); } } else { mapContext.RollBackTransaction();//事务回滚 return(result); } } catch (Exception ex) { mapContext.RollBackTransaction(); throw ex; } finally { //mapContext.CommitTransaction(); } }
public bool UpdateEntity(int id, ServRegulationFileModel newentity) { throw new NotImplementedException(); }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model"></param> public int UpdateRegulationFileById(ServRegulationFileModel model) { int result = mapContext.Update("UpdateRegulationFileById", model); return(result); }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="entity"></param> public int AddEntity(ServRegulationFileModel entity) { int id = (int)mapContext.Insert("InsertRegulationFile", entity); return(id); }
/// <summary> /// 修改预案条例 /// </summary> /// <param name="entity"></param> /// <param name="fileInfo"></param> /// <returns></returns> public bool UpdatePlanRegulation(ServPlanRegulationModel entity, List <ServFileInfoModel> fileInfo) { mapContext.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);//创建事务 try { bool result = false; //向预案条例信息表中添加信息 int regId = (int)mapContext.Update("UpdatePlanRegulationById", entity); if (regId > 0) { List <ServRegulationFileModel> servRegulationFileInfo = mapContext.QueryForList <ServRegulationFileModel>("GetRegulationFileByRegId", entity.id).ToList(); for (var i = 0; i < servRegulationFileInfo.Count(); i++) { int fileId = (int)mapContext.Delete("DeleteFileInfoById", servRegulationFileInfo[i].file_id); if (fileId > -1) { result = true; } else { mapContext.RollBackTransaction(); result = false; break; } } if (result == true) { int Id = (int)mapContext.Delete("DeletePlanRegulationFileById", entity.id); if (Id > -1) { //向文件表中添加数据 for (var i = 0; i < fileInfo.Count(); i++) { int fileId = (int)mapContext.Insert("InsertFileInfo", fileInfo[i]); if (fileId > 0) { //向关联表中添加信息 ServRegulationFileModel RegulationFile = new ServRegulationFileModel(); RegulationFile.reg_id = entity.id; RegulationFile.file_id = fileId; int relationId = (int)mapContext.Insert("InsertRegulationFile", RegulationFile); if (relationId > 0) { result = true; } else { result = false; break; } } else { result = false; } } } else { mapContext.RollBackTransaction(); result = false; } } } else { mapContext.RollBackTransaction(); result = false; } if (result == true) { mapContext.CommitTransaction();//提交事务 return(result); } else { mapContext.RollBackTransaction();//事务回滚 return(result); } } catch (Exception ex) { mapContext.RollBackTransaction(); throw ex; } finally { //mapContext.CommitTransaction(); } }
/// <summary> /// 添加预案条例 /// </summary> /// <param name="entity"></param> /// <param name="fileInfo"></param> /// <returns></returns> public bool AddPlanRegulation(ServPlanRegulationModel entity, List <ServFileInfoModel> fileInfo) { mapContext.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);//创建事务 try { bool result = false; //向预案条例信息表中添加信息 int regId = (int)mapContext.Insert("InsertPlanRegulation", entity); if (regId > 0) { //向文件表中添加数据 for (var i = 0; i < fileInfo.Count(); i++) { int fileId = (int)mapContext.Insert("InsertFileInfo", fileInfo[i]); if (fileId > 0) { //向关联表中添加信息 ServRegulationFileModel RegulationFile = new ServRegulationFileModel(); RegulationFile.reg_id = regId; RegulationFile.file_id = fileId; int relationId = (int)mapContext.Insert("InsertRegulationFile", RegulationFile); if (relationId > 0) { result = true; } else { result = false; } } else { result = false; } } } else { mapContext.RollBackTransaction(); result = false; } if (result == true) { mapContext.CommitTransaction();//提交事务 return(result); } else { mapContext.RollBackTransaction();//事务回滚 return(result); } } catch (Exception ex) { mapContext.RollBackTransaction(); throw ex; } finally { //mapContext.CommitTransaction(); } }