Пример #1
0
        public byte[] GetEmployeesLoggedTimeByPeriod(LoggedTimeByPeriodListViewModel request, DateTime startDate,
                                                     DateTime dueDate)
        {
            var pdf  = new PdfDocument();
            var page = pdf.AddPage();

            page.Orientation = PageOrientation.Landscape;
            page.Size        = PageSize.A4;

            var pages = new List <PdfPage> {
                page
            };

            //Create pdf content
            var doc = CreateDocument(nameof(this.GetProjectGeneralReport),
                                     string.Format("{1}, {0}", "Default", "Default"));

            var commonParameter = new CommonPdfParameter
            {
                Document = doc, Pdf = pdf, PdfPages = pages, StartDate = startDate,
                DueDate  = dueDate, PdfTableHelper = new PdfTableHelperA4()
            };

            PopulateForGetEmployeesLoggedTimeByPeriod(commonParameter, request);

            //Create renderer for content
            var renderer = new DocumentRenderer(doc);

            renderer.PrepareDocument();

            var pageSize = GetPageSizeInXRectUnits(page.Size);

            var pageNumber = 0;

            foreach (var item in pages)
            {
                var gfx       = XGraphics.FromPdfPage(item);
                var container = gfx.BeginContainer(pageSize, pageSize, XGraphicsUnit.Point);
                gfx.DrawRectangle(XPens.LightGray, pageSize);
                renderer.RenderPage(gfx, ++pageNumber);
                gfx.EndContainer(container);
            }

            using (MemoryStream ms = new MemoryStream())
            {
                pdf.Save(ms, true);
                return(ms.ToArray());
            }
        }
Пример #2
0
        /// <summary>
        /// Creates the common part for general report.
        /// </summary>
        /// <param name="request">The class which contains necessary data.</param>
        /// <param name="startDate">Represents start date.</param>
        /// <param name="dueDate">Represents due date</param>
        /// <returns></returns>
        private byte[] CsvForGeneralReport(LoggedTimeByPeriodListViewModel request, DateTime startDate, DateTime dueDate)
        {
            var result = new StringBuilder();

            result.AppendFormat("{0}, {1}{2}", "Start date", $"{startDate:dddd, dd MMMM yyyy}", '\n');
            result.AppendFormat("{0}, {1}{2}", "Due date", $"{dueDate:dddd, dd MMMM yyyy}", '\n');

            result.Append('\n');

            result.AppendFormat("{0}, {1}, {2}, {3}{4}",
                                "#", "Employee", "Est.", "Log.", '\n');

            int iteration = 0;

            foreach (var loggedTime in request.UsersLoggedEstimatedTime)
            {
                result.AppendFormat("{0}, {1}, {2}, {3}{4}", ++iteration, loggedTime.Name,
                                    loggedTime.UserEstimatedTimeByPeriod, loggedTime.UserLoggedTimeByPeriod, '\n');
            }

            result.AppendFormat("{0}, {1}, {2}{3}", "Total time", request.TotalEstimatedTime, request.TotalLoggedTime, '\n');

            return(Encoding.Unicode.GetBytes(result.ToString()));
        }
Пример #3
0
 public byte[] GetEmployeesLoggedTimeByPeriod(LoggedTimeByPeriodListViewModel request, DateTime startDate, DateTime dueDate)
 {
     return(CsvForGeneralReport(request, startDate, dueDate));
 }
Пример #4
0
        private void PopulateForGetEmployeesLoggedTimeByPeriod(CommonPdfParameter common, LoggedTimeByPeriodListViewModel request)
        {
            #region Header
            var section = common.Document.AddSection();
            var header  = section.Headers.Primary.AddParagraph();
            header.Format.Font.Size   = common.PdfTableHelper.HeaderSize;
            header.Format.Font.Color  = Colors.DarkBlue;
            header.Format.Font.Bold   = true;
            header.Format.Font.Italic = true;
            header.Format.Alignment   = ParagraphAlignment.Center;
            #endregion

            #region Table

            var tableCells = common.HeaderNames;
            var table      = CreateTableHeader(ref section, common.PdfTableHelper, tableCells);

            var iteration = 0;

            foreach (var user in request.UsersLoggedEstimatedTime)
            {
                var row = table.AddRow();
                row.Cells[0].AddParagraph((++iteration).ToString());
                row.Cells[1].AddParagraph(user.Name);
                row.Cells[2].AddParagraph(user.UserEstimatedTimeByPeriod.ToString("0.00"));
                row.Cells[3].AddParagraph(user.UserLoggedTimeByPeriod.ToString("0.00"));

                if (iteration % common.PdfTableHelper.ItemsPerPage == 0)
                {
                    section = common.Document.AddSection();
                    header  = section.Headers.Primary.AddParagraph();
                    header.AddText(string.Empty);

                    var page = common.Pdf.AddPage();
                    page.Orientation = PageOrientation.Landscape;
                    page.Size        = common.PdfTableHelper.PageSize;
                    common.PdfPages.Add(page);
                    section.AddPageBreak();
                    table = CreateTableHeader(ref section, common.PdfTableHelper, tableCells);
                }
            }

            if (request.UsersLoggedEstimatedTime.Count % common.PdfTableHelper.ItemsPerPage > 0)
            {
                section.AddPageBreak();
            }

            var column = table.AddRow();
            column.Borders.Style = BorderStyle.None;

            column = table.AddRow();
            column.Format.Font.Bold = true;
            column.Cells[2].AddParagraph("Start Date");
            column.Cells[3].AddParagraph(string.Format("{0:yyyy-M-d}", common.StartDate));

            column = table.AddRow();
            column.Format.Font.Bold = true;
            column.Cells[2].AddParagraph("Due Date");
            column.Cells[3].AddParagraph(string.Format("{0:yyyy-M-d}", common.DueDate));

            column = table.AddRow();
            column.Format.Font.Bold = true;
            column.Cells[2].AddParagraph("Total Estimated:");
            column.Cells[3].AddParagraph(request.TotalEstimatedTime.ToString("0.00"));

            column = table.AddRow();
            column.Format.Font.Bold = true;
            column.Cells[2].AddParagraph("Total Logged:");
            column.Cells[3].AddParagraph(request.TotalLoggedTime.ToString("0.00"));
            table = CreateTableHeader(ref section, common.PdfTableHelper, tableCells);

            table.Rows.Alignment = RowAlignment.Center;
            #endregion
        }