/// <summary> /// 拖拽排序(拖拽完就保存) /// </summary> /// <param name="new_prev_order">拖拽后上节点排序值</param> /// <param name="currDisciplineId">当前被拖拽ID</param> /// <param name="currParentId">当前被拖拽ID的父ID</param> /// <returns></returns> public bool MoveDiscipline(SortDisciplineModel model, int System_Station_ID) { SqlMapper.BeginTransaction(); try { W_Discipline disModel = Orm.Single <W_Discipline>(x => x.ID == model.currDisciplineId && x.System_Station_ID == System_Station_ID); if (disModel == null) { throw new ApiException("请刷新重试,您要操作的数据不存在"); } if (model.currParentId == 0) { SqlMapper.Update("MoveIDDiscipline", new { new_prev_order = model.new_prev_order, currParentId = 0, currDisciplineId = model.currDisciplineId, System_Station_ID = System_Station_ID }); } else if (model.currParentId > 0) { SqlMapper.Update("MoveIDDiscipline", new { currParentId = model.currParentId, new_prev_order = model.new_prev_order, currDisciplineId = model.currDisciplineId, System_Station_ID = System_Station_ID }); } SqlMapper.CommitTransaction(); return(true); } catch (Exception ex) { SqlMapper.RollBackTransaction(); throw ex; } }
public dynamic MoveDiscipline(SortDisciplineModel model) { return(Success(mapper.MoveDiscipline(model, System_Station_ID))); }
/// <summary> /// 拖拽排序(拖拽完就保存) /// </summary> /// <param name="old_prev_order">拖拽前上节点排序值</param> /// <param name="old_next_order">拖拽前下节点排序值</param> /// <param name="new_prev_order">拖拽后上节点排序值</param> /// <param name="new_next_order">拖拽后下节点排序值</param> /// <param name="currDisciplineId">当前被拖拽ID</param> /// <param name="currParentId">当前被拖拽ID的父ID</param> /// <param name="System_Station_ID">系统ID</param> /// <returns></returns> public bool SortDiscipline(SortDisciplineModel model, int System_Station_ID) { SqlMapper.BeginTransaction(); try { W_Discipline Disciplinemodel = Orm.Single <W_Discipline>(x => x.ID == model.currDisciplineId && x.System_Station_ID == System_Station_ID); if (model.new_prev_order == model.old_prev_order && model.new_next_order == model.old_next_order) //没移动 { return(false); } if (model.new_prev_order == 0) //第一种情况:拖到最上面 (拖拽后上一层order为0) { Disciplinemodel.Orders = 1; if (Orm.Update(Disciplinemodel) > 0) { if (model.old_next_order == 0) //从最下面拖到最上面 { SqlMapper.Update("SortDiscipline", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, currDisciplineId = model.currDisciplineId }); } else { SqlMapper.Update("SortDiscipline1", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, old_next_order = model.old_next_order, currDisciplineId = model.currDisciplineId }); } } } else if (model.new_next_order == 0)//第二种情况:拖到最下面(拖拽后下一层order为0) { if (SqlMapper.Update("SortDiscipline2", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, currDisciplineId = model.currDisciplineId }) > 0) { if (model.old_prev_order == 0) //从最上面拖到最下面 { SqlMapper.Update("SortDiscipline3", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, currDisciplineId = model.currDisciplineId }); } else { SqlMapper.Update("SortDiscipline4", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, old_prev_order = model.old_prev_order, currDisciplineId = model.currDisciplineId }); } } } else if (model.new_prev_order > 0 && model.new_next_order > 0) //第三种情况:拖到中间 { if (model.new_prev_order < model.old_prev_order && model.new_next_order < model.old_next_order) //往上拖 { if (SqlMapper.Update("SortDiscipline5", new { new_next_order = model.new_next_order, currDisciplineId = model.currDisciplineId, System_Station_ID = System_Station_ID }) > 0) { if (model.old_next_order == 0) //从最下面往上拖 { SqlMapper.Update("SortDiscipline6", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, new_prev_order = model.new_prev_order, currDisciplineId = model.currDisciplineId }); } else { SqlMapper.Update("SortDiscipline7", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, old_next_order = model.old_next_order, new_prev_order = model.new_prev_order, currDisciplineId = model.currDisciplineId }); } } } else if (model.new_prev_order > model.old_prev_order && model.new_next_order > model.old_next_order)//往下拖 { if (SqlMapper.Update("SortDiscipline8", new { new_prev_order = model.new_prev_order, currDisciplineId = model.currDisciplineId, System_Station_ID = System_Station_ID }) > 0) { if (model.old_prev_order == 0) //从最上面往下拖 { SqlMapper.Update("SortDiscipline9", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, new_next_order = model.new_next_order, currDisciplineId = model.currDisciplineId }); } else { SqlMapper.Update("SortDiscipline10", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, new_next_order = model.new_next_order, old_prev_order = model.old_prev_order, currDisciplineId = model.currDisciplineId }); } } } } SqlMapper.CommitTransaction(); return(true); } catch (Exception ex) { SqlMapper.RollBackTransaction(); throw ex; } }