ParameterServices.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Utility;
  6. using EMIS.DataLogic.SystemDAL;
  7. namespace EMIS.CommonLogic.SystemServices
  8. {
  9. public class ParameterServices : BaseServices, IParameterServices
  10. {
  11. public ParameterDAL ParameterDAL { get; set; }
  12. /// <summary>
  13. ///
  14. /// </summary>
  15. /// <typeparam name="T"></typeparam>
  16. /// <param name="parameterType"></param>
  17. /// <returns></returns>
  18. public Nullable<T> GetParameterValue<T>(ViewModel.CF_ParameterType parameterType) where T : struct
  19. {
  20. var parameter = ParameterDAL.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)parameterType);
  21. if (parameter == null || string.IsNullOrEmpty(parameter.Value)) return null;
  22. T result;
  23. if (parameter.Value.TryParseTo(out result))
  24. {
  25. return result;
  26. }
  27. return null;
  28. }
  29. /// <summary>
  30. ///
  31. /// </summary>
  32. /// <param name="parameterType"></param>
  33. /// <returns></returns>
  34. public string GetParameterValue(ViewModel.CF_ParameterType parameterType)
  35. {
  36. var parameter = ParameterDAL.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)parameterType);
  37. if (parameter == null || string.IsNullOrEmpty(parameter.Value)) return null;
  38. return parameter.Value;
  39. }
  40. /// <summary>
  41. ///
  42. /// </summary>
  43. /// <param name="parameterType"></param>
  44. /// <param name="value"></param>
  45. public void SaveTo(ViewModel.CF_ParameterType parameterType, object value)
  46. {
  47. var parameter = ParameterDAL.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)parameterType);
  48. if (parameter == null)
  49. {
  50. parameter = new Entities.CF_Parameter();
  51. parameter.ParameterID = Guid.NewGuid();
  52. parameter.ParameterTypeID = (int)parameterType;
  53. if (value != null)
  54. {
  55. parameter.Value = value.ToString();
  56. }
  57. else
  58. {
  59. parameter.Value = null;
  60. }
  61. this.SetNewStatus(parameter);
  62. this.UnitOfWork.Add(parameter);
  63. }
  64. else
  65. {
  66. if (value != null)
  67. {
  68. parameter.Value = value.ToString();
  69. }
  70. else
  71. {
  72. parameter.Value = null;
  73. }
  74. this.SetModifyStatus(parameter);
  75. }
  76. this.UnitOfWork.Commit();
  77. }
  78. }
  79. }