<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Admin.Master"
   CodeBehind="Promotions.aspx.vb" Inherits="RGBC_Promotions.Promotions" EnableEventValidation="false" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
   <fieldset>
      <legend>Promotions</legend>
      <table style="width: 1000px;" class="" border="0">
         <tr>
            <td align="left" valign="top" width="20%">
               <table style="width: 100%;" class="" border="0" cellpadding="2">
                  <tr>
                     <td width="">
                     </td>
                  </tr>
                  <tr>
                     <td>
                        &nbsp;
                     </td>
                  </tr>
               </table>
            </td>
            <td align="left" valign="top" width="30%">
               <table style="width: 100%;" class="" border="0" cellpadding="2">
                  <tr>
                     <td align="right" width="50%">
                     </td>
                     <td width="">
                     </td>
                     <td width="">
                     </td>
                  </tr>
                  <tr>
                     <td align="right">
                        Year:
                     </td>
                     <td nowrap="nowrap">
                        <asp:DropDownList ID="ddlYear" runat="server" AppendDataBoundItems="True" DataSourceID="sdsYear"
                           DataTextField="DataValueField" DataValueField="DataTextField">
                           <asp:ListItem Value="0">- Select -</asp:ListItem>
                        </asp:DropDownList>
                        <b>*</b>
                     </td>
                     <td>
                     </td>
                  </tr>
                  <tr>
                     <td align="right">
                        Region:
                     </td>
                     <td nowrap="nowrap">
                        <asp:DropDownList ID="ddlRegion" runat="server" AppendDataBoundItems="True" DataSourceID="sdsRegion"
                           DataTextField="strRegionDesc2" DataValueField="strRegionDesc2">
                           <asp:ListItem Value="">- Select -</asp:ListItem>
                        </asp:DropDownList>
                        <b>*</b>
                     </td>
            </td>
            <td>
            </td>
         </tr>
         <tr>
            <td colspan="2" align="right">
               <asp:RequiredFieldValidator ID="valYear" runat="server" ErrorMessage="Please select a Financial Year. "
                  CssClass="textError boxError" ControlToValidate="ddlYear" SetFocusOnError="True"
                  Display="Dynamic" ForeColor="" Type="Integer" InitialValue="0" BorderColor="#7F0206"
                  BorderStyle="Solid" BorderWidth="1px"></asp:RequiredFieldValidator>
               &nbsp;
               <asp:RequiredFieldValidator ID="valBrand" runat="server" ErrorMessage="Please select a Region. "
                  CssClass="textError boxError" ControlToValidate="ddlRegion" SetFocusOnError="True"
                  Display="Dynamic" ForeColor="" Type="Integer" BorderColor="#7F0206" BorderStyle="Solid"
                  BorderWidth="1px"></asp:RequiredFieldValidator>
            </td>
         </tr>
      </table>
      </td >
      <td align="right" valign="top" width="40%">
         <table style="width: 100%;" class="" border="0" cellpadding="2">
            <tr>
               <td align="right" width="40%">
               </td>
               <td width="">
               </td>
               <td width="">
               </td>
            </tr>
            <tr>
               <td align="right">
                  Brand:
               </td>
               <td nowrap="nowrap" align="left">
                  <asp:DropDownList ID="ddlBrand" runat="server" AppendDataBoundItems="True" DataSourceID="sdsBrand"
                     DataTextField="strBrand" DataValueField="BrandID">
                     <asp:ListItem Value="0">- All -</asp:ListItem>
                  </asp:DropDownList>
               </td>
            </tr>
            <tr>
               <td align="right">
                  Channel:
               </td>
               <td align="left">
                  <asp:DropDownList ID="ddlChannel" runat="server" AppendDataBoundItems="True" DataSourceID="sdsChannel"
                     DataTextField="strSegments" DataValueField="strSegments">
                     <asp:ListItem Value="">- All -</asp:ListItem>
                  </asp:DropDownList>
               </td>
               <td>
               </td>
            </tr>
            <tr>
               <td align="left" colspan='2'>
                  &nbsp;
               </td>
               <td>
                  &nbsp;
               </td>
            </tr>
         </table>
      </td>
      </tr>
      <tr>
         <td>
         </td>
         <td align="right">
            &nbsp;<asp:Button ID="btnExport" runat="server" Text="Export" Enabled="False" OnClientClick="" />
            &nbsp;<asp:Button ID="btnImport" runat="server" Text="Import" Enabled="False" OnClientClick="" />
         </td>
         <td>
            <asp:Button ID="btnLoad" runat="server" Text="Load" OnClientClick="jsShowLoading(1);" />&nbsp;
            <asp:Button ID="btnSave" runat="server" Text="Save" OnClientClick="jsShowLoading(1);"
               Enabled="false" />&nbsp;
         </td>
      </tr>
      </table>
   </fieldset>
   <br />
   <br />
   <asp:Label ID="lblMessage" runat="server" CssClass="boxError"></asp:Label>
   <br />
   <br />
   <asp:GridView ID="gvPromotions" runat="server" AutoGenerateColumns="False" BorderColor="Black"
      BorderStyle="Solid" BorderWidth="1px" Caption="Promotions" CellPadding="4" DataSourceID="sdsPromotionsBlank"
      Visible="False" DataKeyNames="PromoID" DataMember="DefaultView" AllowSorting="True">
      <Columns>
         <asp:BoundField DataField="#" HeaderText="#" SortExpression="">
            <HeaderStyle HorizontalAlign="Center" Width="10px" Wrap="False" />
            <ItemStyle HorizontalAlign="Right" Width="10px" Wrap="False" />
         </asp:BoundField>
         <asp:BoundField DataField="PromoID" HeaderText="PromoID" InsertVisible="False" ReadOnly="True"
            SortExpression="PromoID" Visible="False" />
         <asp:BoundField DataField="Period" HeaderText="Period" SortExpression="Period" />
         <asp:TemplateField ConvertEmptyStringToNull="False" HeaderText="Duration" SortExpression="Duration">
            <ItemTemplate>
               <asp:TextBox ID="txtDuration" runat="server" Text='<%# Bind("Duration")%>' Enabled="false"></asp:TextBox>
            </ItemTemplate>
         </asp:TemplateField>
         <asp:BoundField DataField="Region" HeaderText="Region" SortExpression="Region" />
         <asp:BoundField DataField="Brand" HeaderText="Brand" SortExpression="Brand" />
         <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
         <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
         <asp:BoundField DataField="Channel" HeaderText="Channel" SortExpression="Channel" />
         <asp:TemplateField HeaderText="Segment" SortExpression="Segment">
            <ItemTemplate>
               <asp:DropDownList ID="ddlChannelSegmentL3" runat="server" AppendDataBoundItems="True"
                  DataSourceID="sdsChannelSegmentL3" DataTextField="strChannelSegmentL3" DataValueField="strChannelSegmentL3">
                  <asp:ListItem Value="">- Any -</asp:ListItem>
               </asp:DropDownList>
            </ItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Rep" SortExpression="Rep">            
            <ItemTemplate>
               <asp:TextBox ID="txtRep" runat="server" Text='<%# Bind("Rep")%>'></asp:TextBox>
            </ItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="AccountNo" SortExpression="AccountNo">
            <ItemTemplate>
               <asp:TextBox ID="txtCustomerNo" runat="server" Text='<%# Bind("AccountNo") %>'></asp:TextBox>
            </ItemTemplate>
            <ControlStyle Width="80px" />
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Account Details" SortExpression="Account">
            <ItemTemplate>
               <asp:Label ID="lblAccountDetails" runat="server" Text='<%# Bind("Account") %>'></asp:Label>
            </ItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Date" SortExpression="Date">
            <ItemTemplate>
               <asp:TextBox ID="txtDate" runat="server" Text='<%# Bind("Date") %>'></asp:TextBox>
            </ItemTemplate>
            <ControlStyle CssClass="controlDate datePicker" Width="80px" />
         </asp:TemplateField>
         <asp:CommandField ShowDeleteButton="True">
            <HeaderStyle Width="1%" HorizontalAlign="Center" Wrap="False" />
            <ItemStyle HorizontalAlign="Center" Width="1%" Wrap="False" />
         </asp:CommandField>
      </Columns>
   </asp:GridView>
   <br />
   <asp:SqlDataSource ID="sdsPromotionsBlank" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>"
      SelectCommand="SELECT '' AS '#', dwfPromo.PromoID, dwfPromo.strPeriod AS Period, dwfPromo.strRegion AS Region, mstBrand.strBrand AS Brand, dwfPromo.strActivityType AS Type, dwfPromo.strActivityName AS Name, dwfPromo.strSegments AS Channel, dwfPromo.strChannelPrimary AS Segment, dwfPromo.strCustomerNo AS AccountNo, dwdCustomer.strCustomerNo AS Account, dwfPromo.strDate AS Date, dwfPromo.strDuration AS Duration, dwfPromo.strRep AS Rep FROM dwfPromo INNER JOIN mstBrand ON dwfPromo.refBrandID = mstBrand.BrandID INNER JOIN mstUserBrand ON dwfPromo.refBrandID = mstUserBrand.refBrandID LEFT OUTER JOIN dwdCustomer ON dwfPromo.strCustomerNo = dwdCustomer.strCustomerNo WHERE (mstUserBrand.refUserID = @UserID) AND (1 = 0) ORDER BY Period, Region, Brand, Channel, Type, Name"
      DeleteCommand="DELETE FROM dwfPromo WHERE PromoID = @PromoID">
      <DeleteParameters>
         <asp:Parameter Name="PromoID" />
      </DeleteParameters>
      <SelectParameters>
         <asp:SessionParameter DbType="Int32" DefaultValue="26" Name="UserID" SessionField="USERID" />
      </SelectParameters>
   </asp:SqlDataSource>
   <asp:Label ID="Label1" runat="server" Text="//CHANGES TO sdsPromoBlank must be made in GetPromotionsDT() also! - pj" Visible="False"></asp:Label>
   <asp:SqlDataSource ID="sdsYear" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>"
      SelectCommand="SELECT mstPeriod.intFiscalYear AS DataValueField, mstPeriod.intFiscalYear AS DataTextField FROM mstPeriod INNER JOIN dwfPromo ON mstPeriod.strPeriod = dwfPromo.strPeriod WHERE (mstPeriod.intFiscalYear &gt; 2011) GROUP BY mstPeriod.intFiscalYear ORDER BY DataTextField DESC">
   </asp:SqlDataSource>
   <asp:SqlDataSource ID="sdsBrand" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>"
      SelectCommand="SELECT mstBrand.BrandID, mstBrand.strBrand FROM mstUserBrand INNER JOIN dwfPromo ON mstUserBrand.refBrandID = dwfPromo.refBrandID INNER JOIN mstBrand ON dwfPromo.refBrandID = mstBrand.BrandID WHERE (mstBrand.blnActive = 1) AND refUserID = @UserID GROUP BY mstBrand.BrandID, mstBrand.strBrand ORDER BY mstBrand.strBrand">
      <SelectParameters>
         <asp:SessionParameter DbType="Int32" DefaultValue="26" Name="UserID" SessionField="USERID" />
      </SelectParameters>
   </asp:SqlDataSource>
   <asp:SqlDataSource ID="sdsRegion" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>"
      SelectCommand="SELECT mstBranch.strRegionDesc2, mstBranch.strRegionOrder FROM mstBranch INNER JOIN dwfPromo ON mstBranch.strRegionDesc2 = dwfPromo.strRegion WHERE (mstBranch.strRegion = N'Domestic') GROUP BY mstBranch.strRegionDesc2, mstBranch.strRegionOrder HAVING (mstBranch.strRegionOrder &lt;&gt; '0') ORDER BY mstBranch.strRegionOrder">
   </asp:SqlDataSource>
   <asp:SqlDataSource ID="sdsChannel" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>"
      SelectCommand="SELECT strSegments FROM dwfPromo GROUP BY strSegments ORDER BY strSegments">
   </asp:SqlDataSource>
   <asp:SqlDataSource ID="sdsChannelSegmentL3" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>"
      SelectCommand="SELECT mstChannelSegment.strSegmentPrimary + '\' + mstChannelSegment.strSegment + '\' + mstChannelSegment.strChannelPrimary AS strChannelSegmentL3 FROM mstChannelSegment INNER JOIN dwfPromo ON mstChannelSegment.strSegmentPrimary + '\' + mstChannelSegment.strSegment = dwfPromo.strSegments GROUP BY mstChannelSegment.strSegmentPrimary, mstChannelSegment.strSegment, mstChannelSegment.strChannelPrimary HAVING (NOT (mstChannelSegment.strSegmentPrimary IN (N'Unknown', N'Export', 'House', 'Not Allocated'))) ORDER BY strChannelSegmentL3">
   </asp:SqlDataSource>
</asp:Content>
