<%@ Page Title="" Language="C#" MasterPageFile="~/Master/MasterPage.master" AutoEventWireup="true" CodeBehind="Manufacturers.aspx.cs" Inherits="PirTickets.Manufacturers" ViewStateEncryptionMode="Never"  %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <H2>Manufacturers</h2>

        <h4>Add New Manufacturer</h4>
        <asp:TextBox ID="TxtAdd" runat="server" MaxLength="50" Width="220px"></asp:TextBox>
        <asp:Button ID="badd" runat="server" onclick="badd_Click" Text="Add New" />
            <asp:Label ID="lblAlert" runat="server"></asp:Label>

    <asp:UpdatePanel runat="server" ID="updatepanel2" UpdateMode="Always">
    <ContentTemplate>   

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" DataKeyNames="id" 
            DataSourceID="SqlDataManufacturers" Width="600px" AllowPaging="True" 
            AllowSorting="True" EmptyDataText="No Manufacturers to display" 
            EnableSortingAndPagingCallbacks="True" 
            onselectedindexchanged="GridView1_SelectedIndexChanged" 
            OnRowEditing="GridView1_edit" OnRowDeleted ="GridView1_delete" 
            OnSorting ="Gridview1_Sorting" AutoGenerateSelectButton="True" 
            CellPadding="4" ForeColor="#333333" ShowFooter="True">
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <Columns>
                <asp:BoundField DataField="id" HeaderText="ID" InsertVisible="False" 
                    ReadOnly="True" SortExpression="id" >
                <HeaderStyle HorizontalAlign="Left" />
                <ItemStyle Width="75px" />
                </asp:BoundField>
                <asp:BoundField DataField="manufacturer" HeaderText="Manufacturer" 
                    SortExpression="manufacturer" >
                <ItemStyle Width="400px" />
                </asp:BoundField>
            </Columns>
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataManufacturers" runat="server" 
            ConnectionString="<%$ ConnectionStrings:PirTickets %>" 
            SelectCommand="SELECT [id], [manufacturer] FROM [Manufacturers] order by [manufacturer]" UpdateCommand="update [Manufacturers] set [manufacturer] = @manufacturer where id =@id" DeleteCommand ="delete from [manufacturers] where id = @id">
        </asp:SqlDataSource>
            <br />
        <h4>Add New Model to Manufacturer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
           
        </h4>
        <asp:TextBox ID="txtAddModel" runat="server" MaxLength="50" Width="220px"></asp:TextBox>
        <asp:Button ID="btAddModel" runat="server" onclick="baddModel_Click" Text="Add New" />
            <asp:Label ID="lblModel" runat="server"></asp:Label>
        <asp:GridView ID="GridView2" runat="server" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" AutoGenerateDeleteButton="True" 
            AutoGenerateEditButton="True" DataKeyNames="modelid" 
            DataSourceID="SqlDataModels" Width="600px" CellPadding="4" 
            ForeColor="#333333" ShowFooter="True">
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <Columns>
                <asp:BoundField DataField="modelid" HeaderText="modelid" InsertVisible="False" 
                    ReadOnly="True" SortExpression="modelid">
                <ItemStyle Width="100px" />
                </asp:BoundField>
                <asp:BoundField DataField="ModelName" HeaderText="Model" 
                    SortExpression="ModelName">
                <ItemStyle Width="600px" />
                </asp:BoundField>
            </Columns>
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>

        <asp:SqlDataSource ID="SqlDataModels" runat="server" 
            ConnectionString="<%$ ConnectionStrings:PirTickets %>" 
            SelectCommand="SELECT [modelid], [ModelName] FROM [Models] WHERE ([manufacturerID] = @manufacturerID)"
            DeleteCommand="DELETE from [MODELS] WHERE modelid = @modelid"
            UpdateCommand="UPDATE [MODELS] SET [ModelName] = @ModelName WHERE modelid = @modelid"
            >
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView1" Name="manufacturerID" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>

        <asp:UpdateProgress ID="UpdateProgress1" runat="server" 
            AssociatedUpdatePanelID="updatepanel2">
        </asp:UpdateProgress>
            &nbsp;
            </ContentTemplate>
    </asp:UpdatePanel>
    
</asp:Content>
