<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="True" Inherits="Kesion.NET.WebSite.Admin.KS_FieldManage" Codebehind="KS.FieldManage.aspx.cs" %>
<%@ Import Namespace="Kesion.Publics"%>
<%@ Import Namespace="Kesion.Cache"%>
<%@ Import Namespace="Kesion.BLL"%>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Xml" %>
<asp:Content ID="Content1" ContentPlaceHolderID="KSContent" runat="Server">
	<div id="manage_top" class="toptitle menu_top_fixed">
      <ul class="titleTab">
          <li><a href="KS.DataReplace.aspx">数据库字段替换</a></li>
          <li><a href="KS.DataBack.aspx">在线备份数据库</a></li>
          <li><a href="KS.ExeSQL.aspx">在线执行SQL语句</a></li>
          <li><a href="KS.Data.Table.aspx">查看数据库里所有数据表</a></li>
          <li class="curr"><a href="KS.FieldManage.aspx">数据表字段增减</a></li>
       </ul>
    </div>
    <div class="menu_top_fixed_height"></div> 

    <asp:Panel ID="listPanel" runat="server" Width="100%">
   	<div class="content-area"> 
   		
        <div class="tabs_header">
        <span class="fr"><asp:LinkButton ID="addbutton" CssClass="button button_on mr20" runat="server" OnClick="addbutton_Click">新增字段</asp:LinkButton></span>
        <ul class="tabs">
        <%
            Response.Write(menuSb.ToString());
        %>
        </ul>
    </div>
           
        <KS:KSGV ID="FieldListView" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" GridLines="None"
            OnRowDataBound="FieldListView_RowDataBound" EmptyDataText="没有字段！" PagerType="CustomNumeric" Width="99%" CssClass="CTable"  OnRowCommand="FieldListView_RowCommand">
            <Columns>
                <asp:TemplateField HeaderText="排序">
                    <itemstyle width="60px" horizontalalign="Center"  />
                    <headerstyle height="18px"/>
                    <itemtemplate>
                        <asp:HiddenField  ID="HiddenFieldID" runat="server" Value='<%#Eval("ID")%>'  />
                    
                     <asp:DropDownList id="orderid" datasource="<%#bindorder() %>" runat="server"></asp:DropDownList>
                    </itemtemplate>
                </asp:TemplateField>
                  <asp:BoundField DataField="FieldOrtherName" HeaderText="字段别名">
                    <itemstyle width="100px" />
                </asp:BoundField>

                <asp:BoundField DataField="FieldName" HeaderText="字段名称">
                    <itemstyle width="100px" ForeColor="#999999" horizontalalign="Center" />
                </asp:BoundField>

              <asp:TemplateField HeaderText="字段类型">
              <itemstyle width="30px" horizontalalign="Center"/>
              <itemtemplate>
                 <%#GetTypeStr(Utils.StrToInt(Eval("FieldType"))) %>
              </itemtemplate>
            </asp:TemplateField>

              
             <asp:TemplateField HeaderText="属性">
              <itemstyle width="30px" horizontalalign="Center"/>
              <itemtemplate>
                 <%#Eval("InputItem").ToString()=="0"?"选填":"<font color='red'>必填</font>" %>
              </itemtemplate>
            </asp:TemplateField>


             <asp:TemplateField HeaderText="状态">
              <itemstyle width="30px" horizontalalign="Center"/>
              <itemtemplate>
                   <a href="?action=Disabled&FiledID=<%#Eval("id")%>" <%# Convert.ToString(Eval("IsDisabled"))=="0"?"class='no' title='禁用'":"class='ok' title='正常'" %>></a>
              </itemtemplate>
            </asp:TemplateField>


            <asp:TemplateField HeaderText="编辑">
              <itemstyle width="30px" horizontalalign="Center"/>
              <itemtemplate>
                  <a Class="edit" href="KS.FieldManage.aspx?action=edit&id=<%=KSCMS.S("id") %>&FiledID=<%#Eval("id") %>"></a>
                    
              </itemtemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="删除">
              <itemstyle width="30px" horizontalalign="Center"/>
              <itemtemplate>
                     <a Class="delete" href="KS.FieldManage.aspx?action=del&id=<%=KSCMS.S("id") %>&FiledID=<%#Eval("id") %>&name=<%#Eval("FieldName").ToString () %>&ModelType=<%#Eval("FieldModeType").ToString() %>" onclick="return(confirm('删除字段，此操作不可逆，确定删除该字段吗?'));"></a>
                    
              </itemtemplate>
            </asp:TemplateField>

                
            </Columns>
             <EmptyDataRowStyle CssClass="emptycss" />
            <HeaderStyle CssClass="CTitle" />
        </KS:KSGV>
        <asp:Panel ID="Panel1" runat="server" Height="30px">
            <div class="listedit"><asp:Button ID="Button1" runat="server" Text="批量保存字段排序" OnClick="Button1_Click1" /></div>
        </asp:Panel>
         <asp:Panel ID="Panel2" runat="server" Height="30px" Width="100%">
        <script type="text/javascript">
            showtips('<span class="state"><strong>操作说明：</strong><br /></span>在模板页的调用格式：{KS:Field:<font  color="red">字段名称</font>}。');
		</script>

       </asp:Panel>
             <KS:Page ID="page1" runat="server" />
        </div>
     </asp:Panel>
    
    <asp:Panel ID="addPanel" runat="server" Width="100%" Visible="false">
          <script>
              jQuery(document).ready(function () { ShowArea(); });

              function ShowArea() {
                  var v = parseInt(jQuery("#<%=this.FieldType.ClientID %> :radio[checked]").val());
                  //if (v == 12) {
                  //    jQuery("#ParentIDArea").show();
                  //} else {
                  //    jQuery("#ParentIDArea").hide();
                  //}
                  if (v == 2 || v == 3) {
                      jQuery("#HeightArea").show();
                  }
                  else {
                      jQuery("#HeightArea").hide();
                  }
                  if (v == 10 || v == 11) {
                      jQuery("#FileArea").show()
                  }
                  else {
                      jQuery("#FileArea").hide();
                  }
                  if (v == 4 || v == 5 || v == 6) {
                      jQuery("#ListArea").show();
                  }
                  else {
                      jQuery("#ListArea").hide();
                  }
                  if (v == 5 || v == 6) {
                      jQuery("#WidthArea").hide();
                  }
                  else {
                      jQuery("#WidthArea").show();
                  }
                  if (v == 6) {
                      jQuery("#CheckTips").show();
                  }
                  else {
                      jQuery("#CheckTips").hide();
                  }
                  if (v == 3) {
                      jQuery("#ToolbarArea").show();
                  }
                  else {
                      jQuery("#ToolbarArea").hide();
                  }
                  if (v == 16) {
                      $("#showDefaultValue").hide();
                      $("#showBindModel").show();
                  } else {
                      $("#showDefaultValue").show();
                      $("#showBindModel").hide();
                  }
              }
        function CheckForm() {
            var fileName = $("#<%=FieldName.ClientID%>").val();
            if (fileName == '') {
                KesionJS.Alert('请输入字段名称！', "jQuery('#<%=this.FieldName.ClientID %>').focus()");
                return false;
            } else {
                var reg = /[a-zA-Z]+\w{2,}/;
                var r = fileName.match(reg);
                if (r == null) {
                    KesionJS.Alert('字段名称必须以字母开头,后面跟字母、数字或下划线的任意组合,且必须大于等于3个字符！', "jQuery('#<%=this.FieldName.ClientID %>').focus()");
                    return false;
                }
            }
            if ($("#<%=FieldAlias.ClientID%>").val() == '') {
                KesionJS.Alert('请输入字段别名！', "jQuery('#<%=this.FieldAlias.ClientID %>').focus()");
                return false;
            }
            return true;
        }
          </script>
