QueryParamsModel.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Web;
  6. using Bowin.Common.Linq.Entity;
  7. namespace EMIS.ViewModel
  8. {
  9. public class QueryParamsModel
  10. {
  11. public int? page { get; set; }
  12. public int? rows { get; set; }
  13. public string QueryParamsDatas { get; set; }
  14. /// <summary>
  15. ///
  16. /// </summary>
  17. public string OrderBy
  18. {
  19. get
  20. {
  21. var orderby = (OrderByStatementView)HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"];
  22. if (orderby == null)
  23. {
  24. return null;
  25. }
  26. else
  27. {
  28. return orderby.OrderBy;
  29. }
  30. }
  31. set
  32. {
  33. if (value == null)
  34. {
  35. HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"] = null;
  36. return;
  37. }
  38. var orderby = (OrderByStatementView)HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"];
  39. if (orderby == null)
  40. {
  41. orderby = new OrderByStatementView() { OrderBy = value };
  42. }
  43. else
  44. {
  45. orderby.OrderBy = value;
  46. }
  47. HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"] = orderby;
  48. }
  49. }
  50. /// <summary>
  51. ///
  52. /// </summary>
  53. public bool? IsAsc
  54. {
  55. get
  56. {
  57. var orderby = (OrderByStatementView)HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"];
  58. if (orderby == null)
  59. {
  60. return null;
  61. }
  62. else
  63. {
  64. return orderby.isAsc;
  65. }
  66. }
  67. set
  68. {
  69. if (value == null)
  70. {
  71. HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"] = null;
  72. return;
  73. }
  74. var orderby = (OrderByStatementView)HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"];
  75. if (orderby == null)
  76. {
  77. orderby = new OrderByStatementView() { isAsc = value.Value };
  78. }
  79. else
  80. {
  81. orderby.isAsc = value.Value;
  82. }
  83. HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"] = orderby;
  84. }
  85. }
  86. /// <summary>
  87. ///
  88. /// </summary>
  89. /// <returns></returns>
  90. protected Dictionary<string, string> getParamsSource()
  91. {
  92. Dictionary<string, string> dicparams = new Dictionary<string, string>();
  93. if (!string.IsNullOrEmpty(QueryParamsDatas))
  94. {
  95. var arrayQueryParams = QueryParamsDatas.Split(new string[] { "|@|" }, StringSplitOptions.RemoveEmptyEntries);
  96. arrayQueryParams.ToList().ForEach(it =>
  97. {
  98. var arraydata = it.Split(new string[] { "|*|" }, StringSplitOptions.None);
  99. dicparams.Add(arraydata[0], arraydata[1]);
  100. });
  101. }
  102. return dicparams;
  103. }
  104. /// <summary>
  105. ///
  106. /// </summary>
  107. /// <param name="QueryparameName"></param>
  108. /// <returns></returns>
  109. public String getExtraString(string QueryparameName)
  110. {
  111. var datas = getParamsSource();
  112. string redata = "";
  113. if (datas.ContainsKey(QueryparameName))
  114. {
  115. redata = datas[QueryparameName];
  116. }
  117. return redata;
  118. }
  119. /// <summary>
  120. ///
  121. /// </summary>
  122. /// <param name="QueryparameName"></param>
  123. /// <returns></returns>
  124. public int? getExtraInt(string QueryparameName)
  125. {
  126. var datas = getParamsSource();
  127. Nullable<int> redata = new Nullable<int>();
  128. if (datas.ContainsKey(QueryparameName))
  129. {
  130. int idata = 0;
  131. if (int.TryParse(datas[QueryparameName], out idata))
  132. {
  133. redata = idata;
  134. }
  135. }
  136. return redata;
  137. }
  138. /// <summary>
  139. ///
  140. /// </summary>
  141. /// <param name="QueryparameName"></param>
  142. /// <returns></returns>
  143. public bool? getExtraBool(string QueryparameName)
  144. {
  145. var datas = getParamsSource();
  146. if (datas.ContainsKey(QueryparameName))
  147. {
  148. if (datas[QueryparameName].ToLower().Contains("true"))
  149. {
  150. return true;
  151. }
  152. else
  153. {
  154. return false;
  155. }
  156. }
  157. else
  158. {
  159. return null;
  160. }
  161. }
  162. /// <summary>
  163. ///
  164. /// </summary>
  165. /// <param name="QueryparameName"></param>
  166. /// <returns></returns>
  167. public DateTime? getExtraDateTime(string QueryparameName)
  168. {
  169. var datas = getParamsSource();
  170. Nullable<DateTime> redata = new Nullable<DateTime>();
  171. if (datas.ContainsKey(QueryparameName))
  172. {
  173. DateTime idata = DateTime.MinValue;
  174. if (DateTime.TryParse(datas[QueryparameName], out idata))
  175. {
  176. redata = idata;
  177. }
  178. }
  179. return redata;
  180. }
  181. /// <summary>
  182. ///
  183. /// </summary>
  184. /// <param name="QueryparameName"></param>
  185. /// <returns></returns>
  186. public Guid? getExtraGuid(string QueryparameName)
  187. {
  188. var datas = getParamsSource();
  189. Nullable<Guid> redata = new Nullable<Guid>();
  190. if (datas.ContainsKey(QueryparameName))
  191. {
  192. Guid idata = Guid.Empty;
  193. if (Guid.TryParse(datas[QueryparameName], out idata))
  194. {
  195. redata = idata;
  196. }
  197. }
  198. return redata;
  199. }
  200. }
  201. }