private void FillEditViewForm(bool isEditMode)
    {
        Credit credit = CreditDB.GetByID(GetFormID());

        if (credit == null)
        {
            HideTableAndSetErrorMessage("Invalid ID");
            return;
        }

        FillCreditGrid(credit);

        string heading = "";

        if (credit.CreditType.ID == 1)
        {
            heading = "Voucher";
        }
        if (credit.CreditType.ID == 2)
        {
            heading = "Use Of Voucher";
        }
        if (credit.CreditType.ID == 3)
        {
            heading = "Cashout - Tyro To Mediclinic";
        }
        if (credit.CreditType.ID == 4)
        {
            heading = "Cashout - Mediclinic To Patient";
        }
        lblHeading.Text = isEditMode ? "Edit " + heading : "View " + heading;

        if (isEditMode && credit.CreditType.ID != 1)
        {
            throw new CustomMessageException("Can no edit a '" + heading + "'");
        }

        lblId.Text        = credit.CreditID.ToString();
        lblType.Text      = credit.CreditType.Descr;
        idRow.Visible     = Utilities.IsDev();
        typeRow.Visible   = Utilities.IsDev();
        clinicRow.Visible = false;

        bool isMobileDevice = Utilities.IsMobileDevice(Request);

        lblInvoice.Text = GetInvoiceLink(isMobileDevice, credit);
        lblVoucher.Text = GetVoucherLink(isMobileDevice, credit);

        lblAddedBy.Text          = credit.AddedBy.Person.FullnameWithoutMiddlename;
        lblDateAdded.Text        = credit.DateAdded.ToString("d MMM, yyyy");
        lblModifiedBy.Text       = credit.ModifiedBy == null ? "" : credit.ModifiedBy.Person.FullnameWithoutMiddlename;
        lblDateModified.Text     = credit.DateModified == DateTime.MinValue  ? "" : credit.DateModified.ToString("d MMM, yyyy");
        lblDeletedBy.Text        = credit.DeletedBy == null ? string.Empty : credit.DeletedBy.Person.FullnameWithoutMiddlename;
        lblDateDeleted.Text      = credit.DateDeleted == DateTime.MinValue  ? "" : credit.DateDeleted.ToString("d MMM, yyyy");
        lblPreDeletedAmount.Text = ((credit.CreditType.ID == 1 || credit.CreditType.ID == 3 ? 1 : -1) * credit.PreDeletedAmount).ToString();

        bool isDeleted = credit.DeletedBy != null || credit.DateDeleted != DateTime.MinValue;

        if (!isDeleted)
        {
            deletedSpaceRow.Visible     = false;
            deletedbyRow.Visible        = false;
            dateDeletedRow.Visible      = false;
            preDeletedAmountRow.Visible = false;
        }

        bool isModified = credit.ModifiedBy != null || credit.DateModified != DateTime.MinValue;

        if (!isModified)
        {
            modifiedbyRow.Visible   = false;
            dateModifiedRow.Visible = false;
        }

        invoiceListSpaceRow.Visible = false;
        invoiceListRow.Visible      = false;
        amountUsedRow.Visible       = false;
        amountRemainingRow.Visible  = false;

        if (credit.CreditType.ID == 1)
        {
            Credit[] payments = CreditDB.GetByVoucherCreditID(credit.CreditID);
            if (payments.Length > 0)
            {
                string invoicesText = string.Empty;
                foreach (Credit payment in payments)
                {
                    string invoiceLink = GetInvoiceLink(isMobileDevice, payment);
                    if (invoiceLink != null && invoiceLink.Length > 0)
                    {
                        invoicesText += (invoicesText.Length == 0 ? "" : "<br />") + invoiceLink + " $" + (-1 * payment.Amount);
                    }
                }

                if (invoicesText.Length > 0)
                {
                    invoiceListSpaceRow.Visible      = true;
                    invoiceListRow.Visible           = true;
                    lblInvoicesUsingThisVoucher.Text = invoicesText;
                }
            }


            decimal totalUsed = CreditDB.GetTotalUsed(credit.CreditID);
            amountUsedRow.Visible      = true;
            amountRemainingRow.Visible = true;
            lblAmountUsed.Text         = (-1 * totalUsed).ToString();
            lblRemainingUsed.Text      = (credit.Amount + totalUsed).ToString();
        }



        if (isEditMode)
        {
            txtAmount.Visible = false;
            lblAmount.Text    = credit.Amount.ToString();

            txtDescr.Text = credit.VoucherDescr;

            if (credit.ExpiryDate != DateTime.MinValue)
            {
                ddlExpiry_Day.SelectedValue   = credit.ExpiryDate.Day.ToString();
                ddlExpiry_Month.SelectedValue = credit.ExpiryDate.Month.ToString();
                ddlExpiry_Year.SelectedValue  = credit.ExpiryDate.Year.ToString();
            }

            lblDescr.Visible  = false;
            lblExpiry.Visible = false;
        }
        else
        {
            lblAmount.Text = ((credit.CreditType.ID == 1 || credit.CreditType.ID == 3 ? 1 : -1) * credit.Amount).ToString();
            lblDescr.Text  = credit.VoucherDescr;
            lblExpiry.Text = credit.ExpiryDate == DateTime.MinValue ? "No Date Set" : credit.ExpiryDate.ToString("d MMM, yyyy");

            txtAmount.Visible       = false;
            txtDescr.Visible        = false;
            ddlExpiry_Day.Visible   = false;
            ddlExpiry_Month.Visible = false;
            ddlExpiry_Year.Visible  = false;
        }


        if (credit.CreditType.ID != 1)
        {
            descrRow.Visible  = false;
            expiryRow.Visible = false;
        }
        if (credit.CreditType.ID != 2)
        {
            voucherUsedRow.Visible = false;
            invoiceRow.Visible     = false;
        }

        btnSubmit.Text = isEditMode ? "Update Details" : "Edit Details";
        btnCancel.Text = isEditMode ? "Cancel" : "Close";

        btnSubmit.Visible = !isDeleted && credit.CreditType.ID == 1;
    }