此主题相关图片如下:test.png
Dim dlg As New OpenFileDialog '--------定义一个新的OpenFileDialog
dlg.Filter= "Excel文件|*.xls;*.xlsx" '--------设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '--------如果用户单击了确定按钮
MessageBox.Show("你选择的是:" & dlg.FileName,"提示") '--------提示用户选择的文件
Else
Return
End If
Dim ip As New Importer '--------定义输入
ip.SourcePath = dlg.FileName '--------指定数据文件
ip.SourceTableName = "部门资料$" '--------指定要导入的表
ip.NewTableName ="DTTMP" '--------导入后的表名
ip.Format = "Excel" '--------设置导入格式
ip.Import() '--------EXCEL载入foxtable
Dim Cols_count As Integer = Tables("DTTMP").Cols.count '--------定义数据表列数
Dim Rows_count As Integer = Tables("DTTMP").Rows.count '--------定义数据表行数
Dim dr As DataRow
For i As Integer = 0 To Cols_count - 1 '--------循环,写入到 TB_INFO
dr = DataTables("NG_TABLE").AddNew()
dr("Tbname") = "部门资料"
dr("COLUMN_NAME") = Tables("DTTMP").Rows(1)(i)
dr("COLUMN_CAPTION") = Tables("DTTMP").Rows(2)(i)
dr("CHECK_FLAG") = False
dr("IMPORT_FLAG") = True
Next i
Tables("DTTMP").Rows.Delete(0) '--------删除第一行
Tables("DTTMP").Rows.Delete(0) '--------删除第二行
Tables("DTTMP").Rows.Delete(0) '--------删除第三行
DataTables("DTTMP").Save()
Rows_count = Tables("DTTMP").Rows.count '--------设置新的表行数
Dim dr1 As DataRow
For i As Integer = 0 To Rows_count - 1
dr1 = DataTables("DEPT").AddNew()
dr1("NO") = Tables("DTTMP").Rows(i)("NO")
dr1("NAME") = Tables("DTTMP").Rows(i)("NAME")
dr1("DEP") = Tables("DTTMP").Rows(i)("DEP")
dr1("UP") = Tables("DTTMP").Rows(i)("UP")
dr1("USR") = Tables("DTTMP").Rows(i)("USR")
dr1("SYS_DATE") = Tables("DTTMP").Rows(i)("SYS_DATE")
dr1("MAKE_ID") = Tables("DTTMP").Rows(i)("MAKE_ID")
dr1("NAME_PY") = Tables("DTTMP").Rows(i)("NAME_PY")
Next i
'---------------CHECK数据
Dim file As New System.IO.StreamWriter("D:\checklog.txt", True)
Dim drs2 As List(of DataRow) = DataTables("DTTMP").SQLSelect("LEN(NAME) >= 15 or MAKE_ID not in (1,2,3) or LEN(NAME_PY) >= 15")
For Each dr2 As DataRow In drs2
If(len(dr2("NAME"))>=15) Then
file.WriteLine("ERROR" & " " & Datetime.now & " " & "NAME列" & dr2("F1") & "行")
End If
If(dr2("MAKE_ID")<>1 And dr2("MAKE_ID")<>2 And dr2("MAKE_ID")<>3) Then
file.WriteLine("ERROR" & " " & Datetime.now & " " & "MAKE_ID列" & dr2("F1") & "行")
End If
If(len(dr2("NAME_PY"))>=15) Then
file.WriteLine("ERROR" & " " & Datetime.now & " " & "NAME_PY列" & dr2("F1") & "行")
End If
Next
file.Close()
Dim Builder As New ADOXBuilder
Builder.Open()
With Builder
.DeleteTable("DTTMP")
End With
Builder.Close()
Syscmd.Project.Open(ProjectFile) '--------重新加载项目