public Boolean ThemTP(ThucPham_DTO tp) { string sql = "INSERT INTO ThucPham VALUES(N'" + tp.IDThucPham + "', N'" + tp.TenTP + "', '" + tp.DonGia + "', N'" + tp.NhaSX + "', '" + tp.NgaySX.ToString("yyyy-MM-dd") + "', '" + tp.HanSD.ToString("yyyy-MM-dd") + "', N'" + tp.MieuTa + "')"; return(new ExecuteDB().ExecuteData(sql)); }
public Boolean SuaTP(ThucPham_DTO tp) { string sql = "UPDATE ThucPham SET TenTP = N'" + tp.TenTP + "', DonGia = '" + tp.DonGia + "', NhaSX = N'" + tp.NhaSX + "', NgaySX = '" + tp.NgaySX.ToString("yyyy-MM-dd") + "', HanSD = '" + tp.HanSD.ToString("yyyy-MM-dd") + "', MieuTa = N'" + tp.MieuTa + "'WHERE IDThucPham = N'" + tp.IDThucPham + "'"; return(new ExecuteDB().ExecuteData(sql)); }
public Boolean SuaTP(ThucPham_DTO tp) { try { if (tp.IDThucPham == "") { throw new Exception("Field \"IDThucPham\" không thể trống."); } return(new ThucPham_DAL().SuaTP(tp)); } catch (Exception ex) { throw ex; } }
private void btnSua_Click(object sender, EventArgs e) { try { ThucPham_DTO tp = new ThucPham_DTO(txtIDTP.Text, txtTenTP.Text, txtDonGia.Text, txtNhaSX.Text, dtNgaySX.Text, dtHanSD.Text, txtMieuTa.Text); if (MessageBox.Show("Lưu sửa đổi?", "Chú ý!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { BUS.SuaTP(tp); MessageBox.Show("Sửa thành công!"); dgvThucPham.DataSource = BUS.GetDataTP(); Init(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }