<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TA_UI_Master_ShiftPattern.aspx.cs"
    MasterPageFile="~/MasterFile/TimeCheck.master" Inherits="Masters_TA_UI_Master_ShiftPattern" %>

<%@ Register TagPrefix="dxGridview" Namespace="DevExpress.Web" Assembly="DevExpress.Web.v14.2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="BodyContentPH" runat="server">
    <script type="text/javascript">
        function navi(loc) {
            document.getElementById('ctl00_BodyContentPH_iframePopup').src = loc;
            return false;
        }
        function Delete_Conf() {
            //Alert_AreyousuretoDelete
            return confirm('Are you sure to Delete ?');
        }
    </script>
    <div class="content-header">
        <h1 style="background-image: url('../dist/img/shift-pattern.png'); background-repeat: no-repeat; padding-left: 35px">
            <asp:Label ID="lbl_HeaderShiftPattern" runat="server"></asp:Label>
        </h1>
        <asp:SiteMapPath ID="site" runat="server" CssClass="breadcrumb">
            <NodeStyle CssClass="active" />
        </asp:SiteMapPath>
    </div>
    <div class="content">
        <div id="myModal" class="modal modal-default fade" role="dialog">
            <div class="modal-dialog" style="width: 90%;">
                <!-- Modal content-->
                <div class="modal-content" style="margin-top: 55px">
                    <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="400px"
                            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="border-table new-space" style="margin-top: 0px !important">
            <div class="form-horizontal">
                <div class="row form-group">
                    <div class="col-md-12" style="overflow: auto; overflow-y: hidden; padding-bottom: 10px">
                        <asp:HiddenField ID="hdnSelectRow" runat="server" />
                        <asp:HiddenField ID="hdnGetAllid" runat="server" />
                        <dxGridview:ASPxGridView ID="Grv_ShiftPattern" runat="server" AutoGenerateColumns="False"
                            EnableCallBacks="false" ClientInstanceName="Grv_ShiftPattern" DataSourceID="ObjectDataSource1"
                            OnHtmlRowCreated="Grv_ShiftPattern_HtmlRowCreated" KeyFieldName="ShiftPattern_Id">
                            <Columns>
                                <dxGridview:GridViewDataColumn VisibleIndex="0" 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("ShiftPattern_Id") %>' />
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="ShiftPattern_Id" Visible="false">
                                    <DataItemTemplate>
                                        <asp:Label ID="lbl_PatternId" Text='<%#Eval("ShiftPattern_Id") %>' runat="server"></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn Caption="Pattern Name" FieldName="Pattern_Name"
                                    Width="230px" VisibleIndex="1">
                                    <DataItemTemplate>
                                        <asp:Label ID="lbl_PatternName" Text='<%#Eval("Pattern_Name") %>' runat="server"
                                            CssClass="dxlabel"></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="Shift_days" VisibleIndex="2" Width="100px">
                                    <DataItemTemplate>
                                        <asp:Label ID="lbl_Nodays" Text='<%# Eval("Shift_days")%>' runat="server"></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="name" VisibleIndex="3" Width="300px">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblCompanyName" runat="server" Text='<%# Bind("name") %>' CssClass="dxlabel"></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <%--<dxGridview:GridViewDataTextColumn FieldName="Isdeleted" VisibleIndex="5" Width="75px">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblIsDeleted" runat="server" Text=' <%# Eval("Isdeleted")%>' ForeColor='<%#((Eval("Isdeleted").ToString()=="True")?System.Drawing.ColorTranslator.FromHtml("#FF0033"):System.Drawing.ColorTranslator.FromHtml("black")) %> '>
                                        </asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>--%>
                                <dxGridview:GridViewDataColumn HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center" VisibleIndex="4"
                                    CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center" Width="30px">
                                    <Settings AllowAutoFilter="false" />
                                    <DataItemTemplate>
                                        <a data-toggle="modal" title='<%# Session["View"] %>' data-placement="top" data-target="#myModal" onclick="return navi('TA_UI_Master_ShiftPatternView.aspx?PatternId=<%# Eval("ShiftPattern_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" VisibleIndex="5"
                                    CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center" Width="30px">
                                    <Settings AllowAutoFilter="false" />
                                    <DataItemTemplate>
                                        <asp:LinkButton ID="btnEdit" runat="server" ToolTip='<%# Session["Edit"] %>' data-toggle="tooltip"
                                            OnClick="EditLinkButton_Click" CommandName='<%# Eval("ShiftPattern_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" VisibleIndex="6"
                                    CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center" Width="30px">
                                    <Settings AllowAutoFilter="false" />
                                    <DataItemTemplate>
                                        <asp:LinkButton ID="btnDelete" runat="server" ToolTip='<%# Session["Delete"] %>' data-toggle="tooltip"
                                            OnClick="btn_delete_Click_1" CommandName='<%# Eval("ShiftPattern_Id") %>' data-placement="top"
                                            CssClass="btn btn-defalut del-icons" Style="color: Red" OnClientClick="return Delete_Conf();"></asp:LinkButton>
                                    </DataItemTemplate>
                                </dxGridview:GridViewDataColumn>
                            </Columns>
                            <SettingsText EmptyDataRow="No Records Found" />
                            <SettingsPager PageSize="10">
                            </SettingsPager>
                            <Settings ShowFilterRow="true" />
                            <SettingsBehavior SortMode="Value" AllowSort="true" AllowDragDrop="true" />
                            <Styles AlternatingRow-CssClass="table-bg">
                            </Styles>
                        </dxGridview:ASPxGridView>
                        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="SelectShiftPattern"
                            TypeName="ShiftPatternEventData">
                            <SelectParameters>
                                <asp:SessionParameter Name="UserGroupName" SessionField="UserGroupName" Type="string" />
                                <asp:SessionParameter Name="UserLevels" SessionField="LevelRights" Type="string" />
                                <asp:SessionParameter Name="parentLevelId" SessionField="parentLevelId" Type="Int32" />
                            </SelectParameters>
                        </asp:ObjectDataSource>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div class="pull-right-button">
                            <asp:LinkButton ID="btn_Add" CssClass="btn add-btn fa-plus" runat="server" OnClick="btn_Add_Click" />
                            <asp:LinkButton ID="btn_Delete" CssClass="btn del-btn fa-close" runat="server" CausesValidation="False"
                                OnClick="btn_Delete_Click" OnClientClick="return confirmdelete(this.form);" />
                            <asp:Button ID="btn_Restore" runat="server" CausesValidation="true" CssClass="but"
                                OnClientClick="return RestoreData();" OnClick="btn_Restore_Click" />
                            <asp:HiddenField ID="hdnDeletedData" runat="server" />
                            <asp:LinkButton ID="btn_PermanentDelete" runat="server" CausesValidation="true" CssClass="btn save-btn fa-trash-o"
                                OnClientClick="return Permanentconfirmdelete(this.form);" OnClick="btn_PermanentDelete_Click" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" language="javascript">
        function OnInit(s, e) {
            AdjustSize();
        }
        function OnEndCallback(s, e) {
            AdjustSize();
        }
        function AdjustSize() {
            var height = Math.max(0, document.documentElement.clientHeight);
            var width = Math.max(0, document.documentElement.clientWidth);
            grid.SetHeight(height);
        }
        function SelectAllOnThisPage(chkSelectAll) {
            var hdnSelectRow = document.getElementById('<%= hdnSelectRow.ClientID %>');
            var hdnSelectAll = document.getElementById('<%= hdnGetAllid.ClientID %>');
            if (chkSelectAll.checked == true) {
                for (var i = 0; i < Grv_ShiftPattern.pageRowCount; i++) {
                    if (document.getElementById('ctl00_BodyContentPH_Grv_ShiftPattern_cell' + (i + Grv_ShiftPattern.visibleStartIndex) + '_0_chkSelect').disabled == false) {
                        document.getElementById('ctl00_BodyContentPH_Grv_ShiftPattern_cell' + (i + Grv_ShiftPattern.visibleStartIndex) + '_0_chkSelect').checked = true;
                        var hdnUserId = document.getElementById('ctl00_BodyContentPH_Grv_ShiftPattern_cell' + (i + Grv_ShiftPattern.visibleStartIndex) + '_0_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 < Grv_ShiftPattern.pageRowCount; i++) {
                    document.getElementById('ctl00_BodyContentPH_Grv_ShiftPattern_cell' + (i + Grv_ShiftPattern.visibleStartIndex) + '_0_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 < Grv_ShiftPattern.pageRowCount; i++) {
                    if (document.getElementById('ctl00_BodyContentPH_Grv_ShiftPattern_cell' + (i + Grv_ShiftPattern.visibleStartIndex) + '_0_chkSelect').disabled == false) {
                        varTotalEnabled = varTotalEnabled + 1;
                    }
                    if (document.getElementById('ctl00_BodyContentPH_Grv_ShiftPattern_cell' + (i + Grv_ShiftPattern.visibleStartIndex) + '_0_chkSelect').checked)
                        varTotalCheckedCount = varTotalCheckedCount + 1;
                }
                if (varTotalCheckedCount == varTotalEnabled)
                    document.getElementById('ctl00_BodyContentPH_Grv_ShiftPattern_header0_chkSelectAll').checked = true;
                else
                    document.getElementById('ctl00_BodyContentPH_Grv_ShiftPattern_header0_chkSelectAll').checked = false;
            }
            else {
                if (Array.contains(removeId, hdnUserId)) {
                    Array.remove(removeId, hdnUserId);
                }
                hdnSelectRow.value = removeId;
                document.getElementById('ctl00_BodyContentPH_Grv_ShiftPattern_header0_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 = Grv_ShiftPattern.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++) {
                    //alert(selectedRow[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>
