private void btnThemCTHD_Click(object sender, EventArgs e) { try { bool bien = true; for (int i = 0; i < gdvCTHD.Rows.Count - 1; i++) { string masp = gdvCTHD.Rows[i].Cells["MaSP"].Value.ToString(); if (masp.Equals(cboTSP.SelectedValue.ToString())) { bien = false; break; } else { bien = true; } } if (bien) { int tt = (int.Parse(num_SL.Value.ToString()) * int.Parse(txtGiaBan.Text)); DTO_CTHD cthd = new DTO_CTHD(int.Parse(txtMaHD.Text), int.Parse(cboTSP.SelectedValue.ToString()), int.Parse(num_SL.Value.ToString()), int.Parse(txtGiaBan.Text), tt); bshd.InsertCT_HD(cthd); XtraMessageBox.Show("Thêm thành công."); gdvCTHD.DataSource = bshd.getCTHD(int.Parse(txtMaHD.Text)); int sl = int.Parse(num_SL.Value.ToString()); string mah = cboTSP.SelectedValue.ToString(); hh.Updatesoluonggiam(int.Parse(mah), sl); } else { XtraMessageBox.Show("Đã có sản phẩm trong giỏ hàng.\n Bạn có thể sửa số lượng sản phẩm trong giỏ."); } } catch { XtraMessageBox.Show("Thêm thất bại."); } }