public static ObservableCollection<ColumnConfig> ConvertToGridData(WidgetModel widgetModel, List<DimensionTypeModel> dimensionsCache, List<MetricTypeModel> metricsCache) { var columnConfigList = new ObservableCollection<ColumnConfig>(); try { #region 设置维度列 if(widgetModel.Dimensions != null) { var dimensions = widgetModel.Dimensions.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach(var dimension in dimensions) { var dimensionx = dimensionsCache.Find(m => m.EnName.ToUpperInvariant() == dimension.ToUpperInvariant() && m.SystemTypeId == (int)SystemTypeEnum.Sponsor); var dd = dimension.Substring(0, 1).ToUpperInvariant() + dimension.Substring(1, dimension.Length - 1); columnConfigList.Add(new ColumnConfig { ColumnName = dd, HeaderName = "数据类型", HeaderDescription = "数据类型", Width = 130, FormatString = dimensionx.Format, HeaderColorString = dimensionx.Color }); } } #endregion #region 设置指标列 var metrics = widgetModel.Metrics.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach(var metric in metrics) { var metricx = metricsCache.Find(m => m.EnName == metric && m.SystemTypeId == widgetModel.SystemTypeId); var mm = metric.Substring(0, 1).ToUpperInvariant() + metric.Substring(1, metric.Length - 1); columnConfigList.Add(new ColumnConfig { ColumnName = mm, HeaderName = metricx.CnName, HeaderDescription = metricx.CnDescription, Width = metricx.CnName.Length * 20, FormatString = metricx.Format, HeaderColorString = metricx.Color }); } #endregion } catch(Exception ex) { ShowMessage.Show("转换表格数据出错"); LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "Failed to ConvertToGridData", ex); } finally { if(LogHelper.LogLevel == LogLevelEnum.Debug || LogHelper.LogLevel == LogLevelEnum.Info) { LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "ConvertToGridData", null); } } return columnConfigList; }
public static List<object> ConvertToChartData(WidgetModel widgetModel, ResultValue resultValue, List<MetricTypeModel> metricsCache) { var datas = new ObservableCollection<string>(); var series = new ObservableCollection<MyReport>(); var axisDic = new Dictionary<string, Tuple<string, string>>(); var values = new List<decimal>(); var metrics = widgetModel.Metrics.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach(var metric in metrics) { var metricX = metricsCache.FirstOrDefault(m => m.SystemTypeId == widgetModel.SystemTypeId && m.EnName == metric); datas.Add(metricX.CnName); axisDic.Add(metric, new Tuple<string, string>(metricX.CnName, "Y")); } #region var label = string.Empty; switch(widgetModel.DataType) { case "1": label = "所有节目"; break; case "2": label = "指定节目"; break; case "3": label = "节目类型"; break; case "4": label = "赞助级别"; break; case "5": label = "电视台"; break; case "6": label = "视频网站自制"; break; case "7": label = "品牌品类"; break; } switch(widgetModel.DateTypeId) { case 5: label += "-本期"; break; case 6: label += "-上期"; break; case 7: label += "-历史"; break; } #endregion var report = new MyReport(); report.Label = label; var data = new ObservableCollection<C1Data>(); Type systemType = typeof(SponsorData); var resultX = JsonConvert.DeserializeObject<SponsorData>(resultValue.Value); foreach(var metric in metrics) { PropertyInfo mPropertyInfo = systemType.GetProperty(metric.Substring(0, 1).ToUpperInvariant() + metric.Substring(1, metric.Length - 1).TrimEnd()); decimal value; if(mPropertyInfo.GetValue(resultX, null) == null) { value = 0; } else { if(mPropertyInfo.GetValue(resultX, null) is int) { value = Convert.ToInt32(mPropertyInfo.GetValue(resultX, null)); } else if(mPropertyInfo.GetValue(resultX, null) is double || mPropertyInfo.GetValue(resultX, null) is decimal) { value = Convert.ToDecimal(mPropertyInfo.GetValue(resultX, null)); } else { value = 0; } } data.Add(new C1Data { Value = value }); values.Add(value); } report.Data = data; series.Add(report); return new List<object> { datas, series, axisDic, values }; }
public void GetParameters() { try { if (WidgetModelEntity == null) { WidgetModelEntity = new WidgetModel(); } WidgetModelEntity.Title = WidgetTitle; WidgetModelEntity.DataCabinId = DataCabinId; WidgetModelEntity.SystemTypeId = (int)SystemTypeEnum.Benchmark; WidgetModelEntity.DisplayType = DisplayType.Type; WidgetModelEntity.DisplayTypeIndex = DisplayType.TypeIndex; WidgetModelEntity.DateTypeId = DateTypeId; WidgetModelEntity.DataType = DataTypeId.ToString(); switch (DataTypeId) { case 1: WidgetModelEntity.Dimensions = "program"; break; case 2: WidgetModelEntity.Dimensions = "program"; break; case 3: WidgetModelEntity.Dimensions = "programType"; break; case 4: WidgetModelEntity.Dimensions = "sponsorLevel"; break; case 5: WidgetModelEntity.Dimensions = "tvStation"; break; case 6: WidgetModelEntity.Dimensions = "videoSet"; break; case 7: WidgetModelEntity.Dimensions = "category1"; break; } WidgetModelEntity.StartDate = StartDate; WidgetModelEntity.EndDate = EndDate; WidgetModelEntity.EnHeader = GetHeader(); switch (DataTypeId) { case (int)BenchmarkTypeEnum.AllProgram: break; case (int)BenchmarkTypeEnum.DesignatedProgram: case (int)BenchmarkTypeEnum.ProgramType: case (int)BenchmarkTypeEnum.SponsorLevel: case (int)BenchmarkTypeEnum.TvStation: case (int)BenchmarkTypeEnum.VideoSite: WidgetModelEntity.Filter = SelectedCategory; break; case (int)BenchmarkTypeEnum.BrandType: WidgetModelEntity.Filter = SelectedCategorys1 + "*" + SelectedCategorys2; break; } _metricString = string.Empty; foreach (var metricItem in MetricItemsSource) { foreach (var metric in metricItem.Items) { if (metric.IsChecked) { if (string.IsNullOrEmpty(_metricString)) { _metricString = metric.EnName; } else { _metricString += "," + metric.EnName; } } } } WidgetModelEntity.Metrics = _metricString; } catch (Exception ex) { ShowMessage.Show("整理参数出错"); LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "Failed to GetParameters", ex); } finally { if (LogHelper.LogLevel == LogLevelEnum.Debug || LogHelper.LogLevel == LogLevelEnum.Info) { LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "GetParameters", null); } } }