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

<%@ Register Assembly="BasicFrame.WebControls.BasicDatePicker" Namespace="BasicFrame.WebControls" TagPrefix="BDP" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <br />
   <div class="divQuestions">
      <fieldset class="textNowrap divQuestionnaireHeading">
         <legend><b>Survey Filter</b></legend>
         <table width="100%" cellpadding="2" cellspacing="1" border="0">
            <tr>
               <td align="right">Questionnaire:</td>
               <td>
                  <asp:DropDownList ID="strQuestionnaire" runat="server" ForeColor="Black" DataSourceID="sdsQuestionnaire" DataTextField="strQuestionnaire" DataValueField="QuestionnaireID" AppendDataBoundItems="True">
                     <asp:ListItem Value="0">- All -</asp:ListItem>
                  </asp:DropDownList>
               </td>
               <td align="right">Start Date:</td>
               <td>
                  <asp:TextBox ID="strStartDate" runat="server" onfocus="showCalendarControl(this);"></asp:TextBox>
               </td>
            </tr>
            <tr>
               <td></td>
            </tr>
            <tr>
               <td align="right">Reviewer:</td>
               <td>
                  <asp:DropDownList ID="strRSM" runat="server" ForeColor="Black" DataSourceID="sdsRSM" DataTextField="strUserName" DataValueField="UserID" AppendDataBoundItems="True" CssClass="controlTextboxBigger">
                     <asp:ListItem Value="0">- All -</asp:ListItem>
                  </asp:DropDownList>
               </td>
               <td align="right">End Date:</td>
               <td>
                  <asp:TextBox ID="strEndDate" runat="server" onfocus="showCalendarControl(this);"></asp:TextBox>
               </td>
            </tr>
            <tr>
               <td></td>
            </tr>
            <tr>
               <td align="right">User:</td>
               <td width="55%">
                  <asp:DropDownList ID="strSalesPerson" runat="server" ForeColor="Black" DataSourceID="sdsSalesPerson" DataTextField="strUserName" DataValueField="UserID" AppendDataBoundItems="True">
                     <asp:ListItem Value="0">- All -</asp:ListItem>
                  </asp:DropDownList>
               </td>
               <td align="right">Ignore Date:</td>
               <td>
                  <asp:CheckBox ID="chkIgnoreDateRange" runat="server"></asp:CheckBox>
               </td>
            </tr>
            <tr>
               <td></td>
            </tr>
            <tr>
               <td align="right" colspan="4">
                  <asp:Button ID="btnFilter" runat="server" Text="Filter" />
                  &nbsp;
                  <asp:Button ID="btnClear" runat="server" Text="Clear" />
               </td>
            </tr>
         </table>
         <asp:Label ID="lblMessage" runat="server" ForeColor="red" value="" />
      </fieldset>
      <br />
      <div id="surveyGrid">
         <asp:GridView ID="gvSurvey" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="SurveyID" DataSourceID="sdsSurvey" BorderColor="Black"
            BorderStyle="Solid" BorderWidth="1px" Caption="Surveys" CellPadding="4" CssClass="tableBlank" Width="100%" AllowPaging="True" PageSize="25">
            <Columns>
               <asp:TemplateField HeaderText="#">
                  <ItemTemplate>
                     <%# Container.DataItemIndex + 1 %>
                  </ItemTemplate>
               </asp:TemplateField>

               <%--<asp:BoundField DataField="SurveyID" HeaderText="Survey ID" InsertVisible="False" ReadOnly="True" SortExpression="SurveyID" Visible="True" />--%>

               <asp:HyperLinkField DataNavigateUrlFields="SurveyID" DataNavigateUrlFormatString="PeopleBalanceSheetNew.aspx?SurveyID={0}" SortExpression="SurveyID" DataTextField="SurveyID" HeaderText="Survey ID" ItemStyle-HorizontalAlign="Center">
                  <ItemStyle HorizontalAlign="Center"></ItemStyle>
               </asp:HyperLinkField>
               <asp:BoundField DataField="strSurveyDate" HeaderText="Date" SortExpression="strSurveyDate" ReadOnly="True">
                  <ItemStyle HorizontalAlign="Right" />
               </asp:BoundField>
               <asp:BoundField DataField="strUserName" HeaderText="Reviewer" SortExpression="strUserName" />
               <asp:BoundField DataField="strQuestionnaire" HeaderText="Questionnaire" SortExpression="strQuestionnaire" />
               <asp:BoundField DataField="strRepName" HeaderText="User" SortExpression="strRepName" NullDisplayText="&lt;i class=textGrey&gt;n/a&lt;/i&gt;" />
               <asp:BoundField DataField="Score" HeaderText="Score" ReadOnly="True" SortExpression="Score">
                  <ItemStyle HorizontalAlign="Right" />
               </asp:BoundField>
               <asp:BoundField DataField="strLastUser" HeaderText="Last User" SortExpression="strLastUser" />
               <asp:BoundField DataField="strEditDate" HeaderText="Last Edit" SortExpression="strEditDate" />
               <asp:BoundField DataField="QuestionnaireID" HeaderText="QuestionnaireID" ReadOnly="True" SortExpression="QuestionnaireID" Visible="false" />
               <asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" Visible="false" />
            </Columns>
         </asp:GridView>
      </div>
      <br />
      <asp:SqlDataSource ID="sdsSalesPerson" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>" SelectCommand="SELECT mstUser.UserID, mstUser.strUserName FROM mstUser INNER JOIN scrSurvey ON mstUser.UserID = scrSurvey.RepID GROUP BY mstUser.strUserName, mstUser.UserID ORDER BY mstUser.strUserName">
         <SelectParameters>
            <asp:Parameter DefaultValue="true" Name="blnRep" Type="Boolean" />
         </SelectParameters>
      </asp:SqlDataSource>
      <asp:SqlDataSource ID="sdsRSM" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>" 
          SelectCommand="SELECT mstUser.UserID, mstUser.strUserName FROM mstUser INNER JOIN scrSurvey ON mstUser.UserID = scrSurvey.UserID GROUP BY mstUser.strUserName, mstUser.UserID ORDER BY mstUser.strUserName">
      </asp:SqlDataSource>
      <asp:SqlDataSource ID="sdsQuestionnaire" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>" SelectCommand="SELECT [QuestionnaireID], [strQuestionnaire] FROM [scrQuestionnaire] Order by strQuestionnaire"></asp:SqlDataSource>

      <asp:SqlDataSource ID="sdsSurvey" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>"
         SelectCommand="SELECT scrSurvey.SurveyID, CONVERT (varchar(10), scrSurvey.dtDate, 120) AS strSurveyDate, mstUser.strUserName, scrQuestionnaire.strQuestionnaire, 
