Exemplo n.º 1
0
        private void btnHieuChinh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            vitri             = bdsDsLop.Position;
            groupBox1.Enabled = true;
            btnThem.Enabled   = btnHieuChinh.Enabled = btnXoa.Enabled = btnReload.Enabled = btnExit.Enabled = false;
            btnGhi.Enabled    = btnPhucHoi.Enabled = true;
            txtMaLop.Enabled  = txtMaKhoa.Enabled = false;
            txtTenLop.Focus();
            gcLop.Enabled = false;
            choose        = Program.HIEU_CHINH;

            // lưu stack cho undo

            lop = new Lop(txtMaLop.Text, txtTenLop.Text, txtMaKhoa.Text);
        }
Exemplo n.º 2
0
        private void btnPhucHoi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (btnHieuChinh.Enabled == false || btnThem.Enabled == false)
            {
                bdsDsLop.CancelEdit();
                this.lOPTableAdapter.Connection.ConnectionString = Program.connstr;

                if (btnThem.Enabled == false)
                {
                    bdsDsLop.Position = vitri;
                }
                gcLop.Enabled     = true;
                groupBox1.Enabled = false;
                btnThem.Enabled   = btnHieuChinh.Enabled = btnXoa.Enabled = btnReload.Enabled = btnExit.Enabled = true;
                btnGhi.Enabled    = btnPhucHoi.Enabled = false;

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

                Program.ObjectUndo objUndo = (Program.ObjectUndo)st.Peek();
                Object             obj     = objUndo.obj;

                switch (objUndo.type)
                {
                case Program.THEM:
                    if (MessageBox.Show("Khôi phục sau khi thêm", "Xác nhận", MessageBoxButtons.OKCancel)
                        == DialogResult.Cancel)
                    {
                        return;
                    }

                    st.Pop();
                    String lenh = "";

                    try
                    {
                        lenh = obj.ToString();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

                    Program.ExecSqlDataReader(lenh);
                    this.lOPTableAdapter.Fill(this.dS.LOP);
                    updateUIButtonPhucHoi();

                    break;

                case Program.HIEU_CHINH:
                    if (MessageBox.Show("Khôi phục sau khi hiệu chỉnh", "Xác nhận", MessageBoxButtons.OKCancel)
                        == DialogResult.Cancel)
                    {
                        return;
                    }

                    st.Pop();
                    try
                    {
                        Lop lopHieuChinh = (Lop)objUndo.obj;
                        MessageBox.Show(lopHieuChinh.tenLop);

                        if (Program.conn.State == ConnectionState.Closed)
                        {
                            Program.conn.Open();
                        }
                        String strLenh = "dbo.sp_UndoHieuChinh";
                        Program.sqlcmd             = Program.conn.CreateCommand();
                        Program.sqlcmd.CommandType = CommandType.StoredProcedure;
                        Program.sqlcmd.CommandText = strLenh;
                        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();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

                    break;

                case Program.XOA:
                    if (MessageBox.Show("Khôi phục sau khi xóa", "Xác nhận", MessageBoxButtons.OKCancel)
                        == DialogResult.Cancel)
                    {
                        return;
                    }

                    st.Pop();

                    try
                    {
                        Lop lopXoa = (Lop)objUndo.obj;

                        String    sql = "exec sp_InsertLop N'" + lopXoa.maLop + "', N'" + lopXoa.tenLop + "', N'" + maKhoa + "'";
                        DataTable tb  = Program.ExecSqlDataTable(sql);
                        if (tb.Rows.Count > 0)
                        {
                            MessageBox.Show("Undo success");
                        }
                        else
                        {
                            MessageBox.Show("Undo failed");
                        }

                        reload();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    break;
                }
            }
        }