public void CreatePdf(Project project, Stream writeStream)
        {
            var document = new Document();
            var writer = PdfWriter.GetInstance(document, writeStream);

            // landscape
            document.SetPageSize(PageSize.A4.Rotate());
            document.SetMargins(36f, 36f, 36f, 36f); // 0.5 inch margins

            // metadata
            document.AddCreator("EstimatorX.com");
            document.AddKeywords("estimation");
            document.AddAuthor(project.Creator);
            document.AddSubject(project.Name);
            document.AddTitle(project.Name);
            
            document.Open();

            AddName(project, document);
            AddDescription(project, document);
            AddAssumptions(project, document);
            AddFactors(project, document);
            AddTasks(project, document);
            AddSummary(project, document);

            writer.Flush();
            document.Close();
        }
        private void AddName(Project project, Document document)
        {
            var paragraph = new Paragraph(project.Name, HeaderFont());
            paragraph.SpacingAfter = 6f;

            document.Add(paragraph);
        }
        private void AddDescription(Project project, Document document)
        {
            if (string.IsNullOrWhiteSpace(project.Description))
                return;

            var element = new Paragraph(project.Description);
            document.Add(element);
        }
        public byte[] CreatePdf(Project project)
        {
            byte[] buffer;

            using (var memoryStream = new MemoryStream())
            {
                CreatePdf(project, memoryStream);
                
                buffer = memoryStream.ToArray();
            }

            return buffer;
        }
        private static void UpdateSection(Project project, Section section)
        {
            foreach (var task in section.Tasks)
            {
                UpdateEstimate(project, task);

                // update parent totals
                section.TotalTasks += task.TotalTasks;
                section.TotalHours += task.TotalHours;
            }

            // calculate weeks after children total
            var hoursPerWeek = (double)project.HoursPerWeek;
            section.TotalWeeks = Math.Round(section.TotalHours / hoursPerWeek, 2);
        }
        private bool HasAccess(string id, out Project project)
        {
            project = null;
            string userId = User.Identity.GetUserId();
            var user = _userRepository.Find(userId);
            if (user == null)
                return false;

            project = _projectRepository.Find(id);
            if (project == null)
                return true; // allow create

            // user must be member 
            return project.OrganizationId == user.Id
                || user.Organizations.Contains(project.OrganizationId);
        }
        private void AddAssumptions(Project project, Document document)
        {
            if (project.Assumptions == null || project.Assumptions.Count < 1)
                return;

            var element = new Paragraph("Assumptions", TitleFont());
            element.SpacingBefore = 5f;
            document.Add(element);

            var list = new List(false, false, 10);
            list.SetListSymbol("\u2022");
            list.IndentationLeft = 10f;

            foreach (var assumption in project.Assumptions)
            {
                var item = new ListItem(assumption);
                list.Add(item);
            }

            document.Add(list);
        }
        private static void UpdateEstimate(Project project, Task task)
        {
            byte verySimple = (task.VerySimple ?? 0);
            byte simple = (task.Simple ?? 0);
            byte medium = (task.Medium ?? 0);
            byte complex = (task.Complex ?? 0);
            byte veryComplex = (task.VeryComplex ?? 0);

            var factor = project.Factors.FirstOrDefault(f => f.Id == task.FactorId) ?? new Factor();

            task.TotalTasks = verySimple
                + simple
                + medium
                + complex
                + veryComplex;

            task.TotalHours = (verySimple * factor.VerySimple)
                + (simple * factor.Simple)
                + (medium * factor.Medium)
                + (complex * factor.Complex)
                + (veryComplex * factor.VeryComplex);
        }
        /// <summary>
        /// Updates all the totals the specified <paramref name="project"/>.
        /// </summary>
        /// <param name="project">The project to total.</param>
        /// <returns></returns>
        public static Project UpdateTotals(Project project)
        {
            var hoursPerWeek = (double)project.HoursPerWeek;

            foreach (var section in project.Sections)
            {
                UpdateSection(project, section);

                // update parent totals
                project.TotalTasks += section.TotalTasks;
                project.TotalHours += section.TotalHours;
            }

                // calculate weeks after children total
            project.TotalWeeks = Math.Round(project.TotalHours / hoursPerWeek, 2);

            double contingencyPercent = project.ContingencyRate / 100;
            double contingencyHours = project.TotalHours * (1 + contingencyPercent);
            project.ContingencyHours = Convert.ToInt32(Math.Round(contingencyHours, 0));
            project.ContingencyWeeks = Math.Round(project.ContingencyHours / hoursPerWeek, 2);

            return project;
        }
