<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Client/ClientMaster.master" CodeBehind="Training.aspx.vb" Inherits="Web.Training" %>
<%@ MasterType VirtualPath="ClientMaster.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="phContent" runat="server">

    <div class="container">
        <asp:Button ID="btnAdd" runat="server" CssClass="btn btn-primary float-right" Text="Add Training" />
        <h1>Training</h1>

        <div class="form-group">
            <asp:CheckBox ID="chkActive" runat="server" AutoPostBack="true" Checked="true" CssClass="mr-1" />
            <asp:Label runat="server" AssociatedControlID="chkActive" Text="Active Only" />
        </div>
        
        <div class="table-responsive">
            <asp:GridView ID="gvTraining" runat="server" DataSourceID="dsTraining" AutoGenerateColumns="false" AllowSorting="true"
                CssClass="table clickable-rows table-hover floating-hscroll" CellSpacing="-1" GridLines="None" data-fixed-columns="true" data-fixed-right-number="2">
                <HeaderStyle CssClass="thead-light" />
                <Columns>
                    <asp:BoundField HeaderText="Employee" SortExpression="DriverName" DataField="DriverName" />
                    <asp:BoundField HeaderText="Topic" SortExpression="TopicName" DataField="TopicName" />
                    <asp:BoundField HeaderText="Specific" SortExpression="SpecificTopic" DataField="SpecificTopic" />
                    <asp:BoundField HeaderText="Training Date" SortExpression="TrainingDate" DataField="TrainingDate" DataFormatString="{0:d}" />
                    <asp:BoundField HeaderText="Training Expires" SortExpression="ExpireDate" DataField="ExpireDate" DataFormatString="{0:d}" />
                    <asp:BoundField HeaderText="Notes" SortExpression="Notes" DataField="Notes" />
                    <asp:TemplateField HeaderText="">
                        <ItemTemplate>
                            <div class="text-right">
                                <a href="DocumentsNew.aspx?ctx=Training&id=<%# Eval("id") %>&cid=<%# Eval("ContractID") %>" >
                                    <i class="fa fa-fw fa-file"></i>
                                </a>
                            </div>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="">
                        <ItemTemplate>
                            <div class="text-right">
                                <a href="RemoveTraining.aspx?id=<%# Eval("id") %>&cid=<%# Eval("ContractID") %>" class="btn btn-outline-danger">
                                    <i class="fa fa-trash-alt fa-fw" title="delete"></i>
                                </a>
                            </div>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <EmptyDataTemplate>
                    <p>There are no training entries.</p>
                </EmptyDataTemplate>
            </asp:GridView>
            <asp:SqlDataSource ID="dsTraining" runat="server" SelectCommand="
                SELECT t.ID,t.Notes,t.SpecificTopic,topic.Name TopicName, t.ContractID,
                    CASE WHEN LEN(ISNULL(t.DriverName,''))=0
                        THEN d.LastName+', '+d.FirstName+' '+d.MiddleName+' '+d.Suffix
                        ELSE DriverName END DriverName,
	                CASE WHEN t.TrainingDate>='9/9/9998' THEN NULL ELSE t.TrainingDate END TrainingDate,
	                CASE WHEN t.ExpireDate>='9/9/9998' THEN NULL ELSE t.ExpireDate END ExpireDate
                FROM Training t LEFT JOIN TrainingTopic topic ON topic.ID=t.TopicID LEFT JOIN Driver d ON d.ID=t.DriverID
                WHERE t.ContractID=@contractId AND (d.Terminated=0 OR @activeOnly=0)
                ORDER BY DriverName,TopicName,t.TrainingDate,t.ID">
                <SelectParameters>
                    <asp:Parameter Name="contractId" />
                    <asp:ControlParameter Name="activeOnly" ControlID="chkActive" PropertyName="Checked" />
                </SelectParameters>
            </asp:SqlDataSource>
        </div>

    </div>

</asp:Content>
