Ejemplo n.º 1
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report115Entity> AddDataToCache()
        {
            var userData  = UserData;
            var cacheKey1 = WebUtility.GetCacheKeyName(userData, "kpi-report-115");
            var cacheKey2 = WebUtility.GetCacheKeyName(userData, "kpi-report-115-02");

            HttpRuntime.Cache.Remove(cacheKey1);
            HttpRuntime.Cache.Remove(cacheKey2);

            var lscs = new List <LscUserInfo>();

            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]);
                    var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                    if (lscUser != null)
                    {
                        lscs.Add(lscUser);
                    }
                }
            }
            else
            {
                lscs.AddRange(userData.LscUsers);
            }
            if (lscs.Count == 0)
            {
                return(null);
            }

            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 fromTime = DateTime.Parse(BeginFromDate.Text);
            var toTime   = DateTime.Parse(BeginToDate.Text);

            var auxSets    = new List <String>();
            var texts      = new List <String>();
            var filterText = WebUtility.StringSplit(NodeText.Text.Trim());

            foreach (var ft in filterText)
            {
                if (String.IsNullOrEmpty(ft.Trim()))
                {
                    continue;
                }
                if (FilterList.SelectedItem.Value.Equals("1"))
                {
                    auxSets.Add(ft.Trim());
                }
                else
                {
                    texts.Add(ft.Trim());
                }
            }
            if (texts.Count == 0 && auxSets.Count == 0)
            {
                return(null);
            }

            var almNames = new List <String>();
            var almIds   = new Dictionary <String, String>();
            var almText  = WebUtility.StringSplit(AlarmNameText.Text.Trim());

            foreach (var at in almText)
            {
                if (String.IsNullOrEmpty(at.Trim()))
                {
                    continue;
                }
                if (AlmNameList.SelectedItem.Value.Equals("1"))
                {
                    almIds[at.Trim()] = null;
                }
                else
                {
                    almNames.Add(at.Trim());
                }
            }

            var nodeEntity   = new BNode();
            var otherEntity  = new BOther();
            var alarmEntity  = new BAlarm();
            var source1      = new List <Report115Entity>();
            var source2      = new Dictionary <String, List <StationInfo> >();
            var activeAlarms = WebUtility.GetUserAlarms(userData).FindAll(alarm => lscs.Any(l => l.LscID == alarm.LscID) && alarm.StartTime >= fromTime && alarm.StartTime <= toTime);

            foreach (var lsc in lscs)
            {
                var alarms = activeAlarms.FindAll(a => a.LscID == lsc.LscID);
                alarms.AddRange(alarmEntity.GetHisAlarms(lsc.LscID, lsc.LscName, userData.StandardProtocol, lsc.Group.GroupNodes, fromTime, toTime));
                if (almNames.Count > 0)
                {
                    alarms = alarms.FindAll(a => almNames.Any(n => a.AlarmName.Contains(n)));
                }
                if (almIds.Count > 0)
                {
                    alarms = alarms.FindAll(a => almIds.ContainsKey(a.AlarmID.ToString()));
                }

                var stations = otherEntity.GetStations(lsc.LscID).FindAll(s => staTypes.ContainsKey(s.StaTypeID));
                var nodes    = nodeEntity.GetNodes(lsc.LscID, EnmNodeType.Aic, texts.ToArray(), auxSets.ToArray(), null);
                var gn       = from n in nodes
                               group n by n.StaID into g
                               select new {
                    StaID = g.Key,
                    Nodes = g.ToList()
                };

                var ns = from s in stations
                         join n in gn on s.StaID equals n.StaID
                         select new {
                    Station = s,
                    Nodes   = n.Nodes
                };

                var ndWam = from alarm in alarms
                            join node in nodes on new { alarm.NodeID, alarm.NodeType } equals new { node.NodeID, node.NodeType }
                select new {
                    Node  = node,
                    Alarm = alarm
                };

                var gndWam = from na in ndWam
                             group na by na.Node.StaID into g
                             select new {
                    StaID  = g.Key,
                    Alarms = g.Select(a => a.Alarm)
                };

                var sndWam = from s in ns
                             join gw in gndWam on s.Station.StaID equals gw.StaID
                             select new {
                    Station = s.Station,
                    Nodes   = s.Nodes,
                    Alarms  = gw.Alarms
                };

                source1.Add(new Report115Entity {
                    LscID     = lsc.LscID,
                    LscName   = lsc.LscName,
                    ThisCount = sndWam.Count(),
                    LastCount = ns.Count()
                });

                source2[String.Format("{0}-ThisCount", lsc.LscID)] = sndWam.Select(s => s.Station).ToList();
                source2[String.Format("{0}-LastCount", lsc.LscID)] = ns.Select(s => s.Station).ToList();
            }

            if (source1.Count > 0)
            {
                source1.Add(new Report115Entity {
                    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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report004Entity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-004");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscs = new List <LscUserInfo>();

            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]);
                    var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                    if (lscUser != null)
                    {
                        lscs.Add(lscUser);
                    }
                }
            }
            else
            {
                lscs.AddRange(userData.LscUsers);
            }
            if (lscs.Count == 0)
            {
                return(null);
            }

            var fromTime = DateTime.Parse(BeginFromDate.Text);
            var toTime   = DateTime.Parse(BeginToDate.Text);
            var roads    = Convert.ToInt32(EPRoadSpinnerField.Number);

            var auxSets    = new List <String>();
            var texts      = new List <String>();
            var filterText = WebUtility.StringSplit(NodeText.Text.Trim());

            foreach (var ft in filterText)
            {
                if (String.IsNullOrEmpty(ft.Trim()))
                {
                    continue;
                }
                if (FilterList.SelectedItem.Value.Equals("1"))
                {
                    auxSets.Add(ft.Trim());
                }
                else
                {
                    texts.Add(ft.Trim());
                }
            }
            if (texts.Count == 0 && auxSets.Count == 0)
            {
                return(null);
            }

            var almNames = new List <String>();
            var almIds   = new Dictionary <String, String>();
            var almText  = WebUtility.StringSplit(AlarmNameText.Text.Trim());

            foreach (var at in almText)
            {
                if (String.IsNullOrEmpty(at.Trim()))
                {
                    continue;
                }
                if (AlmNameList.SelectedItem.Value.Equals("1"))
                {
                    almIds[at.Trim()] = null;
                }
                else
                {
                    almNames.Add(at.Trim());
                }
            }

            var nodeEntity  = new BNode();
            var nodes       = new List <NodeInfo>();
            var otherEntity = new BOther();
            var stations    = new List <StationInfo>();

            foreach (var lsc in lscs)
            {
                nodes.AddRange(nodeEntity.GetNodes(lsc.LscID, EnmNodeType.Img, texts.ToArray(), auxSets.ToArray(), null));
                stations.AddRange(otherEntity.GetStations(lsc.LscID, lsc.Group.GroupID));
            }

            var alarmEntity = new BAlarm();
            var alarms      = WebUtility.GetUserAlarms(userData).FindAll(alarm => lscs.Any(l => l.LscID == alarm.LscID) && alarm.StartTime >= fromTime && alarm.StartTime <= toTime);

            foreach (var lsc in lscs)
            {
                alarms.AddRange(alarmEntity.GetHisAlarms(lsc.LscID, lsc.LscName, userData.StandardProtocol, lsc.Group.GroupNodes, fromTime, toTime));
            }

            var ndWam = from alarm in alarms
                        join node in nodes on new { alarm.LscID, alarm.NodeID, alarm.NodeType } equals new { node.LscID, node.NodeID, node.NodeType }
            where (almNames.Count == 0 || almNames.Any(name => alarm.AlarmName.Contains(name))) && (almIds.Count == 0 || almIds.ContainsKey(alarm.AlarmID.ToString())) && string.IsNullOrEmpty(alarm.ProjName)
            select new {
                Node  = node,
                Alarm = alarm
            };

            var almGroup = from alarm in ndWam
                           group alarm by new { alarm.Node.LscID, alarm.Node.StaID } into g
                select new {
                LscID  = g.Key.LscID,
                StaID  = g.Key.StaID,
                Alarms = g.Select(a => a.Alarm)
            };

            var result = (from sta in stations
                          join ag in almGroup on new { sta.LscID, sta.StaID } equals new { ag.LscID, ag.StaID } into lt
                          from la in lt.DefaultIfEmpty()
                          orderby sta.LscID, sta.StaID
                          select new Report004Entity {
                LscID = sta.LscID,
                LscName = sta.LscName,
                Area2ID = sta.Area2ID,
                Area2Name = sta.Area2Name,
                Area3ID = sta.Area3ID,
                Area3Name = sta.Area3Name,
                StaID = sta.StaID,
                StaName = sta.StaName,
                BeginTime = fromTime,
                EndTime = toTime,
                Roads = roads,
                Alarms = la == null ? new List <AlarmInfo>() : la.Alarms.ToList()
            }).ToList();

            if (result.Count > 0)
            {
                result.Add(new Report004Entity {
                    LscID     = -100,
                    LscName   = "汇总(平均值)",
                    Area2ID   = WebUtility.DefaultInt32,
                    Area2Name = WebUtility.DefaultString,
                    Area3ID   = WebUtility.DefaultInt32,
                    Area3Name = WebUtility.DefaultString,
                    StaID     = WebUtility.DefaultInt32,
                    StaName   = WebUtility.DefaultString,
                    BeginTime = fromTime,
                    EndTime   = toTime,
                    Roads     = roads,
                    Alarms    = new List <AlarmInfo>()
                });
            }

            int cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]);

            HttpRuntime.Cache.Insert(cacheKey, result, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report122Entity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-122");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscUsers = new List <LscUserInfo>();

            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]);
                    var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                    if (lscUser != null)
                    {
                        lscUsers.Add(lscUser);
                    }
                }
            }
            else
            {
                lscUsers.AddRange(userData.LscUsers);
            }

            if (lscUsers.Count == 0)
            {
                return(null);
            }

            var fromTime = DateTime.Parse(BeginFromDate.Text);
            var toTime   = DateTime.Parse(BeginToDate.Text);
            var dates    = new List <string>();
            var temp     = fromTime;

            while (temp <= toTime)
            {
                dates.Add(WebUtility.GetDateString2(temp));
                temp = temp.AddDays(1);
            }

            var staTypes = new HashSet <int>();

            foreach (var dt in StaTypeMultiCombo.SelectedItems)
            {
                staTypes.Add(int.Parse(dt.Value));
            }
            if (staTypes.Count == 0)
            {
                return(null);
            }

            var alarmId = int.Parse(AlarmNameComboBox.SelectedItem.Value);

            var otherEntity = new BOther();
            var alarmEntity = new BAlarm();
            var source      = new List <Report122Entity>();

            foreach (var lu in lscUsers)
            {
                var stations = otherEntity.GetStations(lu.LscID, lu.Group.GroupID).FindAll(s => staTypes.Contains(s.StaTypeID));
                var alarms   = alarmEntity.GetHisAlarms(lu.LscID, lu.LscName, userData.StandardProtocol, lu.Group.GroupNodes, fromTime, toTime).FindAll(a => a.AlarmID == alarmId);
                var perdays  = alarms.GroupBy(a => WebUtility.GetDateString2(a.StartTime)).Select(g => new { Date = g.Key, StationKeys = new HashSet <string>(g.Select(a => a.StaName)) });

                foreach (var date in dates)
                {
                    var day = perdays.FirstOrDefault(p => p.Date.Equals(date));
                    source.Add(new Report122Entity {
                        LscID     = lu.LscID,
                        LscName   = lu.LscName,
                        Date      = date,
                        Gstations = day == null ? new List <StationInfo>() : stations.FindAll(s => day.StationKeys.Contains(s.StaName)),
                        Stations  = stations
                    });
                }
            }

            int cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]);

            HttpRuntime.Cache.Insert(cacheKey, source, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(source);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report104Entity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-104");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscs = new List <LscUserInfo>();

            if (LscsComboBox.SelectedIndex > 0)
            {
                var ids = WebUtility.ItemSplit(LscsComboBox.SelectedItem.Value);
                if (ids.Length != 2)
                {
                    return(null);
                }
                var lscId   = Int32.Parse(ids[0]);
                var groupId = Int32.Parse(ids[1]);
                var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                if (lscUser == null)
                {
                    return(null);
                }
                lscs.Add(lscUser);
            }
            else
            {
                lscs.AddRange(userData.LscUsers);
            }

            var fromTime = DateTime.Parse(BeginFromDate.Text);
            var toTime   = DateTime.Parse(BeginToDate.Text);

            var texts      = new List <String>();
            var auxSets    = new List <String>();
            var filterText = WebUtility.StringSplit(NodeText.Text.Trim());

            foreach (var ft in filterText)
            {
                if (String.IsNullOrEmpty(ft.Trim()))
                {
                    continue;
                }
                if (FilterTypeList.SelectedItem.Value.Equals("1"))
                {
                    auxSets.Add(ft.Trim());
                }
                else
                {
                    texts.Add(ft.Trim());
                }
            }

            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 almNames = new List <String>();
            var almIds   = new Dictionary <String, String>();
            var almText  = WebUtility.StringSplit(AlarmNameText.Text.Trim());

            foreach (var at in almText)
            {
                if (String.IsNullOrEmpty(at.Trim()))
                {
                    continue;
                }
                if (AlmNameList.SelectedItem.Value.Equals("1"))
                {
                    almIds[at.Trim()] = null;
                }
                else
                {
                    almNames.Add(at.Trim());
                }
            }

            var otherEntity = new BOther();
            var nodeEntity  = new BNode();
            var stations    = new List <StationInfo>();
            var devices     = new List <DeviceInfo>();
            var nodes       = new List <NodeInfo>();

            foreach (var lsc in lscs)
            {
                stations.AddRange(otherEntity.GetStations(lsc.LscID, lsc.Group.GroupID).FindAll(s => s.BuildingID != WebUtility.DefaultInt32));
                devices.AddRange(otherEntity.GetDevices(lsc.LscID, lsc.Group.GroupID));
                nodes.AddRange(nodeEntity.GetNodes(lsc.LscID, EnmNodeType.Aic, texts.ToArray(), auxSets.ToArray(), devTypes.Keys.ToArray()));
            }

            if (Area2ComboBox.SelectedIndex > 0)
            {
                var area2Id = Int32.Parse(Area2ComboBox.SelectedItem.Value);
                stations = stations.FindAll(s => s.Area2ID == area2Id);
            }
            if (Area3ComboBox.SelectedIndex > 0)
            {
                var area3Id = Int32.Parse(Area3ComboBox.SelectedItem.Value);
                stations = stations.FindAll(s => s.Area3ID == area3Id);
            }
            if (stations.Count == 0)
            {
                return(null);
            }

            devices = devices.FindAll(d => devTypes.ContainsKey(d.DevTypeID));
            var devGroup = from dev in devices
                           group dev by new { dev.LscID, dev.StaID } into g
                select new {
                LscID   = g.Key.LscID,
                StaID   = g.Key.StaID,
                Devices = g.ToList()
            };

            var staWdv = from sta in stations
                         join dg in devGroup on new { sta.LscID, sta.StaID } equals new { dg.LscID, dg.StaID } into lt
            from ds in lt.DefaultIfEmpty()
            select new {
                Station = sta,
                Devices = ds == null ? new List <DeviceInfo>() : ds.Devices
            };

            var alarmEntity = new BAlarm();
            var alarms      = WebUtility.GetUserAlarms(userData).FindAll(alarm => lscs.Any(l => l.LscID == alarm.LscID) && alarm.StartTime >= fromTime && alarm.StartTime <= toTime);

            foreach (var lsc in lscs)
            {
                alarms.AddRange(alarmEntity.GetHisAlarms(lsc.LscID, lsc.LscName, userData.StandardProtocol, lsc.Group.GroupNodes, fromTime, toTime));
            }

            var ndWam = from alarm in alarms
                        join node in nodes on new { alarm.LscID, alarm.NodeID, alarm.NodeType } equals new { node.LscID, node.NodeID, node.NodeType }
            where (almNames.Count == 0 || almNames.Any(name => alarm.AlarmName.Contains(name))) && (almIds.Count == 0 || almIds.ContainsKey(alarm.AlarmID.ToString()))
            select new {
                Node  = node,
                Alarm = alarm
            };

            var almGroup = from alarm in ndWam
                           group alarm by new { alarm.Node.LscID, alarm.Node.StaID } into g
                select new {
                LscID  = g.Key.LscID,
                StaID  = g.Key.StaID,
                Alarms = g.Select(a => a.Alarm)
            };

            var staWam = from sd in staWdv
                         join ga in almGroup on new { sd.Station.LscID, sd.Station.StaID } equals new { ga.LscID, ga.StaID } into lt
            from gs in lt.DefaultIfEmpty()
            select new {
                Station = sd.Station,
                Devices = sd.Devices,
                Alarms  = gs == null ? new List <AlarmInfo>() : gs.Alarms
            };

            var result = (from sa in staWam
                          group sa by new { sa.Station.LscID, sa.Station.Area3ID, sa.Station.BuildingID } into g
                          orderby g.Key.LscID, g.Key.Area3ID, g.Key.BuildingID
                          select new Report104Entity {
                Station = g.First().Station,
                BeginTime = fromTime,
                EndTime = toTime,
                Devices = g.SelectMany(s => s.Devices).ToList(),
                Alarms = g.SelectMany(a => a.Alarms).ToList()
            }).ToList();

            int cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]);

            HttpRuntime.Cache.Insert(cacheKey, result, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report120Entity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-120");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscUsers = new List <LscUserInfo>();

            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]);
                    var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                    if (lscUser != null)
                    {
                        lscUsers.Add(lscUser);
                    }
                }
            }
            else
            {
                lscUsers.AddRange(userData.LscUsers);
            }

            if (lscUsers.Count == 0)
            {
                return(null);
            }

            var fromTime = DateTime.Parse(BeginFromDate.Text);
            var toTime   = DateTime.Parse(BeginToDate.Text);

            var staTypes = new HashSet <int>();

            foreach (var dt in StaTypeMultiCombo.SelectedItems)
            {
                staTypes.Add(int.Parse(dt.Value));
            }
            if (staTypes.Count == 0)
            {
                return(null);
            }

            var devTypes = new HashSet <int>();

            foreach (var dt in DevTypeMultiCombo.SelectedItems)
            {
                devTypes.Add(int.Parse(dt.Value));
            }
            if (devTypes.Count == 0)
            {
                return(null);
            }

            var alarmId = int.Parse(AlarmNameComboBox.SelectedItem.Value);

            var otherEntity = new BOther();
            var alarmEntity = new BAlarm();
            var source      = new List <Report120Entity>();

            foreach (var lu in lscUsers)
            {
                var devices       = otherEntity.GetDevices(lu.LscID, lu.Group.GroupID).FindAll(d => staTypes.Contains(d.StaTypeID) && devTypes.Contains(d.DevTypeID));
                var devkeys       = new HashSet <string>(devices.Select(d => string.Format("{0}┊{1}", d.StaName, d.DevName)));
                var alarms        = alarmEntity.GetHisAlarms(lu.LscID, lu.LscName, userData.StandardProtocol, lu.Group.GroupNodes, fromTime, toTime).FindAll(a => a.AlarmID == alarmId && devkeys.Contains(string.Format("{0}┊{1}", a.StaName, a.DevName)));
                var perNodeAlarms = alarms.GroupBy(a => new { a.StaName, a.DevName, a.NodeName }).Select(g => {
                    var first = g.First();
                    return(new Report120Node {
                        LscID = first.LscID,
                        LscName = first.LscName,
                        Area1Name = first.Area1Name,
                        Area2Name = first.Area2Name,
                        Area3Name = first.Area3Name,
                        Area4Name = first.Area4Name,
                        StaName = g.Key.StaName,
                        DevName = g.Key.DevName,
                        NodeName = g.Key.NodeName,
                        First = g.Min(c => c.StartTime),
                        Last = g.Max(c => c.StartTime)
                    });
                });

                source.Add(new Report120Entity {
                    LscID   = lu.LscID,
                    LscName = lu.LscName,
                    Nodes   = perNodeAlarms.ToList(),
                    Devices = devices
                });
            }

            int cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]);

            HttpRuntime.Cache.Insert(cacheKey, source, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(source);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Add Data To Cache
        /// </summary>
        private DataTable AddDataToCache()
        {
            var userData  = UserData;
            var cacheKey1 = WebUtility.GetCacheKeyName(userData, "his-alarm-category-source1");
            var cacheKey2 = WebUtility.GetCacheKeyName(userData, "his-alarm-category-source2");

            HttpRuntime.Cache.Remove(cacheKey1);
            HttpRuntime.Cache.Remove(cacheKey2);

            var source1 = new DataTable();
            var source2 = new DataTable();

            var startFromTime = DateTime.Parse(BeginFromDate.Text);
            var startToTime   = DateTime.Parse(BeginToDate.Text);
            var alarmEntity   = new BAlarm();

            if (LscsComboBox.SelectedIndex == 0)
            {
                source1 = CreateCustomizeTable1(11);
                source2 = CreateCustomizeTable2(11);
                foreach (var lscUser in userData.LscUsers)
                {
                    var dr1 = source1.NewRow();
                    var dr2 = source2.NewRow();

                    dr1[1] = WebUtility.GetNodeTypeName(EnmNodeType.LSC);
                    dr2[1] = (Int32)EnmNodeType.LSC;
                    dr1[2] = lscUser.LscName;
                    dr2[2] = lscUser.LscID;

                    var filters = alarmEntity.GetHisAlarms(lscUser.LscID, lscUser.LscName, userData.StandardProtocol, lscUser.Group.GroupNodes, startFromTime, startToTime);

                    dr1[3] = filters.Count;
                    dr2[3] = filters;
                    var cntAlarms = filters.FindAll(agi => { return(agi.AlarmLevel == EnmAlarmLevel.Critical); });
                    dr1[4]    = cntAlarms.Count;
                    dr2[4]    = cntAlarms;
                    cntAlarms = filters.FindAll(agi => { return(agi.AlarmLevel == EnmAlarmLevel.Major); });
                    dr1[5]    = cntAlarms.Count;
                    dr2[5]    = cntAlarms;
                    cntAlarms = filters.FindAll(agi => { return(agi.AlarmLevel == EnmAlarmLevel.Minor); });
                    dr1[6]    = cntAlarms.Count;
                    dr2[6]    = cntAlarms;
                    cntAlarms = filters.FindAll(agi => { return(agi.AlarmLevel == EnmAlarmLevel.Hint); });
                    dr1[7]    = cntAlarms.Count;
                    dr2[7]    = cntAlarms;
                    cntAlarms = filters.FindAll(agi => { return(agi.AlarmID != 0); });
                    dr1[8]    = cntAlarms.Count;
                    dr2[8]    = cntAlarms;
                    cntAlarms = filters.FindAll(agi => { return(agi.AlarmID == 0); });
                    dr1[9]    = cntAlarms.Count;
                    dr2[9]    = cntAlarms;
                    var bz  = Convert.ToDouble(dr1[8]);
                    var fbz = Convert.ToDouble(dr1[9]);
                    var tbz = bz + fbz;
                    dr1[10] = String.Format("{0:P2}", tbz == 0 ? 1 : bz / tbz);
                    dr2[10] = null;

                    source1.Rows.Add(dr1);
                    source2.Rows.Add(dr2);
                }

                var total1 = source1.NewRow();
                var total2 = source2.NewRow();
                total1[1] = "CSC"; total2[1] = -1;
                total1[2] = "总计"; total2[2] = -1;
                for (int i = 3; i < 10; i++)
                {
                    var cnt = 0;
                    for (int j = 0; j < source1.Rows.Count; j++)
                    {
                        cnt += Convert.ToInt32(source1.Rows[j][i]);
                    }
                    total1[i] = cnt;
                    total2[i] = null;
                }

                var totalbz  = Convert.ToDouble(total1[8]);
                var totalfbz = Convert.ToDouble(total1[9]);
                var totaltbz = totalbz + totalfbz;

                total1[10] = String.Format("{0:P2}", totaltbz == 0 ? 1 : totalbz / totaltbz);
                total2[10] = null;

                source1.Rows.Add(total1);
                source2.Rows.Add(total2);
            }
            else
            {
                var ids = WebUtility.ItemSplit(LscsComboBox.SelectedItem.Value);
                if (ids.Length == 2)
                {
                    var lscId   = Int32.Parse(ids[0]);
                    var groupId = Int32.Parse(ids[1]);
                    var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                    if (lscUser != null)
                    {
                        var nodeId   = 0;
                        var nodeName = lscUser.LscName;
                        var alarms   = alarmEntity.GetHisAlarms(lscUser.LscID, lscUser.LscName, userData.StandardProtocol, lscUser.Group.GroupNodes, startFromTime, startToTime);

                        var columns = lscUser.AlarmStaticFiterItem;
                        source1 = CreateCustomizeTable1(columns.Count + 8);
                        source2 = CreateCustomizeTable2(columns.Count + 8);
                        if (Area3ComboBox.SelectedIndex > 0)
                        {
                            nodeId   = Int32.Parse(Area3ComboBox.SelectedItem.Value);
                            nodeName = Area3ComboBox.SelectedItem.Text;
                            alarms   = alarms.FindAll(alarm => { return(alarm.Area3Name.Equals(nodeName)); });
                        }
                        else if (Area2ComboBox.SelectedIndex > 0)
                        {
                            nodeId   = Int32.Parse(Area2ComboBox.SelectedItem.Value);
                            nodeName = Area2ComboBox.SelectedItem.Text;
                            alarms   = alarms.FindAll(alarm => { return(alarm.Area2Name.Equals(nodeName)); });
                        }

                        var childNodes = lscUser.Group.GroupNodes.FindAll(gti => { return(gti.LastNodeID == nodeId); });
                        for (int i = 0; i < childNodes.Count; i++)
                        {
                            if (childNodes[i].NodeType == EnmNodeType.Area)
                            {
                                #region area
                                var dr1 = source1.NewRow();
                                var dr2 = source2.NewRow();

                                dr1[1] = WebUtility.GetNodeTypeName(childNodes[i].NodeType);
                                dr2[1] = (int)childNodes[i].NodeType;
                                dr1[2] = childNodes[i].NodeName;
                                dr2[2] = childNodes[i].LscID;
                                var filters = alarms.FindAll(agi => {
                                    return((childNodes[i].Remark.Equals("1") && agi.Area1Name.Equals(childNodes[i].NodeName)) ||
                                           (childNodes[i].Remark.Equals("2") && agi.Area2Name.Equals(childNodes[i].NodeName)) ||
                                           (childNodes[i].Remark.Equals("3") && agi.Area3Name.Equals(childNodes[i].NodeName)));
                                });
                                dr1[3] = filters.Count;
                                dr2[3] = filters;
                                var cntAlarms = filters.FindAll(agi => { return(agi.AlarmLevel == EnmAlarmLevel.Critical); });
                                dr1[4]    = cntAlarms.Count;
                                dr2[4]    = cntAlarms;
                                cntAlarms = filters.FindAll(agi => { return(agi.AlarmLevel == EnmAlarmLevel.Major); });
                                dr1[5]    = cntAlarms.Count;
                                dr2[5]    = cntAlarms;
                                cntAlarms = filters.FindAll(agi => { return(agi.AlarmLevel == EnmAlarmLevel.Minor); });
                                dr1[6]    = cntAlarms.Count;
                                dr2[6]    = cntAlarms;
                                cntAlarms = filters.FindAll(agi => { return(agi.AlarmLevel == EnmAlarmLevel.Hint); });
                                dr1[7]    = cntAlarms.Count;
                                dr2[7]    = cntAlarms;

                                for (int j = 0; j < columns.Count; j++)
                                {
                                    string[] items = null;
                                    switch (columns[j].FilterType)
                                    {
                                    case EnmAlarmFiterType.AlarmDeviceID:
                                        items      = WebUtility.StringSplit(columns[j].FilterItem);
                                        cntAlarms  = filters.FindAll(agi => { return(items.Contains(agi.AlarmDeviceTypeID.ToString())); });
                                        dr1[8 + j] = cntAlarms.Count;
                                        dr2[8 + j] = cntAlarms;
                                        break;

                                    case EnmAlarmFiterType.AlarmLogID:
                                        items      = WebUtility.StringSplit(columns[j].FilterItem);
                                        cntAlarms  = filters.FindAll(agi => { return(items.Contains(agi.AlarmLogTypeID.ToString())); });
                                        dr1[8 + j] = cntAlarms.Count;
                                        dr2[8 + j] = cntAlarms;
                                        break;

                                    case EnmAlarmFiterType.AlarmID:
                                        items      = WebUtility.StringSplit(columns[j].FilterItem);
                                        cntAlarms  = filters.FindAll(agi => { return(items.Contains(agi.AlarmID.ToString())); });
                                        dr1[8 + j] = cntAlarms.Count;
                                        dr2[8 + j] = cntAlarms;
                                        break;

                                    case EnmAlarmFiterType.AlarmDesc:
                                        cntAlarms  = filters.FindAll(agi => { return(agi.AlarmDesc.Contains(columns[j].FilterItem)); });
                                        dr1[8 + j] = cntAlarms.Count;
                                        dr2[8 + j] = cntAlarms;
                                        break;

                                    case EnmAlarmFiterType.NodeName:
                                        var nodeNames = WebUtility.StringSplit(columns[j].FilterItem);
                                        cntAlarms = filters.FindAll(agi => {
                                            foreach (var name in nodeNames)
                                            {
                                                if (agi.NodeName.Contains(name))
                                                {
                                                    return(true);
                                                }
                                            }
                                            return(false);
                                        });
                                        dr1[8 + j] = cntAlarms.Count;
                                        dr2[8 + j] = cntAlarms;
                                        break;

                                    case EnmAlarmFiterType.TimeShare:
                                        items = WebUtility.StringSplit(columns[j].FilterItem);
                                        if (items.Length != 2)
                                        {
                                            dr1[8 + j] = 0;
                                        }
                                        else
                                        {
                                            var minInterval = WebUtility.GetSecondFromDateTime(items[0]);
                                            var maxInterval = WebUtility.GetSecondFromDateTime(items[1]);
                                            cntAlarms = filters.FindAll(agi => {
                                                var dateInterval = DateTime.Now.Subtract(agi.StartTime).TotalSeconds;
                                                return(dateInterval >= minInterval && dateInterval <= maxInterval);
                                            });
                                            dr1[8 + j] = cntAlarms.Count;
                                            dr2[8 + j] = cntAlarms;
                                        }
                                        break;

                                    case EnmAlarmFiterType.DevName:
                                        var devNames = WebUtility.StringSplit(columns[j].FilterItem);
                                        cntAlarms = filters.FindAll(agi => {
                                            foreach (var name in devNames)
                                            {
                                                if (agi.DevName.Contains(name))
                                                {
                                                    return(true);
                                                }
                                            }
                                            return(false);
                                        });
                                        dr1[8 + j] = cntAlarms.Count;
                                        dr2[8 + j] = cntAlarms;
                                        break;

                                    default:
                                        break;
                                    }
                                }

                                source1.Rows.Add(dr1);
                                source2.Rows.Add(dr2);
                                #endregion
                            }
                            else if (childNodes[i].NodeType == EnmNodeType.Sta)
                            {
                                #region Sta
                                var dr1 = source1.NewRow();
                                var dr2 = source2.NewRow();
                                dr1[1] = WebUtility.GetNodeTypeName(childNodes[i].NodeType);
                                dr2[1] = (int)childNodes[i].NodeType;
                                dr1[2] = childNodes[i].NodeName;
                                dr2[2] = childNodes[i].LscID;
                                var filters = alarms.FindAll(agi => { return(agi.StaName.Equals(childNodes[i].NodeName)); });
                                dr1[3] = filters.Count;
                                dr2[3] = filters;
                                var cntAlarms = filters.FindAll(agi => { return(agi.AlarmLevel == EnmAlarmLevel.Critical); });
                                dr1[4]    = cntAlarms.Count;
                                dr2[4]    = cntAlarms;
                                cntAlarms = filters.FindAll(agi => { return(agi.AlarmLevel == EnmAlarmLevel.Major); });
                                dr1[5]    = cntAlarms.Count;
                                dr2[5]    = cntAlarms;
                                cntAlarms = filters.FindAll(agi => { return(agi.AlarmLevel == EnmAlarmLevel.Minor); });
                                dr1[6]    = cntAlarms.Count;
                                dr2[6]    = cntAlarms;
                                cntAlarms = filters.FindAll(agi => { return(agi.AlarmLevel == EnmAlarmLevel.Hint); });
                                dr1[7]    = cntAlarms.Count;
                                dr2[7]    = cntAlarms;

                                for (int j = 0; j < columns.Count; j++)
                                {
                                    string[] items = null;
                                    switch (columns[j].FilterType)
                                    {
                                    case EnmAlarmFiterType.AlarmDeviceID:
                                        items      = WebUtility.StringSplit(columns[j].FilterItem);
                                        cntAlarms  = filters.FindAll(agi => { return(items.Contains(agi.AlarmDeviceTypeID.ToString())); });
                                        dr1[8 + j] = cntAlarms.Count;
                                        dr2[8 + j] = cntAlarms;
                                        break;

                                    case EnmAlarmFiterType.AlarmLogID:
                                        items      = WebUtility.StringSplit(columns[j].FilterItem);
                                        cntAlarms  = filters.FindAll(agi => { return(items.Contains(agi.AlarmLogTypeID.ToString())); });
                                        dr1[8 + j] = cntAlarms.Count;
                                        dr2[8 + j] = cntAlarms;
                                        break;

                                    case EnmAlarmFiterType.AlarmID:
                                        items      = WebUtility.StringSplit(columns[j].FilterItem);
                                        cntAlarms  = filters.FindAll(agi => { return(items.Contains(agi.AlarmID.ToString())); });
                                        dr1[8 + j] = cntAlarms.Count;
                                        dr2[8 + j] = cntAlarms;
                                        break;

                                    case EnmAlarmFiterType.AlarmDesc:
                                        cntAlarms  = filters.FindAll(agi => { return(agi.AlarmDesc.Contains(columns[j].FilterItem)); });
                                        dr1[8 + j] = cntAlarms.Count;
                                        dr2[8 + j] = cntAlarms;
                                        break;

                                    case EnmAlarmFiterType.NodeName:
                                        var nodeNames = WebUtility.StringSplit(columns[j].FilterItem);
                                        cntAlarms = filters.FindAll(agi => {
                                            foreach (var name in nodeNames)
                                            {
                                                if (agi.NodeName.Contains(name))
                                                {
                                                    return(true);
                                                }
                                            }
                                            return(false);
                                        });
                                        dr1[8 + j] = cntAlarms.Count;
                                        dr2[8 + j] = cntAlarms;
                                        break;

                                    case EnmAlarmFiterType.TimeShare:
                                        items = WebUtility.StringSplit(columns[j].FilterItem);
                                        if (items.Length != 2)
                                        {
                                            dr1[8 + j] = 0;
                                        }
                                        else
                                        {
                                            var minInterval = WebUtility.GetSecondFromDateTime(items[0]);
                                            var maxInterval = WebUtility.GetSecondFromDateTime(items[1]);
                                            cntAlarms = filters.FindAll(agi => {
                                                var dateInterval = DateTime.Now.Subtract(agi.StartTime).TotalSeconds;
                                                return(dateInterval >= minInterval && dateInterval <= maxInterval);
                                            });
                                            dr1[8 + j] = cntAlarms.Count;
                                            dr2[8 + j] = cntAlarms;
                                        }
                                        break;

                                    case EnmAlarmFiterType.DevName:
                                        var devNames = WebUtility.StringSplit(columns[j].FilterItem);
                                        cntAlarms = filters.FindAll(agi => {
                                            foreach (var name in devNames)
                                            {
                                                if (agi.DevName.Contains(name))
                                                {
                                                    return(true);
                                                }
                                            }
                                            return(false);
                                        });
                                        dr1[8 + j] = cntAlarms.Count;
                                        dr2[8 + j] = cntAlarms;
                                        break;

                                    default:
                                        break;
                                    }
                                }

                                source1.Rows.Add(dr1);
                                source2.Rows.Add(dr2);
                                #endregion
                            }
                        }
                    }
                }
            }

            var 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);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report009Entity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-009");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscs = new List <LscUserInfo>();

            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]);
                    var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                    if (lscUser != null)
                    {
                        lscs.Add(lscUser);
                    }
                }
            }
            else
            {
                lscs.AddRange(userData.LscUsers);
            }
            if (lscs.Count == 0)
            {
                return(null);
            }

            var fromTime = DateTime.Parse(BeginFromDate.Text);
            var toTime   = DateTime.Parse(BeginToDate.Text);

            var auxSets    = new List <String>();
            var texts      = new List <String>();
            var filterText = WebUtility.StringSplit(NodeText.Text.Trim());

            foreach (var ft in filterText)
            {
                if (String.IsNullOrEmpty(ft.Trim()))
                {
                    continue;
                }
                if (FilterList.SelectedItem.Value.Equals("1"))
                {
                    auxSets.Add(ft.Trim());
                }
                else
                {
                    texts.Add(ft.Trim());
                }
            }
            if (texts.Count == 0 && auxSets.Count == 0)
            {
                return(null);
            }

            var almNames = new List <String>();
            var almIds   = new Dictionary <String, String>();
            var almText  = WebUtility.StringSplit(AlarmNameText.Text.Trim());

            foreach (var at in almText)
            {
                if (String.IsNullOrEmpty(at.Trim()))
                {
                    continue;
                }
                if (AlmNameList.SelectedItem.Value.Equals("1"))
                {
                    almIds[at.Trim()] = null;
                }
                else
                {
                    almNames.Add(at.Trim());
                }
            }

            var nodeEntity   = new BNode();
            var alarmEntity  = new BAlarm();
            var result       = new List <Report009Entity>();
            var activeAlarms = WebUtility.GetUserAlarms(userData).FindAll(alarm => lscs.Any(l => l.LscID == alarm.LscID) && alarm.StartTime >= fromTime && alarm.StartTime <= toTime);

            foreach (var lsc in lscs)
            {
                var nodes  = nodeEntity.GetNodes(lsc.LscID, EnmNodeType.Img, texts.ToArray(), auxSets.ToArray(), null);
                var alarms = alarmEntity.GetHisAlarms(lsc.LscID, lsc.LscName, userData.StandardProtocol, lsc.Group.GroupNodes, fromTime, toTime);
                alarms.AddRange(activeAlarms.FindAll(a => a.LscID == lsc.LscID));
                var ndWam = from alarm in alarms
                            join node in nodes on new { alarm.LscID, alarm.NodeID, alarm.NodeType } equals new { node.LscID, node.NodeID, node.NodeType }
                where (almNames.Count == 0 || almNames.Any(name => alarm.AlarmName.Contains(name))) && (almIds.Count == 0 || almIds.ContainsKey(alarm.AlarmID.ToString())) && string.IsNullOrEmpty(alarm.ProjName)
                select new {
                    Node  = node,
                    Alarm = alarm
                };

                result.Add(new Report009Entity {
                    LscID     = lsc.LscID,
                    LscName   = lsc.LscName,
                    ThisCount = fRadio.Checked ? ndWam.GroupBy(n => n.Node.StaID).Count() : ndWam.GroupBy(n => n.Node.Area3ID).Count(),
                    LastCount = fRadio.Checked ? nodes.GroupBy(n => n.StaID).Count() : nodes.GroupBy(n => n.Area3ID).Count()
                });
            }

            if (result.Count > 0)
            {
                result.Add(new Report009Entity {
                    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);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report108Entity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-108");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscs = new List <LscUserInfo>();

            if (LscsComboBox.SelectedIndex > 0)
            {
                var ids = WebUtility.ItemSplit(LscsComboBox.SelectedItem.Value);
                if (ids.Length != 2)
                {
                    return(null);
                }
                var lscId   = Int32.Parse(ids[0]);
                var groupId = Int32.Parse(ids[1]);
                var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                if (lscUser == null)
                {
                    return(null);
                }
                lscs.Add(lscUser);
            }
            else
            {
                lscs.AddRange(userData.LscUsers);
            }

            var fromTime = DateTime.Parse(BeginFromDate.Text);
            var toTime   = DateTime.Parse(BeginToDate.Text);

            var alarmNames = new Dictionary <Int32, String>();

            foreach (var item in AlarmNameMultiCombo.SelectedItems)
            {
                alarmNames[Convert.ToInt32(item.Value)] = item.Text;
            }
            if (alarmNames.Count == 0)
            {
                return(null);
            }
            var split    = ";";
            var alarmIds = String.Join(split, alarmNames.Select(n => n.Key.ToString()).ToArray());

            var otherEntity = new BOther();
            var alarmEntity = new BAlarm();
            var result      = new List <Report108Entity>();

            foreach (var lsc in lscs)
            {
                var stations = otherEntity.GetStations(lsc.LscID, lsc.Group.GroupID).FindAll(s => s.BuildingID != WebUtility.DefaultInt32);
                if (Area2ComboBox.SelectedIndex > 0)
                {
                    var area2Id = Int32.Parse(Area2ComboBox.SelectedItem.Value);
                    stations = stations.FindAll(s => s.Area2ID == area2Id);
                }
                if (Area3ComboBox.SelectedIndex > 0)
                {
                    var area3Id = Int32.Parse(Area3ComboBox.SelectedItem.Value);
                    stations = stations.FindAll(s => s.Area3ID == area3Id);
                }
                if (stations.Count == 0)
                {
                    continue;
                }

                var fsuCnt = otherEntity.GetStationFSUCnt(lsc.LscID, lsc.Group.GroupID, alarmIds, split);
                var alarms = WebUtility.GetUserAlarms(userData).FindAll(alarm => alarm.LscID == lsc.LscID && alarm.StartTime >= fromTime && alarm.StartTime <= toTime && alarmNames.ContainsKey(alarm.AlarmID));
                alarms.AddRange(alarmEntity.GetHisAlarms(lsc.LscID, lsc.LscName, userData.StandardProtocol, lsc.Group.GroupNodes, fromTime, toTime).FindAll(alarm => {
                    return(alarmNames.ContainsKey(alarm.AlarmID));
                }));

                var staWam = from alarm in alarms
                             group alarm by new { alarm.LscID, alarm.StaName } into g
                    select new {
                    LscID   = g.Key.LscID,
                    StaName = g.Key.StaName,
                    Alarms  = g
                };

                var staWfa = from sn in stations
                             join fc in fsuCnt on new { sn.LscID, sn.StaID } equals new { fc.LscID, fc.StaID } into lt1
                from fs in lt1.DefaultIfEmpty()
                join sw in staWam on new { sn.LscID, sn.StaName } equals new { sw.LscID, sw.StaName } into lt2
                from ws in lt2.DefaultIfEmpty()
                select new {
                    Station = sn,
                    FSUCnt  = fs != null ? fs.AICnt + fs.AOCnt + fs.DICnt + fs.DOCnt : 0,
                    Alarms  = ws != null?ws.Alarms.ToList() : new List <AlarmInfo>()
                };

                result.AddRange(from sf in staWfa
                                group sf by new { sf.Station.LscID, sf.Station.Area3ID, sf.Station.BuildingID } into g
                                orderby g.Key.LscID, g.Key.Area3ID, g.Key.BuildingID
                                select new Report108Entity {
                    Station   = g.First().Station,
                    BeginTime = fromTime,
                    EndTime   = toTime,
                    FSUCnt    = g.Sum(f => f.FSUCnt),
                    Alarms    = g.SelectMany(a => a.Alarms).ToList()
                });
            }

            int cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]);

            HttpRuntime.Cache.Insert(cacheKey, result, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(result);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report002Entity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-002");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscs = new List <LscUserInfo>();

            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]);
                    var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                    if (lscUser != null)
                    {
                        lscs.Add(lscUser);
                    }
                }
            }
            else
            {
                lscs.AddRange(userData.LscUsers);
            }
            if (lscs.Count == 0)
            {
                return(null);
            }

            var fromTime = DateTime.Parse(BeginFromDate.Text);
            var toTime   = DateTime.Parse(BeginToDate.Text);

            var auxSets    = new List <String>();
            var texts      = new List <String>();
            var filterText = WebUtility.StringSplit(NodeText.Text.Trim());

            foreach (var ft in filterText)
            {
                if (String.IsNullOrEmpty(ft.Trim()))
                {
                    continue;
                }
                if (FilterList.SelectedItem.Value.Equals("1"))
                {
                    auxSets.Add(ft.Trim());
                }
                else
                {
                    texts.Add(ft.Trim());
                }
            }
            if (texts.Count == 0 && auxSets.Count == 0)
            {
                return(null);
            }

            var pauxSets    = new List <String>();
            var ptexts      = new List <String>();
            var pfilterText = WebUtility.StringSplit(PNodeText.Text.Trim());

            foreach (var ft in pfilterText)
            {
                if (String.IsNullOrEmpty(ft.Trim()))
                {
                    continue;
                }
                if (PFilterList.SelectedItem.Value.Equals("1"))
                {
                    pauxSets.Add(ft.Trim());
                }
                else
                {
                    ptexts.Add(ft.Trim());
                }
            }
            if (ptexts.Count == 0 && pauxSets.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 almNames = new List <String>();
            var almIds   = new Dictionary <String, String>();
            var almText  = WebUtility.StringSplit(AlarmNameText.Text.Trim());

            foreach (var at in almText)
            {
                if (String.IsNullOrEmpty(at.Trim()))
                {
                    continue;
                }
                if (AlmNameList.SelectedItem.Value.Equals("1"))
                {
                    almIds[at.Trim()] = null;
                }
                else
                {
                    almNames.Add(at.Trim());
                }
            }

            var palmNames = new List <String>();
            var palmIds   = new Dictionary <String, String>();
            var palmText  = WebUtility.StringSplit(PAlarmNameText.Text.Trim());

            foreach (var at in palmText)
            {
                if (String.IsNullOrEmpty(at.Trim()))
                {
                    continue;
                }
                if (PAlmNameList.SelectedItem.Value.Equals("1"))
                {
                    palmIds[at.Trim()] = null;
                }
                else
                {
                    palmNames.Add(at.Trim());
                }
            }

            var otherEntity = new BOther();
            var nodeEntity  = new BNode();
            var devices     = new List <DeviceInfo>();
            var nodes       = new List <NodeInfo>();
            var pnodes      = new List <NodeInfo>();

            foreach (var lsc in lscs)
            {
                devices.AddRange(otherEntity.GetDevices(lsc.LscID, lsc.Group.GroupID));
                nodes.AddRange(nodeEntity.GetNodes(lsc.LscID, EnmNodeType.Img, texts.ToArray(), auxSets.ToArray(), null));
                if (ptexts.Count > 0 || pauxSets.Count > 0)
                {
                    pnodes.AddRange(nodeEntity.GetNodes(lsc.LscID, EnmNodeType.Img, ptexts.ToArray(), pauxSets.ToArray(), null));
                }
            }

            devices = devices.FindAll(d => devTypes.ContainsKey(d.AlmDevTypeID));
            var devGroup = from dev in devices
                           group dev by new { dev.LscID } into g
                select new {
                LscID   = g.Key.LscID,
                Devices = g.ToList()
            };

            var lcWdv = from lsc in lscs
                        join dg in devGroup on new { lsc.LscID } equals new { dg.LscID } into lt
            from gs in lt.DefaultIfEmpty()
            select new {
                LscID   = lsc.LscID,
                LscName = lsc.LscName,
                Devices = gs == null ? new List <DeviceInfo>() : gs.Devices
            };

            var alarmEntity = new BAlarm();
            var alarms      = WebUtility.GetUserAlarms(userData).FindAll(alarm => lscs.Any(l => l.LscID == alarm.LscID) && alarm.StartTime >= fromTime && alarm.StartTime <= toTime);

            foreach (var lsc in lscs)
            {
                alarms.AddRange(alarmEntity.GetHisAlarms(lsc.LscID, lsc.LscName, userData.StandardProtocol, lsc.Group.GroupNodes, fromTime, toTime));
            }

            var ndWam = from alarm in alarms
                        join node in nodes on new { alarm.LscID, alarm.NodeID, alarm.NodeType } equals new { node.LscID, node.NodeID, node.NodeType }
            where (almNames.Count == 0 || almNames.Any(name => alarm.AlarmName.Contains(name))) && (almIds.Count == 0 || almIds.ContainsKey(alarm.AlarmID.ToString())) && string.IsNullOrEmpty(alarm.ProjName)
            select new {
                Node  = node,
                Alarm = alarm
            };

            var pdWam = from alarm in alarms
                        join node in pnodes on new { alarm.LscID, alarm.NodeID, alarm.NodeType } equals new { node.LscID, node.NodeID, node.NodeType }
            where (palmNames.Count == 0 || palmNames.Any(name => alarm.AlarmName.Contains(name))) && (palmIds.Count == 0 || palmIds.ContainsKey(alarm.AlarmID.ToString())) && string.IsNullOrEmpty(alarm.ProjName)
            select new {
                Node  = node,
                Alarm = alarm
            };

            var almGroup = from alarm in ndWam
                           group alarm by new { alarm.Node.LscID } into g
                select new {
                LscID  = g.Key.LscID,
                Alarms = g.Select(a => a.Alarm)
            };

            var plmGroup = from alarm in pdWam
                           group alarm by new { alarm.Node.LscID } into g
                select new {
                LscID  = g.Key.LscID,
                Alarms = g.Select(a => a.Alarm)
            };

            var result = (from ld in lcWdv
                          join ag in almGroup on new { ld.LscID } equals new { ag.LscID } into lt1
                          from la in lt1.DefaultIfEmpty()
                          join pg in plmGroup on new { ld.LscID } equals new { pg.LscID } into lt2
                          from lp in lt2.DefaultIfEmpty()
                          orderby ld.LscID
                          select new Report002Entity {
                LscID = ld.LscID,
                LscName = ld.LscName,
                BeginTime = fromTime,
                EndTime = toTime,
                Devices = ld.Devices,
                Alarms = la == null ? new List <AlarmInfo>() : la.Alarms.ToList(),
                PAlarms = lp == null ? new List <AlarmInfo>() : lp.Alarms.ToList()
            }).ToList();

            if (result.Count > 0)
            {
                result.Add(new Report002Entity {
                    LscID     = -100,
                    LscName   = "汇总(平均值)",
                    BeginTime = fromTime,
                    EndTime   = toTime,
                    Devices   = new List <DeviceInfo>(),
                    Alarms    = new List <AlarmInfo>(),
                    PAlarms   = new List <AlarmInfo>()
                });
            }

            int cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]);

            HttpRuntime.Cache.Insert(cacheKey, result, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(result);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report111Entity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-111");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscs = new List <LscUserInfo>();

            if (LscsComboBox.SelectedIndex > 0)
            {
                var ids = WebUtility.ItemSplit(LscsComboBox.SelectedItem.Value);
                if (ids.Length != 2)
                {
                    return(null);
                }
                var lscId   = Int32.Parse(ids[0]);
                var groupId = Int32.Parse(ids[1]);
                var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                if (lscUser == null)
                {
                    return(null);
                }
                lscs.Add(lscUser);
            }
            else
            {
                lscs.AddRange(userData.LscUsers);
            }

            var fromTime = DateTime.Parse(BeginFromDate.Text);
            var toTime   = DateTime.Parse(BeginToDate.Text);

            var texts      = new List <String>();
            var auxSets    = new List <String>();
            var filterText = WebUtility.StringSplit(NodeText.Text.Trim());

            foreach (var ft in filterText)
            {
                if (String.IsNullOrEmpty(ft.Trim()))
                {
                    continue;
                }
                if (FilterTypeList.SelectedItem.Value.Equals("1"))
                {
                    auxSets.Add(ft.Trim());
                }
                else
                {
                    texts.Add(ft.Trim());
                }
            }

            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 almNames = new List <String>();
            var almIds   = new Dictionary <String, String>();
            var almText  = WebUtility.StringSplit(AlarmNameText.Text.Trim());

            foreach (var at in almText)
            {
                if (String.IsNullOrEmpty(at.Trim()))
                {
                    continue;
                }
                if (AlmNameList.SelectedItem.Value.Equals("1"))
                {
                    almIds[at.Trim()] = null;
                }
                else
                {
                    almNames.Add(at.Trim());
                }
            }

            var nodeEntity  = new BNode();
            var lscEntity   = new BLsc();
            var alarmEntity = new BAlarm();
            var result      = new List <Report111Entity>();

            var virtualData = WebConfigurationManager.AppSettings["Kpi-HeNan-Virtual-Enable"] != null && WebConfigurationManager.AppSettings["Kpi-HeNan-Virtual-Enable"].Equals("1");
            var lscParms    = new List <LscParamInfo>();

            if (virtualData)
            {
                lscParms.AddRange(new BOther().GetLscParam());
            }

            foreach (var l in lscs)
            {
                var lsc = lscEntity.GetLsc(l.LscID);
                if (lsc == null)
                {
                    continue;
                }

                var stations = Report111Entity.GetStations(lsc.LscID, lsc.LscName, WebUtility.CreateLscConnectionString(lsc));
                var nodes    = nodeEntity.GetNodes(lsc.LscID, EnmNodeType.Dic, texts.ToArray(), auxSets.ToArray(), devTypes.Keys.ToArray());
                if (nodes.Count == 0)
                {
                    result.Add(new Report111Entity {
                        LscID     = lsc.LscID,
                        LscName   = lsc.LscName,
                        BeginTime = fromTime,
                        EndTime   = toTime,
                        Alarms    = new List <AlarmInfo>(),
                        NodeCnt   = stations.Count
                    });
                }
                else
                {
                    var alarms = WebUtility.GetUserAlarms(userData).FindAll(alarm => alarm.LscID == lsc.LscID && alarm.StartTime >= fromTime && alarm.StartTime <= toTime);
                    alarms.AddRange(alarmEntity.GetHisAlarms(lsc.LscID, lsc.LscName, userData.StandardProtocol, l.Group.GroupNodes, fromTime, toTime));

                    var ta = alarms.FindAll(alarm => {
                        return((almNames.Count == 0 || almNames.Any(name => alarm.AlarmName.Contains(name))) &&
                               (almIds.Count == 0 || almIds.ContainsKey(alarm.AlarmID.ToString())));
                    });

                    var temp = from alarm in ta
                               join node in nodes on new { alarm.LscID, alarm.NodeID, alarm.NodeType } equals new { node.LscID, node.NodeID, node.NodeType }
                    select alarm;

                    var record = new Report111Entity {
                        LscID     = lsc.LscID,
                        LscName   = lsc.LscName,
                        BeginTime = fromTime,
                        EndTime   = toTime,
                        Alarms    = temp.ToList(),
                        NodeCnt   = stations.Count
                    };

                    if (virtualData)
                    {
                        var parm = lscParms.Find(s => s.LscID == lsc.LscID);
                        if (parm != null && parm.StaTNumber != WebUtility.DefaultInt32)
                        {
                            record.NodeCnt = parm.StaTNumber;
                        }
                    }

                    result.Add(record);
                }
            }

            int cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]);

            HttpRuntime.Cache.Insert(cacheKey, result, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(result);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report005Entity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-005");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscs = new List <LscUserInfo>();

            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]);
                    var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                    if (lscUser != null)
                    {
                        lscs.Add(lscUser);
                    }
                }
            }
            else
            {
                lscs.AddRange(userData.LscUsers);
            }
            if (lscs.Count == 0)
            {
                return(null);
            }

            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 fromTime = DateTime.Parse(BeginFromDate.Text);
            var toTime   = DateTime.Parse(BeginToDate.Text);

            var alarmNames = new Dictionary <Int32, String>();

            foreach (var item in AlarmNameMultiCombo.SelectedItems)
            {
                alarmNames[Convert.ToInt32(item.Value)] = item.Text;
            }
            if (alarmNames.Count == 0)
            {
                return(null);
            }
            var split    = ";";
            var alarmIds = String.Join(split, alarmNames.Select(n => n.Key.ToString()).ToArray());

            var alarmEntity = new BAlarm();
            var otherEntity = new BOther();
            var result      = new List <Report005Entity>();

            foreach (var lsc in lscs)
            {
                var fsuCnt = otherEntity.GetStationFSUCnt(lsc.LscID, lsc.Group.GroupID, alarmIds, split).FindAll(fc => staTypes.ContainsKey(fc.StaTypeID));
                var alarms = WebUtility.GetUserAlarms(userData).FindAll(alarm => alarm.LscID == lsc.LscID && alarm.StartTime >= fromTime && alarm.StartTime <= toTime && alarmNames.ContainsKey(alarm.AlarmID) && string.IsNullOrEmpty(alarm.ProjName));
                alarms.AddRange(alarmEntity.GetHisAlarms(lsc.LscID, lsc.LscName, userData.StandardProtocol, lsc.Group.GroupNodes, fromTime, toTime).FindAll(alarm => {
                    return(alarmNames.ContainsKey(alarm.AlarmID) && string.IsNullOrEmpty(alarm.ProjName));
                }));

                var temp = from alarm in alarms
                           join fct in fsuCnt on alarm.StaName equals fct.StaName
                           select alarm;

                result.Add(new Report005Entity()
                {
                    LscID     = lsc.LscID,
                    LscName   = lsc.LscName,
                    BeginTime = fromTime,
                    EndTime   = toTime,
                    FSUCnt    = fsuCnt.Sum(fc => fc.AICnt + fc.AOCnt + fc.DICnt + fc.DOCnt),
                    Alarms    = temp.ToList()
                });
            }

            if (result.Count > 0)
            {
                result.Add(new Report005Entity {
                    LscID     = -100,
                    LscName   = "汇总(平均值)",
                    BeginTime = fromTime,
                    EndTime   = toTime,
                    FSUCnt    = 0,
                    Alarms    = new List <AlarmInfo>()
                });
            }

            int cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]);

            HttpRuntime.Cache.Insert(cacheKey, result, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(result);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report011Entity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-011");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscs = new List <LscUserInfo>();

            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]);
                    var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                    if (lscUser != null)
                    {
                        lscs.Add(lscUser);
                    }
                }
            }
            else
            {
                lscs.AddRange(userData.LscUsers);
            }
            if (lscs.Count == 0)
            {
                return(null);
            }

            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 fromTime = DateTime.Parse(BeginFromDate.Text);
            var toTime   = DateTime.Parse(BeginToDate.Text);

            var alarmNames = new Dictionary <Int32, String>();

            foreach (var item in AlarmNameMultiCombo.SelectedItems)
            {
                alarmNames[Convert.ToInt32(item.Value)] = item.Text;
            }

            var otherEntity = new BOther();
            var nodeEntity  = new BNode();
            var lscEntity   = new BLsc();
            var alarmEntity = new BAlarm();
            var result      = new List <Report011Entity>();

            foreach (var l in lscs)
            {
                var lsc = lscEntity.GetLsc(l.LscID);
                if (lsc == null)
                {
                    continue;
                }

                var stations = otherEntity.GetStations(lsc.LscID, l.Group.GroupID).FindAll(sta => staTypes.ContainsKey(sta.StaTypeID));
                var alarms   = WebUtility.GetUserAlarms(userData).FindAll(alarm => alarm.LscID == lsc.LscID && alarm.StartTime >= fromTime && alarm.StartTime <= toTime && alarmNames.ContainsKey(alarm.AlarmID) && string.IsNullOrEmpty(alarm.ProjName));
                alarms.AddRange(alarmEntity.GetHisAlarms(lsc.LscID, lsc.LscName, userData.StandardProtocol, l.Group.GroupNodes, fromTime, toTime).FindAll(alarm => {
                    return(alarmNames.ContainsKey(alarm.AlarmID) && string.IsNullOrEmpty(alarm.ProjName));
                }));

                var nalm = from alarm in alarms
                           join sta in stations on alarm.StaName equals sta.StaName
                           select alarm;

                var parm   = Report011Entity.GetLscParam(lsc.LscID, WebUtility.CreateLscConnectionString(lsc));
                var record = new Report011Entity {
                    LscID     = lsc.LscID,
                    LscName   = lsc.LscName,
                    BeginTime = fromTime,
                    EndTime   = toTime,
                    Alarms    = nalm.Any() ? nalm.ToList() : new List <AlarmInfo>(),
                    StaCnt    = parm != null ? parm.StaMNumber : 0,
                };

                result.Add(record);
            }

            if (result.Count > 0)
            {
                result.Add(new Report011Entity {
                    LscID     = -100,
                    LscName   = "汇总(平均值)",
                    BeginTime = fromTime,
                    EndTime   = toTime,
                    Alarms    = new List <AlarmInfo>(),
                    StaCnt    = (Int32)result.Average(r => r.StaCnt)
                });
            }

            int cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]);

            HttpRuntime.Cache.Insert(cacheKey, result, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(result);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Add Data To Cache
        /// </summary>
        private List <AlarmInfo> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "his-alarms");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscUsers = new List <LscUserInfo>();

            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]);
                    var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                    if (lscUser != null)
                    {
                        lscUsers.Add(lscUser);
                    }
                }
            }
            else
            {
                lscUsers.AddRange(userData.LscUsers);
            }

            if (lscUsers.Count == 0)
            {
                return(null);
            }

            var alarmEntity = new BAlarm();
            var condition   = GetCondition();
            var alarms      = new List <AlarmInfo>();

            foreach (var lu in lscUsers)
            {
                alarms.AddRange(alarmEntity.GetHisAlarms(lu.LscID, lu.LscName, userData.StandardProtocol, lu.Group.GroupNodes, condition));
            }

            if (alarms.Count > 0)
            {
                alarms = (from alarm in alarms
                          where (AlarmDevComboBox.SelectedIndex == 0 || alarm.AlarmDeviceType.Equals(AlarmDevComboBox.SelectedItem.Text)) &&
                          (AlarmLogicComboBox.SelectedIndex == 0 || alarm.AlarmLogType.Equals(AlarmLogicComboBox.SelectedItem.Text)) &&
                          (AlarmNameComboBox.SelectedIndex == 0 || alarm.AlarmName.Equals(AlarmNameComboBox.SelectedItem.Text)) &&
                          (!OtherOptionsMenuItem1.Checked || alarm.ConfirmMarking == EnmConfirmMarking.NotConfirm) &&
                          (!OtherOptionsMenuItem2.Checked || alarm.ConfirmMarking != EnmConfirmMarking.NotConfirm) &&
                          (!OtherOptionsMenuItem3.Checked || alarm.AlarmID != 0) &&
                          (!OtherOptionsMenuItem4.Checked || alarm.AlarmID == 0) &&
                          (!OtherOptionsMenuItem5.Checked || String.IsNullOrEmpty(alarm.ProjName)) &&
                          (!OtherOptionsMenuItem6.Checked || !String.IsNullOrEmpty(alarm.ProjName))
                          orderby alarm.StartTime descending
                          select alarm).ToList();
            }

            int cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]);

            HttpRuntime.Cache.Insert(cacheKey, alarms, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(alarms);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report012Entity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-012");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscs = new List <LscUserInfo>();

            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]);
                    var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == lscId); });
                    if (lscUser != null)
                    {
                        lscs.Add(lscUser);
                    }
                }
            }
            else
            {
                lscs.AddRange(userData.LscUsers);
            }
            if (lscs.Count == 0)
            {
                return(null);
            }

            var fromTime = DateTime.Parse(BeginFromDate.Text);
            var toTime   = DateTime.Parse(BeginToDate.Text);

            var auxSets    = new List <String>();
            var texts      = new List <String>();
            var filterText = WebUtility.StringSplit(NodeText.Text.Trim());

            foreach (var ft in filterText)
            {
                if (String.IsNullOrEmpty(ft.Trim()))
                {
                    continue;
                }
                if (FilterList.SelectedItem.Value.Equals("1"))
                {
                    auxSets.Add(ft.Trim());
                }
                else
                {
                    texts.Add(ft.Trim());
                }
            }
            if (texts.Count == 0 && auxSets.Count == 0)
            {
                return(null);
            }

            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 almNames = new List <String>();
            var almIds   = new Dictionary <String, String>();
            var almText  = WebUtility.StringSplit(AlarmNameText.Text.Trim());

            foreach (var at in almText)
            {
                if (String.IsNullOrEmpty(at.Trim()))
                {
                    continue;
                }
                if (AlmNameList.SelectedItem.Value.Equals("1"))
                {
                    almIds[at.Trim()] = null;
                }
                else
                {
                    almNames.Add(at.Trim());
                }
            }

            var nodeEntity  = new BNode();
            var otherEntity = new BOther();
            var alarmEntity = new BAlarm();
            var result      = new List <Report012Entity>();

            foreach (var lsc in lscs)
            {
                var devices = otherEntity.GetDevices(lsc.LscID, lsc.Group.GroupID).FindAll(d => staTypes.ContainsKey(d.StaTypeID) && devTypes.ContainsKey(d.DevTypeID));
                var nodes   = nodeEntity.GetNodes(lsc.LscID, EnmNodeType.Aic, texts.ToArray(), auxSets.ToArray(), null);

                var nnodes = from node in nodes
                             join dev in devices on node.DevID equals dev.DevID
                             select node;

                var alarms = WebUtility.GetUserAlarms(userData).FindAll(alarm => alarm.LscID == lsc.LscID && alarm.StartTime >= fromTime && alarm.StartTime <= toTime);
                alarms.AddRange(alarmEntity.GetHisAlarms(lsc.LscID, lsc.LscName, userData.StandardProtocol, lsc.Group.GroupNodes, fromTime, toTime));

                var nalm = from alarm in alarms
                           join nns in nnodes on new { alarm.NodeID, alarm.NodeType } equals new { nns.NodeID, nns.NodeType }
                where (alarm.AlarmLevel == EnmAlarmLevel.Hint) && (almNames.Count == 0 || almNames.Any(name => alarm.AlarmName.Contains(name))) && (almIds.Count == 0 || almIds.ContainsKey(alarm.AlarmID.ToString())) && string.IsNullOrEmpty(alarm.ProjName)
                select alarm;

                result.Add(new Report012Entity {
                    LscID     = lsc.LscID,
                    LscName   = lsc.LscName,
                    BeginTime = fromTime,
                    EndTime   = toTime,
                    Devices   = devices,
                    Alarms    = nalm.Any() ? nalm.ToList() : new List <AlarmInfo>()
                });
            }

            if (result.Count > 0)
            {
                result.Add(new Report012Entity {
                    LscID     = -100,
                    LscName   = "汇总(平均值)",
                    BeginTime = fromTime,
                    EndTime   = toTime,
                    Devices   = new List <DeviceInfo>(),
                    Alarms    = new List <AlarmInfo>()
                });
            }

            int cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]);

            HttpRuntime.Cache.Insert(cacheKey, result, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(result);
        }