private void btn_them_Click(object sender, EventArgs e) { if (tbx_masp.Text.Trim() == "" || tbx_madm.Text.Trim() == "" || tbx_mancc.Text.Trim() == "" || tbx_sl.Text.Trim() == "" || tbx_gia.Text.Trim() == "") { MessageBox.Show("Hãy Nhập Đầy Đủ Thông Tin!", "Thông Báo!"); tbx_masp.Focus(); } else { DataTable dtsp = new DataTable(); DataTable dtncc = new DataTable(); DataTable dtdm = new DataTable(); dtsp = acc.CheckSql("select * from SANPHAM where MASP ='" + tbx_masp.Text + "'"); dtncc = acc.CheckSql("select * from NHACUNGCAP where MANCC ='" + tbx_mancc.Text + "'"); dtdm = acc.CheckSql("select * from DANHMUC where MADANHMUC ='" + tbx_madm.Text + "'"); if (dtsp.Rows.Count > 0 || dtncc.Rows.Count < 1 || dtdm.Rows.Count < 1) { MessageBox.Show("Sản phẩm đã tồn tại Hoặc nhà cung cấp Hoặc danh mục không tồn tại!", "Lỗi"); tbx_masp.Clear(); tbx_mancc.Clear(); tbx_madm.Clear(); tbx_masp.Focus(); } else { if (tbx_masp.Text == dgvsanpham.CurrentRow.Cells["MASP"].Value.ToString().Trim()) { MessageBox.Show("Sản phẩm Này Đã Tồn Tại. Vui Lòng Sủa Lại!", "Thông Báo!"); } else { acc.Them_SanPham(tbx_masp.Text, tbx_tensp.Text, tbx_mancc.Text, float.Parse(tbx_gia.Text), tbx_madm.Text, tbx_serial.Text, dateTimePicker_sx.Value, dateTimePicker_sd.Value, tbx_ghichu.Text, int.Parse(tbx_sl.Text), tbx_phanloai.Text, filepath); dgvsanpham.DataSource = acc.Select_Data("Select * from SANPHAM"); ClearText(); dgvsanpham.ClearSelection(); } } } }