/// <summary> /// 排序 /// </summary> /// <param name="ID"></param> /// <param name="IsUp"></param> public void Sort(int ID, bool IsUp) { using (var ct = new DS_PropertyDataContext(DbHelperSQL.Connection)) { var md = ct.DS_Property.Single(a => a.ID == ID); ct.ExecuteCommand("update DS_Property set px=(select RowNumber from (select (ROW_NUMBER() OVER (ORDER BY px)) AS RowNumber,id from DS_Property where SysCatID={0}) as p2 where id=DS_Property.id) where SysCatID={0}", md.SysCatID); if (IsUp) { DS_Property p = ct.DS_Property.Single(a => a.ID == ID); DS_Property p1; if (p.Px > 1) { p1 = ct.DS_Property.Single(a => a.Px == (p.Px - 1) && a.SysCatID == md.SysCatID); p.Px--; p1.Px++; } } else { DS_Property p = ct.DS_Property.Single(a => a.ID == ID); DS_Property p1; if (p.Px < ct.DS_Property.Where(a => a.SysCatID == md.SysCatID).Count()) { p1 = ct.DS_Property.Single(a => a.Px == (p.Px + 1) && a.SysCatID == md.SysCatID); p.Px++; p1.Px--; } } ct.SubmitChanges(); } }