public ActionResult CTS340_searchIncident(string summaryPeriod) { ObjectResultData res = new ObjectResultData(); try { doSummaryPeriod condition = CTS340_getPeriodDate(summaryPeriod); IIncidentHandler hand = ServiceContainer.GetService<IIncidentHandler>() as IIncidentHandler; List<dtSummaryIncident> summary = hand.SummaryIncident(condition.dateFrom, condition.dateTo, condition.current); CommonUtil.MappingObjectLanguage<dtSummaryIncident>(summary); string xml = CommonUtil.ConvertToXml<dtSummaryIncident>(summary, "Contract\\CTS340", CommonUtil.GRID_EMPTY_TYPE.SEARCH); xml = xml.Replace("&amp;nbsp;", "&nbsp;"); //decode back res.ResultData = xml; } catch (Exception ex) { res.AddErrorMessage(ex); } return Json(res); }
/// <summary> /// Create search condition from selected summary period /// </summary> /// <param name="summaryPeriod"></param> /// <returns></returns> private doSummaryPeriod CTS340_getPeriodDate(string summaryPeriod) { doSummaryPeriod result = new doSummaryPeriod(); result.current = DateTime.Now; // All result.dateFrom = null; result.dateTo = null; DateTime temp = DateTime.Now; if (IncidentSummaryPeriod.C_INCIDENT_SUMMARY_PERIOD_THISWEEK.Equals(summaryPeriod)) { int dayOfWeek = (int)DateTime.Now.DayOfWeek; temp = DateTime.Now.AddDays(1.0 - dayOfWeek); result.dateFrom = new DateTime(temp.Year, temp.Month, temp.Day, 0, 0, 0); result.dateTo = new DateTime(result.current.Value.Year, result.current.Value.Month, result.current.Value.Day, 23, 59, 59); } else if (IncidentSummaryPeriod.C_INCIDENT_SUMMARY_PERIOD_THISMONTH.Equals(summaryPeriod)) { temp = CommonUtil.FirstDayOfMonthFromDateTime(result.current.Value.Month, result.current.Value.Year); result.dateFrom = new DateTime(temp.Year, temp.Month, temp.Day, 0, 0, 0); result.dateTo = new DateTime(result.current.Value.Year, result.current.Value.Month, result.current.Value.Day, 23, 59, 59); } else if (IncidentSummaryPeriod.C_INCIDENT_SUMMARY_PERIOD_LASTWEEK.Equals(summaryPeriod)) { int dayOfWeek = (int)DateTime.Now.DayOfWeek; temp = DateTime.Now.AddDays(-6.0 - dayOfWeek); //(1.0 - dayOfWeek - 7) result.dateFrom = new DateTime(temp.Year, temp.Month, temp.Day, 0, 0, 0); temp = DateTime.Now.AddDays(0 - dayOfWeek); result.dateTo = new DateTime(temp.Year, temp.Month, temp.Day, 23, 59, 59); } else if (IncidentSummaryPeriod.C_INCIDENT_SUMMARY_PERIOD_LASTMONTH.Equals(summaryPeriod)) { temp = CommonUtil.FirstDayOfMonthFromDateTime(result.current.Value.Month - 1, result.current.Value.Year); result.dateFrom = new DateTime(temp.Year, temp.Month, temp.Day, 0, 0, 0); temp = CommonUtil.LastDayOfMonthFromDateTime(result.current.Value.Month - 1, result.current.Value.Year); result.dateTo = new DateTime(temp.Year, temp.Month, temp.Day, 23, 59, 59); } else if (IncidentSummaryPeriod.C_INCIDENT_SUMMARY_PERIOD_TODAY.Equals(summaryPeriod)) { result.dateFrom = new DateTime(result.current.Value.Year, result.current.Value.Month, result.current.Value.Day, 0, 0, 0); result.dateTo = new DateTime(result.current.Value.Year, result.current.Value.Month, result.current.Value.Day, 23, 59, 59); } return result; }