Esempio n. 1
0
        private void btnXacNhan_Click(object sender, EventArgs e)
        {
            //Them Hoa Don và hỏi có thêm chi tiết không ?
            if (txtTenSP.Text == "" || txtKhachHang.Text == "")
            {
                MessageBox.Show("Chưa thêm thông tin sản phẩm....!", "Thông Báo lỗi");
            }
            else
            {
                try
                {
                    mahd = _hdService.SinhMaHoaDon();
                    HoaDon    hd   = new HoaDon();
                    Ct_HoaDon cthd = new Ct_HoaDon();
                    hd.mahd     = mahd;
                    hd.makh     = txtKhachHang.Text.Trim().Split('-')[0];
                    hd.manv     = txtMaNV.Text.Trim();
                    hd.ngayxuat = DateTime.Parse(txtNgayLap.Text.Trim());
                    hd.tongtien = 0;

                    cthd.mahang    = txtTenSP.Text.Trim().Split('-')[0];
                    cthd.mahd      = mahd;
                    cthd.soluong   = decimal.Parse(txtSoLuong.Text.Trim());
                    cthd.giaban    = decimal.Parse(txtGiaBan.Text.Trim());
                    cthd.thanhtien = decimal.Parse(txtThanhTien.Text.Trim());

                    if (_hdService.ThemHoaDon(hd))
                    {
                        _main.dataGridView2.DataSource = _hdService.DanhSachHoaDon();
                        if (_hdService.ThemCTHoaDon(cthd))
                        {
                            hd.tongtien = _hdService.layTongTienHoaDon(hd.mahd.Trim());
                            _hdService.SuaHoaDon(hd);
                            _main.dataGridView2.DataSource = _hdService.DanhSachHoaDon();
                            if (_spService.CapNhatSoLuong(cthd.mahang.Trim(), "HOADON", cthd.soluong))
                            {
                                _main.dataGridView.DataSource = _spService.DanhSachSanPham();
                            }
                            if (themChiTiet())
                            {
                                txtTenSP.Clear();
                                txtThanhTien.Text = "0";
                                txtSoLuong.Text   = "0";
                                txtGiaBan.Text    = "0";
                                txtTenSP.Focus();
                                btnThemTiep.Show();
                            }
                            else
                            {
                                btnThemTiep.Hide();
                                _main.dataGridView2.DataSource = _hdService.DanhSachHoaDon();
                                this.Close();
                            }
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Số lượng đã nhập sai, kiểm tra lại.", "Thông Báo lỗi");
                }
            }
        }