using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;

public partial class User_booking : System.Web.UI.Page
{
    string Cancellation_Status_request = "";
    string IntClientPassword, IntClientID, IntClientType, IntCancellation, IntCancellationStatus;
    string Clientid, Clientpassword, Clienttype;
    string sys_IP;
    string Current_Rfnd_Status;
    decimal Total_CancellationCharges = 0;
    decimal Total_CancelationCharge = 0;
    DataSet DS_Cancellation_Status_Response;
    //DataSet DS_Cancellation_Status_Response;
    DataSet DS_Cancellation_Request;
    DataSet DS_Cancellation_Response;
    DataSet DS_Cancellation_Status_Request;
    AirEpointSupport obj_AirEpointSupport = new AirEpointSupport();
    decimal Total_CancellationCharges_Return = 0;
    decimal Total_FinalRefundAmt = 0;
   // AirInternationalCalculation obj_AirInternationalCalculation;
 decimal Penalty_Amount = 0;
  
    
    decimal Refunded_Amount = 0;

    protected void Page_Load(object sender, EventArgs e)
    {

       // Session["agid"] = "1304";
        try
        {
            sys_IP = Request.UserHostAddress;
            SqlHelper acs = new SqlHelper();
            
            if (!IsPostBack)
            {
                string status = string.Empty;
                string pnrSt = string.Empty;
               // DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2Bflight_Get_Cancellation_Trip_Details_W@r10ck", new SqlParameter[] { new SqlParameter("@UserID", Convert.ToString(Session["agid"])) });

                DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Get_Cancel_Trip_Lavi", new SqlParameter[] { new SqlParameter("@UserID", Convert.ToString(Session["agid"])) });

                if (ds.Tables.Count > 0)
                {
                    gridview_cancelled_trip.DataSource = ds.Tables[0];
                    gridview_cancelled_trip.DataBind();

                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
					  status = Convert.ToString(ds.Tables[0].Rows[i]["CancellationStatus"]);
                        //status = Convert.ToString(ds.Tables[0].Rows[i]["CStatus"]);
                       // pnrSt = Convert.ToString(ds.Tables[0].Rows[i]["Confirmationid"]);
                        Label lblstatus = (Label)gridview_cancelled_trip.Rows[i].FindControl("lbl_status_cancel");
                       // Button btnstatus = (Button)gridview_cancelled_trip.Rows[i].FindControl("btnpending");
                        LinkButton linkP = (LinkButton)gridview_cancelled_trip.Rows[i].FindControl("lnk_status_cancel");
                        //LinkButton linkC = (LinkButton)gridview_cancelled_trip.Rows[i].FindControl("linkcancel");


                        if (status == "Pending")
                        {
                            lblstatus.Visible = false;
                            linkP.Visible = true;
                        }
                       
                        else
                        {
                            lblstatus.Visible = true;
                            linkP.Visible = false;
                        }
                       
                    }



                }

                btnflight.Style.Add("background", "#c02d3d");
                btnflight.Style.Add("box-shadow", "0 0 3px #333");
                btnflight.Style.Add("color", "white");
            }
           
        }
        catch (Exception ex)
        {
            AirEpointSupport ob = new AirEpointSupport();
            ob.WriteToLog(ex.Message, "Fltcancellationdetails", "page_load__" + Convert.ToString(Session["agid"]));
            Response.Redirect("../User/index.aspx?s=exception");
        }
   
    }

     protected void gridview_cancelled_trip_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "details")
            {
                string message;
                string arg = Convert.ToString(e.CommandArgument);
                string partnerrefid = arg.Split(',')[0];
                string canid = arg.Split(',')[1];
                AirEpointSupport obj_airsupport = new AirEpointSupport();
                string FlightType = obj_airsupport.getFlightType(partnerrefid,Convert.ToString(Session["HURL"]));

                Session["partnerrefidcancel"] = partnerrefid;
                Session["canidcancel"] = canid;
                ViewState["partnerRefId"] = partnerrefid;
                ViewState["canid"] = canid;

                    string cancellation_Date = arg.Split(',')[2];
                  //  cancellation_Date = DateTime.Parse(cancellation_Date).ToString("MM/dd/yyyy");
                    string mm = DateTime.Parse(cancellation_Date).Month.ToString();
                    if (mm.Length < 2)
                    {
                        mm = "0" + mm;
                    }
                    string dd = DateTime.Parse(cancellation_Date).Day.ToString();
                    if (dd.Length < 2)
                    {
                        dd = "0" + dd;
                    }
                    string yy = DateTime.Parse(cancellation_Date).Year.ToString();

                    cancellation_Date = mm + "/" + dd + "/" + yy;
                    Session["flighttype"] = FlightType;

                    Session["candate"] = cancellation_Date;

                    ViewState["candate"] = cancellation_Date;
                    if (FlightType == "DOM")
                    {
                        Session["HermesPNRNo"] = SqlHelper.ExecuteScaler(SqlHelper.mainConnectionString, CommandType.Text, "select transid from Air_Booking_Information where partnerrefid='" + partnerrefid + "'");
                    }
                    else if (FlightType == "INAIR")
                    {
                        Session["HermesPNRNo"] = SqlHelper.ExecuteScaler(SqlHelper.mainConnectionString, CommandType.Text, "select Confirmationid from Air_InterNationalFlightSegmentOneWay where partnerrefid='" + partnerrefid + "'");
                    }
                    message = Check_Status_dom_hermes();

                    Page.RegisterStartupScript("XXX", "<script> alert('" + message + "')</script>");
               
                
            }
            if (e.CommandName == "problem")
            {
                Session["partnerrefidproblem"] = Convert.ToString(e.CommandArgument); ;
                Page.ClientScript.RegisterStartupScript(this.GetType(), "aks", "window.open('policy.aspx','Lavi','height=300, width = 450')", true);

            }
        }
        catch (Exception ex)
        {
            AirEpointSupport ob = new AirEpointSupport();
            ob.WriteToLog(ex.Message, "Allcencelled", "gridview_cancelled_trip_RowCommand__" + Convert.ToString(Session["user_id"]));
            Response.Redirect("../User/index.aspx?s=exception");
        }
    }



  string message;
    public string Check_Status_dom_hermes()
    {
        try
        {
            string CancelRefundRequest = @"<CancelRefundRequest>
                               <CancelledDate>" + Convert.ToString(ViewState["candate"]) + @"</CancelledDate>
                               </CancelRefundRequest>";
            obj_AirEpointSupport.WriteXmlLog(CancelRefundRequest, "CancellationRefund_Request__" + Convert.ToString(ViewState["partnerRefId"]));
            Hermes objhermes = new Hermes();
            string cancel_Refund = objhermes.Cancellation_Refund(CancelRefundRequest);
            obj_AirEpointSupport.WriteXmlLog(cancel_Refund, "CancellationRefund_Response__" + Convert.ToString(ViewState["partnerRefId"]));
            // string cancel_Refund = @"<CancelRefundResponse><ResultCode><Status>1</Status></ResultCode><RefundDetails><Item><HermesPNR>KD8L2E</HermesPNR><AirlinePNR>E3TCNF</AirlinePNR><TicketNumber>KD8L2E1</TicketNumber><TicketCost>5018.0000</TicketCost><Penalty>1525.0000</Penalty><CommissionReverse>0.0000</CommissionReverse><RefundAmount>3407.9800</RefundAmount></Item></RefundDetails></CancelRefundResponse>";
            DataSet cancrel_ref_res = new DataSet();
            cancrel_ref_res.ReadXml(new StringReader(cancel_Refund));
            if (cancrel_ref_res.Tables.Contains("response"))
            {
                message = Convert.ToString(cancrel_ref_res.Tables[0].Rows[0]["error"]);

            }
            else
            {
                DataTable canreftable = cancrel_ref_res.Tables["Item"];
                DataTable refundable = (from asd in canreftable.AsEnumerable()
                                        where asd.Field<string>("HermesPNR") == Convert.ToString(Session["HermesPNRNo"])
                                        select asd).CopyToDataTable();

               // Refunded_Amount = Refunded_Amount + Convert.ToDecimal(refundable.Rows[0]["RefundAmount"]);
                //string Cancellation_Charges = refundable.Rows[0]["Penalty"].ToString();

                   for (int i = 0; i < refundable.Rows.Count; i++)
                    {
                        Refunded_Amount = Refunded_Amount + Convert.ToDecimal(refundable.Rows[i]["RefundAmount"]);
                        Penalty_Amount = Penalty_Amount + Convert.ToDecimal(refundable.Rows[i]["Penalty"]);
                    }
                SqlParameter[] RefundUpdate = new SqlParameter[]
                          {
                  
                   new SqlParameter("@partnerRefid",Convert.ToString(Session["partnerrefidcancel"])),
                   new SqlParameter("@hermespnr",Convert.ToString(Session["HermesPNRNo"])),
                   new SqlParameter("@Refund_status",Convert.ToString("Refunded")),
                   new SqlParameter("@Cancellation_status",Convert.ToString("Success")),
                   new SqlParameter("@Refunded_Amt",Convert.ToDecimal(Refunded_Amount)),
                   new SqlParameter("@cancellation_Charges",Convert.ToDecimal(Penalty_Amount)),
                          };

                SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "InsertRefundAmount", RefundUpdate);


                B2B objb2b = new B2B();
                if (Convert.ToString(Session["flighttype"]) == "DOM")
                {
                    objb2b.Credit_Agent_Amount_Insertin_ATT_Flight_Refund(Convert.ToString(Session["agid"]), Convert.ToString(Session["partnerrefidcancel"]), Request.UserHostAddress, Convert.ToDecimal(Refunded_Amount));
                }
                else if (Convert.ToString(Session["flighttype"]) == "INAIR")
                {
                  //  objb2b.Credit_Agent_Amount_Insertin_ATT(Convert.ToString(Session["agid"]), Refunded_Amount, Convert.ToString(Session["partnerrefidcancel"]), Convert.ToString(Session["distributor"]), Request.UserHostAddress, "Intl Flight Cancellation", Convert.ToString(Session["HURL"]));
                }
                Session["agent_amount"] = Convert.ToDecimal(objb2b.CheckAgentBalance(Convert.ToString(Session["agid"]), Convert.ToString(Session["HURL"])));
                message = "Your Refund is Successful";

            }
        }
        catch (Exception ex)
        {
            obj_AirEpointSupport.WriteToLog(ex.Message, "cancel_Refund", "Cancel_Refund__" + Convert.ToString(Session["partnerrefidcancel"]));
            Response.Redirect("../User/index.aspx?s=exception");
        }
        //canreftable.



        //SqlHelper acs = new SqlHelper();
        //acs.Get_DB(Convert.ToString(Session["HURL"]));
        //try
        //{
        //    SqlParameter[] paramBookingInformation = new SqlParameter[]
        //    {
        //         new SqlParameter("@ResultBkngInf_Output",SqlDbType.Int,4),
        //         new SqlParameter("@partnerRefId",Convert.ToString(ViewState["partnerRefId"])),

        //           new SqlParameter("@userid",Convert.ToString(Session["agid"])), 

        //    };

        //    paramBookingInformation[0].Direction = ParameterDirection.Output;
        //    DataSet DataSetBookingInformationStatus = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_GetBookingInformationStatus", paramBookingInformation);

        //    string ResultBkngInf = Convert.ToString(paramBookingInformation[0].Value);

        //    if (ResultBkngInf == "1")
        //    {
        //        string Status = Convert.ToString(DataSetBookingInformationStatus.Tables[0].Rows[0]["Status"]);
        //        ViewState["TicketStatus"] = Status;
        //        if (Status == "Pending")
        //        {
        //            ViewState["transid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[0].Rows[0]["transid"]);
        //            //ViewState["canid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[1].Rows[0]["CancellationId"]);
        //for (int i = 0; i < DataSetBookingInformationStatus.Tables[1].Rows.Count; i++)
        //            {
        //               if(Convert.ToString(DataSetBookingInformationStatus.Tables[0].Rows[i]["Status"])!="Refunded")
        //                {

        //                ViewState["canid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[1].Rows[i]["CancellationId"]);
        //                string canid1 = Convert.ToString(ViewState["canid"]);
        //                GetBookingId();
        //                SendCancellationRequestAndUpdateTables(canid1);
        //                 }

        //            }
        //        }
        //        else if (Status == "SUCCESS" || Status == "Refunded")
        //        {
        //            ViewState["transid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[0].Rows[0]["transid"]);
        //           // ViewState["canid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[1].Rows[0]["CancellationId"]);
        //    for (int i = 0; i < DataSetBookingInformationStatus.Tables[1].Rows.Count; i++)
        //            {

        //               if(Convert.ToString(DataSetBookingInformationStatus.Tables[0].Rows[i]["Status"])!="Refunded")
        //                {
        //                ViewState["canid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[1].Rows[i]["CancellationId"]);
        //                string canid1 = Convert.ToString(ViewState["canid"]);
        //                GetBookingId();
        //                SendCancellationRequestAndUpdateTables(canid1);
        //                }

        //            }
        //        }
        //        else if (Status == "Cancelled")
        //        {
        //            //Response.Redirect("Trip.aspx", false);
        //        }
        //    }
        //    else if (ResultBkngInf == "0")
        //    {
        //        // "BookingInformation Status not Get successfully"; Technical Error Occured
        //    }
        //}
        //catch (Exception ex)
        //{
        //    obj_AirEpointSupport.WriteToLog(ex.Message, "cancel", "Check Status__" + Convert.ToString(ViewState["partnerRefId"]));
        //    Response.Redirect("../User/index.aspx?s=exception");
        //}
        return message;
    }


    protected void btnFltsbtn_Click(object sender, EventArgs e)
    {
        btnFltdwnld.Visible = false;
        SqlHelper acs = new SqlHelper();
        //acs.Get_DB(Convert.ToString(Session["HURL"]));
        DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2Bflight_Get_Cancellation_Trip_Details_W@r10ck_New", new SqlParameter[] { new SqlParameter("@UserID", Convert.ToString(Session["agid"])), new SqlParameter("@fromdate", Convert.ToString(txtFlightfrom.Text.Trim())), new SqlParameter("@todate", Convert.ToString(txtFlightto.Text.Trim())) });

       

        if (ds.Tables.Count > 0)
        {
            gridview_cancelled_trip.DataSource = ds.Tables[0];
            gridview_cancelled_trip.DataBind();
        }

    }
    protected void btnHotelsbmt_Click(object sender, EventArgs e)
    {
        btnHoteldwnld.Visible = false;
        getcandall();
    }
    protected void btnBussbmt_Click(object sender, EventArgs e)
    {
        btnBusdwnld.Visible = false;

        getBuscandall();

    }

    private void getBuscandetails()
    {
        //SqlHelper acs = new SqlHelper();
        //acs.Get_DB(Convert.ToString(Session["HURL"]));
        //try
        //{
        //    SqlParameter[] puneet = new SqlParameter[]
        //{
            
        //    new SqlParameter("@agent_id",Convert.ToString(Session["agid"]))
        //};
        //   //DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "ticket_cancelll_details_k", puneet);
        //   DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "ticket_cancelll_details_new", puneet);
        //    if (ds.Tables[0].Rows.Count > 0)
        //    {
        //        GridView2.DataSource = ds;
        //        GridView2.DataBind();
        //        //lblerror.Visible = false;
        //        GridView2.Visible = true;
        //    }
        //    else
        //    {
        //        //lblerror.Text = "No data found.";
        //        //lblerror.ForeColor = System.Drawing.Color.Red;
        //        //lblerror.Visible = true;
        //        GridView2.Visible = false;
        //    }
        //}
        //catch (Exception ex)
        //{
        //}
    }

    protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {

        GridView2.PageIndex = e.NewPageIndex;
        getBuscandetails();
    }

    private void getBuscandall()
    {


        //SqlHelper acs = new SqlHelper();
        //acs.Get_DB(Convert.ToString(Session["HURL"]));
        //try
        //{



        //    SqlParameter[] puneet = new SqlParameter[]
        //{
        //    new SqlParameter("@todate",Convert.ToString(txtBusto.Text.Trim())),
        //    new SqlParameter("@fromdate",Convert.ToString(txtBusfrom.Text.Trim())),
        //    new SqlParameter("@agent_id",Convert.ToString(Session["agid"]))
        //};
        //    DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2Bbus_ticket_cancelll_details_W@r10ck", puneet);
        //    if (ds.Tables[0].Rows.Count > 0)
        //    {
        //        GridView2.DataSource = ds;
        //        GridView2.DataBind();
        //        //lblerror.Visible = false;
        //        GridView2.Visible = true;
        //    }
        //    else
        //    {
        //        //lblerror.Text = "No data found.";
        //        //lblerror.ForeColor = System.Drawing.Color.Red;
        //        //lblerror.Visible = true;
        //        GridView2.Visible = false;
        //    }
        //}
        //catch (Exception ex)
        //{
        //}
    }
    protected void btnflight_Click(object sender, EventArgs e)
    {
        count_3_1.Style.Add("display", "none");
        count_2_1.Style.Add("display", "none");
        count_1_1.Style.Add("display", "");
        btnflight.Style.Add("background", "#c02d3d");
        btnflight.Style.Add("box-shadow", "0 0 3px #333");

        btnbus.Style.Add("background", "rgb(235,235,235)");
        btnbus.Style.Add("color", "#00468e");

        btnhotel.Style.Add("background", "rgb(235,235,235)");
        btnhotel.Style.Add("color", "#00468e");

        btnflight.Style.Add("color", "white");
    }
    protected void btnhotel_Click(object sender, EventArgs e)
    {
        count_3_1.Style.Add("display", "none");
        count_2_1.Style.Add("display", "");
        btnhotel.Style.Add("background", "#c02d3d");
        btnhotel.Style.Add("color", "white");

        btnflight.Style.Add("background", "rgb(235,235,235)");
        btnflight.Style.Add("color", "#00468e");

        btnbus.Style.Add("background", "rgb(235,235,235)");
        btnbus.Style.Add("color", "#00468e");

        count_1_1.Style.Add("display", "none");


        if (Page.Session["agid"] == null)
        {
            Response.Redirect("../sessionexpire.aspx");
        }
        else
        {
            getcandetails();
        }

    }
    protected void btnbus_Click(object sender, EventArgs e)
    {
        count_3_1.Style.Add("display", "");
        count_2_1.Style.Add("display", "none");
        count_1_1.Style.Add("display", "none");
        btnbus.Style.Add("background", "#c02d3d");
        btnbus.Style.Add("color", "white");

        btnflight.Style.Add("background", "rgb(235,235,235)");
        btnflight.Style.Add("color", "#00468e");

        btnhotel.Style.Add("background", "rgb(235,235,235)");
        btnhotel.Style.Add("color", "#00468e");


        if (Page.Session["agid"] == null)
        {
            Response.Redirect("../sessionexpire.aspx");
        }
        else
        {
            getBuscandetails();
        }

    }

    private void getcandetails()
    {
        //SqlHelper acs = new SqlHelper();
        //acs.Get_DB(Convert.ToString(Session["HURL"]));
        //try
        //{
        //    SqlParameter[] puneet = new SqlParameter[]
        //{
            
        //    new SqlParameter("@agent_id",Convert.ToString(Session["agid"]))
        //};
        //   DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "ticket_hotel_can_details", puneet);
        //    if (ds.Tables[0].Rows.Count > 0)
        //    {
        //        GridView1.DataSource = ds;
        //        GridView1.DataBind();
        //       // lblerror.Visible = false;
        //        GridView1.Visible = true;
        //    }
        //    else
        //    {
        //        //lblerror.Text = "No data found.";
        //        //lblerror.ForeColor = System.Drawing.Color.Red;
        //        //lblerror.Visible = true;
        //        GridView1.Visible = false;
        //    }
        //}
        //catch (Exception ex)
        //{
        //}
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {

        GridView1.PageIndex = e.NewPageIndex;
        getcandetails();
    }

    private void getcandall()
    {

        //SqlHelper acs = new SqlHelper();
        //acs.Get_DB(Convert.ToString(Session["HURL"]));
        //try
        //{



        //    SqlParameter[] puneet = new SqlParameter[]
        //{
        //    new SqlParameter("@todate",Convert.ToDateTime(txtHotelto.Text.Trim()+" 00:00:01.4370000")),
        //    new SqlParameter("@fromdate",Convert.ToDateTime(txtHotelfrom.Text.Trim()+" 23:59:59.4370000")),
        //    new SqlParameter("@agent_id",Convert.ToString(Session["agid"]))
        //};
        //   DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "ticket_hotelcan_details", puneet);
        //    if (ds.Tables[0].Rows.Count > 0)
        //    {
        //        GridView1.DataSource = ds;
        //        GridView1.DataBind();
        //        //lblerror.Visible = false;
        //        GridView1.Visible = true;
        //    }
        //    else
        //    {
        //        //lblerror.Text = "No data found.";
        //        //lblerror.ForeColor = System.Drawing.Color.Red;
        //        //lblerror.Visible = true;
        //        GridView1.Visible = false;
        //    }
        //}
        //catch (Exception ex)
        //{
        //}
    }
   // protected void btnHotelsbmt_Click(object sender, EventArgs e)
    //{
    //    getcandall();
    //}

    #region find cancellatoin status process for DOM type flight include all related functions


    private void Check_Status_dom()
    {
        SqlHelper acs = new SqlHelper();
       // acs.Get_DB(Convert.ToString(Session["HURL"]));
        try
        {
            SqlParameter[] paramBookingInformation = new SqlParameter[]
            {
                 new SqlParameter("@ResultBkngInf_Output",SqlDbType.Int,4),
                 new SqlParameter("@partnerRefId",Convert.ToString(ViewState["partnerRefId"])),

                   new SqlParameter("@userid",Convert.ToString(Session["agid"])), 
             
            };

            paramBookingInformation[0].Direction = ParameterDirection.Output;
            DataSet DataSetBookingInformationStatus = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_GetBookingInformationStatus", paramBookingInformation);

            string ResultBkngInf = Convert.ToString(paramBookingInformation[0].Value);

            if (ResultBkngInf == "1")
            {
                string Status = Convert.ToString(DataSetBookingInformationStatus.Tables[0].Rows[0]["Status"]);
                ViewState["TicketStatus"] = Status;
                if (Status == "Pending")
                {
                    ViewState["transid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[0].Rows[0]["transid"]);
                    //ViewState["canid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[1].Rows[0]["CancellationId"]);
		for (int i = 0; i < DataSetBookingInformationStatus.Tables[1].Rows.Count; i++)
                    {
                       if(Convert.ToString(DataSetBookingInformationStatus.Tables[0].Rows[i]["Status"])!="Refunded")
                        {

                        ViewState["canid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[1].Rows[i]["CancellationId"]);
                        string canid1 = Convert.ToString(ViewState["canid"]);
                        GetBookingId();
                        SendCancellationRequestAndUpdateTables(canid1);
                         }

                    }
                }
                else if (Status == "SUCCESS" || Status == "Refunded")
                {
                    ViewState["transid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[0].Rows[0]["transid"]);
                   // ViewState["canid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[1].Rows[0]["CancellationId"]);
		    for (int i = 0; i < DataSetBookingInformationStatus.Tables[1].Rows.Count; i++)
                    {

                       if(Convert.ToString(DataSetBookingInformationStatus.Tables[0].Rows[i]["Status"])!="Refunded")
                        {
                        ViewState["canid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[1].Rows[i]["CancellationId"]);
                        string canid1 = Convert.ToString(ViewState["canid"]);
                        GetBookingId();
                        SendCancellationRequestAndUpdateTables(canid1);
                        }

                    }
                }
                else if (Status == "Cancelled")
                {
                    //Response.Redirect("Trip.aspx", false);
                }
            }
            else if (ResultBkngInf == "0")
            {
                // "BookingInformation Status not Get successfully"; Technical Error Occured
            }
        }
        catch (Exception ex)
        {
            obj_AirEpointSupport.WriteToLog(ex.Message, "cancel", "Check Status__" + Convert.ToString(ViewState["partnerRefId"]));
            Response.Redirect("../User/index.aspx?s=exception");
        }
    }
	  private void Check_Status_Inter()
    {
        SqlHelper acs = new SqlHelper();
       // acs.Get_DB(Convert.ToString(Session["HURL"]));
        try
        {
            SqlParameter[] paramBookingInformation = new SqlParameter[]
            {
                 new SqlParameter("@ResultBkngInf_Output",SqlDbType.Int,4),
                 new SqlParameter("@partnerRefId",Convert.ToString(ViewState["partnerRefId"])),

                   new SqlParameter("@userid",Convert.ToString(Session["agid"])), 
             
            };

            paramBookingInformation[0].Direction = ParameterDirection.Output;
            DataSet DataSetBookingInformationStatus = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_GetBookingInformationStatus", paramBookingInformation);

            string ResultBkngInf = Convert.ToString(paramBookingInformation[0].Value);

            if (ResultBkngInf == "1")
            {
                string Status = Convert.ToString(DataSetBookingInformationStatus.Tables[0].Rows[0]["Status"]);
                ViewState["TicketStatus"] = Status;
                if (Status == "Pending")
                {
                    ViewState["transid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[0].Rows[0]["transid"]);
                    for (int i = 0; i < DataSetBookingInformationStatus.Tables[1].Rows.Count; i++)
                    {
                        if(Convert.ToString(DataSetBookingInformationStatus.Tables[0].Rows[i]["Status"])!="Refunded")
                        {
                        ViewState["canid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[1].Rows[i]["CancellationId"]);
                        string canid2 = Convert.ToString(ViewState["canid"]);
                        GetBookingId();
                        SendCancellationRequestAndUpdateTables_INTER(canid2);
                        }
                    }
                    // ViewState["canid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[1].Rows[0]["CancellationId"]);
                }
                else if (Status == "SUCCESS" || Status == "Refunded")
                {
                    ViewState["transid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[0].Rows[0]["transid"]);
                    for (int i = 0; i < DataSetBookingInformationStatus.Tables[1].Rows.Count; i++)
                    {
                         if(Convert.ToString(DataSetBookingInformationStatus.Tables[0].Rows[i]["Status"])!="Refunded")
                        {
                        ViewState["canid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[1].Rows[i]["CancellationId"]);
                        string canid2 = Convert.ToString(ViewState["canid"]);
                        GetBookingId();
                        SendCancellationRequestAndUpdateTables_INTER(canid2);
                        }

                    }
                    //ViewState["canid"] = Convert.ToString(DataSetBookingInformationStatus.Tables[1].Rows[0]["CancellationId"]);
                }
                else if (Status == "Cancelled")
                {
                    //Response.Redirect("Trip.aspx", false);
                }
            }
            else if (ResultBkngInf == "0")
            {
                // "BookingInformation Status not Get successfully"; Technical Error Occured
            }
        }
        catch (Exception ex)
        {
            obj_AirEpointSupport.WriteToLog(ex.Message, "cancel", "Check Status__" + Convert.ToString(ViewState["partnerRefId"]));
            Response.Redirect("../User/index.aspx?s=exception");
        }
    }
    public void GetBookingId()
    {
        SqlHelper acs = new SqlHelper();
       // acs.Get_DB(Convert.ToString(Session["HURL"]));
        ViewState["Booking_St_Id"] = SqlHelper.ExecuteScaler(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_get_booking_stid", new SqlParameter[] { new SqlParameter("@partnerrefid", Convert.ToString(ViewState["partnerRefId"])) });

    }

    void SendCancellationRequestAndUpdateTables(string CancellationId)
    {
        //try
        //{
        //    string Cancellation_Status_request = "<EticketCanStatusReq><Clientid>" + Clientid + "</Clientid><Clientpassword>" + Clientpassword + "</Clientpassword><Clienttype>" + Clienttype + "</Clienttype><transid>" + Convert.ToString(ViewState["transid"]) + "</transid><partnerRefId>" + Convert.ToString(ViewState["partnerRefId"]) + "</partnerRefId><CancellationId>" + CancellationId + "</CancellationId></EticketCanStatusReq>";
        //   // obj_AirEpointSupport.WriteXmlLog(Cancellation_Status_request, "Domestic_CancellationStatus_Request__" + Convert.ToString(ViewState["partnerRefId"]));



        //    DOMFlightCancellationStatus domfs = new DOMFlightCancellationStatus();
        //    string Get_Cancellation_Status = domfs.getCancelationStatus(Convert.ToString(Cancellation_Status_request));
        //  //  obj_AirEpointSupport.WriteXmlLog(Get_Cancellation_Status, "Domestic_CancellationStatus_Response__" + Convert.ToString(ViewState["partnerRefId"]));
        //    DS_Cancellation_Status_Response = new DataSet();
        //    DS_Cancellation_Status_Response.ReadXml(new StringReader(Convert.ToString(Get_Cancellation_Status)));


        //    #region Get Cancellation_Status_Response and Display Cancel and Refund Amount details
        //    if ((!DS_Cancellation_Status_Response.Tables["EticketCanStatusRes"].Columns.Contains("error")))
        //    {
        //        if (DS_Cancellation_Status_Response.Tables.Contains("Cancellation"))
        //        {
        //            if (DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count != 0)
        //            {


        //                for (int i = 0; i < DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count; i++)
        //                {

        //                    //if ((DS_Cancellation_Status_Response.Tables["Cancellation"].Columns.Contains("CancellationStatus")) && (DS_Cancellation_Status_Response.Tables["Cancellation"].Columns.Contains("RefundStatus")))
        //                    if ((DS_Cancellation_Status_Response.Tables["Cancellation"].Columns.Contains("CancellationStatus")))
        //                    {
        //                        ViewState["Cancellation_status_response"] = Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationStatus"]);


        //                        if (Convert.ToString(ViewState["Cancellation_status_response"]) == "Pending" || Convert.ToString(ViewState["Cancellation_status_response"]) == "pending")
        //                        {

        //                            Page.RegisterStartupScript("XXX", "<script> alert('Ticket (s) cancellation is under process.')</script>");


        //                        }
        //                        else if (Convert.ToString(ViewState["Cancellation_status_response"]) == "Processed")
        //                        {

        //                            Page.RegisterStartupScript("XXX", "<script> alert('Ticket (s) cancellation is done.')</script>");



        //                        }

        //                        else if (Convert.ToString(ViewState["Cancellation_status_response"]) == "Rejected" || Convert.ToString(ViewState["Cancellation_status_response"]) == "Reject")
        //                        {
        //                             //warlock Rejected Process (Update B2B_Air_Cancellation_Details table cancellation status from pending to Rejected.)
        //                            Update_cancellation_status_for_rejected();
        //                            //end warlock's function
        //                            Page.RegisterStartupScript("XXX", "<script> alert('Ticket (s) cancellation request is rejected.')</script>");


        //                        }


        //                    }

        //                    if ((DS_Cancellation_Status_Response.Tables["Cancellation"].Columns.Contains("RefundStatus")))
        //                    {

        //                        ViewState["Refund_status_response"] = Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["RefundStatus"]);


        //                        if (Convert.ToString(ViewState["Refund_status_response"]) == "Pending" || Convert.ToString(ViewState["Refund_status_response"]) == "pending")
        //                        {

        //                            Page.RegisterStartupScript("XXX", "<script> alert('Refund is under process.')</script>");


        //                        }

        //                        else if (Convert.ToString(ViewState["Refund_status_response"]) == "Processed")
        //                        {
        //                            Page.RegisterStartupScript("XXX", "<script> alert('Refund is successfully done.')</script>");



        //                        }

        //                    }

        //                }



        //            }


        //        }


        //    }
        //    else
        //    {

        //        string EticketStatus_response_Error = Convert.ToString(DS_Cancellation_Status_Response.Tables["EticketCanStatusRes"].Rows[0]["error"]);
        //        Page.ClientScript.RegisterStartupScript(this.GetType(), "test", "alert('" + EticketStatus_response_Error + "');", true);
        //    }

        //    #endregion

        //    Update_Air_Adult_Child_Infant_Cancel_Ticket_Info_Details_Table_According_To_Cancellation_Status_Response();
        //    Update_Air_Cancellation_Details_Table_when_Status_Processed();
        //    Update_Air_All_Table_When_Refund_Status_Processed();
        //    //Update_Air_Adult_Child_Infant_Cancel_Ticket_Info_Details_Table_According_To_Cancellation_Status_Response_ReturnFlight();         
        //    //Update_Air_Cancellation_Details_Table_when_Status_Processed_for_ReturnFlight();
        //    //Update_Air_All_Table_When_Refund_Status_Processed_ReturnFlight();

        //}
        //catch (Exception ex)
        //{
        //    AirEpointSupport ob = new AirEpointSupport();
        //    ob.WriteToLog(ex.Message, "Cancel.aspx", "SendCancellationRequestAndUpdateTables__" + Convert.ToString(ViewState["partnerRefId"]));
        //    Response.Redirect("../User/index.aspx?s=exception");
        //}
    }

    public void Update_Air_Adult_Child_Infant_Cancel_Ticket_Info_Details_Table_According_To_Cancellation_Status_Response()
    {

        SqlHelper acs = new SqlHelper();
     //   acs.Get_DB(Convert.ToString(Session["HURL"]));

        try
        {
            if (Convert.ToString(ViewState["Cancellation_status_response"]) == "Processed")
            {

                if (DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count != 0)
                {


                    for (int i = 0; i < DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count; i++)
                    {
                        #region Update_Cancellation and Refund Details in Adult_Child_Infant_TicketInfoTable
                        for (int j = 0; j < DS_Cancellation_Status_Response.Tables["ETicket"].Rows.Count; j++)
                        {


                            if (Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["Cancellation_Id"]) == Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Eticketdto_Id"]))
                            {



                                SqlParameter[] paramAdult_Child_Infant_ticketInfo = new SqlParameter[]
                          {
                          
                   new SqlParameter("@Result_Adult_Child_Infant_TicketInfo_Output",SqlDbType.Int,4),
                   new SqlParameter("@Booking_St_Id",Convert.ToString(ViewState["Booking_St_Id"])),
                   new SqlParameter("@partnerRefId",Convert.ToString(ViewState["partnerRefId"])),
                   new SqlParameter("@CancellationId",Convert.ToInt32(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationId"])),                                       
                   new SqlParameter("@CancellationStatus",Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationStatus"])),   
                   new SqlParameter("@CancellationProcessDateTime",Convert.ToDateTime(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationProcessDateTime"])), 
                   new SqlParameter("@CancellationCharges",Convert.ToDecimal(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationCharges"])), 
                   new SqlParameter("@RefundStatus",Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["RefundStatus"])), 
                   new SqlParameter("@FinalRefundAmount",Convert.ToDecimal(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["FinalRefundAmount"])), 
                   new SqlParameter("@RefundDateTime",Convert.ToDateTime(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["RefundDateTime"])), 
                                  

                   new SqlParameter("@eticketno",Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["eticketno"])),
                   new SqlParameter("@flightuid",Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["flightuid"])),
                   new SqlParameter("@passuid",Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["passuid"])),
                   new SqlParameter("@PnrNumber",Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["PnrNumber"])), 
                   new SqlParameter("@Origin",Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Origin"])), 
                   new SqlParameter("@Destination",Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Destination"])),
                 

                 
                          };

                                paramAdult_Child_Infant_ticketInfo[0].Direction = ParameterDirection.Output;

                                SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_uAir_Update_Adult_Child_Infant_TicketInfo_Table", paramAdult_Child_Infant_ticketInfo);
                                string Result_paramAdult_Child_Infant_ticketInfo_Status = Convert.ToString(paramAdult_Child_Infant_ticketInfo[0].Value);



                                if (Result_paramAdult_Child_Infant_ticketInfo_Status == "1")
                                {


                                }
                                else if (Result_paramAdult_Child_Infant_ticketInfo_Status == "0")
                                {
                                    //lblerrormsg.Text = "Adult Child and Infant Ticket Info Records not update successfully";
                                }



                            }


                        }

                        #endregion

                    }



                }
            }


        }
        catch (Exception ex)
        {
            obj_AirEpointSupport.WriteToLog(ex.Message, "Cancel", "Update_Air_Adult_Child_Infant_Cancel_Ticket_Info_Details_Table_According_To_Cancellation_Status_Response__" + Convert.ToString(ViewState["partnerRefId"]));
            Response.Redirect("../User/index.aspx?s=exception");


        }


    }
    public void Update_Air_Cancellation_Details_Table_when_Status_Processed()
    {

        SqlHelper acs = new SqlHelper();
     //   acs.Get_DB(Convert.ToString(Session["HURL"]));

        try
        {
            if (Convert.ToString(ViewState["Cancellation_status_response"]) == "Processed")
            {

                if (DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count != 0)
                {


                    for (int i = 0; i < DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count; i++)
                    {
                        #region Update_Cancellation and Refund Details in Adult_Child_Infant_TicketInfoTable
                        for (int j = 0; j < DS_Cancellation_Status_Response.Tables["ETicket"].Rows.Count; j++)
                        {


                            if (Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["Cancellation_Id"]) == Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Eticketdto_Id"]))
                            {



                                SqlParameter[] param_Cancellation_Info = new SqlParameter[]
                          {
                          
                   new SqlParameter("@Result_Cancellation_Details_Output",SqlDbType.Int,4),
                        //------------Edit Vk
                   new SqlParameter("@Can_Sno",SqlDbType.Int),
                   //-----Closed
                   new SqlParameter("@Agent_id",Convert.ToString(  Session["agid"])),
                   new SqlParameter("@Booking_St_Id",Convert.ToString(ViewState["Booking_St_Id"])),
                   new SqlParameter("@partnerRefId",Convert.ToString(ViewState["partnerRefId"])),
                   new SqlParameter("@CancellationId",Convert.ToInt32(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationId"])),                                       
                   new SqlParameter("@CancellationStatus",Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationStatus"])),   
                   new SqlParameter("@CancellationProcessDateTime",Convert.ToDateTime(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationProcessDateTime"])), 
                   new SqlParameter("@CancellationCharges",Convert.ToDecimal(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationCharges"])), 
                   new SqlParameter("@RefundStatus",Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["RefundStatus"])), 
                   new SqlParameter("@FinalRefundAmount",Convert.ToDecimal(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["FinalRefundAmount"])), 
                   new SqlParameter("@RefundDateTime",Convert.ToDateTime(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["RefundDateTime"])), 
                                  

                   new SqlParameter("@eticketno",Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["eticketno"])),
                   new SqlParameter("@flightuid",Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["flightuid"])),
                   new SqlParameter("@Passuid",Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["passuid"])),
                   new SqlParameter("@PnrNumber",Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["PnrNumber"])), 
                   new SqlParameter("@Origin",Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Origin"])), 
                   new SqlParameter("@Destination",Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Destination"])),
                 

                 
                          };

                                param_Cancellation_Info[0].Direction = ParameterDirection.Output;
                                param_Cancellation_Info[1].Direction = ParameterDirection.Output;
                                SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_Update_Cancellation_Details_Table", param_Cancellation_Info);
                                string Result_param_Cancellation_Info_Status = Convert.ToString(param_Cancellation_Info[0].Value);

                                //---------Edit By Vinod Find C_no-----
                                ViewState["Can_Sno"] = param_Cancellation_Info[1].Value;
                                //-----------------



                                if (Result_param_Cancellation_Info_Status == "1")
                                {


                                }
                                else if (Result_param_Cancellation_Info_Status == "0")
                                {
                                    //lblerrormsg.Text = "Cancellation Details of Depart flights Records not update successfully";
                                }



                            }


                        }

                        #endregion

                    }



                }
            }


        }
        catch (Exception ex)
        {
            obj_AirEpointSupport.WriteToLog(ex.Message, "Cancel", "Update_Air_Cancellation_Details_Table_when_Status_Processed__" + Convert.ToString(ViewState["partnerRefId"]));
            Response.Redirect("../User/index.aspx?s=exception");


        }


    }
    public void Update_Air_All_Table_When_Refund_Status_Processed()
    {
        SqlHelper acs = new SqlHelper();
     //   acs.Get_DB(Convert.ToString(Session["HURL"]));
        try
        {
            if (Convert.ToString(ViewState["Refund_status_response"]) == "Processed")
            {
                if (DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count != 0)
                {

                    #region Update_agent_transaction_details,agent_amount and All realated Table have Status Column When Refund Status is Processed
                    Total_FinalRefundAmt = 0;
                    Total_CancelationCharge = 0;
                    for (int i = 0; i < DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count; i++)
                    {


                        Total_FinalRefundAmt = Total_FinalRefundAmt + Convert.ToDecimal(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["FinalRefundAmount"]);
                        //vk
                        Total_CancelationCharge = Total_CancelationCharge + Convert.ToDecimal(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationCharges"]);
                        //closed vk
                        Current_Rfnd_Status = Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["RefundStatus"]);


                    }
                    //________________Change New--03/AGUST-----
                    //   ViewState["Total_FinalRefundAmt_depart"] = Total_FinalRefundAmt;
                    //  ViewState["Total_CancelationCharge_depart"] = Total_CancelationCharge;
                    //--------------

                    SqlParameter[] param_ForAll_refundedCaseTable1 = new SqlParameter[]
                          {
                          
                   new SqlParameter("@Result_RefundedCaseProcessed_Status_Output",SqlDbType.Int,4),
                   new SqlParameter("@partnerRefId",Convert.ToString(ViewState["partnerRefId"])),
                   new SqlParameter("@Tran_status","Refunded"),                 
                   new SqlParameter("@UpdIpAddress",sys_IP),
                   new SqlParameter("@FinalRefundAmount",Total_FinalRefundAmt), 
                   new SqlParameter("@Remark",Current_Rfnd_Status), 
                   new SqlParameter("@Can_Sno",Convert.ToString(ViewState["Can_Sno"])),
              
                          };

                    param_ForAll_refundedCaseTable1[0].Direction = ParameterDirection.Output;

                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Update_Refund_Status_Proceessd_Related_AllTable", param_ForAll_refundedCaseTable1);
                    string Result_ForAll_refundedCase_Table_Status = Convert.ToString(param_ForAll_refundedCaseTable1[0].Value);



                    if (Result_ForAll_refundedCase_Table_Status == "1")
                    {
                        B2B objb2b = new B2B();
                       // objb2b.Credit_Agent_Amount_Insertin_ATT(Convert.ToString(Session["agid"]), Total_FinalRefundAmt, Convert.ToString(ViewState["partnerRefId"]), Convert.ToString(Session["distributor"]), Request.UserHostAddress, "Dom Flight Cancellation",Convert.ToString(Session["HURL"]));


                        //Session["agent_amount"] = Convert.ToDecimal(objb2b.CheckAgentcutoffbal(Convert.ToString(Session["agid"]),Convert.ToString(Session["HURL"])));  //get the latest amount             
Session["agent_amount"] = Convert.ToDecimal(objb2b.CheckAgentBalance(Convert.ToString(Session["agid"]), Convert.ToString(Session["HURL"]))); 
                        //   SendMailDepart();

                    }
                    else if (Result_ForAll_refundedCase_Table_Status == "0")
                    {
                        //lblerrormsg.Text = "Refund Staus Processed Related Table Records not update successfully";
                    }

                    #endregion


                }
            }


        }
        catch (Exception ex)
        {
            obj_AirEpointSupport.WriteToLog(ex.Message, "Cancel", "Update_Air_All_Table_When_Refund_Status_Processed__" + Convert.ToString(ViewState["partnerRefId"]));
            Response.Redirect("../User/index.aspx?s=exception");


        }


    }

   

    #endregion

    #region find cancellatoin status process for INTER type flight include all related functions

    void SendCancellationRequestAndUpdateTables_INTER(string CancellationId)
    {

        #region Send Cancellation Status Request and Get Cancellation Status Response xml
        string cdate = DateTime.Now.ToString("yyy-MM-dd");
        string ctime = DateTime.Now.ToString("HH_mm_ss");
        string time_date = cdate + "_" + ctime;

        #region Send Cancellation Status Request and Get Cancellation Status Response xml

        if (Convert.ToString(ViewState["Cancellation_Response_error"]) != "")
        {
            ViewState["Cancellation_id"] = "";
        }
        Cancellation_Status_request = "<CanStatusIntRequest><Clientid>" + IntClientID + "</Clientid><Clientpassword>" + IntClientPassword + "</Clientpassword><Clienttype>" + IntClientType + "</Clienttype><Transid>" + Convert.ToString(ViewState["transid"]) + "</Transid><PartnerRefId>" + Convert.ToString(ViewState["partnerRefId"]) + "</PartnerRefId><CancellationId>" + CancellationId + "</CancellationId></CanStatusIntRequest>";
        DS_Cancellation_Status_Request = new DataSet();
        //obj_AirEpointSupport.WriteXmlLog(Cancellation_Status_request, Convert.ToString(ViewState["partnerRefId"]) + "_Cancellation_Status_Request" + time_date + ".xml");
        string Get_Cancellation_Status = obj_AirEpointSupport.sendRequestAndGetResponse_Arzoo(IntCancellationStatus, Cancellation_Status_request);
        //XmlDocument xDoc = new XmlDocument();
        //xDoc.Load(Server.MapPath("~/Xml_Req_Resp/Cancellation_Status_Response.xml"));
        //string Get_Cancellation_Status = xDoc.InnerXml;
        DS_Cancellation_Status_Response = new DataSet();
        DS_Cancellation_Status_Response.ReadXml(new StringReader(Convert.ToString(Get_Cancellation_Status)));
       // obj_AirEpointSupport.WriteXmlLog(Get_Cancellation_Status, Convert.ToString(ViewState["partnerRefId"]) + "_Cancellation_Status_Response" + time_date + ".xml");

        #endregion  //send cancellation request if there is no error tag first time that is request has been send...  and  now send cancellation status request

        string str = DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[0]["CancellationStatus"].ToString();
        Get_Cancellation_Status_Response_For_UpdateTableInternational();  //read cancel status Pending,Processed,Rejected
        //read refund status  Pending,Processed


        //  update  adult child infant ticket status  if cancellation status is pending or processed
        //  Update_Air_Adult_Child_Infant_Cancel_Ticket_Info_Details_Table_When_Cancellation_Status_Response_Pending_For_DepartFlightInternational();  //if pending  
        Update_Air_Adult_Child_Infant_Cancel_Ticket_Info_Details_Table_According_To_Cancellation_Status_ResponseInternational();  //if processed

        //  insert in  cancellation table insert first time when pending else update when processed
        // Insert_Air_Cancellation_Details_Table_When_Status_PendingInternational();  //if pending
        Update_Air_Cancellation_Details_Table_when_Status_ProcessedInternational();  //if processed


        // if refund status is processes then update in transaction details table about amounts 
        Update_Air_All_Table_When_Refund_Status_ProcessedInternational();   //refund
        // Response.Redirect("CancelStatusInternational.aspx", false);
        #endregion


    }
    public void Get_Cancellation_Status_Response_For_UpdateTableInternational()
    {
        try
        {
            #region Get Cancellation_Status_Response and Display Cancel and Refund Amount details
            if ((!DS_Cancellation_Status_Response.Tables["CanStatusIntResponse"].Columns.Contains("Error")))
            {
                if (DS_Cancellation_Status_Response.Tables.Contains("Cancellation"))
                {
                    if (DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count != 0)
                    {


                        for (int i = 0; i < DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count; i++)
                        {

                            //if ((DS_Cancellation_Status_Response.Tables["Cancellation"].Columns.Contains("CancellationStatus")) && (DS_Cancellation_Status_Response.Tables["Cancellation"].Columns.Contains("RefundStatus")))
                            if ((DS_Cancellation_Status_Response.Tables["Cancellation"].Columns.Contains("CancellationStatus")))
                            {
                                ViewState["Cancellation_status_response"] = DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[0]["CancellationStatus"].ToString();

                                if (Convert.ToString(ViewState["Cancellation_status_response"]) == "Pending" || Convert.ToString(ViewState["Cancellation_status_response"]) == "pending")
                                {

                                    Page.RegisterStartupScript("XXX", "<script> alert('Ticket (s) cancellation is under process.')</script>");
                                }
                                else if (Convert.ToString(ViewState["Cancellation_status_response"]) == "Processed")
                                {
                                    Page.RegisterStartupScript("XXX", "<script> alert('Ticket (s) cancellation is done.')</script>");
                                }
                                else if (Convert.ToString(ViewState["Cancellation_status_response"]) == "Rejected" || Convert.ToString(ViewState["Cancellation_status_response"]) == "Reject")
                                {

                                     //warlock Rejected Process (Update B2B_Air_Cancellation_Details table cancellation status from pending to Rejected.)
                                    Update_cancellation_status_for_rejected();
                                    //end warlock's function
                                    Page.RegisterStartupScript("XXX", "<script> alert('Ticket (s) cancellation request is rejected.')</script>");
                                }
                            }

                            if ((DS_Cancellation_Status_Response.Tables["Cancellation"].Columns.Contains("RefundStatus")))
                            {
                                ViewState["Refund_status_response"] = Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["RefundStatus"]);
                                if (Convert.ToString(ViewState["Refund_status_response"]) == "Pending" || Convert.ToString(ViewState["Refund_status_response"]) == "pending")
                                {
                                    Page.RegisterStartupScript("XXX", "<script> alert('Refund is under process.')</script>");
                                }
                                else if (Convert.ToString(ViewState["Refund_status_response"]) == "Processed")
                                {
                                    Page.RegisterStartupScript("XXX", "<script> alert('Refund is successfully done.')</script>");

                                }

                            }

                        }



                    }


                }


            }
            else
            {

                string EticketStatus_response_Error = Convert.ToString(DS_Cancellation_Status_Response.Tables["EticketCanStatusRes"].Rows[0]["error"]);
                Page.ClientScript.RegisterStartupScript(this.GetType(), "test", "alert('" + EticketStatus_response_Error + "');", true);
            }

            #endregion
        }
        catch (Exception ex)
        {
            // obj_AirEpointSupport.WriteToLog("InternationalCancel.aspx-Get_Cancellation_Status_Response_For_UpdateTableInternational()" + ex.Message.ToString(), Server.MapPath("~/Air_InternaltionalExceptionList"));
        }
    }
    public void Update_Air_Adult_Child_Infant_Cancel_Ticket_Info_Details_Table_According_To_Cancellation_Status_ResponseInternational()
    {
        //string Result_paramAdult_Child_Infant_ticketInfo_Status = string.Empty;

        //AirInternationalCalculation objAir = new AirInternationalCalculation();

        
        //try
        //{
        //    if (Convert.ToString(ViewState["Cancellation_status_response"]) == "Processed")
        //    {

        //        if (DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count != 0)
        //        {


        //            for (int i = 0; i < DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count; i++)
        //            {
        //                #region Update_Cancellation and Refund Details in Adult_Child_Infant_TicketInfoTable
        //                for (int j = 0; j < DS_Cancellation_Status_Response.Tables["ETicket"].Rows.Count; j++)
        //                {

        //                    //if (Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationId"]) )
        //                    {

        //                        string Booking_St_Id = Convert.ToString(ViewState["Booking_St_Id"]);
        //                        string partnerRefId = Convert.ToString(ViewState["partnerRefId"]);
        //                        string CancellationId = Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationId"]);
        //                        string CancellationStatus = Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationStatus"]);
        //                        string CancellationProcessDateTime = Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationProcessDateTime"]);
        //                        if (CancellationProcessDateTime == "")
        //                        {
        //                            CancellationProcessDateTime = DateTime.Now.ToShortDateString();
        //                        }
        //                        string CancellationCharges = Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationCharges"]);
        //                        string FinalRefundAmount = Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["FinalRefundAmount"]);
        //                        string RefundStatus = Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["RefundStatus"]);
        //                        string RefundDateTime = Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["RefundDateTime"]);
        //                        if (RefundDateTime == "")
        //                        {
        //                            RefundDateTime = DateTime.Now.ToShortDateString();
        //                        }
        //                        string eticketno = Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Eticketno"]);
        //                        string flightuid = Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Flightuid"]);
        //                        string passuid = Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Passuid"]);
        //                        string PnrNumber = Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["PnrNumber"]);
        //                        string Origin = Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Origin"]);
        //                        string Destination = Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Destination"]);
        //                        Result_paramAdult_Child_Infant_ticketInfo_Status = objAir.Update_Air_Adult_Child_Infant_Cancel_Ticket_Info_Details_Table_According_To_Cancellation_Status_Response
        //                            (Booking_St_Id, partnerRefId, CancellationId, CancellationStatus, CancellationProcessDateTime, CancellationCharges, RefundStatus, FinalRefundAmount, RefundDateTime,
        //                            eticketno, flightuid, passuid, PnrNumber, Origin, Destination,Convert.ToString(Session["HURL"]));
        //                        if (Result_paramAdult_Child_Infant_ticketInfo_Status == "1")
        //                        {


        //                        }
        //                        else if (Result_paramAdult_Child_Infant_ticketInfo_Status == "0")
        //                        {
        //                            //lblerrormsg.Text = "Adult Child and Infant Ticket Info Records not update successfully";
        //                        }



        //                    }


        //                }

        //                #endregion

        //            }



        //        }
        //    }


        //}
        //catch (Exception ex)
        //{
        //    Air_transaction_Cal.writeToLogFile("Info.aspx-Update_Air_Adult_Child_Infant_Cancel_Ticket_Info_Details_Table_According_To_Cancellation_Status_ResponseInternational()" + ex.Message.ToString(), Server.MapPath("~/Air_InternaltionalExceptionList"));

        //}


    }
    public void Update_Air_Cancellation_Details_Table_when_Status_ProcessedInternational()
    {
       //AirInternationalCalculation obj2 = new AirInternationalCalculation();
       // try
       // {
       //     if (Convert.ToString(ViewState["Cancellation_status_response"]) == "Processed")
       //     {

       //         if (DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count != 0)
       //         {


       //             for (int i = 0; i < DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count; i++)
       //             {
       //                 #region Update_Cancellation and Refund Details in Adult_Child_Infant_TicketInfoTable
       //                 for (int j = 0; j < DS_Cancellation_Status_Response.Tables["ETicket"].Rows.Count; j++)
       //                 {
       //                     if (Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["Cancellation_Id"]) == Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Eticketdto_Id"]))
       //                     {
       //                         ArrayList arlist = new ArrayList();
       //                         arlist = obj2.Update_Air_Cancellation_Details_Table_when_Status_Processed
       //                             (Convert.ToString(Session["agid"]), Convert.ToString(ViewState["Booking_St_Id"]), Convert.ToString(ViewState["partnerRefId"]),
       //                             Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationId"]),
       //                             Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationStatus"]),
       //                             Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationProcessDateTime"]),
       //                             Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationCharges"]),
       //                             Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["RefundStatus"]),
       //                             Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["FinalRefundAmount"]),
       //                             Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["RefundDateTime"]),
       //                             Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Eticketno"]),
       //                             Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Flightuid"]),
       //                             Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Passuid"]),
       //                             Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["PnrNumber"]),
       //                             Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Origin"]),
       //                             Convert.ToString(DS_Cancellation_Status_Response.Tables["ETicket"].Rows[j]["Destination"]),Convert.ToString(Session["HURL"]));
       //                         if (Convert.ToString(arlist[0]) == "1")
       //                         {
       //                             ViewState["Can_Sno"] = Convert.ToString(arlist[1]);
       //                             string str = Convert.ToString(arlist[1]);
       //                         }
       //                         if (Convert.ToString(arlist[0]) == "1")
       //                         {


       //                         }
       //                         else if (Convert.ToString(arlist[0]) == "0")
       //                         {
       //                             //            lblerrormsg.Text = "Cancellation Details of Depart and Return flights Records not update successfully";
       //                         }
       //                     }


       //                 }

       //                 #endregion

       //             }



       //         }
       //     }


       // }
       // catch (Exception ex)
       // {
       //     Air_transaction_Cal.writeToLogFile("Info.aspx-Update_Air_Cancellation_Details_Table_when_Status_ProcessedInternational()" + ex.Message.ToString(), Server.MapPath("~/Air_InternaltionalExceptionList"));

       // }


    }
    public void Update_Air_All_Table_When_Refund_Status_ProcessedInternational()
    {
 //       SqlHelper acs = new SqlHelper();
 //       acs.Get_DB(Convert.ToString(Session["HURL"]));

 //       AirInternationalCalculation obj3 = new AirInternationalCalculation();
 //       try
 //       {
 //           if (Convert.ToString(ViewState["Refund_status_response"]) == "Processed")
 //           {
 //               if (DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count != 0)
 //               {
 //                   Total_FinalRefundAmt = 0;
 //                   Total_CancelationCharge = 0;
 //                   #region Update_agent_transaction_details,agent_amount and All realated Table have Status Column When Refund Status is Processed
 //                   for (int i = 0; i < DS_Cancellation_Status_Response.Tables["Cancellation"].Rows.Count; i++)
 //                   {


 //                       Total_FinalRefundAmt = Total_FinalRefundAmt + Convert.ToDecimal(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["FinalRefundAmount"]);
 //                       //vk
 //                       Total_CancelationCharge = Total_CancelationCharge + Convert.ToDecimal(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["CancellationCharges"]);
 //                       //closed vk
 //                       Current_Rfnd_Status = Convert.ToString(DS_Cancellation_Status_Response.Tables["Cancellation"].Rows[i]["RefundStatus"]);


 //                   }
 //                   //________________Change New--03/AGUST-----
 //                   ViewState["Total_FinalRefundAmt_depart"] = Total_FinalRefundAmt;
 //                   ViewState["Total_CancelationCharge_depart"] = Total_CancelationCharge;                  //--------------
 //                   string Result_ForAll_refundedCase_Table_Status = obj3.Update_Air_All_Table_When_Refund_Status_Processed(Convert.ToString(ViewState["partnerRefId"]),
 //                   "SUCCESS", "CREDIT", sys_IP, Convert.ToString(Total_FinalRefundAmt), Current_Rfnd_Status, Convert.ToString(ViewState["Can_Sno"]),
 //                   Convert.ToString(Total_CancelationCharge),Convert.ToString(Session["HURL"]));
 //                   if (Result_ForAll_refundedCase_Table_Status == "1")
 //                   {

 //                       B2B objb2b = new B2B();
 //                       objb2b.Credit_Agent_Amount_Insertin_ATT(Convert.ToString(Session["agid"]), Total_FinalRefundAmt, Convert.ToString(ViewState["partnerRefId"]), Convert.ToString(Session["distributor"]), Request.UserHostAddress, "Intl Flight Cancellation",Convert.ToString(Session["HURL"]));


 //                       //Session["agent_amount"] = Convert.ToDecimal(objb2b.CheckAgentcutoffbal(Convert.ToString(Session["agid"]),Convert.ToString(Session["HURL"])));  //get the latest amount             

 //Session["agent_amount"] = Convert.ToDecimal(objb2b.CheckAgentBalance(Convert.ToString(Session["agid"]),Convert.ToString(Session["HURL"])));

 //                   }
 //                   else if (Result_ForAll_refundedCase_Table_Status == "0")
 //                   {
 //                       //lblerrormsg.Text = "Refund Staus Processed Related Table Records not update successfully";
 //                   }

 //                   #endregion


 //               }
 //           }


 //       }
 //       catch (Exception ex)
 //       {
 //           Air_transaction_Cal.writeToLogFile("Info.aspx-Update_Air_All_Table_When_Refund_Status_ProcessedInternational()" + ex.Message.ToString(), Server.MapPath("~/Air_InternaltionalExceptionList"));

 //       }


    }
    #endregion

          public void Update_cancellation_status_for_rejected()
    {
        //try
        //{
        //    SqlParameter[] cancellation_status = new SqlParameter[]
        //    {
                 
        //         new SqlParameter("@partnerRefId",Convert.ToString(ViewState["partnerRefId"])),
        //         new SqlParameter("@userid",Convert.ToString(Session["agid"])), 
        //         new SqlParameter("@cancellationID",Convert.ToString(ViewState["canid"])),
             
        //    };

        //    int a = SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "b2b_flight_update_cancellation_status_for_rejected", cancellation_status);
        //}
        //catch (Exception ex)
        //{
        //    Air_transaction_Cal.writeToLogFile("Info.aspx-Update_cancellation_status_for_rejected()" + ex.Message.ToString(), Server.MapPath("~/Air_InternaltionalExceptionList"));
        //}
    }

}

