// hiển thị hóa đơn public void loadBill(int id) { dgrBillInfo.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; BillInfoDAL billInfoDAL = new BillInfoDAL(); DataTable data = billInfoDAL.getBillInfoByIdBill(id); dgrBillInfo.DataSource = data; // hien thi tổng tiền hiện tại this.total = 0; foreach (DataRow row in data.Rows) { this.total = total + Convert.ToInt32(row.ItemArray[5].ToString()); } lbTotal.Text = total.ToString(); // cap nhat lai tong tin hao don BilDAL billDAL = new BilDAL(); billDAL.updateTotalBill(id, total); }
private void _CreateReceipt(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Graphics graphic = e.Graphics; Font font = new Font("Courier New", 12); float FontHeight = font.GetHeight(); int startX = 10; int startY = 10; int offset = 40; graphic.DrawString(" NHÀ HÀNG ẨM THỰC ADNB", new Font("Courier New", 18), new SolidBrush(Color.Black), startX, startY); offset = offset + (int)FontHeight + 5; graphic.DrawString(" HOÁ ĐƠN BÁN HÀNG", new Font("Courier New", 18), new SolidBrush(Color.Black), startX, startY + offset); offset = offset + (int)FontHeight + 20; string top = "Tên Sản Phẩm".PadRight(24) + "Số lượng".PadRight(10) + "Đơn giá".PadRight(10) + "Thành Tiền"; graphic.DrawString(top, font, new SolidBrush(Color.Black), startX, startY + offset); offset = offset + (int)FontHeight; graphic.DrawString("--------------------------------------------------------------", font, new SolidBrush(Color.Black), startX, startY + offset); offset = offset + (int)FontHeight + 5; BillInfoDAL billInfoDAL = new BillInfoDAL(); DataTable data = billInfoDAL.getBillInfoByIdBill(idBill); for (int i = 0; i < data.Rows.Count; i++) { graphic.DrawString(data.Rows[i].ItemArray[1].ToString(), font, new SolidBrush(Color.Black), startX, startY + offset); graphic.DrawString(data.Rows[i].ItemArray[3].ToString(), font, new SolidBrush(Color.Black), startX + 250, startY + offset); graphic.DrawString(data.Rows[i].ItemArray[4].ToString(), font, new SolidBrush(Color.Black), startX + 350, startY + offset); graphic.DrawString(data.Rows[i].ItemArray[5].ToString(), font, new SolidBrush(Color.Black), startX + 450, startY + offset); offset = offset + (int)FontHeight + 5; //xuong 1 dong } offset = offset + 10; graphic.DrawString("--------------------------------------------------------------", font, new SolidBrush(Color.Black), startX, startY + offset); offset = offset + 10; graphic.DrawString("TỔNG TIỀN TRẢ ", new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startX, startY + offset); graphic.DrawString(this.total.ToString(), new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startX + 450, startY + offset); try { AccountDAL accDAL = new AccountDAL(); Employee emp = accDAL.getEmployeeByAccount(this.acc.UserName); offset = offset + (int)FontHeight + 10; graphic.DrawString("Nhân viên : " + emp.Name, font, new SolidBrush(Color.Black), startX, startY + offset); } catch { } offset = offset + (int)FontHeight + 15; graphic.DrawString(" CẢM ƠN BẠN ĐÃ GHÉ THĂM!,", font, new SolidBrush(Color.Black), startX, startY + offset); offset = offset + (int)FontHeight + 5; graphic.DrawString(" HI VỌNG BẠN SẼ GHÉ THĂM LẠI!", font, new SolidBrush(Color.Black), startX, startY + offset); }