Private Sub CmdDownload_Click()
Dim rstProduct As New ADODB.Recordset, rstRecord As New ADODB.Recordset, rstCompare As New ADODB.Recordset, rstDocuments As New ADODB.Recordset, rstNew As New ADODB.Recordset
Dim strDocRecord As String, strCompare As String, strDocuments As String, strProduct As String, strNotComplete As String, strNew As String
Dim i As Long, strTemp As String
On Error GoTo ErrAction
strDocRecord = "select productdwgcode,code,revnumber,filename from documents_record "
rstRecord.Open strDocRecord, Conn, adOpenKeyset, adLockReadOnly, adCmdText
If rstRecord.EOF Then ''Record 表中没有记录
strProduct = "select distinct productdwgcode from documents "
rstProduct.Open strProduct, Conn, adOpenKeyset, adLockReadOnly, adCmdText
i = 1
While Not rstProduct.EOF
Label1.Caption = "正在处理的产品:" & rstProduct.Fields("productdwgcode")
Label3.Caption = "共有" & rstProduct.RecordCount & "个产品,正在处理第" & i & "个产品!"
If CreateFolder(rstProduct.Fields("productdwgcode")) = True Then
strDocuments = "select productdwgcode,code,revnumber,filename,filetype,fileremark from documents where productdwgcode='" & rstProduct.Fields("productdwgcode") & "'order by productdwgcode,code,revnumber desc"
rstDocuments.Open strDocuments, Conn, adOpenKeyset, adLockReadOnly, adCmdText
strTemp = ""
While Not rstDocuments.EOF
If Right(rstDocuments.Fields("filename"), 4) = ".DWG" Or Right(rstDocuments.Fields("filename"), 4) = ".dwg" Then
If strTemp <> rstDocuments.Fields("productdwgcode") & rstDocuments.Fields("code") Then
If GetFromFTP(rstDocuments.Fields("productdwgcode"), rstDocuments.Fields("code")) = True Then
Conn.Execute "insert into documents_record (productdwgcode,code,filename,filetype,fileremark,revnumber) values('" & rstDocuments.Fields("productdwgcode") & "','" & rstDocuments.Fields("code") & _
"','" & rstDocuments.Fields("filename") & "','" & rstDocuments.Fields("filetype") & "','" & rstDocuments.Fields("fileremark") & "','" & rstDocuments.Fields("revnumber") & "')"
End If
strTemp = rstDocuments.Fields("productdwgcode") & rstDocuments.Fields("code")
End If
End If
rstDocuments.MoveNext
Wend
rstDocuments.Close
Set rstDocuments = Nothing
End If
i = i + 1
rstProduct.MoveNext
Wend
Label1.Caption = "下载完毕!"
Label3.Caption = "所有产品图纸下载完毕!"
txtLog.Text = txtLog.Text & "所有产品图纸下载完毕!" & Chr(13) + Chr(10)
rstProduct.Close
Set rstProduct = Nothing
rstRecord.Close
Set rstRecord = Nothing
Else ''Record 表中有记录
Label1.Caption = "正在核对已下载过的图纸!"
Label3.Caption = "正在检查是否有最新版本的图纸需要更新!"
While Not rstRecord.EOF ''检查是不是最新版本
strCompare = "select productdwgcode,code,revnumber,filename,filetype,fileremark from documents where productdwgcode='" & rstRecord.Fields("productdwgcode") & "' and code='" & rstRecord.Fields("code") & "' order by productdwgcode,code,revnumber desc"
rstCompare.Open strCompare, Conn, adOpenKeyset, adLockReadOnly, adCmdText
If Not rstCompare.EOF Then
If rstCompare.Fields("revnumber") > rstRecord.Fields("revnumber") Then
If Right(rstCompare.Fields("filename"), 4) = ".DWG" Or Right(rstCompare.Fields("filename"), 4) = ".dwg" Then
If GetFromFTP(rstCompare.Fields("productdwgcode"), rstCompare.Fields("code")) = True Then
Kill DRAWINGPATH & "\" & rstRecord.Fields("productdwgcode") & "\" & Left(rstRecord.Fields("filename"), Len(rstRecord.Fields("filename")) - 4) & ".dwf"
Conn.Execute "update documents_record set filename='" & rstCompare.Fields("filename") & "',revnumber='" & rstCompare.Fields("revnumber") & "',fileremark='" & rstCompare.Fields("fileremark") & "' where productdwgcode='" & rstRecord.Fields("productdwgcode") & "' and code='" & rstRecord.Fields("code") & "'"
txtLog.Text = txtLog.Text & "产品" & rstCompare.Fields("productdwgcode") & "的图纸" & rstRecord.Fields("filename") & "已更新为最新版本!" & Chr(13) + Chr(10)
End If
End If
End If
End If
rstCompare.Close
rstRecord.MoveNext
Wend
Set rstCompare = Nothing
rstRecord.Close
Set rstRecord = Nothing
Label1.Caption = "正在查找新图纸!"
Label3.Caption = "正在查找新图纸!" ''没有下载完全的
strProduct = "select distinct productdwgcode from documents where productdwgcode in (select distinct productdwgcode from documents_record)"
rstProduct.Open strProduct, Conn, adOpenKeyset, adLockReadOnly, adCmdText
While Not rstProduct.EOF
Label1.Caption = "正在处理的产品:" & rstProduct.Fields("productdwgcode")
strNotComplete = "select productdwgcode,code,revnumber,filename,filetype,fileremark from documents where (code not in (select code from documents_record where productdwgcode='" & rstProduct.Fields("productdwgcode") & "')) and (productdwgcode='" & rstProduct.Fields("productdwgcode") & "') order by productdwgcode,code,revnumber desc"
rstDocuments.Open strNotComplete, Conn, adOpenKeyset, adLockReadOnly, adCmdText
strTemp = ""
While Not rstDocuments.EOF
If Right(rstDocuments.Fields("filename"), 4) = ".DWG" Or Right(rstDocuments.Fields("filename"), 4) = ".dwg" Then
If strTemp <> rstDocuments.Fields("productdwgcode") & rstDocuments.Fields("code") Then
Label3.Caption = "正在下载新图纸:" & rstDocuments.Fields("filename")
If GetFromFTP(rstDocuments.Fields("productdwgcode"), rstDocuments.Fields("code")) = True Then
Conn.Execute "insert into documents_record (productdwgcode,code,filename,filetype,fileremark,revnumber) values('" & rstDocuments.Fields("productdwgcode") & "','" & rstDocuments.Fields("code") & _
"','" & rstDocuments.Fields("filename") & "','" & rstDocuments.Fields("filetype") & "','" & rstDocuments.Fields("fileremark") & "','" & rstDocuments.Fields("revnumber") & "')"
End If
strTemp = rstDocuments.Fields("productdwgcode") & rstDocuments.Fields("code")
End If
End If
rstDocuments.MoveNext
Wend
rstDocuments.Close
rstProduct.MoveNext
Wend
rstProduct.Close
Set rstProduct = Nothing
''从未下载的
strNew = "select distinct productdwgcode from documents where productdwgcode not in (select distinct productdwgcode from documents_record)"
rstNew.Open strNew, Conn, adOpenKeyset, adLockReadOnly, adCmdText
i = 1
While Not rstNew.EOF
Label1.Caption = "正在处理的产品:" & rstNew.Fields("productdwgcode")
Label3.Caption = "还有" & rstNew.RecordCount & "个产品未下载,正在处理第" & i & "个产品!"
If CreateFolder(rstNew.Fields("productdwgcode")) = True Then
strDocuments = "select productdwgcode,code,revnumber,filename,filetype,fileremark from documents where productdwgcode='" & rstNew.Fields("productdwgcode") & "'order by productdwgcode,code,revnumber desc"
rstDocuments.Open strDocuments, Conn, adOpenKeyset, adLockReadOnly, adCmdText
strTemp = ""
While Not rstDocuments.EOF
If Right(rstDocuments.Fields("filename"), 4) = ".DWG" Or Right(rstDocuments.Fields("filename"), 4) = ".dwg" Then
If strTemp <> rstDocuments.Fields("productdwgcode") & rstDocuments.Fields("code") Then
If GetFromFTP(rstDocuments.Fields("productdwgcode"), rstDocuments.Fields("code")) = True Then
Conn.Execute "insert into documents_record (productdwgcode,code,filename,filetype,fileremark,revnumber) values('" & rstDocuments.Fields("productdwgcode") & "','" & rstDocuments.Fields("code") & _
"','" & rstDocuments.Fields("filename") & "','" & rstDocuments.Fields("filetype") & "','" & rstDocuments.Fields("fileremark") & "','" & rstDocuments.Fields("revnumber") & "')"
End If
strTemp = rstDocuments.Fields("productdwgcode") & rstDocuments.Fields("code")
End If
End If
rstDocuments.MoveNext
Wend
rstDocuments.Close
End If
i = i + 1
rstNew.MoveNext
Wend
Label1.Caption = "下载完毕!"
Label3.Caption = "所有产品图纸下载完毕!"
txtLog.Text = txtLog.Text & "所有产品图纸下载完毕!" & Chr(13) + Chr(10)
Set rstDocuments = Nothing
rstNew.Close
Set rstNew = Nothing
End If