private void AddNew() { try { string vMaKhoa = MaSo; Class_Subject sj = new Class_Subject { MaMon = txtSubjectID.Text.Trim(), TenMon = txtSubjectName.Text.Trim(), Khoa = txtKhoa.Text.Trim() }; int result = da.ExecuteData(sj.ToInsertQuery(), sj.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); } }
private void EditData() { try { Class_Subject sj = new Class_Subject { MaMon = txtSubjectID.Text, TenMon = txtSubjectName.Text, Khoa = txtKhoa.Text }; int result = da.ExecuteData(sj.ToUpdateQuery(), sj.ToParameters()); if (result > 0) { MessageBox.Show("Success"); ButtonClick = ""; ViewMode(); LoadData(); } else { MessageBox.Show("Failed"); } } catch (Exception ex) { MessageBox.Show("Có lỗi! " + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static List <KeyValuePair <string, object> > ToParameters(this Class_Subject sj) { var parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>("MaMon", sj.MaMon)); parameters.Add(new KeyValuePair <string, object>("TenMon", sj.TenMon)); parameters.Add(new KeyValuePair <string, object>("Khoa", sj.Khoa)); //parameters.Add(new KeyValuePair<string, object>("NhanVienCoiThi", sj.NhanVienCoiThi)); return(parameters); }
public static string ToUpdateQuery(this Class_Subject sj) { return(@"UPDATE DANHSACHMONTHI SET TenMon = @TenMon, Khoa = @Khoa WHERE MaMon = @MaMon"); }
public static string ToInsertQuery(this Class_Subject sj) { return(@"INSERT INTO DANHSACHMONTHI(MaMon, TenMon, Khoa) VALUES (@MaMon, @TenMon, @Khoa)"); }