public int ThemOBJ(BaoHetHang obj) { int kq = 0; try { string sql = "insert into BaoHetHang (SoSanPhamConLai, SoLanBao) values(" + obj.SoLuongCon + "," + obj.SoLanBao + ")"; kq = dbclass.TruyVan_XuLy(sql); return(kq); } catch (Exception) { return(kq); } }
public int SuaThongTinOBJ(BaoHetHang obj) { int kq = 0; try { string sql = "update BaoHetHang set SoSanPhamConLai = " + obj.SoLuongCon + ", SoLanBao =" + obj.SoLanBao + " where STT ='" + obj.STT + "'"; kq = dbclass.TruyVan_XuLy(sql); return(kq); } catch (Exception) { MessageBox.Show("Lỗi: Không thể thay đổi thông tin mặt hàng dưới CSDL", "Lỗi truy vấn CSDL", MessageBoxButtons.OK, MessageBoxIcon.Error); return(kq); } }
private void butLuuHienThiDen_Click(object sender, EventArgs e) { if (dataGridBaoHetHang.Rows.Count > 0) { for (int i = 0; i < dataGridBaoHetHang.Rows.Count - 1; i++) { if (dataGridBaoHetHang.Rows[i].Cells[0].Value == null) { BaoHetHang bhh = new BaoHetHang(); bhh.SoLuongCon = 0; try { bhh.SoLuongCon = int.Parse(dataGridBaoHetHang.Rows[i].Cells[1].Value.ToString()); } catch (Exception) { } bhh.SoLanBao = 0; try { bhh.SoLanBao = int.Parse(dataGridBaoHetHang.Rows[i].Cells[2].Value.ToString()); } catch (Exception) { } baohethangDAO.ThemOBJ(bhh); } else { BaoHetHang bhh = new BaoHetHang { STT = int.Parse(dataGridBaoHetHang.Rows[i].Cells[0].Value.ToString()), SoLuongCon = int.Parse(dataGridBaoHetHang.Rows[i].Cells[1].Value.ToString()), SoLanBao = int.Parse(dataGridBaoHetHang.Rows[i].Cells[2].Value.ToString()) }; baohethangDAO.SuaThongTinOBJ(bhh); } } dataGridBaoHetHang.Rows.Clear(); dataGridBaoHetHang.Refresh(); baohethangDAO.LoadOBJToDataGirdview(dataGridBaoHetHang); } }