using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Linq; using WeiSha.Common; using Song.Entities; using WeiSha.Data; using Song.ServiceInterfaces; using System.Data.Common; namespace Song.ServiceImpls { public class AddressListCom : IAddressList { /// /// 清除所有信息 /// public void Clear() { Gateway.Default.Delete(AddressList._.Adl_Id > 0); Gateway.Default.Delete(AddressSort._.Ads_Id > 0); } /// /// 添加 /// /// 业务实体 public void AddressAdd(AddressList entity) { //当前通讯录信息,归属于某个用户,记录其id entity.Acc_Id = Extend.LoginState.Admin.CurrentUser.Acc_Id; Song.Entities.Organization org = Business.Do().OrganCurrent(); if (org != null) { entity.Org_ID = org.Org_ID; entity.Org_Name = org.Org_Name; } Gateway.Default.Save(entity); } /// /// 修改 /// /// 业务实体 public void AddressSave(AddressList entity) { Gateway.Default.Save(entity); } /// /// 删除 /// /// 业务实体 public void AddressDelete(AddressList entity) { Gateway.Default.Delete(AddressList._.Adl_Id == entity.Adl_Id); } /// /// 删除,按主键ID; /// /// 实体的主键 public void AddressDelete(int identify) { Gateway.Default.Delete(AddressList._.Adl_Id == identify); } /// /// 删除所有 /// public void AddressDeleteAll() { Gateway.Default.Delete(AddressList._.Adl_Id > 0); } /// /// 删除,按人员名称 /// /// 人员名称 public void AddressDelete(string name) { Gateway.Default.Delete(AddressList._.Adl_Name == name); } /// /// 获取单一实体对象,按主键ID; /// /// 实体的主键 /// public AddressList AddressSingle(int identify) { return Gateway.Default.From().Where(AddressList._.Adl_Id == identify).ToFirst(); } public AddressList AddressSingle(string mobiTel) { return Gateway.Default.From().Where(AddressList._.Adl_MobileTel == mobiTel.Trim()).ToFirst(); } /// /// 获取某个院系的所有人员; /// /// 是否显示 /// public List AddressAll() { return Gateway.Default.From().ToList(); } public List AddressAll(int? sortId) { WhereClip wc = new WhereClip(); if (sortId != null && sortId > 0) wc.And(AddressList._.Ads_Id == (int)sortId); return Gateway.Default.From().Where(wc).ToList(); } /// /// 分页获取所有的人员; /// /// 每页显示几条记录 /// 当前第几页 /// 记录总数 /// public List AddressPager(int accId, int size, int index, out int countSum) { WhereClip wc = AddressList._.Acc_Id == accId; countSum = Gateway.Default.Count(wc); return Gateway.Default.From().Where(wc).OrderBy(AddressList._.Adl_Id.Desc).ToList(size, (index - 1) * size); } /// /// 分页获取所有的人员; /// /// 分类id /// /// /// /// public List AddressPager(int accId, string typeName, string personName, int size, int index, out int countSum) { WhereClip wc = AddressList._.Acc_Id == accId; if (typeName.Trim()!="") { wc.And(AddressList._.Ads_Name == typeName); } if (personName.Trim() != "" && personName != null) { wc.And(AddressList._.Adl_Name.Like("%" + personName + "%")); } countSum = Gateway.Default.Count(wc); return Gateway.Default.From().Where(wc).OrderBy(AddressList._.Adl_Name.Asc).ToList(size, (index - 1) * size); } #region 通讯录分类 /// /// 添加 /// /// 业务实体 public int SortAdd(AddressSort entity) { //添加对象,并设置排序号 object obj = Gateway.Default.Max( AddressSort._.Ads_Tax,AddressSort._.Ads_Id > -1); int tax = 0; if (obj is int) tax = (int)obj; entity.Ads_Tax = tax + 1; return Gateway.Default.Save(entity); } /// /// 修改 /// /// 业务实体 public void SortSave(AddressSort entity) { using (DbTrans trans = Gateway.Default.BeginTrans()) { try { trans.Save(entity); trans.Update(new Field[] { AddressList._.Ads_Name }, new object[] { entity.Ads_Name }, AddressList._.Ads_Id == entity.Ads_Id); trans.Commit(); } catch { trans.Rollback(); throw; } finally { trans.Close(); } } } /// /// 删除 /// /// 业务实体 public void SortDelete(AddressSort entity) { this.SortDelete(entity.Ads_Id); } /// /// 删除,按主键ID; /// /// 实体的主键 public void SortDelete(int identify) { using (DbTrans tran = Gateway.Default.BeginTrans()) { try { object obj = Gateway.Default.Count(AddressList._.Ads_Id == identify); if ((int)obj > 0) throw new Exception("当前分类含有下属信息,请勿删除"); // tran.Delete(AddressSort._.Ads_Id); tran.Delete(AddressList._.Ads_Id); tran.Commit(); } catch { tran.Rollback(); throw; } finally { tran.Close(); } } } /// /// 清除所有分类,包括通讯录信息 /// public void SortDeleteAll() { Gateway.Default.Delete(AddressList._.Adl_Id > 0); Gateway.Default.Delete(AddressSort._.Ads_Id > 0); } /// /// 获取单一实体对象,按主键ID; /// /// 实体的主键 /// public AddressSort SortSingle(int identify) { return Gateway.Default.From().Where(AddressSort._.Ads_Id == identify).ToFirst(); } /// /// 获取某个院系的所有人员; /// /// 是否使用 /// public List SortAll(bool? isUse) { WhereClip wc = new WhereClip(); if (isUse != null) wc.And(AddressSort._.Ads_IsUse == (bool)isUse); return Gateway.Default.From().Where(wc).ToList(); } /// /// 分页获取; /// /// 所属人员的id /// 每页显示几条记录 /// 当前第几页 /// 记录总数 /// public List SortPager(int accId, int size, int index, out int countSum) { WhereClip wc = AddressSort._.Acc_Id == accId; countSum = Gateway.Default.Count(wc); return Gateway.Default.From().Where(wc).OrderBy(AddressSort._.Ads_Tax.Desc).ToList(size, (index - 1) * size); } /// /// 分页获取所有的人员; /// /// 所属人员的id /// 分类名称 /// /// /// /// public List SortPager(int accId, string sortName, int size, int index, out int countSum) { WhereClip wc = AddressSort._.Acc_Id == accId; if (sortName != string.Empty) wc.And(AddressSort._.Ads_Name.Like("%" + sortName + "%")); countSum = Gateway.Default.Count(wc); return Gateway.Default.From().Where(wc).OrderBy(AddressSort._.Ads_Tax.Desc).ToList(size, (index - 1) * size); } /// /// 将当前栏目向上移动;仅在当前对象的同层移动,即同一父节点下的对象之间移动; /// /// /// 如果已经处于顶端,则返回false;移动成功,返回true public bool SortRemoveUp(int id) { //当前对象 AddressSort current = Gateway.Default.From().Where(AddressSort._.Ads_Id == id).ToFirst(); //当前对象排序号 int orderValue = (int)current.Ads_Tax; //上一个对象,即兄长对象; AddressSort up = Gateway.Default.From().Where(AddressSort._.Ads_Tax > orderValue).OrderBy(AddressSort._.Ads_Tax.Asc).ToFirst(); if (up == null) { //如果兄长对象不存在,则表示当前节点在兄弟中是老大;即是最顶点; return false; } //交换排序号 current.Ads_Tax = up.Ads_Tax; up.Ads_Tax = orderValue; using (DbTrans trans = Gateway.Default.BeginTrans()) { try { trans.Save(current); trans.Save(up); trans.Commit(); return true; } catch { trans.Rollback(); throw; } finally { trans.Close(); } } } /// /// 将当前栏目向下移动;仅在当前对象的同层移动,即同一父节点下的对象之间移动; /// /// /// 如果已经处于最底端,则返回false;移动成功,返回true public bool SortRemoveDown(int id) { //当前对象 AddressSort current = Gateway.Default.From().Where(AddressSort._.Ads_Id == id).ToFirst(); //当前对象排序号 int orderValue = (int)current.Ads_Tax; //下一个对象,即弟弟对象; AddressSort down = Gateway.Default.From().Where(AddressSort._.Ads_Tax < orderValue).OrderBy(AddressSort._.Ads_Tax.Desc).ToFirst(); if (down == null) { //如果弟对象不存在,则表示当前节点在兄弟中是老幺;即是最底端; return false; } //交换排序号 current.Ads_Tax = down.Ads_Tax; down.Ads_Tax = orderValue; using (DbTrans trans = Gateway.Default.BeginTrans()) { try { trans.Save(current); trans.Save(down); trans.Commit(); } catch { trans.Rollback(); throw; } finally { trans.Close(); } } return true; } #endregion } }