//Kiểm tra trước khi lưu public bool KiemTraTruocKhiLuu(TheLoai_DTO tl) { if (tl.TenTL.Equals("")) { MessageBox.Show("Tên Thể Loại không hợp lệ ! "); return false; } return true; }
//Sửa Thể Loại vào CSDL public bool SuaTL(TheLoai_DTO tl) { if (KiemTraTruocKhiLuu(tl)) { string sql = string.Format("UPDATE THELOAI SET TenTL=N'{0}', GhiChu=N'{1}' WHERE MaTL='{2}'", tl.TenTL, tl.GhiChu, tl.MaTL); if (connData.ThucThiSQL(sql)) { MessageBox.Show("Sửa Thể Loại 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 ThemTL(TheLoai_DTO tl) { if (KiemTraTruocKhiLuu(tl)) { string sql = string.Format("INSERT INTO THELOAI (MaTL, TenTL, GhiChu)" + " VALUES ('{0}', N'{1}', N'{2}')", tl.MaTL, tl.TenTL, tl.GhiChu); if (connData.ThucThiSQL(sql)) { MessageBox.Show("Thêm Thể loại 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 ThemTL(TheLoai_DTO tl) { int param = 3; string[] name = new string[param]; object[] value = new object[param]; name[0] = "MaTL"; value[0] = tl.MaTL; name[1] = "TenTL"; value[1] = tl.TenTL; name[2] = "GhiChu"; value[2] = tl.GhiChu; if (KiemTraTruocKhiLuu(tl)) { if (connect.Update("sp_ThemTL", name, value, param) > 0) { MessageBox.Show("Thêm Thể loại thành công", "Thông tin", MessageBoxButtons.OK, MessageBoxIcon.Information); return true; } return false; } return false; }
//Lấy Thông tin Thể loại private TheLoai_DTO LayTTTL() { TheLoai_DTO tl = new TheLoai_DTO(); tl.MaTL = txtMaTL.Text; tl.TenTL = txtTenTL.Text; tl.GhiChu = txtGhiChu.Text; return tl; }
//Thêm Thể loại vào CSDL public bool ThemTL(TheLoai_DTO tl) { return theloai_dal.ThemTL(tl); }
//Sửa Thể Loại vào CSDL public bool SuaTL(TheLoai_DTO tl) { return theloai_dal.SuaTL(tl); }
//Kiểm tra trước khi lưu public bool KiemTraTruocKhiLuu(TheLoai_DTO tl) { return theloai_dal.KiemTraTruocKhiLuu(tl); }