private void InitDefaultOrderItem()
        {
            InitOrderItems();

            _orderRulesX = new ObservableCollection<ResultValue>();
            _orderRulesX.Add(new ResultValue { Key = "0", Value = "升序" });
            _orderRulesX.Add(new ResultValue { Key = "1", Value = "降序" });

            DataOrderItem = new DataOrderItem { OrderNames = _orderDatasX, OrderRules = _orderRulesX };
        }
 /// <summary>
 /// 删除过滤
 /// </summary>
 /// <param name="dataOrderItem"></param>
 public void DeleteDataFilter(DataOrderItem dataOrderItem)
 {
     try
     {
         DataOrderItems.Remove(dataOrderItem);
         if (DataOrderItems.Count == 0)
         {
             DataOrderItems.Add(new DataOrderItem { OrderNames = _orderDatasX, OrderRules = _orderRulesX });
         }
     }
     catch (Exception ex)
     {
         ShowMessage.Show("删除过滤出错");
         LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "Failed to DeleteDataFilter", ex);
     }
     finally
     {
         if (LogHelper.LogLevel == LogLevelEnum.Debug || LogHelper.LogLevel == LogLevelEnum.Info)
         {
             LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "DeleteDataFilter", null);
         }
     }
 }
        /// <summary>
        /// 系统类型改变事件
        /// </summary>
        public async void SystemTypeChanged()
        {
            try
            {
                #region 控制显示性

                switch (SystemType.Id)
                {
                    case (int)SystemTypeEnum.SiteAnalysisReport:
                        break;
                    case (int)SystemTypeEnum.SiteDataBank:
                        break;
                    case (int)SystemTypeEnum.SiteRealtime:
                        TimeDimensionVisibility = Visibility.Collapsed;
                        TimeVisibility = Visibility.Collapsed;
                        IgrpCityVisibility = Visibility.Collapsed;
                        SiteVisibility = Visibility.Collapsed;
                        DimensionVisibility = Visibility.Collapsed;
                        MetricVisibility = Visibility.Collapsed;
                        DataTypeVisibility = Visibility.Visible;
                        break;
                    case (int)SystemTypeEnum.Sponsor:
                        TimeDimensionVisibility = Visibility.Visible;
                        TimeVisibility = Visibility.Visible;
                        IgrpCityVisibility = Visibility.Collapsed;
                        SiteVisibility = Visibility.Collapsed;
                        DimensionVisibility = Visibility.Visible;
                        MetricVisibility = Visibility.Visible;
                        DataTypeVisibility = Visibility.Collapsed;
                        break;
                    case (int)SystemTypeEnum.TrackAnalysisReport:
                        TimeDimensionVisibility = Visibility.Visible;
                        TimeVisibility = Visibility.Visible;
                        IgrpCityVisibility = Visibility.Collapsed;
                        SiteVisibility = Visibility.Collapsed;
                        DimensionVisibility = Visibility.Visible;
                        MetricVisibility = Visibility.Visible;
                        DataTypeVisibility = Visibility.Collapsed;
                        break;
                    case (int)SystemTypeEnum.TrackDataBank:
                        break;
                    case (int)SystemTypeEnum.TrackRealtime:
                        TimeDimensionVisibility = Visibility.Visible;
                        TimeVisibility = Visibility.Hidden;
                        IgrpCityVisibility = Visibility.Collapsed;
                        SiteVisibility = Visibility.Collapsed;
                        DimensionVisibility = Visibility.Visible;
                        MetricVisibility = Visibility.Visible;
                        DataTypeVisibility = Visibility.Collapsed;
                        break;
                }

                #endregion

                #region 清空数据

                ProgramItems = new ObservableCollection<Node>();
                ProgramString = string.Empty;
                TimeDimensionTypeList = new ObservableCollection<TimeDimensionTypeModel>();
                DimensionItemsSource = new ObservableCollection<CheckBoxTab>();
                DataTypeItemsSource = new ObservableCollection<CheckBoxTab>();
                MetricItemsSource = new ObservableCollection<CheckBoxTab>();
                _selectedTimeDimensions = new List<TimeDimensionTypeModel>();
                _selectedDimensions = new List<DimensionTypeModel>();
                _selectedMetrics = new List<MetricTypeModel>();
                DisplayType = DisplayTypeList.FirstOrDefault();
                foreach (var displayTypeModel in DisplayTypeList)
                {
                    displayTypeModel.IsEnabled = true;
                }

                DataOrderItems.Clear();

                #endregion

                #region 查询数据表

                var system = SystemDataBuilder.SystemBuilder(SystemType.Id);
                var parameterDictionary = new Dictionary<string, object>();
                parameterDictionary.Add("SystemTypeId", SystemType.Id);
                parameterDictionary.Add("ClientId", ClientId);
                parameterDictionary.Add("UserId", User.UserInfo.Id);
                var items = await system.GetTableSource(parameterDictionary);
                ProgramItems = items;

                #endregion

                #region 查询时间粒度,维度,指标

                var result = await WidgetService.GetDataBySystemType(SystemType.Id);
                if (result != null)
                {
                    var baseDataDic = result.Data.ToDictionary(d => d.Key, d => d.Value);

                    if (SystemType.Id == (int)SystemTypeEnum.SiteRealtime)
                    {
                        var dataTypeHeaderString = baseDataDic["DataTypeHeaderList"];
                        var dataTypeListString = baseDataDic["DataTypeList"];
                        InitDataType(dataTypeHeaderString, dataTypeListString);
                    }
                    else
                    {
                        switch (SystemType.Id)
                        {
                            case (int)SystemTypeEnum.TrackRealtime:
                                SetDisplayTypeEnabled(_trackRealtimeDisplayType);
                                break;
                            case (int)SystemTypeEnum.Sponsor:
                            case (int)SystemTypeEnum.TrackAnalysisReport:
                                var dateTypeListString = baseDataDic["DateTypeList"];
                                InitDateTypeList(dateTypeListString);
                                break;
                        }

                        var timeDimensionTypeListString = baseDataDic["TimeDimensionTypeList"];
                        var dimensionHeaderString = baseDataDic["DimensionHeaderList"];
                        var dimensionTypeListString = baseDataDic["DimensionTypeList"];
                        var metricHeaderList = baseDataDic["MetricHeaderList"];
                        var metricTypeListString = baseDataDic["MetricTypeList"];
                        InitTimeDimension(timeDimensionTypeListString);
                        InitDimension(dimensionHeaderString, dimensionTypeListString);
                        InitMetric(metricHeaderList, metricTypeListString);
                    }

                    #region 赋值

                    if (WidgetModelEntity != null && WidgetModelEntity.Id != 0 && WidgetModelEntity.SystemTypeId == SystemType.Id)
                    {
                        ProgramString = WidgetModelEntity.TableName;
                        SetDisplayType();

                        if (WidgetModelEntity.SystemTypeId == (int)SystemTypeEnum.SiteRealtime)
                        {
                            #region 设置数据类型

                            switch (WidgetModelEntity.EnHeader)
                            {
                                case "online":
                                    DataTypeTabSelectedIndex = 0;
                                    break;
                                case "statistics":
                                    DataTypeTabSelectedIndex = 1;
                                    break;
                                case "transform":
                                    DataTypeTabSelectedIndex = 2;
                                    break;
                            }
                            _dataType = WidgetModelEntity.DataType;
                            var selectedDataType = DataTypeCache.Find(d => d.EnName == _dataType && d.SystemTypeId == WidgetModelEntity.SystemTypeId);
                            if (selectedDataType != null)
                            {
                                foreach (var dataType in DataTypeItemsSource[DataTypeTabSelectedIndex].Items)
                                {
                                    if (_dataType == dataType.EnName)
                                    {
                                        dataType.IsChecked = true;
                                        break;
                                    }
                                }
                            }

                            _dataTypeCount = 1;

                            #endregion
                        }
                        else
                        {
                            #region 设置时间维度

                            var timeDimensionsx = WidgetModelEntity.TimeDimensions.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (var timeDimensionx in timeDimensionsx)
                            {
                                var selectedTimeDimensionx = TimeDimensionsCache.Find(t => t.EnName == timeDimensionx && t.SystemTypeId == WidgetModelEntity.SystemTypeId);
                                if (selectedTimeDimensionx != null)
                                {
                                    _selectedTimeDimensions.Add(selectedTimeDimensionx);
                                }
                            }

                            var timeDimensionList = TimeDimensionTypeList.Where(t => WidgetModelEntity.TimeDimensions.Contains(t.EnName));
                            foreach (var timeDimension in timeDimensionList)
                            {
                                timeDimension.IsChecked = true;
                            }

                            #endregion

                            if (WidgetModelEntity.SystemTypeId != (int)SystemTypeEnum.Sponsor)
                            {
                                for (int i = 0; i < DimensionItemsSource.Count; i++)
                                {
                                    if (DimensionItemsSource[i].Header.EnHeader == WidgetModelEntity.EnHeader)
                                    {
                                        DimensionTabSelectedIndex = MetricTabSelectedIndex = i;
                                    }
                                }
                            }

                            #region 设置维度

                            _dimensionString = WidgetModelEntity.Dimensions;
                            var dimensionsx = WidgetModelEntity.Dimensions.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (var dimensionx in dimensionsx)
                            {
                                var selectedDimensionx = DimensionsCache.Find(d => d.EnName == dimensionx && d.SystemTypeId == WidgetModelEntity.SystemTypeId && (d.EnHeader == WidgetModelEntity.EnHeader || d.EnHeader == "ALL"));
                                if (selectedDimensionx != null)
                                {
                                    _selectedDimensions.Add(selectedDimensionx);
                                }
                            }

                            var dimensionXX = WidgetModelEntity.Dimensions.Split(',');
                            foreach (var dimensionItems in DimensionItemsSource)
                            {
                                if (dimensionItems.Header.EnHeader == WidgetModelEntity.EnHeader || dimensionItems.Header.EnHeader == "ALL")
                                {
                                    foreach (var dimension in dimensionItems.Items)
                                    {
                                        if (dimensionXX.Contains(dimension.EnName))
                                        {
                                            dimension.IsChecked = true;
                                        }
                                    }
                                }
                            }

                            #endregion

                            #region 设置指标

                            _metricString = WidgetModelEntity.Metrics;
                            var metricsx = WidgetModelEntity.Metrics.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            if (WidgetModelEntity.SystemTypeId == (int)SystemTypeEnum.Sponsor)
                            {
                                foreach (var metricx in metricsx)
                                {
                                    var selectedMetricx = MetricsCache.Find(m => m.EnName == metricx && m.SystemTypeId == WidgetModelEntity.SystemTypeId);
                                    if (selectedMetricx != null)
                                    {
                                        _selectedMetrics.Add(selectedMetricx);
                                    }
                                }
                            }
                            else
                            {
                                foreach (var metricx in metricsx)
                                {
                                    var selectedMetricx = MetricsCache.Find(m => m.EnName == metricx && m.SystemTypeId == WidgetModelEntity.SystemTypeId && (m.EnHeader == WidgetModelEntity.EnHeader || m.EnHeader == "ALL"));
                                    if (selectedMetricx != null)
                                    {
                                        _selectedMetrics.Add(selectedMetricx);
                                    }
                                }
                            }

                            var metricsXX = WidgetModelEntity.Metrics.Split(',');
                            if (WidgetModelEntity.SystemTypeId == (int)SystemTypeEnum.Sponsor)
                            {
                                foreach (var metricItems in MetricItemsSource)
                                {
                                    foreach (var metric in metricItems.Items)
                                    {
                                        if (metricsXX.Contains(metric.EnName))
                                        {
                                            metric.IsChecked = true;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                foreach (var metricItems in MetricItemsSource)
                                {
                                    if (metricItems.Header.EnHeader == WidgetModelEntity.EnHeader || metricItems.Header.EnHeader == "ALL")
                                    {
                                        foreach (var metric in metricItems.Items)
                                        {
                                            if (metricsXX.Contains(metric.EnName))
                                            {
                                                metric.IsChecked = true;
                                            }
                                        }
                                    }
                                }
                            }

                            #endregion

                            if (WidgetModelEntity.SystemTypeId != (int)SystemTypeEnum.TrackRealtime)
                            {
                                StartDate = WidgetModelEntity.StartDate;
                                EndDate = WidgetModelEntity.EndDate;
                            }
                            else if (WidgetModelEntity.SystemTypeId == (int)SystemTypeEnum.TrackAnalysisReport)
                            {
                                switch (DimensionItemsSource[DimensionTabSelectedIndex].Header.EnHeader)
                                {
                                    case "igrp":
                                        IgrpCityVisibility = Visibility.Visible;
                                        SiteVisibility = Visibility.Collapsed;
                                        break;
                                    case "integrate":
                                        IgrpCityVisibility = Visibility.Collapsed;
                                        SiteVisibility = Visibility.Visible;
                                        break;
                                    default:
                                        IgrpCityVisibility = Visibility.Collapsed;
                                        SiteVisibility = Visibility.Collapsed;
                                        break;
                                }
                            }
                        }

                        SetDisplayType();

                        #region 设置显示类型

                        var displayType = DisplayTypeList.FirstOrDefault(d => d.Type == WidgetModelEntity.DisplayType && d.TypeIndex == WidgetModelEntity.DisplayTypeIndex);
                        DisplayType = displayType;

                        #endregion

                        DataCount = WidgetModelEntity.DataCount;

                        #region 排序

                        var dataOrderBys = WidgetModelEntity.DataOrderBy == null ? null : WidgetModelEntity.DataOrderBy.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        var orderNames = new ObservableCollection<ResultValue>();

                        if (!string.IsNullOrEmpty(WidgetModelEntity.TimeDimensions))
                        {
                            var timeDimensions = WidgetModelEntity.TimeDimensions.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            for (var i = 0; i < timeDimensions.Count(); i++)
                            {
                                var timeDimension = TimeDimensionsCache.Find(t => t.EnName == timeDimensions[i]);
                                if (timeDimension != null)
                                {
                                    orderNames.Add(new ResultValue
                                    {
                                        Key = timeDimensions[i],
                                        Value = timeDimension.CnName
                                    });
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(WidgetModelEntity.Dimensions))
                        {
                            var dimensions = WidgetModelEntity.Dimensions.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            for (var i = 0; i < dimensions.Count(); i++)
                            {
                                var dimension = DimensionsCache.Find(d => d.EnName == dimensions[i]);
                                if (dimension != null)
                                {
                                    orderNames.Add(new ResultValue
                                    {
                                        Key = dimensions[i],
                                        Value = dimension.CnName
                                    });
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(WidgetModelEntity.Metrics))
                        {
                            var metrics = WidgetModelEntity.Metrics.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            for (var i = 0; i < metrics.Count(); i++)
                            {
                                var metric = MetricsCache.Find(m => m.EnName == metrics[i]);
                                if (metric != null)
                                {
                                    orderNames.Add(new ResultValue
                                    {
                                        Key = metrics[i],
                                        Value = metric.CnName
                                    });
                                }
                            }
                        }

                        _orderRulesX = new ObservableCollection<ResultValue>();
                        _orderRulesX.Add(new ResultValue { Key = "0", Value = "升序" });
                        _orderRulesX.Add(new ResultValue { Key = "1", Value = "降序" });

                        

                        if (dataOrderBys != null)
                        {
                            foreach (var dataOrderBy in dataOrderBys)
                            {
                                var dataOrders = dataOrderBy.Split(new[] { "*" }, StringSplitOptions.RemoveEmptyEntries);
                                var dataOrderItem = new DataOrderItem();
                                dataOrderItem.OrderName = dataOrders[0];
                                dataOrderItem.OrderNames = orderNames;
                                dataOrderItem.OrderRule = dataOrders[1];
                                dataOrderItem.OrderRules = _orderRulesX;
                                DataOrderItems.Add(dataOrderItem);
                            }
                        }

                        #endregion
                    }

                    #endregion
                }

                #endregion
            }
            catch (Exception ex)
            {
                ShowMessage.Show("系统类型改变出错");
                LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "Failed to SystemTypeChanged", ex);
            }
            finally
            {
                if (LogHelper.LogLevel == LogLevelEnum.Debug || LogHelper.LogLevel == LogLevelEnum.Info)
                {
                    LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "SystemTypeChanged", null);
                }
            }
        }