void sv_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (_historyView == null)
            {
                _historyView = CollectionViewSource.GetDefaultView(History);
            }
            ServiceView        sv     = (ServiceView)sender;
            Predicate <object> filter = new Predicate <object>(sv.FilterByServiceName);

            if (sv.Show)
            {
                RemoveFilter(filter);
            }
            else
            {
                AddFilter(filter);
            }
            _historyView.Filter = Filter;
        }
        public void LoadHistory()
        {
            if (_filters != null)
            {
                _filters.Clear();
            }
            if (_historyViewRef != null)
            {
                _historyViewRef.Clear();
            }
            if (History != null)
            {
                History.Clear();
            }
            using (SqlConnection conn = new SqlConnection(AppSettings.GetConnectionString(this, "History")))
            {
                conn.Open();
                {
                    SqlCommand command = DataManager.CreateCommand(@"SELECT InstanceID,AccountID,ParentInstanceID,ServiceName,TimeScheduled,TimeStarted,TimeEnded,Configuration.value('data(/ActiveService/@TargetPeriod)[1]','nvarchar(255)') as TargetPeriod,Outcome,State
																    FROM ServiceInstance
																    WHERE TimeStarted BETWEEN @Form:DateTime AND @To:DateTime"                                                                , CommandType.Text);
                    command.Parameters["@Form"].Value = Times.From;
                    command.Parameters["@To"].Value   = Times.To;
                    command.Connection = conn;
                    List <ServiceHistoryView> childs = new List <ServiceHistoryView>();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            ServiceHistoryView hv = new ServiceHistoryView();
                            hv.InstanceID       = Convert.ToInt32(reader["InstanceID"]);
                            hv.AccountID        = Convert.ToInt32(reader["AccountID"]);
                            hv.ParentInstanceID = reader["ParentInstanceID"] == DBNull.Value ? null : (int?)Convert.ToInt32(reader["ParentInstanceID"]);
                            hv.ServiceName      = reader["ServiceName"].ToString();
                            hv.TimeScheduled    = reader["TimeScheduled"].ToString();
                            hv.TimeStarted      = reader["TimeStarted"].ToString();
                            hv.TimeEnded        = reader["TimeEnded"].ToString();
                            hv.TargetPeriod     = FormatTargetPeriodFromJson(reader["TargetPeriod"].ToString());
                            hv.Outcome          = (Core.Services.ServiceOutcome)Enum.Parse(typeof(Core.Services.ServiceOutcome), (reader["Outcome"].ToString()));
                            hv.State            = (Core.Services.ServiceState)Enum.Parse(typeof(Core.Services.ServiceState), (reader["State"].ToString()));
                            if (hv.ParentInstanceID.HasValue)
                            {
                                childs.Add(hv);
                            }
                            else
                            {
                                History.Add(hv);
                            }
                            if (!_historyViewRef.ContainsKey(hv.InstanceID.Value))
                            {
                                _historyViewRef.Add(hv.InstanceID.Value, hv);
                            }
                            if (!_accountsDic.ContainsKey(hv.AccountID))
                            {
                                _accountsDic.Add(hv.AccountID, hv.AccountID);
                                if (Accounts == null)
                                {
                                    Accounts = new ObservableCollection <AccountView>();
                                }
                                AccountView av = new AccountView()
                                {
                                    AccountID = hv.AccountID, Show = true
                                };
                                av.PropertyChanged += new PropertyChangedEventHandler(accountView_PropertyChanged);
                                Accounts.Add(av);
                            }
                            if (!ServicesDic.ContainsKey(hv.ServiceName) && !hv.ParentInstanceID.HasValue)
                            {
                                ServicesDic.Add(hv.ServiceName, hv.ServiceName);
                                if (Services == null)
                                {
                                    Services = new ObservableCollection <ServiceView>();
                                }
                                ServiceView sv = new ServiceView()
                                {
                                    ServiceName = hv.ServiceName, Show = true
                                };
                                sv.PropertyChanged += new PropertyChangedEventHandler(sv_PropertyChanged);
                                Services.Add(sv);
                            }
                        }
                    }
                    foreach (var child in childs)
                    {
                        if (_historyViewRef.ContainsKey(child.ParentInstanceID.Value))
                        {
                            _historyViewRef[child.ParentInstanceID.Value].ChildsHistoryView.Add(child);
                        }
                    }
                }
            }
        }