Пример #1
0
    public string getagent()
    {
        if (HttpContext.Current.Session["UserID"] != null)
        {
            ClsBAL objBAL = new ClsBAL();
            DataSet dsCommSlab = objBAL.GetCommissionSlab("Agent", "Bus", "");
            if (dsCommSlab != null)
            {
                if (dsCommSlab.Tables[0].Rows.Count > 0)
                {
                    HttpContext.Current.Session["fare"] = Convert.ToString(dsCommSlab.Tables[0].Rows[0]["Commission"]);

                }

            }
        }
        else
        {
            HttpContext.Current.Session["fare"] = null;
        }
        return JsonConvert.SerializeObject(HttpContext.Current.Session["fare"]);
    }
    protected void btnIntBook_Click(object sender, EventArgs e)
    {
        if (Session["UserID"] == null) { Response.Redirect("~/Default.aspx", false); return; }
        ClsBAL objBAL = new ClsBAL();
        DataSet dsBookingResponse = new DataSet();

        //if (Session["Role"].ToString() == "Agent")
        //{

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

        DataSet dsCommSlab = objBAL.GetCommissionSlab(Session["Role"].ToString(), "InterNationalFlights",lblairline.Text); // Change it
        string commisionPercentage = string.Empty;
        if (dsCommSlab.Tables[0].Rows.Count > 0)
            commisionPercentage = dsCommSlab.Tables[0].Rows[0]["Commission"].ToString();// Change it
        else
            commisionPercentage = "0";

        string balance = dsBalance.Tables[0].Rows[0]["Balance"].ToString();
          //  string commisionPercentage = dsBalance.Tables[0].Rows[0]["CommisionPercentage"].ToString();
        string agentId = dsBalance.Tables[0].Rows[0]["AgentId"].ToString();

        string actualFare = Session["TotalFare"].ToString();

        string deductAmount = Convert.ToString(Convert.ToDouble(actualFare.ToString()) -
            ((Convert.ToDouble(actualFare.ToString()) * Convert.ToDouble(commisionPercentage)) / 100));
        string commisionFare = Convert.ToString(Convert.ToDouble(actualFare.ToString()) - Convert.ToDouble(deductAmount));

        Session["AgentId_Agent"] = agentId;
        Session["ActualFare_Agent"] = actualFare;
        Session["CommisionFare_Agent"] = commisionFare;
        Session["CommisionPercentage_Agent"] = commisionPercentage;
        Session["DeductAmount_Agent"] = deductAmount;

        if (Convert.ToDouble(balance) >= Convert.ToDouble(deductAmount))
        {
            dsBookingResponse = GetIntBookingRequest();
        }
        else { lblMsg.Text = "Please contact administrator."; return; }
        //}
        //else if (Session["Role"].ToString() == "User")
        //{

        //}

        #region Save Response
        FlightBAL objFlightBal = new FlightBAL();
        if (dsBookingResponse.Tables.Count > 0)
        {
            if (dsBookingResponse.Tables["BookingResponse"].Rows.Count > 0)
            {
                objFlightBal.ReferenceNo = Common.GetFlightsReferenceNo("LJIF");
                objFlightBal.TransId = dsBookingResponse.Tables["BookingResponse"].Rows[0]["transid"].ToString();
                objFlightBal.Status = dsBookingResponse.Tables["BookingResponse"].Rows[0]["status"].ToString();
                objFlightBal.AdultPax = Convert.ToInt32(dsBookingResponse.Tables["BookingResponse"].Rows[0]["noadults"].ToString());
                objFlightBal.InfantPax = Convert.ToInt32(dsBookingResponse.Tables["BookingResponse"].Rows[0]["noinfant"].ToString());
                objFlightBal.ChildPax = Convert.ToInt32(dsBookingResponse.Tables["BookingResponse"].Rows[0]["nochild"].ToString());
                objFlightBal.Origin_Destination_Id = dsBookingResponse.Tables["OriginDestinationOption"].Rows[0]["id"].ToString();
                objFlightBal.Origin_Destination_Key = dsBookingResponse.Tables["OriginDestinationOption"].Rows[0]["key"].ToString();
                objFlightBal.ActualBasefare = Convert.ToDecimal(dsBookingResponse.Tables["FareDetails"].Rows[0]["ActualBasefare"].ToString());
                objFlightBal.Tax = Convert.ToDecimal(dsBookingResponse.Tables["FareDetails"].Rows[0]["Tax"].ToString());
                objFlightBal.STax = Convert.ToDecimal(dsBookingResponse.Tables["FareDetails"].Rows[0]["STax"].ToString());
                objFlightBal.TCharge = Convert.ToDecimal(dsBookingResponse.Tables["FareDetails"].Rows[0]["TCharge"].ToString());
                objFlightBal.Scharge = Convert.ToDecimal(dsBookingResponse.Tables["FareDetails"].Rows[0]["Scharge"].ToString());
                objFlightBal.TDiscount = Convert.ToDecimal(dsBookingResponse.Tables["FareDetails"].Rows[0]["TDiscount"].ToString());
                objFlightBal.TMarkUp = Convert.ToDecimal(dsBookingResponse.Tables["FareDetails"].Rows[0]["TMarkUp"].ToString());
                objFlightBal.TPartnerCommission = Convert.ToDecimal(dsBookingResponse.Tables["FareDetails"].Rows[0]["TPartnerCommission"].ToString());
                objFlightBal.TSDiscount = Convert.ToDecimal(dsBookingResponse.Tables["FareDetails"].Rows[0]["TSDiscount"].ToString());
                objFlightBal.CreatedBy = Convert.ToInt32(Session["UserID"]);
                objFlightBal.TripMode = "One";

                DataTable dtflightBookingId = objFlightBal.AddDInternationalFlightBooking(objFlightBal);
                string flightBookingId = dtflightBookingId.Rows[0]["FlightBookingID"].ToString();

                //Do the Insert of Flgiht Segment

                objFlightBal.FlightBookingID = flightBookingId.ToString();
                if (dsBookingResponse.Tables["FlightSegment"].Rows.Count > 0)
                {
                    for (int j = 0; j < dsBookingResponse.Tables["FlightSegment"].Rows.Count; j++)
                    {
                        objFlightBal.AirEquipType = dsBookingResponse.Tables["FlightSegment"].Rows[j]["AirEquipType"].ToString();
                        objFlightBal.ArrivalAirportCode = dsBookingResponse.Tables["FlightSegment"].Rows[j]["ArrivalAirportCode"].ToString();
                        objFlightBal.ArrivalAirportName = dsBookingResponse.Tables["FlightSegment"].Rows[j]["ArrivalAirportName"].ToString();
                        objFlightBal.ArrivalDateTime = dsBookingResponse.Tables["FlightSegment"].Rows[j]["ArrivalDateTime"].ToString();
                        objFlightBal.DepartureAirportCode = dsBookingResponse.Tables["FlightSegment"].Rows[j]["DepartureAirportCode"].ToString();
                        objFlightBal.DepartureAirportName = dsBookingResponse.Tables["FlightSegment"].Rows[j]["DepartureAirportName"].ToString();
                        objFlightBal.DepartureDateTime = dsBookingResponse.Tables["FlightSegment"].Rows[j]["DepartureDateTime"].ToString();
                        objFlightBal.FlightNumber = dsBookingResponse.Tables["FlightSegment"].Rows[j]["FlightNumber"].ToString();
                        objFlightBal.MarketingAirlineCode = dsBookingResponse.Tables["FlightSegment"].Rows[j]["MarketingAirlineCode"].ToString();
                        objFlightBal.OperatingAirlineCode = dsBookingResponse.Tables["FlightSegment"].Rows[j]["OperatingAirlineCode"].ToString();
                        objFlightBal.OperatingAirlineName = dsBookingResponse.Tables["FlightSegment"].Rows[j]["OperatingAirlineName"].ToString();
                        objFlightBal.OperatingAirlineFlightNumber = dsBookingResponse.Tables["FlightSegment"].Rows[j]["OperatingAirlineFlightNumber"].ToString();
                        objFlightBal.NumStops = dsBookingResponse.Tables["FlightSegment"].Rows[j]["NumStops"].ToString();
                        objFlightBal.LinkSellAgrmnt = dsBookingResponse.Tables["FlightSegment"].Rows[j]["LinkSellAgrmnt"].ToString();
                        objFlightBal.Conx = dsBookingResponse.Tables["FlightSegment"].Rows[j]["Conx"].ToString();
                        objFlightBal.AirpChg = dsBookingResponse.Tables["FlightSegment"].Rows[j]["AirpChg"].ToString();
                        objFlightBal.InsideAvailOption = dsBookingResponse.Tables["FlightSegment"].Rows[j]["InsideAvailOption"].ToString();
                        objFlightBal.GenTrafRestriction = dsBookingResponse.Tables["FlightSegment"].Rows[j]["GenTrafRestriction"].ToString();
                        objFlightBal.DaysOperates = dsBookingResponse.Tables["FlightSegment"].Rows[j]["DaysOperates"].ToString();
                        objFlightBal.JrnyTm = dsBookingResponse.Tables["FlightSegment"].Rows[j]["JrnyTm"].ToString();
                        objFlightBal.EndDt = dsBookingResponse.Tables["FlightSegment"].Rows[j]["EndDt"].ToString();
                        objFlightBal.StartTerminal = dsBookingResponse.Tables["FlightSegment"].Rows[j]["StartTerminal"].ToString();
                        objFlightBal.EndTerminal = dsBookingResponse.Tables["FlightSegment"].Rows[j]["EndTerminal"].ToString();
                        objFlightBal.FltTm = dsBookingResponse.Tables["FlightSegment"].Rows[j]["FltTm"].ToString();
                        objFlightBal.LSAInd = dsBookingResponse.Tables["FlightSegment"].Rows[j]["LSAInd"].ToString();
                        objFlightBal.Mile = dsBookingResponse.Tables["FlightSegment"].Rows[j]["Mile"].ToString();
                        objFlightBal.Availability = dsBookingResponse.Tables["BookingClass"].Rows[j]["Availability"].ToString();
                        objFlightBal.BIC = dsBookingResponse.Tables["BookingClass"].Rows[j]["BIC"].ToString();
                        objFlightBal.emailAddress = dsBookingResponse.Tables["email"].Rows[0]["emailAddress"].ToString();
                        objFlightBal.telephone = dsBookingResponse.Tables["telephone"].Rows[0]["PhoneNumber"].ToString();
                        objFlightBal.CreatedBy = Convert.ToInt32(Session["UserID"]);
                        string givenName = string.Empty;
                        string surName = string.Empty;
                        string namereference = string.Empty;
                        string psgrType = string.Empty;
                        string customerInfo = string.Empty;
                        string Age = string.Empty;
                        for (int i = 0; i < dsBookingResponse.Tables["CustomerInfo"].Rows.Count; i++)
                        {

                            givenName = dsBookingResponse.Tables["CustomerInfo"].Rows[i]["givenName"].ToString();
                            surName = dsBookingResponse.Tables["CustomerInfo"].Rows[i]["surName"].ToString();
                            namereference = dsBookingResponse.Tables["CustomerInfo"].Rows[i]["nameReference"].ToString();
                            psgrType = dsBookingResponse.Tables["CustomerInfo"].Rows[i]["psgrtype"].ToString();

                            if (dsBookingResponse.Tables["CustomerInfo"].Columns.Contains("age"))
                            {
                                Age = dsBookingResponse.Tables["CustomerInfo"].Rows[i]["age"].ToString();
                                if (customerInfo == string.Empty)
                                {
                                    customerInfo = namereference + "|" + givenName + "|" + surName + "|" + psgrType + "|" + Age;
                                }
                                else
                                {
                                    customerInfo = customerInfo + ";" + namereference + "|" + givenName + "|" + surName + "|" + psgrType + "|" + Age;
                                }
                            }
                            else
                            {
                                Age = "-";
                                if (customerInfo == string.Empty)
                                {
                                    customerInfo = namereference + "|" + givenName + "|" + surName + "|" + psgrType + "|" + Age;
                                }
                                else
                                {
                                    customerInfo = customerInfo + ";" + namereference + "|" + givenName + "|" + surName + "|" + psgrType + "|" + Age;
                                }
                            }

                        }
                        objFlightBal.Customer_Details = customerInfo;

                        objFlightBal.bookingClass = dsBookingResponse.Tables["BookingClassFare"].Rows[0]["bookingClass"].ToString();
                        objFlightBal.ClassType = dsBookingResponse.Tables["BookingClassFare"].Rows[0]["ClassType"].ToString();
                        objFlightBal.farebasisCode = dsBookingResponse.Tables["BookingClassFare"].Rows[0]["farebasisCode"].ToString();
                        objFlightBal.Fare_Rule = dsBookingResponse.Tables["BookingClassFare"].Rows[0]["Rule"].ToString();
                        objFlightBal.PsgrType = dsBookingResponse.Tables["psgr"].Rows[0]["PsgrType"].ToString();
                        objFlightBal.BaseFare = dsBookingResponse.Tables["psgr"].Rows[0]["BaseFare"].ToString();
                        objFlightBal.psgrTax = dsBookingResponse.Tables["psgr"].Rows[0]["Tax"].ToString();
                        objFlightBal.BagInfo = dsBookingResponse.Tables["psgr"].Rows[0]["BagInfo"].ToString();

                        bool res1 = objFlightBal.AddInternationalFlightSegment(objFlightBal);

                        if (res1)
                        {
                            string[] commPer = Session["CommisionPercentage_Agent"].ToString().Split('.');
                            DeductAgentBalance(Convert.ToInt32(Session["AgentId_Agent"].ToString()), Convert.ToDouble(Session["DeductAmount_Agent"].ToString()),
                                       Convert.ToInt32(Session["UserID"].ToString()), objFlightBal.ReferenceNo.ToString(), Convert.ToDouble(Session["ActualFare_Agent"].ToString()),
                                       Convert.ToDouble(Session["CommisionFare_Agent"].ToString()), Convert.ToInt32(commPer[0]));

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

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

                            GetIntBookingStatus(objFlightBal.ReferenceNo.ToString());
                            GetDetailsForPrint(objFlightBal.ReferenceNo.ToString());

                        }

                    }

                    lbtnmail.Visible = false;
                    pnlIntPassengerDet.Visible = false;
                    lblMsg.Visible = true;
                    lblMsg.Text = "Ticket has been booked successfully. Reference Number is : " + objFlightBal.ReferenceNo.ToString();
                    lblMsg.ForeColor = System.Drawing.Color.Green;
                    lbtnmail_Click1(sender, e);
                }
            }
        }

        #endregion
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        objArzooHotelAPILayer = ArzooHotelFactoryManager.GetArzooHotelAPILayerObject();
        objArzooHotelAPILayer.UserName = ArzooHotelConstants.USERNAME;
        objArzooHotelAPILayer.UserId = ArzooHotelConstants.USERID;
        objArzooHotelAPILayer.UserType = ArzooHotelConstants.USERTYPE;
        objArzooHotelAPILayer.Password = ArzooHotelConstants.PASSWORD;
        objArzooHotelAPILayer.PartnerId = ArzooHotelConstants.PARTNERID;
        lblMsg.Text = "";
        this.Page.Title = "LoveJourney - Hotel - Ticket";
        if (!IsPostBack)
        {
            if (Session["HotelRefNo"] != null)
            {
                string strRefNo = Session["HotelRefNo"].ToString();

                HotelBAL obj = new HotelBAL();
                obj.ReferenceNo = strRefNo;
                DataSet ds = obj.GetHotelProvisional();

                if (ds != null)
                {
                    string hotelId = ""; string webService = ""; string ratePlanCode = ""; string roomTypeCode = "";
                    string cityName = ""; string allocavailResult = "";
                    string allocidResult = ""; string fromDate = ""; string toDate = ""; string roomType = "";
                    string wsKey = ""; string roomBasis = ""; string title = "";
                    string firstName = ""; string middleName = ""; string lastName = ""; int noOfRooms = 0;
                    int[] noOfAdultsInARoom = null; int[] noOfChildsInARoom = null;
                    int[] firstChildAge = null; int[] secondChildAge = null;
                    string roomStayCandidate = "";

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

                    hotelId = dr["HotelId"].ToString();
                    webService = dr["WebService"].ToString();
                    ratePlanCode = dr["RatePlanType"].ToString();
                    roomTypeCode = dr["RoomTypeCode"].ToString();
                    cityName = dr["HotelCity"].ToString();
                    allocavailResult = dr["FromAllocation"].ToString();
                    allocidResult = dr["AllocationId"].ToString();

                    roomType = dr["RoomType"].ToString();
                    firstName = dr["FirstName"].ToString();
                    middleName = dr["MiddleName"].ToString();
                    lastName = dr["LastName"].ToString();
                    wsKey = dr["WsKey"].ToString();
                    roomBasis = dr["RoomBasis"].ToString();
                    title = dr["Title"].ToString();
                    noOfRooms = Convert.ToInt32(dr["NoOfRooms"].ToString());
                    roomStayCandidate = dr["RoomStayCandidate"].ToString();

                    string[] strValues = roomStayCandidate.Split(':');

                    fromDate = ConvertDate(strValues[1].ToString());
                    fromDate = fromDate.Replace('-', '/');
                    toDate = ConvertDate(strValues[2].ToString());
                    toDate = toDate.Replace('-', '/');

                    noOfRooms = Convert.ToInt32(strValues[3].ToString());

                    noOfAdultsInARoom = new int[noOfRooms];
                    noOfChildsInARoom = new int[noOfRooms];
                    firstChildAge = new int[noOfRooms];
                    secondChildAge = new int[noOfRooms];
                    int j = 0;
                    for (int i = 0; i < noOfRooms; i++)
                    {
                        if (i == 0)
                        {
                            j = 0;
                        }
                        else
                        {
                            j = 4 * i;
                        }

                        noOfAdultsInARoom[i] = Convert.ToInt32(strValues[4 + j].ToString());
                        noOfChildsInARoom[i] = Convert.ToInt32(strValues[5 + j].ToString());
                        firstChildAge[i] = Convert.ToInt32(strValues[6 + j].ToString());
                        secondChildAge[i] = Convert.ToInt32(strValues[7 + j].ToString());
                    }

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

                    DataSet dsCommSlabRet = objBAL.GetCommissionSlab(Session["Role"].ToString(), "Hotels","");

                    string balance = dsBalance.Tables[0].Rows[0]["Balance"].ToString();
                   // string commisionPercentage = dsBalance.Tables[0].Rows[0]["CommisionPercentage"].ToString();
                    string commisionPercentage = dsCommSlabRet.Tables[0].Rows[0]["Commission"].ToString();

                    string agentId = dsBalance.Tables[0].Rows[0]["AgentId"].ToString();

                    string actualFare = dr["HotelTotalFare"].ToString().ToString();
                    string deductAmount = Convert.ToString(Convert.ToDouble(actualFare.ToString()) -
                        ((Convert.ToDouble(actualFare.ToString()) * Convert.ToDouble(commisionPercentage)) / 100));
                    string commisionFare = Convert.ToString(Convert.ToDouble(actualFare.ToString()) - Convert.ToDouble(deductAmount));

                    Session["AgentId_Agent"] = agentId;
                    Session["ActualFare_Agent"] = actualFare;
                    Session["CommisionFare_Agent"] = commisionFare;
                    Session["CommisionPercentage_Agent"] = commisionPercentage;
                    Session["DeductAmount_Agent"] = deductAmount;

                    if (Convert.ToDouble(balance) >= Convert.ToDouble(deductAmount))
                    {

                        DataSet dsHotelBooking = objArzooHotelAPILayer.HotelBooking
                            (hotelId, webService, ratePlanCode, roomTypeCode, cityName, allocavailResult,
                            allocidResult, fromDate, toDate, roomType, wsKey, roomBasis, title, firstName, middleName, lastName, noOfRooms,
                            noOfAdultsInARoom, noOfChildsInARoom, firstChildAge, secondChildAge);

                        int provisionalId = Convert.ToInt32(dr["Id"].ToString());

                        if (!dsHotelBooking.Tables.Contains("HotelBooking"))
                        { lblMsg.Text = "Failed to book the ticket."; return; }

                        if (dsHotelBooking.Tables["HotelBooking"].Rows.Count == 0)
                        { lblMsg.Text = "Failed to book the ticket."; return; }

                        DataRow drr = dsHotelBooking.Tables["HotelBooking"].Rows[0];
                        wsKey = drr["wsKey"].ToString();

                        string extGuestTotal = drr["extGuestTotal"].ToString();
                        string roomTotal = drr["roomTotal"].ToString();
                        string serviceTaxTotal = drr["servicetaxTotal"].ToString();
                        string bookingStatus = drr["bookingstatus"].ToString();
                        string bookingRemarks = drr["bookingremarks"].ToString();
                        string bookingRefNo = drr["bookingref"].ToString();
                        string bookingTrn = drr["bookingTrn"].ToString();
                        string discount = drr["discount"].ToString();
                        string contactNumbers = drr["contactNumbers"].ToString();
                        string faxNumbers = drr["faxNumbers"].ToString();

                        if (drr["bookingstatus"].ToString() == "C")
                        {
                            string stt = "";
                            stt = InsertHotelBooking(provisionalId, wsKey, extGuestTotal, roomTotal, serviceTaxTotal, bookingStatus, bookingRemarks,
                                bookingRefNo, bookingTrn, discount, contactNumbers, faxNumbers, Convert.ToInt32(Session["UserID"].ToString()));
                            if (stt == "Success")
                            {
                                //lblMsg.Text = "Your ticket has been booked successfully. " + " BookingRefNo : " + Session["HotelRefNo"].ToString();

                                pnlTicket.Visible = true;
                                pnlOptions.Visible = true;

                                DeductAgentBalance(Convert.ToInt32(Session["AgentId_Agent"].ToString()), Convert.ToDouble(Session["DeductAmount_Agent"].ToString()),
                                          Convert.ToInt32(Session["UserID"].ToString()), strRefNo, Convert.ToDouble(Session["ActualFare_Agent"].ToString()),
                                          Convert.ToDouble(Session["CommisionFare_Agent"].ToString()), Convert.ToDouble(Session["CommisionPercentage_Agent"].ToString()));

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

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

                                HotelBAL objTicket = new HotelBAL();
                                objTicket.ReferenceNo = strRefNo;
                                DataSet dsTicket = objTicket.GetHotelProvisional();

                                if (dsTicket != null)
                                {
                                    DataRow drTicketRow = dsTicket.Tables[0].Rows[0];
                                    lblHotelRefNo.Text = drTicketRow["ReferenceNo"].ToString();
                                    lblarzoorefno.Text = drTicketRow["BookingRefNo"].ToString();
                                    lblStatus.Text = drTicketRow["Status"].ToString();
                                    lblHotelName.Text = drTicketRow["HotelName"].ToString();

                                    lblAddress.Text = drTicketRow["HotelAddress"].ToString();

                                    lblHotelCity.Text = drTicketRow["HotelCity"].ToString();
                                    lblCheckIn.Text = drTicketRow["CheckInDate"].ToString();
                                    lblCheckOut.Text = drTicketRow["CheckOutDate"].ToString();
                                    lblRoomType.Text = drTicketRow["RoomType"].ToString();

                                    lblStar.Text = drTicketRow["HotelStar"].ToString() + " Star";
                                    lblNoOfRooms.Text = drTicketRow["NoOfRooms"].ToString();
                                    lblPaxGreaterThan12.Text = drTicketRow["NoOfAdults"].ToString();
                                    lblPaxLessThan12.Text = drTicketRow["NoOfChildren"].ToString();

                                    lblBookedDate.Text = drTicketRow["BookedDate"].ToString();
                                    lblHotelContactDetails.Text = drTicketRow["ContactNumbers"].ToString() + " , Fax Nos: " + drTicketRow["FaxNumbers"].ToString();

                                    lblTotalPrice.Text = drTicketRow["HotelTotalFare"].ToString() + "~" + drTicketRow["HotelTotlaFareDetails"].ToString();/////////////

                                    lblTitle.Text = drTicketRow["Title"].ToString();
                                    lblFirstName.Text = drTicketRow["FirstName"].ToString();
                                    lblMiddleName.Text = drTicketRow["MiddleName"].ToString();
                                    lblLastName.Text = drTicketRow["LastName"].ToString();
                                    lblMobileNo.Text = drTicketRow["MobileNumber"].ToString();
                                    lblEmailId.Text = drTicketRow["EmailId"].ToString();
                                    lblAdd.Text = drTicketRow["CustAddressLine"].ToString();
                                    lblState.Text = drTicketRow["CustState"].ToString();
                                    lblPinCode.Text = drTicketRow["CustZipCode"].ToString();

                                    lblCity.Text = drTicketRow["CustCity"].ToString();

                                    SMS();
                                    Mail(lblEmailId.Text.ToString());
                                }
                            }
                            else { lblMsg.Text = "Please Try Again."; }
                        }
                        else if (drr["bookingstatus"].ToString() == "E")
                        {
                            lblMsg.Text = "Failed to book the ticket.";
                        }

                    }
                    else
                    {
                        lblMsg.Text = "Your account does have the sufficient balance to book the ticket.";
                        pnlTicket.Visible = false;
                    }

                    Session["HotelRefNo"] = null;
                }
            }
        }
    }
