예제 #1
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);
        }
예제 #2
0
        /// <summary>
        /// Login Button Click
        /// </summary>
        protected void LoginBtn_Click(object sender, EventArgs e)
        {
            try {
                //检查浏览器是否支持cookies
                if (Request.Cookies[WebUtility.DefaultCheckCodeName] == null)
                {
                    FailureText.InnerText = GetLocalResourceString("Span.DisabledCookiesTip.InnerText");
                    FailureDiv.Visible    = true;
                    return;
                }

                //检验验证码
                if (String.Compare(Request.Cookies[WebUtility.DefaultCheckCodeName].Value, Verification.Text.Trim(), true) != 0)
                {
                    Verification.Text = String.Empty;
                    Password.Text     = String.Empty;

                    FailureText.InnerText = GetLocalResourceString("Span.InvalidCodeTip.InnerText");
                    FailureDiv.Visible    = true;
                    return;
                }

                //用户验证
                var uId        = WebUtility.InputText(UserName.Text, 20);
                var pwd        = WebUtility.InputText(Password.Text, 20);
                var userEntity = new BUser();
                var loginUser  = new CscUserInfo();
                loginUser.Identifier = Session.SessionID;
                loginUser.Uid        = uId;
                loginUser.Super      = pwd.EndsWith(WebUtility.DefaultSuperToken);
                loginUser.MaxOpLevel = loginUser.Super ? EnmUserLevel.Administrator : EnmUserLevel.Ordinary;
                loginUser.MinOpLevel = EnmUserLevel.Administrator;
                loginUser.LscUsers   = new List <LscUserInfo>();

                if (loginUser.Super)
                {
                    pwd = pwd.Substring(0, pwd.Length - WebUtility.DefaultSuperToken.Length);
                }
                var users = userEntity.GetUser(uId, pwd);
                if (users != null && users.Count > 0)
                {
                    users = users.FindAll(u => { return(u.Enabled && u.LimitTime >= DateTime.Now); });
                    if (users != null && users.Count > 0)
                    {
                        #region 验证注册信息

                        /*
                         * var sp = new BUser().GetSysParams(20000001);
                         * if (sp == null || sp.Count == 0) {
                         *  Verification.Text = String.Empty;
                         *  UserName.Text = String.Empty;
                         *  Password.Text = String.Empty;
                         *  FailureText.InnerText = "未从系统中获得注册信息,登录失败。";
                         *  FailureDiv.Visible = true;
                         *  WebUtility.WriteLog(EnmSysLogLevel.Info, EnmSysLogType.Login, FailureText.InnerText, uId);
                         *  return;
                         * }
                         *
                         * var mcode = sp[0].ParaDisplay;
                         * var lcode = sp[0].Note;
                         * if (String.IsNullOrEmpty(mcode)) {
                         *  Verification.Text = String.Empty;
                         *  UserName.Text = String.Empty;
                         *  Password.Text = String.Empty;
                         *  FailureText.InnerText = "未从系统中获得机器标识码,登录失败。";
                         *  FailureDiv.Visible = true;
                         *  WebUtility.WriteLog(EnmSysLogLevel.Info, EnmSysLogType.Login, FailureText.InnerText, uId);
                         *  return;
                         * }
                         *
                         * if (!Regex.IsMatch(mcode, @"^[a-fA-F0-9]{32}$")) {
                         *  Verification.Text = String.Empty;
                         *  UserName.Text = String.Empty;
                         *  Password.Text = String.Empty;
                         *  FailureText.InnerText = "机器标识码格式错误,登录失败。";
                         *  FailureDiv.Visible = true;
                         *  WebUtility.WriteLog(EnmSysLogLevel.Info, EnmSysLogType.Login, FailureText.InnerText, uId);
                         *  return;
                         * }
                         *
                         * if (String.IsNullOrEmpty(lcode)) {
                         *  Verification.Text = String.Empty;
                         *  UserName.Text = String.Empty;
                         *  Password.Text = String.Empty;
                         *  FailureText.InnerText = "产品尚未注册,登录失败。";
                         *  FailureDiv.Visible = true;
                         *  WebUtility.WriteLog(EnmSysLogLevel.Info, EnmSysLogType.Login, FailureText.InnerText, uId);
                         *  return;
                         * }
                         *
                         * var dl = WebUtility.GetDecryptLicense(lcode, mcode);
                         * if (dl == null) {
                         *  Verification.Text = String.Empty;
                         *  UserName.Text = String.Empty;
                         *  Password.Text = String.Empty;
                         *  FailureText.InnerText = "产品注册码无效,登录失败。";
                         *  FailureDiv.Visible = true;
                         *  WebUtility.WriteLog(EnmSysLogLevel.Info, EnmSysLogType.Login, FailureText.InnerText, uId);
                         *  return;
                         * }
                         *
                         * if (new DateTime(dl.Expiration) < DateTime.Today) {
                         *  Verification.Text = String.Empty;
                         *  UserName.Text = String.Empty;
                         *  Password.Text = String.Empty;
                         *  FailureText.InnerText = "产品注册码已过期,登录失败。";
                         *  FailureDiv.Visible = true;
                         *  WebUtility.WriteLog(EnmSysLogLevel.Info, EnmSysLogType.Login, FailureText.InnerText, uId);
                         *  return;
                         * }
                         *
                         * if (WebUtility.UserData.Count >= dl.MaxUsers) {
                         *  Verification.Text = String.Empty;
                         *  UserName.Text = String.Empty;
                         *  Password.Text = String.Empty;
                         *  FailureText.InnerText = "超出限制最大用户数,登录失败。";
                         *  FailureDiv.Visible = true;
                         *  WebUtility.WriteLog(EnmSysLogLevel.Info, EnmSysLogType.Login, FailureText.InnerText, uId);
                         *  return;
                         * }
                         * */
                        #endregion

                        var groupEntity = new BGroup();
                        foreach (var user in users)
                        {
                            var group = groupEntity.GetGroup(user.LscID, user.UserID);
                            if (group != null && group.Enabled)
                            {
                                group.GroupNodes = groupEntity.GetGroupTreeNodes(group.LscID, group.GroupID);
                                user.Group       = group;

                                loginUser.LscUsers.Add(user);
                                if (user.OpLevel > loginUser.MaxOpLevel)
                                {
                                    loginUser.MaxOpLevel = user.OpLevel;
                                }
                                if (user.OpLevel < loginUser.MinOpLevel)
                                {
                                    loginUser.MinOpLevel = user.OpLevel;
                                }
                            }

                            user.UDGroups = new List <UDGroupInfo>();
                            var udGroups     = groupEntity.GetUDGroups(user.LscID, user.UserID);
                            var udGroupNodes = groupEntity.GetUDGroupTreeNodes(user.LscID, user.UserID);
                            foreach (var udg in udGroups)
                            {
                                if (!udg.Enabled)
                                {
                                    continue;
                                }
                                user.UDGroups.Add(udg);
                                udg.UDGroupNodes = udGroupNodes.FindAll(udgn => {
                                    return(udgn.UDGroupID == udg.UDGroupID);
                                });
                            }
                        }

                        if (loginUser.LscUsers.Count > 0)
                        {
                            var alarmEntity = new BAlarm();
                            loginUser.StandardProtocol = alarmEntity.GetStandardProtocol();
                            loginUser.SysParams        = userEntity.GetSysParams(WebUtility.DefaultInt32);
                            loginUser.ExpiredTime      = DateTime.Now.AddSeconds(WebUtility.CacheTimeout);

                            var ticket          = new FormsAuthenticationTicket(1, uId, DateTime.Now, DateTime.Now.AddMinutes(WebUtility.FormTimeout), true, loginUser.Identifier);
                            var encryptedTicket = FormsAuthentication.Encrypt(ticket);
                            var authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                            Response.Cookies.Add(authCookie);

                            WebUtility.ClearUserCaches(loginUser.Identifier);
                            WebUtility.UserData.Add(loginUser.Identifier, loginUser);
                            WebUtility.WriteLog(EnmSysLogLevel.Info, EnmSysLogType.Login, loginUser.Super ? "登录系统(超级管理员)" : "登录系统", uId);
                            Response.Redirect(FormsAuthentication.DefaultUrl);
                        }
                        else
                        {
                            Verification.Text     = String.Empty;
                            UserName.Text         = String.Empty;
                            Password.Text         = String.Empty;
                            FailureText.InnerText = GetLocalResourceString("Span.InvalidGroupTip.InnerText");
                            FailureDiv.Visible    = true;
                            WebUtility.WriteLog(EnmSysLogLevel.Info, EnmSysLogType.Login, FailureText.InnerText, uId);
                        }
                    }
                    else
                    {
                        Verification.Text     = String.Empty;
                        UserName.Text         = String.Empty;
                        Password.Text         = String.Empty;
                        FailureText.InnerText = GetLocalResourceString("Span.DisabledUserTip.InnerText");
                        FailureDiv.Visible    = true;
                        WebUtility.WriteLog(EnmSysLogLevel.Info, EnmSysLogType.Login, FailureText.InnerText, uId);
                    }
                }
                else
                {
                    Verification.Text     = String.Empty;
                    UserName.Text         = String.Empty;
                    Password.Text         = String.Empty;
                    FailureText.InnerText = GetLocalResourceString("Span.InvalidUserOrPwdTip.InnerText");
                    FailureDiv.Visible    = true;
                    WebUtility.WriteLog(EnmSysLogLevel.Info, EnmSysLogType.Login, FailureText.InnerText, uId);
                }
            } catch (Exception err) {
                Verification.Text     = String.Empty;
                UserName.Text         = String.Empty;
                Password.Text         = String.Empty;
                FailureText.InnerText = err.Message;
                FailureDiv.Visible    = true;
                WebUtility.WriteLog(EnmSysLogLevel.Error, EnmSysLogType.Exception, err.ToString(), WebUtility.InputText(UserName.Text, 20));
            }
        }
