private void PhieuTamTinh_Load(object sender, EventArgs e) { DataTable tb = new DataTable(); tb.Columns.Add("TenSP", typeof(string)); tb.Columns.Add("SoLuong", typeof(int)); tb.Columns.Add("GiaBan", typeof(decimal)); tb.Columns.Add("Tong", typeof(decimal)); List <ChiTietOrderDTO> list = ChiTietOrderDAO.Instance.GetListTamTinh(od.getID()); foreach (ChiTietOrderDTO ct in list) { decimal tamtinh = (decimal)ct.SoLuong * ct.SanPham.GiaBan; tb.Rows.Add(ct.SanPham.TenSP, ct.SoLuong, ct.SanPham.GiaBan, tamtinh); } phuthu = 0; giamgia = 0; thuevat = 0; ReportDataSource db = new ReportDataSource("DataSetPhieuTamTinh", tb); ReportParameter[] pm = new ReportParameter[6]; pm[0] = new ReportParameter("ngay", od.Thoigiantao.ToString("dd/MM/yyyy H:mm:ss")); pm[1] = new ReportParameter("ban", od.Ban.TenBan + " KV: " + od.Ban.KhuVuc.TenKV); pm[2] = new ReportParameter("thungan", od.NhanVien.TenNV); pm[3] = new ReportParameter("giamgia", giamgia.ToString()); pm[4] = new ReportParameter("phuthu", phuthu.ToString()); pm[5] = new ReportParameter("thue", thuevat.ToString()); this.reportViewer1.LocalReport.SetParameters(pm); this.reportViewer1.LocalReport.DataSources.Clear(); this.reportViewer1.LocalReport.DataSources.Add(db); this.reportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth; this.reportViewer1.RefreshReport(); }
private void BtnApDung_Click(object sender, EventArgs e) { if (tienthoi < 0) { MessageBox.Show("Khách chưa thanh toán đủ số tiền!"); } else { HoaDonDTO hd = new HoaDonDTO(); int maHT = HoaDonDAO.Instance.getNewCode(); string phanSau = maHT.ToString(); while (phanSau.Length < 18) { phanSau = "0" + phanSau; } hd.MaHD = "HD" + phanSau; hd.TenKH = od.KhachHang.TenKH; hd.MaKH = od.KhachHang.MaKH; hd.DiaChi = od.KhachHang.DiaChi; hd.MaSoThue = od.KhachHang.MaSoThue; hd.SoDienThoai = od.KhachHang.SoDienThoai; hd.NgayTao = od.Thoigiantao; hd.GiamGia = 0; hd.Thue = 0; hd.PhuThu = 0; hd.Tong = tongtien; hd.NhanVien = od.NhanVien.TenNV; try { if (HoaDonDAO.Instance.Insert(hd)) { List <ChiTietOrderDTO> list = ChiTietOrderDAO.Instance.GetListTamTinh(od.getID()); foreach (ChiTietOrderDTO ct in list) { ChiTietHoaDonDTO cthd = new ChiTietHoaDonDTO(); cthd.MaHD = hd.MaHD; cthd.SanPham = ct.SanPham.TenSP; cthd.MaSP = ct.SanPham.MaSP; cthd.SoLuong = ct.SoLuong; cthd.DonGia = ct.SanPham.GiaBan; if (!ChiTietHoaDonDAO.Instance.Insert(cthd)) { MessageBox.Show("Loi CT hoa DOn"); break; } } } } catch { MessageBox.Show("Loi them hoa don"); } BanDAO.Instance.SetTrangThai(3, od.Ban.MaBan); fmOrder.backToBanHang(); this.Close(); } }