using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using Bowin.Common.Linq.Entity; using Bowin.Common.Linq; using EMIS.DataLogic.SystemSetting; using EMIS.ViewModel.SystemSetting; using EMIS.ViewModel; using EMIS.Entities; namespace EMIS.CommonLogic.SystemSetting { public class DictionaryServices : BaseServices, IDictionaryServices { public DictionaryDAL DictionaryDAL { get; set; } /// /// 查询对应的字典类型信息View /// /// /// /// /// /// public IGridResultSet GetDictionaryViewGird(ConfiguretView configuretView, int? isEditable, int pageIndex, int pageSize) { //字典类型 Expression> exp = (x => true); if (isEditable.HasValue) { //可否编辑 if (isEditable == (int)CF_GeneralPurpose.IsYes) { exp = exp.And(x => x.IsEditable == true); } if (isEditable == (int)CF_GeneralPurpose.IsNo) { exp = exp.And(x => x.IsEditable != true); } } var query = DictionaryDAL.GetDictionaryViewQueryable(exp); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.DictionaryCode).ThenBy(x => x.DictionaryName) .ThenBy(x => x.OrderNo) .ToGridResultSet(pageIndex, pageSize); } /// /// 查询对应的字典类型信息List /// /// /// /// public IList GetDictionaryViewList(ConfiguretView configuretView, int? isEditable) { //字典类型 Expression> exp = (x => true); if (isEditable.HasValue) { //可否编辑 if (isEditable == (int)CF_GeneralPurpose.IsYes) { exp = exp.And(x => x.IsEditable == true); } if (isEditable == (int)CF_GeneralPurpose.IsNo) { exp = exp.And(x => x.IsEditable != true); } } var query = DictionaryDAL.GetDictionaryViewQueryable(exp); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.DictionaryCode).ThenBy(x => x.DictionaryName) .ThenBy(x => x.OrderNo) .ToList(); } /// /// 根据字典类型Code查询对应的字典类型信息DictionaryView /// /// /// public DictionaryView GetDictionaryView(string DictionaryCode) { try { var dictionaryView = DictionaryDAL .GetDictionaryViewQueryable(x => x.DictionaryCode == DictionaryCode).SingleOrDefault(); return dictionaryView; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑(修改) /// /// public void DictionaryEdit(DictionaryView dictionaryView) { try { //查询数据库进行验证 var dictionaryVerification = DictionaryDAL.DictionaryRepository .GetList(x => x.DictionaryCode != dictionaryView.DictionaryCode && x.Name == dictionaryView.DictionaryName) .SingleOrDefault(); if (dictionaryVerification == null) { //数据有误验证 if (!string.IsNullOrEmpty(dictionaryView.DictionaryCode)) { var dictionary = DictionaryDAL.DictionaryRepository .GetList(x => x.DictionaryCode == dictionaryView.DictionaryCode) .SingleOrDefault(); if (dictionary == null) { throw new Exception("数据有误,请核查"); } else { //表示修改 dictionary.OrderNo = (short)dictionaryView.OrderNo; dictionary.Name = dictionaryView.DictionaryName; //SetModifyStatus(dictionary); } } else { //表示新增(暂不考虑) } } else { throw new Exception("已存在相同的类型名称,请核查"); } //事务提交 UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除(不可删除) /// /// /// public bool DictionaryDelete(IList dictionaryCodeList) { try { //UnitOfWork.Delete(x => dictionaryCodeList.Contains(x.DictionaryCode)); //UnitOfWork.Commit(); return false; } catch (Exception ex) { throw new Exception(ex.Message); } } } }