<%@ Page Title="" Language="C#" MasterPageFile="~/helpdesk/step.master" AutoEventWireup="true" CodeBehind="Step_Survey_1.aspx.cs" Inherits="helpdesk.helpdesk.Step_Survey_1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

     
  <h4>问卷调查每个问题名称。启明星一份问卷调查最多支持30个问题。</h4>
 
 
  
<div style=" padding:20px;">
 
 
     
        
        <table   class="table votes">
        <tr>
            <th style="width:150px">
问题名称
            </th>
        <td>
           <asp:TextBox ID="subjectTextBox" placeholder="例如：您的性别是？" CssClass="form-control inline"  ValidationGroup="inserts" Width="400" runat="server" Text='<%# Bind("subject") %>' />
            <asp:RequiredFieldValidator   ValidationGroup="inserts" ControlToValidate="subjectTextBox" runat="server" ID="RequiredFieldValidator1" ErrorMessage="*" Display="Dynamic"></asp:RequiredFieldValidator>
      
        </td>
        </tr>
        <tr>
            <th>
问题类型
            </th>
          <td>
          
          <div style=" margin-left:5px;">
          
          
          <asp:RadioButtonList Width="600" RepeatColumns="2" RepeatDirection="Horizontal"
               ClientIDMode="Static" id="itemtype" runat="server">
                     <asp:ListItem Text="下拉框" Value="DropDownList"></asp:ListItem>
                    <asp:ListItem Text="单选框" Value="RadioButtonList"></asp:ListItem> 
                    <asp:ListItem Text="复选框" Value="CheckBoxList"></asp:ListItem>
                    <asp:ListItem Text="单行文本框" Value="TextBox"></asp:ListItem>
                    <asp:ListItem Text="多行文本框" Value="MultiTextBox"></asp:ListItem>
                    <asp:ListItem Text="标签" Value="Label"></asp:ListItem>
                    <asp:ListItem Text="日期" Value="Date"></asp:ListItem>
                    <asp:ListItem Text="附件" Value="FileUpload"></asp:ListItem>
                    <asp:ListItem Text="分组选项" Value="GroupOption"></asp:ListItem>  
                   
            </asp:RadioButtonList>  

            <div id="div_gpblock" style="display:none">
            
            数字范围<asp:DropDownList runat="server" ID="coin" Width=100px>
            <asp:ListItem Text="3" Value="3"></asp:ListItem>
            <asp:ListItem Text="4" Value="4"></asp:ListItem>
            <asp:ListItem Text="5" Selected="True" Value="5"></asp:ListItem>
            <asp:ListItem Text="6" Value="6"></asp:ListItem>
            <asp:ListItem Text="7" Value="7"></asp:ListItem>
            <asp:ListItem Text="8" Value="8"></asp:ListItem>
            <asp:ListItem Text="9" Value="9"></asp:ListItem>
            </asp:DropDownList>
            <br />
            范围文本(由低至高)<br />
           <asp:TextBox runat="server" ID="bad"  Text="差"  class="gptext"></asp:TextBox>
            <asp:TextBox runat="server" ID="mid"  Text="中" class="gptext"></asp:TextBox>
            <asp:TextBox runat="server" ID="good"  Text="好" class="gptext"></asp:TextBox> 

            </div>



            <div id="div_optioncount" style="display:none">
            
               每行选项的个数： 
            <asp:TextBox ID="txt_col"    Text="3" runat="server"></asp:TextBox>  

            </div>

            </div>
             
          </td>
         </tr>
       

          


        <tr>
        <th>
是否必填
        </th>
        <td>
         <asp:CheckBox runat="server" ID="cb_mustfilled"  />
        
        </td>
        </tr>
       
       
        <tr   >
        <th>
单独一行
        </th>
        <td>

        <div class="td_singlerow">
           <asp:CheckBox runat="server" Checked="true" ID="cb_issinglerow" ClientIDMode="Static" /> 
        </div>
        </td>


        </tr>
        
        </table>
         
     <div style="margin-left:100px"  >
            <asp:Button ID="InsertButton" runat="server" ValidationGroup="inserts" CausesValidation="True" 
                Text="添加"  CssClass="btn btn-primary btn-flat" onclick="InsertButton_Click"  />
    
         <a href="pages.aspx?activeid=<%=activeid %>" target="_blank"  class="btn  bg-green btn-flat" >预览</a>
      </div>
        
     