Example #10
0
        public static Project Create()
        {
            var project = new Project
            {
                HoursPerWeek = 30,
                ContingencyRate = 10,
                Id = ObjectId.GenerateNewId().ToString(),
                Name = "New Project",
                Created = DateTime.Now,
                Creator = UserName.Current(),
                Updated = DateTime.Now,
                Updater = UserName.Current()
            };

            project.Assumptions.Add("Project Assumption");

            var presentationFactor = new Factor
            {
                Id = ObjectId.GenerateNewId().ToString(),
                Name = "Presentation Factor",
                VerySimple = 2,
                Simple = 4,
                Medium = 8,
                Complex = 16,
                VeryComplex = 32,
            };
            project.Factors.Add(presentationFactor);

            var backendFactor = new Factor
            {
                Id = ObjectId.GenerateNewId().ToString(),
                Name = "Back-End Logic Factor",
                VerySimple = 2,
                Simple = 4,
                Medium = 8,
                Complex = 16,
                VeryComplex = 32,
            };
            project.Factors.Add(backendFactor);

            var section = new Section
            {
                Id = ObjectId.GenerateNewId().ToString(),
                Name = "Application Section",
            };
            project.Sections.Add(section);

            var presentationEstimate = new Task
            {
                Id = ObjectId.GenerateNewId().ToString(),
                Name = "Presentation Task",
                FactorId = presentationFactor.Id,
            };
            section.Tasks.Add(presentationEstimate);

            var backendEstimate = new Task
            {
                Id = ObjectId.GenerateNewId().ToString(),
                Name = "Back-End Logic Task",
                FactorId = backendFactor.Id,
            };
            section.Tasks.Add(backendEstimate);

            return project;
        }
Example #11
0
 public void CreatePdf(Project project, string fileName)
 {
     using (var fileStream = File.Create(fileName))
         CreatePdf(project, fileStream);
 }
Example #12
0
        private void AddSummary(Project project, Document document)
        {
            var element = new Paragraph("Summary", TitleFont());
            element.SpacingBefore = 5f;
            document.Add(element);

            var table = new PdfPTable(5);
            table.SetWidths(new[] { 15, 30, 10, 15, 30 });
            table.WidthPercentage = 100;
            table.SpacingBefore = 10f;
            table.SpacingAfter = 10f;

            table.AddCell(PropertyCell("Total Tasks:"));
            table.AddCell(RowCell(project.TotalTasks.ToString()));
            table.AddCell(BlankCell());
            table.AddCell(PropertyCell("Created:"));
            table.AddCell(RowCell(project.Created.ToString()));

            table.AddCell(PropertyCell("Total Hours:"));
            table.AddCell(RowCell(project.TotalHours.ToString()));
            table.AddCell(BlankCell());
            table.AddCell(PropertyCell("Creator:"));
            table.AddCell(RowCell(project.Creator));

            table.AddCell(PropertyCell("Contingency Hours:"));
            table.AddCell(RowCell(project.ContingencyHours.ToString()));
            table.AddCell(BlankCell());
            table.AddCell(PropertyCell("Updated:"));
            table.AddCell(RowCell(project.Updated.ToString()));

            table.AddCell(PropertyCell("Total Weeks:"));
            table.AddCell(RowCell(project.TotalWeeks.ToString()));
            table.AddCell(BlankCell());
            table.AddCell(PropertyCell("Updater:"));
            table.AddCell(RowCell(project.Updater));

            table.AddCell(PropertyCell("Contingency Weeks:"));
            table.AddCell(RowCell(project.ContingencyWeeks.ToString()));
            table.AddCell(BlankCell(3));

            table.AddCell(PropertyCell("Hours Per Week:"));
            table.AddCell(RowCell(project.HoursPerWeek.ToString()));
            table.AddCell(BlankCell(3));

            table.AddCell(PropertyCell("Contingency Rate:"));
            table.AddCell(RowCell(project.ContingencyRate.ToString()));
            table.AddCell(BlankCell(3));
            
            document.Add(table);

        }
