public static void CreateAPdf(InfoClinic InformationOfClinic, string MaBn, Patient patient, List<Medicine> Medicines, string taikham, string Diagno, string tuoi,int Stt,string reasonComeBack) { Document document = new Document(); document.Info.Author = "Luong Y"; Unit width, height; PageSetup.GetPageSize(PageFormat.A5, out width, out height); document.DefaultPageSetup.PageWidth = width; document.DefaultPageSetup.PageHeight = height; int tongTienThuoc = 0; AddSection(document, InformationOfClinic, MaBn, patient, Medicines, false, taikham, ref tongTienThuoc, Diagno, tuoi, Stt, reasonComeBack); AddSection(document, InformationOfClinic, MaBn, patient, Medicines, true, taikham, ref tongTienThuoc, Diagno, tuoi, Stt, reasonComeBack); //document.LastSection.AddPageBreak(); PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always); pdfRenderer.Document = document; pdfRenderer.RenderDocument(); pdfRenderer.PdfDocument.Save("firstpage.pdf"); }
private static void AddSection(Document document, InfoClinic InformationOfClinic, string MaBn, Patient patient, List<Medicine> Medicines, bool onlyServices, string taikham, ref int tongTienThuoc, string Diagno, string tuoi, int Stt, string reasonComeBack) { Section section = document.AddSection(); section.PageSetup.LeftMargin = 10; Paragraph paragraph =section.Headers.Primary.AddParagraph(); //= section.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Left; paragraph.AddText(InformationOfClinic.Name); //+"Mã BN: " + patient.Id + " \n" +" Địa chỉ xxxxx"); paragraph.AddText(" \n"); string[] addressArray = InformationOfClinic.Address.Split(';'); paragraph.AddSpace(int.Parse(addressArray[0])); paragraph.AddText(addressArray[1]); paragraph.AddText(" \n"); string[] sdtArray = InformationOfClinic.Sdt.Split(';'); paragraph.AddSpace(int.Parse(sdtArray[0])); paragraph.AddText(sdtArray[1]); Paragraph paragraph2 = section.Headers.Primary.AddParagraph(); paragraph2.Format.Alignment = ParagraphAlignment.Right; paragraph2.AddText("ID : " + MaBn); paragraph2.AddText(" \n"); paragraph2.AddText("STT : " + Stt); paragraph.AddText(" \n"); paragraph.AddText(" \n"); paragraph.AddText(" \n"); paragraph.AddText(" \n"); //Table InfoTable = section.AddTable(); //InfoTable.Borders.Width = 0; //Column ColumnInfo1 = InfoTable.AddColumn(500); //Row rowInfoName = InfoTable.AddRow(); //Paragraph para1 = rowInfoName.Cells[0].AddParagraph(InformationOfClinic.Name); //Row rowInfo2 = InfoTable.AddRow(); //Paragraph paraInfo = rowInfo2.Cells[0].AddParagraph(); //paraInfo.AddSpace(4); //paraInfo.AddText(InformationOfClinic.Address); //rowsignatureAndMore2.Cells[0].AddParagraph(taikham); //Paragraph para = rowsignatureAndMore2.Cells[2].AddParagraph(" \n \n \n \n" + Form1.nameOfDoctor); //para.Format.Alignment = ParagraphAlignment.Center; Paragraph paragraphTitle = section.AddParagraph(); paragraphTitle.Format.Alignment = ParagraphAlignment.Center; paragraphTitle.AddTab(); paragraphTitle.AddTab(); if (!onlyServices) { paragraphTitle.AddFormattedText("TOA THUỐC \n \n", new MigraDoc.DocumentObjectModel.Font("Times New Roman", 24)); } else { paragraphTitle.AddFormattedText("Bảng Dịch Vụ \n \n", new MigraDoc.DocumentObjectModel.Font("Times New Roman", 24)); } Table table = new Table(); table.Borders.Width = 0; Column column = table.AddColumn(); column.Width = 80; table.AddColumn(440); Row row = table.AddRow(); row.Cells[0].AddParagraph("Bệnh nhân: "); row.Cells[1].AddParagraph(patient.Name); //int tuoi = DateTime.Now.Year - patient.Birthday.Year; row.Cells[0].AddParagraph("Tuổi:"); row.Cells[1].AddParagraph(tuoi); Row row2 = table.AddRow(); row2.Cells[0].AddParagraph("Địa chỉ: "); row2.Cells[1].AddParagraph(patient.Address); //row2.Cells[2].AddParagraph("Mã BN: "+ patient.Id); if (!onlyServices) { Row row3 = table.AddRow(); row3.Cells[0].AddParagraph("Chẩn đoán: "); row3.Cells[1].AddParagraph(Diagno); } Table tableMedicines = new Table(); tableMedicines.Borders.Width = 0; tableMedicines.BottomPadding = 10; Column columnMedicines1 = tableMedicines.AddColumn(30); Column columnMedicines2; if (onlyServices) { columnMedicines2 = tableMedicines.AddColumn(140); } else { columnMedicines2 = tableMedicines.AddColumn(240); } Column columnMedicines3 = tableMedicines.AddColumn(70); Column columnMedicines4 = tableMedicines.AddColumn(130); Row rowMedicinesHeader = tableMedicines.AddRow(); rowMedicinesHeader.Cells[0].AddParagraph("STT"); if (!onlyServices) { rowMedicinesHeader.Cells[1].AddParagraph("Tên thuốc/Cách dùng"); } else { rowMedicinesHeader.Cells[1].AddParagraph("Tên dịch vụ"); } rowMedicinesHeader.Cells[2].AddParagraph("Số lượng"); if (onlyServices) { rowMedicinesHeader.Cells[3].AddParagraph("Số tiền"); int totalServices = 0; int indexServices = 1; for (int i = 0; i < Medicines.Count; i++) { if (Medicines[i].Name[0] == '@') { string name = Medicines[i].Name.Substring(1, Medicines[i].Name.Length - 1); Row rowDetail = tableMedicines.AddRow(); rowDetail.Cells[0].AddParagraph(indexServices.ToString()); rowDetail.Cells[1].AddParagraph(name + "\n" + Medicines[i].HDSD); rowDetail.Cells[2].AddParagraph(Medicines[i].Number.ToString()); rowDetail.Cells[3].AddParagraph(Medicines[i].CostOut.ToString("C0")); indexServices++; totalServices += Medicines[i].CostOut; } } //tong cong thuoc Row rowTotalThuoc = tableMedicines.AddRow(); rowTotalThuoc.Cells[1].AddParagraph("Thuốc"); rowTotalThuoc.Cells[3].AddParagraph(tongTienThuoc.ToString("C0")); Row gachdit = tableMedicines.AddRow(); gachdit.Cells[3].AddParagraph("________________"); int total = totalServices + tongTienThuoc; Row rowTotal = tableMedicines.AddRow(); rowTotal.Cells[2].AddParagraph("Tổng cộng:"); rowTotal.Cells[3].AddParagraph(total.ToString("C0")); } else { int indexMedicines = 1; for (int i = 0; i < Medicines.Count; i++) { if (Medicines[i].Name[0] != '@') { Row rowDetail = tableMedicines.AddRow(); rowDetail.Cells[0].AddParagraph(indexMedicines.ToString()); rowDetail.Cells[1].AddParagraph(Medicines[i].Name + "\n" + Medicines[i].HDSD); rowDetail.Cells[2].AddParagraph(Medicines[i].Number.ToString()); indexMedicines++; tongTienThuoc += Medicines[i].CostOut; } } } //Table loi dan , chu ky Table signatureAndMore = new Table(); signatureAndMore.Borders.Width = 0; Column columnsignatureAndMore1 = signatureAndMore.AddColumn(150); Column columnsignatureAndMore2 = signatureAndMore.AddColumn(50); Column columnsignatureAndMore3 = signatureAndMore.AddColumn(210); Row rowsignatureAndMore1 = signatureAndMore.AddRow(); if (!onlyServices) { // rowsignatureAndMore1.Cells[0].AddParagraph("Lời dặn: " + InformationOfClinic.Advice); } Paragraph paramNgayThang = rowsignatureAndMore1.Cells[2].AddParagraph("Ngày " + DateTime.Now.Day + " tháng " + DateTime.Now.Month + " năm " + DateTime.Now.Year); paramNgayThang.Format.Alignment = ParagraphAlignment.Center; Row rowsignatureAndMore2 = signatureAndMore.AddRow(); rowsignatureAndMore2.VerticalAlignment = VerticalAlignment.Center; rowsignatureAndMore2.Cells[0].AddParagraph(taikham + ": " + reasonComeBack); Paragraph para = rowsignatureAndMore2.Cells[2].AddParagraph(" \n \n \n \n" + Form1.nameOfDoctor); para.Format.Alignment = ParagraphAlignment.Center; document.LastSection.Add(table); document.LastSection.AddParagraph("\n"); document.LastSection.Add(tableMedicines); document.LastSection.AddParagraph("\n"); document.LastSection.Footers.Primary.Add(signatureAndMore); }