protected void btnGenerateVoucher_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidateGenerateVoucher())
                {
                    Voucher voucher = PrepareVoucher();
                    Business.ClaimManagement.Voucher        objVoucher        = new Business.ClaimManagement.Voucher();
                    Business.ClaimManagement.VoucherPayment objVoucherPayment = new Business.ClaimManagement.VoucherPayment();
                    Business.ClaimManagement.VoucherPaymentDetailsDetails objVoucherPaymentDetailsDetails = new Business.ClaimManagement.VoucherPaymentDetailsDetails();
                    int voucherId = objVoucher.Voucher_Save(voucher);

                    VoucherPayment voucherPayment = voucher.VoucherPayment;
                    voucherPayment.VoucherId = voucherId;
                    int voucherPaymentId = objVoucherPayment.VoucherPayment_Save(voucherPayment);

                    int retValue = 0;
                    List <VoucherPaymentDetails> voucherPaymentDetailsList = new List <VoucherPaymentDetails>();
                    voucherPaymentDetailsList = voucher.VoucherPayment.VoucherPaymentDetailsList;
                    retValue = VoucherPaymentDetails_Save(objVoucherPaymentDetailsDetails, voucherPaymentId, retValue, voucherPaymentDetailsList);

                    DataTable dtVoucher = objVoucher.Voucher_GetById(voucherId);
                    if (dtVoucher != null && dtVoucher.AsEnumerable().Any() && retValue == voucherPaymentDetailsList.Count())
                    {
                        ClaimApplicationStatusUpdate();
                        int claimDisbursementId = ClaimDisbursement_Save(voucherId);
                        ClaimDisbursementDetails_Save(claimDisbursementId);
                        ClaimApplication_GetAll();
                        ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('VoucherPrint.aspx?no=" + dtVoucher.Rows[0]["VoucherNo"].ToString() + "','mywindow','menubar=1,resizable=1,width=900,height=600');", true);
                        MessageSuccess.IsSuccess  = true;
                        MessageSuccess.Text       = string.Format("Voucher generated successfully. Voucher number is <a target='_blank' href='../ClaimManagement/VoucherPrint.aspx?no={0}'>{0}</a>", dtVoucher.Rows[0]["VoucherNo"].ToString());
                        MessageSuccess.Show       = true;
                        lblTotalAmountPaying.Text = "0.00";
                        _ClaimPaymentDetails      = null;
                        LoadClaimPaymentDetails();
                    }
                    else
                    {
                        Message.IsSuccess = false;
                        Message.Text      = "Voucher generation failed.";
                        Message.Show      = true;
                        ModalPopupExtender1.Show();
                    }

                    ClearPaymentDetailsControls();
                    _ClaimPaymentDetails.Clear();
                    LoadClaimPaymentDetails();
                }
            }
            catch (Exception ex)
            {
                ex.WriteException();
                Message.IsSuccess = false;
                Message.Text      = ex.Message;
                Message.Show      = true;
            }
        }
        private static int VoucherPaymentDetails_Save(Business.ClaimManagement.VoucherPaymentDetailsDetails objVoucherPaymentDetailsDetails, int voucherPaymentId, int retValue, List <VoucherPaymentDetails> voucherPaymentDetailsList)
        {
            foreach (VoucherPaymentDetails voucherPaymentDetails in voucherPaymentDetailsList)
            {
                voucherPaymentDetails.VoucherPaymentId = voucherPaymentId;
                retValue += objVoucherPaymentDetailsDetails.VoucherPaymentDetails_Save(voucherPaymentDetails);
            }

            return(retValue);
        }