예제 #1
0
    protected void GrdCredit_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "_Delete")
        {
            try
            {
                int    credit_id = Convert.ToInt32(e.CommandArgument);
                Credit credit    = CreditDB.GetByID(credit_id);

                UserView userview = UserView.GetInstance();

                if (userview.IsProviderView && Convert.ToInt32(Session["StaffID"]) != credit.AddedBy.StaffID)
                {
                    throw new CustomMessageException("You Can Not Delete Vouchers Entered By Other Providers.");
                }

                CreditDB.SetAsDeleted(credit_id, Convert.ToInt32(Session["StaffID"]));

                FillCreditGrid();
                FillPayments();
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = ex.Message;
            }
        }
    }
예제 #2
0
    protected void ReverseVoucher_Command(object sender, CommandEventArgs e)
    {
        try
        {
            // for some reason, it doesn't keep the command argument when set in
            // the code behind in a nested repeater, so set it in a hidden control and its fine

            //int creditID = Convert.ToInt32(e.CommandArgument);

            int creditID = -1;
            foreach (Control c in ((Control)sender).Parent.Controls)
            {
                if (c.ID == "lblHiddenVoucherID")
                {
                    creditID = Convert.ToInt32(((HiddenField)c).Value);
                }
            }


            Credit credit = CreditDB.GetByID(creditID);
            if (credit == null)
            {
                throw new CustomMessageException("Invalid voucher - does not exist");
            }
            if (credit.IsDeleted)
            {
                throw new CustomMessageException("Voucher already reversed");
            }

            CreditDB.SetAsDeleted(credit.CreditID, Convert.ToInt32(Session["StaffID"]));

            FillInvoicesList();
        }
        catch (CustomMessageException cmEx)
        {
            SetErrorMessage(cmEx.Message);
        }
        catch (Exception ex)
        {
            SetErrorMessage("", ex.ToString());
        }
    }