<% 
Dim action,ModeID,Rs,UploadSize,UploadPath,UnlockTime,FormCode,ifuser,StartTime,Endtime,UserGroupList,SubmitNum,Moneys,ModeStatus
	ModeID = skweboa.Return_to_numerical(Request("ModeID"))
	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
	        TableName=skweboa.SK_axe("select ModeTable from ModeForm_skweb Where ModeID=" & ModeID & " ")(0) 
			skweboa.SK_axe("Delete From ModeForm_skweb Where ModeID=" & ModeID)		
		    Conn.execute("Drop table "&TableName&"") '删除数据表
			skweboa.SK_axe("Delete from Table_skweb  Where ModeID="&ModeID&" and  skweboa=3 ")
			 Call  skweboa.SK_log(server.MapPath(""&MyDbPath&"SKCMS/log/adminlog.cs"),""  & now() &"  - "&admininame&" 删除了 "&TableName&" 表单  <br><br>",true) 
			Call skweboa.SK_window("删除表单成功","" & Request.ServerVariables("HTTP_REFERER") & "","","")
 	End IF
	
	
	Sub AddSave()
		 Dim ModeName,ModeTable,sql,skarsq,skarsqSql,ModeNote
		 Dim UpfilesDir,RecyleIF
	adminemail=skweboa.S("adminemail")
	adminmoblie=skweboa.S("adminmoblie")
		 
		 ModeName = skweboa.S("ModeName")
		 ModeTable = skweboa.S("ModeTable")&"_Form_skweb"
		 ModeNote = skweboa.S("ModeNote")
		 UploadPath = skweboa.S("UploadPath")
		 UploadSize = skweboa.Return_to_numerical(skweboa.S("UploadSize"))
		 UnlockTime = skweboa.Return_to_numerical(skweboa.S("UnlockTime"))
		 StartTime = skweboa.S("StartTime")
		 EndTime = skweboa.S("EndTime")
		 suinfo = skweboa.S("suinfo")
		 sjtz = skweboa.S("sjtz")		 
		 yjtz = skweboa.S("yjtz")				 
		 UserGroupList = skweboa.S("UserGroupList")
		 SubmitNum = skweboa.Return_to_numerical(skweboa.S("SubmitNum"))
		 ModeStatus = skweboa.Return_to_numerical(skweboa.S("ModeStatus"))
		 Moneys = skweboa.S("Moneys")
		 If Not IsNumeric(Moneys) Then Moneys=0
		 If  UserGroupList =""  Then UserGroupList=0
		 FormCode = skweboa.Return_to_numerical(skweboa.S("FormCode"))
		 ifuser = skweboa.Return_to_numerical(skweboa.S("ifuser"))
		 mailcong = skweboa.S("mailcong")
		 adminmailcong = skweboa.S("adminmailcong")		 
		 admimail= skweboa.S("admimail")	
		 jbxxuser=skweboa.Return_to_numerical(skweboa.S("jbxxuser"))
		 MobileCODE=skweboa.Return_to_numerical(skweboa.S("MobileCODE"))
		 IF skweboa.S("ModeName") = "" Then
		  Call skweboa.SK_window("表单名称为空","","1","3") :Exit Sub
		 End if
		 IF Not IsDate(StartTime) Then StartTime=Now
		 IF Not IsDate(EndTime) Then EndTime=Now+10
		 if action="AddSave" Then
			 IF skweboa.S("ModeTable") = "" Then
			 Call skweboa.SK_window("数据表为空","","1","3") :Exit Sub
			 End if
			 If Not skweboa.SK_axe("SELECT ModeName FROM ModeForm_skweb Where ModeName='" & ModeName & "' order by ModeID desc").eof Then
			 Call skweboa.SK_window("系统已存在该表单名称","","1","3") :Exit Sub
			 End if	
			 If Not skweboa.SK_axe("SELECT ModeTable FROM ModeForm_skweb Where ModeTable='" & ModeTable & "' order by ModeID desc").eof Then
			 Call skweboa.SK_window("系统已存在该数据表","","1","3"):Exit Sub
			 End if	
			 Set skarsq = Server.CreateObject("adodb.recordset")
			  skarsqSql = "select * from ModeForm_skweb"
			  skarsq.Open skarsqSql, Conn, 1, 3
			  skarsq.AddNew
		 	  skarsq("ModeTable") = ModeTable
			  skarsq("ModeName") = ModeName
			  skarsq("ModeNote") = ModeNote
			  skarsq("UploadPath") = UploadPath
			  skarsq("UploadSize") = UploadSize
			  skarsq("UnlockTime") = UnlockTime
			  skarsq("StartTime") = StartTime
			  skarsq("EndTime") = EndTime
			  skarsq("UserGroupList") = UserGroupList
			  skarsq("SubmitNum") = SubmitNum
			  skarsq("Moneys") = Moneys
			  skarsq("FormCode") = FormCode
		      skarsq("ifuser") = ifuser
			  skarsq("ModeStatus") = ModeStatus
			  skarsq("mailcong") = mailcong			  
			  skarsq("adminmailcong") = adminmailcong
			  skarsq("admimail") = admimail	
			  skarsq("suinfo") = suinfo
			  skarsq("jbxxuser") = jbxxuser				  
			  skarsq("MobileCODE") = MobileCODE		
			  skarsq("sjtz") = sjtz				  
			  skarsq("yjtz") = yjtz				  
			  skarsq("adminemail") = adminemail			  
			  skarsq("adminmoblie") =adminmoblie	
 
			  		  
			  skarsq.Update
			  skarsq.Close:Set skarsq = Nothing			
				 Dim sqlformat:If  DataBaseType="access" Then sqlformat=" CONSTRAINT PrimaryKey PRIMARY KEY"
 				 Sql="CREATE TABLE "&ModeTable&" ([ID] int IDENTITY (1, 1) NOT NULL "&sqlformat&" ,"&_
				"UpdateTime datetime,"&_
				"ModeID SmallInt Default 0,"&_
				"UModeID SmallInt Default 0,"&_
				"Sh SmallInt Default 0,"&_
				"HH text,"&_
				"Email text,"&_		
				"Mobile text,"&_
				"name text,"&_	
				"UserIP varchar(50),"&_
				"UserID int Default 0 "&_
				")"
			'SmallInt 整型,varchar(200)'文本,tinyint 字节, int Default 0 长整型
			skweboa.SK_axe(sql)
		    Call skweboa.SK_window("添加成功",""&MyDbPath&"SKCMS/dialog.asp?action=closmain","","3")
 		 Else
		 	If Not skweboa.SK_axe("SELECT ModeName FROM ModeForm_skweb Where ModeID <>" & ModeID & " AND  ModeName='" & ModeName & "' order by ModeID desc").eof Then
		  Call skweboa.SK_window("系统已存在该表单名称","","1","3"):Exit Sub
			 End if	
			 Set skarsq = Server.CreateObject("adodb.recordset")
			  skarsqSql = "select * from ModeForm_skweb Where ModeID=" &ModeID
			  skarsq.Open skarsqSql, Conn, 1, 3
			  if skarsq.eof then Call skweboa.Alert("错误!",""):Exit Sub
		 End if 
			  skarsq("ModeName") = ModeName
			  skarsq("ModeNote") = ModeNote
			  skarsq("UploadPath") = UploadPath
			  skarsq("UploadSize") = UploadSize
			  skarsq("UnlockTime") = UnlockTime
			  skarsq("StartTime") = StartTime
			  skarsq("EndTime") = EndTime
			  skarsq("UserGroupList") = UserGroupList
			  skarsq("SubmitNum") = SubmitNum
			  skarsq("Moneys") = Moneys
			  skarsq("FormCode") = FormCode
			  skarsq("ifuser") = ifuser
			  skarsq("ModeStatus") = ModeStatus
			  skarsq("mailcong") = mailcong			  
			  skarsq("adminmailcong") = adminmailcong
			  skarsq("admimail") = admimail	
			  skarsq("suinfo") = suinfo
			  skarsq("jbxxuser") = jbxxuser	
			  skarsq("MobileCODE") = MobileCODE	
			   skarsq("sjtz") = sjtz				  
			  skarsq("yjtz") = yjtz		
			  skarsq("adminemail") = adminemail			  
			  skarsq("adminmoblie") =adminmoblie	
		  skarsq.Update
		  skarsq.Close:Set skarsq = Nothing	
          Call  skweboa.SK_log(server.MapPath(""&MyDbPath&"SKCMS/log/adminlog.cs"),""  & now() &"  - ["&Request.Cookies(SkcmsCookies)("AdminName")&"]  IP: "&skweboa.SK_GetIP()&" 修改了表单"&ModeName&" <br><br>",true) 
		  Call skweboa.SK_window("修改成功",""&MyDbPath&"SKCMS/dialog.asp?action=closmain","","3")
 	End Sub
	Sub Main()
	%>	