private void btnIn_Click(object sender, EventArgs e) { try { int sodong = dgvSP.Rows.Count - 1; if (ttkh() && sodong > 0) { if (!ktkh) { khachhangbll.ThemKhachHang(ref error, txtSDT.Text, txtHoTen.Text, txtDiaChi.Text); dskh = khachhangbll.TimKhachHang(ref error, txtSDT.Text); idkh = Convert.ToInt32(dskh.Tables[0].Rows[0]["idKH"].ToString()); } //insert hóa đơn hoadonBLL.ThemHoaDon(ref error, idkh, idnv, Convert.ToDouble(txtTongTien.Text), DateTime.Now); //Insert Hóa Đơn chi tiết for (int i = 0; i < sodong; i++) { int idsp = Convert.ToInt32(dgvSP.Rows[i].Cells[0].Value.ToString()); int soluongsp = Convert.ToInt32(dgvSP.Rows[i].Cells[2].Value.ToString()); double dongia = Convert.ToDouble(dgvSP.Rows[i].Cells[3].Value.ToString()); //Thêm hóa đơn chi tiết hoadonBLL.ThemCTHoaDon(ref error, idsp, soluongsp, dongia); //Trừ trong kho spbll.SuaSLSP(ref error, idsp, soluongsp * -1); //Nếu hạn bảo hành lớn không if (Convert.ToInt32(dgvSP.Rows[i].Cells[4].Value.ToString()) > 0) { //Thêm bảo hành spbll.ThemBaoHanh(ref error, idsp, idkh, GetDate(Convert.ToInt32(dgvSP.Rows[i].Cells[4].Value.ToString()))); } } MessageBox.Show("Xuất hàng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); this.Close(); f.Show(); } else { MessageBox.Show("Vui lòng xem lại thông tin khách hàng hoặc đơn hàng rỗng", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }catch (Exception excep) { MessageBox.Show(excep.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }