<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Admin.Master" CodeBehind="ExportsList.aspx.vb" Inherits="Superbowl.ExportsList" 
    title="Untitled Page" EnableEventValidation="false"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

<script type="text/javascript">

</script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="body" runat="server">
  <table width="100%" cellpadding="2">
    <tr>
        <td align="center" class="headings" colspan="4">Exports List</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td width="35%">&nbsp;</td>
    </tr>
    <tr>		 
        <td align="right">Customer:</td>
        <td  align="left">
          <asp:DropDownList ID="ddlCustomer" runat="server" Width="400px" 
            DataSourceID="sdsCustomer" DataTextField="strCustomerName" 
            DataValueField="strCustomerNo">
          </asp:DropDownList>
        </td>        
        <td align="right">Period:</td>
        <td>
          <asp:DropDownList ID="ddlPeriod" runat="server" DataSourceID="sdsPeriod" 
            DataTextField="strPeriod" DataValueField="strPeriod" Width="100px">
          </asp:DropDownList>

        </td>
    </tr>
    <tr>		 
        <td align="right">Brand:</td>
        <td  align="left">
          <asp:DropDownList ID="ddlBrand" runat="server" AutoPostBack="True" 
            DataSourceID="sdsBrand" DataTextField="strBrand" DataValueField="BrandID" 
            Width="400px">
          </asp:DropDownList>
        </td>
        <td align="right">Status:</td>
        <td  align="left"><asp:DropDownList ID="ddlStatus" runat="server" Width="100px">
            <asp:ListItem Value="-1">- All -</asp:ListItem>
            <asp:ListItem Value="1">Processed</asp:ListItem>
            <asp:ListItem Value="0">Not Processed</asp:ListItem></asp:DropDownList>
        </td>
    </tr>
    <tr>		 
        <td align="right">Product:</td>
        <td  align="left">
          <asp:DropDownList ID="ddlProduct" runat="server" Width="400px" 
            DataSourceID="sdsBrandProduct" DataTextField="strProductDesc" 
            DataValueField="strProdCode">
          </asp:DropDownList>

        </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="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="gvExports" runat="server" Width="100%" CellPadding="2" 
				  AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" 
				  DataSourceID="sdsExports" PageSize="25" HeaderStyle-CssClass="gvHeader" 
				  DataKeyNames="ExportID,blnProcessed,refBatch">	  	
					<Columns>
						<asp:BoundField DataField="#" HeaderText="#" ReadOnly="True" >
							<HeaderStyle Width="1%" />
							<ItemStyle Font-Size="Smaller" HorizontalAlign="Right" />
						</asp:BoundField>
						<asp:HyperLinkField DataNavigateUrlFields="ExportID"	SortExpression="mstPeriod"
							DataNavigateUrlFormatString="ExportsDetails.aspx?EID={0}" 
							DataTextField="mstPeriod" HeaderText="Period" 
							 ItemStyle-Width="10%" >
<ItemStyle Width="10%"></ItemStyle>
						</asp:HyperLinkField>
						<asp:HyperLinkField DataNavigateUrlFields="ExportID"	SortExpression="mstCustomer"
							DataNavigateUrlFormatString="ExportsDetails.aspx?EID={0}" 
							DataTextField="mstCustomer" HeaderText="Customer" 
							 ItemStyle-Width="10%" >
<ItemStyle Width="10%"></ItemStyle>
						</asp:HyperLinkField> <asp:BoundField DataField="strCustomerName" HeaderText="Name" 
              SortExpression="strCustomerName" NullDisplayText="&lt;div align=center&gt;&lt;img src='redExclamation24.png'/&gt;&lt;/div&gt;"/>            
						<asp:HyperLinkField DataNavigateUrlFields="ExportID"	SortExpression="mstProdCode"
							DataNavigateUrlFormatString="ExportsDetails.aspx?EID={0}" 
							DataTextField="mstProdCode" HeaderText="Product" 
							 ItemStyle-Width="10%" >
