using NFine.Domain.Entity.SystemManage; using NFine.Domain.IRepository.SystemManage; using NFine.Repository; using NFine.Repository.SystemManage; using System; using System.Collections.Generic; using System.Data; using System.Linq; namespace NFine.Application.SystemManage { public class OrganizeApp : RepositoryFactory { private IOrganizeRepository service = new OrganizeRepository(); public List GetList() { List List = service.IQueryable().OrderBy(t => t.F_CreatorTime).ToList(); DataTable dt = GetOrganizeType(); Dictionary type = new Dictionary(); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { type.Add(dr["F_ItemCode"].ToString(), dr["F_ItemName"].ToString()); } } if (List != null && List.Count > 0) { for (int i = 0; i < List.Count; i++) { List[i].F_CategoryId = type[List[i].F_CategoryId]; } } return List; } public OrganizeEntity GetForm(string keyValue) { return service.FindEntity(keyValue); } public DataTable GetOrganizeType() { DataTable dt = new DataTable(); string sql = @" SELECT detail.F_ItemCode F_ItemCode ,detail.F_ItemName F_ItemName FROM Sys_SRM_Items item inner join Sys_SRM_ItemsDetail detail on detail.F_ItemId=item.F_Id WHERE item.F_EnCode='OrganizeType' and detail.F_EnabledMark='1' order BY detail.F_SortCode "; return Repository().FindTableBySql(sql); } public void DeleteForm(string keyValue) { if (service.IQueryable().Count(t => t.F_ParentId.Equals(keyValue)) > 0) { throw new Exception("删除失败!操作的对象包含了下级数据。"); } else { service.Delete(t => t.F_Id == keyValue); } } public void SubmitForm(OrganizeEntity organizeEntity, string keyValue) { if (!string.IsNullOrEmpty(keyValue)) { organizeEntity.Modify(keyValue); service.Update(organizeEntity); } else { organizeEntity.Create(); service.Insert(organizeEntity); } } } }