以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]谁能帮忙翻译一下代码的含义 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=97983) |
||||
-- 作者:拽拽陪你笑 -- 发布时间:2017/3/22 10:02:00 -- [求助]谁能帮忙翻译一下代码的含义 刚开始接触,哪位高工能帮我翻译一下语句,看了好久没看懂。附件有例子。 Dim dt As DataTable = DataTables("认证报名表") 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 Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets("认证报名表") dt.ResumeRedraw() dt.StopRedraw() \'systemready = False 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 If dt.DataCols.Contains(sheet(0,c).Text.replace(" ", "")) Then nms.Add(sheet(0,c).Text.replace(" ", ""), c) End If Next For n As Integer = 1 To Sheet.Rows.Count -1 Dim sfzhm As String = sheet(n,nms("身份证号码")).Text If sfzhm = "" Then Continue For Dim dr As DataRow = dt.Find("身份证号码 = \'" & sfzhm & "\'") If dr Is Nothing Then ls.add(n) Else dic.Add(dr, n) End If Next For Each key As DataRow In dic.Keys For Each m As String In nms.keys If dt.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 dt.DataCols(m).Expression > "" Then \'表达式列 Else If dt.DataCols(m).IsNumeric Then key(m) = val(Sheet(dic(key),nms(m)).Value) Else If dt.DataCols(m).IsDate Then Dim d As Date If Date.TryParse(Sheet(dic(key),nms(m)).Value, d) key(m) = d End If Else key(m) = Sheet(dic(key),nms(m)).Value End If Next Next For Each l As Integer In ls Dim ndr As DataRow = dt.AddNew For Each m As String In nms.keys If dt.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 dt.DataCols(m).Expression > "" Then \'表达式列 Else If dt.DataCols(m).IsNumeric Then ndr (m) = val(Sheet(l,nms(m)).Value) Else If dt.DataCols(m).IsDate Then Dim d As Date If Date.TryParse(Sheet(l,nms(m)).Value, d) ndr (m) = d End If Else ndr (m) = Sheet(l,nms(m)).Value End If Next Next dt.ResumeRedraw() \'systemready = True End If End If
|
||||
-- 作者:拽拽陪你笑 -- 发布时间:2017/3/22 10:04:00 -- 附件~
|
||||
-- 作者:有点色 -- 发布时间:2017/3/22 10:11:00 -- 这段代码是合并数据的一段代码,不需要看懂。大体思路是:如果表里面有相同的身份证,就修改数据,否则,就新增数据。
你只需要修改红色代码和表名,其余不变。
Dim sfzhm As String = sheet(n,nms("身份证号码")).Text If sfzhm = "" Then Continue For
Dim dr As DataRow = dt.Find("身份证号码 = \'" & sfzhm & "\'")
|
||||
-- 作者:拽拽陪你笑 -- 发布时间:2017/3/22 10:13:00 -- 我有数据强迫症,我想弄清楚它是怎么思考的 |
||||
-- 作者:有点色 -- 发布时间:2017/3/22 11:23:00 -- 以下是引用拽拽陪你笑在2017/3/22 10:13:00的发言:
我有数据强迫症,我想弄清楚它是怎么思考的
这段多了一个[处理效率]的步骤,下面这个帮助文档有助于你理解
http://www.foxtable.com/webhelp/scr/2334.htm
|
||||
-- 作者:拽拽陪你笑 -- 发布时间:2017/3/22 11:32:00 -- 感谢啊!~~ |