<ItemStyle Width="10%"></ItemStyle>
						</asp:HyperLinkField>	
           <asp:BoundField DataField="strLongProdDesc" HeaderText="Description" 
              SortExpression="strLongProdDesc" NullDisplayText="&lt;div align=center&gt;&lt;img src='redExclamation24.png'/&gt;&lt;/div&gt;"/>
            <asp:BoundField DataField="dblUnits" HeaderText="Units" 
              SortExpression="dblUnits" DataFormatString="{0:#,###}" >
            <ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
            <asp:BoundField DataField="dblNsv" HeaderText="NSV" 
              SortExpression="dblNsv" DataFormatString="{0:#,###}" >												 						
						<ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
						<asp:BoundField DataField="strCountry" HeaderText="Country" 
              SortExpression="strCountry" />
            <asp:TemplateField HeaderText="Processed" SortExpression="blnProcessed">
              <ItemTemplate>               
                <asp:CheckBox ID="chkProcessed" runat="server" 
                  Checked='<%# Bind("blnProcessed") %>' Visible="<%# true %>" />               
              </ItemTemplate>
              <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>  						
            <asp:BoundField DataField="refBatch" HeaderText="Batch" 
              SortExpression="refBatch" >
						<HeaderStyle Width="1%" />
            </asp:BoundField>
						<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>
					  <asp:TemplateField HeaderText="Select">
              <ItemTemplate>
                <asp:CheckBox ID="chkSelect" runat="server" Checked="false" 
                  Visible='<%# Not Eval("blnProcessed") %>'  />
              </ItemTemplate>
              <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
					</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="sdsExports" AutoGenerateColumns="False" DataKeyNames="ExportID">
				   <Columns>
						<asp:BoundField DataField="ExportID" HeaderText="Export ID" InsertVisible="False" ReadOnly="True" />
						<asp:BoundField DataField="mstPeriod" HeaderText="Period" 
              SortExpression="mstPeriod" />
						<asp:BoundField DataField="mstCustomer" HeaderText="Customer No" 
              SortExpression="mstCustomer" />
            <asp:BoundField DataField="strCustomerName" HeaderText="Customer Name" 
              SortExpression="strCustomerName" />
            <asp:BoundField DataField="mstProdCode" HeaderText="Product Code" 
              SortExpression="mstProdCode" />
            <asp:BoundField DataField="strLongProdDesc" HeaderText="Product Description" 
              SortExpression="strLongProdDesc" />
            <asp:BoundField DataField="dblUnits" HeaderText="Units" 
              SortExpression="dblUnits" />
             <asp:BoundField DataField="dblGSV" HeaderText="GSV" 
               SortExpression="dblGSV" />
            <asp:BoundField DataField="dblNsv" HeaderText="NSV" 
              SortExpression="dblNsv" />												 						
						 <asp:BoundField DataField="dblNettEx" HeaderText="Nett Excluding" 
               SortExpression="dblNettEx" />
             <asp:BoundField DataField="strCountry" HeaderText="Country" 
               SortExpression="strCountry" />
						 <asp:BoundField DataField="blnProcessed" HeaderText="Processed" SortExpression="blnProcessed" />						
						 <asp:BoundField DataField="refBatch" HeaderText="refBatch" 
               SortExpression="refBatch" />
						<asp:BoundField DataField="strLastUser" HeaderText="Last User" 
							SortExpression="strLastUser" />
						<asp:BoundField DataField="dtStamp" HeaderText="Stamp" 
							SortExpression="dtStamp"/>
					   <asp:BoundField DataField="refBrandID" HeaderText="refBrandID" 
               SortExpression="refBrandID" />
             <asp:BoundField DataField="dblPrice" HeaderText="dblPrice" 
               SortExpression="dblPrice" />
             <asp:BoundField DataField="intPack" HeaderText="intPack" 
               SortExpression="intPack" />
             <asp:BoundField DataField="intSize" HeaderText="intSize" 
               SortExpression="intSize" />
					</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="right">
          <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/MonthEnd.aspx">Month End Utility</asp:HyperLink>
        </td>
        <td align="right"><asp:Button ID="btnExport" runat="server" Text="Export" /></td>
        <td  align="left"><asp:Button ID="btnProcess" runat="server" Text="Process" />
          &nbsp;
          <asp:Button ID="btnSelectAll" runat="server" Text="Select All" 
            onclientclick="SelectAll()" />
        </td>
    </tr>
