不知道有没有帮助,N年前写的代码,比较菜
<%response.buffer=false
Server.ScriptTimeOut=5000%>
<link href="command/jsmis.css" rel="stylesheet" type="text/css">
<!--#include file="ConnDataBase.asp"-->
<!--#include file="CheckForm_JS.asp"-->
<%
Dim errStr
errStr="Client_Area|1|客户所属地区必须选择!"
Call checkform_js("form1",errStr)
function checkStr(str, ch) '判断记录格式
checkStr=UBound(split(str,ch))+1
end function
function isRd00100(str) '判断是否是Ctais一般纳税人档案文件
isRd00100=false
if not txt.atendofstream then
if instr(txt.ReadLine,str)<>0 then
isRd00100=true
end if
end if
end function
function ClientIsNew(Client_Name) '根据名称判断是否是新的客户信息
if conn.execute("Select * from Client Where Client_name='"&Client_Name&"'").eof then
ClientIsNew=true
else
ClientIsNew=false
end if
end function
function Append(ClientTxt,UpdateClient) '保存客户数据
abcd=split(ClientTxt,"~~")
if UBound(abcd)+1=30 then
Client_Name=abcd(16)
Client_Address=abcd(17)
Client_Phone=abcd(19)
Client_Linkman=abcd(20)
Client_Qy_TaxNum=abcd(1)
Client_Qy_Revenue=abcd(24)
Client_Qy_HowMach=abcd(26)
Client_Qy_Princial_Phone=abcd(20)+space(1)+abcd(19)
Client_Qy_Account=abcd(28)+abcd(29)
Client_Qy_Range=abcd(25)
Client_Area=Request("Client_Area")
Client_Kind="企业用户"
Client_Status="1"
'假如判断客户是否存在
'客户所属地区选择!
'更新客户信息或跳过选择
if ClientIsNew(Client_Name)=true then
strSql="Insert Into Client (Client_Name,Client_ShortName,Client_Address,Client_Phone,Client_Linkman,"
strSql=strSql+"Client_Area,Client_Kind,Client_Status,Client_Remark,Client_Qy_TaxNum,Client_Qy_Kind,"
strSql=strSql+"Client_Qy_Revenue,Client_Qy_Range,Client_Qy_HowMach,Client_Qy_Size,Client_Qy_Princial_Phone,"
strSql=strSql+"Client_Qy_Account,Client_Gr_WorkUnit,Client_Gr_Kind,Client_Gr_Workaddress,Client_Gr_Workphone,"
strSql=strSql+"Client_Gr_Department,Client_Gr_Headship,Client_Sy_Kind,Client_Sy_Linkman_Phone,Client_Sy_Headship,"
strSql=strSql+"Client_Sy_Department) values ("
strSql=strSql+"'"+ Client_Name +"',dbo.getPY('"+ Client_Name +"'),'"+ Client_Address +"',"
strSql=strSql+"'"+ Client_Phone +"','"+ Client_Linkman +"','"+ Client_Area +"',"
strSql=strSql+"'"+ Client_Kind +"',"+ Client_Status +",'"+ Client_Remark +"','"+ Client_Qy_TaxNum +"',"
strSql=strSql+"'"+ Client_Qy_Kind +"','"+ Client_Qy_Revenue +"','"+ Client_Qy_Range +"',"
strSql=strSql+"'"+ Client_Qy_HowMach +"','"+ Client_Qy_Size +"','"+ Client_Qy_Princial_Phone +"',"
strSql=strSql+"'"+ Client_Qy_Account +"','"+ Client_Gr_WorkUnit +"','"+ Client_Gr_Kind +"',"
strSql=strSql+"'"+ Client_Gr_Workaddress +"','"+ Client_Gr_Workphone +"','"+ Client_Gr_Department +"',"
strSql=strSql+"'"+ Client_Gr_Headship +"','"+ Client_Sy_Kind +"','"+ Client_Sy_Linkman_Phone +"',"
strSql=strSql+"'"+ Client_Sy_Headship +"','"+ Client_Sy_Department +"')"
Append="Insert"
Set rs=conn.execute(strSql)
end if
if ClientIsNew(Client_Name)=false and UpdateClient="Yes" then
strSQL="Update Client Set Client_Name='"+ Client_Name +"',Client_ShortName=dbo.getPY('"+ Client_Name +"'),"
strSQL=strSQL+"Client_Address='"+ Client_Address +"',Client_Phone='"+ Client_Phone +"',"
strSQL=strSQL+"Client_Linkman='"+ Client_Linkman +"',Client_Kind='"+ Client_Kind +"',"
strSQL=strSQL+"Client_Status="+ Client_Status +",Client_Remark='"+ Client_Remark +"',"
strSQL=strSQL+"Client_Qy_TaxNum='"+ Client_Qy_TaxNum +"',Client_Qy_Kind='"+ Client_Qy_Kind +"',"
strSQL=strSQL+"Client_Qy_Revenue='"+ Client_Qy_Revenue +"',Client_Qy_Range='"+ Client_Qy_Range +"',"
strSQL=strSQL+"Client_Qy_HowMach='"+ Client_Qy_HowMach +"',Client_Qy_Size='"+ Client_Qy_Size +"',"
strSQL=strSQL+"Client_Qy_Princial_Phone='"+ Client_Qy_Princial_Phone +"',Client_Qy_Account='"+ Client_Qy_Account +"',"
strSQL=strSQL+"Client_Gr_WorkUnit='"+ Client_Gr_WorkUnit +"',Client_Gr_Kind='"+ Client_Gr_Kind +"',"
strSQL=strSQL+"Client_Gr_Workaddress='"+ Client_Gr_Workaddress +"',Client_Gr_Workphone='"+ Client_Gr_Workphone +"',"
strSQL=strSQL+"Client_Gr_Department='"+ Client_Gr_Department +"',Client_Gr_Headship='"+ Client_Gr_Headship +"',"
strSQL=strSQL+"Client_Sy_Kind='"+ Client_Sy_Kind +"',Client_Sy_Linkman_Phone='"+ Client_Sy_Linkman_Phone +"',"
strSQL=strSQL+"Client_Sy_Headship='"+ Client_Sy_Headship +"',Client_Sy_Department='"+ Client_Sy_Department +"'"
strSQL=strSQL+" Where Client_Name = '"&Client_Name&"'"
Append="Update"
Set rs=conn.execute(strSQL)
end if
end if
end function
if request("action")="append" then
times=now()
AnalyseFlag=false '标记
set fs=server.CreateObject("scripting.filesystemobject")
set Rs=conn.Execute("select * from Upfiles where Upfiles_Id="&Request("Upfiles_Id") )
If not Rs.eof then
filename=LEFT(Server.Mappath(Request.ServerVariables("PATH_INFO")), InStrRev(Server.Mappath(Request.ServerVariables("PATH_INFO")), "\")) &Rs("Upfiles_Path")&Rs("Upfiles_Name")
if fs.FileExists(filename)=true then
AnalyseFlag=true
response.Write "在服务器已找到你选择要导入的文件!<br>"
else
AnalyseFlag=false
response.Write "你选择的文件在服务器上已不存在!请[<a href="javascript:history.back();">重新选择</a>]"
response.End
end if
else
response.Write "文件编号传送错误,请[<a href="javascript:history.back();">重新选择</a>]"
End if
set Rs=nothing
Set txt = fs.OpenTextFile(filename,1) '1表示只读
AnalyseFlag=isRd00100("BEGIN")
AnalyseFlag=isRd00100("RD00100")
AnalyseFlag=isRd00100("{")
AnalyseFlag=isRd00100("增值税一般纳税人档案")
AnalyseFlag=isRd00100("1~~")
AnalyseFlag=isRd00100("2~~3~~")
if AnalyseFlag=false then
response.Write "你选择的文件不是Ctais导出的一般纳税人档案文件!请[<a href="javascript:history.back();">重新选择</a>]"
response.End
end if
rline = space(0)
rightcount=0
errorcont=0
insertcount=0
updatecount=0
response.Write "正在读取文本文件信息,并进行转换,可能需要花费几分钟。请稍候..."
do while not txt.atendofstream
str=txt.ReadLine
if checkStr(str, "~~")=30 then
AppendStatus=Append(str,request("UpdateClient"))
if AppendStatus="Insert" then
insertcount=insertcount+1
end if
if AppendStatus="Update" then
updatecount=updatecount+1
end if
rightcount=rightcount+1
else
errorcont=errorcont+1
end if
loop
txt.close
response.write "<br>文本文件导入完毕!"
response.write "<br>正确记录数:"&rightcount
response.write "<br>错误记录数:"&errorcont
response.write "<br>插入记录数:"&insertcount
response.write "<br>更新记录数:"&updatecount
response.write "<br>页面执行时间:"&DateDiff("s",times,Now())&"秒"
conn.execute("Update Upfiles Set Upfiles_Conver=Upfiles_Conver+1 Where Upfiles_Id="&Request("Upfiles_Id"))
response.write "<br><br> [<a href="Client_Append.asp">返回上传文件列表</a>]"
response.end
end if
%>
<form name="form1" method="post" action="?action=append" onsubmit="javascript:return checkSubmit()">
<p>
<input type="hidden" name="act" value="upload">
</p>
<table width="70%" align="center" border="1" bordercolorlight='#999999' bordercolordark='#FFFFFF' cellpadding="1" cellspacing="0">
<tr valign="middle" bgcolor="#FFFFFF">
<td height="25" colspan="2" background="images/bg_title.gif">客户信息导入选项:</td>
</tr>
<tr align="center" valign="middle">
<td height="92" align="center" bgcolor="#ffffff" id="upid">
<input name="Upfiles_Id" type="hidden" id="Upfiles_Id" value="<%=request("Upfiles_Id") %>">
说明: </td>
<td height="92" align="left" bgcolor="#FFFFFF" id="upid">
<p>1、导入客户信息根据文件大小所用的时间会有所不同,开始后请耐心等待……</p>
<p>2、<Font Color="Red">客户所属地区一定要选择正确,导入后将无法修改。</Font></p>
<p>3、导入过程中请不要关闭浏览器或手工刷新页面。</p></td>
</tr>
<tr align="center" valign="middle" bgcolor="#f6f6f6">
<td height="38" align="center">客户所属地区:</td>
<td height="38" align="left">
<select name="Client_Area" id="select">
<option selected>选择地区</option>
<option value="aa">aa</option>
<option value="bb">bb</option>
<option value="cc">cc</option>
<option value="dd">dd</option>
</select></td>
</tr>
<tr align="center" valign="middle">
<td width="19%" height="36" align="center">更新设置:</td>
<td width="81%" align="left"><input name="UpdateClient" type="radio" value="No" checked>
如果客户信息已经存在,跳过
<input type="radio" name="UpdateClient" value="Yes">
不,我要更新客户信息!</td>
</tr>
<tr align="center" valign="middle">
<td height="52" colspan="2" bgcolor="#f6f6f6">
<input name="Submit" type="submit" class="Button" value="开始导入">
<input type="reset" name="Submit" value="重新选择" class="Button"></td>
</tr>
</table>
</form>