以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  网站的代码放在什么位置  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=81342)

--  作者:lihe60
--  发布时间:2016/2/25 10:47:00
--  网站的代码放在什么位置

下面这些代码分别放在什么位置?

 

在订单编号框中输入订单编号,点击“查询”按钮,通过下面的代码获取订单内容:

 

        result = UDPCommunication("%G|" & orderNum & "%")

 

然后进行内容解析:

 

        If result IsNot Nothing Then

            If result.StartsWith("%") AndAlso result.EndsWith("%") Then

                Session("OrderNum") = orderNum \'记录订单编号

                Dim orders() As String = result.Trim("%").Split("$") \'分离主表和明细

                Dim orderdetails() As String = orders(0).Split("|")

                txtName.Value = orderdetails(0)

                txtOrderDate.Value = orderdetails(1)

                txtDeliverDate.Value = orderdetails(2)

                If orders.Length = 2 Then

                    If orders(1).StartsWith("@") AndAlso orders(1).EndsWith("@") Then

                        Dim detailArry() As String = orders(1).Trim("@").Split("@") \'分离不同明细

 

                        For Each de As String In detailArry

                            Dim details() As String = de.Split("|")

                            Dim dr As DataRow

                            dr = order.NewRow()

                            For i As Integer = 0 To details.Length - 1

                                dr(i) = details(i) \'定义的字段必须和返回值的字段顺序一致

                            Next

                            order.Rows.Add(dr)

                        Next

                    End If

                End If

            End If

        End If

 

这里定义一个函数来和FoxtableUDPClient进行通讯,如

 

Function UDPCommunication(ByVal input As String) As String

        Dim udp As New System.Net.Sockets.UdpClient(0)

        Dim ip As New System.Net.IPEndPoint(System.Net.IPAddress.Parse("127.0.0.1"), 52177) \'定义通讯的网络端点,地址和端口号要和和UDPClient启动时的一致

 

        Dim bytes() As Byte = System.Text.Encoding.Unicode.GetBytes(input)

        udp.Send(bytes, bytes.Length, ip) \'发送数据

        Dim result As String = "!false"

        Dim sdt As Date = Date.Now

        While Date.Now < sdt.AddSeconds(1) \'1

            If udp.Available > 0 Then

                Dim remoteIp As New System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)

                Dim rbytes() As Byte = udp.Receive(remoteIp)

                result = System.Text.Encoding.Unicode.GetString(rbytes) \'获取返回值

            End If

        End While

        udp.Close()

        Return result

    End Function


--  作者:大红袍
--  发布时间:2016/2/25 11:19:00
--  

网站那里,双击查询按钮,click事件里面贴如代码;

 

同样,在编写代码的地方,也可以定义函数。

 

foxtable给你提供了具体的例子啊,你打开那个来看即可

 

 

官方网站为本节内容提供了示例,下载地址:
http://www.foxtable.com/samples/UDPWeb.rar