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