mstUser_1.strUserName AS strRepName, mstUser_1.UserID AS RepID, scrSurvey.strLastEdit AS strEditDate, dwfScoreCard.strLastUser, CAST(SUM(dwfScoreCard.intAnswer) AS varchar(10)) + '%' AS Score, scrQuestionnaire.QuestionnaireID, scrSurvey.UserID
FROM scrQuestionnaire INNER JOIN scrSurvey ON scrQuestionnaire.QuestionnaireID = scrSurvey.QuestionnaireID 
INNER JOIN mstUser ON scrSurvey.UserID = mstUser.UserID 
LEFT OUTER JOIN mstUser AS mstUser_1 ON scrSurvey.RepID = mstUser_1.UserID 
LEFT OUTER JOIN dwfScoreCard ON scrSurvey.SurveyID = dwfScoreCard.SurveyID 
GROUP BY scrSurvey.SurveyID, scrSurvey.dtDate, mstUser.strUserName, scrQuestionnaire.strQuestionnaire, mstUser_1.strUserName, mstUser_1.UserID, scrSurvey.strLastEdit, dwfScoreCard.strLastUser, scrQuestionnaire.QuestionnaireID, scrSurvey.UserID
ORDER BY scrSurvey.dtDate DESC, mstUser.strUserName, scrQuestionnaire.strQuestionnaire, mstUser_1.strUserName"></asp:SqlDataSource>
   </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder3" runat="server">
</asp:Content>