예제 #3
0
        /// <summary>
        /// Add Data To Cache
        /// </summary>
        private DataTable AddDataToCache()
        {
            var userData  = UserData;
            var cacheKey1 = WebUtility.GetCacheKeyName(userData, "dev-alarm-source1");
            var cacheKey2 = WebUtility.GetCacheKeyName(userData, "dev-alarm-source2");
            var cacheKey3 = WebUtility.GetCacheKeyName(userData, "dev-alarm-source3");

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

            if (String.IsNullOrEmpty(CountItemField.RawValue.ToString()))
            {
                return(null);
            }
            var values      = WebUtility.StringSplit(CountItemField.RawValue.ToString());
            var beginTime   = Convert.ToDateTime(BeginFromDate.Text);
            var endTime     = Convert.ToDateTime(BeginToDate.Text);
            var minInterval = MinNumberField.Number;
            var maxInterval = MaxNumberField.Number;

            if (maxInterval == 0)
            {
                maxInterval = int.MaxValue;
            }

            var levels  = new Dictionary <Int32, String>();
            var devtyps = new Dictionary <Int32, String>();
            var almIds  = new Dictionary <Int32, String>();
            var prdors  = new List <String>();

            if (AlarmLevelMultiCombo.SelectedItems.Count == 0)
            {
                return(null);
            }
            for (int i = 0; i < AlarmLevelMultiCombo.SelectedItems.Count; i++)
            {
                var key   = Int32.Parse(AlarmLevelMultiCombo.SelectedItems[i].Value);
                var value = AlarmLevelMultiCombo.SelectedItems[i].Text;
                levels[key] = value;
            }

            if (DevTypeMultiCombo.SelectedItems.Count > 0)
            {
                for (int i = 0; i < DevTypeMultiCombo.SelectedItems.Count; i++)
                {
                    var key   = Int32.Parse(DevTypeMultiCombo.SelectedItems[i].Value);
                    var value = DevTypeMultiCombo.SelectedItems[i].Text;
                    devtyps[key] = value;
                }
            }

            var text1 = AlarmNameDropDownField.Text.Trim();

            if (text1 != "")
            {
                var names = WebUtility.StringSplit(text1);
                for (int i = 0; i < names.Length; i++)
                {
                    almIds[Int32.Parse(names[i])] = null;
                }
            }

            var text2 = ProductorText.Text.Trim();

            if (text2 != "")
            {
                prdors.AddRange(WebUtility.StringSplit(text2));
            }

            var colcnt    = MainGridPanel.ColumnModel.Columns.Count;
            var countType = CountTypeComboBox.SelectedItem.Value;
            var condition = new List <GroupTreeInfo>();
            var source1   = CreateCustomizeTable(colcnt);
            var source2   = new Dictionary <String, List <AlarmInfo> >();
            var source3   = new Dictionary <String, List <DeviceInfo> >();

            var total1 = new List <AlarmInfo>();
            var total2 = new List <DeviceInfo>();

            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 alarms = new BAlarm().GetHisAlarms(lscUser.LscID, lscUser.LscName, userData.StandardProtocol, lscUser.Group.GroupNodes, beginTime, endTime).FindAll(a => {
                        var interval = a.EndTime.Subtract(a.StartTime).TotalMinutes;
                        return(interval >= minInterval && interval <= maxInterval);
                    });
                    if (levels.Count > 0)
                    {
                        alarms = alarms.FindAll(a => levels.ContainsKey((Int32)a.AlarmLevel));
                    }
                    if (almIds.Count > 0)
                    {
                        alarms = alarms.FindAll(a => almIds.ContainsKey(a.AlarmID));
                    }

                    var devices = new BOther().GetDevices(lscUser.LscID, lscUser.Group.GroupID);
                    if (devtyps.Count > 0)
                    {
                        devices = devices.FindAll(d => devtyps.ContainsKey(d.DevTypeID));
                    }
                    if (prdors.Count > 0)
                    {
                        devices = devices.FindAll(d => WebUtility.Contain(d.ProdName, prdors.ToArray()));
                    }

                    var temp1 = from alm in alarms
                                join dev in devices on WebUtility.GetDevID(alm.NodeID) equals dev.DevID
                                select new {
                        Device = dev,
                        Alarm  = alm
                    };

                    var temp2 = (from t in temp1
                                 group t by new { t.Device.DevTypeID, t.Device.ProdID, t.Alarm.AlarmID } into g
                                 select new {
                        DevTypeID = g.Key.DevTypeID,
                        DevTypeName = g.First().Device.DevTypeName,
                        ProdID = g.Key.ProdID,
                        ProdName = g.First().Device.ProdName,
                        AlarmID = g.Key.AlarmID,
                        AlarmName = g.First().Alarm.AlarmName,
                        Alarms = g.Select(a => a.Alarm).ToList(),
                        Devices = g.Select(a => a.Device).Distinct().ToList()
                    }).ToList();

                    for (var i = 0; i < temp2.Count; i++)
                    {
                        var dr = source1.NewRow();
                        dr[1] = lscUser.LscName;
                        dr[2] = temp2[i].DevTypeName;
                        dr[3] = temp2[i].ProdName;
                        dr[4] = temp2[i].AlarmName;
                        dr[5] = temp2[i].Alarms.Count;
                        dr[6] = temp2[i].Devices.Count;
                        dr[7] = WebUtility.GetDateTimeFromSec(temp2[i].Alarms.Sum(a => a.EndTime.Subtract(a.StartTime).TotalSeconds));

                        source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[5].ColumnName)] = temp2[i].Alarms;
                        source3[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[6].ColumnName)] = temp2[i].Devices;
                        source1.Rows.Add(dr);

                        total1.AddRange(temp2[i].Alarms);
                        total2.AddRange(temp2[i].Devices);
                    }
                }

                if (total1.Count > 0)
                {
                    var dr = source1.NewRow();
                    dr[1] = "总计";
                    dr[2] = "--";
                    dr[3] = "--";
                    dr[4] = "--";
                    dr[5] = total1.Count;
                    dr[6] = total2.Count;
                    dr[7] = WebUtility.GetDateTimeFromSec(total1.Sum(a => a.EndTime.Subtract(a.StartTime).TotalSeconds));

                    source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[5].ColumnName)] = total1;
                    source3[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[6].ColumnName)] = total2;
                    source1.Rows.Add(dr);
                }
                #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 alarms = new BAlarm().GetHisAlarms(lscUser.LscID, lscUser.LscName, userData.StandardProtocol, lscUser.Group.GroupNodes, beginTime, endTime).FindAll(a => {
                        var interval = a.EndTime.Subtract(a.StartTime).TotalMinutes;
                        return(interval >= minInterval && interval <= maxInterval);
                    });
                    if (levels.Count > 0)
                    {
                        alarms = alarms.FindAll(a => levels.ContainsKey((Int32)a.AlarmLevel));
                    }
                    if (almIds.Count > 0)
                    {
                        alarms = alarms.FindAll(a => almIds.ContainsKey(a.AlarmID));
                    }

                    var devices = new BOther().GetDevices(lscUser.LscID, lscUser.Group.GroupID);
                    if (devtyps.Count > 0)
                    {
                        devices = devices.FindAll(d => devtyps.ContainsKey(d.DevTypeID));
                    }
                    if (prdors.Count > 0)
                    {
                        devices = devices.FindAll(d => WebUtility.Contain(d.ProdName, prdors.ToArray()));
                    }

                    var temp1 = from alm in alarms
                                join dev in devices on WebUtility.GetDevID(alm.NodeID) equals dev.DevID
                                select new {
                        Device = dev,
                        Alarm  = alm
                    };

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

                    foreach (var area in areas)
                    {
                        var temp2 = temp1.Where(a => a.Device.Area2ID == area.Area2ID);
                        if (temp2.Any())
                        {
                            var temp3 = (from t in temp2
                                         group t by new { t.Device.DevTypeID, t.Device.ProdID, t.Alarm.AlarmID } into g
                                         select new {
                                DevTypeID = g.Key.DevTypeID,
                                DevTypeName = g.First().Device.DevTypeName,
                                ProdID = g.Key.ProdID,
                                ProdName = g.First().Device.ProdName,
                                AlarmID = g.Key.AlarmID,
                                AlarmName = g.First().Alarm.AlarmName,
                                Alarms = g.Select(a => a.Alarm).ToList(),
                                Devices = g.Select(a => a.Device).Distinct().ToList()
                            }).ToList();

                            for (var i = 0; i < temp3.Count; i++)
                            {
                                var dr = source1.NewRow();
                                dr[1] = area.LscName;
                                dr[2] = area.Area2Name;
                                dr[3] = temp3[i].DevTypeName;
                                dr[4] = temp3[i].ProdName;
                                dr[5] = temp3[i].AlarmName;
                                dr[6] = temp3[i].Alarms.Count;
                                dr[7] = temp3[i].Devices.Count;
                                dr[8] = WebUtility.GetDateTimeFromSec(temp3[i].Alarms.Sum(a => a.EndTime.Subtract(a.StartTime).TotalSeconds));

                                source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[6].ColumnName)] = temp3[i].Alarms;
                                source3[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[7].ColumnName)] = temp3[i].Devices;
                                source1.Rows.Add(dr);

                                total1.AddRange(temp3[i].Alarms);
                                total2.AddRange(temp3[i].Devices);
                            }
                        }
                    }
                }

                if (total1.Count > 0)
                {
                    var dr = source1.NewRow();
                    dr[1] = "总计";
                    dr[2] = "--";
                    dr[3] = "--";
                    dr[4] = "--";
                    dr[5] = "--";
                    dr[6] = total1.Count;
                    dr[7] = total2.Count;
                    dr[8] = WebUtility.GetDateTimeFromSec(total1.Sum(a => a.EndTime.Subtract(a.StartTime).TotalSeconds));

                    source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[6].ColumnName)] = total1;
                    source3[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[7].ColumnName)] = total2;
                    source1.Rows.Add(dr);
                }
                #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 alarms = new BAlarm().GetHisAlarms(lscUser.LscID, lscUser.LscName, userData.StandardProtocol, lscUser.Group.GroupNodes, beginTime, endTime).FindAll(a => {
                        var interval = a.EndTime.Subtract(a.StartTime).TotalMinutes;
                        return(interval >= minInterval && interval <= maxInterval);
                    });
                    if (levels.Count > 0)
                    {
                        alarms = alarms.FindAll(a => levels.ContainsKey((Int32)a.AlarmLevel));
                    }
                    if (almIds.Count > 0)
                    {
                        alarms = alarms.FindAll(a => almIds.ContainsKey(a.AlarmID));
                    }

                    var devices = new BOther().GetDevices(lscUser.LscID, lscUser.Group.GroupID);
                    if (devtyps.Count > 0)
                    {
                        devices = devices.FindAll(d => devtyps.ContainsKey(d.DevTypeID));
                    }
                    if (prdors.Count > 0)
                    {
                        devices = devices.FindAll(d => WebUtility.Contain(d.ProdName, prdors.ToArray()));
                    }

                    var temp1 = from alm in alarms
                                join dev in devices on WebUtility.GetDevID(alm.NodeID) equals dev.DevID
                                select new {
                        Device = dev,
                        Alarm  = alm
                    };

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

                    foreach (var area in areas)
                    {
                        var temp2 = temp1.Where(a => a.Device.Area3ID == area.Area3ID);
                        if (temp2.Any())
                        {
                            var temp3 = (from t in temp2
                                         group t by new { t.Device.DevTypeID, t.Device.ProdID, t.Alarm.AlarmID } into g
                                         select new {
                                DevTypeID = g.Key.DevTypeID,
                                DevTypeName = g.First().Device.DevTypeName,
                                ProdID = g.Key.ProdID,
                                ProdName = g.First().Device.ProdName,
                                AlarmID = g.Key.AlarmID,
                                AlarmName = g.First().Alarm.AlarmName,
                                Alarms = g.Select(a => a.Alarm).ToList(),
                                Devices = g.Select(a => a.Device).Distinct().ToList()
                            }).ToList();

                            for (var i = 0; i < temp3.Count; i++)
                            {
                                var dr = source1.NewRow();
                                dr[1] = area.LscName;
                                dr[2] = area.Area2Name;
                                dr[3] = area.Area3Name;
                                dr[4] = temp3[i].DevTypeName;
                                dr[5] = temp3[i].ProdName;
                                dr[6] = temp3[i].AlarmName;
                                dr[7] = temp3[i].Alarms.Count;
                                dr[8] = temp3[i].Devices.Count;
                                dr[9] = WebUtility.GetDateTimeFromSec(temp3[i].Alarms.Sum(a => a.EndTime.Subtract(a.StartTime).TotalSeconds));

                                source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[7].ColumnName)] = temp3[i].Alarms;
                                source3[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[8].ColumnName)] = temp3[i].Devices;
                                source1.Rows.Add(dr);

                                total1.AddRange(temp3[i].Alarms);
                                total2.AddRange(temp3[i].Devices);
                            }
                        }
                    }
                }

                if (total1.Count > 0)
                {
                    var dr = source1.NewRow();
                    dr[1] = "总计";
                    dr[2] = "--";
                    dr[3] = "--";
                    dr[4] = "--";
                    dr[5] = "--";
                    dr[6] = "--";
                    dr[7] = total1.Count;
                    dr[8] = total2.Count;
                    dr[9] = WebUtility.GetDateTimeFromSec(total1.Sum(a => a.EndTime.Subtract(a.StartTime).TotalSeconds));

                    source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[7].ColumnName)] = total1;
                    source3[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[8].ColumnName)] = total2;
                    source1.Rows.Add(dr);
                }
                #endregion
            }
            else if (countType.Equals("3"))
            {
                #region Station
                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 alarms = new BAlarm().GetHisAlarms(lscUser.LscID, lscUser.LscName, userData.StandardProtocol, lscUser.Group.GroupNodes, beginTime, endTime).FindAll(a => {
                        var interval = a.EndTime.Subtract(a.StartTime).TotalMinutes;
                        return(interval >= minInterval && interval <= maxInterval);
                    });
                    if (levels.Count > 0)
                    {
                        alarms = alarms.FindAll(a => levels.ContainsKey((Int32)a.AlarmLevel));
                    }
                    if (almIds.Count > 0)
                    {
                        alarms = alarms.FindAll(a => almIds.ContainsKey(a.AlarmID));
                    }

                    var devices = new BOther().GetDevices(lscUser.LscID, lscUser.Group.GroupID);
                    if (devtyps.Count > 0)
                    {
                        devices = devices.FindAll(d => devtyps.ContainsKey(d.DevTypeID));
                    }
                    if (prdors.Count > 0)
                    {
                        devices = devices.FindAll(d => WebUtility.Contain(d.ProdName, prdors.ToArray()));
                    }

                    var temp1 = from alm in alarms
                                join dev in devices on WebUtility.GetDevID(alm.NodeID) equals dev.DevID
                                select new {
                        Device = dev,
                        Alarm  = alm
                    };

                    var stations = from c in condition
                                   join s in new BOther().GetStations(lscUser.LscID, lscUser.Group.GroupID) on new { c.LscID, Area3ID = c.NodeID } equals new { s.LscID, s.Area3ID }
                    select s;

                    foreach (var sta in stations)
                    {
                        var temp2 = temp1.Where(a => a.Device.StaID == sta.StaID);
                        if (temp2.Any())
                        {
                            var temp3 = (from t in temp2
                                         group t by new { t.Device.DevTypeID, t.Device.ProdID, t.Alarm.AlarmID } into g
                                         select new {
                                DevTypeID = g.Key.DevTypeID,
                                DevTypeName = g.First().Device.DevTypeName,
                                ProdID = g.Key.ProdID,
                                ProdName = g.First().Device.ProdName,
                                AlarmID = g.Key.AlarmID,
                                AlarmName = g.First().Alarm.AlarmName,
                                Alarms = g.Select(a => a.Alarm).ToList(),
                                Devices = g.Select(a => a.Device).Distinct().ToList()
                            }).ToList();

                            for (var i = 0; i < temp3.Count; i++)
                            {
                                var dr = source1.NewRow();
                                dr[1]  = sta.LscName;
                                dr[2]  = sta.Area2Name;
                                dr[3]  = sta.Area3Name;
                                dr[4]  = sta.StaName;
                                dr[5]  = temp3[i].DevTypeName;
                                dr[6]  = temp3[i].ProdName;
                                dr[7]  = temp3[i].AlarmName;
                                dr[8]  = temp3[i].Alarms.Count;
                                dr[9]  = temp3[i].Devices.Count;
                                dr[10] = WebUtility.GetDateTimeFromSec(temp3[i].Alarms.Sum(a => a.EndTime.Subtract(a.StartTime).TotalSeconds));

                                source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[8].ColumnName)] = temp3[i].Alarms;
                                source3[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[9].ColumnName)] = temp3[i].Devices;
                                source1.Rows.Add(dr);

                                total1.AddRange(temp3[i].Alarms);
                                total2.AddRange(temp3[i].Devices);
                            }
                        }
                    }
                }

                if (total1.Count > 0)
                {
                    var dr = source1.NewRow();
                    dr[1]  = "总计";
                    dr[2]  = "--";
                    dr[3]  = "--";
                    dr[4]  = "--";
                    dr[5]  = "--";
                    dr[6]  = "--";
                    dr[7]  = "--";
                    dr[8]  = total1.Count;
                    dr[9]  = total2.Count;
                    dr[10] = WebUtility.GetDateTimeFromSec(total1.Sum(a => a.EndTime.Subtract(a.StartTime).TotalSeconds));

                    source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[8].ColumnName)] = total1;
                    source3[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[9].ColumnName)] = total2;
                    source1.Rows.Add(dr);
                }
                #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);
            HttpRuntime.Cache.Insert(cacheKey3, source3, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(source1);
        }
