<%@ page language="C#" masterpagefile="~/Pages/Common/MasterPages/MainMasterPage_new.master" autoeventwireup="true" inherits="Pages_Transport_QuickAssignRoute, App_Web_sdcsgwte" enableEventValidation="false" viewStateEncryptionMode="Never" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register Src="~/UserControls/GridViewPager/GridViewPager.ascx" TagName="GridViewPager" TagPrefix="uc1" %>
<%@ Register Src="~/UserControls/Common/ScreenGroup/ScreenGroup.ascx" TagName="ScreenGroupControl" TagPrefix="ScreenGroup" %>
<%@ Register Src="~/UserControls/DatePicker/DatePickerControl.ascx" TagName="DatePickerControl" TagPrefix="Date" %>
<%@ Register Src="~/UserControls/Common/Transport/TransportDetailBoxControl.ascx" TagName="TransportControl" TagPrefix="Transport" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CP" runat="Server">
<style type="text/css">
input:disabled + input[type=image], input:read-only + a {
pointer-events: visible;
cursor: pointer !important;
}
</style>
    <asp:UpdatePanel ID="IncidentLogUpdatePanel" runat="server" UpdateMode="Always">
        <ContentTemplate>
            <div id="divContentPage" class="divcontentpagemargin">
                <!-- ContentPlaceHolder Box Starts -->
                <div class="dashBoardLeftCont">
                    <div class="himssuHeader3WireBox">
                        <%--<div class="himsBoxHeader">
                                        <div class="leftdiv">
                                        </div>
                                        <div class="himsBoxTitle">
                                            <div class="headerText">
                                            <asp:Label runat="server" ID="ScreenGroupNameLabel"></asp:Label>    
                                            </div>
                                        </div>
                                    </div>--%>
                        <table>
                            <tr>
                                <td>
                                    <div class="himsBoxContent">
                                        <div class="leftUlMenu">
                                            <ScreenGroup:ScreenGroupControl EnableViewState="true" ID="ScreenGroupControl" ScreenGroupId="106"
                                                Visible="true" runat="server" />
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="whiteboxpaddingleft row">
                    <Transport:TransportControl ID="TransportUserControl" runat="server" Visible="true" />
                    <div class="himssuHeader2WireBox">
                        <div class="contentHolder">
                            <div class="himssuHeader1WireBox card card-box">
                                <div class="himsBoxHeader card-head">
                                    <div class="leftdiv">
                                    </div>
                                    <div class="himsBoxTitle">
                                        <div class="headerText">
                                            <header>
                                                <i class="fas fa-map"></i>
                                                <asp:Label ID="Label1" runat="server" Text="Quick Assign Route"></asp:Label>
                                            </header>
                                        </div>
                                    </div>
                                </div>
                                <div class="himsBoxContent card-body">
                                    <asp:Panel ID="DetailPanel" runat="Server">
                                        <div class="contentHolder">

                                            <asp:Panel ID="SearchCriteriaPanel" runat="Server">
                                                <div class="outerBox pTop5 col-md-3">
                                                    <div class="controlLabelWidth">
                                                        <asp:Label ID="OrganizationLabel" runat="server" Text="Organization" CssClass="mandatory"></asp:Label>
                                                    </div>
                                                    <div class="fLeft pRight5">
                                                        <asp:DropDownList runat="server" ID="OrganizationDropDownList" SkinID="CustomWidthDropDownList"
                                                            CssClass="form-control" onmouseleave="showHideTooltip()" onmouseenter="showHideTooltip()" AutoPostBack="true" OnSelectedIndexChanged="OrganizationDropDownList_SelectedIndexChanged">
                                                        </asp:DropDownList>
                                                    </div>
                                                </div>
                                                <div class="outerBox pTop5 col-md-3">
                                                    <div class="controlLabelWidth">
                                                        <asp:Label ID="SearchBusRouteLabel" runat="server" Text="Bus Route" CssClass="mandatory"></asp:Label>
                                                    </div>
                                                    <div class="fLeft pRight5">
                                                        <asp:DropDownList runat="server" ID="SearchBusRouteDropDownList" SkinID="CustomWidthDropDownList"
                                                            CssClass="form-control" onmouseleave="showHideTooltip()" onmouseenter="showHideTooltip()"
                                                            AutoPostBack="true" OnTextChanged="SearchBusRouteDropDownList_TextChanged">
                                                        </asp:DropDownList>
                                                    </div>
                                                </div>
                                                <div class="outerBox pTop5 col-md-3">
                                                    <div class="controlLabelWidth">
                                                        <asp:Label ID="PickUpPointLabel" runat="server" Text="Pick Up Route"></asp:Label>
                                                    </div>
                                                    <div class="fLeft pRight5 display-flex">
                                                        <asp:DropDownList runat="server" ID="SearchPickupDropDownList" SkinID="CustomWidthDropDownList"
                                                            CssClass="form-control" onmouseleave="showHideTooltip()" onmouseenter="showHideTooltip()" AutoPostBack="true" OnSelectedIndexChanged="SearchPickupDropDownList_SelectedIndexChanged">
                                                        </asp:DropDownList>
                                                        <a runat="server" id="DeleteStudent" data-toggle="modal" data-target="#assignroute" onclick="GetPickupStudent();" visible="false">
                                                            <img src="../../Images/icons/magnifier.png" width="20" />
                                                        </a>
                                                    </div>
                                                </div>

                                                <div class="alignCenter pTop5 col-md-12">
                                                    <asp:Button ID="BlankPrintButton" Text="&#xf02f; Blank Print" runat="Server" OnClick="BlankPrintButton_Click"
                                                        SkinID="0" CssClass="btn btn-assign fas" />
                                                    <asp:Button ID="SearchPrintButton" runat="server" SkinID="0" Text="&#xf0ca; PrintList" OnClick="SearchPrintButton_Click" CssClass="btn btn-assign fas" />
                                                    <asp:Button ID="ExportButton" runat="server" Text="&#xf093; Export" OnClick="ExportButton_Click" CssClass="fas btn btn-examcommon" SkinID="0" />
                                                    <a href="javascript:;" onclick="OpenFileUpload();" class="btn btn-browser"><i class="fas fa-upload"></i>Browse</a>
                                                    <asp:FileUpload ID="flUpload" runat="server" onChange="readURL(this);" ClientIDMode="Static" Style="display: none;" />
                                                    <asp:Button ID="ImportFromExcelButton" runat="server" Text="&#xf019; Import From Excel" SkinID="0" CssClass="fas btn btn-examcommon" OnClick="ImportFromExcelButton_Click" />
                                                    <asp:Label ID="Label2" runat="server" Text="" Style="padding-left: 10px; font-size: medium;"></asp:Label>
                                                </div>

                                                <div class="pTop15 col-md-12">
                                                    <div class="controlLabelWidth alert alert-info col-md-12" style="margin: 0px">
                                                        <i class="material-icons">info</i>
                                                        <asp:Label ID="RamarkLabel" runat="server" Text="Add student Id No with . Dot seperation (Eg. 2. 5. 10)" Font-Bold="true"></asp:Label>
                                                    </div>
                                                </div>

                                            </asp:Panel>

                                            <div id="Div1" class="himssuHeader7WireBox col-md-12" runat="server">
                                                <div id="GridViewPagerDiv" runat="server" visible="True">
                                                    <div class="leftdiv">
                                                    </div>
                                                    <div class="himsBoxTitle">
                                                    </div>
                                                </div>

                                                <div class="himsBoxHeader card-head inner" id="Div3" runat="server">
                                                    <div class="gridHeaderText">
                                                        <header>
                                                            <asp:Label ID="Label6" runat="server" Text="Quick Assign Route"></asp:Label>
                                                        </header>
                                                    </div>
                                                </div>

                                                <div class="himsBoxContent table-responsive">
                                                    <asp:GridView ID="PickupDetailGridView" runat="server" AutoGenerateColumns="False"
                                                        EmptyDataText="No Records Found !!"
                                                        AllowPaging="false"
                                                        ShowHeader="true"
                                                        DataKeyNames="PickUpRouteId,PickUpPoint"
                                                        CssClass="table table-striped table-bordered table-hover" OnRowDataBound="PickupDetailGridView_RowDataBound">
                                                        <Columns>
                                                            <asp:TemplateField HeaderText="Pickup Point" ItemStyle-Width="15%" ItemStyle-Wrap="true" HeaderStyle-HorizontalAlign="Left">
                                                                <ItemTemplate>
                                                                    <%--<asp:LinkButton runat="server" ID="PickupPointLabel" Text='<%#Eval("PickUpPoint") %>' OnClientClick='GetStudentPick(<%#Eval("PickUpRouteId")%>)'></asp:LinkButton>--%>
                                                                    <a href="javascript:;" id="PickupPointLabel" onclick='GetStudentPick(<%#Eval("PickUpRouteId")%>);'><%#Eval("PickUpPoint") %></a>
                                                                </ItemTemplate>
                                                            </asp:TemplateField>
                                                            <%--<asp:TemplateField HeaderText="Drop Point" ItemStyle-Width="14%" ItemStyle-Wrap="true"
                                                                            HeaderStyle-HorizontalAlign="Left">
                                                                            <ItemTemplate>
                                                                                <asp:DropDownList runat="server" ID="DropDestinationDropDownList" SkinID="CustomWidthDropDownList"
                                                                                    Width="154px" onmouseleave="showHideTooltip()" onmouseenter="showHideTooltip()">
                                                                                </asp:DropDownList>
                                                                            </ItemTemplate>
                                                                        </asp:TemplateField>--%>
                                                            <asp:TemplateField HeaderText="Total" ItemStyle-Wrap="true" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="5%">
                                                                <ItemTemplate>
                                                                    <asp:Label runat="server" ID="AssignStudentCoutTextBox" SkinID="CustomWidthTextBox"></asp:Label>
                                                                </ItemTemplate>
                                                            </asp:TemplateField>
                                                            <asp:TemplateField HeaderText="Assign Student" ItemStyle-Wrap="true" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="40%">
                                                                <ItemTemplate>
                                                                    <asp:Label runat="server" ID="AssignStudentIdNoTextBox" SkinID="CustomWidthTextBox" Width="450px"></asp:Label>
                                                                </ItemTemplate>
                                                            </asp:TemplateField>
                                                            <asp:TemplateField ItemStyle-Wrap="true" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="40%">
                                                                <ItemTemplate>
                                                                    <asp:TextBox runat="server" ID="StudentIdNoTextBox" SkinID="CustomWidthTextBox"  AutoPostBack="true"></asp:TextBox>
                                                                </ItemTemplate>
                                                            </asp:TemplateField>
                                                        </Columns>
                                                        <PagerSettings Visible="False" />
                                                    </asp:GridView>
                                                    <asp:HiddenField ID="StudentIdHiddenField" runat="server" />
                                                    <asp:HiddenField ID="AcademicIdHiddenField" runat="server" />




                                                </div>
                                            </div>
                                        </div>
                                        <div id="assignroute" class="modal" role="dialog">
                                            <div class="modal-dialog">

                                                <!-- Modal content-->
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <button id="btnClose" title="Close (Esc)" type="button" class="close" data-dismiss="modal" onclick="Closepopup();">&times;</button>
                                                        <div class="leftdiv">
                                                        </div>
                                                        <div class="himsBoxTitle">
                                                            <div class="headerText">
                                                                <asp:Label ID="MainLabel" runat="server" Text="Student List"></asp:Label>
                                                            </div>
                                                        </div>
                                                    </div>

                                                    <div class="modal-body">
                                                        <div class="outerBox pTop5 col-md-6">
                                                            <div class="controlLabelWidth">
                                                                <asp:Label ID="Label3" runat="server" Text="Bus Route" CssClass="mandatory"></asp:Label>
                                                            </div>
                                                            <div class="fLeft pRight5">
                                                                <asp:DropDownList runat="server" ID="BUsRouteDropDownList" SkinID="CustomWidthDropDownList"
                                                                    CssClass="form-control" onmouseleave="showHideTooltip()" onmouseenter="showHideTooltip()" onchange="getPickupList();">
                                                                </asp:DropDownList>
                                                            </div>
                                                        </div>
                                                        <div class="outerBox pTop5 col-md-6">
                                                            <div class="controlLabelWidth">
                                                                <asp:Label ID="Label4" runat="server" Text="Pick Up Route"></asp:Label>
                                                            </div>
                                                            <div class="fLeft pRight5">
                                                                <asp:DropDownList runat="server" ID="StudentPickupDropDownList" SkinID="CustomWidthDropDownList"
                                                                    CssClass="form-control" onmouseleave="showHideTooltip()" onmouseenter="showHideTooltip()">
                                                                </asp:DropDownList>
                                                            </div>
                                                        </div>

                                                        <div class="alignCenter col-md-12 pb5 pTop5">
                                                            <input type="button" class="btn-search btn fas" value="&#xf002;  Search" onclick="GetSearchPickupStudent();" />
                                                        </div>
                                                        <table class="width-100 pTop15 table table-bordered table-striped" id="StudentDiv">
                                                            <thead>
                                                                <tr>
                                                                    <th align="left" scope="col">
                                                                        <asp:Label ID="Label5" runat="server"></asp:Label></th>
                                                                    <th align="left" scope="col">Name</th>
                                                                    <th align="left" scope="col">SUId</th>
                                                                    <th align="left" scope="col">PickUpPoint</th>
                                                                    <th align="left" scope="col">Delete</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody id="dvPickupGridDiv">
                                                            </tbody>
                                                        </table>
                                                    </div>

                                                </div>

                                            </div>

                                        </div>
                                    </asp:Panel>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>

    <script data-main='<%=ResolveUrl("~/JavaScript/rjs/fee-invoice-import")%>' src='<%=ResolveUrl("~/JavaScript/rjs/require.js")%>'></script>
    <%--Commented for mantis : 34101--%>
    <%--<script data-main='<%=ResolveUrl("~/JavaScript/rjs/quick-assignroute")%>' src='<%=ResolveUrl("~/JavaScript/rjs/require.js")%>'></script>--%>

    <%--Added for mantis : 34101--%>
    <script type="text/javascript">
        function validateQuickassignroute() {
            var himsValidator = [new hims_ctl_val("ctl00_CP_SearchBusRouteDropDownList", "BusRoute", "T", "", "", "", 20),
                new hims_ctl_val("ctl00_CP_OrganizationDropDownList", "Organization", "T", "", "", "", 20)];
            if (fnDoValidate(himsValidator))
                return true;
            else
                return false;
        }


        function GetPickupStudent() {
            var Pickup = 0;
            var busroute = $('#ctl00_CP_SearchBusRouteDropDownList').val();
            $('#ctl00_CP_BUsRouteDropDownList').val(busroute);
            getPickupList();

            if ($("#ctl00_CP_SearchPickupDropDownList").prop('selectedIndex') > 0) {
                Pickup = $('#ctl00_CP_SearchPickupDropDownList').val();
            }
            $.ajax({
                type: "POST",
                url: "/Pages/Transport/QuickAssignRoute.aspx/GetPickupStudent",
                data: '{"OrgId":"' + $('[id$=OrganizationDropDownList]').val() + '","Pickupid":"' + Pickup + '","BusRouteId":"' + busroute + '"}',
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function (data) {
                    var datas = $.parseJSON(data.d);
                    if ($("#ctl00_CP_SearchPickupDropDownList").prop('selectedIndex') > 0) {
                        Pickup = $('#ctl00_CP_SearchPickupDropDownList').val();
                        $('#ctl00_CP_StudentPickupDropDownList').val(Pickup);

                    }
                    openpopup();
                    if (datas.PickGrid != '') {
                        $('#dvPickupGridDiv').html('');
                        $('#dvPickupGridDiv').html(datas.PickGrid);
                    }
                    else {
                        $('#dvPickupGridDiv').html('');
                        $('#dvPickupGridDiv').html("<tr>No Records found !</tr>");
                    }
                },
                error: function (xhr, status, error) {
                    $('[id$=MainUpdateProgress]').hide();
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }
        function LoadingMsg(msg1, msg2) {
            $('.hls-bg').show();
            $('#spnmain1msg').html(msg1);
            $('#spnmain2msg').html(msg2);
            $('#assignroute').show();
        }
        function CloseLoading() {
            $('.hls-bg').hide();
            $('#assignroute').hide();
        }
        function Closepopup() {
            $('.hls-bg').hide();
            $('#assignroute').hide();
        }
        function openpopup() {
            LoadingMsg('Loading Details', '<b>Please Wait ...</b>');
            window.setTimeout(function () {
                CloseLoading();
                $('.hls-bg').show();
                $('#assignroute').show();
            }, 500);
        }
        function DeleteStudentDetail(obj, sourceId) {
            if (confirm("Do you really want to delete?") == true) {
                $.ajax({
                    type: "POST",
                    url: "/Pages/Transport/QuickAssignRoute.aspx/DeleteStudentDetail",
                    data: '{"SourceId":"' + sourceId + '"}',
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        if (data.d = 1) {
                            GetPickupStudent();
                        }
                        else if (data.d = 0) {
                            alert('Error In Delete');
                        }
                    },
                    error: function (xhr, status, error) {
                        var err = eval("(" + xhr.responseText + ")");
                        console.log(err.Message);
                    }
                });
            }
        }
        function GetStudentPick(pickupid) {
            $('[id$=BUsRouteDropDownList]').val($('[id$=SearchBusRouteDropDownList]').val())
            getPickupList();

            $.ajax({
                type: "POST",
                url: "/Pages/Transport/QuickAssignRoute.aspx/GetPickupStudent",
                data: '{"OrgId":"' + $('[id$=OrganizationDropDownList]').val() + '","Pickupid":"' + pickupid + '","BusRouteId":"' + $('[id$=SearchBusRouteDropDownList]').val() + '"}',
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function (data) {
                    var datas = $.parseJSON(data.d);
                    openpopup();
                    $('#ctl00_CP_StudentPickupDropDownList').val(pickupid);
                    if (datas.PickGrid != '') {
                        $('#dvPickupGridDiv').html('');
                        $('#dvPickupGridDiv').html(datas.PickGrid);
                    }
                    else {
                        $('#dvPickupGridDiv').html("");
                        $('#dvPickupGridDiv').html("<tr>No Records found !</tr>");
                    }
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }
        function getPickupList() {
            $.ajax
            ({
                url: "/Pages/Transport/QuickAssignRoute.aspx/GetpickDropDown",
                type: "POST",
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                data: '{"BusId":"' + $('#ctl00_CP_BUsRouteDropDownList').find(":selected").val() + '"}',
                success: function (data) {
                    var ddlCustomers = $("#ctl00_CP_StudentPickupDropDownList");
                    ddlCustomers.empty().append('<option  value="0">- ALL - </option>');
                    $.each(data.d, function () {
                        ddlCustomers.append($("<option></option>").val(this['Value']).html(this['Text']));
                    });
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }
        function GetSearchPickupStudent() {
            var Pickup = 0;
            if ($("#ctl00_CP_BUsRouteDropDownList").prop('selectedIndex') <= 0) {
                alert("select Busroute");
                $('#dvPickupGridDiv').html('');
                return;
            }
            if ($("#ctl00_CP_StudentPickupDropDownList").prop('selectedIndex') > 0) {
                Pickup = $('[id$=StudentPickupDropDownList]').val();
            }
            var busroute = $('#ctl00_CP_BUsRouteDropDownList').val();
            $('#ctl00_CP_BUsRouteDropDownList').val(busroute);
            $.ajax({
                type: "POST",
                url: "/Pages/Transport/QuickAssignRoute.aspx/GetPickupStudent",
                data: '{"OrgId":"' + $('[id$=OrganizationDropDownList]').val() + '","Pickupid":"' + Pickup + '","BusRouteId":"' + busroute + '"}',
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function (data) {
                    var datas = $.parseJSON(data.d);
                    openpopup();
                    if (datas.PickGrid != '') {
                        $('#dvPickupGridDiv').html('');
                        $('#dvPickupGridDiv').html(datas.PickGrid);
                    }
                    else {
                        $('#dvPickupGridDiv').html('');
                        $('#dvPickupGridDiv').html("<tr>No Records found !</tr>");
                    }
                },
                error: function (xhr, status, error) {
                    $('[id$=MainUpdateProgress]').hide();
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }
    </script>

</asp:Content>
