public Document CreateDocument(List<ChildVaccination> vaccinations, List<ChildMeasurement> measurements , Child child, string branch) { // Create a new MigraDoc document this.document = new Document(); document.DefaultPageSetup.Orientation = Orientation.Portrait; this.document.Info.Title = "Report Requested"; this.document.Info.Subject = "Demonstrates how to create an invoice."; this.document.Info.Author = "Stefan Lange"; DefineStyles(); CreatePage(child); try { List<ChildVaccination> tmp = vaccinations.Where(x => x.Vaccinated == true).ToList(); ChildVaccination tmpChild = vaccinations.FirstOrDefault(x => x.DueDate > DateTime.Today && x.Vaccinated == false); if (tmpChild != null) { tmp.Add(tmpChild); } FillContent(tmp, child, branch); CreateMeasurementsPage(measurements); FillMeasurementsContent(measurements); } catch (Exception ex) { } return this.document; }
public void SetChildForSession(string sessionId, Child child) { SetChildIdForSession(sessionId, child.IdNumber); AddChild(child); }
public void AddChild(Child child) { Children[child.IdNumber] = child; }
void FillContent(List<ChildVaccination> vaccinations , Child child, string branch) { Details.AddFormattedText("Name", TextFormat.Bold); Details.AddTab(); Details.AddTab(); Details.AddTab(); Details.AddTab(); Details.AddText(child.Name); Details.AddLineBreak(); Details.Format.Font.Size = 10; Details.AddFormattedText("Surname", TextFormat.Bold); Details.AddTab(); Details.AddTab(); Details.AddTab(); Details.AddText(child.Surname); Details.AddLineBreak(); Details.AddFormattedText("ID Number", TextFormat.Bold); Details.AddTab(); Details.AddTab(); Details.AddTab(); Details.AddText(child.IdNumber); Details.AddLineBreak(); Details.AddFormattedText("Blood Type", TextFormat.Bold); Details.AddTab(); Details.AddTab(); Details.AddTab(); Details.AddText(child.BloodType.ToString()); Details.AddLineBreak(); Details.AddLineBreak(); if (child.Mother != null) { Details.AddFormattedText("Mother: Name", TextFormat.Bold); Details.AddTab(); Details.AddTab(); Details.AddText(child.Mother.Name.ToString()); Details.AddLineBreak(); Details.AddFormattedText("Mother: Surname", TextFormat.Bold); Details.AddTab(); Details.AddTab(); Details.AddText(child.Mother.Surname.ToString()); Details.AddLineBreak(); Details.AddFormattedText("Mother: ID Number", TextFormat.Bold); Details.AddTab(); Details.AddText(child.Mother.IdNumber.ToString()); Details.AddLineBreak(); } Details.AddLineBreak(); if (child.Father != null) { Details.AddFormattedText("Father: Name", TextFormat.Bold); Details.AddTab(); Details.AddTab(); Details.AddText(child.Father.Name.ToString()); Details.AddLineBreak(); Details.AddFormattedText("Father: Surname", TextFormat.Bold); Details.AddTab(); Details.AddTab(); Details.AddText(child.Father.Surname.ToString()); Details.AddLineBreak(); Details.AddFormattedText("Father: ID Number", TextFormat.Bold); Details.AddTab(); Details.AddTab(); Details.AddText(child.Father.IdNumber.ToString()); Details.AddLineBreak(); } Details.AddLineBreak(); Details.AddLineBreak(); // Iterate the invoice items foreach (var vacc in vaccinations) { //if (vacc.Existing) //{ // Each item fills two rows Row row1 = this.table.AddRow(); //Row row2 = this.table.AddRow(); //row1.TopPadding = 1.5; //row1.Cells[0].Shading.Color = Colors.Gray; //row1.Cells[0].VerticalAlignment = VerticalAlignment.Center; //row1.Cells[0].MergeDown = 1; //row1.Cells[1].Format.Alignment = ParagraphAlignment.Left; //row1.Cells[1].MergeRight = 3; //row1.Cells[5].Shading.Color = Colors.Gray; //row1.Cells[5].MergeDown = 1; string dueDate = vacc.DueDate.HasValue ? vacc.DueDate.Value.ToShortDateString() : ""; row1.Cells[0].AddParagraph(dueDate); row1.Cells[1].AddParagraph(vacc.Name); string descr = !string.IsNullOrEmpty(vacc.Description) ? vacc.Description : ""; row1.Cells[2].AddParagraph(descr); row1.Cells[3].AddParagraph(vacc.DateVaccinated.HasValue ? vacc.DateVaccinated.Value.ToShortDateString() : ""); row1.Cells[4].AddParagraph(vacc.SerialNumber ?? ""); row1.Cells[5].AddParagraph(vacc.Signature ?? ""); row1.Cells[6].AddParagraph(branch); this.table.SetEdge(0, this.table.Rows.Count - 2, 6, 2, Edge.Box, BorderStyle.Single, 0.75); //} } // Add an invisible row as a space line to the table Row row = this.table.AddRow(); row.Borders.Visible = false; }
public ActionResult ChildVaccinations(Child child) { ViewBag.CurrentPage = "Children"; List<VaccinationDefinition> VaccinationDefs = db.VaccinationDefinitions. OrderBy(v => v.Age.Code). ToList(); List<Vaccination> childVaccinations = db.Vaccinations. Where(v => v.IdNumber == child.IdNumber). ToList(); List<ChildVaccination> Vaccinations = new List<ChildVaccination>(); foreach (var vaccine in VaccinationDefs) { ChildVaccination cv = new ChildVaccination() { Age = vaccine.Age, Code = vaccine.Code, ICDCode = vaccine.ICDCode, Description = vaccine.Description, Name = vaccine.Name, IdNumber = child.IdNumber, Id = vaccine.Id, }; Vaccination Vaccination = childVaccinations != null ? childVaccinations.Where(v => v.VaccinationDefinitionId == vaccine.Id).FirstOrDefault() : null; if (Vaccination != null) { cv.Vaccinated = true; cv.DateVaccinated = Vaccination.Date; cv.Existing = true; } else { cv.DateVaccinated = null; } Vaccinations.Add(cv); } Vaccinations = Vaccinations.OrderBy(x => x.Age.Code).ToList(); //VaccinationContainer vaxC = new VaccinationContainer() //{ // IdNumber = child.IdNumber, // Vaccinations = Vaccinations //}; return View(Vaccinations); }
void CreatePage(Child child) { // Each MigraDoc document needs at least one section. Section section = this.document.AddSection(); section.AddParagraph("Summary Report on " + child.Name + " " + child.Surname, "heading1"); //// Put a logo in the header //Image image = section.Headers.Primary.AddImage("../../PowerBooks.png"); //image.Height = "2.5cm"; //image.LockAspectRatio = true; //image.RelativeVertical = RelativeVertical.Line; //image.RelativeHorizontal = RelativeHorizontal.Margin; //image.Top = ShapePosition.Top; //image.Left = ShapePosition.Right; //image.WrapFormat.Style = WrapStyle.Through; //TextFrame header = section.Headers.Primary.AddTextFrame(); //Paragraph headerParagraph = header.AddParagraph(); //headerParagraph.AddText("Child Vaccinations"); // Create footer Paragraph paragraph = section.Footers.Primary.AddParagraph(); paragraph.Format.Font.Size = 9; paragraph.Format.Alignment = ParagraphAlignment.Center; //// Create the text frame for the address //this.addressFrame = section.AddTextFrame(); //this.addressFrame.Height = "3.0cm"; //this.addressFrame.Width = "7.0cm"; //this.addressFrame.Left = ShapePosition.Left; //this.addressFrame.RelativeHorizontal = RelativeHorizontal.Margin; //this.addressFrame.Top = "5.0cm"; //this.addressFrame.RelativeVertical = RelativeVertical.Page; //// Put sender in address frame //paragraph = this.addressFrame.AddParagraph("Hileya Trading PTY LTD"); //paragraph.Format.Font.Name = "Times New Roman"; //paragraph.Format.Font.Size = 7; //paragraph.Format.SpaceAfter = 3; // Add the print date field Details = section.AddParagraph(); //paragraph.AddDateField("dd.MM.yyyy"); var par = section.AddParagraph(); par.AddTab(); par.AddTab(); par.AddTab(); par.AddTab(); par.AddFormattedText("Vaccinations", TextFormat.Bold); par.AddLineBreak(); par.AddLineBreak(); // Create the item table this.table = section.AddTable(); this.table.Style = "Table"; this.table.Borders.Color = Colors.Black; this.table.Borders.Width = 0.25; this.table.Borders.Left.Width = 0.5; this.table.Borders.Right.Width = 0.5; this.table.Rows.LeftIndent = 0; // Before you can add a row, you must define the columns Column column = this.table.AddColumn("1.7cm"); column.Format.Alignment = ParagraphAlignment.Left; column = this.table.AddColumn("2cm"); column.Format.Alignment = ParagraphAlignment.Left; column = this.table.AddColumn("3cm"); column.Format.Alignment = ParagraphAlignment.Left; column = this.table.AddColumn("2.5cm"); column.Format.Alignment = ParagraphAlignment.Left; column = this.table.AddColumn("2cm"); column.Format.Alignment = ParagraphAlignment.Left; column = this.table.AddColumn("2.5cm"); column.Format.Alignment = ParagraphAlignment.Right; column = this.table.AddColumn("2.5cm"); column.Format.Alignment = ParagraphAlignment.Right; // Create the header of the table Row row = table.AddRow(); row.HeadingFormat = true; row.Format.Alignment = ParagraphAlignment.Center; row.Format.Font.Bold = true; row.Shading.Color = Color.FromCmyk(0, 46, 62, 10); row.Cells[0].AddParagraph("Date"); row.Cells[0].Format.Alignment = ParagraphAlignment.Left; row.Cells[0].VerticalAlignment = VerticalAlignment.Bottom; row.Format.Font.Color = Colors.White; row.Cells[1].AddParagraph("Vaccine Name"); row.Cells[1].Format.Alignment = ParagraphAlignment.Left; row.Cells[1].VerticalAlignment = VerticalAlignment.Bottom; row.Cells[2].AddParagraph("Description"); row.Cells[2].Format.Alignment = ParagraphAlignment.Left; row.Cells[2].VerticalAlignment = VerticalAlignment.Bottom; row.Cells[3].AddParagraph("Date Vaccinated"); row.Cells[3].Format.Alignment = ParagraphAlignment.Left; row.Cells[3].VerticalAlignment = VerticalAlignment.Bottom; row.Cells[4].AddParagraph("Batch Number"); row.Cells[4].Format.Alignment = ParagraphAlignment.Left; row.Cells[4].VerticalAlignment = VerticalAlignment.Bottom; row.Cells[5].AddParagraph("Nurse Signature"); row.Cells[5].Format.Alignment = ParagraphAlignment.Left; row.Cells[5].VerticalAlignment = VerticalAlignment.Bottom; row.Cells[6].AddParagraph("Branch"); row.Cells[6].Format.Alignment = ParagraphAlignment.Left; row.Cells[6].VerticalAlignment = VerticalAlignment.Bottom; //row = table.AddRow(); //row.HeadingFormat = true; //row.Format.Alignment = ParagraphAlignment.Center; //row.Format.Font.Bold = true; //row.Shading.Color = Colors.Blue; //row.Cells[1].AddParagraph("Quantity"); //row.Cells[1].Format.Alignment = ParagraphAlignment.Left; //row.Cells[2].AddParagraph("Unit Price"); //row.Cells[2].Format.Alignment = ParagraphAlignment.Left; //row.Cells[3].AddParagraph("Discount (%)"); //row.Cells[3].Format.Alignment = ParagraphAlignment.Left; //row.Cells[4].AddParagraph("Taxable"); //row.Cells[4].Format.Alignment = ParagraphAlignment.Left; //this.table.SetEdge(0, 0, 6, 2, Edge.Box, BorderStyle.Single, 0.75, Color.Empty); }
public ActionResult AddParent(Child child) { string branch = db.UserStatus.FirstOrDefault(x => x.Username == User.Identity.Name).Branch_Practice_No; ViewBag.CurrentPage = "Children"; if (child.Mother != null && !child.Mother.Found) { child.Mother.IdNumber = child.MotherId; child.Mother.Branch = branch; db.Parents.Add(child.Mother); db.SaveChanges(); } if (child.Father != null && !child.Father.Found) { child.Father.IdNumber = child.FatherId; child.Father.Branch = branch; db.Parents.Add(child.Father); db.SaveChanges(); } return RedirectToAction("ChildVaccinations", child); }
public ActionResult Edit(Child child) { ViewBag.CurrentPage = "Children"; if (ModelState.IsValid) { db.Entry(child).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(child); }
//public ActionResult Create([Bind(Include = "IdNumber,Surname,Name,BloodType,FatherId,MotherId")] Child child) public ActionResult Create(Child child) { ViewBag.CurrentPage = "Children"; if (ModelState.IsValid) { string loggedOnBranch = db.UserStatus.FirstOrDefault(x => x.Username == User.Identity.Name).Branch_Practice_No; child.Branch = loggedOnBranch; db.Children.Add(child); db.SaveChanges(); if (!string.IsNullOrEmpty(child.MotherId)) { child.Mother = FindParent(child.MotherId); } if (!string.IsNullOrEmpty(child.FatherId)) { child.Father = FindParent(child.FatherId); } _childService.SetChildForSession(User.Identity.Name, child); return RedirectToAction("AddMeasurements"); } return View(child); }
public ActionResult FullDetails(Child child) { ViewBag.CurrentPage = "Children"; return View(child); }
public ActionResult Details(Child child) { ViewBag.CurrentPage = "Children"; try { if (child == null || string.IsNullOrEmpty(child.IdNumber)) child = _childService.GetChildForSession(User.Identity.Name); VaccinationReport report = new VaccinationReport(); var usr = User; //User.Identity.Name UserStatus result = db.UserStatus.FirstOrDefault(x => x.Username == User.Identity.Name); string branch; if (result != null) { branch = result.Branch_Practice_No; Branch resultBranch = db.Branches1.FirstOrDefault(x => x.Practice_No == branch); if (resultBranch != null) { branch = resultBranch.Name; } else { branch = "Not Specified"; } } else { branch = "Not Specified"; } var measurements = from cust in db.ChildMeasurements where cust.ChildID == child.IdNumber select cust; ViewBag.measurementsList = measurements.ToList(); List<ChildMeasurement> measurementListLocal = measurements.ToList(); Document document = report.CreateDocument(Vaccinations, measurementListLocal, child, branch); //string ddl = MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToString(document); PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always); renderer.Document = document; renderer.RenderDocument(); using (MemoryStream stream = new MemoryStream()) { renderer.PdfDocument.Save(stream, false); return File(stream.ToArray(), "application/pdf"); } } catch (Exception ex) { return RedirectToAction("Index"); } //eturn RedirectToAction("Index"); }