123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Bowin.Common.Utility;
- using EMIS.DataLogic.SystemDAL;
- namespace EMIS.CommonLogic.SystemServices
- {
- public class ParameterServices : BaseServices, IParameterServices
- {
- public ParameterDAL ParameterDAL { get; set; }
- /// <summary>
- ///
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="parameterType"></param>
- /// <returns></returns>
- public Nullable<T> GetParameterValue<T>(ViewModel.CF_ParameterType parameterType) where T : struct
- {
- var parameter = ParameterDAL.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)parameterType);
- if (parameter == null || string.IsNullOrEmpty(parameter.Value)) return null;
- T result;
- if (parameter.Value.TryParseTo(out result))
- {
- return result;
- }
- return null;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="parameterType"></param>
- /// <returns></returns>
- public string GetParameterValue(ViewModel.CF_ParameterType parameterType)
- {
- var parameter = ParameterDAL.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)parameterType);
- if (parameter == null || string.IsNullOrEmpty(parameter.Value)) return null;
- return parameter.Value;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="parameterType"></param>
- /// <param name="value"></param>
- public void SaveTo(ViewModel.CF_ParameterType parameterType, object value)
- {
- var parameter = ParameterDAL.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)parameterType);
- if (parameter == null)
- {
- parameter = new Entities.CF_Parameter();
- parameter.ParameterID = Guid.NewGuid();
- parameter.ParameterTypeID = (int)parameterType;
- if (value != null)
- {
- parameter.Value = value.ToString();
- }
- else
- {
- parameter.Value = null;
- }
- this.SetNewStatus(parameter);
- this.UnitOfWork.Add(parameter);
- }
- else
- {
- if (value != null)
- {
- parameter.Value = value.ToString();
- }
- else
- {
- parameter.Value = null;
- }
- this.SetModifyStatus(parameter);
- }
- this.UnitOfWork.Commit();
- }
- }
- }
|