private void btnInCTHD_Click(object sender, EventArgs e) { List <CHITIETHOADON> ds = CHITIETHOADONDAO.dsCTHDTheoMaHD(dsCTHD, cbboxMaHD.SelectedItem.ToString().Trim()); string line4 = ""; string mahd = ""; foreach (CHITIETHOADON sp in ds) { int lengthten = SANPHAMDAO.TenSP(QuanLyHangHoa.dsSP, sp.getMasp()).Length; int length = 20 - lengthten; string khoangcach = ""; for (int i = 0; i < length; i++) { khoangcach += " "; } mahd = sp.getMahd(); line4 += SANPHAMDAO.TenSP(QuanLyHangHoa.dsSP, sp.getMasp()) + khoangcach + sp.getSoluong() + " " + sp.thanhtien(SANPHAMDAO.GiaMaSP(QuanLyHangHoa.dsSP, sp.getMasp())) + "\n"; } string[] lines = { " Hóa Đơn\n", "Tên khách hàng: " + HOADONDAO.TenKhachHang(dsHD, mahd) + "\n", "Mã hóa đơn: " + mahd + "\n", "Tên Sản Phẩm Số lượng Thành tiền", line4, "Tổng tiền: " + txtTongTien.Text }; // WriteAllText creates a file, writes the specified string to the file, // and then closes the file. You do NOT need to call Flush() or Close(). System.IO.File.WriteAllLines(@"C:\DevPrograms\DoAnCongNghePhanMem (2)\Phan tich thiet ke HTTT\Phan tich thiet ke HTTT\BanIn\In.txt", lines); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = @"C:\DevPrograms\DoAnCongNghePhanMem (2)\Phan tich thiet ke HTTT\Phan tich thiet ke HTTT\BanIn\In.txt"; // Your absolute PATH Process.Start(startInfo); }
private void cbboxMaHD_SelectedIndexChanged(object sender, EventArgs e) { dgvCTHD.Rows.Clear(); dgvCTHD.Enabled = true; btnThemCTHD.Enabled = true; btnLuuCTHD.Enabled = false; btnSuaCTHD.Enabled = false; btnXoaCTHD.Enabled = false; btnInCTHD.Enabled = true; txtSoLuong.Enabled = false; List <CHITIETHOADON> ds = CHITIETHOADONDAO.dsCTHDTheoMaHD(dsCTHD, cbboxMaHD.SelectedItem.ToString().Trim()); foreach (CHITIETHOADON cthd in ds) { dgvCTHD.Rows.Add(cthd.getMahd(), SANPHAMDAO.TenSP(QuanLyHangHoa.dsSP, cthd.getMasp()), cthd.getSoluong(), cthd.thanhtien(SANPHAMDAO.GiaMaSP(QuanLyHangHoa.dsSP, cthd.getMasp()))); } txtTongTien.Text = "" + TongTien(); }