コード例 #1
0
        private void btnHoanThanh_Click(object sender, EventArgs e)
        {
            if (txtTenKhach.Text == "" || cmbTenNhanVien.SelectedIndex == -1)
            {
                MessageBox.Show("Chưa nhập đủ thông tin");
                return;
            }

            string tenKH   = txtTenKhach.Text;
            string ngayLap = dtpNgayLap.Value.Year.ToString() + "-"
                             + dtpNgayLap.Value.Month.ToString() + "-" + dtpNgayLap.Value.Day.ToString();
            int thanhTien = 0;

            try
            {
                thanhTien = Int32.Parse(txtThanhTien.Text);
            }
            catch (Exception ea) { Console.WriteLine(ea.Message); }

            string maNV = "";

            if (cmbTenNhanVien.SelectedIndex != -1)
            {
                maNV = nvBUL.TimMaNhanVien(cmbTenNhanVien.SelectedItem.ToString());
            }

            HoaDon hd = new HoaDon();

            hd.MaHoaDon     = 1;
            hd.TenKhachHang = tenKH;
            hd.Ngay         = ngayLap;
            hd.ThanhTien    = thanhTien;
            hd.MaNhanVien   = maNV;

            hdBUL.ThemHoaDon(hd);
            int a = hdBUL.TimMaHoaDonCuoiCung();

            foreach (SanPhamHoaDon ele in sphdBUL.LayGioHang())
            {
                ChiTietHoaDon cthd = new ChiTietHoaDon();
                cthd.MaHoaDon  = a;
                cthd.SoLuong   = ele.SoLuongMua;
                cthd.MaSanPham = spBUL.TimMaSanPhamTheoTen(ele.TenSanPham);
                cthdBUL.ThemChiTietHoaDon(cthd);
            }
            frmInHoaDon f = new frmInHoaDon();

            f.Show();
            sphdBUL.XoaBangSanPhamHoaDon();

            txtTenKhach.Text             = "";
            txtThanhTien.Text            = "";
            cmbTenNhanVien.SelectedIndex = -1;
            dgvListSanPhamMua.DataSource = null;
            //MessageBox.Show("Thành công");
        }