/// <summary> /// Add data to cache. /// </summary> private List <Report117Entity> AddDataToCache() { var userData = UserData; var cacheKey1 = WebUtility.GetCacheKeyName(userData, "kpi-report-117"); var cacheKey2 = WebUtility.GetCacheKeyName(userData, "kpi-report-117-02"); HttpRuntime.Cache.Remove(cacheKey1); HttpRuntime.Cache.Remove(cacheKey2); var lscIds = new List <int>(); if (LscsComboBox.SelectedIndex > 0) { var ids = WebUtility.ItemSplit(LscsComboBox.SelectedItem.Value); if (ids.Length == 2) { var lscId = Int32.Parse(ids[0]); var groupId = Int32.Parse(ids[1]); lscIds.Add(lscId); } } else { lscIds.AddRange(userData.LscUsers.Select(l => l.LscID)); } if (lscIds.Count == 0) { return(null); } var fromTime = DateTime.Parse(BeginFromDate.Text); var toTime = DateTime.Parse(BeginToDate.Text); var staTypes = new Dictionary <Int32, String>(); foreach (var dt in StaTypeMultiCombo.SelectedItems) { staTypes[Int32.Parse(dt.Value)] = dt.Text; } if (staTypes.Count == 0) { return(null); } var devTypes = new Dictionary <Int32, String>(); foreach (var dt in DevTypeMultiCombo.SelectedItems) { devTypes[Int32.Parse(dt.Value)] = dt.Text; } if (devTypes.Count == 0) { return(null); } var otherEntity = new BOther(); var lscEntity = new BLsc(); var source1 = new List <Report117Entity>(); var source2 = new Dictionary <String, List <StationInfo> >(); foreach (var id in lscIds) { var lsc = lscEntity.GetLsc(id); if (lsc == null) { continue; } var stations = new Dictionary <Int32, String>(); var bats = otherEntity.GetBatStaticCount(lsc.LscID, fromTime, toTime, null, null, 1d / 24d, Int32.MaxValue); if (bats != null && bats.Count > 0) { var devices = otherEntity.GetDevices(lsc.LscID).FindAll(d => staTypes.ContainsKey(d.StaTypeID) && devTypes.ContainsKey(d.DevTypeID)); var temp = from dev in devices join bat in bats on new { dev.LscID, dev.DevID } equals new { LscID = bat.ID, DevID = bat.Value } select dev; foreach (var t in temp) { stations[t.StaID] = t.StaName; } } var stations1 = otherEntity.GetStations(lsc.LscID).FindAll(s => stations.ContainsKey(s.StaID)); var stations2 = Report117Entity.GetStations(lsc.LscID, lsc.LscName, WebUtility.CreateLscConnectionString(lsc)); var record = new Report117Entity { LscID = lsc.LscID, LscName = lsc.LscName, ThisCount = stations1.Count, LastCount = stations2.Count }; source1.Add(record); source2[String.Format("{0}-ThisCount", lsc.LscID)] = stations1; source2[String.Format("{0}-LastCount", lsc.LscID)] = stations2; } if (source1.Count > 0) { source1.Add(new Report117Entity { LscID = -100, LscName = "汇总", ThisCount = (Int32)source1.Sum(r => r.ThisCount), LastCount = (Int32)source1.Sum(r => r.LastCount) }); } int cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]); HttpRuntime.Cache.Insert(cacheKey1, source1, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null); HttpRuntime.Cache.Insert(cacheKey2, source2, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null); return(source1); }
/// <summary> /// Add data to cache. /// </summary> private List <Report010Entity> AddDataToCache() { var userData = UserData; var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-010"); HttpRuntime.Cache.Remove(cacheKey); var lscIds = new List <int>(); if (LscsComboBox.SelectedIndex > 0) { var ids = WebUtility.ItemSplit(LscsComboBox.SelectedItem.Value); if (ids.Length == 2) { var lscId = Int32.Parse(ids[0]); var groupId = Int32.Parse(ids[1]); lscIds.Add(lscId); } } else { lscIds.AddRange(userData.LscUsers.Select(l => l.LscID)); } if (lscIds.Count == 0) { return(null); } var fromTime = DateTime.Parse(BeginFromDate.Text); var toTime = DateTime.Parse(BeginToDate.Text); var devTypes = new Dictionary <Int32, String>(); foreach (var dt in DevTypeMultiCombo.SelectedItems) { devTypes[Int32.Parse(dt.Value)] = dt.Text; } if (devTypes.Count == 0) { return(null); } var lscEntity = new BLsc(); var otherEntity = new BOther(); var result = new List <Report010Entity>(); foreach (var id in lscIds) { var lsc = lscEntity.GetLsc(id); if (lsc == null) { continue; } var bats = otherEntity.GetBatStaticCount(lsc.LscID, fromTime, toTime, null, null, 1d / 24d, Int32.MaxValue); var devices = otherEntity.GetDevices(lsc.LscID).FindAll(d => devTypes.ContainsKey(d.AlmDevTypeID)); var batDev = from dev in devices join bat in bats on new { dev.DevID } equals new { DevID = bat.Value } select dev; var parm = Report010Entity.GetLscParam(lsc.LscID, WebUtility.CreateLscConnectionString(lsc)); result.Add(new Report010Entity { LscID = lsc.LscID, LscName = lsc.LscName, ThisCount = batDev == null ? 0 : (fRadio.Checked ? batDev.GroupBy(d => d.StaID).Count() : batDev.GroupBy(d => d.Area3ID).Count()), LastCount = parm != null ? parm.StaTNumber : 0 }); } if (result.Count > 0) { result.Add(new Report010Entity { LscID = -100, LscName = "汇总(平均值)", ThisCount = (Int32)result.Average(r => r.ThisCount), LastCount = (Int32)result.Average(r => r.LastCount) }); } int cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]); HttpRuntime.Cache.Insert(cacheKey, result, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null); return(result); }