Dim Daima As String
Dim CheckedRowsYhq As List(of Row)
Dim AllRowsYhq As List(of Row)
Dim CheckedRowsBb As List(of Row)
Dim YhqArgs(20) As String
Dim AllYhqArgs(40) As String
Dim ReturnFlag As Integer = 0
Dim ErrStr As String
'Dim web As New system.windows.Forms.WebBrowser
'web.ScriptErrorsSuppressed = True
Dim elements,element, elements2,element2, elements3,element3, elements4,element4, elements5,element5 As object
Dim elements6,element6,elements7,element7,elements8,element8 As object
FileSys.WriteAllText("result.txt","", False, Encoding.Default)
Dim DaimaYuan As DataRow = DataTables("代码信息").sqlfind("代码类型 = '优惠券'")
CheckedRowsyhq = Tables("优惠券信息").GetCheckedRows
If CheckedRowsyhq.count = 0 Then
messagebox.show("请选择要设置的优惠券!")
'web.Dispose
Return 1
End If
CheckedRowsBb = Tables("宝贝信息").GetCheckedRows
'messagebox.show(CheckedRowsbb.count)
If CheckedRowsbb.count = 0 Then
messagebox.show("请选择要设置的宝贝!")
'web.Dispose
Return 1
End If
messagebox.show("开始设置优惠券,请暂时不要操作宝贝!")
'AllRowsYhq = Tables("优惠券信息").Rows
For y As Integer = 0 To Tables("优惠券信息").Rows.count - 1
AllYhqArgs(y) = DaimaYuan("代码1") & Tables("优惠券信息").Rows(y)("卖家ID") & DaimaYuan("代码2") & Tables("优惠券信息").Rows(y)("优惠券标示") & DaimaYuan("代码3")
Next
For i As Integer = 0 To CheckedRowsyhq.count - 1
YhqArgs(i) = DaimaYuan("代码1") & CheckedRowsyhq(i)("卖家ID") & DaimaYuan("代码2") & CheckedRowsyhq(i)("优惠券标示") & DaimaYuan("代码3")
Daima = Daima & YhqArgs(i)
Next
'开始设置宝贝
For j As Integer = 0 To CheckedRowsBb.count - 1
Dim web As New system.windows.Forms.WebBrowser
web.ScriptErrorsSuppressed = True
try
'页面加载完整,从两方面判断
'判断页面是否初步加载完成
web.Navigate(CheckedRowsBb(j)("宝贝修改链接"))
'messagebox.show(CheckedRowsBb(j)("宝贝修改链接"))
Do While web.Isbusy OrElse (web.ReadyState <> 4) OrElse (web.Document Is Nothing)
Yanshi(100)'让渡下否则读不到数据
If ReturnFlag = 300 Then
'messagebox.show("页面处理异常,请检查网络或账号登陆1")
web.dispose
ErrStr = CheckedRowsBb(j)("宝贝ID") & chr(9) & "Fail" & chr(9) & "页面处理异常,请检查网络或账号登陆1" & chr(10)
FileSys.WriteAllText("result.txt",ErrStr, True, Encoding.Default)
'web.Document.window.close
Continue For
ElseIf ReturnFlag Mod 10 = 0 Then
web.Navigate(CheckedRowsBb(j)("宝贝修改链接"))
End If
ReturnFlag = ReturnFlag + 1
Loop
ReturnFlag = 0
'FileSys.WriteAllText("C:\Users\guigu\Documents\Foxtable项目\派券精灵\1.txt", web.Document.body.outerhtml, False, Encoding.Default)
'判断页面是否加载完整
Do until (web.Document.body.outerhtml.contains("电脑端") )
Yanshi(100)'让渡下否则读不到数据
If ReturnFlag = 100 Then
'messagebox.show("页面处理异常,请检查网络或账号登陆2")
web.dispose
ErrStr = CheckedRowsBb(j)("宝贝ID") & chr(9) & "Fail" & chr(9) & "页面处理异常,请检查网络或账号登陆1" & chr(10)
FileSys.WriteAllText("result.txt",ErrStr, True, Encoding.Default)
'web.Document.window.close
Continue For
End If
ReturnFlag = ReturnFlag + 1
Loop
ReturnFlag = 0
'messagebox.show(2)
elements = web.document.GetElementById("J_TabWPDesc").GetElementsByTagName("li")
'来到电脑端详情页页面
For Each element In elements
If element.outerhtml.contains("电脑端") Then
element.InvokeMember("click")
yanshi(600)
Exit For
End If
Next
'messagebox.show(3)
'切换到代码模式
element2 = web.document.GetElementById("keTplMod_1") '.GetElementsByTagName("li")
'如果第一个模块没有打开,则单击打开
If not(element2.outerhtml.contains("desc-tpl-item desc-tpl-category desc-tpl-endup desc-tpl-hascontent")) Then
elements3 = element2.GetElementsByTagName("a")
For Each element3 In elements3
If element3.outerhtml.contains("编辑") Then
element3.InvokeMember("click")
yanshi(600)
Exit For
End If
Next
End If
'messagebox.show(4)
'单击切换到编码模式
element4 = web.document.GetElementById("newTabContent")
elements5 = element4.GetElementsByTagName("span")
For Each element5 In elements5
If element5.outerhtml.contains("ks-editor-toolbar-item ks-editor-toolbar-sourceArea") Then
element5.InvokeMember("click")
yanshi(600)
Exit For
End If
Next
'完成代码替换
'elements6 = element4.GetElementsByTagName("textarea")
'messagebox.show(elements6(0).Innertext)
'FileSys.WriteAllText("C:\Users\guigu\Documents\Foxtable项目\派券精灵\1.txt",elements6(0).Innertext, False, Encoding.Default)
'Dim Strtmp As String = elements6(0).Innertext
'For m As Integer = 0 To CheckedRowsyhq.count - 1
' Strtmp = Strtmp.replace(YhqArgs(m),"")
'Next
'elements6(0).Innertext = Daima & Strtmp
'FileSys.WriteAllText("C:\Users\guigu\Documents\Foxtable项目\派券精灵\1.txt",elements6(0).Innertext, False, Encoding.Default)
'messagebox.show(web.Document.window.frames.count)
'For s As Integer = 0 To web.Document.window.frames.count
'messagebox.show(web.Document.window.frames(s).document.body.outerhtml)
'Next
elements6 = web.Document.window.frames(1).document.GetElementsByTagName("body")
'messagebox.show(elements6(0).outerhtml)
Dim Strtmp As String = elements6(0).outerhtml
For m As Integer = 0 To Tables("优惠券信息").Rows.count - 1
Strtmp = Strtmp.replace(AllYhqArgs(m),"")
'messagebox.show(YhqArgs(m))
'messagebox.Show(Strtmp.IndexOf(YhqArgs(m).trim(vblf,chr(10),Chr(13))))
Next
Dim Tihuan As String = "<body class=" & """" & "ks-editor" & """" & ">"
Strtmp.trim(Tihuan)
elements6(0).outerhtml = Tihuan & Daima & Strtmp
'FileSys.WriteAllText("C:\Users\guigu\Documents\Foxtable项目\派券精灵\1.txt",elements6(0).outerhtml, False, Encoding.Default)
'单击切换到图片模式
element4 = web.document.GetElementById("newTabContent")
elements5 = element4.GetElementsByTagName("span")
For Each element5 In elements5
If element5.outerhtml.contains("ks-editor-toolbar-item ks-editor-toolbar-sourceArea") Then
element5.InvokeMember("click")
yanshi(600)
Exit For
End If
Next
'提交修改
element6 = web.Document.GetElementById("event_submit_do_edit")
element6.InvokeMember("click")
Do until (web.Document.url.Tostring.contains("item.htm?") )
Yanshi(100)'让渡下否则读不到数据
If ReturnFlag = 600 Then
'messagebox.show("页面处理异常,请检查网络或账号登陆3")
ErrStr = CheckedRowsBb(j)("宝贝ID") & chr(9) & "Fail" & chr(9) & web.Document.url.Tostring & chr(10)
FileSys.WriteAllText("result.txt",ErrStr, True, Encoding.Default)
web.dispose
'web.Document.window.close
Continue For
ElseIf ReturnFlag Mod 10 = 0 Then
element6.InvokeMember("click")
End If
ReturnFlag = ReturnFlag + 1
Loop
ReturnFlag = 0
'messagebox.show(web.Document.url.Tostring)
Catch ex As Exception
web.dispose
ErrStr = CheckedRowsBb(j)("宝贝ID") & chr(9) & "Fail" & chr(9) & ex.tostring & chr(10)
FileSys.WriteAllText("result.txt",ErrStr, True, Encoding.Default)
'web.Document.window.close
Continue For
End try
Dim ErrStrsuccess As String = CheckedRowsBb(j)("宝贝ID") & chr(9) & "Success" & chr(10)
FileSys.WriteAllText("result.txt",ErrStrsuccess, True, Encoding.Default)
web.dispose
'web.Document.window.close
Next
'web.Dispose
messagebox.show("修改成功")