/// <summary> /// Add Data To Cache /// </summary> private List <AppointmentInfo> AddDataToCache() { var userData = UserData; var cacheKey = WebUtility.GetCacheKeyName(userData, "appointments"); HttpRuntime.Cache.Remove(cacheKey); if (LscsComboBox.SelectedItem.Value == null || LscsComboBox.SelectedItem.Value == String.Empty) { return(null); } var ids = WebUtility.ItemSplit(LscsComboBox.SelectedItem.Value); if (ids.Length != 2) { return(null); } var lscId = Int32.Parse(ids[0]); var lsc = new BLsc().GetLsc(lscId); if (lsc == null) { WebUtility.ShowMessage(EnmErrType.Warning, "无法获取Lsc信息"); return(null); } var beginTime = DateTime.Parse(BeginDate.Text); var endTime = DateTime.Parse(EndDate.Text); var queryType = Int32.Parse(QueryTypeComboBox.SelectedItem.Value); var queryText = QueryContentTextField.Text.Trim(); var appointmentEntity = new BAppointment(); var connectionString = WebUtility.CreateLscConnectionString(lsc); var appointments = appointmentEntity.GetAppointments(lsc.LscID, lsc.LscName, connectionString, beginTime, endTime, queryType, queryText); var cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]); HttpRuntime.Cache.Insert(cacheKey, appointments, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null); return(appointments); }
/// <summary> /// Add Data To Cache /// </summary> private List <ProjectReportPageEntity> AddDataToCache() { var userData = UserData; var cacheKey = WebUtility.GetCacheKeyName(userData, "project-report-entities"); HttpRuntime.Cache.Remove(cacheKey); if (LscsComboBox.SelectedItem.Value == null || LscsComboBox.SelectedItem.Value == String.Empty) { return(null); } var ids = WebUtility.ItemSplit(LscsComboBox.SelectedItem.Value); if (ids.Length != 2) { return(null); } var lsc = new BLsc().GetLsc(Int32.Parse(ids[0])); if (lsc == null) { WebUtility.ShowMessage(EnmErrType.Warning, "无法获取Lsc信息"); return(null); } var beginTime = DateTime.Parse(BeginDate.Text); var endTime = DateTime.Parse(EndDate.Text); var area2Id = WebUtility.DefaultInt32; var area3Id = WebUtility.DefaultInt32; if (Area2ComboBox.SelectedIndex > 0) { area2Id = Int32.Parse(Area2ComboBox.SelectedItem.Value); } if (Area3ComboBox.SelectedIndex > 0) { area3Id = Int32.Parse(Area3ComboBox.SelectedItem.Value); } var appointmentEntity = new BAppointment(); var connectionString = WebUtility.CreateLscConnectionString(lsc); var appointments1 = appointmentEntity.GetAppointments(lsc.LscID, lsc.LscName, connectionString, beginTime, endTime, 0, null); var appointments2 = appointmentEntity.GetHisAppointments(lsc.LscID, lsc.LscName, beginTime, endTime, 0, null); appointments1.AddRange(appointments2); var lscappointments = appointments1.FindAll(a => a.LscIncluded == lsc.LscID); var nonappointments = appointments1.FindAll(a => a.LscIncluded != lsc.LscID); var staSet = new List <IDValuePair <int, AppointmentInfo> >(); foreach (var apt in nonappointments) { if (apt.StaIncluded != null && apt.StaIncluded.Trim() != String.Empty) { var array = apt.StaIncluded.Split(';'); foreach (var id in array) { if (id.Trim() != String.Empty) { staSet.Add(new IDValuePair <int, AppointmentInfo>(Int32.Parse(id), apt)); } } } } var devSet = new List <IDValuePair <int, AppointmentInfo> >(); foreach (var apt in nonappointments) { if (apt.DevIncluded != null && apt.DevIncluded.Trim() != String.Empty) { var array = apt.DevIncluded.Split(';'); foreach (var id in array) { if (id.Trim() != String.Empty) { devSet.Add(new IDValuePair <int, AppointmentInfo>(Int32.Parse(id), apt)); } } } } var otherEntity = new BOther(); var stations = otherEntity.GetStations(lsc.LscID); var master1 = from ss in staSet join sta in stations on ss.ID equals sta.StaID select new IDValuePair <int, AppointmentInfo> { ID = sta.Area3ID, Value = ss.Value }; var devices = otherEntity.GetDevices(lsc.LscID); var master2 = from ds in devSet join dev in devices on ds.ID equals dev.DevID select new IDValuePair <int, AppointmentInfo> { ID = dev.Area3ID, Value = ds.Value }; var master = new Dictionary <String, IDValuePair <int, AppointmentInfo> >(); foreach (var mt in master1) { master[String.Format("{0}-{1}", mt.ID, mt.Value.Id)] = mt; } foreach (var mt in master2) { master[String.Format("{0}-{1}", mt.ID, mt.Value.Id)] = mt; } var areas = otherEntity.GetAreas(lsc.LscID); if (area2Id != WebUtility.DefaultInt32) { areas = areas.FindAll(a => a.Area2ID == area2Id); } if (area3Id != WebUtility.DefaultInt32) { areas = areas.FindAll(a => a.Area3ID == area3Id); } foreach (var area in areas) { foreach (var apt in lscappointments) { master[String.Format("{0}-{1}", area.Area3ID, apt.Id)] = new IDValuePair <int, AppointmentInfo>(area.Area3ID, apt); } } var a1 = from mt in master.Values group mt by new { AreaId = mt.ID, mt.Value.ProjectId } into g select new { g.Key.AreaId, g.Key.ProjectId, Time = g.Sum(a => a.Value.EndTime.Subtract(a.Value.StartTime).TotalSeconds) }; var projects = appointmentEntity.GetProjectItem(lsc.LscID, lsc.LscName, connectionString); var a2 = from a in a1 join p in projects on a.ProjectId equals p.ProjectId select new { AreaId = a.AreaId, Time = a.Time, Project = p, IsExProject = a.Time > p.EndTime.Subtract(p.BeginTime).TotalSeconds }; var a3 = from a in a2 group a by new { a.AreaId } into g select new { g.Key.AreaId, Time = g.Sum(p => p.Time), Projects = g.Select(p => p.Project).ToList(), ExProjects = g.Where(p => p.IsExProject).Select(p => p.Project).ToList() }; var a4 = from area in areas join a in a3 on area.Area3ID equals a.AreaId into l from aa in l.DefaultIfEmpty() select new ProjectReportPageEntity { Area = area, Time = aa != null ? aa.Time : 0, Projects = aa != null ? aa.Projects : new List <ProjectInfo>(), ExProjects = aa != null ? aa.ExProjects : new List <ProjectInfo>() }; var result = a4.ToList(); var cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]); HttpRuntime.Cache.Insert(cacheKey, result, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null); return(result); }