예제 #4
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);
        }
예제 #5
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);
        }
        /// <summary>
        /// Add Data To Cache
        /// </summary>
        private DataTable AddDataToCache() {
            var userData = UserData;
            var cacheKey1 = WebUtility.GetCacheKeyName(userData, "his-alarm-min-interval-source1");
            var cacheKey2 = WebUtility.GetCacheKeyName(userData, "his-alarm-min-interval-source2");
            HttpRuntime.Cache.Remove(cacheKey1);
            HttpRuntime.Cache.Remove(cacheKey2);

            if (String.IsNullOrEmpty(CountItemField.RawValue.ToString())) { return null; }
            var values = WebUtility.StringSplit(CountItemField.RawValue.ToString());
            var beginTime = Convert.ToDateTime(BeginFromDate.Text);
            var endTime = Convert.ToDateTime(BeginToDate.Text);
            var levels = new Dictionary<Int32, String>();
            var len = AlarmLevelMultiCombo.SelectedItems.Count;
            if (len == 0) { return null; }
            for (int i = 0; i < len; i++) {
                var key = Int32.Parse(AlarmLevelMultiCombo.SelectedItems[i].Value);
                var value = AlarmLevelMultiCombo.SelectedItems[i].Text;
                levels[key] = value;
            }

            var interval = MinSpinnerField.Number;
            if (interval == Double.MinValue) { return null; }

            var colcnt = MainGridPanel.ColumnModel.Columns.Count;
            var countType = CountTypeComboBox.SelectedItem.Value;
            var condition = new List<GroupTreeInfo>();
            var source1 = CreateCustomizeTable(colcnt);
            var source2 = new Dictionary<String, List<AlarmInfo>>();
            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 dr1 = source1.NewRow();
                    dr1[1] = lscUser.LscName;

                    var alarms = new BAlarm().GetHisAlarmsMinInterval(lscUser.LscID, lscUser.LscName, userData.StandardProtocol, lscUser.Group.GroupNodes, beginTime, endTime, interval)
                                 .FindAll(a => levels.ContainsKey((Int32)a.AlarmLevel));

                    dr1[2] = alarms.Count;
                    source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[2].ColumnName)] = alarms;
                    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 alarms = new BAlarm().GetHisAlarmsMinInterval(lscUser.LscID, lscUser.LscName, userData.StandardProtocol, lscUser.Group.GroupNodes, beginTime, endTime, interval)
                                 .FindAll(a => levels.ContainsKey((Int32)a.AlarmLevel));

                    var temp0 = from a in alarms
                                group a by new { a.Area2Name } into g
                                select new {
                                    Area2Name = g.Key.Area2Name,
                                    Alarms = g
                                };

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

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

                        var entity = temp0.FirstOrDefault(a => a.Area2Name.Equals(area.Area2Name));
                        var filters = entity == null ? new List<AlarmInfo>() : entity.Alarms.ToList();
                        dr1[3] = filters.Count;
                        source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[3].ColumnName)] = filters;
                        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 alarms = new BAlarm().GetHisAlarmsMinInterval(lscUser.LscID, lscUser.LscName, userData.StandardProtocol, lscUser.Group.GroupNodes, beginTime, endTime, interval)
                                 .FindAll(a => levels.ContainsKey((Int32)a.AlarmLevel));

                    var temp0 = from a in alarms
                                group a by new { a.Area3Name } into g
                                select new {
                                    Area3Name = g.Key.Area3Name,
                                    Alarms = g
                                };

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

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

                        var entity = temp0.FirstOrDefault(a => a.Area3Name.Equals(area.Area3Name));
                        var filters = entity == null ? new List<AlarmInfo>() : entity.Alarms.ToList();
                        dr1[4] = filters.Count;
                        source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[4].ColumnName)] = filters;
                        source1.Rows.Add(dr1);
                    }
                }
                #endregion
            } else if (countType.Equals("3")) {
                #region Station
                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 alarms = new BAlarm().GetHisAlarmsMinInterval(lscUser.LscID, lscUser.LscName, userData.StandardProtocol, lscUser.Group.GroupNodes, beginTime, endTime, interval)
                                 .FindAll(a => levels.ContainsKey((Int32)a.AlarmLevel));

                    var temp0 = from a in alarms
                                group a by new { a.StaName } into g
                                select new {
                                    StaName = g.Key.StaName,
                                    Alarms = g
                                };

                    var stations = from c in condition
                                   join s in new BOther().GetStations(lscUser.LscID, lscUser.Group.GroupID) on new { c.LscID, Area3ID = c.NodeID } equals new { s.LscID, s.Area3ID }
                                   select s;

                    foreach (var sta in stations) {
                        var dr1 = source1.NewRow();
                        dr1[1] = sta.LscName;
                        dr1[2] = sta.Area2Name;
                        dr1[3] = sta.Area3Name;
                        dr1[4] = sta.StaName;

                        var entity = temp0.FirstOrDefault(a => a.StaName.Equals(sta.StaName));
                        var filters = entity == null ? new List<AlarmInfo>() : entity.Alarms.ToList();
                        dr1[5] = filters.Count;
                        source2[String.Format("{0}-{1}", source1.Rows.Count, source1.Columns[5].ColumnName)] = filters;
                        source1.Rows.Add(dr1);
                    }
                }
                #endregion
            }

            var totalStartIndex = colcnt - 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<AlarmInfo>();
                    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;
        }
