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

    <div class="container">
        <h1>Vehicle Profile</h1>

        <ul id="tabList" class="nav nav-tabs">
            <li class="nav-item">
                <a class="nav-link active" href="#general" data-toggle="tab">General Information</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#service" data-toggle="tab">Service Items</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#docs" data-toggle="tab">Documents</a>
            </li>
        </ul>

        <div class="tab-content bg-white border border-top-0 p-3 mb-3">

            <!-- General information tab -->
            <div id="general" class="tab-pane show active">
                <div class="row">
                    <div class="form-group col">
                        <asp:Label runat="server" AssociatedControlID="ddlMake" Text="Make" />
                        <asp:DropDownList ID="ddlMake" runat="server" CssClass="form-control" />
                    </div>
                    <div class="form-group col">
                        <asp:Label runat="server" AssociatedControlID="txtModel" Text="Model" />
                        <asp:TextBox ID="txtModel" runat="server" MaxLength="50" CssClass="form-control" />
                    </div>
                    <div class="form-group col">
                        <asp:Label runat="server" AssociatedControlID="ddlType" Text="Type" />
                        <asp:DropDownList ID="ddlType" runat="server" CssClass="form-control" />
                        <asp:CustomValidator ID="valType" runat="server"
                            ClientValidationFunction="ddlType_ClientValidate" ValidateEmptyText="true"
                            Text="required" Display="Dynamic" CssClass="text-danger" />
                        <script>
                            function ddlType_ClientValidate(s, e) {
                                var ddlType = $('#<%= ddlType.ClientID %>');
                                e.IsValid = (ddlType.val() != 0);
                            }
                        </script>
                    </div>
                </div>
                <div class="row">
                    <div class="form-group col">
                        <asp:Label runat="server" AssociatedControlID="txtUnit" Text="Company Unit Number" />
                        <asp:TextBox ID="txtUnit" runat="server" MaxLength="50" CssClass="form-control" />
                        <asp:RequiredFieldValidator runat="server" ControlToValidate="txtUnit"
                            Text="required" Display="Dynamic" CssClass="text-danger" />
                    </div>
                    <div class="form-group col">
                        <asp:Label runat="server" AssociatedControlID="txtUnitYear" Text="Vehicle Year" />
                        <asp:TextBox ID="txtUnitYear" runat="server" MaxLength="50" TextMode="Number" CssClass="form-control" />
                    </div>
                    <div class="form-group col">
                        <asp:Label runat="server" AssociatedControlID="txtVin" Text="VIN" />
                        <asp:TextBox ID="txtVin" runat="server" MaxLength="200" CssClass="form-control" />
                    </div>
                    <div class="form-group col">
                        <asp:Label runat="server" AssociatedControlID="txtGvwr" Text="GVWR" />
                        <asp:TextBox ID="txtGvwr" runat="server" TextMode="Number" step="0.01" CssClass="form-control" />
                    </div>
                </div>
                <div class="row">
                    <div class="form-group col">
                        <asp:Label runat="server" AssociatedControlID="txtTagNumber" Text="Tag/Registration Number" />
                        <asp:TextBox ID="txtTagNumber" runat="server" MaxLength="50" CssClass="form-control" />
                    </div>
                    <div class="form-group col">
                        <asp:Label runat="server" AssociatedControlID="dtTagExpires" Text="Tag/Registration Expiration Date" />
                        <asp:TextBox ID="dtTagExpires" runat="server" MaxLength="50" TextMode="Date" CssClass="form-control" />
                    </div>
                </div>
                <div class="form-group w-25">
                    <asp:Label runat="server" AssociatedControlID="ddlTireSize" Text="Tire Size" />
                    <asp:DropDownList ID="ddlTireSize" runat="server" CssClass="form-control" />
                </div>
                <div class="form-group w-25">
                    <asp:Label runat="server" AssociatedControlID="ddlOwnedLeased" Text="Owned/Leased" />
                    <asp:DropDownList ID="ddlOwnedLeased" runat="server" CssClass="form-control">
                        <asp:ListItem Text="" />
                        <asp:ListItem Text="Leased" />
                        <asp:ListItem Text="Owned" />
                    </asp:DropDownList>
                </div>
                <div class="form-group w-25">
                    <asp:Label runat="server" AssociatedControlID="txtLocation" Text="Location" />
                    <asp:TextBox ID="txtLocation" runat="server" MaxLength="200" CssClass="form-control" />
                </div>
                <div class="form-group w-25">
                    <asp:Label runat="server" AssociatedControlID="ddlDedicatedDriver" Text="Dedicated Driver" />
                    <asp:DropDownList ID="ddlDedicatedDriver" runat="server" CssClass="form-control" />
                </div>
                <div class="form-group w-25">
                    <asp:Label runat="server" AssociatedControlID="dtPAIDue" Text="Periodic Annual Inspection (Federal) Expiration Date" />
                    <asp:TextBox ID="dtPAIDue" runat="server" MaxLength="50" TextMode="Date" CssClass="form-control" />
                </div>
                <div class="form-group">
                    <asp:CheckBox ID="chkOutOfService" runat="server" CssClass="mr-1" />
                    <asp:Label runat="server" AssociatedControlID="chkOutOfService" Text="Out of Service" CssClass="mr-1" />
                    <asp:TextBox ID="dtOutOfService" runat="server" MaxLength="50" TextMode="Date" CssClass="form-control w-25" />
                </div>
                <div class="form-group">
                    <asp:CheckBox ID="chkSuspended" runat="server" CssClass="mr-1" />
                    <asp:Label runat="server" AssociatedControlID="chkOutOfService" Text="Suspended" CssClass="mr-1" />
                    <asp:TextBox ID="dtSuspended" runat="server" MaxLength="50" TextMode="Date" CssClass="form-control w-25" />
                </div>

        <asp:PlaceHolder ID="phOther" runat="server" Visible="false">
                <div class="form-group">
                    <asp:CheckBox ID="chkOtherDate" runat="server" CssClass="mr-1" />
                    <asp:Label runat="server" AssociatedControlID="chkOtherDate" Text="Other Date Enabled" CssClass="mr-1" />
                    <asp:TextBox ID="dtOtherDate" runat="server" MaxLength="50" TextMode="Date" CssClass="form-control w-25" />
                    <asp:TextBox ID="txtOtherDate" runat="server" CssClass="form-control" Text="Description" placeholder="Other date description" />
                </div>
                <script>
                    $(document).ready(function () {
                        var chkOtherDate = $('#<%= chkOtherDate.ClientID %>');
                        var txtOtherDate = $('#<%= txtOtherDate.ClientID %>');
                        var dtOtherDate = $('#<%= dtOtherDate.ClientID %>');
                        var fixup = function () {
                            if (chkOtherDate.prop('checked') == true) {
                                txtOtherDate.prop('disabled', false);
                                dtOtherDate.prop('disabled', false);
                            } else {
                                txtOtherDate.prop('disabled', true);
                                dtOtherDate.prop('disabled', true);
                            }
                        };
                        fixup();
                        chkOtherDate.change(fixup);
                    });
                </script>
        </asp:PlaceHolder>

        <asp:PlaceHolder ID="phSchedules" runat="server" Visible="false">
                <div class="form-group">
                    <asp:Label runat="server" AssociatedControlID="lstSchedules" Text="Maintenance Schedules" />
                    <asp:CheckBoxList ID="lstSchedules" runat="server" RepeatLayout="UnorderedList" />
                </div>
        </asp:PlaceHolder>

                <div class="form-group">
                    <asp:Label runat="server" AssociatedControlID="txtNotes" Text="Notes" CssClass="long" /><br />
                    <asp:TextBox ID="txtNotes" runat="server" MaxLength="32768" TextMode="MultiLine" CssClass="form-control" />
                </div>
            </div>

            <!-- Service Items tab -->
            <div id="service" class="tab-pane">
