<%@ page language="VB" autoeventwireup="false" inherits="Manage_Employees, App_Web_irlhclvs" enableEventValidation="false" %>

<%@ Register TagPrefix="obout" Namespace="Obout.Grid" Assembly="obout_Grid_NET" %>
<%@ Register TagPrefix="obout" Namespace="OboutInc.Flyout2" Assembly="obout_Flyout2_NET" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript">
    // Client-Side Events for Delete
    function OnInsert(record) {
        document.getElementById("<%=Lbl_InvalidError.ClientID %>").innerHTML = record.Error;
    }
    function OnBeforeDelete(record) {
        record.Error = '';
        document.getElementById("<%=Hdn_EmployeeId.ClientID %>").value = record.EmployeeId;
        if (confirm("Are you sure you want to delete? "))
            return true;
        else
            return false;
    }

    function OnDelete(record) {
        alert(record.Error);
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <link href="../StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body onload="chk_ExpiryRule_CheckedChange();">
    <form id="form1" runat="server">
    <table cellpadding="0" cellspacing="0" style="border-right: gray 1px solid; border-top: gray 1px solid;
        border-left: gray 1px solid; border-bottom: gray 1px solid;">
        <tr style="font-weight: bold; font-size: 14px; background-color: lightsteelblue;
            padding-left: 5px; padding-top: 3px; padding-bottom: 3px; color: white;">
            <td style="font-weight: bold; font-size: 14px; background-color: lightsteelblue;
                padding: 5px; color: white;">
                Employees List
            </td>
            <td align="right">
                <asp:Label ID="lblError" runat="server" Width="300px" ForeColor="Red"></asp:Label>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <obout:Grid ID="Dg_Employee" runat="server" ShowLoadingMessage="true" EnableRecordHover="true"
                    AllowFiltering="true" CallbackMode="true" Serialize="false" KeepSelectedRecords="true"
                    AutoGenerateColumns="false" AllowAddingRecords="true" FolderStyle="~/styles/grid/styles/premiere_blue"
                    Width="907px" OnInsertCommand="InsertRecord" OnDeleteCommand="DeleteRecord">
                    <ClientSideEvents OnClientInsert="OnInsert" OnBeforeClientDelete="OnBeforeDelete"
                        OnClientDelete="OnDelete" />
                    <TemplateSettings NewRecord_TemplateId="tplAddBtn" />
                    <Columns>
                        <obout:Column ID="Id" DataField="EmployeeId" Visible="False" Width="100" ReadOnly="True"
                            HeaderText="EmployeeId" ConvertEmptyStringToNull="False" Index="0" />
                        <obout:Column ID="EmployeeCode" DataField="EmployeeCode" Width="300" HeaderText="EmployeeCode"
                            ConvertEmptyStringToNull="False" Index="1" />
                        <obout:Column ID="EmployeeName" DataField="EmployeeName" Width="300" HeaderText="EmployeeName"
                            ConvertEmptyStringToNull="False" Index="2" />
                        <obout:Column ID="C5" DataField="EmployeeCodeInDevice" Width="200" HeaderText="Employee Device Code"
                            ConvertEmptyStringToNull="False" Index="3">
                        </obout:Column>
                        <obout:Column ConvertEmptyStringToNull="False" DataField="EmployeeRFIDNumber" HeaderText="Card Number"
                            Index="4">
                        </obout:Column>
                        <obout:Column HeaderText="Edit" Width="70" AllowEdit="True" AllowDelete="True" ConvertEmptyStringToNull="False"
                            Index="5" TemplateId="tplEditBtn">
                            <TemplateSettings TemplateId="tplEditBtn" />
                        </obout:Column>
                        <obout:Column HeaderText="Delete" Width="60" AllowDelete="True" ConvertEmptyStringToNull="False"
                            Index="6" />
                        <obout:Column ID="Column40" DataField="BIOPhoto1" Visible="false" Width="120" Index="7"
                            runat="server" />
                        <obout:Column ID="Column41" DataField="BIOPhoto2" Visible="false" Width="120" Index="8"
                            runat="server" />
                        <obout:Column Width="90" HeaderText="Register" AllowEdit="false" AllowDelete="false"
                            Visible="true" Index="9">
                            <TemplateSettings TemplateId="tplFPRegisterBtn" />
                        </obout:Column>
                        <obout:Column ID="Column13" DataField="DeviceExpiryRule" Visible="false" Width="120"
                            HeaderText="DeviceExpiryRule" runat="server" Index="10" />
                        <obout:Column ID="Column14" DataFormatString="{0:dd MMM yyyy}" DataField="DeviceExpiryStartDate"
                            Visible="false" Width="120" HeaderText="DeviceExpiryStartDate" runat="server"
                            Index="11" />
                        <obout:Column ID="Column18" DataFormatString="{0:dd MMM yyyy}" DataField="DeviceExpiryEndDate"
                            Visible="false" Width="120" HeaderText="DeviceExpiryEndDate" runat="server" Index="12" />
                        <obout:Column ID="Column8" Visible="false" Width="120" runat="server" Index="13">
                            <TemplateSettings TemplateId="TP_ExpiryStartDateFormat" />
                        </obout:Column>
                        <obout:Column ID="Column1" Visible="false" Width="120" runat="server" Index="14">
                            <TemplateSettings TemplateId="TP_ExpiryEndDateFormat" />
                        </obout:Column>
                    </Columns>
                    <Templates>
                        <obout:GridTemplate runat="server" ID="tplEditBtn" ControlID="" ControlPropertyName="">
                            <Template>
                                <a href="javascript: //" id="grid_link_<%# Container.PageRecordIndex %>" onclick="attachFlyoutToLink(this,'Update')"
                                    class="ob_gAL">Edit</a>
                            </Template>
                        </obout:GridTemplate>
                        <obout:GridTemplate runat="server" ID="tplAddBtn" ControlID="" ControlPropertyName="">
                            <Template>
                                <a href="javascript: //" id="btAdd" onclick="attachFlyoutToLink(this,'Add')" class="ob_gAL">
                                    <%#CheckPermissions("Add")%>
                                </a>
                            </Template>
                        </obout:GridTemplate>
                        <obout:GridTemplate runat="server" ID="tplFPRegisterBtn">
                            <Template>
                                <asp:HyperLink runat="server" CssClass="ob_gAL" Text="Finger" NavigateUrl='<%# "~/manage/RegisterEmployeeFinger.aspx?EmployeeId=" + GetDataItemValue("EmployeeId", Container)+"&EmployeeName="+GetDataItemValue("EmployeeName", Container)%>'
                                    ID="AA1" />
                            </Template>
                        </obout:GridTemplate>
                        <obout:GridTemplate runat="server" ID="TP_ExpiryStartDateFormat">
                            <Template>
                                <%#ParseDateTime(Container.DataItem.Item("DeviceExpiryStartDate"))%>
                            </Template>
                        </obout:GridTemplate>
                        <obout:GridTemplate runat="server" ID="TP_ExpiryEndDateFormat">
                            <Template>
                                <%#ParseDateTime(Container.DataItem.Item("DeviceExpiryEndDate"))%>
                            </Template>
                        </obout:GridTemplate>
                    </Templates>
                </obout:Grid>
            </td>
        </tr>
    </table>
    <obout:Flyout runat="server" ID="Flyout1" Align="left" Position="BOTTOM_LefT" CloseEvent="NONE"
        OpenEvent="NONE" DelayTime="500">
        <table class="rowEditTable">
            <tr>
                <td>
                    <fieldset>
                        <legend>Employee Details</legend>
                        <table>
                            <tr>
                                <td align="right" style="font-weight: bold;">
                                    Employee Name
                                </td>
                                <td>
                                    <asp:TextBox ID="txt_employeeName" runat="server" CssClass="WebControls" Width="175px"></asp:TextBox>
                                </td>
                                <td align="right" style="font-weight: bold;">
                                    Employee Code
                                </td>
                                <td>
                                    <asp:TextBox ID="txt_Employeecode" runat="server" CssClass="WebControls" Width="175px"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td align="right" style="font-weight: bold;">
                                    Device Code
                                </td>
                                <td>
                                    <asp:TextBox ID="txt_DeviceCode" runat="server" CssClass="WebControls" Width="175px"></asp:TextBox>
                                </td>
                                <td align="right" style="font-weight: bold;">
                                    Card Number
                                </td>
                                <td>
                                    <asp:TextBox ID="txt_CardNumber" runat="server" CssClass="WebControls" Width="175px"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td align="right" style="font-weight: bold;">
                                    Emp.Device Password
                                </td>
                                <td>
                                    <asp:TextBox ID="txt_EmpDevicePassword" TextMode="Password" runat="server" CssClass="WebControls" Width="175px"></asp:TextBox>
                                </td>
                                <td align="right" style="font-weight: bold;">
                                </td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td align="right" style="font-weight: bold;">
                                </td>
                                <td colspan="3" align="left" style="font-weight: bold;">
                                    <asp:CheckBox ID="chk_DeviceExpiryRule" Text="Is Device Expiry Rule Applicable" runat="server" onclick="chk_ExpiryRule_CheckedChange();"/>
                                </td>
                            </tr>
                            <tr>
                                <td align="right" style="font-weight: bold;">
                                    Expiry Start Date
                                </td>
                                <td>
                                    <select id="drp_Startday" class="WebControls" runat="server" width="46px">
                                    </select>
                                    &nbsp;&nbsp;<select id="drp_Startmonth" class="WebControls" runat="server" enableviewstate="true"
                                        width="48px">
                                    </select>&nbsp;&nbsp;<select id="drp_StartYear" class="WebControls" runat="server"
                                        enableviewstate="true" width="69px">
                                    </select>
                                </td>
                                <td align="right" style="font-weight: bold;">
                                    Expiry End Date
                                </td>
                                <td>
                                    <select id="drp_Endday" class="WebControls" runat="server" width="46px">
                                    </select>
                                    &nbsp;&nbsp;<select id="drp_EndMonth" class="WebControls" runat="server" enableviewstate="true"
                                        width="48px">
                                    </select>&nbsp;&nbsp;<select id="drp_EndYear" class="WebControls" runat="server"
                                        enableviewstate="true" width="69px">
                                    </select>
                                </td>
                            </tr>
                            <tr runat="server" id="tdBioPic">
                                <td align="right" style="font-weight: bold;">
                                    User&nbsp;Pic&nbsp;
                                </td>
                                <td colspan="3" align="left">
                                    <img id="imgPic" />
                                </td>
                            </tr>
                            <tr>
                                <td align="right" colspan="2">
                                    <input id="btn_Save" type="button" value="Save" onclick="javascript:btn_Save_onclick();" />&nbsp;&nbsp;<input
                                        id="btn_Cancel" type="button" value="Close" onclick="javascript:closeFlyout_Details();" />
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:HiddenField ID="Hdn_EmployeeId" runat="server" />
                                    <asp:Label runat="server" ForeColor="red" EnableViewState="false" Text="&nbsp;&nbsp;&nbsp;&nbsp;"
                                        ID="Lbl_InvalidError"></asp:Label>
                                </td>
                            </tr>
                        </table>
                    </fieldset>
                </td>
            </tr>
        </table>
    </obout:Flyout>
    </form>
    <script runat="server">
        Function CheckPermissions(ByVal Action As String) As String
            If Not Session.Item("LoginUser") Is Nothing Then
            
                If CType(Session("LoginUser"), eBioServerLibrary.Data.Admin.User).PermissionNameList.Contains("DeviceManagement") Then
                    Return Action
                End If
                Return ""
            End If
        End Function
        
        Function GetDataItemValue(ByVal fieldname As String, ByVal Container As Obout.Grid.TemplateContainer) As String
            If Container.DataItem(fieldname) Is Nothing Then
                Return Container.DataItem(fieldname.ToUpper)
            End If
            Return Container.DataItem(fieldname)
        End Function
        
        Function ParseDateTime(ByVal DateValue As String) As String
            Try
                Return CDate(DateValue).ToString("yyyy-MM-dd")
            Catch ex As Exception
                Return ""
            End Try
            
        End Function
        
    </script>
    <script type="text/javascript">
		        
 	            function attachFlyoutToLink(oLink,Action)
		        {	
	                <%=Flyout1.getClientID()%>.AttachTo(oLink.id);		            		            
	                <%=Flyout1.getClientID()%>.Open();
	                clearFlyout_Details();
	                if(Action=='Update')
	                {
	                    populateEditControls(oLink.id.toString().replace("grid_link_", ""));
	                }
                    else
                    {
                        var img = document.getElementById('imgPic');
                        document.getElementById("<%=tdBioPic.ClientID %>").style.visibility='hidden';
                        img.src="";
                        img.style.visibility = 'hidden';
                    }
		        }
		        function closeFlyout_Details() 
		    {
		        <%=Flyout1.getClientID()%>.Close();
		    }
		    
		    
		     function btn_Save_onclick()
		     {
		        var oRecord = new Object();
		        oRecord.EmployeeId =document.getElementById("<%=Hdn_EmployeeId.ClientID %>").value ;
		        oRecord.Error='';
		        
		        Dg_Employee.executeInsert(oRecord);
		    }
		    
		     function clearFlyout_Details() 
            {
                document.getElementById("<%=Hdn_EmployeeId.ClientID %>").value = '0';
		        document.getElementById("<%=txt_Employeecode.ClientID %>").value = '';
		        document.getElementById("<%=txt_employeeName.ClientID %>").value = '';
		        document.getElementById("<%=txt_DeviceCode.ClientID %>").value = '';
		        document.getElementById("<%=txt_CardNumber.ClientID %>").value = '';
                document.getElementById("<%=txt_EmpDevicePassword.ClientID %>").value = '';
		        document.getElementById("<%=Lbl_InvalidError.ClientID %>").innerHTML='';
                var img = document.getElementById('imgPic');
                img.src="#";

                document.getElementById("<%=chk_DeviceExpiryRule.ClientID%>").checked=false;
                var now=new Date();
                var NowDay=now.getDate();
		        var NowMonth=now.getMonth()+1;
		    
		        var NowYear=now.getFullYear();
		        var value='2000'+'-'+'01' + "-" + '01';
                var value1='2025'+'-'+'01' + "-" + '01';
                SetValueInDropDown(document.getElementById("<%=drp_Startday.ClientID%>"),document.getElementById("<%=drp_Startmonth.ClientID%>"),document.getElementById("<%=drp_StartYear.ClientID%>"),value); 
                SetValueInDropDown(document.getElementById("<%=drp_Endday.ClientID%>"),document.getElementById("<%=drp_EndMonth.ClientID%>"),document.getElementById("<%=drp_EndYear.ClientID%>"),value1); 

		    }

            function chk_ExpiryRule_CheckedChange()
		    {
		        var Sender=document.getElementById("<%=chk_DeviceExpiryRule.ClientID%>");
		        if(Sender.checked)
		            {
		                document.getElementById("<%=drp_Startday.ClientID%>").disabled = false;
                        document.getElementById("<%=drp_Startmonth.ClientID%>").disabled = false;
                        document.getElementById("<%=drp_StartYear.ClientID%>").disabled = false;
                        document.getElementById("<%=drp_Endday.ClientID%>").disabled = false;
                        document.getElementById("<%=drp_EndMonth.ClientID%>").disabled = false;
                        document.getElementById("<%=drp_EndYear.ClientID%>").disabled = false;
		            }
		        else
		            {
		                  document.getElementById("<%=drp_Startday.ClientID%>").disabled = true;
                          document.getElementById("<%=drp_Startmonth.ClientID%>").disabled = true;
                          document.getElementById("<%=drp_StartYear.ClientID%>").disabled = true;
                          document.getElementById("<%=drp_Endday.ClientID%>").disabled = true;
                          document.getElementById("<%=drp_EndMonth.ClientID%>").disabled = true;
                          document.getElementById("<%=drp_EndYear.ClientID%>").disabled = true;
		            }    
		    }

         
		    
		     function populateEditControls(iRecordIndex) 
		    {	
		        document.getElementById("<%=Hdn_EmployeeId.ClientID %>").value = Dg_Employee.Rows[iRecordIndex].Cells[0].Value;
		        document.getElementById("<%=txt_Employeecode.ClientID %>").value = Dg_Employee.Rows[iRecordIndex].Cells[1].Value;
		        document.getElementById("<%=txt_employeeName.ClientID %>").value = Dg_Employee.Rows[iRecordIndex].Cells[2].Value;
		        document.getElementById("<%=txt_DeviceCode.ClientID %>").value = Dg_Employee.Rows[iRecordIndex].Cells[3].Value;
		        document.getElementById("<%=txt_CardNumber.ClientID %>").value = Dg_Employee.Rows[iRecordIndex].Cells[4].Value;
                                
                var BioPicTemp1=Dg_Employee.Rows[iRecordIndex].Cells[7].Value.trim();
                var BioPicTemp2=Dg_Employee.Rows[iRecordIndex].Cells[8].Value.trim();    
                  
                var BioPicTemp="";

                if (BioPicTemp1 =="")
                {
                        BioPicTemp=BioPicTemp2;

                        var img = document.getElementById('imgPic');

                        if(BioPicTemp=="")
                        {
                            document.getElementById("<%=tdBioPic.ClientID %>").style.visibility='hidden';
                            img.src="";
                            img.style.visibility = 'hidden';
                        }
                        else
                        {    
                            document.getElementById("<%=tdBioPic.ClientID %>").style.visibility= 'visible';
                            img.style.visibility = 'visible';     
                            img.src = "data:image/jpeg;base64," + BioPicTemp;
                        }

                }
                else
                {
                        BioPicTemp = BioPicTemp1;

                        var img = document.getElementById('imgPic');

                        if(BioPicTemp=="")
                        {
                          document.getElementById("<%=tdBioPic.ClientID %>").style.visibility='hidden';
                          img.src="";
                          img.style.visibility = 'hidden';
                        }
                        else
                        {    
                          document.getElementById("<%=tdBioPic.ClientID %>").style.visibility= 'visible';
                          img.style.visibility = 'visible';     
                          img.src = "data:image/jpeg;base64," + BioPicTemp;
                        }
                }


                var ExpiryValue= Dg_Employee.Rows[iRecordIndex].Cells[10].Value;
                if (ExpiryValue=="1")
                {

                 document.getElementById("<%=chk_DeviceExpiryRule.ClientID%>").checked=true;
                 chk_ExpiryRule_CheckedChange();

                 SetValueInDropDown(document.getElementById("<%=drp_Startday.ClientID%>"),document.getElementById("<%=drp_Startmonth.ClientID%>"),document.getElementById("<%=drp_StartYear.ClientID%>"),Dg_Employee.Rows[iRecordIndex].Cells[13].Value); 
                 SetValueInDropDown(document.getElementById("<%=drp_Endday.ClientID%>"),document.getElementById("<%=drp_EndMonth.ClientID%>"),document.getElementById("<%=drp_EndYear.ClientID%>"),Dg_Employee.Rows[iRecordIndex].Cells[14].Value); 
                }
                else
                {
                  document.getElementById("<%=chk_DeviceExpiryRule.ClientID%>").checked=false;
                  chk_ExpiryRule_CheckedChange();
                }


		   }


            function SetValueInDropDown(ddobject,mmobject,yyobject,value)
		    {
                var Day=value.split('-')[2].replace(/^\s+|\s+$/g,"");
	            var Month=value.split('-')[1].replace(/^\s+|\s+$/g,"");
	            
	            if(Month.length <2)
	            {
	              Month="0" + Month;
	            }
	            var Year=value.split('-')[0].replace(/^\s+|\s+$/g,"");
		        
                ddobject.value=Day;
                mmobject.value=Month;
                yyobject.value=Year;
		    }

		    
		   
    </script>
</body>
</html>
