PageRenderTime 5052ms CodeModel.GetById 29ms RepoModel.GetById 2ms app.codeStats 0ms

/SourceCode/Wicresoft.RDW/Manage/VisitorStatistics.aspx.cs

#
C# | 254 lines | 226 code | 27 blank | 1 comment | 31 complexity | 2576d0e0e9206cbae60b8eec0787d844 MD5 | raw file
Possible License(s): LGPL-2.1
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Web.UI.WebControls;
  6. using Wicresoft.RDW.Presentation;
  7. using Wicresoft.RDW.Utility;
  8. namespace Wicresoft.RDW.Manage
  9. {
  10. public partial class VisitorStatistics : BasePage_BackEnd
  11. {
  12. private static RequestGroupType groupType = RequestGroupType.Request_VisitorType;
  13. private int Sum = 0;
  14. public class RequestGroupModel
  15. {
  16. public string RequestTypeName { get; set; }
  17. public int RequestCount { get; set; }
  18. public float RequestPercent { get; set; }
  19. }
  20. protected void grRuquestReport_RowDataBound(object sender, GridViewRowEventArgs e)
  21. {
  22. if (e.Row.RowType == DataControlRowType.DataRow)
  23. {
  24. var requestGroupModel = e.Row.DataItem as RequestGroupModel;
  25. var panProbress = e.Row.FindControl("panProbress") as Panel;
  26. panProbress.Width = new Unit(requestGroupModel.RequestPercent * 100, UnitType.Percentage);
  27. }
  28. if (e.Row.RowType == DataControlRowType.Footer)
  29. {
  30. e.Row.Cells[0].Text = Resources.ManageResource.mgr_lblTotalVisitCount;
  31. e.Row.Cells[1].Text = Sum.ToString();
  32. }
  33. }
  34. public override void InitControlResource()
  35. {
  36. lbtnVisitorType.Text = Resources.ManageResource.mgr_lblVisitorsClassification;
  37. lbtnLocation.Text = Resources.ManageResource.mgr_lblLocationName;
  38. lbtnLab.Text = Resources.ManageResource.mgr_lblLabName;
  39. lbtnProduct.Text = Resources.ManageResource.mgr_lblProductName;
  40. btnSelect.Text = Resources.ManageResource.mgr_btnQuery;
  41. int i = 1;
  42. //grRuquestReport.Columns[i++].HeaderText = Resources.ManageResource.mgr_lblVisitorsClassification;
  43. grRuquestReport.Columns[i++].HeaderText = Resources.ManageResource.mgr_lblVisitCount;
  44. grRuquestReport.Columns[i++].HeaderText = Resources.ManageResource.mgr_lblPercent;
  45. RuquestReportBind(groupType);
  46. }
  47. protected void lbtnVisitorType_Click(object sender, EventArgs e)
  48. {
  49. groupType = RequestGroupType.Request_VisitorType;
  50. RuquestReportBind(groupType);
  51. }
  52. protected void lbtnLocation_Click(object sender, EventArgs e)
  53. {
  54. groupType = RequestGroupType.Request_Location;
  55. RuquestReportBind(groupType);
  56. }
  57. protected void lbtnLab_Click(object sender, EventArgs e)
  58. {
  59. groupType = RequestGroupType.Request_Lab;
  60. RuquestReportBind(groupType);
  61. }
  62. protected void lbtnProduct_Click(object sender, EventArgs e)
  63. {
  64. groupType = RequestGroupType.Request_Product;
  65. RuquestReportBind(groupType);
  66. }
  67. protected void btnSelect_Click(object sender, EventArgs e)
  68. {
  69. RuquestReportBind(groupType);
  70. }
  71. private void RuquestReportBind(RequestGroupType eRequestGroupType)
  72. {
  73. lblOverError.Text = string.Empty;
  74. if (string.IsNullOrWhiteSpace(txtStartDate.Text) == false && string.IsNullOrWhiteSpace(txtEndDate.Text) == false)
  75. {
  76. if (string.Compare(txtStartDate.Text, txtEndDate.Text, true) > 0)
  77. {
  78. lblOverError.Text = Resources.NameResource.OverTimeError + "!";
  79. return;
  80. }
  81. }
  82. var listRequestGroupModel = new List<RequestGroupModel>();
  83. Expression<Func<Model.Request, bool>> searchExp = r => r.Status == 7;
  84. if (string.IsNullOrWhiteSpace(txtStartDate.Text) == false)
  85. {
  86. try
  87. {
  88. var startDate = DateTime.Parse(txtStartDate.Text);
  89. searchExp = searchExp.AndPredicate<Model.Request>(r => r.RequestDate >= startDate);
  90. }
  91. catch { }
  92. }
  93. if (string.IsNullOrWhiteSpace(txtEndDate.Text) == false)
  94. {
  95. try
  96. {
  97. var endDate = DateTime.Parse(txtEndDate.Text);
  98. searchExp = searchExp.AndPredicate(r => r.RequestDate <= endDate);
  99. }
  100. catch { }
  101. }
  102. var listRequest = RequestPresent.GetList(searchExp);
  103. switch (eRequestGroupType)
  104. {
  105. case RequestGroupType.Request_Location:
  106. grRuquestReport.Columns[0].HeaderText = Resources.ManageResource.mgr_lblLocationName;
  107. listRequestGroupModel = GetDataByLocation(listRequest);
  108. break;
  109. case RequestGroupType.Request_Lab:
  110. grRuquestReport.Columns[0].HeaderText = Resources.ManageResource.mgr_lblLabName;
  111. listRequestGroupModel = GetDataByLab(listRequest);
  112. break;
  113. case RequestGroupType.Request_Product:
  114. grRuquestReport.Columns[0].HeaderText = Resources.ManageResource.mgr_lblProductName;
  115. listRequestGroupModel = GetDataByProduct(listRequest);
  116. break;
  117. case RequestGroupType.Request_VisitorType:
  118. default:
  119. grRuquestReport.Columns[0].HeaderText = Resources.ManageResource.mgr_lblVisitorsClassification;
  120. listRequestGroupModel = GetDataByVisitorType(listRequest);
  121. break;
  122. }
  123. grRuquestReport.DataSource = listRequestGroupModel;
  124. grRuquestReport.DataBind();
  125. }
  126. private List<RequestGroupModel> GetDataByLocation(List<Model.Request> listRequest)
  127. {
  128. var listRequestGroupModel = new List<RequestGroupModel>();
  129. var lab = LabPresent.GetList();
  130. var location = LocationPresent.GetList();
  131. var group = from r in listRequest
  132. join l in lab on r.LabId equals l.LabId
  133. group l by l.LocationId into g
  134. select new { g.Key, count = g.Count() };
  135. Sum = group.Sum(p => p.count);
  136. foreach (var type in location)
  137. {
  138. var first = group.FirstOrDefault(g => g.Key == type.LocationId);
  139. var count = first == null ? 0 : first.count;
  140. listRequestGroupModel.Add(new RequestGroupModel
  141. {
  142. RequestTypeName = Language == Utility.Language.CN ? type.Name_CN : type.Name_EN,
  143. RequestCount = count,
  144. RequestPercent = count == 0 ? 0 : (float)count / Sum
  145. });
  146. }
  147. return listRequestGroupModel;
  148. }
  149. private List<RequestGroupModel> GetDataByLab(List<Model.Request> listRequest)
  150. {
  151. var listRequestGroupModel = new List<RequestGroupModel>();
  152. var lab = LabPresent.GetList();
  153. var group = from r in listRequest
  154. group r by r.LabId into g
  155. select new { g.Key, count = g.Count() };
  156. Sum = group.Sum(p => p.count);
  157. foreach (var type in lab)
  158. {
  159. var first = group.FirstOrDefault(g => g.Key == type.LabId);
  160. var count = first == null ? 0 : first.count;
  161. listRequestGroupModel.Add(new RequestGroupModel
  162. {
  163. RequestTypeName = type.Name,
  164. RequestCount = count,
  165. RequestPercent = count == 0 ? 0 : (float)count / Sum
  166. });
  167. }
  168. return listRequestGroupModel;
  169. }
  170. private List<RequestGroupModel> GetDataByProduct(List<Model.Request> listRequest)
  171. {
  172. var listRequestGroupModel = new List<RequestGroupModel>();
  173. var visitTequest = VisitRequestPresent.GetList();
  174. var visitProduct = VisitProductPresent.GetList();
  175. var product = ProductPresent.GetList();
  176. var group = from r in listRequest
  177. join vt in visitTequest on r.RequestId equals vt.RequestId
  178. join vp in visitProduct on vt.VisitRequestId equals vp.VisitRequestId
  179. group vp by vp.ProductId into g
  180. select new { g.Key, count = g.Count() };
  181. Sum = group.Sum(p => p.count);
  182. foreach (var type in product)
  183. {
  184. var first = group.FirstOrDefault(g => g.Key == type.ProductId);
  185. var count = first == null ? 0 : first.count;
  186. listRequestGroupModel.Add(new RequestGroupModel
  187. {
  188. RequestTypeName = Language == Utility.Language.CN ? type.Name_CN : type.Name_EN,
  189. RequestCount = count,
  190. RequestPercent = count == 0 ? 0 : (float)count / Sum
  191. });
  192. }
  193. return listRequestGroupModel;
  194. }
  195. private List<RequestGroupModel> GetDataByVisitorType(List<Model.Request> listRequest)
  196. {
  197. var listRequestGroupModel = new List<RequestGroupModel>();
  198. var visitRequest = VisitRequestPresent.GetList();
  199. var requestType = VisitTypePresent.GetList(v => v.Level != 1);
  200. var group = from r in listRequest
  201. join v in visitRequest on r.RequestId equals v.RequestId
  202. join vt in requestType on v.VisitType1 equals vt.Id
  203. group v by v.VisitType1 into g
  204. select new { g.Key, count = g.Count() };
  205. Sum = group.Sum(p => p.count);
  206. foreach (var type in requestType)
  207. {
  208. var first = group.FirstOrDefault(g => g.Key == type.Id);
  209. var count = first == null ? 0 : first.count;
  210. listRequestGroupModel.Add(new RequestGroupModel
  211. {
  212. RequestTypeName = Language == Utility.Language.CN ? type.Name_CN : type.Name_EN,
  213. RequestCount = count,
  214. RequestPercent = count == 0 ? 0 : (float)count / Sum
  215. });
  216. }
  217. return listRequestGroupModel;
  218. }
  219. }
  220. public enum RequestGroupType
  221. {
  222. Request_VisitorType = 0,
  223. Request_Location = 1,
  224. Request_Lab = 2,
  225. Request_Product = 3,
  226. }
  227. }