</div>

<div class="content-area">      
     <div class="myTitle">
          <%if (Utils.StrToInt(KSCMS.S("FiledID"))>0) { %>
           修改数据库表字段
         <%} else { %>
           添加数据库表字段
         <%} %>
   		</div>
         <table width="99%" align="center" border="0" cellpadding="0" cellspacing="0" class="CTable no-borderTable"> 
             <tr>
                 <td align="right" class="lefttd" height="30" style="width: 198px">
                     <strong>所属数据表：</strong></td>
                 <td class="righttd">
                     <asp:DropDownList ID="drpTableID" runat="server"></asp:DropDownList>
                 </td>
             </tr>
             <tr>
                <td align="right" class="lefttd" height="30" style="width: 198px">
                    <strong>字段名称：</strong></td>
                <td class="righttd">
                    <asp:TextBox CssClass="textbox" ID="FieldName" placeholder="不超过20个字符" MaxLength="20" runat="server"></asp:TextBox>
                    <span style="color: #ff0066">*</span> 
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="FieldName"
                        ErrorMessage="请输入名称" Display="Dynamic"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="FieldName"
                        Display="Dynamic" ErrorMessage="必须以字母开头,后面跟字母、数字或下划线的任意组合,且必须大于等于3个字符" ValidationExpression="[a-zA-Z]+\w{2,}"></asp:RegularExpressionValidator><br />
                    <span class="tips">字段名称以字母、数字、和下划线组成,并且只能以字母开头.在模板页的调用格式：<span style="color: #ff0066">{KS:Field:</span><span id="Fields" style="color: #ff0066">字段名称</span><span style="color: #ff0066">}</span></span></td>
             </tr>
             <tr>
                 <td align="right" class="lefttd" style="width: 198px; height: 30px;">
                     <strong>字段别名：</strong></td>
                 <td class="righttd" style="height: 30px">
                     <asp:TextBox CssClass="textbox" ID="FieldAlias" runat="server"></asp:TextBox>
                     <span style="color: #ff0066">*<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
                         runat="server" ControlToValidate="FieldAlias" ErrorMessage="请输入字段别名"></asp:RequiredFieldValidator><br />
                     </span><span class="tips">如:你的姓名，联系方式等等</span></td>
             </tr>
             <tr>
                 <td align="right" class="lefttd" style="width: 198px; height: 30px">
                     <strong>字段录入提示：</strong></td>
                 <td class="righttd" style="height: 30px">
                     <asp:TextBox CssClass="mtext" ID="Tips" runat="server" TextMode="MultiLine"></asp:TextBox>
                     <span class="tips mtext-tips">显示在录入框旁边的提示信息</span></td>
             </tr>
             <tr style="display:none">
                 <td align="right" class="lefttd" style="width: 198px; height: 30px">
                     <strong>字段类别：</strong></td>
                 <td class="righttd" style="height: 30px">
                     <asp:RadioButtonList ID="FieldLevel" runat="server" Enabled="false" RepeatDirection="Horizontal">
                         <asp:ListItem Value="0">系统字段</asp:ListItem>
                         <asp:ListItem Selected="True" Value="1">自定义</asp:ListItem>
                     </asp:RadioButtonList></td>
             </tr>
             <tr>
                 <td align="right" class="lefttd" style="width: 198px; height: 30px">
                     <strong>字段类型：</strong></td>
                 <td class="righttd" style="height: 30px">
                     <asp:RadioButtonList ID="FieldType" runat="server" RepeatColumns="4" RepeatDirection="Horizontal" onclick="ShowArea();">
                         <asp:ListItem Selected="True" Value="1">单行文本</asp:ListItem>
                         <asp:ListItem Value="2">多行文本(不支持HTML)</asp:ListItem>
                         <asp:ListItem Value="3">多行文本(支持HTML)</asp:ListItem>
                         <asp:ListItem Value="4">下拉选项</asp:ListItem>
                         <asp:ListItem Value="5">单选框</asp:ListItem>
                         <asp:ListItem Value="6">复选框</asp:ListItem>
                         <asp:ListItem Value="7">日期</asp:ListItem>
                         <asp:ListItem Value="8">数字（Int）</asp:ListItem>
                         <asp:ListItem Value="13">小数字（Float）</asp:ListItem>
                         <asp:ListItem Value="14">货币（Money）</asp:ListItem>
                         <asp:ListItem Value="9">电子邮箱</asp:ListItem>
                         <asp:ListItem Value="10">图片</asp:ListItem>
                         <asp:ListItem Value="11">文件</asp:ListItem>
                       <%--  <asp:ListItem Value="12" style="color:blue">联动下拉列表</asp:ListItem>--%>
                         <asp:ListItem Value="15">日期+时间</asp:ListItem>
                         <asp:ListItem Value="16">绑定其它模型</asp:ListItem>
                         <asp:ListItem Value="17">图片上传（支持手机）</asp:ListItem>
                         <asp:ListItem Value="19">视频上传（仅支持阿里云）</asp:ListItem>
                     </asp:RadioButtonList></td>
             </tr>
             <tr id="showDefaultValue">
                 <td align="right" class="lefttd" style="width: 198px; height: 30px">
                     <strong>默 认 值：</strong></td>
                 <td class="righttd" style="height: 30px">
                     <asp:TextBox CssClass="textbox" ID="DefaultValue" runat="server"></asp:TextBox> <span id="CheckTips" style="color: #ff0033;display:none;">多个默认选项，请用项英文逗号","隔开</span>
                     <asp:Label ID="LabDefaultValueTips" runat="server"></asp:Label>
                     </td>
             </tr>
            
             <tr id="showBindModel" style="display:none">
                 <td align="right" class="lefttd" style="width: 198px; height: 30px">
                     <strong>请选择要绑定的模型：</strong></td>
                 <td class="righttd" style="height: 30px">
                     <asp:DropDownList ID="DrpModelID" runat="server"></asp:DropDownList>
                 </td>
             </tr>
             <tbody id="ToolbarArea" style="display:none">
                 <tr>
                     <td align="right" class="lefttd" style="width: 198px; height: 30px">
                         <strong>编辑器类型：</strong></td>
                     <td class="righttd" style="height: 30px">
                         <asp:DropDownList ID="Toolbar" runat="server">
                             <asp:ListItem Value="Basic" Selected="True">简洁型编辑器</asp:ListItem>
                             <asp:ListItem Value="Common">标准型编辑器</asp:ListItem>
                             <asp:ListItem Value="Content">增强型编辑器</asp:ListItem>
                         </asp:DropDownList></td>
                 </tr>
               </tbody>
             <tbody id="WidthArea">
             <tr>
                 <td align="right" class="lefttd" style="width: 198px; height: 30px">
                     <strong>显示的宽度：</strong></td>
                 <td class="righttd" style="height: 30px">
                     <asp:TextBox CssClass="textbox" ID="Width" runat="server" Width="44px">350</asp:TextBox>
                     px&nbsp; <span style="color: #ff0066">例如：200px<asp:RegularExpressionValidator ID="RegularExpressionValidator2"
                         runat="server" ControlToValidate="Width" ErrorMessage="请填写数字" ValidationExpression="\d*"></asp:RegularExpressionValidator></span></td>
             </tr>
             </tbody>
             <tbody id="HeightArea" style="display:none">
             <tr>
                 <td align="right" class="lefttd" style="width: 198px; height: 30px">
                     <strong>显示的高度：</strong></td>
                 <td class="righttd" style="height: 30px">
                     <asp:TextBox CssClass="textbox" ID="Height" runat="server" Width="44px">100</asp:TextBox>
                     px&nbsp; <span style="color: #ff0066">例如：200px<asp:RegularExpressionValidator ID="RegularExpressionValidator3"
                         runat="server" ControlToValidate="Height" ErrorMessage="请填写数字" ValidationExpression="\d*"></asp:RegularExpressionValidator></span></td>
             </tr>
             </tbody>
          <%--   <tbody id="ParentIDArea" style="display:none">
              <tr>
                <td align="right" class="lefttd" style="width: 198px; height: 39px">
                         <strong>所属父级字段：<br />
                         </strong><span style="color: #0000ff">不选择表示一级联动字段<br />
 不能指定为下级联动字段</span></td>
                     <td class="righttd" style="height: 39px">
                       <asp:DropDownList ID="DrpParentFieldID" runat="server">
                        <asp:ListItem Value="0">--作为一级联动--</asp:ListItem>
             
                       </asp:DropDownList>
                     </td>
                 </tr>
             </tbody>--%>
             <tbody id="ListArea" style="display:none">
                 <tr>
                     <td align="right" class="lefttd" style="width: 198px; height: 39px">
                         <strong>列表选项：<br />
                         </strong><span style="color: #0000ff">每一行为一个列表选项</span>
                     <br />
                     如果值和显示项不同可以用<span style="color:Red">|</span>隔开