<asp:PlaceHolder ID="phServiceItems" runat="server" Visible="false">
        <section class="mt-3">
            <asp:Button ID="btnAdd" runat="server" CssClass="btn btn-primary float-right" Text="Add Service Entry" />
            <h1>Vehicle Service Items</h1>
            <div class="table-responsive">
                <asp:GridView ID="gvService" runat="server" DataSourceID="dsService" AutoGenerateColumns="false" AllowSorting="true" Width="100%"
                    CssClass="table clickable-rows table-hover floating-hscroll" CellSpacing="-1" GridLines="None" data-fixed-columns="true" data-fixed-right-number="1">
                    <HeaderStyle CssClass="thead-light" />
                    <Columns>
                        <asp:BoundField HeaderText="Unit" SortExpression="unit" DataField="unit" />
                        <asp:BoundField HeaderText="Service Date" SortExpression="serviceDate" DataField="serviceDate" DataFormatString="{0:d}" HeaderStyle-Width="100px" />
                        <asp:BoundField HeaderText="Next Service Date" SortExpression="nextServiceDate" DataField="nextServiceDate" DataFormatString="{0:d}" HeaderStyle-Width="140px" />
                        <asp:BoundField HeaderText="Service Type" SortExpression="label" DataField="label" HeaderStyle-Width="200px" />
                        <asp:BoundField HeaderText="Vendor/Mechanic" SortExpression="mechanic" DataField="mechanic" />
                        <asp:BoundField HeaderText="Description" SortExpression="description" DataField="description" />
                        <asp:BoundField HeaderText="Cost" SortExpression="cost" DataField="cost" HeaderStyle-Width="80px" DataFormatString="{0:c}" />
                        <asp:BoundField HeaderText="Odometer" SortExpression="miles" DataField="miles" HeaderStyle-Width="80px" />
                        <asp:TemplateField HeaderText="">
                            <ItemTemplate>
                                <div class="text-right">
                                    <a href="RemoveServiceItem.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 service items.</p>
                    </EmptyDataTemplate>
                </asp:GridView>
                <asp:SqlDataSource ID="dsService" runat="server"
                    SelectCommand="
                        SELECT vsi.id, ISNULL(v.Unit, '(All)') unit, vsi.contractId,
                            vsi.serviceDate, vsi.nextServiceDate, vsi.label, vsi.description, vsi.cost, vsi.miles,
                            vsi.mechanic, vsi.enteredDate, vsi.enteredBy, vsi.editedDate, vsi.editedBy
                        FROM VehicleServiceItems vsi LEFT JOIN Vehicle v ON v.id=vsi.vehicleId
                        WHERE vsi.vehicleId=@vehicleId OR (vsi.vehicleId IS NULL AND vsi.contractId=@contractId)
                        ORDER BY serviceDate DESC">
                    <SelectParameters>
                        <asp:Parameter Name="contractId" />
                        <asp:Parameter Name="vehicleId" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </div>
        </section>
