Пример #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);
        }
Пример #2
0
        /// <summary>
        /// Add Data To Cache
        /// </summary>
        private DataTable AddDataToCache()
        {
            try {
                var userData  = UserData;
                var cacheKey1 = WebUtility.GetCacheKeyName(userData, "station-count-source1");
                var cacheKey2 = WebUtility.GetCacheKeyName(userData, "station-count-source2");
                HttpRuntime.Cache.Remove(cacheKey1);
                HttpRuntime.Cache.Remove(cacheKey2);

                var types = StaTypeMultiCombo.SelectedItems;
                if (types.Count == 0)
                {
                    return(null);
                }

                if (String.IsNullOrEmpty(StaCountField.RawValue.ToString()))
                {
                    return(null);
                }
                var values = WebUtility.StringSplit(StaCountField.RawValue.ToString());

                var colcnt      = StaCntGridPanel.ColumnModel.Columns.Count;
                var countType   = CountTypeComboBox.SelectedItem.Value;
                var condition   = new List <GroupTreeInfo>();
                var otherEntity = new BOther();
                var source1     = CreateCustomizeTable(colcnt);
                var source2     = new Dictionary <String, List <StationInfo> >();
                if (countType.Equals("0"))
                {
                    #region Lsc
                    foreach (var v in values)
                    {
                        var ids = WebUtility.ItemSplit(v);
                        if (ids.Length != 5)
                        {
                            continue;
                        }

                        var lscId       = Int32.Parse(ids[0]);
                        var groupId     = Int32.Parse(ids[1]);
                        var nodeId      = Int32.Parse(ids[2]);
                        var nodeType    = Int32.Parse(ids[3]);
                        var remark      = ids[4];
                        var enmNodeType = Enum.IsDefined(typeof(EnmNodeType), nodeType) ? (EnmNodeType)nodeType : EnmNodeType.Null;
                        if (enmNodeType == EnmNodeType.LSC)
                        {
                            condition.Add(new GroupTreeInfo()
                            {
                                LscID    = lscId,
                                GroupID  = groupId,
                                NodeID   = nodeId,
                                NodeType = enmNodeType,
                                Remark   = remark
                            });
                        }
                    }

                    var ls = from c in condition
                             group c by new { c.LscID } into g
                        select new {
                        g.Key.LscID
                    };

                    foreach (var l in ls)
                    {
                        var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == l.LscID); });
                        if (lscUser == null)
                        {
                            continue;
                        }

                        var stations = otherEntity.GetStations(lscUser.LscID, lscUser.Group.GroupID);
                        if (MIDEnabledMenuItem.Checked)
                        {
                            stations = stations.FindAll(s => s.MID != null && s.MID.Trim() != "");
                        }

                        var dr1 = source1.NewRow();
                        dr1[1] = lscUser.LscName;
                        var total = new List <StationInfo>();
                        for (int j = 0; j < types.Count; j++)
                        {
                            var stypeId = Int32.Parse(types[j].Value);
                            var filters = stations.FindAll(s => { return(s.StaTypeID == stypeId); });
                            dr1[2 + j] = filters.Count;
                            source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[2 + j].ColumnName)] = filters;
                            total.AddRange(filters);
                        }

                        //total column
                        dr1[source1.Columns.Count - 1] = total.Count;
                        source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[source1.Columns.Count - 1].ColumnName)] = total;
                        source1.Rows.Add(dr1);
                    }
                    #endregion
                }
                else if (countType.Equals("1"))
                {
                    #region Area=2
                    foreach (var v in values)
                    {
                        var ids = WebUtility.ItemSplit(v);
                        if (ids.Length != 5)
                        {
                            continue;
                        }

                        var lscId       = Int32.Parse(ids[0]);
                        var groupId     = Int32.Parse(ids[1]);
                        var nodeId      = Int32.Parse(ids[2]);
                        var nodeType    = Int32.Parse(ids[3]);
                        var remark      = ids[4];
                        var enmNodeType = Enum.IsDefined(typeof(EnmNodeType), nodeType) ? (EnmNodeType)nodeType : EnmNodeType.Null;
                        if (enmNodeType == EnmNodeType.Area &&
                            remark.Equals("2"))
                        {
                            condition.Add(new GroupTreeInfo()
                            {
                                LscID    = lscId,
                                GroupID  = groupId,
                                NodeID   = nodeId,
                                NodeType = enmNodeType,
                                Remark   = remark
                            });
                        }
                    }

                    var ls = from c in condition
                             group c by new { c.LscID } into g
                        select new {
                        g.Key.LscID
                    };

                    foreach (var l in ls)
                    {
                        var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == l.LscID); });
                        if (lscUser == null)
                        {
                            continue;
                        }

                        var stations = otherEntity.GetStations(lscUser.LscID, lscUser.Group.GroupID);
                        if (MIDEnabledMenuItem.Checked)
                        {
                            stations = stations.FindAll(s => s.MID != null && s.MID.Trim() != "");
                        }

                        var areaSta = from d in stations
                                      group d by new { d.Area2ID } into g
                            select new {
                            Area2ID  = g.Key.Area2ID,
                            Stations = g
                        };

                        var areas = otherEntity.GetAreas(lscUser.LscID, lscUser.Group.GroupID, 2);
                        var nodes = from a in areas
                                    join c in condition on new { a.LscID, a.Area2ID } equals new { c.LscID, Area2ID = c.NodeID }
                        select a;

                        foreach (var node in nodes)
                        {
                            var dr1 = source1.NewRow();
                            dr1[1] = node.LscName;
                            dr1[2] = node.Area2Name;

                            var typeArea = areaSta.FirstOrDefault(t => t.Area2ID == node.Area2ID);
                            var total    = new List <StationInfo>();
                            for (int j = 0; j < types.Count; j++)
                            {
                                var stypeId = Int32.Parse(types[j].Value);
                                var filters = typeArea != null?typeArea.Stations.Where(s => s.StaTypeID == stypeId).ToList() : new List <StationInfo>();

                                dr1[3 + j] = filters.Count;
                                source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[3 + j].ColumnName)] = filters;
                                total.AddRange(filters);
                            }

                            //total column
                            dr1[source1.Columns.Count - 1] = total.Count;
                            source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[source1.Columns.Count - 1].ColumnName)] = total;
                            source1.Rows.Add(dr1);
                        }
                    }
                    #endregion
                }
                else if (countType.Equals("2"))
                {
                    #region Area=3
                    foreach (var v in values)
                    {
                        var ids = WebUtility.ItemSplit(v);
                        if (ids.Length != 5)
                        {
                            continue;
                        }

                        var lscId       = Int32.Parse(ids[0]);
                        var groupId     = Int32.Parse(ids[1]);
                        var nodeId      = Int32.Parse(ids[2]);
                        var nodeType    = Int32.Parse(ids[3]);
                        var remark      = ids[4];
                        var enmNodeType = Enum.IsDefined(typeof(EnmNodeType), nodeType) ? (EnmNodeType)nodeType : EnmNodeType.Null;
                        if (enmNodeType == EnmNodeType.Area &&
                            remark.Equals("3"))
                        {
                            condition.Add(new GroupTreeInfo()
                            {
                                LscID    = lscId,
                                GroupID  = groupId,
                                NodeID   = nodeId,
                                NodeType = enmNodeType,
                                Remark   = remark
                            });
                        }
                    }

                    var ls = from c in condition
                             group c by new { c.LscID } into g
                        select new {
                        g.Key.LscID
                    };

                    foreach (var l in ls)
                    {
                        var lscUser = userData.LscUsers.Find(lu => { return(lu.LscID == l.LscID); });
                        if (lscUser == null)
                        {
                            continue;
                        }

                        var stations = otherEntity.GetStations(lscUser.LscID, lscUser.Group.GroupID);
                        if (MIDEnabledMenuItem.Checked)
                        {
                            stations = stations.FindAll(s => s.MID != null && s.MID.Trim() != "");
                        }

                        var areaSta = from d in stations
                                      group d by new { d.Area3ID } into g
                            select new {
                            Area3ID  = g.Key.Area3ID,
                            Stations = g
                        };

                        var areas = otherEntity.GetAreas(lscUser.LscID, lscUser.Group.GroupID, 3);
                        var nodes = from a in areas
                                    join c in condition on new { a.LscID, a.Area3ID } equals new { c.LscID, Area3ID = c.NodeID }
                        select a;

                        foreach (var node in nodes)
                        {
                            var dr1 = source1.NewRow();
                            dr1[1] = node.LscName;
                            dr1[2] = node.Area2Name;
                            dr1[3] = node.Area3Name;

                            var typeArea = areaSta.FirstOrDefault(t => t.Area3ID == node.Area3ID);
                            var total    = new List <StationInfo>();
                            for (int j = 0; j < types.Count; j++)
                            {
                                var stypeId = Int32.Parse(types[j].Value);
                                var filters = typeArea != null?typeArea.Stations.Where(s => s.StaTypeID == stypeId).ToList() : new List <StationInfo>();

                                dr1[4 + j] = filters.Count;
                                source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[4 + j].ColumnName)] = filters;
                                total.AddRange(filters);
                            }

                            //total column
                            dr1[source1.Columns.Count - 1] = total.Count;
                            source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[source1.Columns.Count - 1].ColumnName)] = total;
                            source1.Rows.Add(dr1);
                        }
                    }
                    #endregion
                }

                var totalStartIndex = colcnt - types.Count - 1;
                if (source1.Rows.Count > 0)
                {
                    var totalRow1 = source1.NewRow();
                    totalRow1[1] = "总计";
                    for (int i = totalStartIndex; i < source1.Columns.Count; i++)
                    {
                        var total = new List <StationInfo>();
                        for (int j = 0; j < source1.Rows.Count; j++)
                        {
                            var key = String.Format("{0}-{1}", j, source1.Columns[i].ColumnName);
                            if (source2.ContainsKey(key))
                            {
                                total.AddRange(source2[key]);
                            }
                        }
                        totalRow1[i] = total.Count;
                        source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[i].ColumnName)] = total;
                    }
                    source1.Rows.Add(totalRow1);
                }

                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);
            } catch { throw; }
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report117Entity> AddDataToCache()
        {
            var userData  = UserData;
            var cacheKey1 = WebUtility.GetCacheKeyName(userData, "kpi-report-117");
            var cacheKey2 = WebUtility.GetCacheKeyName(userData, "kpi-report-117-02");

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

            var lscIds = new List <int>();

            if (LscsComboBox.SelectedIndex > 0)
            {
                var ids = WebUtility.ItemSplit(LscsComboBox.SelectedItem.Value);
                if (ids.Length == 2)
                {
                    var lscId   = Int32.Parse(ids[0]);
                    var groupId = Int32.Parse(ids[1]);
                    lscIds.Add(lscId);
                }
            }
            else
            {
                lscIds.AddRange(userData.LscUsers.Select(l => l.LscID));
            }
            if (lscIds.Count == 0)
            {
                return(null);
            }

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

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

            foreach (var dt in StaTypeMultiCombo.SelectedItems)
            {
                staTypes[Int32.Parse(dt.Value)] = dt.Text;
            }
            if (staTypes.Count == 0)
            {
                return(null);
            }

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

            foreach (var dt in DevTypeMultiCombo.SelectedItems)
            {
                devTypes[Int32.Parse(dt.Value)] = dt.Text;
            }
            if (devTypes.Count == 0)
            {
                return(null);
            }

            var otherEntity = new BOther();
            var lscEntity   = new BLsc();
            var source1     = new List <Report117Entity>();
            var source2     = new Dictionary <String, List <StationInfo> >();

            foreach (var id in lscIds)
            {
                var lsc = lscEntity.GetLsc(id);
                if (lsc == null)
                {
                    continue;
                }

                var stations = new Dictionary <Int32, String>();
                var bats     = otherEntity.GetBatStaticCount(lsc.LscID, fromTime, toTime, null, null, 1d / 24d, Int32.MaxValue);
                if (bats != null && bats.Count > 0)
                {
                    var devices = otherEntity.GetDevices(lsc.LscID).FindAll(d => staTypes.ContainsKey(d.StaTypeID) && devTypes.ContainsKey(d.DevTypeID));
                    var temp    = from dev in devices
                                  join bat in bats on new { dev.LscID, dev.DevID } equals new { LscID = bat.ID, DevID = bat.Value }
                    select dev;

                    foreach (var t in temp)
                    {
                        stations[t.StaID] = t.StaName;
                    }
                }

                var stations1 = otherEntity.GetStations(lsc.LscID).FindAll(s => stations.ContainsKey(s.StaID));
                var stations2 = Report117Entity.GetStations(lsc.LscID, lsc.LscName, WebUtility.CreateLscConnectionString(lsc));

                var record = new Report117Entity {
                    LscID     = lsc.LscID,
                    LscName   = lsc.LscName,
                    ThisCount = stations1.Count,
                    LastCount = stations2.Count
                };

                source1.Add(record);
                source2[String.Format("{0}-ThisCount", lsc.LscID)] = stations1;
                source2[String.Format("{0}-LastCount", lsc.LscID)] = stations2;
            }

            if (source1.Count > 0)
            {
                source1.Add(new Report117Entity {
                    LscID     = -100,
                    LscName   = "汇总",
                    ThisCount = (Int32)source1.Sum(r => r.ThisCount),
                    LastCount = (Int32)source1.Sum(r => r.LastCount)
                });
            }

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

            HttpRuntime.Cache.Insert(cacheKey1, source1, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            HttpRuntime.Cache.Insert(cacheKey2, source2, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(source1);
        }
Пример #6
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report006Entity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-006");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscIds = new List <int>();

            if (LscsComboBox.SelectedIndex > 0)
            {
                var ids = WebUtility.ItemSplit(LscsComboBox.SelectedItem.Value);
                if (ids.Length == 2)
                {
                    var lscId   = Int32.Parse(ids[0]);
                    var groupId = Int32.Parse(ids[1]);
                    lscIds.Add(lscId);
                }
            }
            else
            {
                lscIds.AddRange(userData.LscUsers.Select(l => l.LscID));
            }
            if (lscIds.Count == 0)
            {
                return(null);
            }

            var lscEntity   = new BLsc();
            var otherEntity = new BOther();
            var result      = new List <Report006Entity>();

            foreach (var id in lscIds)
            {
                var lsc = lscEntity.GetLsc(id);
                if (lsc == null)
                {
                    continue;
                }

                var cnt = 0;
                if (fRadio.Checked)
                {
                    var stations = otherEntity.GetStations(lsc.LscID);
                    cnt = stations.Count;
                }
                else
                {
                    var areas = otherEntity.GetAreas(lsc.LscID);
                    cnt = areas.Count;
                }

                var parm = Report006Entity.GetLscParam(lsc.LscID, WebUtility.CreateLscConnectionString(lsc));
                result.Add(new Report006Entity {
                    LscID     = lsc.LscID,
                    LscName   = lsc.LscName,
                    ThisCount = cnt,
                    LastCount = parm != null && parm.StaTNumber != WebUtility.DefaultInt32 ? parm.StaTNumber : 0
                });
            }

            if (result.Count > 0)
            {
                result.Add(new Report006Entity {
                    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);
        }
Пример #7
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report112Entity> AddDataToCache()
        {
            var userData  = UserData;
            var cacheKey1 = WebUtility.GetCacheKeyName(userData, "kpi-report-112");
            var cacheKey2 = WebUtility.GetCacheKeyName(userData, "kpi-report-112-02");

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

            var lscIds = new List <int>();

            if (LscsComboBox.SelectedIndex > 0)
            {
                var ids = WebUtility.ItemSplit(LscsComboBox.SelectedItem.Value);
                if (ids.Length == 2)
                {
                    var lscId   = Int32.Parse(ids[0]);
                    var groupId = Int32.Parse(ids[1]);
                    lscIds.Add(lscId);
                }
            }
            else
            {
                lscIds.AddRange(userData.LscUsers.Select(l => l.LscID));
            }
            if (lscIds.Count == 0)
            {
                return(null);
            }

            var 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 otherEntity = new BOther();
            var lscEntity   = new BLsc();
            var source1     = new List <Report112Entity>();
            var source2     = new Dictionary <String, List <StationInfo> >();

            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(otherEntity.GetLscParam());
            }

            foreach (var id in lscIds)
            {
                var lsc = lscEntity.GetLsc(id);
                if (lsc == null)
                {
                    continue;
                }

                var stations1 = otherEntity.GetStations(lsc.LscID).FindAll(s => staTypes.ContainsKey(s.StaTypeID));
                if (MIDEnabledMenuItem.Checked)
                {
                    stations1 = stations1.FindAll(s => s.MID != null && s.MID.Trim() != "");
                }

                var stations2 = Report112Entity.GetStations(lsc.LscID, lsc.LscName, WebUtility.CreateLscConnectionString(lsc));

                var record = new Report112Entity {
                    LscID     = lsc.LscID,
                    LscName   = lsc.LscName,
                    ThisCount = stations1.Count,
                    LastCount = stations2.Count
                };

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

                source1.Add(record);
                source2[String.Format("{0}-ThisCount", lsc.LscID)] = stations1;
                source2[String.Format("{0}-LastCount", lsc.LscID)] = stations2;
            }

            if (source1.Count > 0)
            {
                source1.Add(new Report112Entity {
                    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);
        }
Пример #8
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);
        }
Пример #9
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <OilEngineEntity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-oil-engine-report");

            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 stexts      = new List <String>();
            var sauxSets    = new List <String>();
            var sfilterText = WebUtility.StringSplit(SNodeText.Text.Trim());

            foreach (var ft in sfilterText)
            {
                if (String.IsNullOrEmpty(ft.Trim()))
                {
                    continue;
                }
                if (SFilterList.SelectedItem.Value.Equals("1"))
                {
                    sauxSets.Add(ft.Trim());
                }
                else
                {
                    stexts.Add(ft.Trim());
                }
            }

            var ytexts      = new List <String>();
            var yauxSets    = new List <String>();
            var yfilterText = WebUtility.StringSplit(YNodeText.Text.Trim());

            foreach (var ft in yfilterText)
            {
                if (String.IsNullOrEmpty(ft.Trim()))
                {
                    continue;
                }
                if (YFilterList.SelectedItem.Value.Equals("1"))
                {
                    yauxSets.Add(ft.Trim());
                }
                else
                {
                    ytexts.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 otherEntity = new BOther();
            var nodeEntity  = new BNode();
            var result      = new List <OilEngineEntity>();

            foreach (var lsc in lscs)
            {
                var stations = otherEntity.GetStations(lsc.LscID, lsc.Group.GroupID);

                var snodes = new List <NodeInfo>();
                var ynodes = new List <NodeInfo>();
                if (stexts.Count > 0 || sauxSets.Count > 0)
                {
                    snodes.AddRange(nodeEntity.GetNodes(lsc.LscID, EnmNodeType.Dic, stexts.ToArray(), sauxSets.ToArray(), devTypes.Keys.ToArray()));
                }
                if (ytexts.Count > 0 || yauxSets.Count > 0)
                {
                    ynodes.AddRange(nodeEntity.GetNodes(lsc.LscID, EnmNodeType.Dic, ytexts.ToArray(), yauxSets.ToArray(), devTypes.Keys.ToArray()));
                }

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

                var spairs = new List <OilEnginePair>();
                var sdiv   = nodeEntity.GetHisDIV(lsc.LscID, snodes.Select(n => n.NodeID).ToArray(), fromTime, toTime);
                foreach (var node in snodes)
                {
                    var curNodes = sdiv.FindAll(d => d.NodeID == node.NodeID).OrderBy(d => d.UpdateTime).ToList();

                    var interval  = 0d;
                    var startTime = DateTime.MinValue;
                    foreach (var cn in curNodes)
                    {
                        if (cn.Value == GJ && startTime == DateTime.MinValue)
                        {
                            startTime = cn.UpdateTime;
                        }
                        else if (cn.Value == ZC && startTime != DateTime.MinValue)
                        {
                            interval += cn.UpdateTime.Subtract(startTime).TotalMinutes;
                            startTime = DateTime.MinValue;
                        }
                    }

                    if (startTime != DateTime.MinValue)
                    {
                        interval += toTime.Subtract(startTime).TotalMinutes;
                        startTime = DateTime.MinValue;
                    }

                    spairs.Add(new OilEnginePair {
                        Node     = node,
                        Divs     = curNodes,
                        Interval = interval
                    });
                }

                var ypairs = new List <OilEnginePair>();
                var ydiv   = nodeEntity.GetHisDIV(lsc.LscID, ynodes.Select(n => n.NodeID).ToArray(), fromTime, toTime);
                foreach (var node in ynodes)
                {
                    var curNodes = ydiv.FindAll(d => d.NodeID == node.NodeID).OrderBy(d => d.UpdateTime).ToList();

                    var interval  = 0d;
                    var startTime = DateTime.MinValue;
                    foreach (var cn in curNodes)
                    {
                        if (cn.Value == GJ && startTime == DateTime.MinValue)
                        {
                            startTime = cn.UpdateTime;
                        }
                        else if (cn.Value == ZC && startTime != DateTime.MinValue)
                        {
                            interval += cn.UpdateTime.Subtract(startTime).TotalMinutes;
                            startTime = DateTime.MinValue;
                        }
                    }

                    if (startTime != DateTime.MinValue)
                    {
                        interval += toTime.Subtract(startTime).TotalMinutes;
                        startTime = DateTime.MinValue;
                    }

                    ypairs.Add(new OilEnginePair {
                        Node     = node,
                        Divs     = curNodes,
                        Interval = interval
                    });
                }

                var sresult = from s in spairs
                              group s by new { s.Node.LscID, s.Node.StaID } into g
                    select new {
                    LscID = g.Key.LscID,
                    StaID = g.Key.StaID,
                    Nodes = g
                };

                var yresult = from y in ypairs
                              group y by new { y.Node.LscID, y.Node.StaID } into g
                    select new {
                    LscID = g.Key.LscID,
                    StaID = g.Key.StaID,
                    Nodes = g
                };

                result.AddRange(from sta in stations
                                join sr in sresult on new { sta.LscID, sta.StaID } equals new { sr.LscID, sr.StaID } into lt1
                                from ss in lt1.DefaultIfEmpty()
                                join yr in yresult on new { sta.LscID, sta.StaID } equals new { yr.LscID, yr.StaID } into lt2
                                from ys in lt2.DefaultIfEmpty()
                                select new OilEngineEntity {
                    Station = sta,
                    SNodes  = ss != null ? ss.Nodes.ToList() : new List <OilEnginePair>(),
                    YNodes  = ys != null ? ys.Nodes.ToList() : new List <OilEnginePair>()
                });
            }

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

            HttpRuntime.Cache.Insert(cacheKey, result, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(result);
        }
Пример #10
0
        /// <summary>
        /// Add Data To Cache
        /// </summary>
        private List <ProjectReportPageEntity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "project-report-entities");

            HttpRuntime.Cache.Remove(cacheKey);

            if (LscsComboBox.SelectedItem.Value == null || LscsComboBox.SelectedItem.Value == String.Empty)
            {
                return(null);
            }
            var ids = WebUtility.ItemSplit(LscsComboBox.SelectedItem.Value);

            if (ids.Length != 2)
            {
                return(null);
            }
            var lsc = new BLsc().GetLsc(Int32.Parse(ids[0]));

            if (lsc == null)
            {
                WebUtility.ShowMessage(EnmErrType.Warning, "无法获取Lsc信息");
                return(null);
            }

            var beginTime = DateTime.Parse(BeginDate.Text);
            var endTime   = DateTime.Parse(EndDate.Text);
            var area2Id   = WebUtility.DefaultInt32;
            var area3Id   = WebUtility.DefaultInt32;

            if (Area2ComboBox.SelectedIndex > 0)
            {
                area2Id = Int32.Parse(Area2ComboBox.SelectedItem.Value);
            }
            if (Area3ComboBox.SelectedIndex > 0)
            {
                area3Id = Int32.Parse(Area3ComboBox.SelectedItem.Value);
            }

            var appointmentEntity = new BAppointment();
            var connectionString  = WebUtility.CreateLscConnectionString(lsc);

            var appointments1 = appointmentEntity.GetAppointments(lsc.LscID, lsc.LscName, connectionString, beginTime, endTime, 0, null);
            var appointments2 = appointmentEntity.GetHisAppointments(lsc.LscID, lsc.LscName, beginTime, endTime, 0, null);

            appointments1.AddRange(appointments2);

            var lscappointments = appointments1.FindAll(a => a.LscIncluded == lsc.LscID);
            var nonappointments = appointments1.FindAll(a => a.LscIncluded != lsc.LscID);

            var staSet = new List <IDValuePair <int, AppointmentInfo> >();

            foreach (var apt in nonappointments)
            {
                if (apt.StaIncluded != null && apt.StaIncluded.Trim() != String.Empty)
                {
                    var array = apt.StaIncluded.Split(';');
                    foreach (var id in array)
                    {
                        if (id.Trim() != String.Empty)
                        {
                            staSet.Add(new IDValuePair <int, AppointmentInfo>(Int32.Parse(id), apt));
                        }
                    }
                }
            }

            var devSet = new List <IDValuePair <int, AppointmentInfo> >();

            foreach (var apt in nonappointments)
            {
                if (apt.DevIncluded != null && apt.DevIncluded.Trim() != String.Empty)
                {
                    var array = apt.DevIncluded.Split(';');
                    foreach (var id in array)
                    {
                        if (id.Trim() != String.Empty)
                        {
                            devSet.Add(new IDValuePair <int, AppointmentInfo>(Int32.Parse(id), apt));
                        }
                    }
                }
            }

            var otherEntity = new BOther();
            var stations    = otherEntity.GetStations(lsc.LscID);
            var master1     = from ss in staSet
                              join sta in stations on ss.ID equals sta.StaID
                              select new IDValuePair <int, AppointmentInfo> {
                ID    = sta.Area3ID,
                Value = ss.Value
            };

            var devices = otherEntity.GetDevices(lsc.LscID);
            var master2 = from ds in devSet
                          join dev in devices on ds.ID equals dev.DevID
                          select new IDValuePair <int, AppointmentInfo> {
                ID    = dev.Area3ID,
                Value = ds.Value
            };

            var master = new Dictionary <String, IDValuePair <int, AppointmentInfo> >();

            foreach (var mt in master1)
            {
                master[String.Format("{0}-{1}", mt.ID, mt.Value.Id)] = mt;
            }
            foreach (var mt in master2)
            {
                master[String.Format("{0}-{1}", mt.ID, mt.Value.Id)] = mt;
            }

            var areas = otherEntity.GetAreas(lsc.LscID);

            if (area2Id != WebUtility.DefaultInt32)
            {
                areas = areas.FindAll(a => a.Area2ID == area2Id);
            }
            if (area3Id != WebUtility.DefaultInt32)
            {
                areas = areas.FindAll(a => a.Area3ID == area3Id);
            }

            foreach (var area in areas)
            {
                foreach (var apt in lscappointments)
                {
                    master[String.Format("{0}-{1}", area.Area3ID, apt.Id)] = new IDValuePair <int, AppointmentInfo>(area.Area3ID, apt);
                }
            }

            var a1 = from mt in master.Values
                     group mt by new { AreaId = mt.ID, mt.Value.ProjectId } into g
                select new {
                g.Key.AreaId,
                g.Key.ProjectId,
                Time = g.Sum(a => a.Value.EndTime.Subtract(a.Value.StartTime).TotalSeconds)
            };

            var projects = appointmentEntity.GetProjectItem(lsc.LscID, lsc.LscName, connectionString);
            var a2       = from a in a1
                           join p in projects on a.ProjectId equals p.ProjectId
                           select new {
                AreaId      = a.AreaId,
                Time        = a.Time,
                Project     = p,
                IsExProject = a.Time > p.EndTime.Subtract(p.BeginTime).TotalSeconds
            };

            var a3 = from a in a2
                     group a by new { a.AreaId } into g
                select new {
                g.Key.AreaId,
                Time       = g.Sum(p => p.Time),
                Projects   = g.Select(p => p.Project).ToList(),
                ExProjects = g.Where(p => p.IsExProject).Select(p => p.Project).ToList()
            };

            var a4 = from area in areas
                     join a in a3 on area.Area3ID equals a.AreaId into l
                     from aa in l.DefaultIfEmpty()
                     select new ProjectReportPageEntity {
                Area       = area,
                Time       = aa != null ? aa.Time : 0,
                Projects   = aa != null ? aa.Projects : new List <ProjectInfo>(),
                ExProjects = aa != null ? aa.ExProjects : new List <ProjectInfo>()
            };


            var result        = a4.ToList();
            var cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]);

            HttpRuntime.Cache.Insert(cacheKey, result, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(result);
        }
Пример #11
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);
        }
