<%@ page language="C#" autoeventwireup="true" masterpagefile="~/MasterFile/TimeCheck.master" inherits="Masters_TA_UI_Master_Terminal, App_Web_fjq0m1z3" %>

<%@ Register TagPrefix="dxGridview" Assembly="DevExpress.Web.v14.2" Namespace="DevExpress.Web" %>
<%@ Register Assembly="DevExpress.Web.v14.2" Namespace="DevExpress.Web"
    TagPrefix="devEditors" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ContentPlaceHolderID="BodyContentPH" ID="conTerminal" runat="server">
    <script src="../plugins/datepicker/jquery-1.11.1.min.js"></script>
    <script language="javascript" src="../js/jquery.autocomplete.js" type="text/javascript"></script>
    <script src="../plugins/datepicker/bootstrap-datepicker.js"></script>
    <script type="text/javascript">
        function navi(loc) {
            document.getElementById('ctl00_BodyContentPH_iframePopup').src = loc;
            return false;
        }
        function Delete_Conf() {
            return confirm('Are you sure to Delete ?');
        }
    </script>
    <script type="text/javascript">
        function checkAll(objRef) {
            var GridView = objRef.parentNode.parentNode.parentNode;
            var inputList = GridView.getElementsByTagName("input");
            for (var i = 0; i < inputList.length; i++) {
                var row = inputList[i].parentNode.parentNode;
                if (inputList[i].type == "checkbox" && objRef != inputList[i]) {
                    if (objRef.checked) {
                        inputList[i].checked = true;
                    }
                    else {
                        inputList[i].checked = false;
                    }
                }
            }
        }
        function ShowPopup() {
            $(document).ready(function () {
                $("#MyShowGrid").modal('show');
            });
        }
    </script>
    <div class="content-header">
        <h1 style="background-image: url('../dist/img/Terminal.png'); background-repeat: no-repeat; padding-left: 35px">
            <asp:Label ID="lbl_TerminalMaster" runat="server"></asp:Label>
        </h1>
        <asp:SiteMapPath ID="site" runat="server" CssClass="breadcrumb">
            <NodeStyle CssClass="active" />
        </asp:SiteMapPath>
    </div>
    <div id="myModal" class="modal modal-default fade" role="dialog">
        <div class="modal-dialog" style="min-width: 85%;">
            <!-- Modal content-->
            <div class="modal-content" style="margin-top: 100px">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" style="border-radius: 50px;">
                        &times;</button>
                    <h4 class="modal-title">
                        <asp:Label ID="lblDataView" runat="server" Text="Data View"></asp:Label>
                    </h4>
                </div>
                <div class="modal-body">
                    <iframe id="iframePopup" runat="server" scrolling="auto" width="100%" height="190px"
                        style="border-style: none"></iframe>
                </div>
                <div class="modal-footer" style="display: none">
                    <button type="button" class="btn btn-primary pull-right" data-dismiss="modal">
                        Close</button>
                </div>
            </div>
        </div>
    </div>
    <div class="content">
        <div class="form-horizontal">
            <div id="MyShowGrid" class="modal modal-default fade" role="dialog">
                <div class="modal-dialog" style="min-width: 50%; max-width: 60%">
                    <!-- Modal content-->
                    <div class="modal-content" style="margin-top: 100px">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" style="border-radius: 50px;">
                                &times;</button>
                            <h4 class="modal-title">
                                <asp:Label ID="lblDeviceList" runat="server" Text="Device List"></asp:Label>
                            </h4>
                        </div>
                        <div class="modal-body">
                            <div align="left" style="color: Green; padding-bottom: 10px" runat="server" id="divNoOfTer">
                                <asp:Label ID="lblNoOfTerminal" runat="server" Font-Names="MS Sans Serif, Arial"
                                    Font-Size="12px"></asp:Label>
                            </div>
                            <asp:GridView ID="gvDeviceList" runat="server" AutoGenerateColumns="False" Width="100%"
                                PageSize="10" AllowPaging="True" CssClass="table das-table1" OnPageIndexChanging="gvDeviceList_PageIndexChanging">
                                <Columns>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            <asp:CheckBox ID="checkall" runat="server" onclick="checkAll(this);" />
                                            <asp:Label ID="lblall" runat="server"></asp:Label>
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:CheckBox ID="chkSelected" runat="server"></asp:CheckBox>
                                        </ItemTemplate>
                                        <ItemStyle HorizontalAlign="Center" Width="6%" />
                                        <HeaderStyle HorizontalAlign="center" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Terminal Name">
                                        <ItemTemplate>
                                            <asp:Label ID="lblReaderId" runat="server" Text='<% # Bind("nReaderIdn") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Terminal Description">
                                        <ItemTemplate>
                                            <asp:Label ID="lblName" runat="server" Text='<% # Bind("sName") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="DataType" Visible="false">
                                        <ItemTemplate>
                                            <asp:Label ID="lblDataType" runat="server" Text='<% # Bind("DataType") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                                <RowStyle Height="30px" CssClass="table-bg" BorderColor="#C5DFFC" />
                                <PagerStyle Font-Overline="False" HorizontalAlign="Right" CssClass="GridPager" />
                                <PagerSettings FirstPageText="<<" LastPageText=">>" Mode="NumericFirstLast" NextPageText=">"
                                    PreviousPageText="<" />
                                <HeaderStyle CssClass="empheader" />
                                <AlternatingRowStyle BackColor="white" />
                            </asp:GridView>
                        </div>
                        <div class="modal-footer">
                            <asp:LinkButton ID="btnSave" runat="server" Text="&nbsp;&nbsp;Save" CssClass="btn save-btn fa-floppy-o"
                                OnClientClick="return TermialSave(this.form);" OnClick="GetSelectedRecords" />
                        </div>
                    </div>
                </div>
            </div>
            <div class="border-table new-space" style="margin-top: 0px">
                <div class="row form-group">
                    <%--if we enable property, in mobile view, the scroll bar will come automatically for grid control but not in PC--%>
                    <%--<div class="col-md-12" style="overflow: auto; overflow-y: hidden; padding-bottom: 10px">--%>
                    <div class="col-md-12">
                        <asp:HiddenField ID="hdnSelectRow" runat="server" />
                        <asp:HiddenField ID="hdnGetAllid" runat="server" />
                        <dxGridview:ASPxGridView ID="gv_Terminal" runat="server" AutoGenerateColumns="false"
                            EnableCallBacks="false" KeyFieldName="Terminal_Id" ClientInstanceName="gv_Terminal"
                            OnHtmlRowCreated="gv_Terminal_HtmlRowCreated">
                            <Columns>
                                <dxGridview:GridViewDataTextColumn Caption="Terminal ID" FieldName="Terminal_Id"
                                    VisibleIndex="0" Visible="false">
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataColumn VisibleIndex="1" Width="30px" HeaderStyle-VerticalAlign="Middle"
                                    HeaderStyle-HorizontalAlign="Center" CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center">
                                    <HeaderTemplate>
                                        <input id="chkSelectAll" runat="server" type="checkbox" onclick="SelectAllOnThisPage(this)" />
                                    </HeaderTemplate>
                                    <DataItemTemplate>
                                        <input id="chkSelect" runat="server" type="checkbox" onclick="SelectOnRow(this)"
                                            accesskey='<%# Eval("Terminal_Id") %>' />
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataColumn>
                                <dxGridview:GridViewDataTextColumn Caption="Terminal Id" FieldName="Terminal_ReaderID"
                                    Width="188px" VisibleIndex="2">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblTerminal_ReaderID" Text='<%# Eval("Terminal_ReaderID") %>' runat="server"
                                            CssClass="dxlabel"></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn Caption="Terminal Name" FieldName="Terminal_Name"
                                    Width="250px" VisibleIndex="3">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblTerminal_Name" Text='<%# Eval("Terminal_Name") %>' runat="server"
                                            CssClass="dxlabel"></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn Caption="Terminal Description" FieldName="Terminal_Description"
                                    Width="250px" VisibleIndex="4">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblTerminal_Description" Text='<%# Eval("Terminal_Description") %>'
                                            runat="server" CssClass="dxlabel"></asp:Label>
                                    </DataItemTemplate>
                                    <Settings AllowAutoFilter="False" />
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn Caption="Raw Data Format" FieldName="Raw_Data_Format"
                                    Width="120px" VisibleIndex="5">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblRaw_Data_Format" Text='<%# Eval("Raw_Data_Format") %>' runat="server"
                                            CssClass="dxlabel"></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataColumn HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center"
                                    CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center" Width="40px">
                                    <Settings AllowAutoFilter="false" />
                                    <DataItemTemplate>
                                        <a data-toggle="modal" title='<%# Session["View"] %>' data-placement="top" data-target="#myModal" onclick="return navi('TA_UI_Master_TerminalView.aspx?Terminal_Id=<%# Eval("Terminal_Id") %>')"
                                            href="#"><span class="btn btn-defalut view-icons"></span></a>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataColumn>
                                <dxGridview:GridViewDataColumn HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center"
                                    CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center" Width="40px">
                                    <Settings AllowAutoFilter="false" />
                                    <DataItemTemplate>
                                        <asp:LinkButton ID="btnEdit" runat="server" ToolTip='<%# Session["Edit"] %>' data-toggle="tooltip"
                                            OnClick="EditLinkButton_Click" CommandName='<%# Eval("Terminal_Id") %>' data-placement="top"
                                            CssClass="btn btn-defalut edit-icons" Style="color: #3C8DBC"></asp:LinkButton>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataColumn>
                                <dxGridview:GridViewDataColumn HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center"
                                    CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center" Width="40px">
                                    <Settings AllowAutoFilter="false" />
                                    <DataItemTemplate>
                                        <asp:LinkButton ID="btnDelete" runat="server" ToolTip='<%# Session["Delete"] %>' data-toggle="tooltip"
                                            OnClick="btn_delete_Click_1" CommandName='<%# Eval("Terminal_Id") %>' data-placement="top"
                                            CssClass="btn btn-defalut del-icons" Style="color: Red" OnClientClick="return Delete_Conf();"></asp:LinkButton>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataColumn>
                            </Columns>
                            <SettingsPager PageSize="10">
                                <PageSizeItemSettings Visible="true" ShowAllItem="true" Items="10,20,50,100,200" />
                            </SettingsPager>
                            <Settings ShowFilterRow="true" ShowFilterRowMenu="true" HorizontalScrollBarMode="Auto" ShowGroupPanel="true" VerticalScrollBarMode="Hidden" VerticalScrollableHeight="400" />
                            <SettingsText EmptyDataRow="No Records Found" />
                            <Settings ShowFilterRow="true" />
                            <SettingsBehavior AllowSort="true" ColumnResizeMode="Control"/>
                            <SettingsPager PageSize="10">
                            </SettingsPager>
                            <Styles AlternatingRow-CssClass="table-bg">
                            </Styles>
                        </dxGridview:ASPxGridView>
                        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="SelectTerminalDetails"
                            TypeName="TerminalEventData">
                            <SelectParameters>
                                <asp:SessionParameter Name="strUserGroupName" SessionField="UserGroupName" Type="String" />
                            </SelectParameters>
                        </asp:ObjectDataSource>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div class="pull-right-button">
                            <asp:Button ID="btnPopup" runat="server" Style="display: none" />
                            <asp:LinkButton ID="btn_add" CssClass="btn add-btn fa-plus" runat="server" OnClick="btn_add_Click" />
                            <asp:LinkButton ID="btnsync" Text="&nbsp;&nbsp;Sync device data" CssClass="btn del-btn fa-refresh"
                                runat="server" OnClick="btnsync_Click" Enabled="false" />
                            <asp:Button ID="btn_Delete" CssClass="but" runat="server" CausesValidation="False"
                                OnClick="btn_Delete_Click" OnClientClick="return confirmdelete(this.form);" Visible="false" />
                            <asp:Button ID="btn_Restore" CssClass="but" runat="server" OnClick="btn_Restore_Click"
                                OnClientClick="return RestoreData();" Visible="false" />
                            <asp:HiddenField ID="hdnDeletedData" runat="server" />
                            <asp:LinkButton ID="btn_PermanentDelete" CssClass="btn del-btn fa-trash-o" runat="server"
                                OnClick="btn_PermanentDelete_Click" OnClientClick="return Permanentconfirmdelete(this.form);"></asp:LinkButton>
                            <asp:LinkButton ID="btn_Cancel" CssClass="btn btn-primary fa fa-hand-o-left" runat="server"
                                OnClick="btn_Cancel_Click" Visible="false" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" language="javascript">
        function SelectAllOnThisPage(chkSelectAll) {
            var hdnSelectRow = document.getElementById('<%= hdnSelectRow.ClientID %>');
            var hdnSelectAll = document.getElementById('<%= hdnGetAllid.ClientID %>');
            if (chkSelectAll.checked == true) {
                for (var i = 0; i < gv_Terminal.pageRowCount; i++) {
                    if (document.getElementById('ctl00_BodyContentPH_gv_Terminal_cell' + (i + gv_Terminal.visibleStartIndex) + '_1_chkSelect').disabled == false) {
                        document.getElementById('ctl00_BodyContentPH_gv_Terminal_cell' + (i + gv_Terminal.visibleStartIndex) + '_1_chkSelect').checked = true;
                        var hdnUserId = document.getElementById('ctl00_BodyContentPH_gv_Terminal_cell' + (i + gv_Terminal.visibleStartIndex) + '_1_chkSelect').accessKey;
                        var hdnSelectRow = document.getElementById('<%= hdnSelectRow.ClientID %>');
                        var removeId = hdnSelectRow.value.split(",");
                        if (hdnUserId != "" && !Array.contains(removeId, hdnUserId)) {
                            if (hdnSelectRow.value != "")
                                hdnSelectRow.value += ",";
                            hdnSelectRow.value += hdnUserId;
                        }
                    }
                }
            }
            else {
                for (var i = 0; i < gv_Terminal.pageRowCount; i++) {
                    document.getElementById('ctl00_BodyContentPH_gv_Terminal_cell' + (i + gv_Terminal.visibleStartIndex) + '_1_chkSelect').checked = false;
                }
                hdnSelectRow.value = '';
            }
        }
        function SelectOnRow(chkOnSelect) {
            var hdnUserId = chkOnSelect.accessKey;
            var hdnSelectRow = document.getElementById('<%= hdnSelectRow.ClientID %>');
            var removeId = hdnSelectRow.value.split(",");
            if (chkOnSelect.checked) {
                if (hdnUserId != "" && !Array.contains(removeId, hdnUserId)) {
                    if (hdnSelectRow.value != "")
                        hdnSelectRow.value += ",";
                    hdnSelectRow.value += hdnUserId;
                }
                var varTotalCheckedCount = 0; var varTotalEnabled = 0;
                for (var i = 0; i < gv_Terminal.pageRowCount; i++) {
                    if (document.getElementById('ctl00_BodyContentPH_gv_Terminal_cell' + (i + gv_Terminal.visibleStartIndex) + '_1_chkSelect').disabled == false) {
                        varTotalEnabled = varTotalEnabled + 1;
                    }
                    if (document.getElementById('ctl00_BodyContentPH_gv_Terminal_cell' + (i + gv_Terminal.visibleStartIndex) + '_1_chkSelect').checked)
                        varTotalCheckedCount = varTotalCheckedCount + 1;
                }
                if (varTotalCheckedCount == varTotalEnabled)
                    document.getElementById('ctl00_BodyContentPH_gv_Terminal_header1_chkSelectAll').checked = true;
                else
                    document.getElementById('ctl00_BodyContentPH_gv_Terminal_header1_chkSelectAll').checked = false;
            }
            else {
                if (Array.contains(removeId, hdnUserId)) {
                    Array.remove(removeId, hdnUserId);
                }
                hdnSelectRow.value = removeId;
                document.getElementById('ctl00_BodyContentPH_gv_Terminal_header1_chkSelectAll').checked = false;
            }
        }
        var Norecordsavailable = "No records available ";
        var AreyousuretoRestore = "Are you sure to Restore? ";
        var Selecteddataisnotindeletedstatus = "Selected data is not in deleted status ";
        var Selectdatatorestore = "Select data to restore ";
        var Nodeletedrecordsavailable = "No deleted records available ";
        function RestoreAlert(norecordsavailable, areyousuretoRestore, selecteddataisnotindeletedstatus, selectdatatorestore, nodeletedrecordsavailable) {
            Norecordsavailable = norecordsavailable;
            AreyousuretoRestore = areyousuretoRestore;
            Selecteddataisnotindeletedstatus = selecteddataisnotindeletedstatus;
            Selectdatatorestore = selectdatatorestore;
            Nodeletedrecordsavailable = nodeletedrecordsavailable;
        }
        function RestoreData() {
            var rowscount = gv_Terminal.pageRowCount;
            if (rowscount == 0) {
                alert(Norecordsavailable);
                return false;
            }
            var hdnSelectRow = document.getElementById('<%= hdnSelectRow.ClientID %>');
            var DeleteDataRow = document.getElementById('<%= hdnDeletedData.ClientID %>');
            if (DeleteDataRow.value != '') {
                if (hdnSelectRow.value != '') {
                    var selectedRow = new Array();
                    selectedRow = hdnSelectRow.value.split(",");
                    var deletedRow = new Array();
                    deletedRow = DeleteDataRow.value.split(",");
                    var Status = false;
                    for (var i = 0; i < selectedRow.length; i++) {
                        if (Array.contains(deletedRow, selectedRow[i])) {
                            Status = true;
                        }
                    }
                    if (Status == true) {
                        return confirm(AreyousuretoRestore);
                    }
                    else {
                        alert(Selecteddataisnotindeletedstatus);
                        return false;
                    }
                }
                else {
                    alert(Selectdatatorestore);
                    return false;
                }
            }
            else {
                if (hdnSelectRow.value == '') {
                    alert(Nodeletedrecordsavailable);
                    return false;
                }
                else {
                    alert(Selecteddataisnotindeletedstatus);
                    return false;
                }
            }
        }
    </script>
</asp:Content>
