private static IDictionary<string, object> GetFieldValues(IInfoClass item, IEnumerable<string> resultColumns) { return resultColumns.ToDictionary(columnName => columnName, columnName => (object)item.GetValueByPropertyName(columnName)); }
private static object FormatImageColumn(IInfoClass infoItem, ColumnMetadata column) { var bytes = infoItem.GetValueByPropertyName(column.SystemName) as byte[]; if (bytes != null && bytes.Length > 0) { var width = column.ImageWidth ?? Constants.DefaultImageWidthOnSearch; var height = column.ImageHeight ?? Constants.DefaultImageHeightOnSearch; bytes = Utils.ResizeImage(bytes, width, height); } return bytes; }
private object FormatBackcolorColumn(IInfoClass infoItem, ColumnMetadata column) { var argb = (long)infoItem.GetValueByPropertyName(column.SystemName); if (argb == 0) { // 0 represents no color. return null; } return ColorTranslator.ToHtml(argb); }
private static object FormatApprovalColumn(IInfoClass infoItem, ColumnMetadata column) { var approvalState = ApprovalStates.NotReadyForApproval; var propertyValue = (string)infoItem.GetValueByPropertyName(column.SystemName); if (!string.IsNullOrEmpty(propertyValue)) { approvalState = (ApprovalStates)Enum.Parse(typeof(ApprovalStates), propertyValue); } return approvalState.GetDisplayName(); }
private object FormatColumn(IInfoClass infoItem, ColumnMetadata column) { switch (column.ColumnType) { case ColumnTypes.Approval: return FormatApprovalColumn(infoItem, column); case ColumnTypes.FieldBackcolor: return FormatBackcolorColumn(infoItem, column); case ColumnTypes.Image: return FormatImageColumn(infoItem, column); default: return infoItem.GetValueByPropertyName(column.SystemName); } }
private void ElementExporting(object sender, GridViewElementExportingEventArgs e) { var bHtml = (TheExportOptionsViewModel.Value.ExportFileType != ExportFileType.ExcelML && TheExportOptionsViewModel.Value.ExportFileType != ExportFileType.Csv); if (!bHtml) return; switch (e.Element) { case ExportElement.HeaderRow: if (TheExportOptionsViewModel.Value.ExportFileType == ExportFileType.Pdf) { if (TheExportOptionsViewModel.Value.HeaderBackground.HasValue) ((GridViewHtmlVisualExportParameters)e.VisualParameters).Styles.Add("background-color", TheExportOptionsViewModel.Value.HeaderBackground.Value.ToString().Remove(1, 2)); } else { ((GridViewHtmlVisualExportParameters)e.VisualParameters).Background = TheExportOptionsViewModel.Value.HeaderBackground; } ((GridViewHtmlVisualExportParameters)e.VisualParameters).FontSize = 20; ((GridViewHtmlVisualExportParameters)e.VisualParameters).FontWeight = FontWeights.Bold; break; case ExportElement.HeaderCell: ((GridViewHtmlVisualExportParameters)e.VisualParameters).Foreground = TheExportOptionsViewModel.Value.HeaderForeground; ((GridViewHtmlVisualExportParameters)e.VisualParameters).Height = 20; break; case ExportElement.Row: _row = (IInfoClass)e.Value; if (TheExportOptionsViewModel.Value.ExportFileType == ExportFileType.Pdf) { if (TheExportOptionsViewModel.Value.RowBackground.HasValue) ((GridViewHtmlVisualExportParameters)e.VisualParameters).Styles.Add("background-color", TheExportOptionsViewModel.Value.RowBackground.Value.ToString().Remove(1, 2)); } else { ((GridViewHtmlVisualExportParameters)e.VisualParameters).Background = TheExportOptionsViewModel.Value.RowBackground; } break; case ExportElement.GroupHeaderRow: ((GridViewHtmlVisualExportParameters)e.VisualParameters).FontFamily = new FontFamily("Arial Unicode MS"); ((GridViewHtmlVisualExportParameters)e.VisualParameters).Background = Colors.LightGray; ((GridViewHtmlVisualExportParameters)e.VisualParameters).Height = 30; var qcvGroup = e.Value as QueryableCollectionViewGroup; if (qcvGroup != null) e.Value = string.Format(CultureInfo.InvariantCulture, "{0} Items", qcvGroup.Items.Count); break; case ExportElement.GroupFooterRow: case ExportElement.FooterRow: if (TheExportOptionsViewModel.Value.ExportFileType == ExportFileType.Pdf) ((GridViewHtmlVisualExportParameters)e.VisualParameters).Styles.Add("background-color", Colors.LightGray.ToString().Remove(1, 2)); else ((GridViewHtmlVisualExportParameters)e.VisualParameters).Background = Colors.LightGray; break; case ExportElement.Cell: if (_accessDeniedProperties.Any(x => x == ((GridViewColumn)e.Context).UniqueName)) { e.Value = "<Blocked>"; ((GridViewHtmlVisualExportParameters)e.VisualParameters).Foreground = Colors.Red; break; } if (e.Value is string && (string)e.Value == "<Rich Text>") { ((GridViewHtmlVisualExportParameters)e.VisualParameters).Foreground = Colors.Blue; break; } if (e.Value is byte[]) { e.Value = "binary data"; } var propertyName = ((GridViewDataColumn)e.Context).UniqueName + Constants.FieldBackColorPostfix; var value = _row.GetValueByPropertyName(propertyName); if (value is long) { var color = ((long)value); if (color != 0) { ((GridViewHtmlVisualExportParameters)e.VisualParameters).Background = ((long)value).ToColor(); } } ((GridViewHtmlVisualExportParameters)e.VisualParameters).Foreground = TheExportOptionsViewModel.Value.RowForeground; break; case ExportElement.GroupFooterCell: if (e.Value == null) return; var qcvg = e.Value as QueryableCollectionViewGroup; if (qcvg != null) { var resultList = new List<string>(); foreach (var aggr in qcvg.AggregateResults) { if (aggr.FunctionName.StartsWith(((GridViewColumn)e.Context).UniqueName, StringComparison.Ordinal)) { resultList.Add(string.Format(CultureInfo.InvariantCulture, "{0} {1}", aggr.Caption, aggr.Value)); } } e.Value = string.Join(", ", resultList); } break; case ExportElement.FooterCell: if (e.Value == null) return; var result = new List<string>(); var array = ((string)e.Value).Split(','); for (byte i = 0; i < ((GridViewColumn)e.Context).AggregateFunctions.Count; i++) result.Add(string.Format(CultureInfo.InvariantCulture, "{0} {1}", ((GridViewColumn)e.Context).AggregateFunctions[i].Caption, array[i])); e.Value = string.Join(", ", result); break; } }