<br /><br />

   <div class="alert alert-danger">
       <b>注意:</b> 如果修改了ID，则ID号必须唯一并且必须小于30，修改ID号的大小可以更改问题的显示顺序
   </div>



<br />
    <asp:GridView ID="GridView1"       
         runat="server" AutoGenerateColumns="False" 
        DataKeyNames="autoid" DataSourceID="SqlDataSource1"   
        GridLines="None"
        onrowdatabound="GridView1_RowDataBound"  
        CssClass="table table-hover"
        >
        <Columns>
           
           
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True"   ItemStyle-Width="80px"  />
          
            <asp:BoundField DataField="id" HeaderText="ID"    ItemStyle-Width="50px" />
           
            <asp:BoundField DataField="subject" HeaderText="投票问题名称"    ItemStyle-Width="300px" />
             
           <asp:TemplateField  ItemStyle-Width="100px">
              <HeaderTemplate>
                <div style=" margin:8px;">问题类型</div>
              </HeaderTemplate>
           <ItemTemplate>
             <asp:Label runat="server" ID="names"  Text='<%#Bind("typesname")%>' ></asp:Label>
           </ItemTemplate>
           
           
           <EditItemTemplate>
            <asp:DropDownList Width="95"   SelectedValue='<%# Bind("types") %>'   id="itemtype" runat="server">
                    <asp:ListItem Text="下拉框" Value="DropDownList"></asp:ListItem>
                    <asp:ListItem Text="单选框" Value="RadioButtonList"></asp:ListItem> 
                    <asp:ListItem Text="复选框" Value="CheckBoxList"></asp:ListItem>
                    <asp:ListItem Text="单行文本框" Value="TextBox"></asp:ListItem>
                    <asp:ListItem Text="多行文本框" Value="MultiTextBox"></asp:ListItem>
                    <asp:ListItem Text="标签" Value="Label"></asp:ListItem> 
                    <asp:ListItem Text="日期" Value="Date"></asp:ListItem>
                     <asp:ListItem Text="附件" Value="FileUpload"></asp:ListItem>
                         <asp:ListItem Text="分组选项" Value="GroupOption"></asp:ListItem>
            </asp:DropDownList> 
           
           </EditItemTemplate>
           
             </asp:TemplateField>
       
       
         <asp:TemplateField  ItemStyle-Width="60px">
              <HeaderTemplate>
              是否必填
              </HeaderTemplate>
           <ItemTemplate>
                <%#Eval("mustfilled").ToString()=="1"?"是":"否" %>
           </ItemTemplate>
           
           
           <EditItemTemplate>
            <asp:CheckBox runat="server" ID="cb2_mustfilled"   />
           </EditItemTemplate>
         </asp:TemplateField>






            <asp:TemplateField  ItemStyle-Width="60px">
              <HeaderTemplate>
                单独一行
              </HeaderTemplate>
           <ItemTemplate>
               <%#Eval("issinglerow").ToString()=="1"?"是":"否" %>
           </ItemTemplate>
           
            <EditItemTemplate>
              <asp:CheckBox runat="server" ID="cb2_issinglerow"   />
           </EditItemTemplate>
           </asp:TemplateField>





          <asp:BoundField DataField="col" HeaderText="每行列数"  ItemStyle-Width="60px"/>
          
           <asp:TemplateField ItemStyle-Width="120px" >
           <ItemTemplate>
               <asp:Label ID="popup" runat="server" Text=""></asp:Label>
               
                <asp:Label ID="types" runat="server" Text=<%#Eval("types") %> Visible="false" ></asp:Label>
                <asp:Label ID="activeid" runat="server" Text=<%#Eval("activeid") %> Visible="false" ></asp:Label>
                 <asp:Label ID="id" runat="server" Text=<%#Eval("id") %> Visible="false" ></asp:Label>
                 
           </ItemTemplate>
           </asp:TemplateField>
       
      
        </Columns>
        <RowStyle  HorizontalAlign=Left Width=130px Height="30px"/>
    </asp:GridView>
    
    
    
    
    <asp:Panel runat="server" ID="pnl_next">
    
    
