public void SortSave(TeacherSort entity) { using (DbTrans tran = Gateway.Default.BeginTrans()) { try { tran.Save <TeacherSort>(entity); tran.Update <Teacher>(new Field[] { Teacher._.Ths_Name }, new object[] { entity.Ths_Name }, Teacher._.Ths_ID == entity.Ths_ID); if (entity.Ths_IsDefault) { tran.Update <TeacherSort>(new Field[] { TeacherSort._.Ths_IsDefault }, new object[] { false }, TeacherSort._.Ths_ID != entity.Ths_ID && TeacherSort._.Org_ID == entity.Org_ID); tran.Update <TeacherSort>(new Field[] { TeacherSort._.Ths_IsDefault }, new object[] { true }, TeacherSort._.Ths_ID == entity.Ths_ID && TeacherSort._.Org_ID == entity.Org_ID); } tran.Commit(); } catch (Exception ex) { tran.Rollback(); throw ex; } finally { tran.Close(); } } }
public bool SortIsExist(TeacherSort entity) { //如果是一个已经存在的对象,则不匹配自己 TeacherSort mm = Gateway.Default.From <TeacherSort>() .Where(TeacherSort._.Org_ID == entity.Org_ID && TeacherSort._.Ths_Name == entity.Ths_Name && TeacherSort._.Ths_ID != entity.Ths_ID) .ToFirst <TeacherSort>(); return(mm != null); }
public void SortAdd(TeacherSort entity) { Song.Entities.Organization org = Business.Do <IOrganization>().OrganCurrent(); if (org != null) { entity.Org_ID = org.Org_ID; entity.Org_Name = org.Org_Name; } //添加对象,并设置排序号 object obj = Gateway.Default.Max <TeacherSort>(TeacherSort._.Ths_Tax, TeacherSort._.Org_ID == org.Org_ID); entity.Ths_Tax = obj is int?(int)obj + 1 : 0; Gateway.Default.Save <TeacherSort>(entity); }
public bool SortRemoveDown(int orgid, int id) { //当前对象 TeacherSort current = Gateway.Default.From <TeacherSort>().Where(TeacherSort._.Ths_ID == id).ToFirst <TeacherSort>(); //当前对象排序号 int orderValue = (int)current.Ths_Tax; //下一个对象,即弟弟对象; TeacherSort down = Gateway.Default.From <TeacherSort>() .Where(TeacherSort._.Org_ID == orgid && TeacherSort._.Ths_Tax > orderValue) .OrderBy(TeacherSort._.Ths_Tax.Asc).ToFirst <TeacherSort>(); if (down == null) { return(false); } //交换排序号 current.Ths_Tax = down.Ths_Tax; down.Ths_Tax = orderValue; using (DbTrans tran = Gateway.Default.BeginTrans()) { try { tran.Save <TeacherSort>(current); tran.Save <TeacherSort>(down); tran.Commit(); } catch { tran.Rollback(); throw; } finally { tran.Close(); } } return(true); }
private void TeacherListSort(TeacherSort sortBy) { List <TeacherListItemViewModel> newList; switch (sortBy) { case TeacherSort.Name: newList = TeacherList.OrderBy(x => x.Teacher.Name).ToList(); TeacherListSortLabel = "Name"; break; case TeacherSort.Username: newList = TeacherList.OrderBy(x => x.Teacher.Username).ToList(); TeacherListSortLabel = "Username"; break; case TeacherSort.Access: newList = TeacherList.OrderBy(x => x.Teacher.Permission).ToList(); TeacherListSortLabel = "Permission"; break; case TeacherSort.Status: newList = TeacherList.OrderBy(x => x.Teacher.Status).ToList(); TeacherListSortLabel = "Status"; break; default: newList = TeacherList.OrderBy(x => x.Teacher.Teacher_ID).ToList(); TeacherListSortLabel = "ID"; break; } if (newList != null) { TeacherList = newList; } }