www.pudn.com > BeiJingBusSerchSystem.rar > frmFind.frm, change:2008-11-27,size:6799b


VERSION 5.00 
Begin VB.Form frmFind  
   Caption         =   "北京公交查询系统" 
   ClientHeight    =   7470 
   ClientLeft      =   60 
   ClientTop       =   450 
   ClientWidth     =   7440 
   LinkTopic       =   "Form1" 
   ScaleHeight     =   7470 
   ScaleWidth      =   7440 
   StartUpPosition =   2  '屏幕中心 
   Begin VB.Frame Frame2  
      Caption         =   "线路查询" 
      Height          =   855 
      Left            =   240 
      TabIndex        =   9 
      Top             =   720 
      Width           =   6975 
      Begin VB.CommandButton cmdFindLine  
         Caption         =   "查询" 
         Height          =   465 
         Left            =   5640 
         TabIndex        =   11 
         Top             =   225 
         Width           =   1095 
      End 
      Begin VB.ComboBox cmbBusLine  
         Height          =   300 
         Left            =   1080 
         TabIndex        =   10 
         Top             =   300 
         Width           =   1575 
      End 
      Begin VB.Label Label5  
         AutoSize        =   -1  'True 
         Caption         =   "线路:" 
         Height          =   180 
         Left            =   480 
         TabIndex        =   12 
         Top             =   360 
         Width           =   540 
      End 
   End 
   Begin VB.Frame Frame1  
      Caption         =   "站点查询" 
      Height          =   855 
      Left            =   240 
      TabIndex        =   3 
      Top             =   1680 
      Width           =   6975 
      Begin VB.ComboBox cmbBegin  
         Height          =   300 
         Left            =   1080 
         TabIndex        =   6 
         Text            =   "Combo1" 
         Top             =   300 
         Width           =   1575 
      End 
      Begin VB.ComboBox cmbEnd  
         Height          =   300 
         Left            =   3840 
         TabIndex        =   5 
         Text            =   "Combo1" 
         Top             =   300 
         Width           =   1575 
      End 
      Begin VB.CommandButton cmdFind  
         Caption         =   "查询" 
         Height          =   465 
         Left            =   5640 
         TabIndex        =   4 
         Top             =   225 
         Width           =   1095 
      End 
      Begin VB.Label Label2  
         AutoSize        =   -1  'True 
         Caption         =   "出发站点:" 
         Height          =   180 
         Left            =   120 
         TabIndex        =   8 
         Top             =   360 
         Width           =   900 
      End 
      Begin VB.Label Label3  
         AutoSize        =   -1  'True 
         Caption         =   "目的站点:" 
         Height          =   180 
         Left            =   2880 
         TabIndex        =   7 
         Top             =   360 
         Width           =   900 
      End 
   End 
   Begin VB.TextBox txtBusLine  
      Height          =   4215 
      Left            =   240 
      Locked          =   -1  'True 
      MultiLine       =   -1  'True 
      ScrollBars      =   3  'Both 
      TabIndex        =   1 
      Top             =   3000 
      Width           =   6975 
   End 
   Begin VB.Label Label4  
      AutoSize        =   -1  'True 
      Caption         =   "查询结果:" 
      Height          =   180 
      Left            =   360 
      TabIndex        =   2 
      Top             =   2640 
      Width           =   900 
   End 
   Begin VB.Label Label1  
      AutoSize        =   -1  'True 
      Caption         =   "乘车查询" 
      BeginProperty Font  
         Name            =   "宋体" 
         Size            =   14.25 
         Charset         =   134 
         Weight          =   400 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   285 
      Left            =   3360 
      TabIndex        =   0 
      Top             =   360 
      Width           =   1140 
   End 
End 
Attribute VB_Name = "frmFind" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
Private Sub cmdFind_Click() 
    Dim strBegin As String, strEnd As String 
    strBegin = Trim(cmbBegin.Text)  '获取出发站点名称 
    strEnd = Trim(cmbEnd.Text)  '获取目的站点名称 
    If strBegin = strEnd Then Exit Sub  '名称相同则退出 
    BusSwitch strBegin, strEnd 
         
End Sub 
 
Private Sub cmdFindLine_Click() 
    Dim cnn As New ADODB.Connection '定义数据库连接变量 
    Dim rst As New ADODB.Recordset  '定义记录集变量 
    Dim str1 As String, str2 As String, str3 As String, i As Integer 
    str1 = cmbBusLine.Text 
    If str1 = "" Then 
        MsgBox "请输入或选择线路名称!", vbCritical + vbOKOnly, "提示" 
        Exit Sub 
    End If 
     
    cnn.ConnectionString = Conn '设置数据库连接字符串 
    cnn.Open    '打开数据库连接 
     
    Set rst.ActiveConnection = cnn  '设置记录集的数据库连接 
    str2 = "SELECT a.[station] FROM [station] a,[bus] b "   '定义查询SQL语句 
    str2 = str2 & " WHERE a.[busid]=b.[id] AND b.[bus]='" & str1 & "'" 
    str2 = str2 & "ORDER BY a.[order]" 
     
    rst.Open str2   '打开记录集 
     
    str3 = "【" & str1 & "】的停靠站点如下:" & vbNewLine   '生成查询结果 
    i = 1 
    Do While Not rst.EOF 
        str3 = str3 & i & ":" & rst(0).Value & vbNewLine   '站点名 
        i = i + 1   '站点序号 
        rst.MoveNext    '处理下一记录 
    Loop 
    txtBusLine.Text = str3  '显示查询结果 
End Sub 
 
Private Sub Form_Load() 
    Dim cnn As New ADODB.Connection '定义数据库连接变量 
    Dim rst As New ADODB.Recordset  '定义记录集变量 
     
    cnn.ConnectionString = Conn '设置数据库连接字符串 
    cnn.Open    '打开数据库连接 
     
    Set rst.ActiveConnection = cnn  '设置记录集的数据库连接 
     
    rst.Open "SELECT [bus] FROM [bus] ORDER BY [bus]"   '选择线路名称 
    If Not rst.EOF Then '记录集中有数据 
        cmbBusLine.Clear    '清空组合框中的列表项 
        Do While Not rst.EOF    '循环处理记录集中的数据 
            cmbBusLine.AddItem rst(0).Value '将线路名添加到组合框中 
            rst.MoveNext    '处理下一记录 
        Loop 
    End If 
    rst.Close   '关闭记录集 
 
    rst.Open "SELECT DISTINCT([station]) FROM [station] ORDER BY [station]" 
    cmbBegin.Clear 
    Do While Not rst.EOF    '循环处理记录集中的数据 
        cmbBegin.AddItem rst(0).Value    '将站名添加到组合框中 
        rst.MoveNext    '处理下一记录 
    Loop 
       
    rst.Close 
    cnn.Close   '关闭数据库连接 
     
    cmbEnd.Clear    '清除组合框中原有数据 
    For i = 0 To cmbBegin.ListCount - 1 '将出发站点的数据复制到目的站点 
        cmbEnd.AddItem cmbBegin.List(i) '向组合框中添加数据 
    Next 
End Sub