private void xuatFileExcel() { ExcelExport ex = new ExcelExport(); List <QL_ChiTietHoaDon> dsKhoa = lstChiTiet; if (dsKhoa.Count == 0) { MessageBox.Show("Không có dữ liệu"); } QL_HoaDon_BanHang hdbh = hd_bll.layHD(maHD); List <QL_ChiTietHoaDon> pListSP = new List <QL_ChiTietHoaDon>(); if (checkDungDiem.Checked) { hdbh.DiemDung = diemDung; } hdbh.TongTienThat = Convert.ToInt32(lbTongTien.Text); // Đỗ dữ liệu vào danh sách int Stt = 1; foreach (QL_ChiTietHoaDon item in dsKhoa) { QL_ChiTietHoaDon chitiet = new QL_ChiTietHoaDon(); QL_SanPham sphientai = sp_bll.laySP(item.MaSP); chitiet.TenSanPham = sphientai.TenSanPham; chitiet.DonGia = item.DonGia; chitiet.Soluong = item.Soluong; chitiet.STT = Stt.ToString(); Stt++; pListSP.Add(chitiet); } string path = string.Empty; ex.ExportKhoa(hdbh, pListSP, ref path, false); if (!string.IsNullOrEmpty(path) && MessageBox.Show("Bạn có muốn mở file", "Xác Nhận", MessageBoxButtons.YesNo) == DialogResult.Yes) { System.Diagnostics.Process.Start(path); } }
private void btn_In_Dong_Click(object sender, EventArgs e) { try { double d = double.Parse(txt_TienTraLai.Text); if (d < 0) { MessageBox.Show("Mời nhập tiền"); return; } } catch (Exception ee) { MessageBox.Show("Mời nhập tiền"); return; } try { //th1: khach mua mang di if (ca.getFlag() == 0) { DateTime dt = DateTime.Now; int maB = ca.getMaBan(); int maNV = ca.getMaNV(); String PT = "Cash"; double tong = ca.tinhTong(); String TT = "Roi"; int x = hd.LuuHoaDon2(dt, maB, maNV, PT, tong, TT); List <Item> lstCart = ca.getCart(); foreach (Item i in lstCart) { int maHD = x; int maMon = i.maMon; int sl = i.sl; double tong2 = i.tongTien; ct.LuuChiTietHD(maHD, maMon, sl, tong2); } //thong bao xong ca.clearCard2(); ca.clearCard(); this.Dispose(); if (Program.frmCNC.Visible == false) { Program.frmCNC = new Form_ChucNangChinh(); } Program.frmCNC.Show(); MessageBox.Show("Thanh Toán Thành Công"); //goi hd ra tblHoaDon hoaDon = hd.getMaHDTheoMaHD(x); //xuat file excel ExcelExport ex = new ExcelExport(); List <tblChiTietHD> lstCTExcel = ct.getCTByMaHD(x).ToList(); string path = string.Empty; DateTime?dtVao = hoaDon.TGVao; DateTime?dtRa = hoaDon.TGRa; double tien1 = 0; double tien2 = 0; try { tien1 = double.Parse(txt_TienKhachDua.Text); tien2 = double.Parse(txt_TienTraLai.Text); } catch (Exception ee) { tien1 = 0; tien2 = 0; } ex.ExportKhoa(lstCTExcel, ref path, false, dtVao.Value, dtRa.Value, (double)hoaDon.TongTienTT, lstCTExcel.Count, tien1, tien2, x, hoaDon.MaBan, hoaDon.MaNV); if (!string.IsNullOrEmpty(path) && MessageBox.Show("Bạn muốn mở file", "Thông tin", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { System.Diagnostics.Process.Start(path); } } if (ca.getFlag() == 1) { //khach tinh tien sau khi ngoi tai quan int maHDExcel = 0; if (ca.getCart2().Count == 0) { tblHoaDon h = hd.getMaHDTheoBan(ca.getMaBan()); maHDExcel = h.MaHD; //DateTime dt = DateTime.Today; DateTime dt = DateTime.Now; hd.suaHoaDon(h.MaHD, dt, "Roi"); ca.clearCard2(); ca.clearCard(); this.Dispose(); if (Program.frmCNC.Visible == false) { Program.frmCNC = new Form_ChucNangChinh(); } Program.frmCNC.Show(); } //khach ngoi tai quan nhung order them roi tinh tien luon else if (ca.getCart2().Count > 0) { tblHoaDon h = hd.getMaHDTheoBan(ca.getMaBan()); maHDExcel = h.MaHD; List <tblChiTietHD> lstCT = ct.getCTByMaHD(h.MaHD).ToList <tblChiTietHD>(); List <Item> lstCart = ca.getCart2(); double tong1 = ca.tinhTong2(); //update lai chi tiet for (int i = 0; i < lstCT.Count; i++) { for (int j = 0; j < lstCart.Count; j++) { if (lstCT[i].MaMon == lstCart[j].maMon) { ct.suaChiTietHD(lstCT[i].MaHD, lstCT[i].MaMon, (lstCart[j].sl + lstCT[i].SoLuong), (lstCart[j].tongTien + (double)lstCT[i].TongTien)); lstCart.Remove(lstCart[j]); j--; } } } //them cac chi tiet moi foreach (Item i in lstCart) { int maHD = h.MaHD; int maMon = i.maMon; int sl = i.sl; double tong = i.tongTien; ct.LuuChiTietHD(maHD, maMon, sl, tong); } //update lai tong tien cho hoa don hd.suaHoaDon(h.MaHD, (tong1 + (double)h.TongTienTT)); //update lai trang thai DateTime dt = DateTime.Now; hd.suaHoaDon(h.MaHD, dt, "Roi"); //thong bao xong ca.clearCard2(); ca.clearCard(); this.Dispose(); if (Program.frmCNC.Visible == false) { Program.frmCNC = new Form_ChucNangChinh(); } Program.frmCNC.Show(); } MessageBox.Show("Thanh Toán Thành Công"); //goi hoa don ra tblHoaDon hoaDon = hd.getMaHDTheoMaHD(maHDExcel); //xuat file excel ExcelExport ex = new ExcelExport(); List <tblChiTietHD> lstCTExcel = ct.getCTByMaHD(maHDExcel).ToList(); string path = string.Empty; DateTime?dtVao = hoaDon.TGVao; DateTime?dtRa = hoaDon.TGRa; double tien1 = 0; double tien2 = 0; try { tien1 = double.Parse(txt_TienKhachDua.Text); tien2 = double.Parse(txt_TienTraLai.Text); } catch (Exception ee) { tien1 = 0; tien2 = 0; } ex.ExportKhoa(lstCTExcel, ref path, false, dtVao.Value, dtRa.Value, (double)hoaDon.TongTienTT, lstCTExcel.Count, tien1, tien2, maHDExcel, hoaDon.MaBan, hoaDon.MaNV); if (!string.IsNullOrEmpty(path) && MessageBox.Show("Bạn muốn mở file", "Thông tin", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { System.Diagnostics.Process.Start(path); } } } catch (Exception ee) { } }