123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- 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; }
- /// <summary>
- /// 查询对应的字典类型信息View
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="isEditable"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<DictionaryView> GetDictionaryViewGird(ConfiguretView configuretView, int? isEditable, int pageIndex, int pageSize)
- {
- //字典类型
- Expression<Func<Sys_Dictionary, bool>> 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<DictionaryView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询对应的字典类型信息List
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="isEditable"></param>
- /// <returns></returns>
- public IList<DictionaryView> GetDictionaryViewList(ConfiguretView configuretView, int? isEditable)
- {
- //字典类型
- Expression<Func<Sys_Dictionary, bool>> 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();
- }
- /// <summary>
- /// 根据字典类型Code查询对应的字典类型信息DictionaryView
- /// </summary>
- /// <param name="DictionaryCode"></param>
- /// <returns></returns>
- 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);
- }
- }
- /// <summary>
- /// 编辑(修改)
- /// </summary>
- /// <param name="dictionaryView"></param>
- 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);
- }
- }
- /// <summary>
- /// 删除(不可删除)
- /// </summary>
- /// <param name="dictionaryCodeList"></param>
- /// <returns></returns>
- public bool DictionaryDelete(IList<string> dictionaryCodeList)
- {
- try
- {
- //UnitOfWork.Delete<Sys_Dictionary>(x => dictionaryCodeList.Contains(x.DictionaryCode));
- //UnitOfWork.Commit();
- return false;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- }
- }
|