正确格式如：<span style="color:Red">男</span> 或 <span style="color:Red">0|男</span>    
                     </td>
                     <td class="righttd" style="height: 39px">
                         <asp:TextBox ID="Options" runat="server" Height="87px" TextMode="MultiLine" Width="219px"></asp:TextBox></td>
                 </tr>
             </tbody>
             <tbody id="FileArea" style="display:none">
             <tr>
                 <td align="right" class="lefttd" style="width: 198px; height: 39px">
                     <strong>允许上传的文件类型：</strong></td>
                 <td class="righttd" style="height: 39px">
                     <asp:TextBox CssClass="textbox" ID="AllowFileExt" Text="jpg|gif|png" runat="server" Width="212px"></asp:TextBox>
                     多个扩展名请用＂|＂隔开</td>
             </tr>
             <tr>
                 <td align="right" class="lefttd" style="width: 198px; height: 30px">
                     <strong>允许上传的文件大小：</strong></td>
                 <td class="righttd" style="height: 30px">
                     <asp:TextBox CssClass="textbox" ID="MaxFileSize" text="1024" runat="server" Width="41px"></asp:TextBox>
                     KB&nbsp; <span style="color: #ff0000">*</span> <span style="color: blue">提示：1 KB = 1024
                         Byte，1 MB = 1024 KB<span> </span></span>
                 </td>
             </tr>
             </tbody>
             <tr>
                 <td align="right" class="lefttd" style="width: 198px; height: 30px">
                     <strong>字段属性：</strong></td>
                 <td class="righttd" style="height: 30px">

                      <asp:RadioButtonList ID="RbInputItem" runat="server" RepeatDirection="Horizontal" >
                         <asp:ListItem Value="0"  Selected>选填</asp:ListItem>
                          <asp:ListItem Value="1" >必填</asp:ListItem> 
                     </asp:RadioButtonList> 
                    </td>
             </tr>
             <tr>
                 <td align="right" class="lefttd" style="width: 198px; height: 30px">
                     <strong>非后台提交权限：<br />
                     </strong></td>
                 <td class="righttd" style="height: 30px">
                    <div ID="GroupPanel" runat="server"></div>
                    <div class="tips">TIPS:不限制请不要勾选，否则只有勾选的用户组才有权限在前台提交数据。</div>
                 </td>
             </tr>
             <tr>
                 <td align="right" class="lefttd" style="width: 198px; height: 30px">
                     <strong>字段状态：<br />
                     </strong></td>
                 <td class="righttd" style="height: 30px">
                     <asp:RadioButtonList ID="Enabled" runat="server" RepeatDirection="Horizontal">
                         <asp:ListItem Selected="True" Value="1">正常</asp:ListItem>
                         <asp:ListItem Value="0">禁用</asp:ListItem>
                     </asp:RadioButtonList></td>
             </tr>
              

        </table>
      <div style="clear:both;text-align:center">
    <br />
        <KS:Foot ID="Foot1" runat="server" OnSubmit="Foot1_Submit" SubmitButtonText="确定添加" />
    </div>
    </asp:Panel>


   </div> 

</asp:Content>