예제 #7
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);
        }
예제 #8
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);
        }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #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);
        }
예제 #12
0
        /// <summary>
        /// Load User
        /// </summary>
        private void LoadUser(String uid)
        {
            var userEntity = new BUser();
            var loginUser  = new CscUserInfo();

            loginUser.Identifier = Session.SessionID;
            loginUser.Uid        = uid;
            loginUser.Super      = false;
            loginUser.MaxOpLevel = loginUser.Super ? EnmUserLevel.Administrator : EnmUserLevel.Ordinary;
            loginUser.MinOpLevel = EnmUserLevel.Administrator;
            loginUser.LscUsers   = new List <LscUserInfo>();

            var users = userEntity.GetUser(uid, null);

            if (users != null && users.Count > 0)
            {
                users = users.FindAll(u => { return(u.Enabled && u.LimitTime >= DateTime.Now); });
                if (users != null && users.Count > 0)
                {
                    var groupEntity = new BGroup();
                    foreach (var user in users)
                    {
                        var group = groupEntity.GetGroup(user.LscID, user.UserID);
                        if (group != null && group.Enabled)
                        {
                            group.GroupNodes = groupEntity.GetGroupTreeNodes(group.LscID, group.GroupID);
                            user.Group       = group;

                            loginUser.LscUsers.Add(user);
                            if (user.OpLevel > loginUser.MaxOpLevel)
                            {
                                loginUser.MaxOpLevel = user.OpLevel;
                            }
                            if (user.OpLevel < loginUser.MinOpLevel)
                            {
                                loginUser.MinOpLevel = user.OpLevel;
                            }
                        }

                        user.UDGroups = new List <UDGroupInfo>();
                        var udGroups     = groupEntity.GetUDGroups(user.LscID, user.UserID);
                        var udGroupNodes = groupEntity.GetUDGroupTreeNodes(user.LscID, user.UserID);
                        foreach (var udg in udGroups)
                        {
                            if (!udg.Enabled)
                            {
                                continue;
                            }
                            user.UDGroups.Add(udg);
                            udg.UDGroupNodes = udGroupNodes.FindAll(udgn => {
                                return(udgn.UDGroupID == udg.UDGroupID);
                            });
                        }
                    }

                    if (loginUser.LscUsers.Count > 0)
                    {
                        var alarmEntity = new BAlarm();
                        loginUser.StandardProtocol = alarmEntity.GetStandardProtocol();
                        loginUser.SysParams        = userEntity.GetSysParams(WebUtility.DefaultInt32);
                        loginUser.ExpiredTime      = DateTime.Now.AddSeconds(WebUtility.CacheTimeout);

                        var ticket          = new FormsAuthenticationTicket(1, uid, DateTime.Now, DateTime.Now.AddMinutes(WebUtility.FormTimeout), true, loginUser.Identifier);
                        var encryptedTicket = FormsAuthentication.Encrypt(ticket);
                        var authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                        Response.Cookies.Add(authCookie);

                        WebUtility.ClearUserCaches(loginUser.Identifier);
                        WebUtility.UserData.Add(loginUser.Identifier, loginUser);
                        WebUtility.WriteLog(EnmSysLogLevel.Info, EnmSysLogType.Login, loginUser.Super ? "CASP认证登录系统(超级管理员)" : "CASP认证登录系统", uid);
                        Response.Redirect(FormsAuthentication.DefaultUrl);
                    }
                    else
                    {
                        FailureText.InnerText = "错误消息:用户群组无效,请与管理员联系。";
                        ErrorTips.Visible     = true;
                    }
                }
                else
                {
                    FailureText.InnerText = "错误消息:用户已失效,请与管理员联系。";
                    ErrorTips.Visible     = true;
                }
            }
            else
            {
                FailureText.InnerText = "错误消息:用户不存在,登录失败。";
                ErrorTips.Visible     = true;
            }
        }
