Ejemplo n.º 1
0
        private void btnXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (Program.conn.State == ConnectionState.Closed)
            {
                Program.conn.Open();
            }
            String strLenh = "dbo.SP_Ktra_DDH_co_CTDDH";

            Program.sqlcmd             = Program.conn.CreateCommand();
            Program.sqlcmd.CommandType = CommandType.StoredProcedure;
            Program.sqlcmd.CommandText = strLenh;
            Program.sqlcmd.Parameters.Add("@MasoDDH", SqlDbType.NChar).Value = txtMaDDH.Text;
            Program.sqlcmd.Parameters.Add("@Ret", SqlDbType.NChar).Direction = ParameterDirection.ReturnValue;
            Program.sqlcmd.ExecuteNonQuery();
            Program.conn.Close();
            String Ret = Program.sqlcmd.Parameters["@Ret"].Value.ToString();

            if (Ret != "0")
            {
                MessageBox.Show("Mã ĐƠN ĐẶT HÀNG đã có CTDDH!", "", MessageBoxButtons.OK);
                txtMaDDH.Focus();
                return;
            }

            if (MessageBox.Show("Bạn có thật sự muốn xóa DDH này ?? ", "Xác nhận",
                                MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                try
                {
                    luaChon = XOA;
                    DDH        ddh = new DDH(txtMaDDH.Text, dtNgay.Text, txtNhaCC.Text, cmbMANV.Text, cmbMAKHO.Text); //truyền các giá trị vô KHO
                    ObjectUndo ob  = new ObjectUndo(luaChon, ddh);
                    st.Push(ob);

                    bdsDDH.RemoveCurrent();
                    this.dATHANGTableAdapter.Connection.ConnectionString = Program.connstr;
                    this.dATHANGTableAdapter.Update(this.dS.DATHANG);
                    this.nHANVIENTableAdapter.Connection.ConnectionString = Program.connstr;
                    this.nHANVIENTableAdapter.Update(this.dS.NHANVIEN);
                    this.kHOTableAdapter.Connection.ConnectionString = Program.connstr;
                    this.kHOTableAdapter.Update(this.dS.KHO);
                    updateButtonPhucHoi();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Lỗi xóa Đơn Đặt Hàng. Bạn hãy xóa lại\n" + ex.Message, "", MessageBoxButtons.OK);
                    this.dATHANGTableAdapter.Fill(this.dS.DATHANG);
                    //bdsKho.Position = bdsKho.Find("MAKHO", makho);
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        private void btnSua_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            groupBox1.Enabled = true;
            btnThem.Enabled   = btnXoa.Enabled = btnReLoad.Enabled = btnSua.Enabled = false;
            btnGhi.Enabled    = btnUndo.Enabled = btnThoat.Enabled = true;
            luaChon           = SUA;

            DDH        ddh = new DDH(txtMaDDH.Text, dtNgay.Text, txtNhaCC.Text, cmbMANV.Text, cmbMAKHO.Text); //truyền các giá trị vô KHO
            ObjectUndo ob  = new ObjectUndo(luaChon, ddh);

            st.Push(ob);
            updateButtonPhucHoi();
        }
Ejemplo n.º 3
0
        private void btnUndo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (btnSua.Enabled == false || btnThem.Enabled == false)
            {
                this.bdsDDH.CancelEdit();
                gcDatHang.Enabled = true;
                groupBox1.Enabled = false;
                btnThem.Enabled   = btnSua.Enabled = btnXoa.Enabled = btnReLoad.Enabled = btnThoat.Enabled = true;
                btnGhi.Enabled    = btnSua.Enabled = false;
            }
            try
            {
                ObjectUndo ob = (ObjectUndo)st.Pop();

                switch (ob.luaChon)
                {
                case THEM:
                    String lenh = (String)ob.obj;
                    MessageBox.Show("Khôi phục sau khi THÊM ");
                    Program.ExecSqlDataReader(lenh);
                    this.dATHANGTableAdapter.Fill(this.dS.DATHANG);
                    break;

                case SUA:
                    MessageBox.Show("Khôi phục sau khi SỬA ");
                    DDH ddh = (DDH)ob.obj;
                    if (Program.conn.State == ConnectionState.Closed)
                    {
                        Program.conn.Open();
                    }
                    String strLenh = "dbo.SP_UndoSuaDDH";
                    Program.sqlcmd             = Program.conn.CreateCommand();
                    Program.sqlcmd.CommandType = CommandType.StoredProcedure;
                    Program.sqlcmd.CommandText = strLenh;
                    Program.sqlcmd.Parameters.Add("@MasoDDH", SqlDbType.NChar).Value  = ddh.MasoDDH;
                    Program.sqlcmd.Parameters.Add("@NGAY", SqlDbType.NVarChar).Value  = ddh.Ngay;
                    Program.sqlcmd.Parameters.Add("@NhaCC", SqlDbType.NVarChar).Value = ddh.NhaCC;
                    Program.sqlcmd.Parameters.Add("@MANV", SqlDbType.NVarChar).Value  = ddh.MaNV;
                    Program.sqlcmd.Parameters.Add("@MAKHO", SqlDbType.NVarChar).Value = ddh.MaKho;

                    Program.sqlcmd.Parameters.Add("@Ret", SqlDbType.NChar).Direction = ParameterDirection.ReturnValue;
                    Program.sqlcmd.ExecuteNonQuery();
                    Program.conn.Close();
                    String Ret = Program.sqlcmd.Parameters["@Ret"].Value.ToString();
                    if (Ret != "0")
                    {
                        MessageBox.Show("Khoi phuc khong thanh cong", "", MessageBoxButtons.OK);
                    }
                    else
                    {
                        MessageBox.Show("Khoi phuc thanh cong", "", MessageBoxButtons.OK);
                    }
                    break;

                case XOA:
                    MessageBox.Show("Khôi phục sau khi XÓA ");
                    DDH ddh1 = (DDH)ob.obj;
                    if (Program.conn.State == ConnectionState.Closed)
                    {
                        Program.conn.Open();
                    }
                    String strLenh1 = "dbo.SP_UndoXoaDDH";
                    Program.sqlcmd             = Program.conn.CreateCommand();
                    Program.sqlcmd.CommandType = CommandType.StoredProcedure;
                    Program.sqlcmd.CommandText = strLenh1;
                    Program.sqlcmd.Parameters.Add("@MasoDDH", SqlDbType.NChar).Value  = ddh1.MasoDDH;
                    Program.sqlcmd.Parameters.Add("@NGAY", SqlDbType.NVarChar).Value  = ddh1.Ngay;
                    Program.sqlcmd.Parameters.Add("@NhaCC", SqlDbType.NVarChar).Value = ddh1.NhaCC;
                    Program.sqlcmd.Parameters.Add("@MANV", SqlDbType.NVarChar).Value  = ddh1.MaNV;
                    Program.sqlcmd.Parameters.Add("@MAKHO", SqlDbType.NVarChar).Value = ddh1.MaKho;

                    Program.sqlcmd.Parameters.Add("@Ret", SqlDbType.NChar).Direction = ParameterDirection.ReturnValue;
                    Program.sqlcmd.ExecuteNonQuery();
                    Program.conn.Close();
                    String Ret1 = Program.sqlcmd.Parameters["@Ret"].Value.ToString();
                    if (Ret1 != "0")
                    {
                        MessageBox.Show("Khoi phuc khong thanh cong", "", MessageBoxButtons.OK);
                    }
                    else
                    {
                        MessageBox.Show("Khoi phuc thanh cong", "", MessageBoxButtons.OK);
                    }
                    break;
                }
                bdsDDH.EndEdit();
                bdsDDH.ResetCurrentItem();
                this.dATHANGTableAdapter.Connection.ConnectionString = Program.connstr;
                this.dATHANGTableAdapter.Update(this.dS.DATHANG);

                updateButtonPhucHoi();
                reload();
            }
            catch (Exception)
            {
                MessageBox.Show("Không có gì để UNDO", "THÔNG BÁO", MessageBoxButtons.OK);
            }
        }