desprating!!!!!! 斑竹还有各位高手们请帮帮我!!

scotish_bagpipe 2006-06-14 11:21:50
以下这个程序是关于在已有的文件夹里(new folder)的所有.txt文件的数据传到数据库之中,
每个txtfile的数据特征如下:
761526|ORIGINAL|2006-06-12|14:57:34|2T268765|26067|NO REG|CH276|STAGED|Order number 2T268765-1|
每个数据用"|"隔开。
传输完的文件之后转移到新的文件夹叫做"post archive" 我已经实现了运行一次就有一个文件的数据被读入数据库之中并且改文件夹的txt文件转移到新的文件夹(post archive)里面
但是我现在的程序不想让它有任何按钮,也就是说要是程序让它随windows一直运行,随时检测new folder里面有没有新的txt文件进来。如果有,就读取数据到数据库之中。如果没有就不运行。所以,“new folder”的文件夹必须随时保持更新。请各位高手们详细解答。可以的话帮我添加一下代码或者注释,真的非常感谢了。。。
以下是程序的代码,但是现在只是每运行一次只有一条记录被写入数据库,同时一个new folder的文本文件被转移到\“post archive\”的文件夹中,所以请帮忙添加可以自动不断的运行。使不断的数据添加到数据库中。



Imports System
Imports System.IO
Imports System.Text
Imports System.Data
Imports System.Timers.Timer
Imports System.Threading
Imports System.Threading.Timer
Imports System.Data.SqlClient
Imports Microsoft.Win32
Imports Microsoft.VisualBasic





Public Class Form1



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the '_zhen_weng_DatabaseDataSet.Load_Id' table. You can move, or remove it, as needed.
Me.Load_IdTableAdapter.Fill(Me._zhen_weng_DatabaseDataSet.Load_Id)
'TODO: This line of code loads data into the '_zhen_weng_DatabaseDataSet.Load_Id' table. You can move, or remove it, as needed.



Dim strSplit() As String


Dim streamreaderobj As StreamReader

Dim linecont As String

Dim FileNewPath As String = "Y:\StoraEnso\ftp_in\load_id\translated\Post Archive\"
Dim destFileName As String = "Y:\StoraEnso\ftp_in\load_id\translated\Moved\"
Dim destFileName1 As String
Dim destFilePath As String
Dim di As New IO.DirectoryInfo("Y:\StoraEnso\ftp_in\load_id\translated\New Folder\")
Dim diar1 As IO.FileInfo() = di.GetFiles()
Dim dra As IO.FileInfo
Dim draconvert As String
Dim dra2 As String
Dim diconvert As String

Dim newLoadIDRow As DataRow = _zhen_weng_DatabaseDataSet.Tables("Load_Id").NewRow()
Dim p As Process





For Each dra In diar1
draconvert = System.Convert.ToString(dra)
diconvert = System.Convert.ToString(di)
dra2 = diconvert + draconvert

'ListBox1.Items.Add(dra)



Do

Try
If Dir("dra2") <> "" Then


Return


ElseIf Dir("dra2") = "" Then


streamreaderobj = File.OpenText(dra2)


Do

linecont = streamreaderobj.ReadLine()

If (linecont <> "") Then

strSplit = Split(linecont, "|")

End If

Loop Until linecont = ""


newLoadIDRow("Message_Number") = strSplit(0)
newLoadIDRow("Message_Status") = strSplit(1)
newLoadIDRow("Message_Date") = strSplit(2)
newLoadIDRow("Message_Time") = strSplit(3)
newLoadIDRow("CH_Reference") = strSplit(4)
newLoadIDRow("Load_ID_Reference") = strSplit(5)
newLoadIDRow("Lorry_ID") = strSplit(6)
newLoadIDRow("Trailer_ID") = strSplit(7)
newLoadIDRow("Load_Status") = strSplit(8)
newLoadIDRow("Additional_information") = strSplit(9)





streamreaderobj.Close()


_zhen_weng_DatabaseDataSet.Tables("Load_Id").Rows.Add(newLoadIDRow)

End If


Catch ex As Exception

End Try


Try
Me.Validate()
Me.LoadIdBindingSource.EndEdit()
Me.Load_IdTableAdapter.Update(Me._zhen_weng_DatabaseDataSet.Load_Id)
'MsgBox("Update successful")

Catch ex As Exception
MsgBox("Update failed")
End Try
Loop Until File.Exists(draconvert) = False



Next



destFileName1 = destFileName + draconvert


Try
If File.Exists(destFileName1) = False Then
File.Move(dra2, destFileName1)
End If

Catch ex As Exception

End Try



destFilePath = FileNewPath + draconvert
Try
If File.Exists(destFilePath) = False Then

File.Move(destFileName1, destFilePath)
End If
Catch ex As Exception

End Try
end sub
end class

...全文
36 点赞 收藏 回复
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
VB
创建于2007-09-28

1.6w+

社区成员

VB技术相关讨论,主要为经典vb,即VB6.0
申请成为版主
帖子事件
创建了帖子
2006-06-14 11:21
社区公告
暂无公告