Пример #4
0
    protected void gvHotelRooms_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            GridView gv = sender as GridView;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string extGuestTotal = ""; string roomTotal = ""; string servicetaxTotal = ""; string discount = ""; string commission = "";
                extGuestTotal = Convert.ToString(gv.DataKeys[e.Row.RowIndex].Values["extGuestTotal"].ToString());

                roomTotal = Convert.ToString(gv.DataKeys[e.Row.RowIndex].Values["roomTotal"].ToString());

                //Rajini ...Added for calculating  the total amount based on no of days
                double RoomTtl = Convert.ToDouble(roomTotal.ToString()) * Convert.ToDouble(ViewState["NoOfdays"].ToString());
                //Rajiniend

                RoomTtl = RoomTtl + ((RoomTtl * 10) / 100);

                servicetaxTotal = Convert.ToString(gv.DataKeys[e.Row.RowIndex].Values["servicetaxTotal"].ToString());
                discount = Convert.ToString(gv.DataKeys[e.Row.RowIndex].Values["discount"].ToString());
                commission = Convert.ToString(gv.DataKeys[e.Row.RowIndex].Values["commission"].ToString());
                // Changed roomTotal to RoomTtl by rajini

                LinkButton lbtnFare = (LinkButton)e.Row.FindControl("lbtnFare");
                lbtnFare.ToolTip = " RoomRate: " + RoomTtl + " \n Extra Guest Charge: " + extGuestTotal
                    + " \n Service Tax: " + servicetaxTotal; //+ " \n Discount: " + discount + " \n Commission: " + commission;
                double total = 0;
                total = (Convert.ToDouble(RoomTtl) + Convert.ToDouble(extGuestTotal) + Convert.ToDouble(servicetaxTotal)); //- (Convert.ToDouble(discount) + Convert.ToDouble(commission));
                lbtnFare.Text = total.ToString();
                lbtnFare.CommandName = lbtnFare.Text.ToString();/////ArzooTotalFare
                lbtnFare.CommandArgument = lbtnFare.ToolTip.ToString();/////ArzooFareDetails
                lbtnFare.ValidationGroup = "0.00";/////AgentMarkUpFare

                LinkButton lbtnNetFare = (LinkButton)e.Row.FindControl("lbtnNetFare");
                string actualFare = lbtnFare.Text.ToString().ToString();

                string deductAmount = Convert.ToString(Convert.ToDouble(actualFare.ToString()));

                if (Session["UserID"] != null)
                {
                    if (Session["Role"].ToString() == "Agent")
                    {
                        if (ViewState["commisionPercentage"] == null)
                        {
                            ClsBAL objBAL = new ClsBAL();
                            DataSet dsCommSlabRet = objBAL.GetCommissionSlab(Session["Role"].ToString(), "Hotels", "");
                            ViewState["commisionPercentage"] = dsCommSlabRet.Tables[0].Rows[0]["Commission"].ToString();
                        }
                        deductAmount = Convert.ToString(Convert.ToDouble(actualFare.ToString()) -
                                          ((Convert.ToDouble(actualFare.ToString()) * Convert.ToDouble(ViewState["commisionPercentage"].ToString())) / 100));
                    }
                }

                string commisionFare = Convert.ToString(Convert.ToDouble(actualFare.ToString()) - Convert.ToDouble(deductAmount));
                lbtnNetFare.Text = Convert.ToDecimal(deductAmount.ToString()).ToString("0.00", System.Globalization.CultureInfo.InvariantCulture).ToString();
                lbtnNetFare.ToolTip = " ActualFare: " + total.ToString() + " \n CommissionFare: "
                    + Convert.ToDecimal(commisionFare).ToString("0.00", System.Globalization.CultureInfo.InvariantCulture);// +" \n NetFare: " + lbtnNetFare.Text.ToString();
                lbtnNetFare.Visible = false;

                if (Session["UserID"] != null)
                {
                    if (Session["Role"].ToString() == "Agent")
                    {
                        if (ViewState["MarkUp"] == null)
                        {
                            Class1 objBal = new Class1();
                            DataSet objDataSet = new DataSet();
                            objBal.ScreenInd = Master123.gettopmarkup;
                            objBal.Agentid = Convert.ToInt32(Session["UserID"].ToString());
                            objBal.Type = "Hotels";
                            objDataSet = (DataSet)objBal.fnGetData();
                            string markUpAmount = "0";
                            ViewState["MarkUp"] = markUpAmount;
                            if (objDataSet != null)
                            {
                                if (objDataSet.Tables.Count > 0)
                                {
                                    markUpAmount = objDataSet.Tables[0].Rows[0]["MarkUpAmount"].ToString();
                                    ViewState["MarkUp"] = markUpAmount;
                                    if (true)
                                    {
                                        lbtnFare.ToolTip = " RoomRate: " + (RoomTtl + Convert.ToDouble(markUpAmount)) + " \n Extra Guest Charge: "
                               + extGuestTotal + " \n Service Tax: " + servicetaxTotal;/////ArzooTotalFare_Agent
                                        total = (Convert.ToDouble(RoomTtl) + Convert.ToDouble(extGuestTotal) + Convert.ToDouble(servicetaxTotal) + Convert.ToDouble(markUpAmount));

                                    }
                             //       else if (objDataSet.Tables[0].Rows[0]["AddSubtract"].ToString() == "Subtract")
                             //       {
                             //           lbtnFare.ToolTip = " RoomRate: " + (RoomTtl - Convert.ToDouble(markUpAmount)) + " \n Extra Guest Charge: "
                             //+ extGuestTotal + " \n Service Tax: " + servicetaxTotal;/////ArzooTotalFare_Agent
                             //           total = (Convert.ToDouble(RoomTtl) + Convert.ToDouble(extGuestTotal) + Convert.ToDouble(servicetaxTotal) - Convert.ToDouble(markUpAmount));

                             //       }

                                    lbtnFare.Text = total.ToString();
                                    lbtnFare.CommandName = lbtnFare.Text.ToString();/////ArzooTotalFare
                                    lbtnFare.CommandArgument = lbtnFare.ToolTip.ToString();/////ArzooFareDetails
                                    lbtnFare.ValidationGroup = markUpAmount;/////AgentMarkUpFare
                                }
                            }
                        }

                        //MarkUp
                        //decimal agentMakrUpFare = Convert.ToDecimal(Convert.ToDecimal(ViewState["MarkUp"].ToString()).ToString("0.00", System.Globalization.CultureInfo.InvariantCulture));

                        //total = (Convert.ToDouble((RoomTtl + Convert.ToDouble(agentMakrUpFare))) + Convert.ToDouble(extGuestTotal) + Convert.ToDouble(servicetaxTotal));
                        //lbtnFare.Text = total.ToString();/////ArzooFareDetails_Agent
                        //lbtnFare.ValidationGroup = agentMakrUpFare.ToString();/////AgentMarkUpFare
                    }
                }
            }
        }
        catch (Exception ex)
        {
            lblMsg.Text = ex.Message;
        }
    }
    protected void gdvIntFlights_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {

            if (Session["dsIntFlights"] != null)
            {
                if (e.Row.RowType == DataControlRowType.Header)
                {
                    dsIntFlights = (DataSet)Session["dsIntFlights"];
                }

                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    Label FlightSegments_ID = (Label)e.Row.FindControl("lblFlightSegments_ID");

                    Label lblConx = (Label)e.Row.FindControl("lblConx");

                    if (lblConx.Text != "Y")
                    {
                        Label airlinename = (Label)e.Row.FindControl("lblAirlineNameMrk");
                        DataTable dtFlightsSegment = dsIntFlights.Tables["FlightSegment"];
                        if (dtFlightsSegment.Rows.Count > 0)
                        {
                            DataRow[] rowFilghtSegment = dtFlightsSegment.Select("FlightSegments_ID = '" + FlightSegments_ID.Text + "'");
                            DataTable dtinnergrid = dtFlightsSegment.Clone();
                            foreach (DataRow item in rowFilghtSegment)
                            {
                                dtinnergrid.ImportRow(item);
                            }
                            GridView gdvconnectingflights = (GridView)e.Row.FindControl("gdvconnectingflights");
                            gdvconnectingflights.DataSource = dtinnergrid;
                            gdvconnectingflights.DataBind();
                            //FlightSegmentsID = rowFilghtSegment[0]["FlightSegments_Id"].ToString();
                        }
                        DataTable dtFareDetails1 = dsIntFlights.Tables["FareDetails"];
                        DataRow[] dtFareDetails = dtFareDetails1.Select("FareDetails_Id=" + FlightSegments_ID.Text);

                         Label lblBaseFare = (Label)e.Row.FindControl("lblBaseFare");
                            Label lblTax = (Label)e.Row.FindControl("lblTax");
                            Label lblSTax = (Label)e.Row.FindControl("lblSTax");
                            Label lblSCharge = (Label)e.Row.FindControl("lblSCharge");
                            Label lblTDiscount = (Label)e.Row.FindControl("lblTDiscount");
                            Label lblTotal = (Label)e.Row.FindControl("lblTotal");
                            Label lblFare = (Label)e.Row.FindControl("lblFare");
                            Label lblTCharge = (Label)e.Row.FindControl("lblTCharge");
                            foreach (DataRow rows in dtFareDetails)
                            {
                                string ActualBaseFare = rows[0].ToString();
                                string Tax = rows[1].ToString();
                                string STax = rows[2].ToString();
                                string TCharge = rows[3].ToString();
                                string SCharge = rows[4].ToString();
                                string TDiscount = rows[5].ToString();
                                string TMarkup = rows[6].ToString();

                                lblBaseFare.Text = ActualBaseFare.ToString();
                                lblTax.Text = Tax.ToString();
                                lblSTax.Text = STax.ToString();
                                lblSCharge.Text = SCharge.ToString();
                                lblTDiscount.Text = TDiscount.ToString();
                                lblTCharge.Text = (Convert.ToDouble(TCharge.ToString()) + Convert.ToDouble(TMarkup.ToString())).ToString();

                                decimal totalFare = Convert.ToDecimal(ActualBaseFare) + Convert.ToDecimal(Tax) + Convert.ToDecimal(STax) + Convert.ToDecimal(TCharge) + Convert.ToDecimal(TMarkup);// + Convert.ToDecimal(SCharge) + Convert.ToDecimal(TDiscount);
                                // Label lblFare = (Label)e.Row.FindControl("lblFare");
                                // lblFare.Text = totalFare.ToString("####0.0");
                                lblFare.Text = lblTotal.Text = totalFare.ToString("####0.0");

                                #region Calculating SNF and HNF internatoional flights

                                if (Session["UserID"] != null)
                                {
                                    if (Session["Role"].ToString() == "Agent")
                                    {
                                        ClsBAL objBAL1 = new ClsBAL();
                                        DataSet dsCommSlab = objBAL1.GetCommissionSlab(Session["Role"].ToString(), "InterNationalFlights", airlinename.Text);
                                        string commisionPercentage = string.Empty;
                                        if (dsCommSlab != null)
                                        {
                                            if (dsCommSlab.Tables[0].Rows.Count > 0)
                                            {
                                                commisionPercentage = dsCommSlab.Tables[0].Rows[0]["Commission"].ToString();
                                            }
                                            else
                                            {
                                                commisionPercentage = "0";
                                            }
                                        }
                                        else
                                        {
                                            commisionPercentage = "0";
                                        }

                                        Label lblHNFFare = (Label)e.Row.FindControl("lblHNFFare");
                                        Label lblOnewayAgentcomm=(Label)e.Row.FindControl("lblOnewayAgentcomm");
                                        double CommissionFare = (Convert.ToDouble(totalFare) * Convert.ToDouble(commisionPercentage)) / Convert.ToDouble(100);
                                        lblOnewayAgentcomm.Text="Com:" +CommissionFare.ToString("####0");
                                        double DeductAmount = Convert.ToDouble(totalFare) - CommissionFare;
                                        lblHNFFare.Text = DeductAmount.ToString();
                                        #region Adding mark up price of agent
                                        Class1 objBal = new Class1();
                                        objBal.ScreenInd = Master123.gettopmarkup;
                                        objBal.Agentid = Convert.ToInt32(Session["UserID"].ToString());
                                        objBal.Type = "International Flights";
                                        objDataSet = (DataSet)objBal.fnGetData();
                                        string markUpAmount = "0";
                                        ViewState["MarkUp"] = markUpAmount;
                                        if (objDataSet != null)
                                        {
                                            if (objDataSet.Tables.Count > 0)
                                            {
                                                if (objDataSet.Tables[0].Rows.Count > 0)
                                                {
                                                    markUpAmount = objDataSet.Tables[0].Rows[0]["MarkUpAmount"].ToString();
                                                    ViewState["MarkUp"] = markUpAmount;

                                                        lblTCharge.Text = (Convert.ToDouble(lblTCharge.Text) + Convert.ToDouble(ViewState["MarkUp"].ToString())).ToString();

                                                    double total1 = Convert.ToDouble(lblBaseFare.Text) + Convert.ToDouble(lblTax.Text) + Convert.ToDouble(lblSTax.Text) + Convert.ToDouble(lblTCharge.Text);
                                                    lblFare.Text = lblTotal.Text = total1.ToString("####0.00");

                                                }
                                            }
                                        }

                                        #endregion
                                    }
                                }
                                #endregion

                            }

                            Label lbljrnytime = (Label)e.Row.FindControl("lbljrnytime");

                            double hours = Convert.ToDouble(lbljrnytime.Text);
                        TimeSpan t = TimeSpan.FromMinutes(hours);
                        string answer = string.Format("{0}h : {1}m ", Convert.ToInt32(t.TotalHours), t.Minutes);
                        lbljrnytime.Text = answer;

                        //DataTable dtFlightSegments = dsIntFlights.Tables["FlightSegments"];
                        //if (dtFlightSegments.Rows.Count > 0)
                        //{
                        //    DataRow[] rowFilghtSegments = dtFlightSegments.Select("FlightSegments_ID = '" + FlightSegments_ID.Text + "'");
                        //    originDestination_Id = rowFilghtSegments[0]["OriginDestinationOption_Id"].ToString();
                        //}
                        //DataTable dtFareDetails = dsIntFlights.Tables[5];
                        //if (dtFareDetails.Rows.Count > 0)
                        //{
                        //    DataRow[] rowFareDetails = dtFareDetails.Select("OriginDestinationOption_Id=" + originDestination_Id);
                        //    fareDetailsId = rowFareDetails[0]["FareDetails_Id"].ToString();
                        //}
                        //DataTable dtChargeableFares = dsIntFlights.Tables[6];
                        //if (dtChargeableFares.Rows.Count > 0)
                        //{
                        //    DataRow[] rowChargeableFareDetails = dtChargeableFares.Select("FareDetails_Id=" + fareDetailsId);

                        //    Label lblBaseFare = (Label)e.Row.FindControl("lblBaseFare");
                        //    Label lblTax = (Label)e.Row.FindControl("lblTax");
                        //    Label lblSTax = (Label)e.Row.FindControl("lblSTax");
                        //    Label lblSCharge = (Label)e.Row.FindControl("lblSCharge");
                        //    Label lblTDiscount = (Label)e.Row.FindControl("lblTDiscount");
                        //    Label lblTotal = (Label)e.Row.FindControl("lblTotal");
                        //    Label lblFare = (Label)e.Row.FindControl("lblFare");
                        //    Label lblTCharge = (Label)e.Row.FindControl("lblTCharge");

                        //    lblBaseFare.Text = Convert.ToDouble(rowChargeableFareDetails[0]["ActualBaseFare"]).ToString("####0.00");
                        //    lblTax.Text = Convert.ToDouble(rowChargeableFareDetails[0]["Tax"]).ToString("####0.00");
                        //    lblSTax.Text = Convert.ToDouble(rowChargeableFareDetails[0]["STax"]).ToString("####0.00");
                        //    lblSCharge.Text = Convert.ToDouble(rowChargeableFareDetails[0]["SCharge"]).ToString("####0.00");
                        //    lblTDiscount.Text = Convert.ToDouble(rowChargeableFareDetails[0]["TDiscount"]).ToString("####0.00");
                        //    lblTCharge.Text = (Convert.ToDouble(rowChargeableFareDetails[0]["TCharge"]) + Convert.ToDouble(rowChargeableFareDetails[0]["TMarkup"])).ToString("####0.00");
                        //    //DataTable dtNonChargeableFares = dsIntFlights.Tables[7];
                        //    //if (dtNonChargeableFares.Rows.Count > 0)
                        //    //{
                        //     //   DataRow[] rowNonChargeableFareDetails = dtNonChargeableFares.Select("FareDetails_Id=" + fareDetailsId);  //CHITTI

                        //   // }
                        //    double total = Convert.ToDouble(lblBaseFare.Text) + Convert.ToDouble(lblTax.Text) + Convert.ToDouble(lblSTax.Text) + Convert.ToDouble(lblTCharge.Text); //+ Convert.ToDouble(lblTDiscount.Text) + Convert.ToDouble(lblSCharge.Text)
                        //    lblFare.Text = lblTotal.Text = total.ToString("####0.00");
                       // }
                    }
                    else
                    {
                        e.Row.Visible = false;
                    }

                     #region old
                //    Label lblBaseFare = (Label)e.Row.FindControl("lblBaseFare");
                //    Label lblTax = (Label)e.Row.FindControl("lblTax");
                //    Label lblSTax = (Label)e.Row.FindControl("lblSTax");
                //    Label lblSCharge = (Label)e.Row.FindControl("lblSCharge");
                //    Label lblTDiscount = (Label)e.Row.FindControl("lblTDiscount");
                //    Label lblTotal = (Label)e.Row.FindControl("lblTotal");
                //    Label lblConx = (Label)e.Row.FindControl("lblConx");
                //    Label lblDeparts = (Label)e.Row.FindControl("lblDeparts");
                //    Label lblArrives = (Label)e.Row.FindControl("lblArrives");
                //    Label lbldepartdate = (Label)e.Row.FindControl("lbldepartdate");
                //    Label lblarrivaldate = (Label)e.Row.FindControl("lblarrivaldate");
                //    Label lblDestinations = (Label)e.Row.FindControl("lblDestinations");
                //    Label lblDuration = (Label)e.Row.FindControl("lblDuration");
                //    Label lblConnectingFlights = (Label)e.Row.FindControl("lblConnectingFlights");
                //    Label lblTCharge = (Label)e.Row.FindControl("lblTCharge");
                //    Label lblFare = (Label)e.Row.FindControl("lblFare");
                //    Label airlinename = (Label)e.Row.FindControl("lblOperatingAirlineName");

                //    TextBox txtfromsearch = new TextBox();
                //    txtfromsearch.Text = Session["From"].ToString();
                //    TextBox txttosearch = new TextBox();
                //    txttosearch.Text = Session["TO"].ToString();

                //    string from = txtfromsearch.Text.Substring(txtfromsearch.Text.IndexOf("(") + 1, 3);
                //    string to = txttosearch.Text.Substring(txttosearch.Text.IndexOf("(") + 1, 3);

                //    lblDeparts.Text = lblDeparts.Text.Substring(lblDeparts.Text.IndexOf("T") + 1, 5);

                //    if (e.Row.RowIndex + 2 <= dsIntFlights.Tables["FlightSegment"].Rows.Count - 2)
                //    {
                //        if (dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex + 1]["Conx"].ToString() == "Y" && dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex]["Conx"].ToString() == "Y")
                //        {
                //            lblConnectingFlights.Visible = true;
                //            lblDestinations.Text = from + " - " + dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex]["ArrivalAirportCode"].ToString() + " - " + dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex + 1]["ArrivalAirportCode"].ToString() + " - " + to;
                //            lblArrives.Text = dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex + 2]["ArrivalDateTime"].ToString();
                //            lblArrives.Text = lblArrives.Text.Substring(lblArrives.Text.IndexOf("T") + 1, 5);

                //            double hours = Convert.ToDouble(dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex + 2]["JrnyTm"].ToString());
                //            TimeSpan t = TimeSpan.FromMinutes(hours);
                //            string answer = string.Format("{0}h : {1}m ", Convert.ToInt32(t.TotalHours), t.Minutes);
                //            lblDuration.Text = answer;
                //        }
                //        else if (dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex]["Conx"].ToString() == "Y")
                //        {
                //            lblConnectingFlights.Visible = true;
                //            lblDestinations.Text = from + " - " + dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex]["ArrivalAirportCode"].ToString() + " - " + to;
                //            lblArrives.Text = dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex + 1]["ArrivalDateTime"].ToString();
                //            lblArrives.Text = lblArrives.Text.Substring(lblArrives.Text.IndexOf("T") + 1, 5);

                //            double hours = Convert.ToDouble(dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex + 1]["JrnyTm"].ToString());
                //            TimeSpan t = TimeSpan.FromMinutes(hours);
                //            string answer = string.Format("{0}h : {1}m ", Convert.ToInt32(t.TotalHours), t.Minutes);
                //            lblDuration.Text = answer;
                //        }
                //        else
                //        {
                //            lblDestinations.Text = from + " - " + to;

                //            lblArrives.Text = dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex]["ArrivalDateTime"].ToString();
                //            lblArrives.Text = lblArrives.Text.Substring(lblArrives.Text.IndexOf("T"), 5);

                //            double hours = Convert.ToDouble(dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex]["JrnyTm"].ToString());
                //            TimeSpan t = TimeSpan.FromMinutes(hours);
                //            string answer = string.Format("{0}h : {1}m ", Convert.ToInt32(t.TotalHours), t.Minutes);
                //            lblDuration.Text = answer;
                //        }
                //    }
                //    else if (e.Row.RowIndex + 1 <= dsIntFlights.Tables["FlightSegment"].Rows.Count - 1)
                //    {
                //        if (dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex]["Conx"].ToString() == "Y")
                //        {
                //            lblConnectingFlights.Visible = true;
                //            lblDestinations.Text = from + " - " + dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex]["ArrivalAirportCode"].ToString() + " - " + to;
                //            lblArrives.Text = dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex + 1]["ArrivalDateTime"].ToString();
                //            lblArrives.Text = lblArrives.Text.Substring(lblArrives.Text.IndexOf("T") + 1, 5);

                //            double hours = Convert.ToDouble(dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex + 1]["JrnyTm"].ToString());
                //            TimeSpan t = TimeSpan.FromMinutes(hours);
                //            string answer = string.Format("{0}h : {1}m ", Convert.ToInt32(t.TotalHours), t.Minutes);
                //            lblDuration.Text = answer;
                //        }
                //        else
                //        {
                //            lblDestinations.Text = from + " - " + to;

                //            lblArrives.Text = dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex]["ArrivalDateTime"].ToString();
                //            lblArrives.Text = lblArrives.Text.Substring(lblArrives.Text.IndexOf("T"), 5);

                //            double hours = Convert.ToDouble(dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex]["JrnyTm"].ToString());
                //            TimeSpan t = TimeSpan.FromMinutes(hours);
                //            string answer = string.Format("{0}h : {1}m ", Convert.ToInt32(t.TotalHours), t.Minutes);
                //            lblDuration.Text = answer;
                //        }
                //    }

                //    if (dsIntFlights.Tables["FlightSegment"].Rows[e.Row.RowIndex]["Conx"].ToString() == "N")
                //    {
                //        e.Row.Visible = false;
                //    }

                //    //string StartTime = lblDeparts.Text;
                //    //string EndTime = lblArrives.Text;
                //    //DateTime Date = Convert.ToDateTime(lbldepartdate.Text);
                //    //DateTime Date1 = Convert.ToDateTime(lblarrivaldate.Text);
                //    //string format = "MMM ddd d HH:mm yyyy";
                //    //lbldepartdate.Text = Date.ToLongDateString();
                //    //lblarrivaldate.Text = Date1.ToLongDateString();

                //    //DateTime startTime = DateTime.Parse(StartTime);
                //    //DateTime endTime = DateTime.Parse(EndTime);

                //    //TimeSpan ts = endTime.Subtract(startTime);

                //    //lblDuration.Text = ts.ToString();
                //    //lblDuration.Text = lblDuration.Text.Substring(0, lblDuration.Text.Length - 3);

                //    if (dsIntFlights.Tables.Count > 0)
                //    {

                //        DataTable dtBookingClassFare = dsIntFlights.Tables[14];
                //        Label lblFareRules = (Label)e.Row.FindControl("lblFareRules");
                //        lblFareRules.Text = dtBookingClassFare.Rows[e.Row.RowIndex]["Rule"].ToString();

                //        //changes ravi
                //        Label lblFlightSegment_ID = (Label)e.Row.FindControl("lblFlightSegment_ID");
                //        DataTable dtFareDetails1 = dsIntFlights.Tables[4];
                //        DataRow[] dtFareDetails = dtFareDetails1.Select("FareDetails_Id=" + lblFlightSegment_ID.Text);
                //        foreach (DataRow rows in dtFareDetails)
                //        {
                //            string ActualBaseFare = rows[0].ToString();
                //            string Tax = rows[1].ToString();
                //            string STax = rows[2].ToString();
                //            string TCharge = rows[3].ToString();
                //            string SCharge = rows[4].ToString();
                //            string TDiscount = rows[5].ToString();
                //            string TMarkup = rows[6].ToString();

                //            lblBaseFare.Text = ActualBaseFare.ToString();
                //            lblTax.Text = Tax.ToString();
                //            lblSTax.Text = STax.ToString();
                //            lblSCharge.Text = SCharge.ToString();
                //            lblTDiscount.Text = TDiscount.ToString();
                //            lblTCharge.Text = (Convert.ToDouble(TCharge.ToString()) + Convert.ToDouble(TMarkup.ToString())).ToString();

                //            decimal totalFare = Convert.ToDecimal(ActualBaseFare) + Convert.ToDecimal(Tax) + Convert.ToDecimal(STax) + Convert.ToDecimal(TCharge) + Convert.ToDecimal(TMarkup);// + Convert.ToDecimal(SCharge) + Convert.ToDecimal(TDiscount);
                //            // Label lblFare = (Label)e.Row.FindControl("lblFare");
                //            // lblFare.Text = totalFare.ToString("####0.0");
                //            lblFare.Text = lblTotal.Text = totalFare.ToString("####0.0");
                //            #region Calculating SNF and HNF
                //            if (Session["UserID"] != null)
                //            {
                //                if (Session["Role"].ToString() == "Agent")
                //                {
                //                    ClsBAL objBAL1 = new ClsBAL();
                //                    DataSet dsCommSlab = objBAL1.GetCommissionSlab(Session["Role"].ToString(), "InterNationalFlights", airlinename.Text);
                //                    string commisionPercentage = string.Empty;
                //                    if (dsCommSlab.Tables[0].Rows.Count > 0)
                //                        commisionPercentage = dsCommSlab.Tables[0].Rows[0]["Commission"].ToString();
                //                    else
                //                        commisionPercentage = "0";

                //                    Label lblHNFFare = (Label)e.Row.FindControl("lblHNFFare");
                //                    double CommissionFare = (Convert.ToDouble(totalFare) * Convert.ToDouble(commisionPercentage)) / Convert.ToDouble(100);
                //                    double DeductAmount = Convert.ToDouble(totalFare) - CommissionFare;
                //                    lblHNFFare.Text = DeductAmount.ToString();
                //                    #region Adding mark up price of agent
                //                    Class1 objBal = new Class1();
                //                    objBal.ScreenInd = Master123.gettopmarkup;
                //                    objBal.Agentid = Convert.ToInt32(Session["UserID"].ToString());
                //                    objBal.Type = "International Flights";
                //                    objDataSet = (DataSet)objBal.fnGetData();
                //                    string markUpAmount = "0";
                //                    ViewState["MarkUp"] = markUpAmount;
                //                    if (objDataSet != null)
                //                    {
                //                        if (objDataSet.Tables.Count > 0)
                //                        {

                //                            markUpAmount = objDataSet.Tables[0].Rows[0]["MarkUpAmount"].ToString();
                //                            ViewState["MarkUp"] = markUpAmount;
                //                            if (objDataSet.Tables[0].Rows[0]["AddSubtract"].ToString() == "Add")
                //                            {
                //                                lblTCharge.Text = (Convert.ToDouble(lblTCharge.Text) + Convert.ToDouble(ViewState["MarkUp"].ToString())).ToString();

                //                            }
                //                            else if (objDataSet.Tables[0].Rows[0]["AddSubtract"].ToString() == "Subtract")
                //                            {
                //                                lblTCharge.Text = (Convert.ToDouble(lblTCharge.Text) - Convert.ToDouble(ViewState["MarkUp"].ToString())).ToString();

                //                            }
                //                            double total1 = Convert.ToDouble(lblBaseFare.Text) + Convert.ToDouble(lblTax.Text) + Convert.ToDouble(lblSTax.Text) + Convert.ToDouble(lblTCharge.Text);
                //                            lblFare.Text = lblTotal.Text = total1.ToString("####0.00");

                //                        }
                //                    }

                //                    #endregion
                //                }
                //            }
                //            #endregion
                //        }

                    DataTable dtactivedetails = dsIntFlights.Tables[0];
                    Label lbladultone = (Label)e.Row.FindControl("lbladultone");
                    Label lblchildone = (Label)e.Row.FindControl("lblchildone");
                    Label lblinfantone = (Label)e.Row.FindControl("lblinfantone");
                    Label lblTripone = (Label)e.Row.FindControl("lblTripone");
                    lbladultone.Text = dtactivedetails.Rows[0]["AdultPax"].ToString();
                    lblchildone.Text = dtactivedetails.Rows[0]["ChildPax"].ToString();
                    lblinfantone.Text = dtactivedetails.Rows[0]["InfantPax"].ToString();
                    lblTripone.Text = dtactivedetails.Rows[0]["Trip"].ToString();

                //        Session["dsIntFlights"] = dsIntFlights;
                    //    }
        #endregion

                }

            }
            else
            {
                Response.Redirect("~/Default.aspx", false);
            }
        }
        catch (NullReferenceException)
        {
            Response.Redirect("~/Default.aspx", false);
        }
    }
    protected void gvCarresult_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (Session["UserID"] != null)
                {
                    if (Session["Role"].ToString() == "Agent")
                    {
                        ClsBAL objBAL = new ClsBAL();
                        DataSet dsCommSlab = objBAL.GetCommissionSlab(Session["Role"].ToString(), "Car", "");
                        string commisionPercentage = string.Empty;
                        if (dsCommSlab != null)
                        {
                            if (dsCommSlab.Tables[0].Rows.Count > 0)
                            {
                                commisionPercentage = dsCommSlab.Tables[0].Rows[0]["Commission"].ToString();
                            }
                            else
                            {
                                commisionPercentage = "0";
                            }
                        }
                        else
                        {
                            commisionPercentage = "0";
                        }

                        Label lblHNFFare = (Label)e.Row.FindControl("lblHNFFare");
                        Label lblBasicPrice = (Label)e.Row.FindControl("lblBasicPrice");
                        total = Convert.ToDouble(lblBasicPrice.Text);

                        double CommissionFare = ((total * Convert.ToDouble(commisionPercentage)) / 100);
                        double DeductAmount = total - CommissionFare;
                        lblHNFFare.Text = Convert.ToDouble(DeductAmount).ToString();
                        double newcomm = total - Convert.ToDouble(DeductAmount);
                        int newcomm1 = Convert.ToInt32(newcomm);

                        Label lblagentcomm1 = (Label)e.Row.FindControl("lblagentcomm1");
                        lblagentcomm1.Text = "com:" + newcomm1.ToString();

                        #region Markupfarefor Individual agents
                        Class1 objBal = new Class1();
                        DataSet objDataSet = new DataSet();
                        objBal.ScreenInd = Master123.gettopmarkup;
                        objBal.Agentid = Convert.ToInt32(Session["UserID"].ToString());
                        objBal.Type = "Cabs";
                        objDataSet = (DataSet)objBal.fnGetData();
                        string markUpAmount = "0";
                        ViewState["MarkUp"] = markUpAmount;
                        if (objDataSet != null)
                        {
                            if (objDataSet.Tables.Count > 0)
                            {
                                markUpAmount = objDataSet.Tables[0].Rows[0]["MarkUpAmount"].ToString();
                                ViewState["MarkUp"] = markUpAmount;
                            }
                        }
                        double markupfare = Convert.ToDouble(ViewState["MarkUp"]);
                        total += markupfare;
                        lblBasicPrice.Text = total.ToString();

                        #endregion

                    }
                }

            }
            else
            {
                e.Row.Visible = false;
            }
    }
    protected void btnProceedToPayment_Click(object sender, EventArgs e)
    {
        try
        {
            if (cbxAgree.Checked == false)
            {
                lblMsg.Text = "please check the Terms & conditions.";
                return;
            }
            int? createdBy = null;
            if (Session["UserID"] != null) { createdBy = Convert.ToInt32(Session["UserID"].ToString()); }
            else { createdBy = 0; }

            if (Session["RedBusBookingDetails"] != null)
            {
                BookingDetails = (String[])Session["RedBusBookingDetails"];
                // string gridviewdata = client.getBoardingPoint(BookingDetails[4].Split('~')[1]);
                // DataTable dtOnwardBoardingInfo = convertJsonStringToDataSet(gridviewdata).Tables[0];
                string boardinginf = BookingDetails[4].ToString();
                string strOnwardBoardingInfo = string.Empty;
                if (BookingDetails[19].ToString().Trim() == "TICKETGOOSE")
                {
                    strOnwardBoardingInfo = Convert.ToString(BookingDetails[4].Split('~')[0]);
                }
                else
                {
                    strOnwardBoardingInfo = Convert.ToString(BookingDetails[4]);
                }

                // string strOnwardBoardingInfo = dtOnwardBoardingInfo.Rows[0]["address"].ToString() + "," +
                // dtOnwardBoardingInfo.Rows[0]["landmark"].ToString();

                String referenceNumber = "";
                String referenceNumberReturn = "";
                referenceNumber = GenerateManabusRefNo();
                string provider = BookingDetails[19].ToString();

                if (BookingDetails[5].ToLower().Contains("single"))
                {
                    Session["Ticketrefno"] = referenceNumber;
                }

                Session["Order_Id"] = referenceNumber;
                Session["Amount"] = lblTotalAmountPayable.Text;
                string phoneno;
                //SingleTrip
                if (BookingDetails[5].ToLower().Contains("single"))
                {

                    #region onwardTrip
                    String nameList = ""; String genderList = ""; String titleList = ""; String ageList = "";
                    int countlist = 0;
                    foreach (RepeaterItem item in rptPassengersonward.Items)
                    {
                        DropDownList ddlrptr = (DropDownList)item.FindControl("ddlGender");
                        TextBox txtPassengerNamerptr = (TextBox)item.FindControl("txtPassengerName");
                        TextBox txtAgerptr = (TextBox)item.FindControl("txtAge");
                        phoneno = txtPhoneNo.Text;
                        if (countlist == 0)
                        {
                            ++countlist;
                            nameList += txtPassengerNamerptr.Text;
                            titleList += ddlrptr.SelectedItem.Value.ToString();
                            ageList += txtAgerptr.Text;
                            genderList += ddlrptr.SelectedItem.Text.ToString();
                        }
                        else
                        {
                            ++countlist;
                            nameList += "," + txtPassengerNamerptr.Text;
                            titleList += "," + ddlrptr.SelectedItem.Value.ToString();
                            ageList += "," + txtAgerptr.Text;
                            genderList += "," + ddlrptr.SelectedItem.Text.ToString();
                        }
                    }

                    String passengerDetailsonward = "";
                    string bookingid = "";
                    string boarding = lblBoardingPoint.ToolTip.ToString();
                    BlockSeats blockseats = new BlockSeats();
                    blockseats.SourceId = int.Parse(BookingDetails[10]);
                    blockseats.DestinationId = int.Parse(BookingDetails[11]);
                    blockseats.TripId = BookingDetails[12];
                    blockseats.JourneyDate = BookingDetails[1];
                    blockseats.BoardingId = BookingDetails[4].Split('~')[1];
                    blockseats.NoOfSeats = countlist;
                    blockseats.SeatNo = BookingDetails[2];
                    blockseats.Title = titleList;
                    blockseats.Name = nameList;
                    blockseats.Age = ageList;
                    blockseats.Sex = genderList;
                    blockseats.Address = txtAddress.Text;
                    blockseats.BookingRefNo = referenceNumber;
                    blockseats.IdCardType = ddlIDType.SelectedItem.Text;
                    blockseats.IdCardNo = txtIDNumber.Text;
                    blockseats.IdCardIssuedBy = txtIdIssuedBY.Text;
                    blockseats.MobileNo = txtPhoneNo.Text;
                    blockseats.EmergencyMobileNo = txtPhoneNo.Text;
                    blockseats.EmailId = txtEmailId.Text;
                    blockseats.ProviderName = BookingDetails[19].ToString();
                    blockseats.BookingId = bookingid;
                    string blockresult = client.blockTicket(blockseats);
                    DataSet ds = convertJsonStringToDataSet(blockresult);
                    if (ds != null)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            if (ds.Tables[0].Columns.Contains("Status"))
                            {
                                if (ds.Tables[0].Rows[0]["Status"].ToString().ToUpper() == "SUCCESS")
                                {
                                    if (ds.Tables[0].Columns.Contains("BookingID"))
                                    {
                                        blockseats.BookingId = ds.Tables[0].Rows[0]["BookingID"].ToString();
                                        lblMsg.Text = Convert.ToString(ds.Tables[0].Rows[0]["Status"]);
                                    }
                                }
                                else
                                {
                                    lblMsg.Text = ds.Tables[0].Rows[0]["message"].ToString();
                                    return;
                                }
                            }
                        }
                    }
                    if (Session["UserID"] != null)
                    {
                        if (Session["Role"].ToString() == "Agent")
                        {
                            ClsBAL objBAL = new ClsBAL();
                            DataSet dsBalance = objBAL.GetAgentByUserId(Convert.ToInt32(Session["UserID"]));
                            DataSet dsCommSlab = objBAL.GetCommissionSlab(Session["Role"].ToString(), "Bus", provider); // Change it
                            if (dsCommSlab != null)
                            {
                                if (dsCommSlab.Tables[0].Rows.Count > 0)
                                {
                                    string commisionPercentage = dsCommSlab.Tables[0].Rows[0]["Commission"].ToString();// Change it

                                    string balance = dsBalance.Tables[0].Rows[0]["Balance"].ToString();
                                    //string commisionPercentage = dsBalance.Tables[0].Rows[0]["CommisionPercentage"].ToString();
                                    string agentId = dsBalance.Tables[0].Rows[0]["AgentId"].ToString();
                                    string actualFare;
                                    string deductAmount;
                                    string commisionFare;
                                    if (ViewState["MarkUp"] != null)
                                    {
                                        double Am = Convert.ToDouble(lblTotalAmountPayable.Text.ToString()) - Convert.ToDouble(ViewState["MarkUp"].ToString());
                                        actualFare = Am.ToString();
                                        deductAmount = Convert.ToString(Convert.ToDouble(actualFare.ToString()) - ((Convert.ToDouble(actualFare.ToString()) * Convert.ToDouble(commisionPercentage)) / 100));
                                        commisionFare = Convert.ToString(Convert.ToDouble(actualFare.ToString()) - Convert.ToDouble(deductAmount));

                                    }
                                    else
                                    {
                                         actualFare = lblTotalAmountPayable.Text.ToString();
                                         deductAmount = Convert.ToString(Convert.ToDouble(lblTotalAmountPayable.Text.ToString()) - ((Convert.ToDouble(lblTotalAmountPayable.Text.ToString()) * Convert.ToDouble(commisionPercentage)) / 100));
                                         commisionFare = Convert.ToString(Convert.ToDouble(lblTotalAmountPayable.Text.ToString()) - Convert.ToDouble(deductAmount));
                                    }

                                    Session["AgentId_Agent"] = agentId;
                                    Session["ActualFare_Agent"] = actualFare;
                                    Session["CommisionFare_Agent"] = commisionFare;
                                    Session["CommisionPercentage_Agent"] = commisionPercentage;
                                    Session["DeductAmount_Agent"] = deductAmount;
                                    Session["Markup"] = ViewState["MarkUp"];
                                    if (Convert.ToDouble(balance) >= Convert.ToDouble(deductAmount))
                                    {
                                        bool b = objBAL.UpdateAgentBalance(Convert.ToInt32(agentId), Convert.ToDouble(deductAmount), Convert.ToDouble(commisionFare));
                                        //UpdateagentBalance,@RefundAmount

                                    }
                                    else
                                    {
                                        lblMsg.Text = "You dont have enough balance to book a ticket.";
                                        return;
                                    }
                                }
                                else
                                {
                                    lblMsg.Text = "Please Contact administrater ";
                                    return;
                                }
                            }
                        }
                    }

                    Session["blockseats"] = blockseats;

                    if (lblMsg.Text.ToString().ToUpper() == "SUCCESS" && lblMsg.Text.ToString().ToLower() != "tentative booking failed")
                    {
                        string[] strDate = BookingDetails[1].Trim().ToString().Split('-');
                        dt = Convert.ToDateTime(strDate[2] + "-" + strDate[1] + "-" + strDate[0]);
                        int countpassengers = 0;
                        foreach (RepeaterItem item in rptPassengersonward.Items)
                        {
                            DropDownList ddlrptr = (DropDownList)item.FindControl("ddlGender");
                            Label lblSeatNorptr = (Label)item.FindControl("lblSeatNo");
                            TextBox txtPassengerNamerptr = (TextBox)item.FindControl("txtPassengerName");
                            TextBox txtAgerptr = (TextBox)item.FindControl("txtAge");
                            if (countpassengers == 0)
                            {
                                ++countpassengers;
                                passengerDetailsonward += lblSeatNorptr.Text + "-" + ddlrptr.SelectedItem.Value + "-" + txtPassengerNamerptr.Text + "-" + txtAgerptr.Text;
                            }
                            else
                            {
                                ++countpassengers;
                                passengerDetailsonward += "," + lblSeatNorptr.Text + "-" + ddlrptr.SelectedItem.Value + "-" + txtPassengerNamerptr.Text + "-" + txtAgerptr.Text;
                            }
                        }
                    }
                    string[] str = new string[1];
                    str[0] = " to";
                    //BookingDetails[4].Split('-')[7].Split('~')[1]
                    String[] cities = BookingDetails[0].ToString().Split(str, StringSplitOptions.None);
                    res = InsertTentativeBooking(referenceNumber, Convert.ToString(Session["Ticketrefno"]), blockseats.BookingId, lblMsg.Text.ToString(), "", "", null, provider
                            , BookingDetails[15].ToString(), BookingDetails[14].ToString(), dt
                            , Convert.ToInt32(BookingDetails[10].ToString()), cities[0].ToString()
                            , Convert.ToInt32(BookingDetails[11].ToString()), cities[1].ToString()
                        , lblSeatNos.Text.ToString(), rptPassengersonward.Items.Count,Convert.ToDecimal(ViewState["MarkUp"].ToString()),  Convert.ToDecimal(lblFare.Text.Trim().ToString()), null
                            , strOnwardBoardingInfo, BookingDetails[4].Split('-')[0].ToString() + "-" + BookingDetails[4].Split('-')[BookingDetails[4].Split('-').Length - 1].ToString().Split('~')[0].ToString(), nameList, 20, "M", txtPhoneNo.Text.ToString()
                            , txtEmailId.Text.ToString(), txtAddress.Text.ToString()
                            , "", null, 0, 0, "Online", "Cash", "Oneway", createdBy, "Online", "", passengerDetailsonward
                            , ddlIDType.SelectedItem.Text.ToString(), txtIDNumber.Text.ToString(), "", provider, Convert.ToDouble(Session["CommisionFare_Agent"]), blockseats.TripId, blockseats.Title, Convert.ToString(blockseats.BoardingId));
                    if (res == true)
                    {
                        if (Session["UserID"] != null)
                        {
                            if (Session["Role"].ToString() == "Admin" || Session["Role"].ToString() == "CSE")
                            {

                                lblMsg.Text = client.bookTicket(blockseats);
                                DataSet dsbook = convertJsonStringToDataSet(lblMsg.Text);
                                if (dsbook != null)
                                {
                                    if (dsbook.Tables[0].Rows.Count > 0)
                                    {
                                        if (dsbook.Tables[0].Columns.Contains("APIPNR"))
                                        {
                                            lblMsg.Text = dsbook.Tables[0].Rows[0]["APIPNR"].ToString();
                                        }
                                    }
                                }
                                if (Convert.ToString(dsbook.Tables[0].Rows[0]["APIPNR"]) == "SUCCESS" || Convert.ToString(dsbook.Tables[0].Rows[0]["Status"]).ToUpper() == "SUCCESS")
                                {
                                    if (lblMsg.Text.ToString().Split(' ').Length == 1)
                                    {
                                        InsertBookedTicketDetails(referenceNumber, lblMsg.Text.ToString());
                                        Response.Redirect("redirectbus.aspx", false);

                                    }
                                }
                                else
                                {
                                    return; //Booking Failed.
                                }
                            }
                            else if (Session["Role"].ToString() == "Agent")
                            {

                                lblMsg.Text = client.bookTicket(blockseats);
                                DataSet dsbook = convertJsonStringToDataSet(lblMsg.Text);
                                if (dsbook != null)
                                {
                                    if (dsbook.Tables[0].Rows.Count > 0)
                                    {
                                        if (dsbook.Tables[0].Columns.Contains("APIPNR"))
                                        {
                                            lblMsg.Text = dsbook.Tables[0].Rows[0]["APIPNR"].ToString();
                                        }
                                    }
                                }
                                if (Convert.ToString(dsbook.Tables[0].Rows[0]["APIPNR"]) == "SUCCESS" || Convert.ToString(dsbook.Tables[0].Rows[0]["Status"]).ToUpper() == "SUCCESS")
                                {
                                    if (lblMsg.Text.ToString().Split(' ').Length == 1)
                                    {
                                        InsertBookedTicketDetails(referenceNumber, lblMsg.Text.ToString());
                                        Response.Redirect("redirectbus.aspx", false);

                                    }
                                }
                                else
                                {
                                    return; //Booking Failed.
                                }

                            }
                            else if (Convert.ToDouble(lblTotalAmountPayable.Text) == Convert.ToDouble(0))
                            {
                                lblMsg.Text = client.bookTicket(blockseats);
                                DataSet dsbook = convertJsonStringToDataSet(lblMsg.Text);
                                if (dsbook != null)
                                {
                                    if (dsbook.Tables[0].Rows.Count > 0)
                                    {
                                        if (dsbook.Tables[0].Columns.Contains("APIPNR"))
                                        {
                                            lblMsg.Text = dsbook.Tables[0].Rows[0]["APIPNR"].ToString();
                                        }
                                    }
                                }
                                if (Convert.ToString(dsbook.Tables[0].Rows[0]["APIPNR"]) == "SUCCESS" || Convert.ToString(dsbook.Tables[0].Rows[0]["Status"]).ToUpper() == "SUCCESS")
                                {
                                    if (lblMsg.Text.ToString().Split(' ').Length == 1)
                                    {
                                        InsertBookedTicketDetails(referenceNumber, lblMsg.Text.ToString());
                                        Response.Redirect("redirectbus.aspx", false);

                                    }
                                }
                                else
                                {
                                    return; //Booking Failed.
                                }
                            }
                            else if (Session["Role"].ToString() == "User")
                            {
                                Server.Transfer("Pay.aspx?val=bus");
                            }
                        }
                        else
                        {
                            // Response.Redirect("redirectbus.aspx?Refno=" + Session["Ticketrefno"].ToString(), false);
                            Response.Redirect("Pay.aspx?val=bus", false);
                        }
                    }

                    #endregion

                }

            }
            else
            {
                Response.Redirect("~/Default.aspx", false);
            }
        }
        catch (Exception ex)
        {
            lblMsg.Text = ex.ToString();
        }
    }
    protected void btnGo_Click(object sender, EventArgs e)
    {
        try
        {
            string refno = GenerateCabRef();
            if (Session["TravelDate"].ToString() != null && Session["CardetailsId"].ToString() != null)
            {
                objPsgDtl.ScreenInd = blossom.InsertPassengerDetails;
                objPsgDtl.TravelDate = Session["TravelDate"].ToString();
                objPsgDtl.CarDetailsId = Convert.ToInt32(Session["CardetailsId"].ToString());
                objPsgDtl.Name = txtName.Text.ToString();
                objPsgDtl.Address = txtAddress.Text.ToString();
                objPsgDtl.City = txtCity.Text.ToString();
                objPsgDtl.State = DDLState.SelectedValue.ToString();
                objPsgDtl.ZipCode = txtZipCode.Text.ToString();
                objPsgDtl.Country = txtCountry.Text.ToString();
                objPsgDtl.EmailId = txtEMailId.Text.ToString();
                objPsgDtl.MobileNo = txtMobileNo.Text.ToString();
                objPsgDtl.LandMark = txtLandMark.Text.ToString();
                objPsgDtl.city_car = Session["CityName"].ToString();
                objPsgDtl.Status = "Blocked";
                objPsgDtl.CarName = CarName.Text.ToString();
                Session["Amount"] = BasicPrice.Text;
                //objPsgDtl.Status = txtStatus.Text.ToString();
                // objPsgDtl.BasicPrice =Convert.ToDouble(txtBasicPrice.Text);
                // objPsgDtl.BookingType = txtBookingType.Text.ToString();
                objPsgDtl.PickUpTime = DDLPickUpTime.SelectedValue.ToString();
                objPsgDtl.Basicfare = BasicPrice.Text;
                if (Session["UserId"] != null)
                {
                    if (Session["Role"].ToString() == "Agent")
                    {

                        Class1 objBal = new Class1();
                        DataSet objDataSet = new DataSet();
                        objBal.ScreenInd = Master123.gettopmarkup;
                        objBal.Agentid = Convert.ToInt32(Session["UserID"].ToString());
                        objBal.Type = "Cabs";
                        objDataSet = (DataSet)objBal.fnGetData();
                        string markUpAmount = "0";
                        ViewState["MarkUp"] = markUpAmount;
                        if (objDataSet != null)
                        {
                            if (objDataSet.Tables.Count > 0)
                            {
                                markUpAmount = objDataSet.Tables[0].Rows[0]["MarkUpAmount"].ToString();
                                ViewState["MarkUp"] = markUpAmount;
                            }
                        }

                        double actualfare = Convert.ToDouble(Session["Amount"]);
                        double totalfare = actualfare + Convert.ToDouble(markUpAmount);
                        objPsgDtl.TotalFare = totalfare.ToString();

                    }
                    else
                    {
                        objPsgDtl.TotalFare = BasicPrice.Text;
                    }
                }
                else
                {
                    objPsgDtl.TotalFare = BasicPrice.Text;
                }

                if (Session["UserId"] != null)
                {
                    objPsgDtl.AgentId = Session["UserId"].ToString();
                    objPsgDtl.AgentName = Session["UserName"].ToString();
                    objPsgDtl.Role = Session["Role"].ToString();
                }
                else
                {
                    objPsgDtl.Role = "Guest";
                }

                Session["refno"] = refno;
                objPsgDtl.ReferanceId = refno;
                objPsgDtl.CreatedBy = 1;
                 if (objPsgDtl.fnInsertRecord() == true)
                {
                    GetMail();
                    lblMsg.Text = "Record Inserted Successfully";
                    str = "SUCCESS";

                }
                 if (Session["UserId"]!=null)
                 {
                     if (Session["Role"].ToString() == "User")
                     {
                         if (str == "SUCCESS")
                         {

                             Response.Redirect("~/Pay.aspx?val=car", false);
                         }
                     }
                 }

                if(Session["UserId"]==null)
                {
                    if (str == "SUCCESS")
                    {

                        Response.Redirect("~/Pay.aspx?val=car", false);
                    }
                    else
                    {
                        lblText.Text = "Booking is failed.Please try later";
                    }
                }
                else if (Session["UserId"] != null && Session["Role"].ToString()=="Admin")
                {
                    if (Session["Role"].ToString() == "Admin")
                    {
                        Response.Redirect("~/CarTicket.aspx", false);
                    }
                }
                else
                {
                    if (Session["Role"] != null)
                    {
                        if (Session["Role"].ToString() == "Agent")
                        {
                            ClsBAL objBal = new ClsBAL();
                            DataSet dsBalance = objBal.GetAgentByUserId(Convert.ToInt32(Session["UserID"].ToString()));
                            DataSet dsCommSlab = objBal.GetCommissionSlab(Session["Role"].ToString(), "Car", ""); // Change it
                            string commisionPercentage = string.Empty;

                            if (dsCommSlab != null)
                            {
                                if (dsCommSlab.Tables[0].Rows.Count > 0)
                                {
                                    commisionPercentage = dsCommSlab.Tables[0].Rows[0]["Commission"].ToString();// Change it
                                }
                                else
                                {
                                    commisionPercentage = "0";
                                }
                            }
                            else
                            {
                                commisionPercentage = "0";
                            }

                            string balance = dsBalance.Tables[0].Rows[0]["Balance"].ToString();
                            string agentId = dsBalance.Tables[0].Rows[0]["AgentId"].ToString();
                            string TotalFare = BasicPrice.Text;
                            string actualFare = TotalFare;
                            string deductAmount = Convert.ToString(Convert.ToDouble(actualFare.ToString()) -
                                ((Convert.ToDouble(actualFare.ToString()) * Convert.ToDouble(commisionPercentage)) / 100));

                            string commisionFare = Convert.ToString(Convert.ToDouble(actualFare.ToString()) - Convert.ToDouble(deductAmount));

                            Session["AgentId_Agent"] = agentId;
                            Session["ActualFare_Agent"] = actualFare;
                            Session["CommisionFare_Agent"] = commisionFare;
                            Session["CommisionPercentage_Agent"] = commisionPercentage;
                            Session["DeductAmount_Agent"] = deductAmount;

                            if (Convert.ToDouble(balance) >= Convert.ToDouble(deductAmount))
                            {
                                string[] commPer = Session["CommisionPercentage_Agent"].ToString().Split('.');
                                DeductAgentBalance(Convert.ToInt32(Session["AgentId_Agent"].ToString()), Convert.ToDouble(Session["DeductAmount_Agent"].ToString()),
                                                        Convert.ToInt32(Session["UserID"].ToString()), refno, Convert.ToDouble(Session["ActualFare_Agent"].ToString()),
                                                        Convert.ToDouble(Session["CommisionFare_Agent"].ToString()), Convert.ToDouble(Session["CommisionPercentage_Agent"]));

                                objBal = new ClsBAL();
                                DataSet dsBalanceA = objBal.GetAgentByUserId(Convert.ToInt32(Session["UserID"].ToString()));

                                string balanceAgent = dsBalanceA.Tables[0].Rows[0]["Balance"].ToString();
                                Label lbl = (Label)this.Master.FindControl("lblBalance");
                                lbl.Text = balanceAgent;
                                Session["Balance"] = balanceAgent;
                                Response.Redirect("~/CarTicket.aspx", false);

                            }
                            else
                            {

                                lblMsg.Text = "Your balance is too low to book the ticket.So,please contact administrator";

                                return;
                            }
                        }
                    }
                }

            }
        }
        catch (Exception ex)
        {
            lblMsg.Text = ex.Message;
            throw;
        }
    }