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

<%@ Register TagPrefix="dxGridview" Namespace="DevExpress.Web" Assembly="DevExpress.Web.v14.2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="BodyContentPH" runat="Server">
    <div class="content-header">
        <h1 style="background-image: url('../dist/img/emplyee-type.png'); background-repeat: no-repeat; padding-left: 35px">
            <asp:Label ID="lbl_EmployeeType" Text="Employee Type" runat="server"></asp:Label>
        </h1>
        <asp:SiteMapPath ID="site" runat="server" CssClass="breadcrumb">
            <NodeStyle CssClass="active" />
        </asp:SiteMapPath>
    </div>
    <div class="content">
        <div class="form-horizontal">
            <div class="border-table new-space" style="margin-top: 0px">
                <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_Type" runat="server" ClientInstanceName="grv_Type"
                            EnableCallBacks="false" AutoGenerateColumns="false" DataSourceID="ObjectDataSource1"
                            OnHtmlRowCreated="grv_Type_HtmlRowCreated" KeyFieldName="TypeId">
                            <Columns>
                                <dxGridview:GridViewDataColumn VisibleIndex="0" Width="30px" HeaderStyle-VerticalAlign="Middle"
                                    HeaderStyle-HorizontalAlign="Center" CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center">
                                    <Settings AllowAutoFilter="false" />
                                    <HeaderTemplate>
                                        <input id="chkSelectAll" runat="server" type="checkbox" onclick="SelectAllOnThisPage(this)" />
                                    </HeaderTemplate>
                                    <DataItemTemplate>
                                        <input id="chkSelect" runat="server" type="checkbox" onclick="SelectOnRow(this)"
                                            disabled='<%#DataBinder.Eval(Container.DataItem,"flag").ToString()=="1" %>' accesskey='<%# Eval("TypeId") %>' />
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" BackColor="#5172AD" />
                                </dxGridview:GridViewDataColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="TypeId" VisibleIndex="4" Visible="false">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblTypeId" runat="server" Text='<%# Eval("TypeId") %>'></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" BackColor="#5172AD" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn Caption="Type Name" FieldName="TypeName" VisibleIndex="1"
                                    Width="600px">
                                    <DataItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("TypeName") %>' CssClass="dxlabel"></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" BackColor="#5172AD" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="IsFlexible" VisibleIndex="2" Width="0px"
                                    Visible="false">
                                    <DataItemTemplate>
                                        <asp:Label ID="lvlIsFlexible" runat="server" Text='<%# Bind("IsFlexible") %>'></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" BackColor="#5172AD" />
                                </dxGridview:GridViewDataTextColumn>
                                <%-- <dxGridview:GridViewDataTextColumn FieldName="isdeleted" VisibleIndex="3" Width="80px">
                                    <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" BackColor="#5172AD" />
                                </dxGridview:GridViewDataTextColumn>--%>
                                <dxGridview:GridViewDataColumn HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center"
                                    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("TypeId") %>' 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="30px">
                                    <Settings AllowAutoFilter="false" />
                                    <DataItemTemplate>
                                        <asp:LinkButton ID="btnDelete" runat="server" ToolTip='<%# Session["Delete"] %>' data-toggle="tooltip"
                                            OnClick="btn_delete_Click_1" CommandName='<%# Eval("TypeId") %>' 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>
                            <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>
                            <%--<ClientSideEvents Init="OnInit" EndCallback="OnEndCallback" />--%>
                        </dxGridview:ASPxGridView>
                        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="SelectAllType"
                            TypeName="TypeEventData">
                            <SelectParameters>
                                <asp:SessionParameter Name="UserType" SessionField="UserGroupName" />
                            </SelectParameters>
                        </asp:ObjectDataSource>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div class="pull-right-button">
                            <asp:LinkButton ID="btn_add" runat="server" CssClass="btn add-btn fa-plus" OnClick="btn_add_Click"
                                Text="Add" />
                            <asp:LinkButton ID="btn_Delete" runat="server" CausesValidation="False" CssClass="btn btn-primary fa fa-trash-o"
                                OnClick="btn_Delete_Click" OnClientClick="return confirmdelete(this.form);" Text="Delete" />
                            <asp:LinkButton ID="btn_Back" runat="server" CausesValidation="false" Visible="false"
                                CssClass="btn btn-primary fa fa-hand-o-left" Text="Back" />
                            <asp:LinkButton ID="btn_Restore" runat="server" CssClass="but" OnClientClick="return RestoreData();"
                                Visible="true" OnClick="btn_Restore_Click" />
                            <asp:HiddenField ID="hdnDeletedData" runat="server" />
                            <asp:LinkButton ID="btn_PermanentDelete" runat="server" CssClass="btn save-btn fa-trash-o"
                                OnClientClick="return Permanentconfirmdelete(this.form);" Visible="true" 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 Delete_Conf() {
            //Alert_AreyousuretoDelete
            return confirm('Are you sure to Delete ?');
        }
        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_Type.pageRowCount; i++) {
                    if (document.getElementById('ctl00_BodyContentPH_grv_Type_cell' + (i + grv_Type.visibleStartIndex) + '_0_chkSelect').disabled == false) {
                        document.getElementById('ctl00_BodyContentPH_grv_Type_cell' + (i + grv_Type.visibleStartIndex) + '_0_chkSelect').checked = true;
                        var hdnUserId = document.getElementById('ctl00_BodyContentPH_grv_Type_cell' + (i + grv_Type.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_Type.pageRowCount; i++) {
                    document.getElementById('ctl00_BodyContentPH_grv_Type_cell' + (i + grv_Type.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_Type.pageRowCount; i++) {
                    if (document.getElementById('ctl00_BodyContentPH_grv_Type_cell' + (i + grv_Type.visibleStartIndex) + '_0_chkSelect').disabled == false) {
                        varTotalEnabled = varTotalEnabled + 1;
                    }
                    if (document.getElementById('ctl00_BodyContentPH_grv_Type_cell' + (i + grv_Type.visibleStartIndex) + '_0_chkSelect').checked)
                        varTotalCheckedCount = varTotalCheckedCount + 1;
                }
                if (varTotalCheckedCount == varTotalEnabled)
                    document.getElementById('ctl00_BodyContentPH_grv_Type_header0_chkSelectAll').checked = true;
                else
                    document.getElementById('ctl00_BodyContentPH_grv_Type_header0_chkSelectAll').checked = false;
            }
            else {
                if (Array.contains(removeId, hdnUserId)) {
                    Array.remove(removeId, hdnUserId);
                }
                hdnSelectRow.value = removeId;
                document.getElementById('ctl00_BodyContentPH_grv_Type_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_Type.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>
