<%@ page language="VB" autoeventwireup="false" enableeventvalidation="false" inherits="Manage_EmployeeDeviceLogs, App_Web_sxxm_njl" %>

<%@ Register TagPrefix="obout" Namespace="Obout.Grid" Assembly="obout_Grid_NET" %>
<%@ Register TagPrefix="obout" Namespace="OboutInc.Flyout2" Assembly="obout_Flyout2_NET" %>
<%@ Register TagPrefix="uctrl" Src="~/Header.ascx" TagName="header" %>
<!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 OnBeforeDelete(record) 
	    {
	    if(record.DeviceId>2)
	            {
	              
	                alert("Only Manual Entry can be delete.");
	                return false;
	            }
	            
	            
	            
	        record.Error='';
		    document.getElementById("<%=hdn_EmployeeManulEntryId.ClientID %>").value = record.DeviceLogId;
	        if(confirm("Are you sure you want to delete? "))
	            return true;
	        else
	            return false;
	    }
	
	function OnDelete(record) 
	{
	    alert(record.Error);
	}
	
	function OnInsert(record) 
	{
		document.getElementById("<%=Lbl_InvalidError.ClientID %>").innerHTML = 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>
    <form id="form1" runat="server">
        <div>
            <uctrl:header ID="MyHeader" 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;">
                        Employee Logs Record
                    </td>
                   
                    <td align="right">
                         <input type="button" class="tdText" value="Refresh" onclick="Dg_EmployeeLogRecords.refresh()" id="btn_Refresh" />
                        &nbsp;Device&nbsp;<asp:DropDownList ID="drp_FilterDevice" AutoPostBack="true" runat="server"> </asp:DropDownList>&nbsp;&nbsp;
                    </td>
                </tr>
                 <tr style=" background-color: lightsteelblue;">
                <td colspan="2">
                <hr />
                </td>
                </tr>
                
                <tr>
                    <td colspan="2">
                        <obout:Grid ID="Dg_EmployeeLogRecords" runat="server" ShowLoadingMessage="true" EnableRecordHover="true" KeepSelectedRecords="true"
                            Serialize="false" AutoGenerateColumns="false" FolderStyle="~/styles/grid/styles/premiere_blue"
                            AllowAddingRecords="true"  OnRebind="RebindGrid" OnInsertCommand="InsertRecord"
                            AllowFiltering="true" OnDeleteCommand="DeleteRecord">
                            <ClientSideEvents OnClientInsert="OnInsert" OnBeforeClientDelete="OnBeforeDelete"
                                OnClientDelete="OnDelete" />
                            <TemplateSettings NewRecord_TemplateId="tplAddBtn" />
                            <Columns>
                                <obout:Column ID="Column0" DataField="DeviceLogId" Visible="false" Width="100" HeaderText="DeviceLogId" runat="server" />
                                <obout:Column ID="Column1" SortOrder="Desc"  Visible="true" Width="155" HeaderText="Log Date" runat="server" DataField="LogDate"  DataFormatString="{0:dd-MMM-yyyy HH:mm}"  />
                                <obout:Column ID="Column2" DataField="DeviceSName" Visible="true" Width="100" HeaderText="Device" runat="server" />
                                <obout:Column ID="Column3" DataField="DeviceId" Visible="false" Width="80" HeaderText="DeviceId" runat="server" />
                                <obout:Column ID="Column4" DataField="Direction" Visible="true" Width="95" HeaderText="Direction" runat="server" />
                                <obout:Column ID="Column5" DataField="WorkCode" Visible="true" Width="105" HeaderText="Work Code" runat="server" />
                                <obout:Column ID="Column6" DataField="EmployeeCode" Visible="true" Width="105" HeaderText="Emp Code" runat="server" />
                                <obout:Column ID="Column7" DataField="EmployeeName" Visible="true" Width="130" HeaderText="Emp Name" runat="server" />
                                <obout:Column ID="Column8" DataField="CompanySName" Visible="true" Width="130" HeaderText="Company" runat="server" />
                                <obout:Column ID="Column9" DataField="DepartmentSName" Visible="true" Width="130" HeaderText="Department" runat="server" />
                                <obout:Column ID="Column10" DataField="Designation" Visible="false" Width="100" HeaderText="Designation" runat="server" />
                                <obout:Column ID="Column11" DataField="CategorySName" Visible="false" Width="100"  HeaderText="Category" runat="server" />
                                <obout:Column ID="Column12" DataField="EmployeesStatus" Visible="false" Width="80" HeaderText="Status" runat="server" />
                                <obout:Column ID="Column13" DataField="EmployementType" Visible="false" Width="85" HeaderText="Emp Type" runat="server" />
                                <obout:Column ID="Column14" Visible="false" Width="155" HeaderText="Log Date" runat="server" ><TemplateSettings TemplateId="TP_LogDateFormat" /></obout:Column>
                                <obout:Column Width="65" AllowEdit="false" AllowDelete="false" Visible="true" HeaderText="Edit"><TemplateSettings TemplateId="tplEditActualLeavesBtn" /> </obout:Column>
                                <obout:Column Width="70" AllowEdit="false" AllowDelete="true" Visible="true" HeaderText="Delete" />
                            </Columns>
                            <Templates>
                            <obout:GridTemplate runat="server" ID="TP_LogDateFormat"><Template><%#ParseDateTime(Container.DataItem.Item("LogDate"))%></Template></obout:GridTemplate>
                                <obout:GridTemplate runat="server" ID="tplEditActualLeavesBtn">
                                    <Template>
                                        <a href="javascript: //" id="grid_link_<%# Container.PageRecordIndex %>" onclick="attachFlyoutToLink(this,'Update')"
                                            class="ob_gAL">
                                            <%#CheckPermissionsEdit("Edit", Container.DataItem("DeviceId"))%>
                                        </a>
                                    </Template>
                                </obout:GridTemplate>
                                <obout:GridTemplate runat="server" ID="tplAddBtn">
                                    <Template>
                                        <asp:HyperLink runat="server" CssClass="ob_gAL" Text='<%#CheckPermissions("Assign Manual Entries")%>'
                                            NavigateUrl='<%# "~/manage/AssignEmployeeDeviceLogs.aspx"%>' ID="AA1" />
                                    </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>Update Employee Log Entry</legend>
                                <table>
                                    <tr>
                                        <td>
                                            Employee Name
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txt_EmployeeName" runat="server" Width="150px" Enabled="false"></asp:TextBox>
                                        </td>
                                        <td>
                                            Employee Code
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txt_EmployeeCode" runat="server" Width="130px" Enabled="false"></asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            Work Code
                                            
                                        </td>
                                        <td>
                                        <asp:DropDownList ID="drp_WorkCode" runat="server"><asp:ListItem>999</asp:ListItem></asp:DropDownList>
                                        </td>
                                        <td>
                                            Device
                                        </td>
                                        <td>
                                            <asp:DropDownList ID="drp_DeviceName" runat="server" Width="140px">
                                            </asp:DropDownList>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="4">
                                            &nbsp;&nbsp;&nbsp;DateTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select
                                                id="drp_Day" runat="server"></select><select id="drp_Month" runat="server"></select><select
                                                    id="drp_Year" runat="server"></select><asp:DropDownList ID="drp_Hour" runat="server"
                                                        Width="48px">
                                                    </asp:DropDownList><asp:DropDownList ID="drp_Minuts" runat="server" Width="49px">
                                                    </asp:DropDownList>&nbsp;&nbsp;Direction&nbsp;
                                            <select id="drp_Direcion" runat="server" width="69px" enableviewstate="true">
                                                <option selected="selected" value="in">In</option>
                                                <option value="out">out</option>
                                                <option value="breakin">Break In</option>
                                                <option value="breakout">Break out</option>
                                            </select>
                                        </td>
                                    </tr>
                                </table>
                            </fieldset>
                        </td>
                    </tr>
                    <tr>
                        <td align="right" colspan="2">
                            <asp:Label runat="server" ForeColor="red" EnableViewState="false" ID="Lbl_InvalidError"></asp:Label><input
                                id="btn_Save" type="button" value="Save" onclick="javascript:btn_Save_onclick();" />&nbsp;&nbsp;&nbsp;&nbsp;<input
                                    id="btn_Cancel" type="button" value="Close" onclick="javascript:closeFlyout();" />
                            <asp:HiddenField ID="hdn_EmployeeManulEntryId" runat="server" />
                        </td>
                    </tr>
                </table>
            </obout:Flyout>
        </div>
    </form>

    <script runat="server">
        Function CheckPermissions(ByVal Action As String) As String
            If Not Session.Item("LoginUser") Is Nothing Then
                If CType(Session("LoginUser"), eTimeTrackLiteLibrary.Data.Admin.User).PermissionNameList.Contains("AddLogRecords") Then
                    Return Action
                End If
                Return ""
            End If
        End Function
         
        Function CheckPermissionsEdit(ByVal Action As String, ByVal DeviceId As String) As String
            If Not Session.Item("LoginUser") Is Nothing Then
                If CType(Session("LoginUser"), eTimeTrackLiteLibrary.Data.Admin.User).PermissionNameList.Contains("EditLogRecords") And (DeviceId = "1" or DeviceId = "2") Then
                    Return Action
                End If
                Return ""
            End If
        End Function
        
        Function ParseDateTime(ByVal DateValue As Date) As String
            Return DateValue.ToString("yyyy-MM-dd HH:mm")
        End Function
        
    </script>

    <script type="text/javascript">
            
	    function attachFlyoutToLink(oLink,Action)
	     {	
	       <%=Flyout1.getClientID()%>.AttachTo(oLink.id);		            		            
	       <%=Flyout1.getClientID()%>.Open();
	       populateEditControls(oLink.id.toString().replace("grid_link_", ""));
         }
		    
		function closeFlyout() 
		    {
		        <%=Flyout1.getClientID()%>.Close();
		    }
		    
	    function populateEditControls(iRecordIndex) 
	    {	
	        var LogDate=Dg_EmployeeLogRecords.Rows[iRecordIndex].Cells[14].Value;
	        var DeviceId=Dg_EmployeeLogRecords.Rows[iRecordIndex].Cells[3].Value;
	        var Direction=Dg_EmployeeLogRecords.Rows[iRecordIndex].Cells[4].Value.toLowerCase(); 
	        var EmployeeName=Dg_EmployeeLogRecords.Rows[iRecordIndex].Cells[7].Value;
	        var EmployeeCode=Dg_EmployeeLogRecords.Rows[iRecordIndex].Cells[6].Value;
            document.getElementById( "<%=txt_EmployeeName.ClientID %>").value =EmployeeName;
            document.getElementById( "<%=txt_EmployeeCode.ClientID %>").value=EmployeeCode;
            document.getElementById( "<%=drp_DeviceName.ClientID %>").value=DeviceId;
            if(Direction=='')
            {
                document.getElementById( "<%=drp_Direcion.ClientID %>").value='in';
            }
            else
            {
             document.getElementById( "<%=drp_Direcion.ClientID %>").value=Direction;   
            }
            
            document.getElementById( "<%=Lbl_InvalidError.ClientID %>").innerHTML='';
            SetValueInDropDown(document.getElementById("<%=drp_Day.ClientID %>"),document.getElementById("<%=drp_Month.ClientID %>"),document.getElementById("<%=drp_Year.ClientID %>"),document.getElementById("<%=drp_Hour.ClientID %>"),document.getElementById("<%=drp_Minuts.ClientID %>"),LogDate);
            document.getElementById("<%=hdn_EmployeeManulEntryId.ClientID %>").value = Dg_EmployeeLogRecords.Rows[iRecordIndex].Cells[0].Value;
            document.getElementById("<%=drp_WorkCode.ClientID %>").value = Dg_EmployeeLogRecords.Rows[iRecordIndex].Cells[5].Value;
	    }
	    
	        
	    
 function SetValueInDropDown(ddobject,mmobject,yyobject,HHobject,MMobject,value)
		    {
                var Day=value.split(' ')[0].split('-')[2];
	            var Month=value.split(' ')[0].split('-')[1];
	            var Year=value.split(' ')[0].split('-')[0];
		        var Hour=value.split(' ')[1].split(':')[0];
		        var Minute=value.split(' ')[1].split(':')[1];
		        
		        yyobject.value=Year;
		        mmobject.value=Month;
		        ddobject.value=Day;
		        HHobject.value=Hour;
		        MMobject.value=Minute;
		        
		    }
	      
	     function btn_Save_onclick()
	     {
	          var oRecord = new Object();
              oRecord.Id=document.getElementById("<%=hdn_EmployeeManulEntryId.ClientID %>").value 
              oRecord.Error='';
	          Dg_EmployeeLogRecords.executeInsert(oRecord);
	     }
	     
	    function RefreshDataGrid()
        {
            Dg_EmployeeLogRecords.refresh();
            window.setTimeout('RefreshDataGrid()', 60000);
        }
            //window.setTimeout('RefreshDataGrid()', 60000);
    </script>
    
    

</body>
</html>
