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

<%@ Register TagPrefix="dxGridview" Namespace="DevExpress.Web" Assembly="DevExpress.Web.v14.2" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="conPermission" runat="Server" ContentPlaceHolderID="BodyContentPH">
    <div class="content-header">
        <h1 style="background-image: url('../dist/img/permission.png'); background-repeat: no-repeat; padding-left: 35px">
            <asp:Label ID="lbl_Header" runat="server"></asp:Label>
        </h1>
        <asp:SiteMapPath ID="site" runat="server" CssClass="breadcrumb">
            <NodeStyle CssClass="active" />
        </asp:SiteMapPath>
    </div>

    <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>

        $(function () {
            $('#ctl00_BodyContentPH_txtPermissionStartDate').datetimepicker({ format: document.getElementById('ctl00_BodyContentPH_Hidden1').value }
            );
        });
        $(function () {
            $('#ctl00_BodyContentPH_txtPermissionEndDate').datetimepicker({ format: document.getElementById('ctl00_BodyContentPH_Hidden1').value }
            );
        });
    </script>

    <script type="text/javascript">

        //values for check date
        //Commented and changing alert message as per discussed with testing team. Bug :  	0021456 TimeCheckV1.4
        //var Monthfourdigit='Please enter valid date as month, day, and four digit year : Format MM/dd/yyyy.';
        var Monthfourdigit = 'Please enter valid date with correct format MM/dd/yyyy';
        //Adding this line var Datefourdigit='Please enter valid date with correct format dd/MM/yyyy'; as newly
        var Datefourdigit = 'Please enter valid date with correct format dd/MM/yyyy';
        var Invalidyearentry = 'Invalid year entry';
        var Invalidmonthentry = 'Invalid month entry';
        var Invaliddateentry = 'Invalid date entry';
        //var DateformatDDMONYYYY='Incorrect date format. Enter as DD-MON-YYYY';
        var DateformatDDMONYYYY = 'Please enter valid date with correct format dd-MMM-yyyy';
        var Entertime = 'Enter time';
        var Valueforhours = 'Invalid value for hours:';
        var Invalidvalueforminutes = 'Invalid value for minutes:';
        var Invalidtimeformat = 'Invalid time format:';
        var EntervalidDateandTime = 'Please enter valid Date and Time';
        var ValiddatemonthMMDDYYHHMM = 'Please enter valid Date and Time MM/dd/yyyy HH:mm';
        var ValiddatemonthMMDDYYHHMMTT = 'Please enter valid Date and Time MM/dd/yyyy hh:mm tt';
        var EntervalidDateandTime = 'Please enter valid Date and Time';
        var Invalidvalueforhours = 'Invalid value for hours:';
        var Invalidvalueforminites = 'Invalid value for minutes:';
        var MaxLength = "Maximum length is ";


        function MaxLengthh(maxLength) {
            MaxLength = maxLength;
        }


        function SetAlertCheckDate(monthfourdigit, datefourdigit, invalidyearentry, invalidmonthentry, invaliddateentry, dateformatDDMONYYYY, entertime, valueforhours, invalidvalueforminutes, invalidtimeformat, entervalidDateandTime, validdatemonthMMDDYYHHMM, validdatemonthMMDDYYHHMMTT, entervalidDateandTime, invalidvalueforhours, invalidvalueforminites) {
            Monthfourdigit = monthfourdigit;
            Datefourdigit = datefourdigit;
            Invalidyearentry = invalidyearentry;
            Invalidmonthentry = invalidmonthentry;
            Invaliddateentry = invaliddateentry;
            DateformatDDMONYYYY = dateformatDDMONYYYY;
            Entertime = Entertime;
            Valueforhours = valueforhours;
            Invalidvalueforminutes = invalidvalueforminutes;
            Invalidtimeformat = invalidtimeformat;
            EntervalidDateandTime = entervalidDateandTime;
            ValiddatemonthMMDDYYHHMM = validdatemonthMMDDYYHHMM;
            ValiddatemonthMMDDYYHHMMTT = validdatemonthMMDDYYHHMMTT;
            EntervalidDateandTime = entervalidDateandTime;
            Invalidvalueforhours = invalidvalueforhours;
            Invalidvalueforminites = invalidvalueforminites;
        }
        var EnterDetails = "Please enter any of the above details";
        var FillFromandToDate = "Please enter both the From and To Date";

        function SetAlertMessages(FillDetails, fillFromToDate) {
            EnterDetails = FillDetails;
            FillFromandToDate = fillFromToDate;
        }

        function WeekdayValidation() {
            var EmpId = document.getElementById('ctl00_BodyContentPH_txtEmployeeId');
            var EmpName = document.getElementById('ctl00_BodyContentPH_txt_EmpName');
            //var weekDay=document.getElementById('ctl00_BodyContentPH_txtPermissionStartDate');
            var DateFormat = document.getElementById('ctl00_BodyContentPH_Hidden1').value;
            var weekDay = document.aspnetForm.ctl00_BodyContentPH_txtPermissionStartDate;
            var weekDay2 = document.aspnetForm.ctl00_BodyContentPH_txtPermissionEndDate;
            swipCard = document.getElementById('ctl00_BodyContentPH_txtSwipeCard');



            if (EmpName == null && EmpId == null && swipCard == null && weekDay.value == '' && weekDay2.value == '') {
                alert(EnterDetails);
                return false;
            }
            else if ((weekDay.value == '' && weekDay2.value != '') || (weekDay.value != '' && weekDay2.value == '')) {
                alert(FillFromandToDate);
                return false;
            }
            else {
                // Nothing
            }

            if (weekDay.value != '') {
                if (checkDate(weekDay, DateFormat, Monthfourdigit, Datefourdigit, Invalidyearentry, Invalidmonthentry, Invaliddateentry, DateformatDDMONYYYY, Entertime, Valueforhours, Invalidvalueforminutes, Invalidtimeformat, EntervalidDateandTime, ValiddatemonthMMDDYYHHMM, ValiddatemonthMMDDYYHHMMTT, EntervalidDateandTime, Invalidvalueforhours, Invalidvalueforminites)) {
                    if (weekDay2.value != '') {
                        if (checkDate(weekDay2, DateFormat, Monthfourdigit, Datefourdigit, Invalidyearentry, Invalidmonthentry, Invaliddateentry, DateformatDDMONYYYY, Entertime, Valueforhours, Invalidvalueforminutes, Invalidtimeformat, EntervalidDateandTime, ValiddatemonthMMDDYYHHMM, ValiddatemonthMMDDYYHHMMTT, EntervalidDateandTime, Invalidvalueforhours, Invalidvalueforminites)) {

                        }
                        else {
                            return false;
                        }
                    }
                    else {
                        document.getElementById('ctl00_BodyContentPH_txtPermissionEndDate').focus();
                        return false;
                    }
                }
                else {
                    return false;
                }
            }
        }
    </script>

    <div class="content">
        <!--FILTERS-->
        <div class="inr-ftr">
            <div class="row">
                <div class="col-md-2">
                    <div class="inr-fil-text">
                        <asp:Label ID="lblFilter" runat="server" Text="Filter"></asp:Label>
                    </div>
                </div>

            </div>
        </div>
        <!--FILTERS-->
        <div class="emp-filter">
            <div class="row">
                <div class="form-horizontal">
                    <asp:HiddenField ID="HiddenField1" runat="server" />
                    <asp:HiddenField ID="Hidden1" runat="server" />
                    <div class="col-md-12">
                        <%--Add Search text box and other search control here--%>
                        <div class="row form-group" id="trSwipeCardNo" runat="server" style="display: none;">
                            <div class="col-md-2">
                                <asp:Label ID="lblEmpSwipe" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-3">
                                <asp:TextBox onpaste="return true" ID="txtSwipeCard" MaxLength="20" runat="server"
                                    CssClass="form-control" onkeypress="return acceptCharsNum_MaxLength(event,this,20,MaxLength);"></asp:TextBox>
                                <cc1:AutoCompleteExtender ID="acSwipeCardNo" runat="server" CompletionSetCount="10"
                                    CompletionListItemCssClass="item" CompletionListHighlightedItemCssClass="AutocompleteCSS"
                                    CompletionInterval="10" Enabled="true" MinimumPrefixLength="1" TargetControlID="txtSwipeCard"
                                    ServicePath="../WebServices/AutoCompleteExtender.asmx" ServiceMethod="GetCardNo"
                                    CompletionListCssClass="autocomplete_completionListElement" FirstRowSelected="true">
                                </cc1:AutoCompleteExtender>
                            </div>
                        </div>
                        <div class="row form-group" id="trEmployeeDetails" runat="server">
                            <div class="col-md-2 col-sm-2">
                                <asp:Label ID="lbl_EmployeeName" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-3 col-sm-3">
                                <asp:TextBox onpaste="return true" ID="txt_EmpName" runat="server" CssClass="form-control"
                                    MaxLength="50" onkeypress="return employeename_singlequotes_maxlength(event,this,50,MaxLength);"></asp:TextBox>
                                <cc1:AutoCompleteExtender ID="acEmpName" runat="server" CompletionInterval="10" CompletionSetCount="10"
                                    CompletionListItemCssClass="item" CompletionListHighlightedItemCssClass="AutocompleteCSS"
                                    Enabled="true" FirstRowSelected="true" MinimumPrefixLength="1" ServicePath="../WebServices/AutoCompleteExtender.asmx"
                                    ServiceMethod="GetEmployeeName" CompletionListCssClass="autocomplete_completionListElement"
                                    TargetControlID="txt_EmpName">
                                </cc1:AutoCompleteExtender>
                            </div>
                            <div class="col-md-1 col-sm-0">
                            </div>
                            <div class="col-md-2 col-sm-2">
                                <asp:Label ID="lbl_EmployeeId" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-3 col-sm-3">
                                <asp:TextBox onpaste="return true" ID="txtEmployeeId" runat="server" CssClass="form-control"
                                    MaxLength="15" onkeypress="return acceptCharsNum_MaxLength(event,this,15,MaxLength);"></asp:TextBox>
                                <cc1:AutoCompleteExtender ID="acEmployeeId" runat="server" CompletionSetCount="10"
                                    CompletionListItemCssClass="item" CompletionListHighlightedItemCssClass="AutocompleteCSS"
                                    CompletionInterval="10" Enabled="true" MinimumPrefixLength="1" TargetControlID="txtEmployeeId"
                                    ServicePath="../WebServices/AutoCompleteExtender.asmx" ServiceMethod="GetEmployeeId"
                                    CompletionListCssClass="autocomplete_completionListElement" FirstRowSelected="true">
                                </cc1:AutoCompleteExtender>
                            </div>
                        </div>
                        <div class="row  form-group">
                            <div class="col-md-2 col-sm-2">
                                <asp:Label ID="lblTimePeriod" runat="server"></asp:Label>
                                <asp:Label ID="lblPermissionStartDate" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-3 col-sm-3">
                                <asp:TextBox onpaste="return true" ID="txtPermissionStartDate" runat="server" CssClass="form-control"
                                    EnableViewState="False" onCut="return false" onDrop="return false"></asp:TextBox>
                            </div>
                            <div class="col-md-1 col-sm-0">
                            </div>
                            <div class="col-md-2 col-sm-2">
                                <asp:Label ID="lblPermissionEndDate" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-3 col-sm-3">
                                <asp:TextBox onpaste="return true" ID="txtPermissionEndDate" runat="server" CssClass="form-control"
                                    EnableViewState="False" onCut="return false" onDrop="return false"></asp:TextBox>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-5 col-sm-4">
                            </div>
                            <div class="col-md-6 col-sm-6">
                                <div class="pull-right-button">
                                    <%--Add serach button here--%>
                                    <asp:Label ID="lbl_Error" runat="server" ForeColor="Red"></asp:Label>
                                    <asp:LinkButton ID="btn_Search" CssClass="btn src-btn fa-search" runat="server" OnClick="btn_Search_Click"
                                        OnClientClick="return WeekdayValidation()" />
                                    <asp:LinkButton ID="btn_Clear" CssClass="btn clr-btn fa-refresh" runat="server" OnClick="btn_Clear_Click" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--RES TABLE-->
        <div class="border-table new-space form-group">
            <div class="table-responsive" style="padding-bottom: 10px">
                <%--Grid Add Here--%>
                <asp:HiddenField ID="hdnSelectRow" runat="server" />
                <asp:HiddenField ID="hdnGetAllid" runat="server" />
                <dxGridview:ASPxGridView ID="grv_Permission" runat="server" ClientInstanceName="grv_Permission"
                    KeyFieldName="Permission_Id" OnHtmlRowCreated="grv_Permission_HtmlRowCreated"
                    EnableCallBacks="false" AutoGenerateColumns="false" Width="100%" DataSourceID="ObjectDataSource1">
                    <Columns>
                        <dxGridview:GridViewDataTextColumn FieldName="Permission_Id" VisibleIndex="0" Visible="false">
                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                        </dxGridview:GridViewDataTextColumn>
                        <dxGridview:GridViewDataTextColumn Caption="Application Date" FieldName="Permission_AppliedDate"
                            VisibleIndex="1" Width="105px">
                            <Settings AllowDragDrop="False" />
                            <DataItemTemplate>
                                <asp:Label ID="AppDate" Text='<%# Eval("Permission_AppliedDate") %>' runat="server"></asp:Label>
                            </DataItemTemplate>
                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                        </dxGridview:GridViewDataTextColumn>
                        <dxGridview:GridViewDataTextColumn FieldName="employeeid" VisibleIndex="2" Width="80px">
                            <Settings AllowDragDrop="False" />
                            <DataItemTemplate>
                                <asp:Label Style="overflow-y: auto; overflow-x: auto; word-break: break-all; word-wrap: break-word; display: inline-block;"
                                    ID="lblEmployee_FirstName" Text='<%# Eval("employeeid") %>'
                                    runat="server"></asp:Label>
                            </DataItemTemplate>
                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                        </dxGridview:GridViewDataTextColumn>
                        <dxGridview:GridViewDataTextColumn FieldName="Employee_FirstName" VisibleIndex="3"
                            Width="120px">
                            <Settings AllowDragDrop="False" />
                            <DataItemTemplate>
                                <asp:Label Style="overflow-y: auto; overflow-x: auto; word-break: break-all; word-wrap: break-word; display: inline-block;"
                                    ID="lblEmployee_FirstName" Text='<%# Eval("Employee_FirstName") %>'
                                    runat="server"></asp:Label>
                            </DataItemTemplate>
                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                        </dxGridview:GridViewDataTextColumn>
                        <dxGridview:GridViewDataTextColumn FieldName="name" VisibleIndex="4" Width="120px">
                            <Settings AllowDragDrop="False" />
                            <DataItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("name") %>' Style="overflow-y: auto; overflow-x: auto; word-break: break-all; word-wrap: break-word; display: inline-block;"></asp:Label>
                            </DataItemTemplate>
                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                        </dxGridview:GridViewDataTextColumn>
                        <dxGridview:GridViewDataTextColumn FieldName="Duration" VisibleIndex="5" Width="120px">
                            <Settings AllowAutoFilter="false" AllowDragDrop="false" />
                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                        </dxGridview:GridViewDataTextColumn>
                        <dxGridview:GridViewDataTextColumn FieldName="Permission_Status" VisibleIndex="6"
                            Width="80px">
                            <Settings AllowDragDrop="False" />
                            <DataItemTemplate>
                                <asp:Label ID="lbl_Status" runat="server" Text='<%# Eval("Permission_Status") %>'></asp:Label>
                            </DataItemTemplate>
                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                        </dxGridview:GridViewDataTextColumn>
                        <dxGridview:GridViewDataTextColumn FieldName="Permission_Reason" VisibleIndex="7"
                            Width="100px">
                            <Settings AllowDragDrop="False" />
                            <DataItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("Permission_Reason") %>' Style="overflow-y: auto; overflow-x: auto; word-break: break-all; word-wrap: break-word; display: inline-block;"></asp:Label>
                            </DataItemTemplate>
                            <Settings AllowAutoFilter="false" />
                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                        </dxGridview:GridViewDataTextColumn>
                        <dxGridview:GridViewDataTextColumn FieldName="Remarks" VisibleIndex="8" Width="100px">
                            <Settings AllowDragDrop="False" />
                            <DataItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("Remarks") %>' Style="overflow-y: auto; overflow-x: auto; word-break: break-all;  word-wrap: break-word; display: inline-block;"></asp:Label>
                            </DataItemTemplate>
                            <Settings AllowAutoFilter="false" />
                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                        </dxGridview:GridViewDataTextColumn>
                        <dxGridview:GridViewDataTextColumn FieldName="Permission_FromTime" VisibleIndex="9"
                            Visible="false">
                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                        </dxGridview:GridViewDataTextColumn>
                        <dxGridview:GridViewDataColumn FieldName="Permission_ToTime" VisibleIndex="10" Width="10%"
                            Visible="false">
                        </dxGridview:GridViewDataColumn>
                        <dxGridview:GridViewDataColumn HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center"
                            CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center" Width="40px">
                            <Settings AllowAutoFilter="false" />
                            <DataItemTemplate>
                                <a title="Edit" href='TA_UI_Transactions_LeavePermissionModify.aspx?Permission_Id=<%# Eval("Permission_Id") %>'
                                    data-toggle="tooltip" data-placement="top"><span class="btn btn-defalut edit-icons"
                                        style="color: Green"></span></a>
                            </DataItemTemplate>
                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                        </dxGridview:GridViewDataColumn>
                    </Columns>
                    <SettingsPager PageSize="10">
                    </SettingsPager>
                    <SettingsText EmptyDataRow="No Records Found" />
                    <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="selectPermissionDetails"
                    TypeName="PermissionEventData">
                    <SelectParameters>
                        <asp:SessionParameter Name="Employee_Id" SessionField="EmpAutoId" Type="Int32" />
                        <asp:SessionParameter Name="GradeLevel" SessionField="GradeLevel" Type="String" />
                        <asp:SessionParameter Name="LevelRights" SessionField="LevelRights" Type="String" />
                        <asp:ControlParameter ControlID="txtPermissionStartDate" DefaultValue="01/01/1900"
                            Type="String" Name="PermissionStartDate" />
                        <asp:ControlParameter ControlID="txtPermissionEndDate" DefaultValue="01/01/1900"
                            Type="String" Name="PermissionEndDate" />
                        <asp:SessionParameter Name="UserGroupName" SessionField="UserGroupName" Type="String" />
                        <asp:SessionParameter Name="parentLevelId" SessionField="parentLevelId" Type="Int32" />
                    </SelectParameters>
                </asp:ObjectDataSource>
                <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="selectPermissionDetailsSuperAdmin"
                    TypeName="PermissionEventData">
                    <SelectParameters>
                        <asp:SessionParameter Name="Employee_Id" SessionField="EmpAutoId" Type="Int32" />
                        <asp:SessionParameter Name="UserGroupName" SessionField="UserGroupName" Type="String" />
                        <asp:SessionParameter Name="GradeLevel" SessionField="GradeLevel" Type="String" />
                        <asp:SessionParameter Name="LevelRights" SessionField="LevelRights" Type="String" />
                        <asp:ControlParameter ControlID="txt_EmpName" Type="string" Name="EmpFirstName" PropertyName="Text" />
                        <asp:ControlParameter ControlID="txtEmployeeId" Type="string" Name="EmpCodeId" PropertyName="Text" />
                        <asp:ControlParameter ControlID="txtPermissionStartDate" DefaultValue="01/01/1900"
                            Type="String" Name="PermissionStartDate" />
                        <asp:ControlParameter ControlID="txtPermissionEndDate" DefaultValue="01/01/1900"
                            Type="String" Name="PermissionEndDate" />
                        <asp:ControlParameter ControlID="txtSwipeCard" Type="string" Name="strSwipeCard"
                            PropertyName="Text" />
                        <asp:SessionParameter Name="parentLevelId" Type="Int32" />
                    </SelectParameters>
                </asp:ObjectDataSource>
            </div>
            <div class="clearfix">
            </div>
            <div class="row page-nos">
                <div class="col-md-6 col-sm-6">
                </div>
                <div class="col-md-6 page-button col-sm-6">
                    <asp:LinkButton ID="btn_Add" CssClass="btn add-btn fa-plus" runat="server" OnClick="btn_Add_Click" />
                </div>
            </div>
        </div>
    </div>
</asp:Content>
