Ejemplo n.º 1
0
        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   = txtMASV.Enabled = false;
            gcSinhVien.Enabled = false;
            choose             = HIEU_CHINH;

            UndoSinhVien undo = new UndoSinhVien(HIEU_CHINH, getInfoSinhVien());

            st.Push(undo);
        }
Ejemplo n.º 2
0
        private void btnPhucHoi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (isDangThem)
            {
                bdsSinhVien.RemoveCurrent();
            }
            this.SinhVienTableAdapter.Connection.ConnectionString = Program.connstr;
            this.SinhVienTableAdapter.Update(this.DS.SINHVIEN);
            bdsSinhVien.CancelEdit();
            if (btnThem.Enabled == false)
            {
                bdsSinhVien.Position = vitri;
            }
            gcSinhVien.Enabled = true;
            groupBox1.Enabled  = false;
            btnThem.Enabled    = btnHieuChinh.Enabled = btnXoa.Enabled = btnThoat.Enabled = true;
            btnGhi.Enabled     = btnPhucHoi.Enabled = false;

            if (st.Count == 0)
            {
                return;
            }

            UndoSinhVien objUndo = (UndoSinhVien)st.Pop();
            Object       obj     = objUndo.getObject();

            switch (objUndo.getType())
            {
            case THEM:
                Program.ExecSqlDataReader(obj.ToString());
                this.SinhVienTableAdapter.Fill(this.DS.SINHVIEN);
                capNhatBtnPhucHoi();
                break;

            case HIEU_CHINH:
                SinhVien svHieuChinh = (SinhVien)obj;
                if (Program.conn.State == ConnectionState.Closed)
                {
                    Program.conn.Open();
                }
                String strPhucHoiHieuChinh = "sp_PhucHoiSinhVien";
                Program.sqlcmd             = Program.conn.CreateCommand();
                Program.sqlcmd.CommandType = CommandType.StoredProcedure;
                Program.sqlcmd.CommandText = strPhucHoiHieuChinh;
                Program.sqlcmd.Parameters.Add("@MASV", SqlDbType.Text).Value         = svHieuChinh.getMaSV();
                Program.sqlcmd.Parameters.Add("@HO", SqlDbType.Text).Value           = svHieuChinh.getHo();
                Program.sqlcmd.Parameters.Add("@TEN", SqlDbType.Text).Value          = svHieuChinh.getTen();
                Program.sqlcmd.Parameters.Add("@PHAI", SqlDbType.Bit).Value          = svHieuChinh.isPhai();
                Program.sqlcmd.Parameters.Add("@NGAYSINH", SqlDbType.DateTime).Value = svHieuChinh.getNgaySinh();
                Program.sqlcmd.Parameters.Add("@NOISINH", SqlDbType.Text).Value      = svHieuChinh.getNoiSinh();
                Program.sqlcmd.Parameters.Add("@DIACHI", SqlDbType.Text).Value       = svHieuChinh.getDiaChi();
                Program.sqlcmd.Parameters.Add("@NGHIHOC", SqlDbType.Bit).Value       = svHieuChinh.isNghiHoc();
                Program.sqlcmd.ExecuteNonQuery();
                Program.conn.Close();
                reload();
                break;

            case XOA:
                SinhVien svXoa = (SinhVien)obj;
                if (Program.conn.State == ConnectionState.Closed)
                {
                    Program.conn.Open();
                }
                String strPhucHoiXoa = "sp_ThemSinhVien";
                Program.sqlcmd             = Program.conn.CreateCommand();
                Program.sqlcmd.CommandType = CommandType.StoredProcedure;
                Program.sqlcmd.CommandText = strPhucHoiXoa;
                Program.sqlcmd.Parameters.Add("@MASV", SqlDbType.Text).Value         = svXoa.getMaSV();
                Program.sqlcmd.Parameters.Add("@HO", SqlDbType.Text).Value           = svXoa.getHo();
                Program.sqlcmd.Parameters.Add("@TEN", SqlDbType.Text).Value          = svXoa.getTen();
                Program.sqlcmd.Parameters.Add("@MALOP", SqlDbType.Text).Value        = svXoa.getMaLop();
                Program.sqlcmd.Parameters.Add("@NGAYSINH", SqlDbType.DateTime).Value = svXoa.getNgaySinh();
                Program.sqlcmd.Parameters.Add("@PHAI", SqlDbType.Bit).Value          = svXoa.isPhai();
                Program.sqlcmd.Parameters.Add("@NOISINH", SqlDbType.Text).Value      = svXoa.getNoiSinh();
                Program.sqlcmd.Parameters.Add("@DIACHI", SqlDbType.Text).Value       = svXoa.getDiaChi();
                Program.sqlcmd.Parameters.Add("@NGHIHOC", SqlDbType.Bit).Value       = svXoa.isNghiHoc();
                Program.sqlcmd.ExecuteNonQuery();
                reload();
                break;
            }
        }
Ejemplo n.º 3
0
        private void btnGhi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (!checkEmtyInfo())
            {
                return;
            }

            switch (choose)
            {
            case THEM:
            {
                if (Program.conn.State == ConnectionState.Closed)
                {
                    Program.conn.Open();
                }

                String strLenh = "sp_KTMaSV";
                Program.sqlcmd             = Program.conn.CreateCommand();
                Program.sqlcmd.CommandType = CommandType.StoredProcedure;
                Program.sqlcmd.CommandText = strLenh;
                Program.sqlcmd.Parameters.Add("@MASV", SqlDbType.Text).Value   = txtMASV.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ã sinh viên bị trùng!", "", MessageBoxButtons.OK);
                    txtMaLop.Focus();
                    Program.conn.Close();
                    return;
                }

                try
                {
                    bdsSinhVien.EndEdit();
                    bdsSinhVien.ResetCurrentItem();
                    this.SinhVienTableAdapter.Connection.ConnectionString = Program.connstr;
                    this.SinhVienTableAdapter.Update(this.DS.SINHVIEN);

                    String       lenhXoaSV = "exec sp_XoaSinhVien '" + txtMASV.Text + "'";
                    UndoSinhVien undoSV    = new UndoSinhVien(THEM, lenhXoaSV);
                    st.Push(undoSV);
                    //capNhatBtnPhucHoi();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Lỗi ghi sinh viên.\n" + ex.Message, "", MessageBoxButtons.OK);
                    return;
                }
                gcSinhVien.Enabled = true;
                btnThem.Enabled    = btnHieuChinh.Enabled = btnXoa.Enabled = btnPhucHoi.Enabled = btnThoat.Enabled = true;
                btnGhi.Enabled     = false;
                groupBox1.Enabled  = false;
                capNhatBtnPhucHoi();
                isDangThem = false;
                break;
            }

            case HIEU_CHINH:
            {
                try
                {
                    bdsSinhVien.EndEdit();
                    bdsSinhVien.ResetCurrentItem();
                    this.SinhVienTableAdapter.Connection.ConnectionString = Program.connstr;
                    this.SinhVienTableAdapter.Update(this.DS.SINHVIEN);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Lỗi hiệu chỉnh sinh viên.\n" + ex.Message, "", MessageBoxButtons.OK);
                    return;
                }
                gcSinhVien.Enabled = true;
                btnThem.Enabled    = btnHieuChinh.Enabled = btnXoa.Enabled = btnPhucHoi.Enabled = btnThoat.Enabled = true;
                btnGhi.Enabled     = btnPhucHoi.Enabled = false;
                groupBox1.Enabled  = false;
                capNhatBtnPhucHoi();
                break;
            }
            }
        }