private void radialMenu1_Click(object sender, EventArgs e) { if (dgv_baocao.Rows.Count > 1) { PDFDocument4 pdf = new PDFDocument4(); pdf.PageSize = PaperFormat.pfA4; pdf.PageOrientation = PaperOrientation.pPortrait; int fnt = pdf.AddFont("Times New Roman", true, false, false, false, fontCharset.fcDefault); pdf.UseFont(fnt, 25); pdf.ShowUnicodeTextAt(lbl_baocao.Location.X - 70, lbl_baocao.Location.Y + 25, lbl_baocao.Text); pdf.UseFont(fnt, 12); pdf.ShowUnicodeTextAt(lbl_thang.Location.X - 80, lbl_thang.Location.Y + 10, lbl_thang.Text); pdf.ShowUnicodeTextAt(cbo_thang.Location.X - 80, cbo_thang.Location.Y + 10, cbo_thang.Text); int n = dgv_baocao.Rows.Count; int hoadon = pdf.AddTable(5, n, fnt, 12); pdf.SetTableColumnSize(hoadon, 0, 50); pdf.SetTableColumnSize(hoadon, 1, 200); pdf.SetTableColumnSize(hoadon, 2, 70); pdf.SetTableColumnSize(hoadon, 3, 70); pdf.SetTableColumnSize(hoadon, 4, 100); pdf.SetCellTableText(hoadon, 0, 0, "STT"); pdf.SetCellTableText(hoadon, 1, 0, "Thuốc"); pdf.SetCellTableText(hoadon, 2, 0, "Đơn giá"); pdf.SetCellTableText(hoadon, 3, 0, "Số lượng"); pdf.SetCellTableText(hoadon, 4, 0, "Số lần dùng"); pdf.SetCellTableTextAlign(hoadon, 0, 0, TextAlign.taCenter); pdf.SetCellTableTextAlign(hoadon, 1, 0, TextAlign.taCenter); pdf.SetCellTableTextAlign(hoadon, 2, 0, TextAlign.taCenter); pdf.SetCellTableTextAlign(hoadon, 3, 0, TextAlign.taCenter); pdf.SetCellTableTextAlign(hoadon, 4, 0, TextAlign.taCenter); int temp = 1; foreach (DataGridViewRow row in dgv_baocao.Rows) { if (row.Cells[0].Value != null) { pdf.SetCellTableText(hoadon, 0, temp, row.Cells[0].Value.ToString()); pdf.SetCellTableText(hoadon, 1, temp, row.Cells[1].Value.ToString()); pdf.SetCellTableText(hoadon, 2, temp, row.Cells[2].Value.ToString()); pdf.SetCellTableText(hoadon, 3, temp, row.Cells[3].Value.ToString()); pdf.SetCellTableText(hoadon, 4, temp, row.Cells[4].Value.ToString()); pdf.SetCellTableTextAlign(hoadon, 0, temp, TextAlign.taCenter); pdf.SetCellTableTextAlign(hoadon, 1, temp, TextAlign.taLeft); pdf.SetCellTableTextAlign(hoadon, 2, temp, TextAlign.taCenter); pdf.SetCellTableTextAlign(hoadon, 3, temp, TextAlign.taCenter); pdf.SetCellTableTextAlign(hoadon, 4, temp, TextAlign.taCenter); temp++; } } pdf.ShowTable(hoadon, dgv_baocao.Location.X + 25, dgv_baocao.Location.Y, 1, 1); pdf.ShowUnicodeTextAt(lbl_tong.Location.X + 20, dgv_baocao.Location.Y + 10 + 20 * n, lbl_tong.Text); pdf.ShowUnicodeTextAt(lbl_thanhchu.Location.X + 20, dgv_baocao.Location.Y + 30 + 20 * n, lbl_thanhchu.Text); pdf.ShowUnicodeTextAt(dgv_baocao.Location.X + 275, dgv_baocao.Location.Y + 50 + 20 * n, "Tp.Hồ Chí Minh, ngày " + string.Format("{0:dd}", DateTime.Now.Date) + " tháng " + string.Format("{0:MM}", DateTime.Now.Date) + " năm " + DateTime.Now.Year.ToString()); pdf.ShowUnicodeTextAt(dgv_baocao.Location.X + 350, dgv_baocao.Location.Y + 70 + 20 * n, "Người lập báo cáo"); timer1.Start(); timer1.Enabled = true; lbl_thongbao.ForeColor = Color.Red; lbl_thongbao.Text = "Lưu thành công"; timer1_Tick(sender, e); pdf.SaveToFile(lbl_path.Text + "\\bao cao thuoc (" + string.Format("{0:MM-yyyy}", NgayDauThang(cbo_thang.Text)) + ").pdf", true); rd_in_MouseLeave(sender, e); } else { DevComponents.DotNetBar.MessageBoxEx.Show("Bạn cần xem báo cáo trước khi in!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); cbo_thang.Focus(); } }
private void rd_xuat_Click(object sender, EventArgs e) { if (dgv_thuoc.Rows.Count > 1) { int now = dgv_benhnhan.CurrentCell.RowIndex; int k = int.Parse(dgv_benhnhan.Rows[now].Cells[0].Value.ToString()); int MaBenhNhan = int.Parse(PHIEUKHAMBENH_BUS.LoadDaKham().Rows[k - 1][0].ToString()); PDFDocument4 pdf = new PDFDocument4(); pdf.PageSize = PaperFormat.pfA4; pdf.PageOrientation = PaperOrientation.pPortrait; int fnt = pdf.AddFont("Times New Roman", true, false, false, false, fontCharset.fcDefault); pdf.UseFont(fnt, 25); pdf.ShowUnicodeTextAt(lbl_hoadon.Location.X + 20, lbl_hoadon.Location.Y + 20, lbl_hoadon.Text); pdf.UseFont(fnt, 12); pdf.ShowUnicodeTextAt(lbl_hoten.Location.X + 20, lbl_hoten.Location.Y + 20, lbl_hoten.Text); pdf.ShowUnicodeTextAt(lbl_ngaykham.Location.X + 20, lbl_ngaykham.Location.Y + 20, lbl_ngaykham.Text); pdf.ShowUnicodeTextAt(lbl_tienkham.Location.X + 20, lbl_tienkham.Location.Y + 20, lbl_tienkham.Text); pdf.ShowUnicodeTextAt(lbl_tienthuoc.Location.X + 20, lbl_tienthuoc.Location.Y + 20, lbl_tienthuoc.Text); int n = dgv_thuoc.Rows.Count; int hoadon = pdf.AddTable(4, n, fnt, 12); pdf.SetTableColumnSize(hoadon, 0, 50); pdf.SetTableColumnSize(hoadon, 1, 200); pdf.SetTableColumnSize(hoadon, 2, 70); pdf.SetTableColumnSize(hoadon, 3, 70); pdf.SetCellTableText(hoadon, 0, 0, "STT"); pdf.SetCellTableText(hoadon, 1, 0, "Tên thuốc"); pdf.SetCellTableText(hoadon, 2, 0, "Số Lượng"); pdf.SetCellTableText(hoadon, 3, 0, "Đơn giá"); pdf.SetCellTableTextAlign(hoadon, 0, 0, TextAlign.taCenter); pdf.SetCellTableTextAlign(hoadon, 1, 0, TextAlign.taCenter); pdf.SetCellTableTextAlign(hoadon, 2, 0, TextAlign.taCenter); pdf.SetCellTableTextAlign(hoadon, 3, 0, TextAlign.taCenter); int temp = 1; foreach (DataGridViewRow row in dgv_thuoc.Rows) { if (row.Cells[0].Value != null) { pdf.SetCellTableText(hoadon, 0, temp, row.Cells[0].Value.ToString()); pdf.SetCellTableText(hoadon, 1, temp, row.Cells[1].Value.ToString()); pdf.SetCellTableText(hoadon, 2, temp, row.Cells[2].Value.ToString()); pdf.SetCellTableText(hoadon, 3, temp, row.Cells[3].Value.ToString()); pdf.SetCellTableTextAlign(hoadon, 0, temp, TextAlign.taCenter); pdf.SetCellTableTextAlign(hoadon, 1, temp, TextAlign.taLeft); pdf.SetCellTableTextAlign(hoadon, 2, temp, TextAlign.taCenter); pdf.SetCellTableTextAlign(hoadon, 3, temp, TextAlign.taCenter); temp++; } } pdf.ShowTable(hoadon, dgv_thuoc.Location.X + 70, dgv_thuoc.Location.Y + 20, 1, 1); pdf.ShowUnicodeTextAt(lbl_tong.Location.X + 20, dgv_thuoc.Location.Y + 30 + 20 * n, lbl_tong.Text); pdf.ShowUnicodeTextAt(lbl_thanhchu.Location.X + 20, dgv_thuoc.Location.Y + 50 + 20 * n, lbl_thanhchu.Text); pdf.ShowUnicodeTextAt(dgv_thuoc.Location.X + 300, dgv_thuoc.Location.Y + 70 + 20 * n, "Tp.Hồ Chí Minh, ngày " + string.Format("{0:dd}", DateTime.Now.Date) + " tháng " + string.Format("{0:MM}", DateTime.Now.Date) + " năm " + DateTime.Now.Year.ToString()); pdf.ShowUnicodeTextAt(dgv_thuoc.Location.X + 380, dgv_thuoc.Location.Y + 90 + 20 * n, "Chữ ký bác sỹ"); timer1.Start(); timer1.Enabled = true; lbl_thongbao.ForeColor = Color.Red; lbl_thongbao.Text = "Lưu thành công"; timer1_Tick(sender, e); pdf.SaveToFile(lbl_path.Text + "\\" + MaBN(MaBenhNhan) + ".pdf", true); } else { DevComponents.DotNetBar.MessageBoxEx.Show("Chưa chọn bệnh nhân cần in hóa đơn!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_ten.Focus(); } }