protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            string bookingRef = "";
            string emailId = "";
            string lastName = "";
            string webService = "";
            string startDate = "";
            string endDate = "";

            HotelBAL obj = new HotelBAL();
            obj.ReferenceNo = txtBookingRefNo.Text.ToString().Trim().ToString();
            DataSet ds = obj.GetHotelProvisional();

            if (ds == null)
            { lblMsg.Text = "Invalid reference number."; return; }
            if (ds.Tables.Count == 0)
            { lblMsg.Text = "Invalid reference number."; return; }
            if (ds.Tables[0].Rows.Count == 0)
            { lblMsg.Text = "Invalid reference number."; return; }

            DataRow dr = ds.Tables[0].Rows[0];

            emailId = dr["EmailId"].ToString();
            lastName = dr["LastName"].ToString();
            bookingRef = dr["BookingRefNo"].ToString();
            webService = dr["WebService"].ToString();
            startDate = ConvertDate(dr["CheckIn"].ToString());
            endDate = ConvertDate1(dr["CheckOut"].ToString());
            string status = dr["Status"].ToString();
            double hotelTotalFare = Convert.ToDouble(dr["HotelTotalFare"].ToString());

            if (status == "Cancelled") { lblMsg.Text = "Already this ticket has been cancelled."; return; }

            DataSet dsHotelCancellation = objArzooHotelAPILayer.HotelCancellation(emailId, lastName, bookingRef, webService, startDate, endDate);

            if (!dsHotelCancellation.Tables.Contains("HotelCancellation"))
            { lblMsg.Text = "Failed to cancel the ticket."; return; }

            DataTable dtCancellation = dsHotelCancellation.Tables["HotelCancellation"];
            if (dtCancellation.Rows.Count > 0)
            {
                DataRow item = dtCancellation.Rows[0];
                string cancellationId = item["cancellationId"].ToString();
                string refundTotalAmount = item["refundTotalAmount"].ToString();
                string cancellationAmount = item["cancellationAmount"].ToString();
                string success = item["success"].ToString();
                string error = item["error"].ToString();
                if (success != "" && cancellationId != "")
                {
                    lblMsg.Text = "Status: " + "Ticket has been cancelled successfully.";
                    string provisionalId = dr["ProvisionalId"].ToString();
                    string bookingId = dr["BookingId"].ToString();

                    double cancellationCharges = hotelTotalFare - Convert.ToDouble(refundTotalAmount);

                    InsertCancellaion(provisionalId, bookingId, Convert.ToDouble(refundTotalAmount),
                        cancellationCharges, Convert.ToInt32(Session["UserID"].ToString()), cancellationId);

                    objBAL = new ClsBAL();
                    objBAL.AdjustAgentBalance(txtBookingRefNo.Text.Trim().ToString(),
                        Convert.ToDouble(refundTotalAmount), Convert.ToDouble(cancellationCharges),
                        Convert.ToInt32(Session["UserID"].ToString()));

                    DataSet dsBalance = objBAL.GetAgentByUserId(Convert.ToInt32(Session["UserID"].ToString()));

                    string balance = dsBalance.Tables[0].Rows[0]["Balance"].ToString();
                    Label lbl = (Label)this.Master.FindControl("lblBalance");
                    lbl.Text = balance;
                    Session["Balance"] = balance;
                    txtBookingRefNo.Text = "";
                }
                else if (error != "") { lblMsg.Text = error.ToString(); }
                else { lblMsg.Text = "Failed to cancel the ticket."; }
            }

        }
        catch (Exception ex)
        {
            lblMsg.Text = ex.Message;
        }
    }
    protected void btnGet_Click(object sender, EventArgs e)
    {
        try
        {
            DataSet dsGetTransId = new DataSet();
            dsGetTransId = objFlightBal.GetTransID(txtBookingReferenceNo.Text);
            transId = dsGetTransId.Tables[0].Rows[0]["transid"].ToString();

            if (transId != "")
            {

                String xmlCancelReqStatus = "<EticketCanStatusReq><Clientid>" + FlightsConstants.USERID + "</Clientid><Clientpassword>" + FlightsConstants.PASSWORD + "</Clientpassword><Clienttype>ArzooFWS1.0</Clienttype><transid>" + transId + "</transid><partnerRefId></partnerRefId><CancellationId></CancellationId></EticketCanStatusReq>";
                 DataSet dsCancelStatusResponse = objFlights.GetCancelTicketStatus(xmlCancelReqStatus);
                //DataSet dsCancelStatusResponse = new DataSet();
                //dsCancelStatusResponse.ReadXml("F:\\Projects\\Love Journey\\Cancel_Domestic_Static_Response.xml");
                if (dsCancelStatusResponse != null)
                {
                    objFlightBal.Status = dsCancelStatusResponse.Tables["Cancellation"].Rows[0]["CancellationStatus"].ToString();
                    objFlightBal.TransId = dsCancelStatusResponse.Tables["EticketCanStatusRes"].Rows[0]["transid"].ToString();
                    objFlightBal.ReferenceNo = txtBookingReferenceNo.Text;

                    objFlightBal.CancellationProcessDateTime = dsCancelStatusResponse.Tables["Cancellation"].Rows[0]["CancellationProcessDateTime"].ToString();
                    objFlightBal.CancellationCharges = dsCancelStatusResponse.Tables["Cancellation"].Rows[0]["CancellationCharges"].ToString();
                    objFlightBal.RefundStatus = dsCancelStatusResponse.Tables["Cancellation"].Rows[0]["RefundStatus"].ToString();
                    objFlightBal.FinalRefundAmount = dsCancelStatusResponse.Tables["Cancellation"].Rows[0]["FinalRefundAmount"].ToString();
                    objFlightBal.RefundDateTime = dsCancelStatusResponse.Tables["Cancellation"].Rows[0]["RefundDateTime"].ToString();

                    bool res = objFlightBal.UpdateDomesticFlightCancelStatus(objFlightBal);
                    ClsBAL objBAL = new ClsBAL();
                    objBAL.AdjustAgentBalance(txtBookingReferenceNo.Text.Trim().ToString(),
                        Convert.ToDouble(objFlightBal.FinalRefundAmount), Convert.ToDouble(objFlightBal.CancellationCharges),
                        Convert.ToInt32(Session["UserID"].ToString()));

                    DataSet dsBalance = objBAL.GetAgentByUserId(Convert.ToInt32(Session["UserID"].ToString()));

                    string balance = dsBalance.Tables[0].Rows[0]["Balance"].ToString();
                    Label lbl = (Label)this.Master.FindControl("lblBalance");
                    lbl.Text = balance;
                    Session["Balance"] = balance;
                    if (res)
                    {
                        lblStatus.Text = "Updated the status";
                        lblStatus.ForeColor = System.Drawing.Color.Green;
                        lblStatus.Visible = true;
                    }
                }
            }
            else
            {
                lblStatus.Text = "Invalid Request";
            }
        }
        catch (Exception ex)
        {

        }
    }
    protected void CancelBitlaTickets(string CancelType, string SeatNos)
    {
        try
        {
            if (ViewState["dsticketdetails"] != null)
            {
                DataTable dt = (DataTable)ViewState["dsticketdetails"];
                int BookingId = Convert.ToInt32(dt.Rows[0]["BookingId"].ToString());
                int tentativeId = Convert.ToInt32(dt.Rows[0]["TentativeId"].ToString());
                string EmailId = dt.Rows[0]["EmailId"].ToString();
                string Name = dt.Rows[0]["FullName"].ToString();
                string ticketNumberBitla = dt.Rows[0]["PNRNumber"].ToString();
                string seatNumbersBitla = dt.Rows[0]["SeatNos"].ToString();
                string cancelllationId = dt.Rows[0]["CancellationId"].ToString();
                string CancelledSaets = dt.Rows[0]["CancelledSeats"].ToString();

                if (CancelType == "Total Cancellation")
                {
                    objBitlaAPILayer.TicketNumber = ticketNumberBitla;
                    objBitlaAPILayer.SeatNumbers = SeatNos;
                    DataSet dsBitla = objBitlaAPILayer.IsTicketCancellable();

                    #region Cancellation
                    if (dsBitla != null)
                    {
                        if (dsBitla.Tables[0].Rows.Count > 0 && dsBitla.Tables[0].Columns.Count > 2)
                        {
                            string refundAmount = dsBitla.Tables[0].Rows[0]["refund_amount"].ToString();
                            string cancellationCharges = dsBitla.Tables[0].Rows[0]["cancellation_charges"].ToString();
                            if (dsBitla.Tables[0].Rows[0]["is_cancellable"].ToString().ToUpper().ToString() == "TRUE")
                            {
                                objBitlaAPILayer.TicketNumber = ticketNumberBitla;
                                DataSet dsBitla1 = objBitlaAPILayer.CancelTicket();

                                if (dsBitla1 != null)
                                {
                                    if (dsBitla1.Tables.Count > 0)
                                    {
                                        if (dsBitla1.Tables[0].Columns.Count > 1 && dsBitla1.Tables[0].Rows.Count > 0)
                                        {
                                            AddCancellation(BookingId, tentativeId, SeatNos, EmailId, refundAmount, Convert.ToString(Convert.ToDouble(refundAmount) + Convert.ToDouble(cancellationCharges)), "Bitla", hour);

                                            Mail(dt.Rows[0]["EmailId"].ToString(), dt.Rows[0]["PGMBRefNo"].ToString());

                                            objBAL = new ClsBAL();
                                            objBAL.AdjustAgentBalance(txtMBRefNo.Text.Trim().ToString(),
                                                Convert.ToDouble(refundAmount), Convert.ToDouble(cancellationCharges),
                                                Convert.ToInt32(Session["UserID"]));

                                            DataSet dsBalance = objBAL.GetAgentByUserId(Convert.ToInt32(Session["UserID"]));

                                            string balance = dsBalance.Tables[0].Rows[0]["Balance"].ToString();
                                            Label lbl = (Label)this.Master.FindControl("lblBalance");
                                            lbl.Text = balance;
                                            Session["Balance"] = balance;
                                            txtEmailID.Text = txtMBRefNo.Text = "";
                                        }
                                        else
                                        {
                                            lblMsg.Text = "Ticket cancelled failed. Try Again";
                                        }
                                    }
                                    else
                                    {
                                        lblMsg.Text = "Ticket cancelled failed. Try Again";
                                    }
                                }
                                else
                                {
                                    lblMsg.Text = "Ticket cancelled failed. Try Again";
                                }
                            }
                            else { lblMsg.Text = "Already cancelled "; }
                        }
                        else
                        {
                            lblMsg.Text = "Already cancelled ";
                        }
                    }
                    #endregion
                }
                else if (CancelType == "Partial Cancellation")
                {
                    objBitlaAPILayer.TicketNumber = ticketNumberBitla;
                    objBitlaAPILayer.SeatNumbers = SeatNos;
                    DataSet dsBitla = objBitlaAPILayer.IsTicketCancellable();

                    #region PartialCancellation
                    if (dsBitla != null)
                    {
                        if (dsBitla.Tables[0].Rows.Count > 0 && dsBitla.Tables[0].Columns.Count > 2)
                        {
                            string refundAmount = dsBitla.Tables[0].Rows[0]["refund_amount"].ToString();
                            string cancellationCharges = dsBitla.Tables[0].Rows[0]["cancellation_charges"].ToString();
                            if (dsBitla.Tables[0].Rows[0]["is_cancellable"].ToString() == "true")
                            {
                                objBitlaAPILayer.TicketNumber = ticketNumberBitla;
                                DataSet dsBitla1 = objBitlaAPILayer.CancelPartialTicket();
                                if (dsBitla1 != null)
                                {
                                    if (dsBitla1.Tables.Count > 0)
                                    {
                                        if (dsBitla1.Tables[0].Columns.Count > 1 && dsBitla1.Tables[0].Rows.Count > 0)
                                        {
                                            if (cancelllationId != "" && CancelledSaets != "")
                                            {
                                                UpdateCancelltion(Convert.ToInt32(cancelllationId), SeatNos, refundAmount, cancellationCharges);
                                            }
                                            else if (cancelllationId == "" && CancelledSaets == "")
                                            {
                                                AddCancellation(BookingId, tentativeId, SeatNos, EmailId, refundAmount, Convert.ToString(Convert.ToDouble(refundAmount) + Convert.ToDouble(cancellationCharges)), "Bitla", hour);
                                            }
                                        }
                                        else
                                        {
                                            lblMsg.Text = "Ticket cancelled failed. Try Again";
                                        }
                                    }
                                    else
                                    {
                                        lblMsg.Text = "Ticket cancelled failed. Try Again";
                                    }
                                }
                                else
                                {
                                    lblMsg.Text = "Ticket cancelled failed. Try Again";
                                }
                            }
                        }
                        else
                        {
                            lblMsg.Text = "Already cancelled ";
                        }
                    }
                    #endregion
                }
            }

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void CancelKesineniTickets(string CancelType, string SeatNos)
    {
        try
        {
            if (ViewState["dsticketdetails"] != null)
            {
                DataTable dt = (DataTable)ViewState["dsticketdetails"];
                int BookingId = Convert.ToInt32(dt.Rows[0]["BookingId"].ToString());
                int tentativeId = Convert.ToInt32(dt.Rows[0]["TentativeId"].ToString());
                string EmailId = dt.Rows[0]["EmailId"].ToString();
                string cancelllationId = dt.Rows[0]["CancellationId"].ToString();
                string CancelledSaets = dt.Rows[0]["CancelledSeats"].ToString();
                string pnrNumberKesineni = dt.Rows[0]["PNRNumber"].ToString().Trim().ToString();
                string firstNameKesineni = dt.Rows[0]["FullName"].ToString();
                string lastNameKesineni = dt.Rows[0]["FullName"].ToString();
                DateTime DOJ = Convert.ToDateTime(dt.Rows[0]["DateOfJourney"].ToString());
                string dateOfJourneyKesineni = DOJ.ToString("MM/dd/yyyy");
                string seatNumberListKesineni = dt.Rows[0]["SeatNos"].ToString();

                if (CancelType == "Total Cancellation")
                {
                    DataSet dsKesineni = objKesineniAPILayer.CancelTickets(pnrNumberKesineni, firstNameKesineni, lastNameKesineni,
             dateOfJourneyKesineni, SeatNos);

                    #region total Cancellation
                    if (dsKesineni != null)
                    {
                        if (dsKesineni.Tables[0].Rows.Count > 0 && dsKesineni.Tables[0].Columns.Count > 2)
                        {
                            double grandTotalRefund = Convert.ToDouble(dsKesineni.Tables[0].Rows[0]["GrandTotalRefunded"].ToString());
                            double cancellationCharges = Convert.ToDouble(dsKesineni.Tables[0].Rows[0]["CancellationCharges"].ToString());

                            DataSet dsKesineni1 = objKesineniAPILayer.ConfirmCancelTickets(pnrNumberKesineni, firstNameKesineni,
                             lastNameKesineni, dateOfJourneyKesineni, SeatNos);

                            if (dsKesineni1 != null)
                            {
                                if (dsKesineni1.Tables.Count > 0)
                                {
                                    if (dsKesineni1.Tables[0].Columns.Count > 1 && dsKesineni1.Tables[0].Rows.Count > 0)
                                    {
                                        AddCancellation(BookingId, tentativeId, SeatNos, EmailId, Convert.ToString(grandTotalRefund), Convert.ToString(Convert.ToDouble(grandTotalRefund) + Convert.ToDouble(cancellationCharges)), "", 0);

                                        objBAL = new ClsBAL();
                                        objBAL.AdjustAgentBalance(txtMBRefNo.Text.Trim().ToString(),
                                            Convert.ToDouble(grandTotalRefund), Convert.ToDouble(cancellationCharges),
                                            Convert.ToInt32(Session["UserID"]));

                                        DataSet dsBalance = objBAL.GetAgentByUserId(Convert.ToInt32(Session["UserID"]));

                                        string balance = dsBalance.Tables[0].Rows[0]["Balance"].ToString();
                                        Label lbl = (Label)this.Master.FindControl("lblBalance");
                                        lbl.Text = balance;
                                        Session["Balance"] = balance;
                                        txtEmailID.Text = txtMBRefNo.Text = "";
                                    }
                                    else
                                    {
                                        lblMsg.Text = "Ticket cancelled failed. Try Again";
                                        lblMsg.ForeColor = System.Drawing.Color.Red;
                                    }
                                }
                                else
                                {
                                    lblMsg.Text = "Ticket cancelled failed. Try Again";
                                    lblMsg.ForeColor = System.Drawing.Color.Red;
                                }
                            }
                            else
                            {
                                lblMsg.Text = "Ticket cancelled failed. Try Again";
                                lblMsg.ForeColor = System.Drawing.Color.Red;
                            }
                        }
                    }
                    #endregion
                }
                else if (CancelType == "Partial Cancellation")
                {
                    DataSet dsKesineni = objKesineniAPILayer.CancelTickets(pnrNumberKesineni, firstNameKesineni, lastNameKesineni,
              dateOfJourneyKesineni, SeatNos);

                    #region PartialCancellation
                    if (dsKesineni != null)
                    {
                        if (dsKesineni.Tables[0].Rows.Count > 0 && dsKesineni.Tables[0].Columns.Count > 2)
                        {
                            double grandTotalRefundp = Convert.ToDouble(dsKesineni.Tables[0].Rows[0]["GrandTotalRefunded"].ToString());
                            double cancellationChargesp = Convert.ToDouble(dsKesineni.Tables[0].Rows[0]["CancellationCharges"].ToString());

                            DataSet dsKesineni1 = objKesineniAPILayer.ConfirmCancelTickets(pnrNumberKesineni, firstNameKesineni,
                             lastNameKesineni, dateOfJourneyKesineni, SeatNos);
                            if (dsKesineni1 != null)
                            {
                                if (dsKesineni1.Tables.Count > 0)
                                {
                                    if (dsKesineni1.Tables[0].Columns.Count > 1 && dsKesineni1.Tables[0].Rows.Count > 0)
                                    {
                                        if (cancelllationId != "" && CancelledSaets != "")
                                        {
                                            UpdateCancelltion(Convert.ToInt32(cancelllationId), SeatNos, Convert.ToString(grandTotalRefundp), Convert.ToString(cancellationChargesp));
                                        }
                                        else if (cancelllationId == "" && CancelledSaets == "")
                                        {
                                            AddCancellation(BookingId, tentativeId, SeatNos, EmailId, Convert.ToString(grandTotalRefundp), Convert.ToString(cancellationChargesp), "", 0);
                                        }
                                    }
                                    else
                                    {
                                        lblMsg.Text = "Ticket cancelled failed. Try Again";
                                        lblMsg.ForeColor = System.Drawing.Color.Red;
                                    }
                                }
                                else
                                {
                                    lblMsg.Text = "Ticket cancelled failed. Try Again";
                                    lblMsg.ForeColor = System.Drawing.Color.Red;
                                }
                            }
                            else
                            {
                                lblMsg.Text = "Ticket cancelled failed. Try Again";
                                lblMsg.ForeColor = System.Drawing.Color.Red;
                            }
                        }
                    }
                    #endregion
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void btnSignIn_Click(object sender, EventArgs e)
    {
        try
        {
            if (Session["UserID"] != null)
            {
                DataSet dsticketdetails = CheckTicketID();
                if (CheckStatus)
                {
                    if (dsticketdetails != null)
                    {
                        int BookingId = Convert.ToInt32(dsticketdetails.Tables[0].Rows[0]["BookingId"].ToString());
                        int tentativeId = Convert.ToInt32(dsticketdetails.Tables[0].Rows[0]["TentativeId"].ToString());
                        string EmailId = dsticketdetails.Tables[0].Rows[0]["EmailId"].ToString();
                        string Name = dsticketdetails.Tables[0].Rows[0]["FullName"].ToString();
                        string seatnumbers = dsticketdetails.Tables[0].Rows[0]["SeatNos"].ToString();
                        string totalfareabhi = dsticketdetails.Tables[0].Rows[0]["TotalFare"].ToString();
                        string ticketNumberBitla = dsticketdetails.Tables[0].Rows[0]["PNRNumber"].ToString();

                        string BoardingPointName = dsticketdetails.Tables[0].Rows[0]["BoardingPointName"].ToString();
                        string DateofJourney = dsticketdetails.Tables[0].Rows[0]["DateOfJourney"].ToString();
                        string[] dd = DateofJourney.Split(' ');
                        string[] bd = BoardingPointName.Split('-');
                        string dateofjourney = dd[0];
                        string datenow = dd[0] + "" + bd[1];
                        string APIName = dsticketdetails.Tables[0].Rows[0]["APIName"].ToString();
                        lblCode.Text = GenerateRandomCode();
                        TimeSpan s = DateTime.Parse(datenow) - DateTime.Now;

                        if (s.Days > 0)
                        {
                            dayhours = Convert.ToInt32(s.Days) * 24;
                        }
                        if (s.Minutes > 30)
                        {
                            hour = dayhours + s.Hours + 1;
                        }
                        if (s.Minutes <= 30)
                        {
                            hour = dayhours + s.Hours;
                        }
                        if (hour > 0)
                        {
                            Session["NameMail"] = Name;
                            Session["EmailIdMail"] = EmailId;

                            #region Kesineni
                            if (dsticketdetails.Tables[0].Rows[0]["APIName"].ToString() == "Kesineni")
                            {
                                ViewState["APIName"] = "Kesineni";
                                rbtnlstCancelType.Visible = gvPartialCancellation.Visible = btnConfrmCancel.Visible = false;
                                gvPartialCancellation.DataSource = dsticketdetails.Tables[1];
                                gvPartialCancellation.DataBind();
                                ViewState["dsticketdetails"] = dsticketdetails.Tables[0];
                                btnConfrmCancel_Click(sender, e);
                            }
                            #endregion

                            #region AbhiBus
                            else if (dsticketdetails.Tables[0].Rows[0]["APIName"].ToString() == "SVR" || dsticketdetails.Tables[0].Rows[0]["APIName"].ToString() == "KAVERI" || dsticketdetails.Tables[0].Rows[0]["APIName"].ToString() == "RAJESH" || dsticketdetails.Tables[0].Rows[0]["APIName"].ToString() == "SAIANJANA" || dsticketdetails.Tables[0].Rows[0]["APIName"].ToString() == "KALLADA")
                            {
                                string ticketNumberAbhiBus = dsticketdetails.Tables[0].Rows[0]["PNRNumber"].ToString();
                                //cancelTicket
                                ClientAPIList objClientAPIList = new ClientAPIList();
                                objClientAPIList = GetAPIProvidersList(ConsumerKey, ConsumerSecret);
                                ClientAPIDetails objClientAPIDetails = objClientAPIList.SingleOrDefault(element => element.ProviderName == dsticketdetails.Tables[0].Rows[0]["APIName"].ToString()); //objClientAPIList.ElementAt(resultSet - 1)
                                LJ.CLB.Buses.AbhibusAPI obj = new LJ.CLB.Buses.AbhibusAPI();
                                DataTable dtAbhiBus = obj.cancelTicket(objClientAPIDetails.APIURL, objClientAPIDetails.ConsumerKey, ticketNumberAbhiBus);

                                if (dtAbhiBus != null)
                                {
                                    if (dtAbhiBus.Rows.Count > 0)
                                    {
                                        if (dtAbhiBus.Rows[0]["status"].ToString().ToUpper().Trim().ToString() == "SUCCESS")
                                        {
                                            string totalRefundAmount = dtAbhiBus.Rows[0]["total_refund_amount"].ToString();
                                            string canpercentage = dtAbhiBus.Rows[0]["cancellation_parcentage"].ToString();
                                            string[] canindec = canpercentage.Split('%');
                                            double cancelcharges = Convert.ToDouble(totalfareabhi) * (Convert.ToDouble(canindec[0].ToString()) / 100);

                                            AddCancellation(BookingId, tentativeId, seatnumbers, EmailId,
                                                Convert.ToString(Convert.ToDouble(totalfareabhi) - cancelcharges), Convert.ToString(totalfareabhi), APIName, hour);
                                            Mail(dsticketdetails.Tables[0].Rows[0]["EmailId"].ToString(), dsticketdetails.Tables[0].Rows[0]["PGMBRefNo"].ToString());
                                            objBAL = new ClsBAL();
                                            objBAL.AdjustAgentBalance(txtMBRefNo.Text.Trim().ToString(),
                                                Convert.ToDouble(Convert.ToDouble(totalfareabhi) - cancelcharges), Convert.ToDouble(cancelcharges),
                                                Convert.ToInt32(Session["UserID"]));

                                            DataSet dsBalance = objBAL.GetAgentByUserId(Convert.ToInt32(Session["UserID"]));

                                            string balance = dsBalance.Tables[0].Rows[0]["Balance"].ToString();
                                            Label lbl = (Label)this.Master.FindControl("lblBalance");
                                            lbl.Text = balance;
                                            Session["Balance"] = balance;
                                            txtEmailID.Text = txtMBRefNo.Text = "";

                                        }
                                        else
                                        {
                                            lblMsg.Text = "Ticket cancelled failed. Try Again";
                                        }
                                    }
                                    else
                                    {
                                        lblMsg.Text = "Ticket cancelled failed. Try Again";
                                    }
                                }
                                else
                                {
                                    lblMsg.Text = "Ticket cancelled failed. Try Again";
                                }
                            }
                            #endregion

                            #region Kallada
                            if (dsticketdetails.Tables[0].Rows[0]["APIName"].ToString() == "kallada")
                            {
                                string ticketNumberkallada = dsticketdetails.Tables[0].Rows[0]["PNRNumber"].ToString();
                                DataTable dtkallada = objkalladaAPILayer.CancellationConfirmation(ticketNumberkallada);
                                if (dtkallada != null)
                                {
                                    if (dtkallada.Rows.Count > 0)
                                    {
                                        if (dtkallada.Rows[0]["status"].ToString() == "Success")
                                        {
                                            string totalRefundAmount = dtkallada.Rows[0]["total_refund_amount"].ToString();
                                            string canpercentage = dtkallada.Rows[0]["cancellation_parcentage"].ToString();
                                            string[] canindec = canpercentage.Split('%');
                                            double cancelcharges = Convert.ToDouble(totalfareabhi) * (Convert.ToDouble(canindec[0].ToString()) / 100);

                                            DataTable dtKallada1 = objkalladaAPILayer.TicketCancellation(ticketNumberkallada);
                                            if (dtKallada1.Rows.Count > 0 && dtKallada1.Columns.Count > 1)
                                            {
                                                if (dtKallada1.Rows[0]["status"].ToString().ToUpper().Trim().ToString() != "FAIL")
                                                {
                                                    AddCancellation(BookingId, tentativeId, seatnumbers, EmailId,
                                                        Convert.ToString(Convert.ToDouble(totalfareabhi) - cancelcharges), Convert.ToString(totalfareabhi), APIName, hour);

                                                    objBAL = new ClsBAL();
                                                    objBAL.AdjustAgentBalance(txtMBRefNo.Text.Trim().ToString(),
                                                        Convert.ToDouble(Convert.ToDouble(totalfareabhi) - cancelcharges), Convert.ToDouble(cancelcharges),
                                                        Convert.ToInt32(Session["UserID"]));
                                                }
                                                else { lblMsg.Text = "Ticket cancelled failed."; }

                                                DataSet dsBalance = objBAL.GetAgentByUserId(Convert.ToInt32(Session["UserID"]));

                                                string balance = dsBalance.Tables[0].Rows[0]["Balance"].ToString();
                                                Label lbl = (Label)this.Master.FindControl("lblBalance");
                                                lbl.Text = balance;
                                                Session["Balance"] = balance;
                                                txtEmailID.Text = txtMBRefNo.Text = "";
                                            }
                                        }
                                        else
                                        {
                                            lblMsg.Text = "Ticket cancelled failed. Try Again";
                                            lblMsg.ForeColor = System.Drawing.Color.Red;
                                        }
                                    }
                                    else
                                    {
                                        lblMsg.Text = "Ticket cancelled failed. Try Again";
                                        lblMsg.ForeColor = System.Drawing.Color.Red;
                                    }
                                }
                                else
                                {
                                    lblMsg.Text = "Ticket cancelled failed. Try Again";
                                    lblMsg.ForeColor = System.Drawing.Color.Red;
                                }
                            }
                            #endregion

                            #region Bitla
                            else if (dsticketdetails.Tables[0].Rows[0]["APIName"].ToString() == "BITLA")
                            {
                                ViewState["APIName"] = "Bitla";
                                rbtnlstCancelType.Visible = gvPartialCancellation.Visible = btnConfrmCancel.Visible = false;
                                gvPartialCancellation.DataSource = dsticketdetails.Tables[1];
                                gvPartialCancellation.DataBind();
                                ViewState["dsticketdetails"] = dsticketdetails.Tables[0];
                                btnConfrmCancel_Click(sender, e);
                            }
                            #endregion

                            #region TicketGoose
                            else if (dsticketdetails.Tables[0].Rows[0]["APIName"].ToString() == "TICKETGOOSE")
                            {
                                ViewState["APIName"] = "TicketGoose";
                                string ticketNumber = dsticketdetails.Tables[0].Rows[0]["PNRNumber"].ToString();
                                string[] seatNos = dsticketdetails.Tables[0].Rows[0]["SeatNos"].ToString().Split(',');
                                DataTable dt = objTicketGooseAPILayer.CancelTicket(ticketNumber, seatNos);
                                if (dt != null)
                                {
                                    if (dt.Rows.Count > 0)
                                    {
                                        if (dt.Rows[0]["Status"].ToString() == "Success")
                                        {
                                            DataTable dtt = objTicketGooseAPILayer.ConfirmTicketCancellation(ticketNumber, seatNos);
                                            if (dtt != null)
                                            {
                                                if (dtt.Rows.Count > 0)
                                                {
                                                    if (dtt.Rows[0]["Status"].ToString() == "Success")
                                                    {
                                                        string refAmount = dtt.Rows[0]["refundAmount"].ToString();
                                                        AddCancellation(BookingId, tentativeId, seatnumbers, EmailId,
                                                       refAmount, Convert.ToString(Convert.ToDouble(totalfareabhi)), APIName, hour);

                                                        Mail(dsticketdetails.Tables[0].Rows[0]["EmailId"].ToString(), dsticketdetails.Tables[0].Rows[0]["PGMBRefNo"].ToString());

                                                        objBAL = new ClsBAL();
                                                        objBAL.AdjustAgentBalance(txtMBRefNo.Text.Trim().ToString(),
                                                            Convert.ToDouble(refAmount), Convert.ToDouble(Convert.ToDouble(totalfareabhi) - Convert.ToDouble(refAmount)),
                                                            Convert.ToInt32(Session["UserID"]));
                                                    }
                                                    else { lblMsg.Text = "Ticket cancelled failed. Try Again"; }

                                                    DataSet dsBalance = objBAL.GetAgentByUserId(Convert.ToInt32(Session["UserID"]));

                                                    string balance = dsBalance.Tables[0].Rows[0]["Balance"].ToString();
                                                    Label lbl = (Label)this.Master.FindControl("lblBalance");
                                                    lbl.Text = balance;
                                                    Session["Balance"] = balance;
                                                    txtEmailID.Text = txtMBRefNo.Text = "";
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion

                            #region EasyBus

                            else if (dsticketdetails.Tables[0].Rows[0]["APIName"].ToString() == "EASYBUS")
                            {
                                string ticketNumberEasybus = dsticketdetails.Tables[0].Rows[0]["PNRNumber"].ToString();
                                //cancelTicket
                                ClientAPIList objClientAPIList = new ClientAPIList();
                                objClientAPIList = GetAPIProvidersList(ConsumerKey, ConsumerSecret);
                                ClientAPIDetails objClientAPIDetails = objClientAPIList.SingleOrDefault(element => element.ProviderName == dsticketdetails.Tables[0].Rows[0]["APIName"].ToString()); //objClientAPIList.ElementAt(resultSet - 1)
                                LJ.CLB.Buses.EasybusAPI obj = new LJ.CLB.Buses.EasybusAPI();
                                DataTable dtEasybus = obj.cancelTicket(objClientAPIDetails.APIURL, objClientAPIDetails.ConsumerKey, ticketNumberEasybus, seatnumbers, dateofjourney);
                                if (dtEasybus != null)
                                {
                                    if (dtEasybus.Rows.Count > 0)
                                    {
                                        if (dtEasybus.Rows[0]["Message"].ToString() == "Your Ticket has been cancelled")
                                        {

                                            string totalRefundAmount = totalfareabhi;
                                            string canpercentage = "10";
                                            string[] canindec = canpercentage.Split('%');
                                            double cancelcharges = Convert.ToDouble(totalfareabhi) * (Convert.ToDouble(canindec[0].ToString()) / 100);

                                            AddCancellation(BookingId, tentativeId, seatnumbers, EmailId,
                                               Convert.ToString(Convert.ToDouble(totalfareabhi) - cancelcharges), Convert.ToString(totalfareabhi), APIName, hour);
                                            Mail(dsticketdetails.Tables[0].Rows[0]["EmailId"].ToString(), dsticketdetails.Tables[0].Rows[0]["PGMBRefNo"].ToString());
                                            objBAL = new ClsBAL();
                                            objBAL.AdjustAgentBalance(txtMBRefNo.Text.Trim().ToString(),
                                                Convert.ToDouble(totalRefundAmount), Convert.ToDouble(Convert.ToDouble(totalfareabhi) - Convert.ToDouble(totalRefundAmount)),
                                                Convert.ToInt32(Session["UserID"]));
                                            DataSet dsBalance = objBAL.GetAgentByUserId(Convert.ToInt32(Session["UserID"]));

                                            string balance = dsBalance.Tables[0].Rows[0]["Balance"].ToString();
                                            Label lbl = (Label)this.Master.FindControl("lblBalance");
                                            lbl.Text = balance;
                                            Session["Balance"] = balance;
                                            txtEmailID.Text = txtMBRefNo.Text = "";

                                        }
                                    }
                                }

                            }
                            #endregion
                        }
                        else
                        {
                            tdmsg.Visible = true;
                            //tdmsg.Style.Add("background-color:#E77471;", "");
                            lblMainMsg.Text = "Invalid Ref No.";
                            lblMainMsg.ForeColor = System.Drawing.Color.Maroon;
                            txtMBRefNo.Text = "";

                        }
                    }
                    else
                    {
                        tdmsg.Visible = true;
                        //tdmsg.Style.Add("background-color:#E77471;", "");
                        lblMainMsg.Text = "Invalid Ref No.";
                        lblMainMsg.ForeColor = System.Drawing.Color.Maroon;
                        txtMBRefNo.Text = "";

                    }
                }
                else
                {
                    tdmsg.Visible = true;
                    //tdmsg.Style.Add("background-color:#E77471;", "");
                    lblMainMsg.Text = "Invalid Ref No.";
                    lblMainMsg.ForeColor = System.Drawing.Color.Maroon;
                    txtMBRefNo.Text = "";
                }
            }
        }
        catch (Exception ex)
        {
            lblMsg.Text = ex.Message;
            throw ex;
        }
    }