protected static NHibernate.StaleObjectStateException EnrichStaleObjectStateException(NHibernate.StaleObjectStateException staleObjectStateException) { //If it's already enriched, return it and get out if (staleObjectStateException.Data["ZAPPDEV_MESSAGE"] != null) { return(staleObjectStateException); } //Otherwise, enrich it string defaultMessage = @"Somebody already committed modifications to the data you are about to commit. <br/>You have been working with <i>stale data</i>.<br/>Please, refresh your page in order to restart with fresh data."; string defaultTitle = "Stale Data"; string message = BaseViewPageBase <string> .GetResourceValue("GlobalResources", "RES_SITE_StaleObjectStateExceptionMessage").ToString(); string title = BaseViewPageBase <string> .GetResourceValue("GlobalResources", "RES_SITE_StaleObjectStateExceptionTitle").ToString(); if (string.IsNullOrWhiteSpace(message)) { message = defaultMessage; } if (string.IsNullOrWhiteSpace(title)) { title = defaultTitle; } staleObjectStateException.Data.Add("ZAPPDEV_MESSAGE", message); staleObjectStateException.Data.Add("ZAPPDEV_TITLE", title); return(staleObjectStateException); }
private static string GenerateFilterCode <T>(List <FilterInfo> filters) { var type = typeof(T); var predicateCode = ""; var lastRowOperator = RowOperator.NONE; var variableDefinitionsCode = ""; // When creating the predicate we start with filters with row operator OR // e.g. Global Filters are set using an OR row operator // Quick Filters and Custom Filters are set using an AND operator // We first want to filter using OR (records matching at least one condition) // then keep records that match ALL other (AND) conditions filters = filters.OrderByDescending(f => f.RowOperator == RowOperator.OR).ToList(); foreach (var filter in filters) { //We do not encrypt the parameter value in the equal and not equal operators, because NHibernate does that for us by calling NullSafeGet //when the query is executed if (filter.Column.IsEncrypted && !(filter.Operator == FilterOperator.EQUAL_TO || filter.Operator == FilterOperator.NOT_EQUAL_TO)) { filter.Value = BaseViewPageBase <object> .EncryptValue(filter.Value); } // Since filters are ordered with OR preceeding AND, when operator changes, // we wrap the predicate created at the moment in parenthesis // so that the above "filtering strategy" is honored var wrap = filters.First() != filter && lastRowOperator != filter.RowOperator; if (wrap) { predicateCode = "(" + predicateCode + ")"; } lastRowOperator = filter.RowOperator; if (!string.IsNullOrWhiteSpace(predicateCode)) { predicateCode += " " + FilterRowOpToCsOp[filter.RowOperator] + " "; } if (ValueCanBeParsedToColumnDatatype(filter) || filter.Operator == FilterOperator.HAS_VALUE || filter.Operator == FilterOperator.HAS_NO_VALUE) { var pathToProp = "q." + filter.Column.Name; var varName = filter.Column.Name.Replace(".", "_") + "Value" + filters.IndexOf((filter)); if (filter.Operator != FilterOperator.HAS_VALUE && filter.Operator != FilterOperator.HAS_NO_VALUE) { if (filter.Column.MambaDataType == "DateTime") { switch (filter.Operator) { case FilterOperator.LIKE: variableDefinitionsCode += $"var {varName} = {FormatFilterValue(filter.Column, filter.Value)}.Date;"; variableDefinitionsCode += $"var {varName}2 = {FormatFilterValue(filter.Column, filter.Value)}.Date.AddDays(1).AddTicks(-1);"; break; case FilterOperator.LESS_THAN_OR_EQUAL_TO: variableDefinitionsCode += $"var {varName} = {FormatFilterValue(filter.Column, filter.Value)}.Date.AddDays(1).AddTicks(-1);"; break; default: variableDefinitionsCode += $"var {varName} = {FormatFilterValue(filter.Column, filter.Value)};"; break; } } else { variableDefinitionsCode += $"var {varName} = {FormatFilterValue(filter.Column, filter.Value)};"; } } if (filter.Operator == FilterOperator.RANGE) { variableDefinitionsCode += $"var {varName}2 = {FormatFilterValue(filter.Column, filter.SecondValue)};"; } predicateCode += CreateFilterExpression(filter.Operator, filter.Column, varName, pathToProp); } else { predicateCode += BuildEnumeratorsPredicate(filter, type); } } return($"public static Expression<Func<{TypeName(type)}, bool>> GetFilterPredicate() {{ {variableDefinitionsCode} return q => {predicateCode}; }}"); }
//PM> Install-Package PdfSharp //license: http://www.pdfsharp.net/PDFsharp_License.ashx public static string ExportListToPDF(ExportOptions opt, List <ExportRecordDTO> result, int totalRows, Func <Document, Table, object> _pdfOvveride) { var firstResult = result.First(); firstResult.MarkVisibleColumns(opt); var columns = result.First().Columns; var visibleColumns = columns.Where(c => c.IsVisible); var document = InitializePDFDocument(visibleColumns.Count(), out Unit availableWidth, out Unit availableColumnWidth, opt.PortraitOrientation); //create section wrapper of table Section section = new Section(); document.Add(section); //create table Table table = new Table(); table.AddColumn();//counterColumn Cell cell; Column column; List <ExportColumnDTO> columnCaptions = new List <ExportColumnDTO>(); //create the columns based on headers foreach (var cols in visibleColumns) { table.AddColumn(); columnCaptions.Add(cols); } //create one row for the headers, the style of headers and the row contents var row = table.AddRow(); GroupStyleColorParse mycolor = new GroupStyleColorParse(opt.HeaderColor); row.Shading.Color = Color.FromRgbColor(255, new Color((byte)mycolor.Red, (byte)mycolor.Green, (byte)mycolor.Blue)); var styleHeader = document.AddStyle("Headers", "Normal"); styleHeader.Font.Name = "Headers"; styleHeader.Font.Bold = true; styleHeader.Font.Size = 14; TextMeasurement tmHeader = new TextMeasurement(document.Styles["Headers"].Font.Clone()); var currentItemIndex = 0; foreach (var col in columnCaptions) { cell = row.Cells[currentItemIndex + 1]; //Cells[0] is emtpy, the header for counter column column = cell.Column; column.Width = availableColumnWidth; Paragraph p = new Paragraph(); var caption = string.IsNullOrWhiteSpace(col.Caption) ? col.ColumnName : col.Caption; p.AddFormattedText(WideWordsAdjust(cell, caption, tmHeader), "Headers"); cell.Add(p); currentItemIndex++; } //Fill with data(default style) the PDf table int rowCounter = 0; var style = document.Styles["Normal"]; TextMeasurement tm = new TextMeasurement(document.Styles["Normal"].Font.Clone()); //var doubleValue = 0.0; mycolor = new GroupStyleColorParse(opt.OddColor); GroupStyleColorParse mycolorEven = new GroupStyleColorParse(opt.EvenColor); foreach (var record in result) { var rowIn = table.AddRow(); rowCounter++; rowIn.Shading.Color = rowCounter % 2 != 0 ? Color.FromRgbColor(255, new Color((byte)mycolor.Red, (byte)mycolor.Green, (byte)mycolor.Blue)) : Color.FromRgbColor(255, new Color((byte)mycolorEven.Red, (byte)mycolorEven.Green, (byte)mycolorEven.Blue)); cell = rowIn.Cells[0]; cell.AddParagraph(rowCounter.ToString()); AutoFitColumn(cell, rowCounter.ToString(), tm); int colCounter = 0; string validPDFFormat = ""; foreach (var visibleColumn in record.Columns) { if (!visibleColumns.Any(c => c.ColumnName == visibleColumn.ColumnName)) { continue; } colCounter += 1; //var recordColumn = record.Columns.FirstOrDefault(c => c.ColumnName == visibleColumn.ColumnName); cell = rowIn.Cells[colCounter]; column = cell.Column; column.Width = availableColumnWidth; validPDFFormat = ApplyValueFormat(visibleColumn); cell.AddParagraph(WideWordsAdjust(cell, validPDFFormat?.ToString(), tm)); //colCounter++; } } if (opt.NonGroupCount) { var totalsRow = table.AddRow(); totalsRow.Cells[0].MergeRight = visibleColumns.Count(); totalsRow.Cells[0].AddParagraph($"{BaseViewPageBase<object>.GetResourceValue("GlobalResources", "RES_DATALIST_AGGREGATORS_GrandCount")}{totalRows}"); } //Add the table to the section and the document is ready for render if (opt.IncludeGridLines) { table.Borders.Visible = true; } if (_pdfOvveride == null) { section.Add(table); } else { _pdfOvveride?.Invoke(document, table); } PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true) { Document = document }; pdfRenderer.RenderDocument(); return(CreateFileAndSendDownloadLink(opt.Filename, null, "pdf", pdfRenderer)); }
public ManualValuesData(string key, string formName, string controlName, bool isPickList) { _key = key; Value = BaseViewPageBase <object> .GetResourceValue(formName, $"RES_{(isPickList ? "PICKLIST" : "LIST")}_{controlName}_VALUE_{key}"); }
private static string ExportListToOffice(ExportOptions options, string fileExtension, List <ExportRecordDTO> result, int totalRows) { //Header Contents var firstResult = result.FirstOrDefault(); firstResult?.MarkVisibleColumns(options); var columns = firstResult?.Columns; var visibleColumns = columns?.Where(c => c.IsVisible); var builder = new StringBuilder(result.Count() * visibleColumns.Count() * 50); string borderTable = (options.IncludeGridLines) ? "border='1'" : ""; builder.AppendFormat("<table {0}>", borderTable); builder.AppendLine("<thead>"); builder.AppendLine("<tr>"); foreach (ExportColumnDTO col in visibleColumns ?? new ExportColumnDTO[] {}) { var caption = string.IsNullOrWhiteSpace(col.Caption) ? col.ColumnName : col.Caption; builder.AppendLine($"<th style='background-color:{options.HeaderColor}'>{caption}</th>"); } builder.AppendLine("</tr>"); builder.AppendLine("</thead>"); //Row Contents builder.AppendLine(); builder.AppendLine("<tbody>"); int currentItemIndex = 0; var doubleValue = 0.0; List <string> listInfoSumAvg = new List <string>(); foreach (var item in result) { builder.AppendLine("<tr>"); int indexOfListInfo = 0; foreach (ExportColumnDTO column in item.Columns) { if (!visibleColumns.Any(c => c.ColumnName == column.ColumnName)) { continue; } var excelCellFormat = CreateExcelFormatting(column); var cellValue = GetOfficeValue(column, options.Type); //Creation of Excel Content with original Format and the case format due excel builder.AppendFormat("<td style='background-color: {0}; {1}'> {2} </td>", currentItemIndex % 2 != 0 ? options.OddColor : options.EvenColor, excelCellFormat, cellValue); //This branch keeps the sum for every column, if it is not possible keeps null if (double.TryParse(column.ToString(), out doubleValue)) { if (currentItemIndex == 0) { listInfoSumAvg.Add(doubleValue.ToString()); } else { listInfoSumAvg[indexOfListInfo] = (Convert.ToDouble(listInfoSumAvg[indexOfListInfo]) + Convert.ToDouble(doubleValue)).ToString(); } } else if (currentItemIndex == 0) { listInfoSumAvg.Add(doubleValue.ToString()); listInfoSumAvg[indexOfListInfo] = null; } indexOfListInfo++; } builder.AppendLine("</tr>"); currentItemIndex++; } //Display Rows for Sum, Avg and Count /* var distinctTypeOfAggregators = options.Aggregators.Select(y => y.Type).Distinct(); * * if (distinctTypeOfAggregators.Contains("SUM")) * { * DisplayInExcelAggregates(opt, ref innerContents, listInfoSumAvg, "SUM", currentItemIndex); * } * if (distinctTypeOfAggregators.Contains("AVERAGE")) * { * DisplayInExcelAggregates(opt, ref innerContents, listInfoSumAvg, "AVERAGE", currentItemIndex); * } * if (opt.TotalNonGroupCount) * { * DisplayInExcelAggregates(opt, ref innerContents, listInfoSumAvg, "COUNT", currentItemIndex); * } */ builder.AppendLine("</tbody>"); builder.AppendLine("<tfoot>"); if (options.NonGroupCount) { builder.AppendLine($"<tr><td colspan='{columns?.Count}'>{BaseViewPageBase<object>.GetResourceValue("GlobalResources", "RES_DATALIST_AGGREGATORS_GrandCount")}{totalRows}</td></tr>"); } builder.AppendLine("</tfoot>"); builder.AppendLine("</table>"); var fileContents = WrapContentsToOfficeFile(builder.ToString(), options.Filename); return(CreateFileAndSendDownloadLink(options.Filename, fileContents, fileExtension)); }