QueryParamsModel.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. public string OrderBy
  15. {
  16. get
  17. {
  18. var orderby = (OrderByStatementView)HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"];
  19. if (orderby == null)
  20. {
  21. return null;
  22. }
  23. else
  24. {
  25. return orderby.OrderBy;
  26. }
  27. }
  28. set
  29. {
  30. if (value == null)
  31. {
  32. HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"] = null;
  33. return;
  34. }
  35. var orderby = (OrderByStatementView)HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"];
  36. if (orderby == null)
  37. {
  38. orderby = new OrderByStatementView() { OrderBy = value };
  39. }
  40. else
  41. {
  42. orderby.OrderBy = value;
  43. }
  44. HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"] = orderby;
  45. }
  46. }
  47. public bool? IsAsc
  48. {
  49. get
  50. {
  51. var orderby = (OrderByStatementView)HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"];
  52. if (orderby == null)
  53. {
  54. return null;
  55. }
  56. else
  57. {
  58. return orderby.isAsc;
  59. }
  60. }
  61. set
  62. {
  63. if (value == null)
  64. {
  65. HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"] = null;
  66. return;
  67. }
  68. var orderby = (OrderByStatementView)HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"];
  69. if (orderby == null)
  70. {
  71. orderby = new OrderByStatementView() { isAsc = value.Value };
  72. }
  73. else
  74. {
  75. orderby.isAsc = value.Value;
  76. }
  77. HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"] = orderby;
  78. }
  79. }
  80. protected Dictionary<string, string> getParamsSource()
  81. {
  82. Dictionary<string, string> dicparams = new Dictionary<string, string>();
  83. if (!string.IsNullOrEmpty(QueryParamsDatas))
  84. {
  85. var arrayQueryParams = QueryParamsDatas.Split(new string[] { "|@|" }, StringSplitOptions.RemoveEmptyEntries);
  86. arrayQueryParams.ToList().ForEach(it =>
  87. {
  88. var arraydata = it.Split(new string[] { "|*|" }, StringSplitOptions.None);
  89. dicparams.Add(arraydata[0], arraydata[1]);
  90. });
  91. }
  92. return dicparams;
  93. }
  94. public List<ConfiguretView> getConditions()
  95. {
  96. var queryParams = this.getParamsSource();
  97. List<ConfiguretView> configuretViews = new List<ConfiguretView>();
  98. foreach (var item in queryParams)
  99. {
  100. if (item.Key != "Attribute" && item.Key != "ConditionValue" && item.Key != "Condition" && !item.Key.Contains("_QueryTextBox"))
  101. {
  102. if (!string.IsNullOrEmpty(item.Value) && item.Value != "-1")
  103. {
  104. configuretViews.Add(new ConfiguretView()
  105. {
  106. Attribute = item.Key,
  107. Condition = "=",
  108. ConditionValue = item.Value
  109. });
  110. }
  111. }
  112. }
  113. return configuretViews;
  114. }
  115. public String getExtraString(string QueryparameName)
  116. {
  117. var datas = getParamsSource();
  118. string redata = "";
  119. if (datas.ContainsKey(QueryparameName))
  120. {
  121. redata = datas[QueryparameName];
  122. }
  123. return redata;
  124. }
  125. public int? getExtraInt(string QueryparameName)
  126. {
  127. var datas = getParamsSource();
  128. Nullable<int> redata = new Nullable<int>();
  129. if (datas.ContainsKey(QueryparameName))
  130. {
  131. int idata = 0;
  132. if (int.TryParse(datas[QueryparameName], out idata))
  133. {
  134. redata = idata;
  135. }
  136. }
  137. return redata;
  138. }
  139. public bool? getExtraBool(string QueryparameName)
  140. {
  141. var datas = getParamsSource();
  142. if (datas.ContainsKey(QueryparameName))
  143. {
  144. if (datas[QueryparameName].ToLower().Contains("true"))
  145. {
  146. return true;
  147. }
  148. else
  149. {
  150. return false;
  151. }
  152. }
  153. else
  154. {
  155. return null;
  156. }
  157. }
  158. public DateTime? getExtraDateTime(string QueryparameName)
  159. {
  160. var datas = getParamsSource();
  161. Nullable<DateTime> redata = new Nullable<DateTime>();
  162. if (datas.ContainsKey(QueryparameName))
  163. {
  164. DateTime idata = DateTime.MinValue;
  165. if (DateTime.TryParse(datas[QueryparameName], out idata))
  166. {
  167. redata = idata;
  168. }
  169. }
  170. return redata;
  171. }
  172. public Guid? getExtraGuid(string QueryparameName)
  173. {
  174. var datas = getParamsSource();
  175. Nullable<Guid> redata = new Nullable<Guid>();
  176. if (datas.ContainsKey(QueryparameName))
  177. {
  178. Guid idata = Guid.Empty;
  179. if (Guid.TryParse(datas[QueryparameName], out idata))
  180. {
  181. redata = idata;
  182. }
  183. }
  184. return redata;
  185. }
  186. }
  187. }