<%
Function GetRandomID18()
	Dim TempYear,TempMonth,TempDay,TempHour,TempMinute,TempSecond,RandomFigure
	Dim TempStr,NowTime
	NowTime = Now()
	TempYear =  Right(CStr(Year(NowTime)),2)
	TempMonth =  CStr(Month(NowTime))
	if Len(TempMonth) = 1 then
		TempHour = "0" & TempMonth
	end if
	TempDay =  CStr(Day(NowTime))
	if Len(TempDay) = 1 then
		TempHour = "0" & TempDay
	end if
	TempHour = CStr(Hour(NowTime))
	if Len(TempHour) = 1 then
		TempHour = "0" & TempHour
	end if
	TempMinute = CStr(Minute(NowTime))
	if Len(TempMinute) = 1 then
		TempMinute = "0" & TempMinute
	end if
	TempSecond = CStr(Second(NowTime))
	if Len(TempSecond) = 1 then
		TempSecond = "0" & TempSecond
	end if
	Randomize 
	RandomFigure = CStr(Int((99999 * Rnd) + 1))
	GetRandomID18 = TempYear & TempMonth & TempDay & TempHour & TempMinute & TempSecond & RandomFigure
End Function

Function ListDBAllTable(DBType,DBServer,DBName,DBUser,DBPassWord)
	Dim Sql,ConnStr,TempConn,RsTempObj,ReturnStr
	ReturnStr = ""
	if DBType = 1 then 'Sql Server
		ConnStr = "Provider=SQLOLEDB.1;Persist Security Info=False;Server=" & DBServer & ";User ID=" & DBUser & ";Password=" & DBPassWord & ";Database=" & DBName & ";"
		On Error Resume Next
		Set TempConn = Server.CreateObject("ADODB.Connection") 
		TempConn.Open ConnStr
		if Err.Number <> 0 then
			ListDBAllTable = Array()
			Set TempConn = Nothing 
			Exit Function
		end if 
		Sql = "SELECT Name FROM sysobjects WHERE (xtype = 'U') AND (status > 0)"
		Set RsTempObj = TempConn.Execute(Sql)
		do while Not RsTempObj.Eof
			if ReturnStr = "" then
				ReturnStr = RsTempObj("Name")
			else
				ReturnStr = ReturnStr & "$$$" & RsTempObj("Name")
			end if
			RsTempObj.MoveNext
		Loop
		Set RsTempObj = Nothing
		Set TempConn = Nothing
		ListDBAllTable = Split(ReturnStr,"$$$")
	elseif DBType = 2 then 'Access
		Dim RSSchema
		if DBName = "1" then
			ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBServer & ";Jet OLEDB:Database Password=" & DBPassWord & ";Persist Security Info=False"
		else
			ConnStr="DBQ="+Server.MapPath(DBServer)+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
		end if
		Set TempConn=Server.CreateObject("ADODB.Connection")
		TempConn.Open ConnStr
		if Err.Number <> 0 then
			ListDBAllTable = Array()
			Set TempConn = Nothing 
			Exit Function
		end if 
		Set RSSchema=TempConn.OpenSchema(20)
		RSSchema.MoveFirst
		Do Until RSSchema.EOF
			if RSSchema("TABLE_TYPE") = "TABLE" then
				if ReturnStr = "" then
					ReturnStr = RSSchema("TABLE_NAME")
				else
					ReturnStr = ReturnStr & "$$$" & RSSchema("TABLE_NAME")
				end if
			end if
			RSSchema.MoveNext
		Loop
		Set RSSchema = Nothing
		Set TempConn=nothing
		ListDBAllTable = Split(ReturnStr,"$$$")
	else 'None
		ListDBAllTable = Array()
	end if
End Function

