以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]导入 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=91799) |
||||
-- 作者:江南小城 -- 发布时间:2016/10/19 12:42:00 -- [求助]导入
|
||||
-- 作者:有点蓝 -- 发布时间:2016/10/19 14:21:00 -- 改为CheckedListBox,不需要的勾选 删除代码 Dim chk As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1") For i As Integer = chk.Items.Count - 1 To 0 Step -1 If chk.GetItemChecked(i) Then chk.Items.RemoveAt(i) Next |
||||
-- 作者:江南小城 -- 发布时间:2016/10/19 15:09:00 -- 老师,下面代码怎样修改。 \'-------取出表名-------\' Dim mylist As String For Each dt As DataTable In DataTables mylist += dt.name & "|" Next Dim mycbo As WinForm.ComboBox = e.Form.Controls("cbo目标表") mycbo.ComboList = mylist.TrimEnd("|") mycbo.SelectedIndex = 0 Dim myf As String = "" For Each dc As DataCol In DataTables(mycbo.SelectedValue).DataCols myf = myf & dc.name & "|" Next Dim drf As WinForm.TextBox = e.Form.Controls("导入列显示") drf.Text = myf Dim bzd As WinForm.ListBox = e.Form.Controls("表字段") bzd.ComboList = myf.TrimEnd("|") Dim sxl As WinForm.ComboBox = e.Form.Controls("筛选列") sxl.ComboList = myf.TrimEnd("|")
|
||||
-- 作者:有点蓝 -- 发布时间:2016/10/19 15:38:00 -- 改啥?到底想要做什么? |
||||
-- 作者:江南小城 -- 发布时间:2016/10/19 16:13:00 -- 老师,换了控件好像好多代码要修改。
|
||||
-- 作者:有点蓝 -- 发布时间:2016/10/19 16:44:00 -- CheckedListBox和ListBox用法基本一样的,至于控件名称之类的自己改改 基本上凡是字段列控件定义WinForm.ListBox 的地方改成WinForm.CheckedListBox 即可 [此贴子已经被作者于2016/10/19 17:11:16编辑过]
|
||||
-- 作者:苏州老街 -- 发布时间:2016/10/19 16:58:00 -- Dim page As WinForm.TabControl = e.Form.Controls("设置步骤") Dim tbl As WinForm.ComboBox = e.Form.Controls("cbo目标表") Dim bookname As WinForm.TextBox = e.Form.Controls("bookName") \'Dim qsh As WinForm.TextBox = e.Form.Controls("起始行") Dim qsh As WinForm.NumericComboBox = e.Form.Controls("有效起始行") Dim sheetname As WinForm.ComboBox = e.Form.Controls("sheetname") Dim lst5r As WinForm.ListBox = e.Form.Controls("lst5r") \'---------效检-------- Dim ts As String = "" If bookname.Text = "" Then ts = "请点击 [Excel文件] 按钮获取文件名及路径!" End If If cint(qsh.text) < 0 Then ts = "起始行应大于 \'0\' !" End If If sheetname.text = "" Or lst5r.ComboList = "" Then ts = "工作表没有选择,选择工作表后,请点击 [读出数据] ! " End If If tbl.SelectedValue = "" Then ts = "请选择目标表 ! " End If If ts = "" Then page.SelectedIndex = 1 Dim lstfile As WinForm.CheckedListBox = e.Form.Controls("文件列表") lstfile.ComboList = bookname.text & "[" & sheetname.text & "]" Else messagebox.Show(ts,"错误信息",MessageBoxButtons.OK,MessageBoxIcon.Error) End If 老师,这是"下一步"按钮,怎样修改
|
||||
-- 作者:有点蓝 -- 发布时间:2016/10/19 17:13:00 -- 回7楼,代码有什么问题? 提问题麻烦说清楚你的问题,有什么错误和真正需要的效果
|
||||
-- 作者:苏州老街 -- 发布时间:2016/10/19 18:48:00 -- 老师好,按"导入数据"按钮报错。 Dim flst As WinForm.CheckedListBox = e.Form.Controls("文件列表") Dim jdt As WinForm.ProgressBar = e.Form.Controls("进度条") jdt.Maximum = flst.Items.Count * 100 jdt.Minimum = 0 For fid As Integer = 0 To flst.Items.Count -1 \'\'-----导出文件-----\' Dim fn As String = flst.Items(fid) Dim bookname As String = fn.Remove(fn.IndexOf("[")) Dim sheetname As String = fn.SubString(fn.IndexOf("[")+1,fn.LastIndexOf("]")-fn.IndexOf("[")-1) Dim Book As New XLS.Book(bookname) Dim sheet As XLS.Sheet = book.sheets(sheetname) \'-----导入文件 Dim tblname As WinForm.ComboBox = e.Form.Controls("cbo目标表") Dim dt As DataTable = DataTables(tblname.Text) \'-------导出配置定义-----------------\' Dim bth As WinForm.CheckBox = e.Form.Controls("标题") Dim qsh As Integer = cint(e.Form.Controls("有效起始行").text) \'----无标题行时,起始行须-1----- If bth.Checked = False Then qsh = qsh -1 End If Dim dcb As WinForm.CheckedListBox = e.Form.Controls("表字段0") Dim drb As WinForm.CheckedListBox = e.Form.Controls("表字段") \'-----导出表字段列表--------\' Dim dc As new List(of String) dc.AddRange(dcb.ComboList.Split("|")) \'-----导入表字段列表-----\' Dim dr As new List(of String) dr.AddRange(drb.ComboList.Split("|")) \'------获取导出表数据----- For r As Integer = qsh To sheet.rows.Count -1 \'-----进度条---- jdt.Value = fid*100 + cint(r*100/sheet.Rows.Count) \'MessageBox.Show(jdt.value) \'-----取出一行导出行各列数据----- Dim data(dr.Count) As String For i As Integer = 0 To dc.Count - 1 \'-----判定标记列-----\' \'MessageBox.Show("dc(i)->" & dc(i)) If dc(i).Contains("标-->") = True Then data(i) = dc(i).SubString(dc(i).IndexOf(">")+1) Else Dim zdh As Integer zdh=cint(dc(i).Remove(dc(i).IndexOf("列")).Trim("第"," ")) data(i) = sheet(r,zdh-1).value End If Next \'-----判断筛选列表是否有效 \'--------筛选列列表-------------\' Dim sxlst As WinForm.CheckedListBox = e.Form.Controls("筛选列表") If sxlst.Items.Count > 0 Then \'-----判断是否符合导出条件----- Dim bds As String = "" \'-----筛选表达式 \'--------遍历条件----- For Each S As String In sxlst.Items \'-----获取列间逻辑符----- Dim ljf As String ljf= s.SubString(0,s.IndexOf(".")) ljf = iif(ljf="并且"," AND ",IIF(ljf="或者"," OR ",iif(ljf="排除","Not",""))) \'-----\'获取筛选列的在导出表中的值 Dim sxl,sxlz,ysf,ysz As String \'筛选列\\筛选列值\\运算符\\运算值 Dim sxid As Integer \'筛选列在导出列表的列位置 sxl = s.Substring( s.IndexOf(".")+1,s.Indexof("[") - s.indexof(".")-1 ) ysf = s.SubString( s.IndexOf("[")+1,s.IndexOf("]") - s.IndexOf("[") -1 ) ysz = s.SubString( s.IndexOf("(")+1,s.LastIndexOf(")") - s.IndexOf("(") -1 ) sxid = Functions.Execute("IndexStr",drb.ComboList,"|",sxl) sxlz =data(sxid) \'----对应的导出数据 \'-----\'将运算符转为表达式可用的符号 ysf = iif(ysf="等于", "=" , iif(ysf="不等于", " <> " ,iif(ysf="大于", " > " ,iif(ysf="大于等于", " >= " ,iif(ysf="小于", " < " ,iif(ysf="小于等于", " <= " ,iif(ysf="包含"," like "," not like "))))))) \'MessageBox.Show("列逻辑符=\'" & ljf & "\' sxid="\' & sxid & "\' sxl=\'" & sxl & "\' ysf=\'" & ysf & "\' ysz=\'" & ysz & "\'") \'-----筛选表达式------ data(sxid)-->是取出导出对应列的值 \'-----导入值和运算值的数值类型判断 Dim exp As String If IsNumeric(sxlz) = True Then exp = cexp(" {0} {1} {2}",data(sxid),ysf,ysz) ElseIf Isdate(sxlz) =True Then exp = cexp(" #{0}# {1} #{2}#",data(sxid),ysf,ysz) Else If ysf.Contains("like") Then exp = data(sxid).Contains(ysz) Else exp = """" & data(sxid) & """" & ysf & """" & ysz & """" End If End If bds = bds & ljf & exp \'MessageBox.Show(bds) Next \'------根据计算表达式计算结果判定导出数据是否符合-------\' If eval(bds) = False Then Continue For End If End If \'-----根据导入模式导入数据----- \'------添加模式----- Dim hl As WinForm.RadioButton = e.Form.Controls("添加") If hl.Checked = True Then Dim ndr As DataRow = dt.AddNew For i As Integer = 0 To dr.Count - 1 ndr(dr(i)) = Data(i) Next End If \'-----更新和跳过模式-----\' Dim gx As WinForm.RadioButton = e.Form.Controls("更新") Dim fq As WinForm.RadioButton = e.Form.Controls("放弃") If gx.Checked = True Or fq.Checked = True Then \'MessageBox.Show("进入更新模式") \'-----判定关键字段为第几字段---- Dim key1 As String = e.Form.Controls("key1").Value Dim key2 As String = e.Form.Controls("key2").value Dim data1,data2 As String \'----根据关键字段在字段列表中的位置,取出要导入的数据值 For i As Integer = 0 To dr.Count -1 \'MessageBox.Show(dr(i) & "->" & dr(i) = key1 ) If dr(i) = key1 Then data1 = data(i) End If If dr(i) = key2 Then data2 =data(i) End If Next \' MessageBox.Show(key1 & "=" & data1 & "--" & key2 & "=" & data2) \'----查找导入表的关键字段同值数据行的条件----- Dim find As DataRow Dim exp As String If data1 <> "" And data2 <> "" Then exp = cexp("[" & key1 & "] = \'{0}\' and [" & key2 & "] = \'{1}\'",data1,data2) ElseIf data1 <> "" Then exp = cexp("[" & key1 & "] = \'{0}\'",data1) ElseIf data2 <> "" Then exp = cexp("[" & key2 & "] = \'{0}\'",data2) End If \'----查找导入表符合条件的行------\' If exp IsNot Nothing Then find = DataTables(tblname.Value).find(exp) End If \'MessageBox.Show("exp=" & exp ) If find IsNot Nothing Then \'-------找到后,模式为更新就更新数据,否则跳过------- If gx.Checked = True Then For i As Integer = 0 To dr.Count - 1 find(dr(i)) = Data(i) Next End If Else \'------没找到,添加数据------ Dim ndr As DataRow = dt.AddNew For i As Integer = 0 To dr.Count - 1 ndr(dr(i)) = Data(i) Next End If End If Next Next jdt.Value = jdt.Maximum [此贴子已经被作者于2016/10/19 20:42:30编辑过]
|
||||
-- 作者:有点蓝 -- 发布时间:2016/10/19 20:37:00 -- 把代码中相应的WinForm.ListBox改为WinForm.CheckedListBox |