예제 #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);
        }
예제 #14
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);
        }
예제 #15
0
        private void LoadUser(string uid)
        {
            var userEntity = new BUser();
            var loginUser  = new CscUserInfo();

            loginUser.Identifier = Session.SessionID;
            loginUser.Uid        = uid;
            loginUser.Super      = false;
            loginUser.MaxOpLevel = loginUser.Super ? EnmUserLevel.Administrator : EnmUserLevel.Ordinary;
            loginUser.MinOpLevel = EnmUserLevel.Administrator;
            loginUser.LscUsers   = new List <LscUserInfo>();

            var users = userEntity.GetUser(uid, null);

            if (users != null && users.Count > 0)
            {
                users = users.FindAll(u => { return(u.Enabled && u.LimitTime >= DateTime.Now); });
                if (users != null && users.Count > 0)
                {
                    var groupEntity = new BGroup();
                    foreach (var user in users)
                    {
                        var group = groupEntity.GetGroup(user.LscID, user.UserID);
                        if (group != null && group.Enabled)
                        {
                            group.GroupNodes = groupEntity.GetGroupTreeNodes(group.LscID, group.GroupID);
                            user.Group       = group;

                            loginUser.LscUsers.Add(user);
                            if (user.OpLevel > loginUser.MaxOpLevel)
                            {
                                loginUser.MaxOpLevel = user.OpLevel;
                            }
                            if (user.OpLevel < loginUser.MinOpLevel)
                            {
                                loginUser.MinOpLevel = user.OpLevel;
                            }
                        }

                        user.UDGroups = new List <UDGroupInfo>();
                        var udGroups     = groupEntity.GetUDGroups(user.LscID, user.UserID);
                        var udGroupNodes = groupEntity.GetUDGroupTreeNodes(user.LscID, user.UserID);
                        foreach (var udg in udGroups)
                        {
                            if (!udg.Enabled)
                            {
                                continue;
                            }
                            user.UDGroups.Add(udg);
                            udg.UDGroupNodes = udGroupNodes.FindAll(udgn => {
                                return(udgn.UDGroupID == udg.UDGroupID);
                            });
                        }
                    }

                    if (loginUser.LscUsers.Count > 0)
                    {
                        var alarmEntity = new BAlarm();
                        loginUser.StandardProtocol = alarmEntity.GetStandardProtocol();
                        loginUser.SysParams        = userEntity.GetSysParams(WebUtility.DefaultInt32);
                        loginUser.ExpiredTime      = DateTime.Now.AddSeconds(WebUtility.CacheTimeout);

                        WebUtility.ClearUserCaches(loginUser.Identifier);
                        WebUtility.UserData.Add(loginUser.Identifier, loginUser);
                        WebUtility.WriteLog(EnmSysLogLevel.Info, EnmSysLogType.Login, loginUser.Super ? "SSO认证登录系统(超级管理员)" : "SSO认证登录系统", uid);
                        Response.Redirect(FormsAuthentication.DefaultUrl);
                    }
                    else
                    {
                        throw new Exception("用户群组无效,请与管理员联系。");
                    }
                }
                else
                {
                    throw new Exception("用户已失效,请与管理员联系。");
                }
            }
            else
            {
                throw new Exception("用户不存在,登录失败。");
            }
        }
예제 #16
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);
        }
예제 #17
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);
        }
예제 #18
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);
        }
예제 #19
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);
        }