Function ListAllFieldOfTable(DBType,DBServer,DBName,DBUser,DBPassWord,DBTable)
	Dim Sql,ConnStr,TempConn,RsTempObj,ReturnStr,FiledObj
	Dim IsRequested,IsRequestedStr
	Const adFldIsNullable = &H00000020
	ReturnStr = ""
	if DBType = 1 then 'Sql Server
		ConnStr = "Provider=SQLOLEDB.1;Persist Security Info=False;Server=" & DBServer & ";User ID=" & DBUser & ";Password=" & DBPassWord & ";Database=" & DBName & ";"
	elseif DBType = 2 then 'Access
		if DBName = "1" then
			ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBServer & ";Jet OLEDB:Database Password=" & DBPassWord & ";Persist Security Info=False"
		else
			ConnStr = "DBQ=" + server.mappath(DBServer) + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
		end if
	else 'None
		ConnStr = ""
	end if
	if ConnStr <> "" then
		On Error Resume Next
		Set TempConn = Server.CreateObject("ADODB.Connection") 
		TempConn.Open ConnStr 
		Sql = "Select * from [" & DBTable & "] where 1=0"
		Set RsTempObj = TempConn.Execute(Sql)
		if Err.Number <> 0 then
			ListAllFieldOfTable = ""
			Set RsTempObj = Nothing
			Set TempConn = Nothing
			Exit Function
		end if
		for Each FiledObj in RsTempObj.Fields
			IsRequested = ((FiledObj.Attributes And adFldIsNullable) = 0)
			if IsRequested then
				IsRequestedStr = "True"
			else
				IsRequestedStr = "False"
			end if
			IsRequestedStr = IsRequestedStr & "|" & GetFieldType(FiledObj.Type)
			IsRequestedStr = "<" & IsRequestedStr & ">"
			if ReturnStr = "" then
				ReturnStr = FiledObj.Name & IsRequestedStr  ' & "---" & FiedlObj.ActualSize
			else
				ReturnStr = ReturnStr & "$$$" & FiledObj.Name & IsRequestedStr ' & "---" & FiedlObj.ActualSize
			end if
		Next
		Set RsTempObj = Nothing
		ListAllFieldOfTable = ReturnStr
	else
		ListAllFieldOfTable = ""
	end if
End Function

Function GetFieldType(FieldType)
	Select Case FieldType
		Case 0
			GetFieldType = "Empty"
		Case 16
			GetFieldType = "TinyInt"
		Case 2
			GetFieldType = "SmallInt"
		Case 3
			GetFieldType = "Integer"
		Case 20
			GetFieldType = "BigInt"
		Case 17
			GetFieldType = "UnsignedTinyInt"
		Case 18
			GetFieldType = "UnsignedSmallInt"
		Case 19
			GetFieldType = "UnsignedInt"
		Case 21
			GetFieldType = "UnsignedBigInt"
		Case 4
			GetFieldType = "Single"
		Case 5
			GetFieldType = "Double"
		Case 6
			GetFieldType = "Currency"
		Case 14
			GetFieldType = "Decimal"
		Case 131
			GetFieldType = "Numeric"
		Case 11
			GetFieldType = "Boolean"
		Case 10
			GetFieldType = "Error"
		Case 132
			GetFieldType = "UserDefined"
		Case 12
			GetFieldType = "Variant"
		Case 9
			GetFieldType = "IDispatch"
		Case 13
			GetFieldType = "IUnknown"
		Case 72
			GetFieldType = "GUID"
		Case 7
			GetFieldType = "Date"
		Case 133
			GetFieldType = "DBDate"
		Case 134
			GetFieldType = "DBTime"
		Case 135
			GetFieldType = "DBTimeStamp"
		Case 8
			GetFieldType = "BSTR"
		Case 129
			GetFieldType = "Char"
		Case 200
			GetFieldType = "VarChar"
		Case 201
			GetFieldType = "LongVarChar"
		Case 130
			GetFieldType = "WChar"
		Case 202
			GetFieldType = "VarWChar"
		Case 203
			GetFieldType = "LongVarWChar"
		Case 128
			GetFieldType = "Binary"
		Case 204
			GetFieldType = "VarBinary"
		Case 205
			GetFieldType = "LongVarBinary"
		Case 136
			GetFieldType = "Chapter"
		Case 64
			GetFieldType = "FileTime"
		Case 138
			GetFieldType = "PropVariant"
		Case 139
			GetFieldType = "VarNumeric"
		Case &H2000
			GetFieldType = "Array"
	End Select
End Function
%>