本文采用Asp技術實現數據導入進度狀態的顯示,代碼如下:
<!– #include file=”inc/dsn.asp” –>
<!–#include file=”inc/vbfun.asp”–>
<form name=”data” action=”” id=”data”>
<input name=”showdata” type=”text” value=”數據正在加載中…” size=”100″>
</form>
<script>
<%
excelurl=request.Form(“file_url”)
gz_year=request.Form(“gz_year”)
gz_month=request.Form(“gz_month”)
if gz_year=”” then
gz_year=year(now())
end if
if gz_month=”” then
gz_month=month(now())
end if
if excelurl<>”” then
set rs=server.CreateObject(“adodb.recordset”)
strexcel=”provider=Microsoft.Jet.OLEDB.4.0; Data Source=”&server.MapPath(excelurl)&”;Extended Properties=Excel 8.0″
set connexcel=CreateObject(“ADODB.Connection”)
connexcel.Open strexcel
Sql=”select * from [sheet1$]”
rs.Open Sql,connexcel
IF rs.Eof And Rs.Bof Then
response.Write(“alert (‘沒有資料可以導入!’);”)
else
Conn.BeginTrans
set rsf=server.CreateObject(“adodb.recordset”)
rsf.open(“select * from gz_infor where gz_year=”&gz_year&” and gz_month=”&gz_month&””) ,conn
if not rsf.eof then
response.write “alert(‘在這個月中您已經導入了一次工資以免重復請核對,該次操作作廢!’);</script>”
response.End()
end if
do while not rs.eof
%>
document.data.showdata.value=”<%=”用戶名:”&rs(1)&” 賬號:”&rs(0)%>”;
<%
process=rs(0)
‘ On Error Resume Next
conn.execute(“importgz ‘”&rs(0)&”‘,'”&rs(1)&”‘,'”&rs(2)&”‘,'”&rs(3)&”‘,'”&rs(4)&”‘,'”&rs(5)&”‘,'”&rs(6)&”‘,'”&rs(7)&”‘,'”&rs(8)&”‘,'”&rs(9)&”‘,'”&rs(10)&”‘,'”&rs(11)&”‘,'”&rs(12)&”‘,'”&rs(13)&”‘,'”&rs(14)&”‘,'”&rs(15)&”‘,'”&rs(16)&”‘,'”&rs(17)&”‘,”&gz_year&”,”&gz_month)
if conn.Errors.Count>0 then
conn.Errors.Clear
conn.RollBackTrans
response.write “<script>alert(導入過程中出現錯誤,該次操作作廢!’);history.back();</Script>”
response.End()
end if
rs.movenext
loop
Conn.CommitTrans
response.Write(“alert(‘成功導入用戶資料’);”)
end if
%>
document.data.showdata.value=”數據導入完畢”;
<%
else
%>
window.alert(“你沒有選擇任何文件”);
document.data.showdata.value=”你沒有選擇任何文件”;
<%
end if
%>
</script>