</table>	  
<asp:SqlDataSource ID="sdsExports" runat="server" 
ConnectionString="<%$ ConnectionStrings:csStockControl %>" 
DeleteCommand="DELETE FROM [mstExports] WHERE [ExportID] = @ExportID" 	
SelectCommand="SELECT '' AS '#', mstExports.ExportID, mstExports.mstPeriod, mstExports.mstCustomer, mstCustomer.strCustomerName, mstExports.mstProdCode, mstProduct.strLongProdDesc, mstExports.dblUnits, mstExports.dblNSV, mstExports.blnProcessed, RIGHT (mstExports.refBatch, 6) AS refBatch, mstExports.strLastUser, mstExports.dtStamp, CASE WHEN refBrandID IS NULL THEN - 1 ELSE refBrandID END AS refBrandID, mstProduct.dblPrice, mstProduct.intPack, mstProduct.intSize, mstExports.dblGSV, mstExports.dblNettEx, mstExports.strCountry FROM mstProduct RIGHT OUTER JOIN mstExports ON mstProduct.strProdCode = mstExports.mstProdCode LEFT OUTER JOIN mstCustomer ON mstExports.mstCustomer = mstCustomer.strCustomerNo ORDER BY mstExports.mstPeriod DESC, refBatch, mstCustomer.strCustomerName, mstProduct.strLongProdDesc"
>
<DeleteParameters>
  <asp:Parameter Name="ExportID" Type="Int32" />
</DeleteParameters>		  				  
</asp:SqlDataSource>

<asp:SqlDataSource ID="sdsCustomer" runat="server" 
  ConnectionString="<%$ ConnectionStrings:csStockControl %>"  
  SelectCommand="SELECT '0' AS strCustomerNo, '- All -' AS strCustomerName UNION SELECT mstExports.mstCustomer AS strCustomerNo, CASE WHEN strCustomerName IS NULL THEN 'Unknown' ELSE LTRIM(REPLACE(REPLACE(mstCustomer.strCustomerName , mstCustomer.strCustomerNo , '') , LEFT (mstCustomer.strCustomerNo , 6) , '')) END + ' - ' + mstExports.mstCustomer AS strCustomerName FROM mstExports LEFT OUTER JOIN mstCustomer ON mstExports.mstCustomer = mstCustomer.strCustomerNo ORDER BY strCustomerName"
  >
 
</asp:SqlDataSource>
			  
<asp:SqlDataSource ID="sdsPeriod" runat="server" 
  ConnectionString="<%$ ConnectionStrings:csStockControl %>" 
  SelectCommand="SELECT '- All -' AS strPeriod UNION SELECT [strPeriod] FROM [mstPeriod] WHERE strPeriod >= '200701' ORDER BY [strPeriod]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdsBrand" runat="server" 
  ConnectionString="<%$ ConnectionStrings:csStockControl %>" 
  
    SelectCommand="SELECT 0 AS BrandID, '- All -' AS strBrand UNION SELECT CASE WHEN mstBrand.BrandID IS NULL THEN - 1 ELSE BrandID END AS BrandID, CASE WHEN mstBrand.strBrand IS NULL THEN 'Unknown' ELSE strBrand END AS strBrand FROM mstBrand RIGHT OUTER JOIN mstProduct ON mstProduct.refBrandID = mstBrand.BrandID RIGHT OUTER JOIN mstExports ON mstExports.mstProdCode = mstProduct.strProdCode ORDER BY strBrand">
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdsBrandProduct" runat="server" 
ConnectionString="<%$ ConnectionStrings:csStockControl %>" 
    
    
    SelectCommand="SELECT '0' AS strProdCode, '- All -' AS strProductDesc, 0 AS refBrandID UNION SELECT mstExports.mstProdCode, CASE WHEN strLongProdDesc IS NULL THEN 'Unknown' ELSE strLongProdDesc END + ' - ' + mstExports.mstProdCode AS strProductDesc, CASE WHEN refBrandID IS NULL THEN - 1 ELSE refBrandID END AS refBrandID FROM mstProduct RIGHT OUTER JOIN mstExports ON mstExports.mstProdCode = mstProduct.strProdCode ORDER BY strProductDesc">
</asp:SqlDataSource>

</asp:Content>