Пример #12
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report101Entity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-101");

            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 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 ctexts      = new List <String>();
            var cauxSets    = new List <String>();
            var cfilterText = WebUtility.StringSplit(CNodeText.Text.Trim());

            foreach (var ft in cfilterText)
            {
                if (String.IsNullOrEmpty(ft.Trim()))
                {
                    continue;
                }
                if (CFilterTypeList.SelectedItem.Value.Equals("1"))
                {
                    cauxSets.Add(ft.Trim());
                }
                else
                {
                    ctexts.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);
            }

            if (texts.Count == 0 && auxSets.Count == 0 && devTypes.Count > 5)
            {
                WebUtility.ShowMessage(EnmErrType.Warning, "数据量过多,请更换查询条件后重试!");
                return(null);
            }

            var otherEntity = new BOther();
            var nodeEntity  = new BNode();
            var stations    = new List <StationInfo>();
            var devices     = new List <DeviceInfo>();
            var nodes       = new List <NodeInfo>();
            var cnodes      = 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 (ctexts.Count > 0 || cauxSets.Count > 0)
                {
                    cnodes.AddRange(nodeEntity.GetNodes(lsc.LscID, EnmNodeType.Aic, ctexts.ToArray(), cauxSets.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 ndGroup = from node in nodes
                          group node by new { node.LscID, node.StaID } into g
                select new {
                LscID = g.Key.LscID,
                StaID = g.Key.StaID,
                Nodes = g.ToList()
            };

            var cndGroup = from node in cnodes
                           group node by new { node.LscID, node.StaID } into g
                select new {
                LscID = g.Key.LscID,
                StaID = g.Key.StaID,
                Nodes = g.ToList()
            };

            var staWdn = from sta in stations
                         join dg in devGroup on new { sta.LscID, sta.StaID } equals new { dg.LscID, dg.StaID } into ltd
            from ds in ltd.DefaultIfEmpty()
            join ng in ndGroup on new { sta.LscID, sta.StaID } equals new { ng.LscID, ng.StaID } into ltn
            from ns in ltn.DefaultIfEmpty()
            join cg in cndGroup on new { sta.LscID, sta.StaID } equals new { cg.LscID, cg.StaID } into ltc
            from cs in ltc.DefaultIfEmpty()
            select new {
                Station = sta,
                Devices = ds == null ? new List <DeviceInfo>() : ds.Devices,
                Nodes   = ns == null ? new List <NodeInfo>() : ns.Nodes,
                CNodes  = cs == null ? new List <NodeInfo>() : cs.Nodes
            };

            var result = (from sta in staWdn
                          group sta by new { sta.Station.LscID, sta.Station.Area3ID, sta.Station.BuildingID } into g
                          orderby g.Key.LscID, g.Key.Area3ID, g.Key.BuildingID
                          select new Report101Entity {
                Station = g.First().Station,
                FH = g.Sum(t => t.Nodes.Sum(n => n.Value)),
                CDFH = g.Sum(t => t.CNodes.Sum(n => n.Value)),
                DesignCapacity = CapacityMenuItem.Checked ? Convert.ToSingle(CapacitySpinnerField.Number) : g.Sum(t => t.Devices.Sum(d => d.DevDesignCapacity == WebUtility.DefaultFloat ? 0 : d.DevDesignCapacity)),
                Devices = g.SelectMany(d => d.Devices).ToList(),
                Nodes = g.SelectMany(n => n.Nodes).ToList(),
                CNodes = g.SelectMany(n => n.CNodes).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);
        }
Пример #13
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);
        }