按老师提示 问题还是依旧……麻烦老师指导下 另外代码有些庸大了 有没有办法精简呢
Dim t2 As WinForm.TextBox = e.Form.Controls("TextBox2")
Dim t3 As WinForm.TextBox = e.Form.Controls("TextBox3")
Dim t1 As WinForm.TextBox = e.Form.Controls("TextBox1")
Dim cm4 As WinForm.ComboBox = e.Form.Controls("ComboBox4")
Dim ck As WinForm.CheckBox = e.Form.Controls("是否批量导入")
Dim tb1 As WinForm.Table = e.Form.Controls("Table1")
Dim jg As WinForm.CheckBox = e.Form.Controls("是否自定义间隔符")
Dim bsbs As String
If t1.text<>"" Then
If ck.Checked=True Then '选择批量导入
'先从其中一个文本里面读取字段列,然后判断表是否存在数据库中,如果不存在,就创建,反之就不创建表
Dim Multi As String
Dim strs As String = FileSys.ReadAllText(t2.text, Encoding.Default)
t2.text=t2.text
Dim Values11() As String = strs.Replace(vbcr,"").split(vblf)
For i1 As Integer = 0 To 0
Dim rs As String = Values11(0)
For i As Integer = 0 To 0
Dim cs() As String = rs.Split(vbtab)
output.Show(cs(0))
Multi = cs(0)
Next
Next
Dim ab As String="否"
Dim lst1 As List(Of String)
lst1 = Connections("委").GetTableNames
For Each nm1 As String In lst1
output.show(nm1)
If t1.text=nm1 Then
ab="是"
End If
Next
Dim Values() As String
If jg.Checked=True Then
Values = Multi.split(t3.text)
Else
Values = Multi.split("|")
End If
If ab="是" Then
Else
Dim Builder As New ADOXBuilder("委") '要指定数据源名称
Dim tbl As ADOXTable
Builder.Open()
tbl = Builder.NewTable(t1.text) '创建表
With tbl
For Index1 As Integer = 0 To Values.Length - 1
.AddColumn(Values(Index1) ,ADOXType.String, 255)
Next
End With
Builder.AddTable(tbl, True, True) '增加表
Builder.Close()
Dim Builder1 As New ADOXBuilder("委") '要指定数据源名称
Builder1.Open() '打开ADOXBuilder
With Builder1.Tables(t1.text)
.AddColumn("日期" ,ADOXType.DateTime) '增加日期型列
End With
Builder1.Close() '关闭ADOXBuilder
End If
'遍历选择的文件所在根目录,然后遍历目录下的所有文件,然后开始赋值
For Each File As String In FileSys.GetFiles(FileSys.GetParentPath(t2.text))
MessageBox.Show(file)
Dim strs1 As String = FileSys.ReadAllText(File, Encoding.Default)
't2.text=FileSys.GetParentPath(t2.text)
Dim Values111() As String = strs1.Replace(vbcr,"").split(vblf)
Dim cmd As New SQL Command
cmd.Conn ect i
Dim dt As DataTable
Dim bbb As String ="SELE CT * From {" & t1.text & "}"" "
cmd.CommandText = bbb
dt = cmd.ExecuteReader(True)
'Dim tb1 As WinForm.Table = e.Form.Controls("Table1")
tb1.Table.DataSource = dt
tb1.Table.StopRedraw
For i As Integer = 1 To Values111.length - 1
If jg.Checked=True Then
Dim cs() As String = Values111(i).split(vbtab)
Dim r As Row = tb1.Table.AddNew
For i1 As Integer = 0 To math.min(cs.Length-1, tb1.Table.cols.count - 1)
Dim bb As String=cs(i1).trim()
If bb > "" Then
If bb.Length=8 Then
If Values(i1).Contains(cm4.text) Then
'If Values(i1).Contains(cm4.text) OrElse Values(i1).Contains("日期") Then
Dim d As Date = cdate(bb.insert(6,"-").insert(4,"-"))
r("日期")= Format(d, "yyyy-MM-dd")
r(i1) = cs(i1)
Else
r(i1) = cs(i1)
End If
Else
If Values(i1).Contains(cm4.text) Then
'If Values(i1).Contains(cm4.text) OrElse Values(i1).Contains("日期") Then
Dim d As Date = cdate(bb)
r("日期")= Format(d, "yyyy-MM-dd")
r(i1) = cs(i1)
Else
r(i1) = cs(i1)
End If
End If
End If
Next
Else
Dim cs() As String = Values111(i).split(t3.text)
Dim r As Row = tb1.Table.AddNew
For i1 As Integer = 0 To math.min(cs.Length-1, tb1.Table.cols.count - 1)
Dim bb As String=cs(i1).trim()
If bb > "" Then
If bb.Length=8 Then
If Values(i1).Contains(cm4.text) Then
'If Values(i1).Contains(cm4.text) OrElse Values(i1).Contains("日期") Then
Dim d As Date = cdate(bb.insert(6,"-").insert(4,"-"))
r("日期")= Format(d, "yyyy-MM-dd")
r(i1) = cs(i1)
Else
r(i1) = cs(i1)
End If
Else
If Values(i1).Contains(cm4.text) Then
'If Values(i1).Contains(cm4.text) OrElse Values(i1).Contains("日期") Then
Dim d As Date = cdate(bb)
r("日期")= Format(d, "yyyy-MM-dd")
r(i1) = cs(i1)
Else
r(i1) = cs(i1)
End If
End If
End If
Next
End If
'Dim cs() As String = Values111(i).split("|")
Next
tb1.Table.ResumeRedraw
tb1.Table.DataTable.Save
Next
Else
Dim Multi As String
Dim strs As String = FileSys.ReadAllText(t2.text, Encoding.Default)
t2.text=t2.text
Dim Values11() As String = strs.Replace(vbcr,"").split(vblf)
For i1 As Integer = 0 To 0
Dim rs As String = Values11(0)
For i As Integer = 0 To 0
Dim cs() As String = rs.Split(vbtab)
output.Show(cs(0))
Multi = cs(0)
Next
Next
Dim ab As String="否"
Dim lst As List(Of String)
lst = Connections("委").GetTableNames
For Each nm As String In lst
output.show(nm)
If t1.text=nm Then
ab="是"
End If
Next
Dim Values() As String
If jg.Checked=True Then
Values = Multi.split(t3.text)
Else
Values = Multi.split("|")
End If
If ab="是" Then
Else
Dim Builder As New ADOXBuilder("委") '要指定数据源名称
Dim tbl As ADOXTable
Builder.Open()
tbl = Builder.NewTable(t1.text) '创建表
With tbl
For Index1 As Integer = 0 To Values.Length - 1
.AddColumn(Values(Index1) ,ADOXType.String, 255)
Next
End With
Builder.AddTable(tbl, True, True) '增加表
Builder.Close()
Dim Builder1 As New ADOXBuilder("委") '要指定数据源名称
Builder1.Open() '打开ADOXBuilder
With Builder1.Tables(t1.text)
.AddColumn("日期" ,ADOXType.DateTime) '增加日期型列
End With
Builder1.Close() '关闭ADOXBuilder
End If
Dim cmd As New SQL Command
cmd.Co nnec ti
Dim dt As DataTable
Dim bbb As String ="SE LECT * From {" & t1.text & "}"" "
cmd.Comman dText = bbb
dt = cmd.ExecuteReader(True)
'Dim tb1 As WinForm.Table = e.Form.Controls("Table1")
tb1.Table.DataSource = dt
tb1.Table.StopRedraw
For i As Integer = 1 To Values11.length - 1
'Dim cs() As String = Values11(i).split("|")
If jg.Checked=True Then
Dim cs() As String = Values11(i).split(vbtab)
Dim r As Row = tb1.Table.AddNew
For i1 As Integer = 0 To math.min(cs.Length-1, tb1.Table.cols.count - 1)
Dim bb As String=cs(i1).trim()
If bb > "" Then
If bb.Length=8 Then
If Values(i1).Contains(cm4.text) Then
'If Values(i1).Contains(cm4.text) OrElse Values(i1).Contains("日期") Then
Dim d As Date = cdate(bb.insert(6,"-").insert(4,"-"))
r("日期")= Format(d, "yyyy-MM-dd")
r(i1) = cs(i1)
Else
r(i1) = cs(i1)
End If
Else
If Values(i1).Contains(cm4.text) Then
'If Values(i1).Contains(cm4.text) OrElse Values(i1).Contains("日期") Then
Dim d As Date = cdate(bb)
r("日期")= Format(d, "yyyy-MM-dd")
r(i1) = cs(i1)
Else
r(i1) = cs(i1)
End If
End If
End If
Next
Else
Dim cs() As String = Values11(i).split(t3.text)
Dim r As Row = tb1.Table.AddNew
For i1 As Integer = 0 To math.min(cs.Length-1, tb1.Table.cols.count - 1)
Dim bb As String=cs(i1).trim()
If bb > "" Then
If bb.Length=8 Then
If Values(i1).Contains(cm4.text) Then
'If Values(i1).Contains(cm4.text) OrElse Values(i1).Contains("日期") Then
Dim d As Date = cdate(bb.insert(6,"-").insert(4,"-"))
r("日期")= Format(d, "yyyy-MM-dd")
r(i1) = cs(i1)
Else
r(i1) = cs(i1)
End If
Else
If Values(i1).Contains(cm4.text) Then
'If Values(i1).Contains(cm4.text) OrElse Values(i1).Contains("日期") Then
Dim d As Date = cdate(bb)
r("日期")= Format(d, "yyyy-MM-dd")
r(i1) = cs(i1)
Else
r(i1) = cs(i1)
End If
End If
End If
Next
End If
Next
tb1.Table.ResumeRedraw
End If
tb1.Table.DataTable.Save
MessageBox.Show("操作完毕","温馨提示")
Else
MessageBox.Show("请先输入拟导入表名!","温馨提示")
End If