private void AddNew() { try { Class_DSKhoa DSK = new Class_DSKhoa { MaKhoa = txtMaKhoa.Text.Trim(), TenKhoa = txtTenKhoa.Text.Trim(), GhiChu = txtGhiChu.Text.Trim() }; int result = da.ExecuteData(DSK.ToInsertQuery(), DSK.ToParameters()); if (result > 0) { MessageBox.Show("Success"); ButtonClick = ""; ViewMode(); LoadData(); } else { MessageBox.Show("Failed"); } } catch (Exception ex) { MessageBox.Show("Error! " + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static List <KeyValuePair <string, object> > ToParameters(this Class_DSKhoa DSK) { var parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>("MaKhoa", DSK.MaKhoa)); parameters.Add(new KeyValuePair <string, object>("TenKhoa", DSK.TenKhoa)); parameters.Add(new KeyValuePair <string, object>("GhiChu", DSK.GhiChu)); return(parameters); }
public static string ToUpdateQuery(this Class_DSKhoa DSK) { return(@"UPDATE DANHSACHKHOA SET TenKhoa = @TenKhoa, GhiChu = @GhiChu WHERE MaKhoa = @MaKhoa"); }
public static string ToInsertQuery(this Class_DSKhoa DSK) { return(@"INSERT INTO DANHSACHKHOA(MaKhoa, TenKhoa, GhiChu) VALUES (@MaKhoa, @TenKhoa, @GhiChu)"); }