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_PhieuXuat_Ktra_CTPX";

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

            if (Ret != "0")
            {
                MessageBox.Show("PHIẾU XUẤT CÓ CTPX KHÔNG XÓA ĐƯỢC!", "", MessageBoxButtons.OK);
                txtMAPX.Focus();
                return;
            }
            if (MessageBox.Show("Bạn có thật sự muốn xóa PHIẾU XUẤT này ?? ", "Xác nhận",
                                MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                try
                {
                    luaChon = XOA;
                    PhieuXuat  phieuxuat = new PhieuXuat(txtMAPX.Text, dtNgay.Text, txtHOTENKH.Text, cmbMANV.Text, cmbMAKHO.Text);; //truyền các giá trị vô KHO
                    ObjectUndo ob        = new ObjectUndo(luaChon, phieuxuat);
                    st.Push(ob);

                    bdsPhieuXuat.RemoveCurrent();
                    this.pHIEUXUATTableAdapter.Connection.ConnectionString = Program.connstr;
                    this.pHIEUXUATTableAdapter.Update(this.dS.PHIEUXUAT);
                    updateButtonPhucHoi();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Lỗi xóa PHIẾU XUẨT. Bạn hãy xóa lại\n" + ex.Message, "", MessageBoxButtons.OK);
                    this.pHIEUXUATTableAdapter.Fill(this.dS.PHIEUXUAT);
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        private void btnPhucHoi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (btnSua.Enabled == false || btnThem.Enabled == false)
            {
                this.bdsPhieuXuat.CancelEdit();
                //if (btnThem.Enabled == false) bdsKho.Position = vitri;
                gcPhieuXuat.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.pHIEUXUATTableAdapter.Fill(this.dS.PHIEUXUAT);
                    break;

                case SUA:
                    MessageBox.Show("Khôi phục sau khi SỬA ");
                    PhieuXuat phieuxuat = (PhieuXuat)ob.obj;
                    if (Program.conn.State == ConnectionState.Closed)
                    {
                        Program.conn.Open();
                    }
                    String strLenh = "dbo.SP_UndoSuaPhieuXuat";
                    Program.sqlcmd             = Program.conn.CreateCommand();
                    Program.sqlcmd.CommandType = CommandType.StoredProcedure;
                    Program.sqlcmd.CommandText = strLenh;
                    Program.sqlcmd.Parameters.Add("@MAPX", SqlDbType.NChar).Value       = phieuxuat.maPhieuXuat;
                    Program.sqlcmd.Parameters.Add("@NGAY", SqlDbType.Date).Value        = phieuxuat.ngay;
                    Program.sqlcmd.Parameters.Add("@HOTENKH", SqlDbType.NVarChar).Value = phieuxuat.HotenKH;
                    Program.sqlcmd.Parameters.Add("@MANV", SqlDbType.Int).Value         = phieuxuat.MaNV;
                    Program.sqlcmd.Parameters.Add("@MAKHO", SqlDbType.NChar).Value      = phieuxuat.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 ");
                    PhieuNhap phieunhap1 = (PhieuNhap)ob.obj;
                    if (Program.conn.State == ConnectionState.Closed)
                    {
                        Program.conn.Open();
                    }
                    String strLenh1 = "dbo.SP_UndoXoaPhieuNhap";
                    Program.sqlcmd             = Program.conn.CreateCommand();
                    Program.sqlcmd.CommandType = CommandType.StoredProcedure;
                    Program.sqlcmd.CommandText = strLenh1;
                    Program.sqlcmd.Parameters.Add("@MAPN", SqlDbType.NChar).Value    = phieunhap1.maPhieuNhap;
                    Program.sqlcmd.Parameters.Add("@NGAY", SqlDbType.Date).Value     = phieunhap1.ngay;
                    Program.sqlcmd.Parameters.Add("@MasoDDH", SqlDbType.NChar).Value = phieunhap1.MasoDDH;
                    Program.sqlcmd.Parameters.Add("@MANV", SqlDbType.Int).Value      = phieunhap1.MaNV;
                    Program.sqlcmd.Parameters.Add("@MAKHO", SqlDbType.NChar).Value   = phieunhap1.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;
                }
                bdsPhieuXuat.EndEdit();
                bdsPhieuXuat.ResetCurrentItem();
                this.pHIEUXUATTableAdapter.Connection.ConnectionString = Program.connstr;
                this.pHIEUXUATTableAdapter.Update(this.dS.PHIEUXUAT);

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