//Lấy Thông tin Thể loại private TuSach_DTO LayTTTuSach() { TuSach_DTO tu = new TuSach_DTO(); tu.MaTuSach = txtMaTu.Text; tu.TuSach = txtTuSach.Text; tu.GhiChu = txtGhiChu.Text; return(tu); }
//Kiểm tra trước khi lưu public bool KiemTraTruocKhiLuu(TuSach_DTO ts) { if (ts.TuSach.Equals("")) { MessageBox.Show("Tủ sách không hợp lệ ! "); return(false); } return(true); }
//Sửa Thể Loại vào CSDL public bool SuaTuSach(TuSach_DTO ts) { if (KiemTraTruocKhiLuu(ts)) { string sql = string.Format("UPDATE TUSACH SET TuSach=N'{0}', GhiChu=N'{1}' WHERE MaTuSach='{2}'", ts.TuSach, ts.GhiChu, ts.MaTuSach); if (connData.ThucThiSQL(sql)) { MessageBox.Show("Sửa tủ sách thành công !", "Thông tin", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } } return(false); }
//Thêm Thể loại vào CSDL public bool ThemTuSach(TuSach_DTO ts) { if (KiemTraTruocKhiLuu(ts)) { string sql = string.Format("INSERT INTO TUSACH (MaTuSach, TuSach, GhiChu)" + " VALUES ('{0}', N'{1}', N'{2}')", ts.MaTuSach, ts.TuSach, ts.GhiChu); if (connData.ThucThiSQL(sql)) { MessageBox.Show("Thêm tủ sách mới thành công", "Thông tin", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } } return(false); }
private void btnLuu_Click(object sender, EventArgs e) { TuSach_DTO ts = LayTTTuSach(); if (add) { tuBUS.ThemTuSach(ts); ttTuSach_Load(sender, e); } if (update) { tuBUS.SuaTuSach(ts); ttTuSach_Load(sender, e); } }