<!--#include file="../Lib/Config.asp"-->
<!--#include file="../Lib/DBConn.asp"-->
<!--#include file="../Lib/DBLib.asp"-->
<!--#include file="../Lib/func.asp"-->

<%
Session.CodePage = "65001"

Dim Query,SQL,ExRs,RSS,TableSource,i,item,TB
Query = "SELECT * FROM [vDat_"& Request("Project_Codes") &"] order by [시작시간]"

SQL = Query

DBConnect()
set ExRs = DBConn.Execute (SQL)			

Dim RStr,iCnt,objArray,TRS,HSTR,HHSTR

Set objArray = Server.CreateObject("Scripting.Dictionary")

If ExRs.Eof Or ExRs.Bof Then
	RSTr = "데이터가 없습니다"
Else
	
	HSTR = ""

	for iCnt=0 to ExRs.fields.count-1
		If objArray.Exists(ExRs.fields(iCnt).name) Then
			HSTR = HSTR & "<td >" & objArray.Item(ExRs.fields(iCnt).name)
		Else
			HSTR = HSTR & "<td >" & ExRs.fields(iCnt).name
		End If

		HHSTR = HHSTR & "[" & ExRs.fields(iCnt).name & "]"

		If iCnt<ExRs.fields.count-1 Then
			'HSTR = HSTR & vbTab
			HSTR =  HSTR & "</td>"
			HHSTR = HHSTR & ","
		End IF
		'TableSource = TableSource & vbtab & vbtab & "<td align='center'>" & rss.fields(i).name & "</td>" & vbcrlf
	Next
	EXRs.Close
	Set EXRs = Nothing

	Dim EXSQL
	EXSQL = "SELECT '<tr><td>""""'," & HHSTR & ",'""""</td></tr>' FROM [vDat_"&Request("Project_Codes")&"]  order by [시작시간]"

'	Response.Write EXSQL
'	Response.End

	'Set ExRs = DBHelper.ExecSQLReturnRS(ExSQL,Nothing,GetDBStr())

	Response.WRite ExSQL
	set ExRs = DBConn.Execute (ExSQL)


	'Q_GetRecordSet EXSQL,EXRs
	HSTR = HSTR & "</td>"
	RStr = EXRs.GetString(2)
	
'	TRS.Close
End If

ExRs.Close
Set objArray = Nothing

  Response.Buffer = True
  Response.ContentType = "appllication/vnd.ms-excel" 
  Response.CacheControl = "public"

' 파일 다운로드 창에서 열기,저장을 선택했을때 부터 데이터를 전송합니다. 
  Response.AddHeader "Content-Disposition","attachment; filename=" & Request("Project_Codes") & "_Data.xls"

	RSTr = Replace(RStr,vbTab,"</td><td style=""mso-number-format:'\@'"">")
	RSTr = Replace(RStr,"<td>""""</td>","")
	RSTr = Replace(RStr,"<td style=""mso-number-format:'\@'"">""""</td>","")


%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table width='98%' cellpadding='0' cellspacing='0' border='1' >
	<tr>
	<%=HSTR%>
	</tr>
	<%=RStr%>
</table>
</body>
</html>
