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

<%@ Register TagPrefix="dxGridview" Assembly="DevExpress.Web.v14.2" Namespace="DevExpress.Web" %>
<%@ Register Assembly="DevExpress.Web.v14.2" Namespace="DevExpress.Web"
    TagPrefix="devxEditors" %>
<asp:Content ContentPlaceHolderID="BodyContentPH" ID="conHoliday" runat="server">
    <div class="content-header">
        <h1 style="background-image: url('../dist/img/holiday.png'); background-repeat: no-repeat; padding-left: 35px">
            <asp:Label ID="lbl_HeaderHolidays" runat="server"></asp:Label>
        </h1>
        <asp:SiteMapPath ID="site" runat="server" CssClass="breadcrumb">
            <NodeStyle CssClass="active" />
        </asp:SiteMapPath>
    </div>
    <div class="content">
        <div class="border-table new-space" style="margin-top: 0px;">
            <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_Holiday" EnableCallBacks="false" ClientInstanceName="grv_Holiday"
                            runat="server" AutoGenerateColumns="false" KeyFieldName="Holiday_Id" DataSourceID="objEvent"
                            OnHtmlRowCreated="grv_Holiday_HtmlRowCreated">
                            <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)"
                                            accesskey='<%# Eval("Holiday_Id") %>' />
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="Holiday_Id" Visible="false">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblHId" runat="server" Text=' <%# Eval("Holiday_Id")%>'></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="Holiday_Description" Caption="Holiday Description"
                                    Width="300px" VisibleIndex="1">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblHdescription" runat="server" Text=' <%# Eval("Holiday_Description")%>'
                                            CssClass="dxlabel">
                                        </asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn Caption="Holiday Date" FieldName="HolidayDate"
                                    Width="150px" VisibleIndex="2">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblHType" Text='<%# Eval("HolidayDate") %>' runat="server"></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>                                
                                <dxGridview:GridViewDataTextColumn FieldName="Htype" Caption="Holiday Type" VisibleIndex="3"
                                    Width="120px">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblHType1" runat="server" Text=' <%# Eval("Htype")%>' CssClass="dxlabel"></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="Holiday_FromDate" Caption="Holiday FromDate"
                                    VisibleIndex="5" Visible="false">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblHolidayFromDate" runat="server" Text=' <%# Eval("Holiday_ToDate")%>'
                                            CssClass="dxlabel">
                                        </asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="Holiday_ToDate" Caption="Holiday ToDate"
                                    VisibleIndex="6" Visible="false">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblHolidayToDate" runat="server" Text=' <%# Eval("Holiday_ToDate")%>'>
                                        </asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" />
                                </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("Holiday_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="30px">
                                    <Settings AllowAutoFilter="false" />
                                    <DataItemTemplate>
                                        <asp:LinkButton ID="btnDelete" runat="server" ToolTip='<%# Session["Delete"] %>' data-toggle="tooltip"
                                            OnClick="btn_delete_Click_1" CommandName='<%# Eval("Holiday_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">
                            </SettingsPager>
                            <Settings ShowFilterRow="true" />
                            <SettingsBehavior SortMode="Value" AllowSort="true" AllowDragDrop="false" />
                            <Styles AlternatingRow-CssClass="table-bg">
                            </Styles>
                        </dxGridview:ASPxGridView>
                        <dxGridview:ASPxGridViewExporter ID="ASPxGridViewExporter1" runat="server" GridViewID="grv_EmpDetails">
                            <PageFooter Right="[Page # of Pages #]">
                            </PageFooter>
                        </dxGridview:ASPxGridViewExporter>
                        <asp:ObjectDataSource ID="objEvent" runat="server" SelectMethod="SelectHolidayDetails"
                            TypeName="HolidayEventData">
                            <SelectParameters>
                                <asp:SessionParameter Name="UserGroupName" SessionField="UserGroupName" Type="string" />
                                <asp:SessionParameter Name="YearsettingsId" SessionField="YearsettingsId" 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 btn-primary fa fa-trash-o" runat="server"
                                CausesValidation="False" OnClick="btn_Delete_Click" OnClientClick="return confirmdelete(this.form);" />

                            <asp:LinkButton 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" />
                            <asp:LinkButton ID="btnExport" CommandName="excel" runat="server" CssClass="btn del-btn fa-file-excel-o" OnClick="btnExport_Click">
                            </asp:LinkButton>
                            <asp:LinkButton ID="btnExportPdf" CommandName="pdf" runat="server" CssClass="btn del-btn fa-file-pdf-o" OnClick="btnExport_Click">
                            </asp:LinkButton>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" language="javascript">
        function Delete_Conf() {
            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_Holiday.pageRowCount; i++) {
                    if (document.getElementById('ctl00_BodyContentPH_grv_Holiday_cell' + (i + grv_Holiday.visibleStartIndex) + '_0_chkSelect').disabled == false) {
                        document.getElementById('ctl00_BodyContentPH_grv_Holiday_cell' + (i + grv_Holiday.visibleStartIndex) + '_0_chkSelect').checked = true;
                        var hdnUserId = document.getElementById('ctl00_BodyContentPH_grv_Holiday_cell' + (i + grv_Holiday.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_Holiday.pageRowCount; i++) {
                    document.getElementById('ctl00_BodyContentPH_grv_Holiday_cell' + (i + grv_Holiday.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_Holiday.pageRowCount; i++) {
                    if (document.getElementById('ctl00_BodyContentPH_grv_Holiday_cell' + (i + grv_Holiday.visibleStartIndex) + '_0_chkSelect').disabled == false) {
                        varTotalEnabled = varTotalEnabled + 1
                    }
                    if (document.getElementById('ctl00_BodyContentPH_grv_Holiday_cell' + (i + grv_Holiday.visibleStartIndex) + '_0_chkSelect').checked)
                        varTotalCheckedCount = varTotalCheckedCount + 1;
                }
                if (varTotalCheckedCount == varTotalEnabled)
                    document.getElementById('ctl00_BodyContentPH_grv_Holiday_header0_chkSelectAll').checked = true;
                else
                    document.getElementById('ctl00_BodyContentPH_grv_Holiday_header0_chkSelectAll').checked = false;
            }
            else {
                if (Array.contains(removeId, hdnUserId)) {
                    Array.remove(removeId, hdnUserId);
                }
                hdnSelectRow.value = removeId;
                document.getElementById('ctl00_BodyContentPH_grv_Holiday_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 ";
        var AreyousuretoDelete = "Are you sure to Delete";
        function RestoreAlert(norecordsavailable, areyousuretoRestore, selecteddataisnotindeletedstatus, selectdatatorestore, nodeletedrecordsavailable, areyousuretoDelete) {
            Norecordsavailable = norecordsavailable;
            AreyousuretoRestore = areyousuretoRestore;
            Selecteddataisnotindeletedstatus = selecteddataisnotindeletedstatus;
            Selectdatatorestore = selectdatatorestore;
            Nodeletedrecordsavailable = nodeletedrecordsavailable;
            AreyousuretoDelete = areyousuretoDelete;
        }
        function Delete_Conf() {
            return confirm(AreyousuretoDelete);
        }
        function RestoreData() {
            var rowscount = grv_Holiday.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>
