<!--#include file="../fy.Function.asp"-->
<!doctype html>
<html>
<head>
<meta charset="gb2312">
<title>用户模型管理</title>
<link rel="stylesheet" type="text/css" href="../css/base.css">
<link rel="stylesheet" type="text/css" href="../css/content.css">
</head>
<body>
<div class="content"> 
	<div class="breadnav">当前位置：<a href="#">后台首页</a> >> 模型管理</div>
    <div class="opers">
    	<a href="?A=Add" class="btn">添加模型</a>
    </div>
<% 	Dim Action,ModeID,Rs
	ModeID = ChkNumeric(Request("ModeID"))
	If Not fycms.ChkAdmin() Then   Call fycms.Alert("对不起，你没有操作权限！","")
	Action = Request.QueryString("A")
	 if ModeID=0 or ModeID="" Then ModeID=1
	Select Case Action
		   Case "AddSave","ESave"
		   		Call AddSave()
			Case "Add","E"
				Call AddEdit()
			Case Else
				Call Main()
	End Select
	
	
	IF Action = "Del" Then
		IF ModeID  > 1 Then
			fycms.ACTEXE("Delete From ModeUser_fy Where ModeID=" & ModeID)		
			Call fycms.ActErr("删除模型成功","User/Reg.MX.asp","")
 		Else
			Call fycms.ActErr("系统定义的模型不允许删除","","1")
		End IF
	End IF
	
	
	Sub AddSave()
		 Dim ModeName,ModeTable,sql,ChannelRS,ChannelRSSql,ModeNote,Template,RegCode
		 Dim UpfilesDir,RecyleIF
		 ModeName = fycms.S("ModeName")
		 ModeTable = fycms.S("ModeTable") 
		 ModeNote = fycms.S("ModeNote")
		 Template = fycms.S("Template")
		 RegCode = fycms.S("RegCode")
		 IF fycms.S("ModeName") = "" Then
		 	Call fycms.Alert("模型名称不能为空!",""):Exit Sub
		 End if

		  IF fycms.S("Template") = "" Then
		 	Call fycms.Alert("模板路径不能为空!",""):Exit Sub
		 End if

	 if Action="AddSave" Then
			 IF fycms.S("ModeTable") = "" Then
				Call fycms.Alert("数据表不能为空!",""):Exit Sub
			 End If
			If fycms.defaultField(ModeName,"")=True Then  Call fycms.Alert("数据库中已存在该字段\n或该字段是系统关键字!", "")
			 If Not fycms.ACTEXE("SELECT ModeName FROM ModeUser_fy Where ModeName='" & ModeName & "' order by ModeID desc").eof Then
				Call fycms.Alert("系统已存在该模型名称!",""):Exit Sub
			 End if	
			 If Not fycms.ACTEXE("SELECT ModeTable FROM ModeUser_fy Where ModeTable='" & ModeTable & "' order by ModeID desc").eof Then
				Call fycms.Alert("系统已存在该数据表!",""):Exit Sub
			 End if	
				 Dim sqlformat:If  DataBaseType="access" Then sqlformat=" CONSTRAINT PrimaryKey PRIMARY KEY"
 				 Sql="CREATE TABLE "&ModeTable&" ([ID] int IDENTITY (1, 1) NOT NULL "&sqlformat&" ,"&_
 				"UserID int Default 0,"&_
 				"GroupID int Default 0,"&_
 				"[UserName] nvarchar(250),"&_
 				"[myface] nvarchar(250),"&_
 				"[RealName] nvarchar(250),"&_
 				"OrderID int Default 0"&_
				")"
			'SmallInt 整型,varchar(200)'文本,tinyint 字节, int Default 0 长整型
			fycms.ACTEXE(sql)
		
			 Set ChannelRS = Server.CreateObject("adodb.recordset")
			  ChannelRSSql = "select * from ModeUser_fy"
			  ChannelRS.Open ChannelRSSql, Conn, 1, 3
			  ChannelRS.AddNew
		 	  ChannelRS("ModeTable") = ModeTable
			  ChannelRS("ModeName") = ModeName
			  ChannelRS("ModeNote") = ModeNote
			  ChannelRS("Template") = Template
			  ChannelRS("RegCode") = RegCode
		 	  ChannelRS("SpaceID") = ChkNumeric(Request("SpaceID"))
			  ChannelRS.Update
			  ChannelRS.Close:Set ChannelRS = Nothing			
			
			
			
			Call fycms.ActErr("操作成功","User/Reg.MX.asp","")
 		 
		 Else
		 	If Not fycms.ACTEXE("SELECT ModeName FROM ModeUser_fy Where ModeID <>" & ModeID & " AND  ModeName='" & ModeName & "' order by ModeID desc").eof Then
				Call fycms.Alert("系统已存在该模型名称-!",""):Exit Sub
			 End if	
			 Set ChannelRS = Server.CreateObject("adodb.recordset")
			  ChannelRSSql = "select * from ModeUser_fy Where ModeID=" &ModeID
			  ChannelRS.Open ChannelRSSql, Conn, 1, 3
			  if ChannelRS.eof then Call fycms.Alert("错误!",""):Exit Sub
		 End if 
		  ChannelRS("ModeName") = ModeName
		  ChannelRS("ModeNote") = ModeNote
		  ChannelRS("Template") = Template
		  ChannelRS("RegCode") = RegCode
		  ChannelRS("SpaceID") = ChkNumeric(Request("SpaceID"))
 		  ChannelRS.Update
		  ChannelRS.Close:Set ChannelRS = Nothing
		  Call fycms.ActErr("操作成功","User/Reg.MX.asp","")	
 	End Sub
	Sub Main()
	%>	
 	<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <thead>
      <tr>
      <th>用户组名称</th>
	  <th>表名</th>
	  <th>类型</th>
	  <th>描述</th>
	  <th>注册默认用户组</th>
	  <th>操作</th>
	  </tr>
    </thead>
