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

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {

            //alert('Arr');
            $("input[type='radio'][id^='radOptions_']").change(
               function () {
                   //alert('Yarr');
                   var lblScore = $('#strScore');
                   var intScore = 0;

                   $("input[type='radio'][id^='radOptions_']:checked").each(function () {
                       intScore += parseFloat(this.value);
                   });
                   lblScore.val(intScore + '/100');
               });
        });

        function jsOptLabel_Click(QID, lbl) {

            var opt = $("tr[id='tr_" + QID + "'] input[type='radio'][value='" + lbl.innerHTML + "']");
            opt.prop('checked', 'true');
            opt.change();
            //opt.click();

        }

        function jsTotal10() {
            var lblScore = $('#strScore');
            var intScore = 0;

            $("input[type='radio'][id^='ContentPlaceHolder2_reQuestions_radOptions_']:checked").each(function () {
                intScore += $this.val();
            });

            lblScore.text(intScore + '/100');
        }
   </script>
</asp:Content>

<asp:Content ID="topContent" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <br />
   <div class="divQuestions divQuestionnaireHeading">
      <%--<h2>Salesperson Scorecard</h2>--%>
      <fieldset class="textNowrap divQuestionnaireHeading">
         <legend><b>Sales Capabilities Scorecard</b></legend>
         <table cellpadding="2" cellspacing="1" width="100%">
            <tr>
               <td align="right" width="90">Sales Person:</td>
               <td width="55%">
                  <asp:DropDownList ID="strSalesPerson" runat="server" ForeColor="Black" DataSourceID="sdsSalesPerson" DataTextField="name" DataValueField="RepID" AppendDataBoundItems="True" CssClass="controlTextboxBigger" AutoPostBack="True">
                     <asp:ListItem Value="0">- Select -</asp:ListItem>
                  </asp:DropDownList>
                  <%--<font color="red"><b>*</b></font>--%>
                  <asp:RequiredFieldValidator ID="rfvSalesPerson" SetFocusOnError="true" runat="server" ControlToValidate="strSalesPerson" ErrorMessage="No Sales Person selected!" ForeColor="Red" InitialValue="0">* No Sales Person selected!</asp:RequiredFieldValidator>
               </td>
               <td align="right" width="12%">Date:</td>
               <td>
                  <asp:TextBox ID="strDate" runat="server" BackColor="LightGray" ForeColor="black" Text='<%# Eval("dtDate") %>' CssClass="controlDate" ReadOnly="True" />
               </td>
            </tr>
            <tr>
               <td></td>
               <td>
                  <asp:Label ID="lblLastDate" runat="server" ForeColor="black" Visible="false">Last Survey Date : </asp:Label>
                  <asp:Label ID="lblDate" runat="server" ForeColor="black" Visible="false" />
               </td>
            </tr>
            <tr>
               <td align="right">RSM:</td>
               <td>
                  <asp:DropDownList ID="strRSM" runat="server" ForeColor="Black" DataSourceID="sdsRSM" DataTextField="strUserName" DataValueField="UserID" AppendDataBoundItems="True" CssClass="controlTextboxBigger">
                     <asp:ListItem Value="0">- Select -</asp:ListItem>
                  </asp:DropDownList>
                  <%--<font color="red"><b>*</b></font>--%>
                  <asp:RequiredFieldValidator ID="rfvRSM" SetFocusOnError="true" runat="server" ControlToValidate="strRSM" ErrorMessage="No RSM selected!" ForeColor="Red" InitialValue="0">* No RSM selected!</asp:RequiredFieldValidator>
               </td>
               <td align="right">Score:</td>
               <td>
                  <asp:TextBox ID="strScore" value="" runat="server" BackColor="LightGray" ForeColor="black" CssClass="controlDate" ClientIDMode="Static" ReadOnly="True" />
               </td>
            </tr>
            <tr>
               <td align="right"><%--Store:--%></td>
               <td>
                  <asp:TextBox ID="strStore" runat="server" ForeColor="black" MaxLength="7" AutoPostBack="False" Text='<%# Eval("Store")%>' CssClass="controlTextboxBig" Visible="false"></asp:TextBox>                  
                  <%--<asp:RequiredFieldValidator ID="rfvStore" SetFocusOnError="true" runat="server" ValidateEmptyText="true" ControlToValidate="strStore" ErrorMessage="No Store Code entered!" ForeColor="Red">* No Store Code entered!</asp:RequiredFieldValidator>--%>
               </td>
            </tr>
         </table>
         <br />
         <%--<asp:Label ID="lblCustomerDetails" runat="server" ForeColor="black" value="here " />--%>
         <asp:Label ID="lblMessage" runat="server" ForeColor="red" value="" />
      </fieldset>
      <%--<p><b>Note:</b> Please fill in the Questionaire according to which trade you are in - OFF trade or <font color="blue">ON trade.</font></p>--%>
       <br />
      <asp:SqlDataSource ID="sdsRegion" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>"
         SelectCommand="SELECT [strRegionDesc2], [strRegionOrder] FROM [mstBranch] GROUP BY [strRegionDesc2], [strRegionOrder] ORDER BY [strRegionDesc2], [strRegionOrder]"></asp:SqlDataSource>
      <asp:SqlDataSource ID="sdsSalesPerson" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>"
         SelectCommand="SELECT RepID, strRepName, strRepName + ' - ' + RepID AS name FROM mstRep WHERE (blnRep = @blnRep) GROUP BY strRepName, RepID ORDER BY strRepName">
         <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 mstUserGroupScoreCard ON mstUser.refUserGroupScoreCardID = mstUserGroupScoreCard.UserGroupID WHERE (mstUserGroupScoreCard.strUserGroup = 'RSM') GROUP BY  mstUser.strUserName, mstUser.UserID ORDER BY mstUser.strUserName, mstUser.UserID "></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="sds1" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>" SelectCommand="SELECT CONVERT(varchar(10), dwfScoreCard.dtDate, 120) AS dtDate , dwfScoreCard.UserID, mstUser.strUserName, mstRep.RepID, mstRep.strRepName, dwdCustomer.strCustomerNo AS Store FROM dwfScoreCard INNER JOIN mstUser ON dwfScoreCard.UserID = mstUser.UserID INNER JOIN mstRep ON dwfScoreCard.RepID = mstRep.RepID INNER JOIN dwdCustomer ON dwfScoreCard.strCustomerNo = dwdCustomer.strCustomerNo CROSS JOIN mstUserGroup WHERE (mstRep.blnRep = 1) AND (dwfScoreCard.SurveyID = @SurveyID)">
         <SelectParameters>
            <asp:QueryStringParameter DefaultValue="1" Name="SurveyID" QueryStringField="SurveyID" />
         </SelectParameters>
      </asp:SqlDataSource>

    <%--Category Repeater--%>
    <asp:Repeater ID="reCategories" runat="server" ClientIDMode="Predictable" OnItemDataBound="Category_ItemBound" DataSourceID="sdsCategories">
       <ItemTemplate>
            <div class="lblCategory">
               <asp:Label ID="strCategory" runat="server" Text='<%# Eval("strCategory")%>'></asp:Label>
            </div>
            <%--Question DataSource--%>
            <asp:SqlDataSource
                ID="sdsQuestions" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>"
                SelectCommand="SELECT QuestionID, refQuestionnaireID, REPLACE(strQuestion, CHAR(13),'<BR/>') AS strQuestion, strCategory, strOptionType, intOrder, blnComments, blnComments As txtComments, blnActive, strLastUser, strLastEdit, '0' AS intAnswer FROM scrQuestion WHERE (refQuestionnaireID = 2) AND (blnActive = 1) AND (strCategory = @strCategory) ORDER BY intOrder, strQuestion">
                <SelectParameters>
                    <asp:Parameter Name="strCategory" />
                </SelectParameters>
            </asp:SqlDataSource>

             <%--Answer DataSource--%>
             <asp:SqlDataSource
                  ID="sdsAnswereds" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>"
                  SelectCommand="SELECT dwfScoreCard.QuestionID, dwfScoreCard.QuestionnaireID AS refQuestionnaireID, REPLACE(dwfScoreCard.strQuestion, CHAR(13), '<BR/>') AS strQuestion, dwfScoreCard.strCategory, dwfScoreCard.strOptionType, dwfScoreCard.intOrder, dwfScoreCard.blnComments, dwfScoreCard.intAnswer, dwfScoreCard.txtComments FROM scrQuestion INNER JOIN dwfScoreCard INNER JOIN scrSurvey ON dwfScoreCard.QuestionnaireID = scrSurvey.QuestionnaireID AND dwfScoreCard.dtDate = scrSurvey.dtDate AND dwfScoreCard.UserID = scrSurvey.UserID AND dwfScoreCard.RepID = scrSurvey.RepID AND dwfScoreCard.SurveyID = scrSurvey.SurveyID ON scrQuestion.QuestionID = dwfScoreCard.QuestionID WHERE (scrSurvey.SurveyID = @SurveyID) ORDER BY dwfScoreCard.intOrder, strQuestion">
                  <SelectParameters>
                     <asp:QueryStringParameter DefaultValue="1" Name="SurveyID" QueryStringField="SurveyID" />
                  </SelectParameters>
             </asp:SqlDataSource>

      <%--Question Repeater--%>
      <asp:Repeater ID="reQuestions" runat="server" ClientIDMode="Predictable" OnItemDataBound="FormatRepeaterRow">
         <ItemTemplate>
            <div class="lblQuestionHeading">
               <asp:Label ID="intOrder" runat="server" Text='<%# "Q" + Eval("intOrder").ToString() %>' CssClass="lblOrder" Visible="False"></asp:Label>
               <asp:Label ID="strQuestion" runat="server" Text='<%# Eval("strQuestion") %>' TextMode="SingleLine" ReadOnly="True" BorderStyle="None" BorderWidth="0"></asp:Label>
            </div>
            <table cellpadding="2" cellspacing="1" class="tblOptions">
               <tr class="trOptions" id='tr_<%# Eval("QuestionID")%>'>
                  <td colspan="100%" align="center">
                     <%--ClientIDMode="Static"--%>
                     <asp:RadioButtonList ID='radOptions' runat="server" CausesValidation="True" CellPadding="0" CellSpacing="0" RepeatDirection="Horizontal" Width="100%" CssClass="range10" AppendDataBoundItems="True">
                        <asp:ListItem Value="1" Text=""> </asp:ListItem>
                        <asp:ListItem Value="2" Text=""></asp:ListItem>
                        <asp:ListItem Value="3" Text=""></asp:ListItem>
                        <asp:ListItem Value="4" Text=""></asp:ListItem>
                        <asp:ListItem Value="5" Text=""></asp:ListItem>
                        <asp:ListItem Value="6" Text=""></asp:ListItem>
                        <asp:ListItem Value="7" Text=""></asp:ListItem>
                        <asp:ListItem Value="8" Text=""></asp:ListItem>
                        <asp:ListItem Value="9" Text=""></asp:ListItem>
                        <asp:ListItem Value="10" Text=""></asp:ListItem>
                     </asp:RadioButtonList>
                  </td>
               </tr>
               <tr class="trOptions" align="center">
                  <td>
                     <label for="" onclick="jsOptLabel_Click(<%# Eval("QuestionID")%>,this);">1</label></td>
                  <td>
                     <label for="" onclick="jsOptLabel_Click(<%# Eval("QuestionID")%>,this);">2</label></td>
                  <td>
                     <label for="" onclick="jsOptLabel_Click(<%# Eval("QuestionID")%>,this);">3</label></td>
                  <td>
                     <label for="" onclick="jsOptLabel_Click(<%# Eval("QuestionID")%>,this);">4</label></td>
                  <td>
                     <label for="" onclick="jsOptLabel_Click(<%# Eval("QuestionID")%>,this);">5</label></td>
                  <td>
                     <label for="" onclick="jsOptLabel_Click(<%# Eval("QuestionID")%>,this);">6</label></td>
                  <td>
                     <label for="" onclick="jsOptLabel_Click(<%# Eval("QuestionID")%>,this);">7</label></td>
                  <td>
                     <label for="" onclick="jsOptLabel_Click(<%# Eval("QuestionID")%>,this);">8</label></td>
                  <td>
                     <label for="" onclick="jsOptLabel_Click(<%# Eval("QuestionID")%>,this);">9</label></td>
                  <td>
                     <label for="" onclick="jsOptLabel_Click(<%# Eval("QuestionID")%>,this);">10</label></td>
               </tr>
               <tr>
                  <td colspan="100%" align="right">
                     <%--<asp:Label runat="server" Visible='<%# IIf(Eval("txtComments").ToString() = "True", "True", "False")%>' Text="Comments:" CssClass="fl textNotBold"></asp:Label>--%>
                     <asp:Label ID="Label1" runat="server" Visible='<%# IIf(Eval("blnComments") = False, "False", "True")%>' Text="Comments:" CssClass="fl textNotBold"></asp:Label>
                     <asp:RequiredFieldValidator Display="Dynamic" EnableClientScript="true" ID="rfvQuestion" SetFocusOnError="true" runat="server" ErrorMessage="Please select a value 1 to 10!" ControlToValidate="radOptions" CssClass="boxError"></asp:RequiredFieldValidator>
                     <asp:HiddenField ID="QuestionID" runat="server" Value='<%# Eval("QuestionID") %>' />
                  </td>
               </tr>
               <tr>
                  <td colspan="100%" align="left">
                     <%--<asp:TextBox ID="txtComments" runat="server" Height="40px" TextMode="MultiLine" Visible='<%# IIf(Eval("txtComments").ToString() = "True", "True", "False")%>' Text='<%# IIf(Eval("txtComments").ToString() = "True" Or "False", "", "")%>'></asp:TextBox>--%>
                     <asp:TextBox ID="txtComments" runat="server" Height="40px" TextMode="MultiLine" Visible='<%# IIf(Eval("blnComments") = False, False, True)%>' Text='<%# IIf(Eval("txtComments").ToString()="True", "", Eval("txtComments").ToString()) %>'></asp:TextBox>
                  </td>
               </tr>
               <tr>
                  <td>
                     <%--<%# IIf(Eval("intAnswer").ToString() Is DBNull.Value Or "0", "-1", Eval("intAnswer").ToString())%>--%>
                  </td>
               </tr>
            </table>
         </ItemTemplate>
      </asp:Repeater>
     </ItemTemplate>
    </asp:Repeater>
   </div>
   <asp:Label ID="lblMessageQuestions" runat="server" ForeColor="red" value="" />
   <br />
   <asp:Button ID="btnSave" runat="server" Text="Save" />

  
   <div id="bottomSection" class="divQuestions divQuestionnaireHeading">     

   <asp:SqlDataSource ID="sdsCategories" runat="server" ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>" SelectCommand="SELECT strCategory FROM scrQuestion WHERE (refQuestionnaireID = 2) AND (blnActive = 1) GROUP BY strCategory ORDER BY strCategory"></asp:SqlDataSource>

   
   </div>

</asp:Content>