st_option.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Common;
  4. using System.Linq;
  5. using System.Text;
  6. using LJLib.DAL.SQL;
  7. using JLHHJSvr.Com.Model;
  8. namespace JLHHJSvr.DBA.DBModle
  9. {
  10. /// <summary>
  11. /// 1-系统收款二维码
  12. /// 2-默认违停收款金额
  13. /// 3-每月备案次数上限
  14. /// 4-即将过期判断天数
  15. /// </summary>
  16. [PK(new[] { "optionid" })]
  17. public sealed class st_option
  18. {
  19. /// <summary>
  20. /// ID
  21. /// </summary>
  22. public int? optionid { get; set; }
  23. /// <summary>
  24. /// 参数名
  25. /// </summary>
  26. public string optionname { get; set; }
  27. /// <summary>
  28. /// 参数值
  29. /// </summary>
  30. public string optionvalue { get; set; }
  31. /// <summary>
  32. /// 参数说明
  33. /// </summary>
  34. public string optiondscrp { get; set; }
  35. /// <summary>
  36. /// 修改人
  37. /// </summary>
  38. public string modemp { get; set; }
  39. /// <summary>
  40. /// 修改时间
  41. /// </summary>
  42. public DateTime? moddate { get; set; }
  43. /// <summary>
  44. /// key:optionid
  45. /// value:默认值
  46. /// </summary>
  47. /// <returns></returns>
  48. public Dictionary<int, st_option> GetDefaultOptions()
  49. {
  50. return new Dictionary<int, st_option>
  51. {
  52. {
  53. 1, new st_option
  54. {
  55. optionid = 1,
  56. optionname = "系统收款二维码",
  57. optionvalue = string.Empty,
  58. optiondscrp = "系统收款二维码"
  59. }
  60. },
  61. {
  62. 2, new st_option
  63. {
  64. optionid = 2,
  65. optionname = "默认违停收款金额(元/天)",
  66. optionvalue = "50",
  67. optiondscrp = "用于自动计算违停处理金额"
  68. }
  69. },
  70. {
  71. 3, new st_option
  72. {
  73. optionid = 3,
  74. optionname = "每月备案次数上限",
  75. optionvalue = "4",
  76. optiondscrp = "每月备案超过指定次数的会提示车主"
  77. }
  78. },
  79. {
  80. 4, new st_option
  81. {
  82. optionid = 4,
  83. optionname = "即将过期判断天数",
  84. optionvalue = "30",
  85. optiondscrp = "有效期结束前指定天数之后视为即将过期"
  86. }
  87. },
  88. {
  89. 5, new st_option
  90. {
  91. optionid = 5,
  92. optionname = "备案截止时间",
  93. optionvalue = "08:00",
  94. optiondscrp = "自助备案时,允许停放到次日的时间,格式hh:mm"
  95. }
  96. },
  97. {
  98. 6, new st_option
  99. {
  100. optionid = 6,
  101. optionname = "图片上传压缩后的宽度",
  102. optionvalue = "800",
  103. optiondscrp = "违停图片上传压缩后的宽度(数值越小图片占用空间越小)"
  104. }
  105. },
  106. {
  107. 7, new st_option
  108. {
  109. optionid = 7,
  110. optionname = "报备开放时间",
  111. optionvalue = "08:00",
  112. optiondscrp = "每天开始接受报备申请的时间点"
  113. }
  114. },
  115. {
  116. 8, new st_option
  117. {
  118. optionid = 8,
  119. optionname = "报备网页顶部通知",
  120. optionvalue = "",
  121. optiondscrp = "报备网页顶部显示的通知信息"
  122. }
  123. },
  124. {
  125. 9, new st_option
  126. {
  127. optionid = 9,
  128. optionname = "报备成功通知",
  129. optionvalue = "",
  130. optiondscrp = "报备网页成功后的弹框通知信息"
  131. }
  132. },
  133. {
  134. 10, new st_option
  135. {
  136. optionid = 10,
  137. optionname = "报备不在时间段的通知",
  138. optionvalue = "当前时间段未开放报备",
  139. optiondscrp = "当报备时间不在开放时间段时,报备页面显示的信息"
  140. }
  141. },
  142. };
  143. }
  144. public void SetValue(DbCommand cmd, int optionid, string value, string modemp)
  145. {
  146. if (optionid == 0)
  147. {
  148. throw new Exception("optionid can't be 0");
  149. }
  150. if (value == null)
  151. {
  152. throw new Exception("value can't be null");
  153. }
  154. switch (optionid)
  155. {
  156. case 2:
  157. case 3:
  158. case 4:
  159. case 6:
  160. try
  161. {
  162. var parsedValue = int.Parse(value);
  163. }
  164. catch (Exception)
  165. {
  166. throw new Exception("非法的系统参数值:只能为数字");
  167. }
  168. break;
  169. case 5:
  170. try
  171. {
  172. if (value.Length != 5 || !value.Contains(':'))
  173. {
  174. throw new Exception();
  175. }
  176. var parsedValue = DateTime.Parse(value);
  177. }
  178. catch (Exception)
  179. {
  180. throw new Exception("非法的系统参数值:格式只能为hh:mm");
  181. }
  182. break;
  183. }
  184. var defOption = GetDefaultOption(optionid);
  185. this.optionid = optionid;
  186. this.optionname = defOption.optionname;
  187. this.optionvalue = value;
  188. this.optiondscrp = defOption.optiondscrp;
  189. this.modemp = modemp;
  190. this.moddate = DateTime.Now;
  191. DbSqlHelper.InsertOrUpdate(cmd, this, "optionname, optionvalue,optiondscrp, modemp, moddate");
  192. }
  193. public String GetValue(DbCommand cmd)
  194. {
  195. return GetValue(cmd, optionid);
  196. }
  197. public String GetValue(DbCommand cmd, int? optionid)
  198. {
  199. if (optionid == null || optionid == 0)
  200. {
  201. throw new Exception("未定义的选项ID");
  202. }
  203. cmd.CommandText = "SELECT optionvalue FROM st_option WHERE optionid = " + optionid;
  204. cmd.Parameters.Clear();
  205. var rslt = cmd.ExecuteScalar();
  206. if (rslt != null && rslt != DBNull.Value)
  207. {
  208. return rslt.ToString();
  209. }
  210. //返回默认值
  211. var defaultOption = GetDefaultOption(optionid.Value);
  212. if (defaultOption == null)
  213. {
  214. return null;
  215. }
  216. else
  217. {
  218. return defaultOption.optionvalue;
  219. }
  220. }
  221. public st_option GetDefaultOption(int optionid)
  222. {
  223. if (optionid == 0)
  224. {
  225. throw new Exception("Unknown Exception: optionid[0]");
  226. }
  227. var defaultDic = GetDefaultOptions();
  228. if (defaultDic.ContainsKey(optionid))
  229. {
  230. return defaultDic[optionid];
  231. }
  232. return null;
  233. }
  234. }
  235. }