以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 函数执行,程序就假死,直到处理完 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=64275) |
-- 作者:ycli368 -- 发布时间:2015/2/9 16:34:00 -- 函数执行,程序就假死,直到处理完 写了个把csv文件导入数据库的功能,单击按钮处理,程序就假死,直到处理完,这个有没有什么解决方案,实现在数据处理的同时, 还能够做其他操作!
|
-- 作者:有点甜 -- 发布时间:2015/2/9 16:36:00 -- 呃,用多线程可能可以。
具体请上传测试例子。 |
-- 作者:Bin -- 发布时间:2015/2/9 16:40:00 -- 只能用多线程来实现,上个例子吧 |
-- 作者:ycli368 -- 发布时间:2015/2/9 16:44:00 -- Dim filenamestr As String = args(0).controls("bookName").Text Dim str As String = FileSys.ReadAllText(filenamestr, Encoding.Default) \'str = str.replace(chr(13),"") Dim ary() As String = str.Split(chr(10)) Dim Total, addlist, uplist,nochange As Integer Dim lentemp As Integer Dim temp2 As String Dim dr As DataRow Dim drs As List(of DataRow) Dim updateflag As Integer \'Tables("订单表").StopRedraw() Dim nms() As String = { "订单编号","买家会员名","买家支付宝账号","买家应付货款","买家应付邮费","买家支付积分","总金额","返点积分","买家实际支付金额","买家实际支付积分","订单状态","买家留言","收货人姓名","收货地址","运送方式","联系电话","联系手机","订单创建时间","订单付款时间","宝贝标题","宝贝种类","物流单号","物流公司","订单备注","宝贝总数量","店铺Id","店铺名称","订单关闭原因","卖家服务费","买家服务费","发票抬头","是否手机订单","分阶段订单信息","定金排名","修改后的sku","修改后的收货地址","异常信息","天猫卡券抵扣","集分宝抵扣","是否是O2O交易","O2O交易类型","O2O店铺id","O2O店铺名称","O2O导购员id","O2O导购员姓名","O2O提货类型","O2O外部订单id" } Total = ary.Length - 2 addlist = 0 uplist = 0 nochange = 0 lentemp = nms.Length - 1-7 For i As Integer = 1 To ary.Length - 2 Dim s() As String = ary(i).Split(",") \'Dim nr As DataRow = DataTables("订单表").AddNew \' nr(1) = s(0).replace("""", "").trim() Dim bh As String = s(0).trim(""""," ") \'Dim dr As DataRow = DataTables("订单表").SQLFind("订单编号 = \'" & bh & "\'") drs = DataTables("订单表").SQLSelect("订单编号 = \'" & bh & "\'") \'dr = drs(0) \'messagebox.show(dr(nms(0))) If drs.count = 0 Then \'如果不存在同编号的订单 \'messagebox.show(333) Dim cmd As New SQLCommand cmd.C \'cmd.CommandText="Insert Into {订单表} ( 订单编号,买家会员名,买家支付宝账号,买家应付货款,买家应付邮费,买家支付积分,总金额,返点积分,买家实际支付金额,买家实际支付积分,订单状态,买家留言,收货人姓名,收货地址,运送方式,联系电话,联系手机,订单创建时间,订单付款时间,宝贝标题,宝贝种类,物流单号,物流公司,订单备注,宝贝总数量,店铺Id,店铺名称,订单关闭原因,卖家服务费,买家服务费,发票抬头,是否手机订单,分阶段订单信息,定金排名,修改后的sku,修改后的收货地址,异常信息,天猫卡券抵扣,集分宝抵扣,是否是O2O交易,O2O交易类型,O2O店铺id,O2O店铺名称,O2O导购员id,O2O导购员姓名,O2O提货类型,O2O外部订单id ) Values( " cmd.CommandText="Insert Into {订单表} ( 订单编号,买家会员名,买家支付宝账号,买家应付货款,买家应付邮费,买家支付积分,总金额,返点积分,买家实际支付金额,买家实际支付积分,订单状态,买家留言,收货人姓名,收货地址,运送方式,联系电话,联系手机,订单创建时间,订单付款时间,宝贝标题,宝贝种类,物流单号,物流公司,订单备注,宝贝总数量,店铺Id,店铺名称,订单关闭原因,卖家服务费,买家服务费,发票抬头,是否手机订单,分阶段订单信息,定金排名,修改后的sku,修改后的收货地址,异常信息,天猫卡券抵扣,集分宝抵扣,是否是O2O交易 ) Values( " \'messagebox.show(s(0).trim(""""," ","\'")) For m As Integer = 0 To lentemp Dim temp As String temp = s(m).trim(""""," ","\'") temp = temp.Replace("\'","") \'messagebox.show(nms(m)) \'temp = s(m).replace(" ", "") If temp = "" Then If ((m = 17) Or (m = 18)) Then temp = "\'" & Nothing & "\'" Else temp = "\'" & " " & "\'" End If Else temp = "\'" & temp & "\'" End If If m = lentemp Then cmd.CommandText = cmd.CommandText & temp & " )" Else cmd.commandtext = cmd.commandtext & temp & "," End If \'dr(nms(m)) =s(m).trim(""""," ") Next \'messagebox.show(cmd.commandtext) cmd.ExecuteNonQuery() addlist = addlist + 1 Else dr = drs(0) \'Dim drs As List(of DataRow) = DataTables("订单表").SQLSelect("订单编号 = \'" & bh & "\'") Dim Colnum As Integer \'messagebox.show(s(0).trim(""""," ","\'")) updateflag = 0 For Colnum = 1 To lentemp temp2 = s(Colnum).trim(""""," ","\'") temp2 = temp2.Replace("\'","") If temp2 = "" And Colnum = 18 Then temp2 = Nothing End If \'messagebox.show(nms(Colnum)) If temp2 <> dr(nms(Colnum)) Then \' If ((nms(Colnum) = "订单创建时间") Or (nms(Colnum) = "订单付款时间")) Then \' If temp2 = "" Then \' dr(nms(Colnum)) = Nothing \' Else \' dr(nms(Colnum)) = temp2 \' End If \' Else \'messagebox.show(222) \'messagebox.show(nms(Colnum)) dr(nms(Colnum)) = temp2 \' End If updateflag = 1 \'DataTables("订单表").SQLReplaceFor(nms(Colnum),temp2, "订单编号 = \'" & bh & "\'") End If temp2 = "" Next \'DataTables("订单表").SQLReplaceFor(nms(Colnum),temp2, "订单编号 = \'" & bh & "\'") \'messagebox.show(3) If updateflag = 1 Then DataTables("订单表").SQLUpdate(drs) uplist = uplist + 1 Else nochange = nochange + 1 End If End If Next \'Tables("订单表").ResumeRedraw() \'DataTables("订单表").LoadFilter = "[订单付款时间] = #" & Date.Today & "#" DataTables("订单表").LoadFilter = "[_Identify] Is Null" \'DataTables("订单表").LoadTop = "20" \'DataTables("订单表").LoadOrder = "订单付款时间 Desc" DataTables("订单表").Load messagebox.show("成功导入:" & Total & "条记录" & Chr(13) & Chr(10) & "更新:" & uplist & Chr(13) & Chr(10) & "增加:" & addlist & Chr(13) & Chr(10) & "未变化:" & nochange)
|
-- 作者:Bin -- 发布时间:2015/2/9 16:44:00 -- 做个可以运行的项目例子文件发上来 |
-- 作者:ycli368 -- 发布时间:2015/2/9 16:45:00 -- 我的例子里有项目的所有密码,所以只贴了导入的密码 多线程具体如何实现,如何传参数 |
-- 作者:Bin -- 发布时间:2015/2/9 16:46:00 -- 或者参考 http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=30251&skin=0 |
-- 作者:ycli368 -- 发布时间:2015/2/9 16:51:00 -- 谢谢,例子确实不错我试下,它里面的函数都没有入参的,如果有参数的话是不是只能通过全局来实现 |
-- 作者:Bin -- 发布时间:2015/2/9 16:51:00 -- 可以这么做 |