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"); }
public Form1(int Authority, string name) { //init MainForm this.TopLevel = true; InitializeComponent(); //init delegate TuThuocForm.refreshMedicines4MainForm = new Clinic.TuThuocForm.RefreshMedicines4MainForm(InitComboboxMedicinesMySql); Services.refreshMedicines4MainForm = new Clinic.Services.RefreshMedicines4MainForm(InitComboboxMedicinesMySql); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Text = "Phòng Khám -" + "User: "******"Loading Database"); //Load Settings if (mainFormSettings == null) { mainFormSettings = CreateMainFormSetttingsFromFile(); } this.checkBoxShowBigForm.Checked = mainFormSettings.ShowBigForm; this.checkBoxShow1Record.Checked = mainFormSettings.ShowOneRecord; this.checkBoxShowMedicines.Checked = mainFormSettings.ShowMedicines; this.Enabled = false; BackgroundWorker backgroundWorkerLoadingDatabase = new BackgroundWorker(); backgroundWorkerLoadingDatabase.WorkerSupportsCancellation = true; backgroundWorkerLoadingDatabase.DoWork += new DoWorkEventHandler(backgroundWorkerLoadingDatabase_DoWork); backgroundWorkerLoadingDatabase.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorkerLoadingDatabase_RunWorkerCompleted); backgroundWorkerLoadingDatabase.RunWorkerAsync(); this.textBoxReason.Visible = false; List<string> listLoaiKham = Helper.GetAllLoaiKham(this.db); this.comboBoxLoaiKham.Items.AddRange(listLoaiKham.ToArray()); comboBoxLoaiKham.Text = "Loại Khám: "; listDiagnosesFromHistory = Helper.GetAllDiagnosesFromHistory(this.db); this.txtBoxClinicRoomDiagnose.AutoCompleteCustomSource.AddRange(listDiagnosesFromHistory.ToArray()); this.StartPosition = FormStartPosition.CenterScreen; //this.WindowState = Clinic.Properties.Settings.Default.State; //if (this.WindowState == FormWindowState.Normal) this.Size = Clinic.Properties.Settings.Default.Size; this.Resize += new System.EventHandler(this.Form1_Resize); try { XmlSerializer xmlSerializer = new XmlSerializer(typeof(InfoClinic)); StreamReader sr = new StreamReader("Information.xml"); infoClinic = xmlSerializer.Deserialize(sr) as InfoClinic; textBoxNameClinic.Text = infoClinic.Name; textBoxAddressClinic.Text = infoClinic.Address; textBoxAdviceClinic.Text = infoClinic.Advice; textBoxSDT.Text = infoClinic.Sdt; textBoxBackupSource.Text = infoClinic.PathData; textBoxBackupTarget.Text = infoClinic.PathTargetBackup; textBoxBackupTimeAuto.Text = infoClinic.TimeBackup; bool temp = bool.Parse(infoClinic.CheckedBackup1.ToLower()); if (temp) { checkBoxAutoCopy.CheckState = CheckState.Checked; } sr.Close(); } catch (Exception exx) { } try { // do any background work //do not change InitComboboxMedicinesMySql(); InitClinicRoom(); dataGridView4.Visible = false; maxIdOfCalendarItem = Helper.SearchMaxValueOfTable(db,"calendar", "IdCalendar", "DESC"); // //Load calendar // List<ADate> listDate = Helper.GetAllDateOfUser(UserName, db); foreach (ADate item in listDate) { CalendarItem cal = new CalendarItem(calendar1, item.StartTime, item.EndTime, item.Text); cal.Tag = item.Id; if (item.color != 0) { cal.ApplyColor(Helper.ConvertCodeToColor(item.color)); } _items.Add(cal); } PlaceItems(); //load lichhen LoadLichHen(DateTime.Now); //xoa listtoday XoaListToday(); } catch (Exception ex) { // log errors } listPatientForm = new Clinic.ListPatientsTodayForm(); listPatientForm.sendCommandKham = new Clinic.ListPatientsTodayForm.SendCommandKham(KhamVaXoa); SearchForm.sendCommand = new Clinic.SearchForm.SendCommandProcessFromSearchForm(this.ProcessWhenUserDoubleClickOnSearch); ///favouriteForm.sendCommand = new Form2.SendCommand(PlayFromFavouriteForm); /// this.ColumnID.Width = 50; this.ColumnNamePatient.Width = 150; this.ColumnNgaySinh.Width = 100; this.ColumnNgayKham.Width = 100; this.ColumnAddress.Width = 100; this.ColumnSymtom.Width = 100; this.ColumnNhietDo.Width = 50; this.ColumnHuyetAp.Width = 50; this.ColumnDiagno.Width = 150; this.ColumnSearchValueMedicines.Width = 250; this.circularProgress1.Hide(); TimerGetId = new System.Windows.Forms.Timer(); TimerGetId.Tick+=new EventHandler(TimerGetId_Tick); TimerGetId.Interval = 2000; TimerGetId.Start(); try { SieuAmManager.Instance.Capture.PreviewWindow = this.panelPreviewVideo; } catch { } }
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); }
private void button1_Click(object sender, EventArgs e) { InfoClinic infoClinic = new InfoClinic(); infoClinic.Name = textBoxNameClinic.Text; infoClinic.Address = textBoxAddressClinic.Text; infoClinic.Advice = textBoxAdviceClinic.Text; infoClinic.Sdt = textBoxSDT.Text; infoClinic.PathData = textBoxBackupSource.Text; infoClinic.PathTargetBackup = textBoxBackupTarget.Text; infoClinic.CheckedBackup1 = checkBoxAutoCopy.Checked.ToString(); infoClinic.TimeBackup = textBoxBackupTimeAuto.Text; XmlSerializer serializer = new XmlSerializer(infoClinic.GetType()); StreamWriter sw = new StreamWriter("Information.xml"); serializer.Serialize(sw, infoClinic); sw.Close(); MessageBox.Show("Thay đổi thành công, yêu cầu chạy lại chương trình để áp dụng thông tin mới", "Thông báo!"); }