</asp:PlaceHolder>

            </div>


            <!-- Documents tab -->
            <div id="docs" class="tab-pane">
                <div class="table-responsive">
                    <asp:GridView ID="gvDocs" runat="server" DataSourceID="dsDocs" AutoGenerateColumns="false" AllowSorting="true"
                        CssClass="table clickable-rows table-hover floating-hscroll" CellSpacing="-1" GridLines="None" data-fixed-columns="true" data-fixed-number="2">
                        <HeaderStyle CssClass="thead-light" />
                        <Columns>
                            <asp:BoundField HeaderText="Document Type" SortExpression="DocSubCategory" DataField="DocSubCategory" />
                            <asp:BoundField HeaderText="File name" SortExpression="DocName" DataField="DocName" />
                            <asp:BoundField HeaderText="Date" SortExpression="EnteredDate" DataField="EnteredDate" DataFormatString="{0:d}" />
                            <asp:HyperLinkField DataNavigateUrlFields="ContractID,ID,Ctx,ItemID" DataNavigateUrlFormatString="DocumentEdit.aspx?cid={0}&docid={1}&ctx={2}&id={3}" Text="Edit" />
                            <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="/_assets/Document.aspx?context=DocumentNew&id={0}" Target="_blank" Text="view" />
                        </Columns>
                        <EmptyDataTemplate>
                            <p>There are no note entries.</p>
                        </EmptyDataTemplate>
                    </asp:GridView>
                    <asp:SqlDataSource ID="dsDocs" runat="server"
                        SelectCommand ="
                            SELECT DocumentsNew.ContractID,ISNULL(DocumentsNew.ItemID,0) AS ItemID,'VehicleEdit' as Ctx,DocumentsNew.ID,DocumentsNew.DocName,DocumentsNew.EnteredDate,ISNULL(DocumentsSubCategory.Name,'') AS DocSubCategory,DocumentsNew.UploadNotes
                            FROM DocumentsNew LEFT JOIN DocumentsSubCategory ON DocumentsNew.SubCategoryID=DocumentsSubCategory.Id
                            WHERE DocumentsNew.ItemID=@ItemId AND DocumentsNew.CategoryID=@CatID AND (ISNULL(DocumentsNew.Deleted,0) = 0) ORDER BY ISNULL(DocumentsSubCategory.Name,''),DocumentsNew.DocName,DocumentsNew.ID">
                        <SelectParameters>
                            <asp:Parameter Name="CatID" />
                            <asp:Parameter Name="ItemId" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                </div>
            </div>


        </div>

        <div class="row">
            <div class="col">
                <asp:Button ID="btnCancel" runat="server" CssClass="btn btn-secondary" Text="Cancel" CausesValidation="false" />
            </div>
            <div class="col text-right">
                <asp:Button ID="btnDownloadAll" runat="server" CssClass="btn btn-primary" Text="Download All" CausesValidation="false" Width="150px" />
                <asp:Button ID="btnUploadDoc" runat="server" CssClass="btn btn-primary" Text="Upload Document"  CausesValidation="false" Width="150px" />
                <asp:Button ID="btnSave" runat="server" CssClass="btn btn-primary" Text="Save" Width="150px" />
            </div>
        </div>




    </div>

</asp:Content>