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

    <div class="container">
        <asp:Button ID="btnAdd" runat="server" Text="Add Contract" CssClass="btn btn-primary float-right" />
        <h1>Subcontracts</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="gvContracts" runat="server" DataSourceID="dsContracts" AutoGenerateColumns="false" AllowSorting="true"
                CssClass="table clickable-rows table-hover floating-hscroll" CellSpacing="-1" GridLines="None">
                <HeaderStyle CssClass="thead-light" />
                <Columns>
                    <asp:BoundField HeaderText="Name" SortExpression="Name" DataField="Name" />
                </Columns>
                <EmptyDataTemplate>
                    There are no subcontracts
                </EmptyDataTemplate>
            </asp:GridView>
            <asp:SqlDataSource ID="dsContracts" runat="server" SelectCommand=
                "SELECT sc.ID,c.Name,c.OwnerContractId parentId
                FROM ServiceContract sc LEFT JOIN Customer c ON c.ID=sc.CustomerID
                WHERE c.OwnerContractId=@contractId AND (@activeOnly=0 OR sc.Status='Active')">
                <SelectParameters>
                    <asp:Parameter Name="contractId" />
                    <asp:ControlParameter Name="activeOnly" ControlID="chkActive" PropertyName="Checked" />
                </SelectParameters>
            </asp:SqlDataSource>
        </div>

    </div>

</asp:Content>