Example #13
0
        private void AddTasks(Project project, Document document)
        {
            var element = new Paragraph("Tasks", TitleFont());
            element.SpacingBefore = 5f;
            document.Add(element);

            var table = new PdfPTable(9);

            table.SetWidths(new[] { 31, 20, 7, 7, 7, 7, 7, 7, 7 });
            table.WidthPercentage = 100;
            table.SpacingBefore = 10f;

            table.AddCell(HeaderCell("Name"));
            table.AddCell(HeaderCell("Factor"));
            table.AddCell(HeaderCell("Very Simple"));
            table.AddCell(HeaderCell("Simple"));
            table.AddCell(HeaderCell("Medium"));
            table.AddCell(HeaderCell("Complex"));
            table.AddCell(HeaderCell("Very Complex"));
            table.AddCell(HeaderCell("Total Tasks"));
            table.AddCell(HeaderCell("Total Hours"));

            foreach (var section in project.Sections)
            {
                table.AddCell(SectionCell(section.Name, 7));
                table.AddCell(SectionCell(section.TotalTasks.ToString()));
                table.AddCell(SectionCell(section.TotalHours.ToString()));

                foreach (var task in section.Tasks)
                {
                    var factorName = project.Factors
                        .Where(f => f.Id == task.FactorId)
                        .Select(f => f.Name)
                        .FirstOrDefault() ?? string.Empty;

                    table.AddCell(RowCell(task.Name));
                    table.AddCell(RowCell(factorName));
                    table.AddCell(RowCell(task.VerySimple.ToString()));
                    table.AddCell(RowCell(task.Simple.ToString()));
                    table.AddCell(RowCell(task.Medium.ToString()));
                    table.AddCell(RowCell(task.Complex.ToString()));
                    table.AddCell(RowCell(task.VeryComplex.ToString()));
                    table.AddCell(TotalCell(task.TotalTasks.ToString()));
                    table.AddCell(TotalCell(task.TotalHours.ToString()));
                }
            }

            document.Add(table);
        }
Example #14
0
        private void AddFactors(Project project, Document document)
        {
            var element = new Paragraph("Factors", TitleFont());
            element.SpacingBefore = 5f;
            document.Add(element);

            var table = new PdfPTable(6);
            table.SetWidths(new[] { 45, 11, 11, 11, 11, 11 });
            table.WidthPercentage = 100;
            table.SpacingBefore = 10f;

            table.AddCell(HeaderCell("Name"));
            table.AddCell(HeaderCell("Very Simple"));
            table.AddCell(HeaderCell("Simple"));
            table.AddCell(HeaderCell("Medium"));
            table.AddCell(HeaderCell("Complex"));
            table.AddCell(HeaderCell("Very Complex"));

            foreach (var factor in project.Factors)
            {
                table.AddCell(RowCell(factor.Name));
                table.AddCell(RowCell(factor.VerySimple.ToString()));
                table.AddCell(RowCell(factor.Simple.ToString()));
                table.AddCell(RowCell(factor.Medium.ToString()));
                table.AddCell(RowCell(factor.Complex.ToString()));
                table.AddCell(RowCell(factor.VeryComplex.ToString()));
            }

            document.Add(table);
        }
Example #15
0
        public Project GenerateProject(string organizationId)
        {
            if (organizationId == null)
                throw new ArgumentNullException("organizationId");

            var project = new Project
            {
                Id = ObjectId.GenerateNewId().ToString(),
                Name = "Sample Project",
                Description = "Generated Sample Project",
                OrganizationId = organizationId,
                HoursPerWeek = 30,
                ContingencyRate = 10,
                Created = DateTime.Now,
                Creator = UserName.Current(),
                Updated = DateTime.Now,
                Updater = UserName.Current()
            };

            project.Assumptions.Add("Project Assumption");

            var presentationFactor = new Factor
            {
                Id = ObjectId.GenerateNewId().ToString(),
                Name = "Presentation Factor",
                VerySimple = 2,
                Simple = 4,
                Medium = 8,
                Complex = 16,
                VeryComplex = 32,
            };
            project.Factors.Add(presentationFactor);

            var backendFactor = new Factor
            {
                Id = ObjectId.GenerateNewId().ToString(),
                Name = "Back-End Logic Factor",
                VerySimple = 2,
                Simple = 4,
                Medium = 8,
                Complex = 16,
                VeryComplex = 32,
            };
            project.Factors.Add(backendFactor);

            var dataFactor = new Factor
            {
                Id = ObjectId.GenerateNewId().ToString(),
                Name = "Data Model Factor",
                VerySimple = 1,
                Simple = 2,
                Medium = 4,
                Complex = 8,
                VeryComplex = 16,
            };
            project.Factors.Add(dataFactor);

            var section = new Section
            {
                Id = ObjectId.GenerateNewId().ToString(),
                Name = "Application Sample Section",
            };
            project.Sections.Add(section);

            var presentationEstimate = new Task
            {
                Id = ObjectId.GenerateNewId().ToString(),
                Name = "Presentation Task",
                FactorId = presentationFactor.Id,
                Medium = 1,
                Simple = 1
            };
            section.Tasks.Add(presentationEstimate);

            var backendEstimate = new Task
            {
                Id = ObjectId.GenerateNewId().ToString(),
                Name = "Back-End Logic Task",
                FactorId = backendFactor.Id,
                Complex = 1,
                Simple = 1
            };
            section.Tasks.Add(backendEstimate);

            ProjectCalculator.UpdateTotals(project);

            return project;
        }