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);
        }
Exemple #2
0
        //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}");
 }
Exemple #4
0
        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));
        }