private void btnThemLinhKien_Click(object sender, EventArgs e) { int MASP = sp_BUS.getMASP(txtTenSanPham.Text); int MAHD = int.Parse(txtIDHD.Text); int SL = int.Parse(txtSoLuong.Text); decimal Gia = decimal.Parse(txtThanhTien.Text); int _SL = cthd_BUS.GetSL(MAHD, MASP) + SL; decimal _GiaTien = cthd_BUS.GetTien(MAHD, MASP) + Gia; CTHD_DTO cthd_DTO = new CTHD_DTO(MAHD, MASP, SL, Gia); if (txtLoai.Text != "Phụ tùng") { if (cthd_BUS.Insert(cthd_DTO)) { loadCTHD(); loadSP(); } else { if (cthd_BUS.Update(MAHD, MASP, _SL, _GiaTien)) { loadCTHD(); loadSP(); } else { MessageBox.Show("Thêm thất bại!"); } } } else { int SLKho = int.Parse(txtTonKho.Text); if (SL <= SLKho) { if (cthd_BUS.Insert(cthd_DTO)) { loadCTHD(); UpdateSLKho(MASP, -SL); loadSP(); } else { if (cthd_BUS.Update(MAHD, MASP, _SL, _GiaTien)) { loadCTHD(); UpdateSLKho(MASP, -SL); loadSP(); } else { MessageBox.Show("Thêm thất bại!"); } } } else { MessageBox.Show("Không đủ hàng trong kho!"); } } }