1、加入一个进度条控件;
2、导入按钮
鉴定管理_导入_Click
Dim tb As WinForm.TabControl = e.Form.Controls("TabControl1")
Dim pg As WinForm.TabPage = tb.SelectedPage
Dim 表 As String = ""
If tb.SelectedPage.Text = "鉴定信息汇总" Then
表 = "鉴定管理表"
ElseIf tb.SelectedPage.Text = "报名登记汇总" Then
表 = "鉴定管理表"
ElseIf tb.SelectedPage.Text = "中高级工资审" Then
表 = "鉴定管理表"
ElseIf tb.SelectedPage.Text = "中高级工考核" Then
表 = "鉴定管理表"
ElseIf tb.SelectedPage.Text = "技师高技资审" Then
表 = "鉴定管理表"
ElseIf tb.SelectedPage.Text = "技师高技理论" Then
表 = "鉴定管理表"
ElseIf tb.SelectedPage.Text = "技师高技实潜" Then
表 = "鉴定管理表"
ElseIf tb.SelectedPage.Text = "上会评审汇总" Then
表 = "鉴定管理表"
ElseIf tb.SelectedPage.Text = "证书编号汇总" Then
表 = "证书编号表"
End If
Dim Result As DialogResult
Result = MessageBox.Show("确定要导入吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls"
dlg.MultiSelect = True '允许选择多个文件
If dlg.ShowDialog =DialogResult.OK Then
Functions.AsyncExecute("异步函数", 表, e.Form.controls("ProgressBar1"), dlg)
End If
End If
3、内部函数【异步函数】代码
Dim 表 = args(0)
Dim p As WinForm.ProgressBar = args(1)
Dim dlg = args(2)
p.Minimum = 0 '设置最小值
p.Value = 0 '设置当前值
p.Visible = True
Dim Book As New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
DataTables(表).ResumeRedraw()
DataTables(表).StopRedraw()
systemready = False
p.Maximum = sheet.Rows.count*2
Dim nms As New Dictionary(Of String, Integer)
Dim dic As new Dictionary(Of DataRow, Integer)
Dim ls As new List(Of Integer)
For c As Integer = 0 To sheet.Cols.Count - 1
Dim str As String = sheet(1,c).Text.Replace(" ", "")
If DataTables(表).DataCols.Contains(str) Then
nms.Add(str, c)
End If
Next
For n As Integer = 2 To Sheet.Rows.Count -1
Dim jdpc As String = sheet(n,6).Text
Dim sfzhm As String = sheet(n,9).Text
Dim dr As DataRow = DataTables(表).Find("鉴定批次 = '" & jdpc & "' And 身份证号码 = '" & sfzhm & "'")
If dr Is Nothing Then
ls.add(n)
Else
dic.Add(dr, n)
End If
p.value += 1
Next
For Each key As DataRow In dic.Keys
For Each m As String In nms.keys
If DataTables(表).DataCols(m).IsBoolean Then
If Sheet(dic(key),nms(m)).Text = "" OrElse Sheet(dic(key),nms(m)).Text = "False" OrElse Sheet(dic(key),nms(m)).Value = 0 Then
key(m) = False
Else
key(m) = True
End If
Else If DataTables(表).DataCols(m).Expression > "" Then
'表达式列
Else If DataTables(表).DataCols(m).IsNumeric Then
key(m) = val(Sheet(dic(key),nms(m)).Value)
Else
key(m) = Sheet(dic(key),nms(m)).Value
End If
p.value += 1
Next
Next
For Each l As Integer In ls
Dim ndr As DataRow = DataTables(表).AddNew
For Each m As String In nms.keys
If DataTables(表).DataCols(m).IsBoolean Then
If Sheet(l,nms(m)).Text = "" OrElse Sheet(l,nms(m)).Text = "False" OrElse Sheet(l,nms(m)).Value = 0 Then
ndr (m) = False
Else
ndr (m) = True
End If
Else If DataTables(表).DataCols(m).Expression > "" Then
'表达式列
Else If DataTables(表).DataCols(m).IsNumeric Then
ndr (m) = val(Sheet(l,nms(m)).Value)
Else
ndr (m) = Sheet(l,nms(m)).Value
End If
Next
p.value += 1
Next
DataTables(表).ResumeRedraw()
systemready = True
msgbox("导入完成")
p.Visible = False