private int Execute(string _operator, DMonHoc _operand, DMonHoc oldstate) { Command command = new MonHocCommand(_operator, _operand, oldstate); int code = command.Execute(); _commands.Push(command); btnUndo.Enabled = true; return(code); }
private void btnXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { btnXoa.Enabled = false; DataRow red = gridView1.GetFocusedDataRow(); DMonHoc MHTrongBang = new DMonHoc { MaMH = red["Mã môn học"].ToString(), TenMH = red["Tên môn học"].ToString() }; int code = Execute("delete", MHTrongBang, null); if (code == 0) { //MessageBox.Show("Xoá thành công"); btnReload.PerformClick(); } else { MessageBox.Show("Xoá thất bại."); } }
public int Operation(string _operator, DMonHoc _operand, DMonHoc oldstate) { int code = 0; switch (_operator) { case "insert": code = CreateMonHoc(_operand); break; case "update": code = UpdateMonHoc(_operand); break; case "delete": code = RemoveMonHoc(_operand); break; case "unupdate": code = UpdateMonHoc(oldstate); break; } return(code); }
private void btnLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { btnLuu.Enabled = false; int noError = 0; string errors = "Nội dung bạn nhập có 1 số lỗi sau. Vui lòng sửa trước khi lưu."; if (textBox1.Text.Trim() == "") { //MessageBox.Show("Mã môn học không được để trống"); errors += "\r\n+ Mã môn học bị bỏ trống"; noError++; } if (textBox2.Text.Trim() == "") { //MessageBox.Show("Tên môn học không được để trống"); errors += "\r\n+ Tên môn học bị bỏ trống"; noError++; } if (noError > 0) { MessageBox.Show(errors); btnLuu.Enabled = true; return; } if (textBox1.Enabled) { DMonHoc MHTrongForm = new DMonHoc { MaMH = textBox1.Text.Trim().ToUpper(), TenMH = textBox2.Text.Trim() }; int code = Execute("insert", MHTrongForm, null); if (code == 0) { btnReload.PerformClick(); //MessageBox.Show("Tạo môn học thành công"); } else { MessageBox.Show("Tạo môn học thất bại"); } textBox1.Enabled = false; } else { DataRow red = gridView1.GetFocusedDataRow(); DMonHoc MHTrongBang = new DMonHoc { MaMH = red["Mã môn học"].ToString(), TenMH = red["Tên môn học"].ToString() }; DMonHoc MHTrongForm = new DMonHoc { MaMH = textBox1.Text.Trim().ToUpper(), TenMH = textBox2.Text.Trim() }; int code = Execute("update", MHTrongForm, MHTrongBang); if (code == 0) { btnReload.PerformClick(); //MessageBox.Show("Lưu môn học thành công"); } else { MessageBox.Show("Lưu môn học thất bại"); } } btnLuu.Enabled = true; }
public int RemoveMonHoc(DMonHoc monHoc) { string[] name = { "@mamh" }; object[] param = { monHoc.MaMH }; return(DBAccess.ExecuteNonQuery("SP_XoaMonHoc", name, param, 1)); }
public int UpdateMonHoc(DMonHoc monHoc) { string[] name = { "@mamh", "@tenmh" }; object[] param = { monHoc.MaMH, monHoc.TenMH }; return(DBAccess.ExecuteNonQuery("SP_SuaMonHoc", name, param, 2)); }
public MonHocCommand(string _operator, DMonHoc _operand, DMonHoc oldstate) { this._operator = _operator; this._operand = _operand; this.oldstate = oldstate; }