<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Admin.Master" CodeBehind="BranchList.aspx.vb" Inherits="Superbowl.BranchList" 
    title="Untitled Page"  EnableEventValidation="false"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="body" runat="server">
<table width="100%" cellpadding="2">
    <tr>
        <td align="center" class="headings" colspan="4">Branch List</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td width="35%">&nbsp;</td>
    </tr>
    <tr>		 
        <td align="right">Branch Name:</td>
        <td  align="left"><asp:TextBox ID="txtBranch" runat="server"></asp:TextBox></td>        
        <td>&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
    <tr>		 
        <td align="right">&nbsp;</td>
        <td  align="left">&nbsp;</td>
        <td align="right"><asp:Button ID="btnSearch" runat="server" Text="Search" /></td>
        <td  align="left"><asp:Button ID="btnAdd1" runat="server" Text="Add" /></td>
    </tr>
    <tr>		 
        <td align="right">&nbsp;</td>
        <td  align="left">&nbsp;</td>
        <td align="right">&nbsp;</td>
        <td  align="left">&nbsp;</td>
    </tr>
    <tr>		 
        <td align="left" colspan="4" style="border: 1px solid maroon">
			  <asp:GridView ID="gvBranch" runat="server" Width="100%" CellPadding="2" 
				  AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" 
				  DataSourceID="sdsBranch" PageSize="25" HeaderStyle-CssClass="gvHeader" 
				  DataKeyNames="BranchID,strBranch">	  	
					<Columns>
						<asp:BoundField DataField="#" HeaderText="#" ReadOnly="True" >
							<HeaderStyle Width="1%" />
							<ItemStyle Font-Size="Smaller" HorizontalAlign="Right" />
						</asp:BoundField>
						<asp:HyperLinkField DataNavigateUrlFields="BranchID"	SortExpression="strBranch"
							DataNavigateUrlFormatString="BranchDetails.aspx?BID={0}" 
							DataTextField="strBranch" HeaderText="Branch" 
							 ItemStyle-Width="30%" ><ItemStyle Width="30%"></ItemStyle>
						</asp:HyperLinkField>	
												 						
						<asp:BoundField DataField="strCode" HeaderText="Code" 
              SortExpression="strCode" />
            <asp:BoundField DataField="strSalesOffice" HeaderText="Sales Office" 
              SortExpression="strSalesOffice" />
            <asp:BoundField DataField="strSAPCode" HeaderText="SAP Code" 
              SortExpression="strSAPCode" />
            <asp:BoundField DataField="strRegionDesc" HeaderText="Region Desc" 
              SortExpression="strRegionDesc" />
            <asp:BoundField DataField="strRegionDesc2" HeaderText="Region Desc 2" 
              SortExpression="strRegionDesc2" />
            <asp:HyperLinkField DataNavigateUrlFields="BranchID" 
              DataNavigateUrlFormatString="CustomerList.aspx?BID={0}" 
              DataTextField="CountCustomers" HeaderText="Customer Count" 
              SortExpression="CountCustomers" Target="_blank">
            <ItemStyle HorizontalAlign="Right" />
            </asp:HyperLinkField>
						<asp:BoundField DataField="strLastUser" HeaderText="Last User" 
							SortExpression="strLastUser" />
						<asp:BoundField DataField="dtStamp" HeaderText="Last Edit" 
							SortExpression="dtStamp" >
							<ItemStyle HorizontalAlign="Right" Wrap="False" Width="5%" />
						</asp:BoundField>
						<asp:CommandField HeaderText="Delete" ShowDeleteButton="True">
							<ItemStyle HorizontalAlign="Center" />
						</asp:CommandField>
					</Columns>
					<HeaderStyle CssClass="gvHeader" Wrap="False"/>				  
				  <AlternatingRowStyle CssClass="lightergrey" />
				   <PagerSettings PageButtonCount="20" Mode="NumericFirstLast" FirstPageText="<B>&lt;&lt;</B>" LastPageText="<B>&gt;&gt;</B>" />
				  <RowStyle CssClass="gvItem" />		
			  </asp:GridView>
			  <asp:Label ID="lblMessage" CssClass="redBold" runat="server" Text=""></asp:Label>
			  <asp:GridView ID="gvExport" runat="server" 
				  AlternatingRowStyle-CssClass="lightergrey"  HeaderStyle-CssClass="gvHeader" 
						SelectedRowStyle-CssClass="gvItem" CellPadding="0" visible="False" 
				  DataSourceID="sdsBranch" AutoGenerateColumns="False" DataKeyNames="BranchID">
				   <Columns>
						
						<asp:BoundField DataField="BranchID" HeaderText="BranchID" 
							SortExpression="BranchID" InsertVisible="False" ReadOnly="True" />
						<asp:BoundField DataField="strBranch" HeaderText="Branch" 
							SortExpression="strBranch" />
						<asp:BoundField DataField="strCode" HeaderText="Code" 
							SortExpression="strCode"/>
					   <asp:BoundField DataField="strSalesOffice" HeaderText="Sales Office" 
               SortExpression="strSalesOffice" />
             <asp:BoundField DataField="strSAPCode" HeaderText="SAP Code" 
               SortExpression="strSAPCode" />
             <asp:BoundField DataField="strRegionDesc" HeaderText="Region Desc" 
               SortExpression="strRegionDesc" />
             <asp:BoundField DataField="strRegionDesc2" HeaderText="Region Desc 2" 
               SortExpression="strRegionDesc2" />
             <asp:BoundField DataField="CountCustomers" HeaderText="Customers Count" 
               ReadOnly="True" SortExpression="CountCustomers" />
             <asp:BoundField DataField="strLastUser" HeaderText="Last User" 
               SortExpression="strLastUser" />
             <asp:BoundField DataField="dtStamp" HeaderText="dtStamp" 
               SortExpression="dtStamp" />
					</Columns>
				   <SelectedRowStyle CssClass="gvItem" />
					<HeaderStyle CssClass="gvHeader" />
					<AlternatingRowStyle CssClass="lightergrey" />	  						
			  </asp:GridView>	  		  
		  	
		  </td>
    </tr>
    <tr>		 
        <td align="left"><asp:CheckBox ID="chkResize" runat="server" AutoPostBack="True" CssClass="red" Text="Show 1000" /></td>
        <td  align="left">&nbsp;</td>
        <td align="right">&nbsp;</td>
        <td  align="left">&nbsp;</td>
    </tr>
    <tr>		 
        <td align="right">&nbsp;</td>
        <td  align="left">&nbsp;</td>
        <td align="right"><asp:Button ID="btnExport" runat="server" Text="Export" /></td>
        <td  align="left"><asp:Button ID="btnAdd2" runat="server" Text="Add" /></td>
    </tr>
