Foxtable(狐表)用户栏目专家坐堂 → 网站的代码放在什么位置


  共有2151人关注过本帖树形打印复制链接

主题:网站的代码放在什么位置

帅哥哟,离线,有人找我吗?
lihe60
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6885 积分:43595 威望:0 精华:0 注册:2009/3/2 14:07:00
网站的代码放在什么位置  发帖心情 Post By: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


 回到顶部