Ejemplo n.º 1
0
        /// <summary>
        /// Add Events To Cache
        /// </summary>
        /// <returns>Operating Events</returns>
        private List <AcEventInfo> AddEventsToCache()
        {
            var userData = UserData;
            var cacheKey = WebUtility.GetCacheKeyName(userData, "netking-events");

            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 types = new Dictionary <Int32, String>();

            foreach (var dt in EventTypeMultiCombo.SelectedItems)
            {
                types[Int32.Parse(dt.Value)] = dt.Text;
            }

            var ctype    = Convert.ToInt32(CountTypeComboBox.SelectedItem.Value);
            var fromTime = DateTime.Parse(FromDate.Text);
            var toTime   = DateTime.Parse(ToDate.Text);

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

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

                List <AcEventInfo> temp = null;
                switch (ctype)
                {
                case 0:
                    temp = otherEntity.GetPubAlertEvent(lsc.LscID, lsc.LscName, WebUtility.CreateLscConnectionString(lsc), fromTime, toTime);
                    break;

                case 1:
                    temp = otherEntity.GetPubGeneralEvent(lsc.LscID, lsc.LscName, WebUtility.CreateLscConnectionString(lsc), fromTime, toTime);
                    break;

                case 2:
                    temp = otherEntity.GetPubInvalidCardEvent(lsc.LscID, lsc.LscName, WebUtility.CreateLscConnectionString(lsc), fromTime, toTime);
                    break;

                case 3:
                    temp = otherEntity.GetPubValidCardEvent(lsc.LscID, lsc.LscName, WebUtility.CreateLscConnectionString(lsc), fromTime, toTime);
                    break;

                default:
                    break;
                }

                if (temp != null)
                {
                    if (types.Count > 0)
                    {
                        temp = temp.FindAll(t => types.ContainsKey(t.MessageID));
                    }

                    result.AddRange(temp);
                }
            }

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

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