/// <summary> /// Compares 2 cells arrays /// </summary> public static int CompareCellsForTableLoad(ResultCell[] a, ResultCell[] b) { if (a.Length == 0 || a.Length != b.Length) { return(0); } ReportModel model = null; int i = a.Length; while (--i >= 0 && model == null) { if (a[i].Element != null) { model = a[i].Element.Model; } } ReportElement element = model.Elements.FirstOrDefault(j => j.FinalSortOrder.Contains(" ")); if (element != null) { var sortIndex = int.Parse(element.FinalSortOrder.Split(' ')[0]); if (sortIndex < a.Length) { ResultCell aCell = a[sortIndex]; ResultCell bCell = b[sortIndex]; int result = CompareCell(aCell, bCell); if (result != 0) { return((element.FinalSortOrder.Contains(ReportElement.kAscendantSortKeyword) ? 1 : -1) * result); } } } return(0); }
/// <summary> /// Compares 2 ResultSerie objects /// </summary> public static int CompareSeries(ResultSerie a, ResultSerie b) { if (a.SplitterCells == null || b.SplitterCells == null) { return(0); } return(ResultCell.CompareCells(a.SplitterCells, b.SplitterCells)); }
/// <summary> /// Compares 2 cells /// </summary> public static int CompareCell(ResultCell a, ResultCell b) { if (a.Value == DBNull.Value && b.Value == DBNull.Value) { return(0); } else if (a.Value == DBNull.Value && b.Value != null) { return(-1); } else if (a.Value != null && b.Value == DBNull.Value) { return(1); } if (a.Element == null && b.Element == null) { return(0); } else if (a.Element == null && b.Element != null) { return(-1); } else if (a.Element != null && b.Element == null) { return(1); } if (a.Element.IsEnum) { return(a.Element.GetEnumSortValue(a.Value.ToString(), true).CompareTo(b.Element.GetEnumSortValue(b.Value.ToString(), true))); } else if (a.Element.IsText) { return(a.Value.ToString().CompareTo(b.Value.ToString())); } else if (a.Element.IsDateTime) { if (a.DateTimeValue == b.DateTimeValue) { return(0); } return(a.DateTimeValue > b.DateTimeValue ? 1 : -1); } else if (a.Element.IsNumeric) { if (a.DoubleValue == b.DoubleValue) { return(0); } return(a.DoubleValue > b.DoubleValue ? 1 : -1); } return(0); }
/// <summary> /// Returns the column number from the element column name. -1 if not found. /// </summary> public int GetCol(string elementName) { int result = -1; for (int col = 0; col < ColumnCount && RowCount > 0; col++) { ResultCell cell = this[0, col]; if (cell != null) { if (cell.Element.MetaColumn.ColumnName == elementName) { result = col; break; } } } return(result); }
int IComparer <ResultSerie> .Compare(ResultSerie x, ResultSerie y) { //Priority to element sort order if (x.Element != y.Element) { if (x.Element.FinalSort > y.Element.FinalSort) { return(1); } else if (x.Element.FinalSort < y.Element.FinalSort) { return(-1); } return(0); } else { //Then by splitter values descending or ascending return(ResultCell.CompareCells(x.SplitterCells, y.SplitterCells)); } }
public static int CompareCells(ResultCell[] a, ResultCell[] b) { if (a.Length == 0 || a.Length != b.Length) { return(0); } ReportModel model = a[0].Element.Model; foreach (ReportElement element in model.Elements.Where(i => !string.IsNullOrEmpty(i.FinalSortOrder)).OrderBy(i => i.FinalSortOrder)) { ResultCell aCell = a.FirstOrDefault(i => i.Element == element); ResultCell bCell = b.FirstOrDefault(i => i.Element == element); if (aCell != null && bCell != null) { int result = CompareCell(aCell, bCell); if (result != 0) { return((element.FinalSortOrder.Contains(SortOrderConverter.kAscendantSortKeyword) ? 1 : -1) * result); } } } return(0); }
private int CompareXDimensionsWithAxis(ResultCell[] a, ResultCell[] b) { return((_serieForSort.Element.SerieSortOrder == PointSortOrder.Ascending ? 1 : -1) * ResultCell.CompareCells(a, b)); }
private void buildTotals(ReportModel model) { var colTotalElements = model.GetElements(PivotPosition.Data).Where(e => e.ShowTotal == ShowTotal.Column || e.ShowTotal == ShowTotal.RowColumn || e.CalculationOption == CalculationOption.PercentageColumn); var rowTotalElements = model.GetElements(PivotPosition.Data).Where(e => e.ShowTotal == ShowTotal.Row || e.ShowTotal == ShowTotal.RowColumn || e.CalculationOption == CalculationOption.PercentageRow || e.CalculationOption == CalculationOption.PercentageAll); var totalElements = colTotalElements.Union(rowTotalElements); Dictionary<string, string> compilationKeys = new Dictionary<string, string>(); foreach (ResultPage page in model.Pages) { if (Report.Cancel) break; //First calculate the total of total cells for each element page.DataTable.TotalCells = new List<ResultTotalCell>(); foreach (var element in totalElements) { ResultTotalCell totalTotalCell = new ResultTotalCell() { Element = element, IsTotal = true, IsTotalTotal = true }; foreach (var rowLine in page.DataTable.Lines) { foreach (var cell in rowLine.Where(i => i.Element == element && !i.IsTitle && !i.IsTotal)) { totalTotalCell.Cells.Add(cell); } } totalTotalCell.Calculate(); page.DataTable.TotalCells.Add(totalTotalCell); } //Totals per columns if (colTotalElements.Count() > 0 && page.DataTable.Lines.Count > 0) { //We add first one/several final lines (one per element) ResultCell[] totalLine = new ResultCell[page.DataTable.Lines[0].Length]; for (int i = 0; i < page.DataTable.Lines[0].Length; i++) { if (Report.Cancel) break; foreach (var element in colTotalElements) { ResultTotalCell totalCell = new ResultTotalCell() { Element = element, IsTotal = true, IsTotalTotal = true }; for (int j = 0; j < page.DataTable.Lines.Count; j++) { ResultCell cell = page.DataTable.Lines[j][i]; if (cell != null && !cell.IsTitle && element == cell.Element) totalCell.Cells.Add(cell); } totalCell.Calculate(); if (element.ShowTotal == ShowTotal.Column || element.ShowTotal == ShowTotal.RowColumn) { //Add titles if not a value if (totalCell.Cells.Count == 0) { if (i == 0) { totalCell.IsTitle = true; totalCell.Value = Report.Translate("Total"); } } totalLine[i] = totalCell; } //Handle calculation if (!totalCell.IsTitle) { if (element.CalculationOption == CalculationOption.PercentageColumn) { foreach (ResultCell cell in totalCell.Cells) cell.Value = cell.DoubleValue / totalCell.DoubleValue; totalCell.Value = 1; } } //This cell is ok for one element, can break if (totalCell.Cells.Count > 0) break; } } //Add line only if a total is set (not only calculation options) if (model.GetElements(PivotPosition.Data).Count(e => e.ShowTotal == ShowTotal.Column || e.ShowTotal == ShowTotal.RowColumn) > 0) page.DataTable.Lines.Add(totalLine); } //Totals per rows if (rowTotalElements.Count() > 0) { //We add first one cell for each line (one per element) -> actually we add columns for (int i = page.DataTable.Lines.Count - 1; i >= 0; i--) { if (Report.Cancel) break; bool isTotalTitleSet = false; var rowLine = page.DataTable.Lines[i]; //Calculate the row total foreach (var element in rowTotalElements) { ResultTotalCell totalCell = new ResultTotalCell() { Element = element, IsTotal = true, IsTotalTotal = (i == page.DataTable.Lines.Count - 1) }; bool isHeaderLine = false; foreach (var cell in rowLine) { if (cell != null && !cell.IsTitle && element == cell.Element) totalCell.Cells.Add(cell); else if (cell != null && cell.IsTitle && element == cell.Element) isHeaderLine = true; } totalCell.Calculate(); //Add the cell if (element.ShowTotal == ShowTotal.Row || element.ShowTotal == ShowTotal.RowColumn) { Array.Resize<ResultCell>(ref rowLine, rowLine.Length + 1); //Add titles if not a value if (totalCell.Cells.Count == 0) { string value = ""; if (i == 0 && !isTotalTitleSet) { if (!isHeaderLine) isTotalTitleSet = true; value = Report.Translate("Total"); } if (isHeaderLine && rowTotalElements.Count() > 1) Helper.AddValue(ref value, " ", Report.Repository.TranslateElement(element, element.DisplayNameEl)); if (!string.IsNullOrEmpty(value)) totalCell.IsTitle = true; totalCell.Value = value; } rowLine[rowLine.Length - 1] = totalCell; page.DataTable.Lines[i] = rowLine; } //Handle calculations if (!totalCell.IsTitle) { if (element.CalculationOption == CalculationOption.PercentageRow) { foreach (ResultCell cell in totalCell.Cells) cell.Value = cell.DoubleValue / totalCell.DoubleValue; totalCell.Value = 1; } else if (element.CalculationOption == CalculationOption.PercentageAll) { ResultTotalCell totalTotalCell = page.DataTable.TotalCells.FirstOrDefault(c => c.Element == element); if (totalTotalCell != null) { foreach (ResultCell cell in totalCell.Cells) cell.Value = cell.DoubleValue / totalTotalCell.DoubleValue; if (totalCell != totalTotalCell) totalCell.Value = totalCell.DoubleValue / totalTotalCell.DoubleValue; } } if (i == page.DataTable.Lines.Count - 1 && element.CalculationOption != CalculationOption.No) { //case of total of total cell with calc options, set value to 1 totalCell.Value = 1; } } } } } //Set total totals to 1 if calculation options. foreach (ResultTotalCell cell in page.DataTable.TotalCells.Where(i => i.Element.CalculationOption != CalculationOption.No)) cell.Value = 1; //Add totals for Page and Summary tables if (page.PageTable != null && page.PageTable.Lines.Count == 2 && page.PageTable.Lines[0].Length > 0) { //Add totals for pages foreach (ResultCell cell in page.DataTable.TotalCells.Where(i => i.Element.ShowTotal != ShowTotal.No)) { ResultCell[] page0 = page.PageTable.Lines[0]; Array.Resize<ResultCell>(ref page0, page0.Length + 1); page0[page0.Length - 1] = new ResultTotalCell() { Element = cell.Element, IsTotal = true, IsTitle = true, Value = cell.Element.DisplayNameEl }; page.PageTable.Lines[0] = page0; ResultCell[] page1 = page.PageTable.Lines[1]; Array.Resize<ResultCell>(ref page1, page1.Length + 1); page1[page1.Length - 1] = cell; page.PageTable.Lines[1] = page1; } } } //Add totals for summary table if (model.Pages.Count > 1) { List<ResultTotalCell> tttCells = new List<ResultTotalCell>(); //First titles line var line0 = model.SummaryTable.Lines[0]; foreach (ResultCell cell in model.Pages[0].DataTable.TotalCells.Where(i => i.Element.ShowTotal != ShowTotal.No)) { Array.Resize<ResultCell>(ref line0, line0.Length + 1); ResultTotalCell totalCell = new ResultTotalCell() { Element = cell.Element, IsTotal = true, IsTitle = true, Value = cell.Element.DisplayNameEl }; line0[line0.Length - 1] = totalCell; } model.SummaryTable.Lines[0] = line0; //Then value per page int index = 1; foreach (ResultPage page in model.Pages) { var line = model.SummaryTable.Lines[index]; foreach (ResultCell cell in page.DataTable.TotalCells.Where(i => i.Element.ShowTotal != ShowTotal.No)) { ResultTotalCell tttCell = tttCells.FirstOrDefault(i => i.Element == cell.Element); if (tttCell == null) { tttCell = new ResultTotalCell() { Element = cell.Element, IsTotal = true, IsTotalTotal = true }; tttCells.Add(tttCell); } Array.Resize<ResultCell>(ref line, line.Length + 1); line[line.Length - 1] = cell; tttCell.Cells.Add(cell); } model.SummaryTable.Lines[index] = line; index++; if (index >= model.SummaryTable.Lines.Count) break; } //Final line: Total of total of total ! ResultCell[] tttLine = new ResultCell[model.SummaryTable.Lines[0].Length]; for (int i = 0; i < line0.Length; i++) { if (!line0[i].IsTotal) { //empty cell tttLine[i] = new ResultTotalCell() { Element = line0[i].Element, IsTotal = true, Value = "" }; } else { ResultTotalCell tttCell = tttCells.FirstOrDefault(cell => cell.Element == line0[i].Element); if (tttCell != null) { tttCell.Calculate(); tttLine[i] = tttCell; } } } model.SummaryTable.Lines.Add(tttLine); } }
static public string ConcatCellValues(ResultCell[] cells, string separator) { string result = ""; foreach (var cell in cells) Helper.AddValue(ref result, separator, cell.ValueNoHTML); return result; }
bool IsDifferent(ResultCell[] values1, ResultCell[] values2) { bool result = false; if (values1.Length != values2.Length) result = true; else { for (int i = 0; i < values1.Length; i++) { if (values1[i].Value.ToString() != values2[i].Value.ToString()) { result = true; break; } } } return result; }
private void buildTables(ReportModel model) { ResultCell[] headerPageValues = GetHeaderCells(PivotPosition.Page, model); ResultCell[] headerRowValues = GetHeaderCells(PivotPosition.Row, model); ResultCell[] headerColumnValues = GetHeaderCells(PivotPosition.Column, model); ResultCell[] headerDataValues = GetHeaderCells(PivotPosition.Data, model); if (headerDataValues.Length == 0 && headerRowValues.Length > 0 && headerColumnValues.Length > 0) Report.LogMessage("WARNING for Model '{0}': Row and Column elements are set but no Data element is specified. Please add a Data element in your model.", model.Name); //Summary table headers model.SummaryTable = new ResultTable(); model.SummaryTable.Lines.Add(headerPageValues); foreach (ResultPage page in model.Pages) { if (Report.Cancel) break; //Summary table values model.SummaryTable.Lines.Add(page.Pages); //Page table page.PageTable = new ResultTable(); page.PageTable.Lines.Add(headerPageValues); page.PageTable.Lines.Add(page.Pages); //Data table page.DataTable = new ResultTable(); //Calculate line width int width = headerRowValues.Length + Math.Max(headerColumnValues.Length, headerDataValues.Length * Math.Max(1, page.Columns.Count)); ResultCell[] line; //First line, only if column values if (headerColumnValues.Length > 0) { line = new ResultCell[width]; if (headerDataValues.Length == 1) line[0] = headerDataValues[0]; //Case 1 Data, title in first cell for (int i = 0; i < headerColumnValues.Length; i++) line[headerRowValues.Length + i] = headerColumnValues[i]; //case cols, no rows, one data, add data title if (headerColumnValues.Length > 0 && headerRowValues.Length == 0 && headerDataValues.Length == 1 && headerColumnValues.Length < width) line[headerColumnValues.Length] = headerDataValues[0]; //Fill empty cells for (int i = 0; i < width; i++) if (line[i] == null) line[i] = new ResultCell() { IsTitle = true }; page.DataTable.Lines.Add(line); } //Intermediate lines, set columns values for (int i = 0; i < headerColumnValues.Length + 1; i++) { line = new ResultCell[width]; if (i < headerColumnValues.Length) { //column values for (int j = 0; j < page.Columns.Count; j++) line[headerRowValues.Length + headerDataValues.Length * j] = page.Columns[j][i]; } else { //headers for rows for (int j = 0; j < headerRowValues.Length; j++) line[j] = headerRowValues[j]; //headers for data for (int j = 0; j < Math.Max(1, page.Columns.Count); j++) { int index = headerDataValues.Length * j; foreach (var header in headerDataValues) line[headerRowValues.Length + index++] = header; } } if (headerColumnValues.Length > 0 && headerDataValues.Length <= 1 && i == headerColumnValues.Length - 1) { //Case 1 Data with at least 1 column, or no data with 1 row and a cloumn, one line less as the titles is already set in first cell //headers for rows for (int j = 0; j < headerRowValues.Length; j++) line[j] = headerRowValues[j]; i++; } //Fill empty cells for (int j = 0; j < width; j++) if (line[j] == null) line[j] = new ResultCell() { IsTitle = (j < headerRowValues.Length) }; page.DataTable.Lines.Add(line); } //Set start row and column page.DataTable.BodyStartRow = page.DataTable.Lines.Count; page.DataTable.BodyStartColumn = headerRowValues.Length; //Finally row and data values if (page.Rows.Count == 0 && page.Datas.Count > 0) { //Case no column, force one row to display data page.Rows.Add(new ResultCell[0]); } foreach (var row in page.Rows) { if (Report.Cancel) break; line = new ResultCell[width]; //Row values for (int i = 0; i < row.Length; i++) line[i] = row[i]; //Data values List<ResultData> datas = null; if (row.Length == 0 && page.Datas.Count > 0) { //Case no rows datas = new List<ResultData>(); foreach (var data0 in page.Datas) datas.AddRange(data0.Value); } //normal case else if (page.Datas.ContainsKey(row)) datas = page.Datas[row]; if (datas != null) { foreach (var data in datas) { //find the index of the column values int columnIndex = 0; if (data.Column.Length > 0) columnIndex = FindDimension(data.Column, page.Columns); for (int i = 0; i < data.Data.Length; i++) line[headerRowValues.Length + headerDataValues.Length * columnIndex + i] = data.Data[i]; } } page.DataTable.Lines.Add(line); for (int i = 0; i < width; i++) if (line[i] == null) line[i] = new ResultCell() { }; } //Set end row page.DataTable.BodyEndRow = page.DataTable.Lines.Count; } }
ResultCell[] GetResultCells(ReportElement[] elements, ResultCell[] row, ResultCell[] col) { ResultCell[] result = new ResultCell[elements.Length]; for (int i = 0; i < elements.Length; i++) { ResultCell val = row.FirstOrDefault(v => v.Element == elements[i]); if (val == null) val = col.FirstOrDefault(v => v.Element == elements[i]); result[i] = new ResultCell() { Element = elements[i], Value = val.Value }; } return result.ToArray(); }
ResultCell[] GetXSerieCells(AxisType xAxisType, ResultCell[] row, ResultCell[] col, ReportModel model) { ReportElement[] elements = model.GetXElements(xAxisType).ToArray(); return GetResultCells(elements, row, col); }
private void setSubReportNavigation(ResultCell[] cellsToAssign, ResultCell[] cellValues) { for (int i = 0; i < cellsToAssign.Length && _processSubReports; i++) { if (cellsToAssign[i] != null && cellsToAssign[i].Element != null && cellsToAssign[i].Element.MetaColumn != null) { foreach (var subreport in cellsToAssign[i].Element.MetaColumn.SubReports) { foreach (var guid in subreport.Restrictions) { bool done = false; for (int j = 0; j < cellValues.Length && !done; j++) { if (guid == cellValues[j].Element.MetaColumnGUID) { cellsToAssign[i].SubReportValues.Add(cellValues[j]); done = true; } } //try in the cells themselves... for (int j = 0; j < cellsToAssign.Length && !done; j++) { if (guid == cellsToAssign[j].Element.MetaColumnGUID) { cellsToAssign[i].SubReportValues.Add(cellsToAssign[j]); done = true; } } } } } } }
public static int CompareCells(ResultCell[] a, ResultCell[] b) { if (a.Length == 0 || a.Length != b.Length) return 0; ReportModel model = a[0].Element.Model; foreach (ReportElement element in model.Elements.OrderBy(i => i.FinalSortOrder)) { ResultCell aCell = a.FirstOrDefault(i => i.Element == element); ResultCell bCell = b.FirstOrDefault(i => i.Element == element); if (aCell != null && bCell != null) { int result = CompareCell(aCell, bCell); if (result != 0) return (element.SortOrder.Contains(SortOrderConverter.kAscendantSortKeyword) ? 1 : -1) * result; } } return 0; }
private void executeCellScript(ResultCell cell) { string script = cell.Element.CellScript; try { if (!_cellCompilationKeys.ContainsKey(script)) { string newKey = Guid.NewGuid().ToString(); Helper.CompileRazor(script, typeof(ResultCell), newKey); _cellCompilationKeys.Add(script, newKey); } string key = _cellCompilationKeys[script]; if (!string.IsNullOrEmpty(key)) Razor.Run(_cellCompilationKeys[script], cell); } catch (Exception ex) { Report.ExecutionMessages += string.Format("Error got when executing Cell Script for '{0}'\r\n{1}\r\n", cell.Element.DisplayNameEl, ex.Message); if (!_cellCompilationKeys.ContainsKey(script)) _cellCompilationKeys.Add(script, ""); } }
private int CompareXDimensionsWithAxis(ResultCell[] a, ResultCell[] b) { return (_serieForSort.Element.SerieSortOrder == PointSortOrder.Ascending ? 1 : -1) * ResultCell.CompareCells(a, b); }
public void InvertDataTables() { foreach (ResultPage page in Pages) { if (Report.Cancel) break; if (page.DataTable.Lines.Count > 0) { ResultTable newTable = new ResultTable(); for (int i = 0; i < page.DataTable.Lines[0].Length; i++) { ResultCell[] newLine = new ResultCell[page.DataTable.Lines.Count]; for (int j = 0; j < page.DataTable.Lines.Count; j++) { newLine[j] = page.DataTable.Lines[j][i]; } newTable.Lines.Add(newLine); } //Revert start row and column newTable.BodyStartRow = page.DataTable.BodyStartColumn; newTable.BodyStartColumn = page.DataTable.BodyStartRow; //Calculate body end for (int i = 0; i < page.DataTable.Lines[0].Length; i++) { if (!page.DataTable.Lines[0][i].IsTotal) newTable.BodyEndRow++; } page.DataTable = newTable; } } }
public string GetLoadTableData(ReportModel model, string parameter) { var parameters = parameter.Split('§'); int echo = 1, len = 50, start = 0; string sort = "", search = ""; try { if (parameters.Length != 5) { throw new Exception("Invalid parameter size"); } echo = int.Parse(parameters[0]); sort = parameters[1]; search = parameters[2]; len = int.Parse(parameters[3]); start = int.Parse(parameters[4]); } catch (Exception ex) { Helper.WriteLogEntryWeb(EventLogEntryType.Error, string.Format("GetLoadTableData-> Error in parameter:{0}\r\n{1}", parameter, ex.Message)); echo = 1; len = 50; start = 0; sort = ""; search = ""; } var sb = new StringBuilder(); sb.Append("\"aaData\": ["); //Check filter first if (search != _lastSearch || _filteredLines == null) { start = 0; _filteredLines = new List <ResultCell[]>(); var search2 = search.ToLower(); for (int row = BodyStartRow; row < BodyEndRow; row++) { ResultCell[] line = Lines[row]; bool filtered = false; if (string.IsNullOrEmpty(search)) { filtered = true; } else { for (int col = 0; col < line.Length && !filtered; col++) { ResultCell cell = line[col]; var cellValue = !string.IsNullOrEmpty(cell.FinalValue) ? cell.FinalValue : cell.DisplayValue; if (!string.IsNullOrEmpty(search) && cellValue.ToLower().Contains(search2)) { filtered = true; break; } } } if (filtered) { _filteredLines.Add(line); } } } _lastSearch = search; //handle sort if (!string.IsNullOrEmpty(sort) && sort.Contains(",") && _filteredLines.Count > 0) { var sortIndex = int.Parse(sort.Split(',')[0]); var refLine = Lines[BodyStartRow]; if (sortIndex < refLine.Length) { //clear other sort foreach (var element in model.Elements) { element.FinalSortOrder = ""; } //set sort to the column, find the related element... foreach (var line in _filteredLines) { ResultCell cell = line[sortIndex]; if (cell.Element != null) { var ascdesc = (sort.ToLower().Contains("asc") ? SortOrderConverter.kAscendantSortKeyword : SortOrderConverter.kDescendantSortKeyword); cell.Element.FinalSortOrder = sortIndex + " " + ascdesc; break; } } } _filteredLines.Sort(ResultCell.CompareCellsForTableLoad); } //build the json result if (len == -1) { start = 0; len = _filteredLines.Count; } for (int row = start; row < _filteredLines.Count && row < start + len; row++) { ResultCell[] line = _filteredLines[row]; if (row != start) { sb.Append(","); } sb.Append("["); for (int col = 0; col < line.Length; col++) { if (col > 0) { sb.Append(","); } ResultCell cell = line[col]; string className = cell.IsTitle && col == 0 ? "cell_title" : "cell_value"; className = cell.IsTotal ? "cell_value_total" : className; var cellValue = !string.IsNullOrEmpty(cell.FinalValue) ? cell.FinalValue : cell.DisplayValue; var fullValue = HttpUtility.JavaScriptStringEncode(string.Format("{0}§{1}§{2}§{3}", model.GetNavigation(cell, true), cell.CellCssStyle, className, cellValue)); sb.AppendFormat("\"{0}\"", fullValue); } sb.Append("]"); } sb.Append("]}"); var sbFinal = new StringBuilder(); sbFinal.Append(@"{" + "\"sEcho\": " + echo.ToString() + ","); sbFinal.Append("\"recordsTotal\": " + _filteredLines.Count.ToString() + ","); sbFinal.Append("\"recordsFiltered\": " + _filteredLines.Count.ToString() + ","); sbFinal.Append("\"iTotalRecords\": " + (BodyEndRow - BodyStartRow).ToString() + ","); sbFinal.Append("\"iTotalDisplayRecords\": " + _filteredLines.Count.ToString() + ","); sbFinal.Append(sb); return(sbFinal.ToString()); }
private int CompareXDimensionsWithSeries(ResultCell[] a, ResultCell[] b) { ResultSerieValue va = _serieForSort.Values.FirstOrDefault(i => i.XDimensionValues == a); ResultSerieValue vb = _serieForSort.Values.FirstOrDefault(i => i.XDimensionValues == b); if (va != null && vb != null) { return (_serieForSort.Element.SerieSortOrder == PointSortOrder.Ascending ? 1 : -1) * CompareResultSerieValues(va, vb); } return 0; }
int FindDimension(ResultCell[] valuesToFind, List<ResultCell[]> valuesList) { for (int i = valuesList.Count - 1; i >= 0; i--) { if (!IsDifferent(valuesList[i], valuesToFind)) { return i; } } //Not found, add it to the list valuesList.Add(valuesToFind); return valuesList.Count - 1; }
public static int CompareCell(ResultCell a, ResultCell b) { if (a.Value == DBNull.Value && b.Value == DBNull.Value) return 0; if (a.Value == DBNull.Value && b.Value != null) return -1; if (a.Value != null && b.Value == DBNull.Value) return 1; if (a.Element.IsEnum) { return a.Element.GetEnumSortValue(a.Value.ToString(), true).CompareTo(b.Element.GetEnumSortValue(b.Value.ToString(), true)); } else if (a.Element.IsText) { return a.Value.ToString().CompareTo(b.Value.ToString()); } else if (a.Element.IsDateTime) { if (a.DateTimeValue == b.DateTimeValue) return 0; return a.DateTimeValue > b.DateTimeValue ? 1 : -1; } else if (a.Element.IsNumeric) { if (a.DoubleValue == b.DoubleValue) return 0; return a.DoubleValue > b.DoubleValue ? 1 : -1; } return 0; }
/// <summary> /// Function to return partial table data to the report result /// </summary> public string GetLoadTableData(ReportView view, string parameter) { var model = view.ModelView.Model; var parameters = parameter.Replace("<", "<").Replace(">", ">").Split('§'); int echo = 1, len = 50, start = 0; string sort = "", search = ""; try { if (parameters.Length != 5) { throw new Exception("Invalid parameter size"); } echo = int.Parse(parameters[0]); sort = parameters[1]; search = parameters[2]; len = int.Parse(parameters[3]); start = int.Parse(parameters[4]); } catch (Exception ex) { Helper.WriteLogEntry("Seal Get Table Data", EventLogEntryType.Error, string.Format("GetLoadTableData-> Error in parameter:{0}\r\n{1}", parameter, ex.Message)); echo = 1; len = 50; start = 0; sort = ""; search = ""; } var sb = new StringBuilder(); sb.Append("\"aaData\": ["); //Check filter first if (search != _lastSearch || _filteredLines == null) { start = 0; _filteredLines = new List <ResultCell[]>(); var search2 = search.ToLower(); for (int row = BodyStartRow; row < BodyEndRow; row++) { ResultCell[] line = Lines[row]; bool filtered = false; if (string.IsNullOrEmpty(search)) { filtered = true; } else { for (int col = 0; col < line.Length && !filtered; col++) { ResultCell cell = line[col]; var cellValue = cell.HTMLValue; if (!string.IsNullOrEmpty(search) && HttpUtility.HtmlDecode(cellValue).ToLower().Contains(search2)) { filtered = true; break; } } } if (filtered) { _filteredLines.Add(line); } } } _lastSearch = search; //handle sort if (!string.IsNullOrEmpty(sort) && sort.Contains(",") && _filteredLines.Count > 0) { var sortIndex = int.Parse(sort.Split(',')[0]); var refLine = Lines[BodyStartRow]; //Handle hidden columns for (int col = 0; col < refLine.Length; col++) { if (col <= sortIndex && (view.IsColumnHidden(col) || IsColumnHidden(col))) { sortIndex++; } } if (sortIndex < refLine.Length) { //clear other sort foreach (var element in model.Elements) { element.FinalSortOrder = ""; } //set sort to the column, find the related element... foreach (var line in _filteredLines) { ResultCell cell = line[sortIndex]; if (cell.Element != null) { var ascdesc = (sort.ToLower().Contains("asc") ? ReportElement.kAscendantSortKeyword : ReportElement.kDescendantSortKeyword); cell.Element.FinalSortOrder = sortIndex + " " + ascdesc; break; } } } if (ResultCell.ShouldSort(_filteredLines)) { _filteredLines.Sort(ResultCell.CompareCellsForTableLoad); } } //build the json result if (len == -1) { start = 0; len = _filteredLines.Count; } var rowBodyClass = view.GetValue("data_table_body_class"); var rowBodyStyle = view.GetValue("data_table_body_css"); var rowSubClass = view.GetValue("data_table_subtotal_class"); var rowSubStyle = view.GetValue("data_table_subtotal_css"); for (int row = start; row < _filteredLines.Count && row < start + len; row++) { ResultCell[] line = _filteredLines[row]; if (row != start) { sb.Append(","); } sb.Append("["); for (int col = 0; col < line.Length; col++) { if (view.IsColumnHidden(col) || IsColumnHidden(col)) { continue; } ResultCell cell = line[col]; var cellValue = cell.HTMLValue; var fullValue = HttpUtility.JavaScriptStringEncode(string.Format("{0}§{1}§{2}§{3}§{4}§{5}", cell.IsSubTotal ? rowSubStyle : rowBodyStyle, cell.IsSubTotal ? rowSubClass : rowBodyClass, model.GetNavigation(cell, true), cell.CellCssStyle, cell.CellCssClass, cellValue)); sb.AppendFormat("\"{0}\",", fullValue); } sb.Length = sb.Length - 1; sb.Append("]"); } sb.Append("]}"); var sbFinal = new StringBuilder(); sbFinal.Append(@"{" + "\"sEcho\": " + echo.ToString() + ","); sbFinal.Append("\"recordsTotal\": " + _filteredLines.Count.ToString() + ","); sbFinal.Append("\"recordsFiltered\": " + _filteredLines.Count.ToString() + ","); sbFinal.Append("\"iTotalRecords\": " + (BodyEndRow - BodyStartRow).ToString() + ","); sbFinal.Append("\"iTotalDisplayRecords\": " + _filteredLines.Count.ToString() + ","); sbFinal.Append(sb); return(sbFinal.ToString()); }
ResultCell[] GetResultCells(ReportElement[] elements, DataRow row) { ResultCell[] result = new ResultCell[elements.Length]; for (int i = 0; i < elements.Length; i++) { result[i] = new ResultCell() { Element = elements[i], Value = row[elements[i].SQLColumnName] }; } return result.ToArray(); }