public String CancelTicket(String bookingId, String seatNos, String ProviderName, String ConsumerKey, String ConsumerSecret)
        {
            if (ValidateRequest(ConsumerKey, ConsumerSecret))
            {
                ClientAPIList objClientAPIList = new ClientAPIList();

                if (HttpContext.Current.Cache["ClientAPI-" + ConsumerKey] == null)
                    GetAPIProvidersList(ConsumerKey, ConsumerSecret);

                objClientAPIList = (ClientAPIList)HttpContext.Current.Cache["ClientAPI-" + ConsumerKey];

                ClientAPIDetails objClientAPIDetails = objClientAPIList.SingleOrDefault(element => element.ProviderName == ProviderName);

                String strCancelResponse = String.Empty;
                try
                {
                    switch (ProviderName)
                    {
                        case "BITLA":
                        case "MORNINGSTAR":
                            BitlaAPI clsBitlaAPI = new BitlaAPI();
                            strCancelResponse = clsBitlaAPI.cancelTicket(bookingId, seatNos, objClientAPIDetails.APIURL, objClientAPIDetails.ConsumerKey);
                            break;
                        case "TICKETGOOSE":
                            TicketGooseAPI clsTicketGooseAPI = new TicketGooseAPI();
                            strCancelResponse = clsTicketGooseAPI.confirmTicketCancellation(bookingId, seatNos, objClientAPIDetails.APIURL, objClientAPIDetails.ConsumerKey, objClientAPIDetails.ConsumerSecret);
                            break;
                        case "ABHIBUS":
                        case "SVR":
                        case "KALLADA":
                        case "KAVERI":
                        case "RAJESH":
                        case "SAIANJANA":
                            AbhibusAPI clsAbhiBusAPI = new AbhibusAPI();
                            strCancelResponse = "";//clsAbhiBusAPI.cancelTicket(objClientAPIDetails.APIURL, objClientAPIDetails.ConsumerKey, bookingId);
                            break;
                        case "EASYBUS":
                            EasybusAPI clsEasyBusAPI = new EasybusAPI();
                            strCancelResponse = "";//  clsEasyBusAPI.cancelTicket(bookingId, seatNos, objClientAPIDetails.APIURL, objClientAPIDetails.ConsumerKey, objClientAPIDetails.ConsumerSecret);
                            break;
                        default:
                            break;
                    }
                }
                catch (Exception)
                {
                    //
                }
                return strCancelResponse;
            }
            else
            {
                return null;
                //throw new http exception
                // throw new System.Web.Http.HttpResponseException(HttpStatusCode.Forbidden);
            }
        }
    protected void btnSignIn_Click(object sender, EventArgs e)
    {
        try
        {

            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());
                                        // 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;
                                        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"].ToString()));
                                            }
                                            else { lblMsg.Text = "Ticket cancelled failed."; }

                                            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;
                                            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());

                                    }
                                }
                            }

                        }
                        #endregion
                    }
                    else
                    {
                        tdmsg.Visible = true;
                        lblMainMsg.Text = "Invalid LoveJourney Ref No.";
                        lblMainMsg.ForeColor = System.Drawing.Color.Maroon;
                        txtMBRefNo.Text = "";
                    }
                }
                else
                {
                    tdmsg.Visible = true;
                    lblMainMsg.Text = "Invalid LoveJourney Ref No.";
                    lblMainMsg.ForeColor = System.Drawing.Color.Maroon;
                    txtMBRefNo.Text = "";

                }
            }
            else
            {
                tdmsg.Visible = true;
                lblMainMsg.Text = "Invalid LoveJourney Ref No.";
                lblMainMsg.ForeColor = System.Drawing.Color.Maroon;
                txtMBRefNo.Text = "";
                txtEmailID.Text = "";

            }

        }
        catch (Exception ex)
        {
            lblMsg.Text = ex.Message;
            throw ex;
        }
    }
        public string BookTicket(BlockSeats blockSeats, String ConsumerKey, String ConsumerSecret)
        {
            if (ValidateRequest(ConsumerKey, ConsumerSecret))
            {
                ClientAPIList objClientAPIList = new ClientAPIList();

                //if (HttpContext.Current.Cache["ClientAPI-" + ConsumerKey] == null)
                GetAPIProvidersList(ConsumerKey, ConsumerSecret);
                objClientAPIList = (ClientAPIList)HttpContext.Current.Cache["ClientAPI-" + ConsumerKey];
                ClientAPIDetails objClientAPIDetails = objClientAPIList.SingleOrDefault(element => element.ProviderName == blockSeats.ProviderName);
                BookSeatsResponse objBookResponse = new BookSeatsResponse();
                if (objClientAPIDetails != null)
                {
                    try
                    {
                        switch (blockSeats.ProviderName)
                        {
                            case "BITLA":
                            case "MORNINGSTAR":
                                BitlaAPI clsBitlaAPI = new BitlaAPI();
                                objBookResponse = clsBitlaAPI.bookTicket(blockSeats.SourceId, blockSeats.DestinationId, blockSeats.TripId,
                                    objClientAPIDetails.APIURL, objClientAPIDetails.ConsumerKey, blockSeats.NoOfSeats, blockSeats.BoardingId.ToString(), blockSeats.SeatNo, blockSeats.Title, blockSeats.Name,
                                    blockSeats.Age, blockSeats.Sex, blockSeats.Address, blockSeats.BookingRefNo, blockSeats.IdCardType, blockSeats.IdCardNo, blockSeats.IdCardIssuedBy,
                                    blockSeats.MobileNo, blockSeats.EmergencyMobileNo, blockSeats.EmailId);
                                break;
                            case "TICKETGOOSE":
                                TicketGooseAPI clsTicketGooseAPI = new TicketGooseAPI();
                                objBookResponse = clsTicketGooseAPI.BookTicket(blockSeats.BookingId, objClientAPIDetails.APIURL, objClientAPIDetails.ConsumerKey, objClientAPIDetails.ConsumerSecret);
                                break;
                            case "ABHIBUS":
                            case "SVR":
                            case "KALLADA":
                            case "KAVERI":
                            case "RAJESH":
                            case "SAIANJANA":
                                AbhibusAPI clsAbhiBusAPI = new AbhibusAPI();
                                objBookResponse = clsAbhiBusAPI.bookSeats(blockSeats.SourceId, blockSeats.DestinationId, blockSeats.JourneyDate
                                    , blockSeats.TripId, blockSeats.SeatNo, blockSeats.Title, blockSeats.Name, blockSeats.BoardingId, blockSeats.Address
                                    , blockSeats.Name, blockSeats.MobileNo, blockSeats.EmailId, blockSeats.BookingRefNo, objClientAPIDetails.APIURL
                                    , objClientAPIDetails.ConsumerKey);

                                objBookResponse.extraseatinfo = blockSeats.SourceId + "," + blockSeats.DestinationId + "," + blockSeats.JourneyDate
                              + "," + blockSeats.TripId + "," + blockSeats.SeatNo + "," + blockSeats.Title + "," + blockSeats.Name + "," + blockSeats.BoardingId + "," + blockSeats.Address
                              + "," + blockSeats.Name + "," + blockSeats.MobileNo + "," + blockSeats.EmailId + "," + blockSeats.BookingRefNo;
                                break;

                            case "EASYBUS":
                                EasybusAPI clsEasyBusAPI = new EasybusAPI();
                                objBookResponse = clsEasyBusAPI.bookSeats(blockSeats.SourceId, blockSeats.DestinationId, blockSeats.JourneyDate
                                    , blockSeats.TripId, blockSeats.SeatNo, blockSeats.Sex, blockSeats.Name, blockSeats.BoardingId, blockSeats.Address
                                    , blockSeats.Name, blockSeats.MobileNo, blockSeats.EmailId, blockSeats.BookingRefNo, objClientAPIDetails.APIURL
                                    , objClientAPIDetails.ConsumerKey);

                                objBookResponse.extraseatinfo = blockSeats.SourceId + "," + blockSeats.DestinationId + "," + blockSeats.JourneyDate
                              + "," + blockSeats.TripId + "," + blockSeats.SeatNo + "," + blockSeats.Title + "," + blockSeats.Name + "," + blockSeats.BoardingId + "," + blockSeats.Address
                              + "," + blockSeats.Name + "," + blockSeats.MobileNo + "," + blockSeats.EmailId + "," + blockSeats.BookingRefNo;

                                break;
                            default:
                                break;
                        }
                    }
                    catch (Exception ex)
                    {
                        objBookResponse.Message = ex.ToString();
                    }
                }
                else
                {
                    objBookResponse.Message = "no api found";
                }
                return JsonConvert.SerializeObject(objBookResponse);
            }
            else
            {
                return null;
                //throw new http exception
                //throw new System.Web.Http.HttpResponseException(HttpStatusCode.Forbidden);

            }
        }
    protected void btnSignIn_Click(object sender, EventArgs e)
    {
        try
        {
            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();

                    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 = true;
                        gvPartialCancellation.DataSource = dsticketdetails.Tables[1];
                        gvPartialCancellation.DataBind();
                        ViewState["dsticketdetails"] = dsticketdetails.Tables[0];
                    }
                    #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();//"OHYD19615";
                        //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(cancelcharges));
                                    Mail(dtAbhiBus.Rows[0]["EmailId"].ToString(), dtAbhiBus.Rows[0]["PGMBRefNo"].ToString());
                                }
                            }
                            else
                            {
                                lblMsg.Text = "Ticket cancelled failed.Try Again";
                            }
                        }
                        else
                        {
                            lblMsg.Text = "Ticket cancelled failed.Try Again";
                        }
                    }
                    #endregion

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

                    #region Kallada
                    if (dsticketdetails.Tables[0].Rows[0]["APIName"].ToString() == "kallada")
                    {

                        string ticketNumberkallada = dsticketdetails.Tables[0].Rows[0]["PNRNumber"].ToString();//"OHYD19615";
                        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)
                                    {
                                        AddCancellation(BookingId, tentativeId, seatnumbers, EmailId, Convert.ToString(Convert.ToDouble(totalfareabhi) - cancelcharges), Convert.ToString(cancelcharges));
                                    }
                                }
                                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 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) - Convert.ToDouble(refAmount)));

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

                                            }
                                            else { lblMsg.Text = "Ticket cancelled failed. Try Again"; }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    txtMBRefNo.Text = "";
                    lblCancelMessage.Visible = true;
                    lblCancelMessage.Text = "Invalid Love Journey RefNo";
                    lblCancelMessage.ForeColor = System.Drawing.Color.Maroon;
                }
            }
            else
            {
                txtMBRefNo.Text = "";
                lblCancelMessage.Visible = true;
                lblCancelMessage.Text = "Invalid Love Journey RefNo";
                lblCancelMessage.ForeColor = System.Drawing.Color.Maroon;

            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }