private void btnXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (MessageBox.Show("Bạn có thật sự muốn xóa sinh viên này ?? ", "Xác nhận", MessageBoxButtons.OKCancel) == DialogResult.OK) { try { UndoLop undo = new UndoLop(XOA, getInfoSinhVien()); st.Push(undo); maSV = ((DataRowView)bdsSinhVien[bdsSinhVien.Position])["MASV"].ToString(); // giữ lại để khi xóa bij lỗi thì ta sẽ quay về lại bdsSinhVien.RemoveCurrent(); this.SinhVienTableAdapter.Connection.ConnectionString = Program.connstr; this.SinhVienTableAdapter.Update(this.DS.SINHVIEN); capNhatBtnPhucHoi(); } catch (Exception ex) { MessageBox.Show("Lỗi xóa lớp. Bạn hãy xóa lại\n" + ex.Message, "", MessageBoxButtons.OK); this.LopTableAdapter.Fill(this.DS.LOP); bdsLop.Position = bdsLop.Find("MALOP", maLop); return; } } if (bdsLop.Count == 0) { btnXoa.Enabled = false; } }
private void btnHieuChinh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { vitri = bdsLop.Position; groupBox1.Enabled = true; btnThem.Enabled = btnHieuChinh.Enabled = btnXoa.Enabled = btnPhucHoi.Enabled = btnThoat.Enabled = false; btnGhi.Enabled = btnPhucHoi.Enabled = true; txtMaLop.Enabled = txtMaKhoa.Enabled = false; gcLop.Enabled = false; choose = HIEU_CHINH; Lop lop = new Lop(txtMaLop.Text, txtTenLop.Text, txtMaKhoa.Text); UndoLop undo = new UndoLop(HIEU_CHINH, lop); st.Push(undo); capNhatBtnPhucHoi(); }
private void btnPhucHoi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (isDangThem) { reload(); capNhatBtnPhucHoi(); isDangThem = false; } bdsLop.CancelEdit(); if (btnThem.Enabled == false) { bdsLop.Position = vitri; } gcLop.Enabled = true; groupBox1.Enabled = false; btnThem.Enabled = btnHieuChinh.Enabled = btnXoa.Enabled = btnThoat.Enabled = true; btnGhi.Enabled = btnPhucHoi.Enabled = false; if (st.Count == 0) { return; } UndoLop objUndo = (UndoLop)st.Pop(); Object obj = objUndo.obj; switch (objUndo.chucNang) { case THEM: Program.ExecSqlDataReader(obj.ToString()); this.LopTableAdapter.Fill(this.DS.LOP); capNhatBtnPhucHoi(); break; case HIEU_CHINH: Lop lopHieuChinh = (Lop)obj; if (Program.conn.State == ConnectionState.Closed) { Program.conn.Open(); } String sqlHieuChinh = "exec sp_PhucHoiLopHieuChinh N'" + lopHieuChinh.maLop + "',N'" + lopHieuChinh.tenLop + "'"; Program.ExecSqlDataTable(sqlHieuChinh); //String strPhucHoiHieuChinh = "sp_PhucHoiLopHieuChinh"; //Program.sqlcmd = Program.conn.CreateCommand(); //Program.sqlcmd.CommandType = CommandType.StoredProcedure; //Program.sqlcmd.CommandText = strPhucHoiHieuChinh; //Program.sqlcmd.Parameters.Add("@MALOP", SqlDbType.Text).Value = lopHieuChinh.maLop; //Program.sqlcmd.Parameters.Add("@TENLOP", SqlDbType.Text).Value = lopHieuChinh.tenLop; //Program.sqlcmd.ExecuteNonQuery(); Program.conn.Close(); reload(); break; case XOA: Lop lopXoa = (Lop)obj; if (Program.conn.State == ConnectionState.Closed) { Program.conn.Open(); } String sql = "exec sp_ThemLop N'" + lopXoa + "',N'" + lopXoa.tenLop + "',N'" + lopXoa.maKhoa + "'"; Program.ExecSqlDataTable(sql); //String strPhucHoiXoa = "sp_ThemLop"; //Program.sqlcmd = Program.conn.CreateCommand(); //Program.sqlcmd.CommandType = CommandType.StoredProcedure; //Program.sqlcmd.CommandText = strPhucHoiXoa; //Program.sqlcmd.Parameters.Add("@MALOP", SqlDbType.Text).Value = lopXoa.maLop; //Program.sqlcmd.Parameters.Add("@TENLOP", SqlDbType.Text).Value = lopXoa.tenLop; //Program.sqlcmd.Parameters.Add("@MAKHOA", SqlDbType.Text).Value = lopXoa.maKhoa; //Program.sqlcmd.ExecuteNonQuery(); reload(); break; } }
private void btnGhi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { switch (choose) { case THEM: if (txtMaLop.Text.Trim() == "") { MessageBox.Show("Mã lớp không được thiếu!", "", MessageBoxButtons.OK); txtMaLop.Focus(); return; } if (txtTenLop.Text.Trim() == "") { MessageBox.Show("Tên lớp không được thiếu!", "", MessageBoxButtons.OK); txtTenLop.Focus(); return; } if (Program.conn.State == ConnectionState.Closed) { Program.conn.Open(); } String strLenh = "dbo.sp_KTMALOP"; Program.sqlcmd = Program.conn.CreateCommand(); Program.sqlcmd.CommandType = CommandType.StoredProcedure; Program.sqlcmd.CommandText = strLenh; Program.sqlcmd.Parameters.Add("@MALOP", SqlDbType.Text).Value = txtMaLop.Text; Program.sqlcmd.Parameters.Add("@Ret", SqlDbType.Int).Direction = ParameterDirection.ReturnValue; Program.sqlcmd.ExecuteNonQuery(); String Ret = Program.sqlcmd.Parameters["@Ret"].Value.ToString(); if (Ret.Equals("1")) { MessageBox.Show("Mã lớp bị trùng!", "", MessageBoxButtons.OK); txtMaLop.Focus(); Program.conn.Close(); return; } String sql = "exec dbo.sp_KTTENLOP N'" + txtTenLop.Text + "'"; DataTable dataTable = Program.ExecSqlDataTable(sql); if (dataTable.Rows.Count > 0) { MessageBox.Show("Tên lớp bị trùng!"); txtTenLop.Focus(); Program.conn.Close(); return; } try { bdsLop.EndEdit(); bdsLop.ResetCurrentItem(); this.LopTableAdapter.Connection.ConnectionString = Program.connstr; this.LopTableAdapter.Update(this.DS.LOP); String lenhXoaLop = "exec sp_XOALOP '" + txtMaLop.Text + "'"; UndoLop undo = new UndoLop(THEM, lenhXoaLop); st.Push(undo); capNhatBtnPhucHoi(); } catch (Exception ex) { MessageBox.Show("Lỗi ghi lớp.\n" + ex.Message, "", MessageBoxButtons.OK); return; } gcLop.Enabled = true; btnThem.Enabled = btnHieuChinh.Enabled = btnXoa.Enabled = btnPhucHoi.Enabled = btnThoat.Enabled = true; btnGhi.Enabled = false; groupBox1.Enabled = false; isDangThem = false; break; case HIEU_CHINH: if (txtTenLop.Text.Trim() == "") { MessageBox.Show("Tên lớp không được thiếu!", "", MessageBoxButtons.OK); txtTenLop.Focus(); return; } if (Program.conn.State == ConnectionState.Closed) { Program.conn.Open(); } String strLenhKiemTraTenLop = "dbo.sp_KTTENLOP"; Program.sqlcmd = Program.conn.CreateCommand(); Program.sqlcmd.CommandType = CommandType.StoredProcedure; Program.sqlcmd.CommandText = strLenhKiemTraTenLop; Program.sqlcmd.Parameters.Add("@TENLOP", SqlDbType.Text).Value = convertStringToUTF8(txtTenLop.Text.Trim()); Program.sqlcmd.Parameters.Add("@Ret", SqlDbType.Int).Direction = ParameterDirection.ReturnValue; Program.sqlcmd.ExecuteNonQuery(); Program.conn.Close(); String RetKiemTraTenLop = Program.sqlcmd.Parameters["@Ret"].Value.ToString(); if (RetKiemTraTenLop == "1") { MessageBox.Show("Tên lớp bị trùng!", "", MessageBoxButtons.OK); txtTenLop.Focus(); return; } try { bdsLop.EndEdit(); bdsLop.ResetCurrentItem(); this.LopTableAdapter.Connection.ConnectionString = Program.connstr; this.LopTableAdapter.Update(this.DS.LOP); } catch (Exception ex) { MessageBox.Show("Lỗi hiệu chỉnh nhân viên.\n" + ex.Message, "", MessageBoxButtons.OK); return; } gcLop.Enabled = true; btnThem.Enabled = btnHieuChinh.Enabled = btnXoa.Enabled = btnPhucHoi.Enabled = btnThoat.Enabled = true; btnGhi.Enabled = false; groupBox1.Enabled = false; break; } }