Пример #1
0
        public byte[] GetEmployeeLoggedTime(UserLoggedTimeListViewModel request, DateTime startDate, DateTime dueDate)
        {
            var result = new StringBuilder();

            result.AppendFormat("{0}, {1}{2}", "Employee", request.UserName, '\n');
            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}, {5}{6}",
                                "#", "Activity", "Project", "Subtype", "Log.", "Date", '\n');

            int iteration = 0;

            foreach (var loggedTime in request.LoggedTimes)
            {
                result.AppendFormat("{0}, {1}, {2}, {3}, {4}, {5}{6}", ++iteration, loggedTime.ActivityName,
                                    loggedTime.ProjectName, loggedTime.TrackerName, loggedTime.Time,
                                    $"{loggedTime.DateOfWork:dddd, dd MMMM yyyy}", '\n');
            }

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

            result.Append('\n');

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

            return(Encoding.Unicode.GetBytes(result.ToString()));
        }
Пример #2
0
        public byte[] GetEmployeeLoggedTime(UserLoggedTimeListViewModel 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()
            };

            PopulateForGetEmployeeLoggedTime(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());
            }
        }
Пример #3
0
        private void PopulateForGetEmployeeLoggedTime(CommonPdfParameter common, UserLoggedTimeListViewModel request)
        {
            #region Header
            var section = common.Document.AddSection();
            var header  = section.Headers.Primary.AddParagraph();
            header.AddText($"{request.UserName}");
            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 loggedTime in request.LoggedTimes)
            {
                var row = table.AddRow();
                row.Cells[0].AddParagraph((++iteration).ToString());
                row.Cells[1].AddParagraph(loggedTime.ProjectName);
                row.Cells[2].AddParagraph(loggedTime.ActivityName);
                row.Cells[3].AddParagraph(loggedTime.TrackerName);
                row.Cells[4].AddParagraph(loggedTime.Time.ToString("0.00"));
                row.Cells[5].AddParagraph(string.Format("{0:yyyy-M-d}", loggedTime.DateOfWork));

                if (iteration % common.PdfTableHelper.ItemsPerPage != 0)
                {
                    continue;
                }

                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.LoggedTimes.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("Employee");
            column.Cells[3].AddParagraph(request.UserName);

            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
        }