<% 
	  Set Rs =fycms.ACTEXE("SELECT ModeID, ModeName,ModeTable, ModeNote  FROM ModeUser_fy order by ModeID asc")
	 If Rs.EOF  Then
	 	echo	"<tr><td colspan=""6"" >没有记录</td></tr>"
	 Else
		Do While Not Rs.EOF	
			 %>

  <tr>
    <td><%= Rs("ModeName") %></td>
    <td><%= Rs("ModeTable") %></td>
    <td><% if Rs("ModeID")<2 Then echo "<font color=red>系统</font>" Else  echo "<font color=blue>自定义</font>"  %></td>
    <td><%= Rs("ModeNote") %></td>
    <td>
	<%Dim rss		
		Set Rss = fycms.ACTEXE("SELECT GroupName FROM Group_fy Where DefaultGroup=1 and  ModeID=" & Rs("ModeID") & " order by ModeID desc")
			 If rss.eof Then 
				echo "<a href=""Group.fy.asp""><font color=red>还未设置默认用户组</font></a>"
			 Else
				echo rss(0)
			 End if	
%>
	
	
	</td>
	<td><a href="Reg.M.ASP?A=L&ModeID=<%=Rs("ModeID")  %>">字段列表</a> ┆ <a href="?A=E&ModeID=<%=Rs("ModeID")  %>" >修改</a>
	<%if Rs("ModeID")>1 Then %>
	┆ <a href="?A=Del&ModeID=<%=Rs("ModeID")  %>"   onClick="{if(confirm('确定删除该模型吗?')){return true;}return false;}">删除</a>
	<%
	Else
	echo "┆  <a href=""#"" disabled=""disabled"">删除</a>"
	
	End if%></td>
  </tr>
  <% 
 		Rs.movenext
		Loop
	End if	 %>

	
	</table>
   