</table>	  
			  <asp:SqlDataSource ID="sdsBranch" runat="server" 
				  ConnectionString="<%$ ConnectionStrings:csStockControl %>" 
				  DeleteCommand="DELETE FROM [mstBranch] WHERE [BranchID] = @BranchID" 	
    SelectCommand="SELECT '' AS '#', mstBranch.BranchID, mstBranch.strBranch, mstBranch.strCode, mstBranch.strSalesOffice, mstBranch.strSAPCode, mstBranch.strRegionDesc, mstBranch.strRegionDesc2, COUNT(mstCustomer.strCustomerNo) AS CountCustomers, mstBranch.strLastUser, mstBranch.dtStamp FROM mstBranch LEFT OUTER JOIN mstCustomer ON mstBranch.BranchID = mstCustomer.refBranchID GROUP BY mstBranch.BranchID, mstBranch.strCode, mstBranch.strBranch, mstBranch.strSalesOffice, mstBranch.strSAPCode, mstBranch.strRegionDesc, mstBranch.strRegionDesc2, mstBranch.strLastUser, mstBranch.dtStamp ORDER BY strBranch" 				  >
				  <DeleteParameters>
					  <asp:Parameter Name="BranchID" Type="Int32" />
				  </DeleteParameters>		  				  
			  </asp:SqlDataSource>			  
</asp:Content>