<div style=" text-align:right;  width:100%">
<a href="step3.aspx?activeid=<%=Request.QueryString["activeid"] %>">下一步</a>
</div>
</asp:Panel>
    
    
    
    
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"    
     OldValuesParameterFormatString="old_{0}"  
        ConflictDetection="CompareAllValues" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
    
        DeleteCommand="DELETE FROM [Survery_subjects] WHERE [autoid] = @old_autoid; delete from survery_options where id=@old_id and activeid=@activeid " 
         
        SelectCommand="SELECT * FROM [survery_subjects] where activeid=@activeid    " 
        
        UpdateCommand=" 
        if(@id>30)
         return

        if(not exists( select * from Survery_subjects where id=@id and  activeid=@activeid)) 
        begin
             update [Survery_subjects] SET col=@col, [subject] = @subject, typesname=@typesname,  
             [types] = @types, [id] = @id,
             mustfilled=@mustfilled , issinglerow=@issinglerow WHERE [autoid] = @old_autoid
             end
         else
         begin

          update [Survery_subjects] SET col=@col, [subject] = @subject, typesname=@typesname,  
        [types] = @types,  
         mustfilled=@mustfilled , issinglerow=@issinglerow WHERE [autoid] = @old_autoid 
         end
         
         update survery_options set id=@id where id=@old_id and activeid=@activeid 
          " 
        
        onupdating="SqlDataSource1_Updating"
         >
        
        <DeleteParameters>
           <asp:QueryStringParameter Name="activeid" Type="Int32" QueryStringField="activeid" />
        </DeleteParameters>
        
         <SelectParameters>
          <asp:QueryStringParameter Name="activeid" Type="Int32" QueryStringField="activeid" />
        </SelectParameters>
       
       
        <UpdateParameters>
            <asp:Parameter Name="subject" Type="String" />
            <asp:Parameter Name="types" Type="String" />
             <asp:Parameter Name="typesname" Type="String" />
            <asp:Parameter Name="id" Type="Int32" />
            <asp:Parameter Name="old_autoid" Type="Int32" />
            <asp:Parameter Name="mustfilled" Type="Int32" />
             <asp:Parameter Name="issinglerow" Type="Int32" />
            <asp:Parameter Name="col" Type="Int32" />
            <asp:QueryStringParameter Name="activeid" Type="Int32" QueryStringField="activeid" />
        </UpdateParameters>
      
    
    </asp:SqlDataSource>
 
    
     
</div>

 
     



















 
 <script>


     $(document).ready(

      function () {

          $("#itemtype").find("input").each(
          function () {

              $(this).click(
              function () {

                  $("#div_optioncount").hide();
                  $("#div_gpblock").hide();
                 // $("#cb_issinglerow").prop("checked", false);
                 // $("#cb_issinglerow").prop("disabled", false);

                  if ($(this).val() == "RadioButtonList" || $(this).val() == "CheckBoxList") {
                      if ($(this).prop("checked")) {
                          $("#div_optioncount").show();
                      }
                      return;
                  }

                  if ($(this).val() == "GroupOption") {
                      if ($(this).prop("checked")) {
                          $("#div_gpblock").show();
                          $("#cb_issinglerow").prop("checked", true);
                          $("#cb_issinglerow").prop("disabled", true);
                      }
                      else {
                          $("#cb_issinglerow").prop("checked", false);
                          $("#cb_issinglerow").prop("disabled", false);
                      }
                    return;
                  }

              });

          });

      });

     

     function openPop(url, title) {

         layer.open(
             {
                 type: 2,
                 title: title,
                  content:url,
                 offset: ['50px', ''],
                 area: ['800px', '500px'] 

             }

             );
           
      }


 </script>



</asp:Content>
