private int Execute(string _operator, DLop _operand, DLop oldstate) { Command command = new LopCommand(_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(); DLop LopTrongBang = new DLop { MaLop = red["Mã lớp"].ToString(), TenLop = red["Tên lớp"].ToString(), MaKhoa = khoa.Select(string.Format("[Tên khoa] ='{0}'", red["Tên khoa"].ToString()))[0][0].ToString() }; int code = Execute("delete", LopTrongBang, null); if (code == 0) { //MessageBox.Show("Xoá lớp thành công"); btnReload.PerformClick(); } else { MessageBox.Show("Xoá lớp thất bại"); } }
public int Operation(string _operator, DLop _operand, DLop oldstate) { int code = 0; switch (_operator) { case "insert": code = CreateLop(_operand); break; case "update": code = UpdateLop(_operand); break; case "delete": code = RemoveLop(_operand); break; case "unupdate": code = UpdateLop(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ã lớp không được bỏ trống"); errors += "\r\n+ Mã lớp bị bỏ trống"; noError++; } if (textBox2.Text.Trim() == "") { //MessageBox.Show("Tên lớp không được bỏ trống"); errors += "\r\n+ Tên lớp bị bỏ trống"; noError++; } if (comboBox3.Text.Trim() == "") { //MessageBox.Show("Tên khoa không được bỏ trống. Vui lòng nhập thêm khoa hoặc kiểm tra lại CSDL"); errors += "\r\n+ Tên khoa bị bỏ trống. Vui lòng nhập thêm khoa hoặc kiểm tra lại CSDL"; noError++; } if (noError > 0) { MessageBox.Show(errors); btnLuu.Enabled = true; return; } if (textBox1.Enabled) { DataRow red = gridView1.GetFocusedDataRow(); string maLopTrongForm = khoa.Select(string.Format("[Tên khoa] ='{0}'", comboBox3.Text))[0][0].ToString(); DLop LopTrongForm = new DLop { MaLop = textBox1.Text.Trim(), TenLop = textBox2.Text.Trim(), MaKhoa = maLopTrongForm }; int code = Execute("insert", LopTrongForm, null); if (code == 0) { btnReload.PerformClick(); // MessageBox.Show("Tạo lớp thành công"); } else { MessageBox.Show("Tạo lớp thất bại"); } textBox1.Enabled = false; } else { DataRow red = gridView1.GetFocusedDataRow(); DLop LopTrongBang = new DLop { MaLop = red["Mã lớp"].ToString(), TenLop = red["Tên lớp"].ToString(), MaKhoa = khoa.Select(string.Format("[Tên khoa] ='{0}'", red["Tên khoa"].ToString()))[0][0].ToString() }; DLop LopTrongForm = new DLop { MaLop = textBox1.Text.Trim(), TenLop = textBox2.Text.Trim(), MaKhoa = khoa.Select(string.Format("[Tên khoa] ='{0}'", comboBox3.Text))[0][0].ToString() }; int code = Execute("update", LopTrongForm, LopTrongBang); 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 RemoveLop(DLop lop) { string[] name = { "@malop" }; object[] param = { lop.MaLop }; return(DBAccess.ExecuteNonQuery("SP_Xoalop", name, param, 1)); }
public int UpdateLop(DLop lop) { string[] name = { "@malop", "@tenlop", "@makh" }; object[] param = { lop.MaLop, lop.TenLop, lop.MaKhoa }; return(DBAccess.ExecuteNonQuery("SP_Sualop", name, param, 3)); }
public LopCommand(string _operator, DLop _operand, DLop oldstate) { this._operator = _operator; this._operand = _operand; this.oldstate = oldstate; }