RetakeConditionServices.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq.Entity;
  6. using Bowin.Common.Utility;
  7. using EMIS.ViewModel.RetakeManage;
  8. using EMIS.DataLogic.RetakeManage;
  9. using EMIS.ViewModel;
  10. using EMIS.Utility;
  11. namespace EMIS.CommonLogic.RetakeManage
  12. {
  13. public class RetakeConditionServices : BaseServices, IRetakeConditionServices
  14. {
  15. public RetakeConditionDAL RetakeConditionDAL { get; set; }
  16. /// <summary>
  17. /// 查询对应的重修条件信息View
  18. /// </summary>
  19. /// <param name="conditionType"></param>
  20. /// <returns></returns>
  21. public RetakeConditionView GetRetakeConditionView(ER_RetakeConditionType conditionType)
  22. {
  23. var query = RetakeConditionDAL.GetRetakeConditionView(x => x.RetakeConditionTypeID == (int)conditionType);
  24. return query.FirstOrDefault();
  25. }
  26. /// <summary>
  27. /// 查询对应的重修条件参数值
  28. /// </summary>
  29. /// <typeparam name="T"></typeparam>
  30. /// <param name="parameterType"></param>
  31. /// <returns></returns>
  32. public Nullable<T> GetParameter<T>(ER_RetakeParameterType parameterType) where T : struct
  33. {
  34. try
  35. {
  36. var parameterTypeEntity = RetakeConditionDAL.RetakeConditionParameterRepository
  37. .GetSingle(x => x.RetakeParameterTypeID == (int)parameterType);
  38. if (parameterTypeEntity == null || string.IsNullOrEmpty(parameterTypeEntity.Value))
  39. {
  40. return null;
  41. }
  42. T result;
  43. if (parameterTypeEntity.Value.TryParseTo(out result))
  44. {
  45. return result;
  46. }
  47. return null;
  48. }
  49. catch (Exception ex)
  50. {
  51. throw new Exception(ex.Message);
  52. }
  53. }
  54. /// <summary>
  55. /// 重修条件参数保存
  56. /// </summary>
  57. /// <param name="parameterType"></param>
  58. /// <param name="value"></param>
  59. public void SetParameter(ER_RetakeParameterType parameterType, object value)
  60. {
  61. try
  62. {
  63. //查询重修条件信息View
  64. var retakeCondition = RetakeConditionDAL.GetRetakeConditionView(x => x.RetakeConditionTypeID == (int)ER_RetakeConditionType.NotPassCount)
  65. .SingleOrDefault();
  66. if (retakeCondition == null)
  67. {
  68. throw new Exception("重修条件未配置,请配置。");
  69. }
  70. else
  71. {
  72. var parameterTypeEntity = RetakeConditionDAL.RetakeConditionParameterRepository
  73. .GetSingle(x => x.RetakeParameterTypeID == (int)parameterType);
  74. if (parameterTypeEntity == null)
  75. {
  76. parameterTypeEntity = new Entities.ER_RetakeConditionParameter
  77. {
  78. RetakeConditionParameterID = Guid.NewGuid(),
  79. RetakeParameterTypeID = (int)parameterType
  80. };
  81. this.SetNewStatus(parameterTypeEntity);
  82. this.UnitOfWork.Add(parameterTypeEntity);
  83. }
  84. else
  85. {
  86. this.SetModifyStatus(parameterTypeEntity);
  87. }
  88. parameterTypeEntity.Value = value.ToString();
  89. this.UnitOfWork.Commit();
  90. }
  91. }
  92. catch (Exception ex)
  93. {
  94. throw new Exception(ex.Message);
  95. }
  96. }
  97. }
  98. }