Beispiel #1
0
        /// <summary>
        /// Add data to cache.
        /// </summary>
        private List <Report006Entity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "kpi-report-006");

            HttpRuntime.Cache.Remove(cacheKey);

            var lscIds = new List <int>();

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

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

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

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

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

            if (result.Count > 0)
            {
                result.Add(new Report006Entity {
                    LscID     = -100,
                    LscName   = "汇总(平均值)",
                    ThisCount = (Int32)result.Average(r => r.ThisCount),
                    LastCount = (Int32)result.Average(r => r.LastCount)
                });
            }

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

            HttpRuntime.Cache.Insert(cacheKey, result, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Add Data To Cache
        /// </summary>
        private DataTable AddDataToCache()
        {
            try {
                var userData  = UserData;
                var cacheKey1 = WebUtility.GetCacheKeyName(userData, "station-count-source1");
                var cacheKey2 = WebUtility.GetCacheKeyName(userData, "station-count-source2");
                HttpRuntime.Cache.Remove(cacheKey1);
                HttpRuntime.Cache.Remove(cacheKey2);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                var cacheDuration = Int32.Parse(WebConfigurationManager.AppSettings["DefaultCacheDuration"]);
                HttpRuntime.Cache.Insert(cacheKey1, source1, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
                HttpRuntime.Cache.Insert(cacheKey2, source2, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(cacheDuration), CacheItemPriority.Default, null);
                return(source1);
            } catch { throw; }
        }
Beispiel #3
0
        /// <summary>
        /// Add Data To Cache
        /// </summary>
        private List <ProjectReportPageEntity> AddDataToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "project-report-entities");

            HttpRuntime.Cache.Remove(cacheKey);

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

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

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

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

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

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

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

            appointments1.AddRange(appointments2);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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