<% 	
 
	End Sub
	Sub AddEdit()


	Dim FileFolder,ModeTable,ModeName,RegCode,ModeNote,A,Template,SpaceID
	if Action="Add" Then
	A="AddSave"
	Else
	Set Rs=server.CreateObject("adodb.recordset") 
	Rs.OPen "Select * from ModeUser_fy Where ModeID = "&ModeID&" order by ModeID desc",Conn,1,1
	ModeTable = Rs("ModeTable")
	ModeName = Rs("ModeName")
	ModeNote=Rs("ModeNote")
	RegCode=Rs("RegCode")
	Template=Rs("Template")
	SpaceID=Rs("SpaceID")
	A="ESave"
	end if
   %>
 
<form id="form1" name="form1" method="post" action="?A=<%= A %>&ModeID=<%= Request.QueryString("ModeID") %>">
    <div class="divtable"> 
        <dl>
            <dt>模型名称：</dt>
            <dd>
               <input name="ModeName" type="text"   class="Ainput" id="ModeName" value="<%=ModeName %>" />
            </dd>
         </dl>
        
        <dl>
            <dt>数据表名称：</dt>
            <dd>
               <input <% if A="ESave" then echo "disabled" %> name="ModeTable" type="text"  class="Ainput" id="ModeTable" value="<%= ModeTable %>" />
             </dd>
         </dl>
        <dl>
            <dt>模型描述：</dt>
            <dd>
               <input name="ModeNote" type="text"   class="Ainput" id="ModeNote" value="<%= ModeNote %>" size="50" maxlength="250" />
        简单的描述.不能超过250个字符 
             </dd>
         </dl>
        <dl>
            <dt>注册验证码：</dt>
            <dd>
                <input  <% IF RegCode = 0 Then echo "Checked" %> id="RegCode1" type="radio" name="RegCode" value="0">
        <label for="RegCode1">显示</label>
      <input  <% IF RegCode = 1 Then echo "Checked" %> id="RegCode2"  type="radio" name="RegCode" value="1"> 
     <label for="RegCode2">不显示</label>
             </dd>
         </dl>
        <dl>
            <dt>模板路径：</dt>
            <dd>
               <input name="Template" type="text"   class="Ainput" id="Template" value="<%=Template%>" />
             </dd>
         </dl>
        <dl>
            <dt>默认栏目：</dt>
            <dd>
               <select name="SpaceID" id="SpaceID">
          <% 
	  dim rs
	 Set Rs =fycms.ACTEXE("SELECT ID, ClassName  FROM space_fy where UModeID="&modeid&" order by ID asc")
	 If Rs.EOF  Then
	 	echo	"<option>没有记录,请先添加</option>"
	 Else
		Do While Not Rs.EOF	 %>
          <option value="<%= rs("ID") %>" <%if rs("ID")=SpaceID then echo " Selected" %>><%= rs("ClassName") %></option>
          <% 
 		Rs.movenext
		Loop
	End if	 %>
	    </select>
             </dd>
         </dl>
             <dl>
            <dt class="vhid">提交：</dt>
            <dd>
                <a class="btn btn_primary" href="javascript:void(0);" onclick="CheckForm()">提交</a>
                <input type="reset" name="Submit2" class="btn btn_primary" value="  重置  " />
            </dd>
         </dl>
        
    </div>
    </form>

<% end sub  %>

</div>
<script language="JavaScript" type="text/javascript">

function CheckForm()
{ var form=document.form1;
	
	 if (form.ModeName.value=='')
		{ alert("请输入模型名称!");   
		  form.ModeName.focus();    
		   return false;
		} 
	 if (form.ModeTable.value=='')
		{ alert("请输入数据表名称!");   
		  form.ModeTable.focus();    
		   return false;
		} 
		
		
	 if (form.Template.value=='')
		{ alert("请输入模板路径!");   
		  form.Template.focus();    
		   return false;
		} 
	    form.submit();
        return true;
	}
</script>
</body>
</html>
