<Form action = "insert. asp" method = "Post" enctype = "multipart/form-Data" name = "form1" onsubmit = "b1_onclick ()">
<Table width = "500" border = "1" align = "center" cellpadding = "0" cellspacing = "0">
<Tr>
<TD colspan = "2" bgcolor = "#999999" class = "T"> select a file
</TD>
</Tr>
<Tr>
<TD colspan = "2" class = "T"> & nbsp; </TD>
</Tr>
<Tr>
<TD width = "126" class = "T"> select a file (Excel)
</TD>
<TD width = "368" class = "T"> <label>
<Input name = "filexls" type = "file" size = "35">
</Label> </TD>
</Tr>
<Tr>
<TD colspan = "2" class = "T">
<Label>
<Input type = "Submit" name = "Submit" value = "import data">
</Label>
<A href = "Limit 2.asp" class =" T "> return </a>
</TD>
</Tr>
</Table>
</Form>
<! -- # Include virtual = "/INC/clsdbctrl. asp" -->
<! -- # Include virtual = "/INC/function. asp" -->
<%
Dim upfile_5xsoft_stream
Class upload_5xsoft
Dim form, file, version
Private sub class_initialize
Dim istart, ifilenamestart, ifilenameend, iend, vbenter, iformstart, iformend, thefile
Dim strdiv, mformname, mformvalue, mfilename, mfilesize, mfilepath, idivlen, mstr
Version = "Ren Xiang dedicated upload program"
If request. totalbytes <1 then exit sub
Set form = Createobject ("scripting. Dictionary ")
Set file = Createobject ("scripting. Dictionary ")
Set upfile_5xsoft_stream = Createobject ("ADODB. Stream ")
Upfile_5xsoft_stream.mode = 3
Upfile_5xsoft_stream.type = 1
Upfile_5xsoft_stream.open
Upfile_5xsoft_stream.write request. binaryread (request. totalbytes)
Vbenter = CHR (13) & CHR (10)
Idivlen = instring (1, vbenter) + 1
Strdiv = substring (1, idivlen)
Iformstart = idivlen
Iformend = instring (iformstart, strdiv)-1
While iformstart <iformend
Istart = instring (iformstart, "name = """)
Iend = instring (istart + 6 ,"""")
Mformname = substring (istart + 6, iEnd-iStart-6)
Ifilenamestart = instring (iend + 1, "filename = """)
If ifilenamestart> 0 and ifilenamestart <iformend then
Ifilenameend = instring (ifilenamestart + 10 ,"""")
Mfilename = substring (ifilenamestart + 10, iFileNameEnd-iFileNameStart-10)
Istart = instring (ifilenameend + 1, vbenter & vbenter)
Iend = instring (istart + 4, vbenter & strdiv)
If iend> istart then
Mfilesize = iEnd-iStart-4
Else
Mfilesize = 0
End if
Set thefile = new fileinfo
Thefile. filename = getfilename (mfilename)
Thefile. filepath = getfilepath (mfilename)
Thefile. filesize = mfilesize
Thefile. filestart = istart + 4
Thefile. formname = formname
File. Add mformname, thefile
Else
Istart = instring (iend + 1, vbenter & vbenter)
Iend = instring (istart + 4, vbenter & strdiv)
If iend> istart then
Mformvalue = substring (istart + 4, iEnd-iStart-4)
Else
Mformvalue = ""
End if
Form. Add mformname, mformvalue
End if
Iformstart = iformend + idivlen
Iformend = instring (iformstart, strdiv)-1
Wend
End sub
Private function substring (thestart, thelen)
Dim I, C, stemp
Upfile_5xsoft_stream.position = theStart-1
Stemp = ""
For I = 1 to thelen
If upfile_5xsoft_stream.eos then exit
C = ASCB (upfile_5xsoft_stream.read (1 ))
If C & gt; 127 then
If upfile_5xsoft_stream.eos then exit
Stemp = stemp & CHR (ASCW (chrb (ASCB (upfile_5xsoft_stream.read (1) & chrb (c )))
I = I + 1
Else
Stemp = stemp & CHR (c)
End if
Next
Substring = stemp
End Function
Private function instring (thestart, varstr)
Dim I, j, BT, thelen, STR
Instring = 0
STR = tobyte (varstr)
Thelen = lenb (STR)
For I = thestart to upfile_5xSoft_Stream.Size-theLen
If I> upfile_5xsoft_stream.size then exit function
Upfile_5xsoft_stream.position = I-1
If ASCB (upfile_5xsoft_stream.read (1) = ASCB (midb (STR, 1) then
Instring = I
For J = 2 to thelen
If upfile_5xsoft_stream.eos then
Instring = 0
Exit
End if
If ASCB (upfile_5xsoft_stream.read (1) <> ASCB (midb (STR, J, 1) then
Instring = 0
Exit
End if
Next
If instring <> 0 Then exit function
End if
Next
End Function
Private sub class_terminate
Form. removeall
File. removeall
Set form = nothing
Set file = nothing
Upfile_5xsoft_stream.close
Set upfile_5xsoft_stream = nothing
End sub
Private function getfilepath (fullpath)
If fullpath <> "" then
Getfilepath = left (fullpath, limit Rev (fullpath ,"\"))
Else
Getfilepath = ""
End if
End Function
Private function getfilename (fullpath)
If fullpath <> "" then
Getfilename = mid (fullpath, limit Rev (fullpath, "\") + 1)
Else
Getfilename = ""
End if
End Function
Private function tobyte (STR)
Dim I, icode, C, ilow, ihigh
Tobyte = ""
For I = 1 to Len (STR)
C = mid (STR, I, 1)
Icode = ASC (c)
If icode <0 then icode = icode + 65535
If icode> 255 then
Ilow = left (hex (ASC (c), 2)
Ihigh = right (hex (ASC (c), 2)
Tobyte = tobyte & chrb ("& H" & ilow) & chrb ("& H" & ihigh)
Else
Tobyte = tobyte & chrb (ASCB (c ))
End if
Next
End Function
End Class
Class fileinfo
Dim formname, filename, filepath, filesize, filestart
Private sub class_initialize
Filename = ""
Filepath = ""
Filesize = 0
Filestart = 0
Formname = ""
End sub
Public Function saveas (fullpath)
Dim DR, errorchar, I
Saveas = 1
If trim (fullpath) = "" Or filesize = 0 or filestart = 0 or filename = "" Then exit function
If filestart = 0 or right (fullpath, 1) = "/" then exit function
Set DR = Createobject ("ADODB. Stream ")
Dr. mode = 3
Dr. type = 1
Dr. Open
Upfile_5xsoft_stream.position = FileStart-1
Upfile_5xsoft_stream.copyto DR, filesize
Dr. savetofile fullpath, 2
Dr. Close
Set DR = nothing
Saveas = 0
End Function
End Class
%>
<%
Function sqlstr (data)
If not isnull (data) then
Sqlstr = "'" & replace (data ,"'","''")&"'"
Else
Sqlstr = "'" & Data &"'"
End if
End Function
%>
<%
Session. codePage = 936
Server. scripttimeout = 600000
Set upload = new upload_5xsoft
Set file = upload. File ("filexls ")
%>
<%
If file. filesize> 0 then
Filename = year (now) & month (now) & Day (now) & hour (now) & minute (now) & Second (now)
Filename = filename + "."
Filenameend = file. filename
Filenameshow = file. filename
Filenameend = Split (filenameend ,".")
If filenameend (1) = "xls" then
Filename = filename & filenameend (1)
File. saveas server. mappath ("uploadfiles/" & filename)
Else
Response. write "the data format is incorrect! "
Response. Write "<a href = file_upload.asp> return"
Response. End ()
End if
Set file = nothing
Else
Response. Write "file cannot be blank! "
Response. Write "<a href = file_upload.asp> return"
Response. End ()
End if
Set upload = nothing
'After the xls file is uploaded, data is read from the uploaded xls file and written to the SQL database.
Straddr = server. mappath ("uploadfiles/" & filename)
Set excelconn = server. Createobject ("ADODB. Connection ")
Excelconn. Open "provider = Microsoft. Jet. oledb.4.0; Data Source =" + straddr + "; extended properties = 'excel 8.0; HDR = no; IMEX = 1 '"
Set rs = server. Createobject ("ADODB. recordset ")
Set RS1 = server. Createobject ("ADODB. recordset ")
SQL = "select * from [sheet1 $]"
Rs. Open SQL, excelconn, 1, 3
If not (Rs. bof and Rs. EOF) then
Rs. movenext
Do while not Rs. EOF
'Response. Write (RS (1 ))
'Response. End ()
Sql1 = "select * from member"
Rs1.open sql1, Conn, 1, 3
Rs1.addnew
Randomize
Username = ""
Do While Len (username) <8' random password count
Num1 = CSTR (CHR (57-48) * RND + 48) '0 ~ 9
'Num2 = CSTR (CHR (90-65) * RND + 65) 'A ~ Z
Num3 = CSTR (CHR (122-97) * RND + 97) 'A ~ Z
Username = username & num1 & num3
Loop
RS1 ("username") = Username
RS1 ("password") = "bb0391ec1d7bda99" 'bamboo123456
If RS (0) <> "then
RS1 ("company") = RS (0)
End if
If RS (1) <> "then
RS1 ("realname") = RS (1)
End if
If RS (2) <> "then
RS1 ("sex") = sexn (RS (2 ))
End if
If RS (3) <> "then
RS1 ("Prof") = RS (3)
End if
If RS (4) <> "then
RS1 ("tel") = RS (4)
End if
If RS (5) <> "then
RS1 ("mobile") = RS (5)
End if
If RS (6) <> "then
RS1 ("Address") = RS (6)
End if
If RS (7) <> "then
RS1 ("area") = getclassdname (RS (7), "area", "cn ")
End if
If RS (8) <> "then
RS1 ("city") = getclassdname (RS (8), "area", "cn ")
End if
If RS (9) <> "then
RS1 ("fax") = RS (9)
End if
If RS (10) <> "then
RS1 ("comtype") = comtypem (RS (10 ))
End if
If RS (11) <> "then
RS1 ("operation") = RS (11)
End if
RS1 ("passed") = 1
RS1 ("activated") = 1
RS1 ("lastlogintime") = now ()
Rs1.update
Rs1.close
Rs. movenext
Loop
End if
Rs. Close ()
Set rs = nothing
Set RS1 = nothing
Excelconn. Close ()
Set excelconn = nothing
Conn. Close ()
Set conn = nothing
Function sexn (STR)
Select case STR
Case "male"
Sexn = 0
Case "female"
Sexn = 1
End select
End Function
Function comtypem (STR)
Select case STR
Case "bamboo products"
Comtypem = 0
Case "Bamboo machinery"
Comtypem = 1
End select
End Function
Function getclassdname (STR, tablename, Lang)
If not isnumeric (ID) Then exit function
Set rs2logs conn.exe cute ("select top 1 ID from" & tablename & "where classname like '%" & STR & "% '")
If not rs2.eof then
If Lang <> "" then
If Lang = "cn" then
Getclassdname = getclassdname & rs2 (0)
Elseif lang = "en" then
Getclassdname = getclassdname & rs2 (0)
End if
End if
Else
Getclassdname = 0
End if
Rs2.close
End Function
%>
<Table width = "300" border = "1" align = "center" cellpadding = "0" cellspacing = "0" bordercolor = "# cccccc">
<Tr>
<TH bordercolor = "# f1f3f8" bgcolor = "#999999" class = "T" Scope = "row"> & nbsp; </Th>
</Tr>
<Tr>
<TH class = "T" Scope = "row"> file <% response. Write (filenameshow) %> imported successfully! </Th>
</Tr>
<Tr>
<TH class = "T" Scope = "row"> <a href = "javascript: Self. close () "class =" T "> close the window </a> </Th>
</Tr>
<Tr>
<TH class = "T" Scope = "row"> <a href = "define 2.asp" class =" T "> return </a> </Th>
</Tr>
</Table>