www.pudn.com > BeiJingBusSerchSystem.rar > frmModifyBus.frm, change:2008-11-26,size:13913b


VERSION 5.00 
Begin VB.Form frmModifybus  
   Caption         =   "北京市公交查询系统" 
   ClientHeight    =   6450 
   ClientLeft      =   60 
   ClientTop       =   450 
   ClientWidth     =   7920 
   LinkTopic       =   "Form1" 
   ScaleHeight     =   6450 
   ScaleWidth      =   7920 
   StartUpPosition =   2  '屏幕中心 
   Begin VB.Frame Frame1  
      Caption         =   "线路" 
      Height          =   4575 
      Left            =   240 
      TabIndex        =   21 
      Top             =   840 
      Width           =   3015 
      Begin VB.ListBox lstbus  
         Height          =   3840 
         Left            =   120 
         TabIndex        =   22 
         Top             =   360 
         Width           =   2655 
      End 
   End 
   Begin VB.Frame Frame2  
      Caption         =   "线路信息" 
      Height          =   4575 
      Left            =   3480 
      TabIndex        =   3 
      Top             =   840 
      Width           =   4095 
      Begin VB.TextBox txtbus  
         Height          =   375 
         Left            =   1320 
         TabIndex        =   12 
         Top             =   383 
         Width           =   2295 
      End 
      Begin VB.TextBox txtBeginEnd  
         Height          =   375 
         Left            =   1320 
         TabIndex        =   11 
         Top             =   880 
         Width           =   2295 
      End 
      Begin VB.TextBox txtRuntime  
         Height          =   375 
         Left            =   1320 
         TabIndex        =   10 
         Top             =   2868 
         Width           =   2295 
      End 
      Begin VB.TextBox txtCompany  
         Height          =   375 
         Left            =   1320 
         TabIndex        =   9 
         Top             =   3365 
         Width           =   2295 
      End 
      Begin VB.TextBox txtMemo  
         Height          =   375 
         Left            =   1320 
         TabIndex        =   8 
         Top             =   3863 
         Width           =   2295 
      End 
      Begin VB.ComboBox cmbTickType  
         Height          =   300 
         ItemData        =   "frmModifyBus.frx":0000 
         Left            =   1320 
         List            =   "frmModifyBus.frx":000A 
         TabIndex        =   7 
         Text            =   "无人售票" 
         Top             =   1414 
         Width           =   2295 
      End 
      Begin VB.ComboBox cmbPrice  
         Height          =   300 
         ItemData        =   "frmModifyBus.frx":0022 
         Left            =   1320 
         List            =   "frmModifyBus.frx":002F 
         TabIndex        =   6 
         Text            =   "上车一元" 
         Top             =   1911 
         Width           =   2295 
      End 
      Begin VB.OptionButton optIC1  
         Caption         =   "是" 
         Height          =   255 
         Left            =   1320 
         TabIndex        =   5 
         Top             =   2431 
         Value           =   -1  'True 
         Width           =   615 
      End 
      Begin VB.OptionButton optIC2  
         Caption         =   "否" 
         Height          =   255 
         Left            =   2160 
         TabIndex        =   4 
         Top             =   2431 
         Width           =   1215 
      End 
      Begin VB.Label Label5  
         AutoSize        =   -1  'True 
         Caption         =   "线路名:" 
         Height          =   180 
         Left            =   540 
         TabIndex        =   20 
         Top             =   480 
         Width           =   720 
      End 
      Begin VB.Label Label6  
         AutoSize        =   -1  'True 
         Caption         =   "运行区间:" 
         Height          =   180 
         Left            =   360 
         TabIndex        =   19 
         Top             =   977 
         Width           =   900 
      End 
      Begin VB.Label Label7  
         AutoSize        =   -1  'True 
         Caption         =   "售票类型:" 
         Height          =   180 
         Left            =   360 
         TabIndex        =   18 
         Top             =   1474 
         Width           =   900 
      End 
      Begin VB.Label Label8  
         AutoSize        =   -1  'True 
         Caption         =   "票价:" 
         Height          =   180 
         Left            =   720 
         TabIndex        =   17 
         Top             =   1971 
         Width           =   540 
      End 
      Begin VB.Label Label9  
         AutoSize        =   -1  'True 
         Caption         =   "支持IC卡:" 
         Height          =   180 
         Left            =   360 
         TabIndex        =   16 
         Top             =   2468 
         Width           =   900 
      End 
      Begin VB.Label Label10  
         AutoSize        =   -1  'True 
         Caption         =   "运行时间:" 
         Height          =   180 
         Left            =   360 
         TabIndex        =   15 
         Top             =   2965 
         Width           =   900 
      End 
      Begin VB.Label Label11  
         AutoSize        =   -1  'True 
         Caption         =   "公交公司:" 
         Height          =   180 
         Left            =   360 
         TabIndex        =   14 
         Top             =   3462 
         Width           =   900 
      End 
      Begin VB.Label Label3  
         AutoSize        =   -1  'True 
         Caption         =   "备注:" 
         Height          =   180 
         Left            =   720 
         TabIndex        =   13 
         Top             =   3960 
         Width           =   540 
      End 
   End 
   Begin VB.CommandButton cmdModify  
      Caption         =   "修改" 
      Height          =   495 
      Left            =   5340 
      TabIndex        =   2 
      Top             =   5640 
      Width           =   975 
   End 
   Begin VB.CommandButton cmdExit  
      Caption         =   "退出" 
      Height          =   495 
      Left            =   6480 
      TabIndex        =   1 
      Top             =   5640 
      Width           =   975 
   End 
   Begin VB.CommandButton cmdCancel  
      Caption         =   "取消" 
      Height          =   495 
      Left            =   4200 
      TabIndex        =   0 
      Top             =   5640 
      Visible         =   0   'False 
      Width           =   975 
   End 
   Begin VB.Label Label2  
      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            =   2520 
      TabIndex        =   23 
      Top             =   240 
      Width           =   2805 
   End 
End 
Attribute VB_Name = "frmModifybus" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
Dim gID As Long '模块变量,保存修改记录的关键字 
Private Sub cmdModify_Click() 
    Dim str1 As String 
    Dim cnn As New ADODB.Connection '数据库连接 
    If cmdModify.Caption = "修改" Then  '按钮为“修改”状态 
        cmdModify.Caption = "保存"  '修改按钮标题为“保存”,提示用户保存数据 
        cmdCancel.Visible = True    '显示“取消”按钮 
        lstbus.Enabled = False  '禁止用户操作列表框 
         
        LockControl (False)  '允许用户操作窗口中部分控件 
    Else 
        If gID <= 0 Then 
            MsgBox "系统出错!", vbCritical + vbOKOnly 
            Unload Me 
        End If 
        If Not CheckInput Then Exit Sub '调用CheckInput函数检查输入数据 
        cmdModify.Caption = "修改"  '修改按钮标题为“修改” 
        cmdCancel.Visible = False   '隐藏“取消按钮" 
        lstbus.Enabled = True   '允许用户操作列表框 
         
        LockControl (True)  '锁定窗口中部分控件 
 
            '定义新增数据的SQL语句 
        str1 = "UPDATE [BUS] SET [bus]='" & Trim(txtbus.Text) & "',"    '线路名 
        str1 = str1 + "[beginend]='" & Trim(txtBeginEnd.Text) & "',"   '运行区间 
        str1 = str1 + "[ticktype]='" & Trim(cmbTickType.Text) & "',"    '售票类型 
        str1 = str1 + "[price]='" & Trim(cmbPrice.Text) & "',"    '票价 
        If optIC1.Value Then    '是否支持IC卡 
            str1 = str1 + "[ic]=true,"  '支持 
        Else 
            str1 = str1 + "[ic]=false," '不支持 
        End If 
        str1 = str1 + "[runtime]='" & Trim(txtRuntime.Text) & "',"     '运行时间 
        str1 = str1 + "[company]='" & Trim(txtCompany.Text) & "',"      '公交公司 
        If Not IsNull(txtMemo.Text) Then 
            str1 = str1 + "[memo]='" & Trim(txtMemo.Text) & "'"   '备注 
        End If 
        str1 = str1 + " WHERE id=" & gID    '条件 
         
        cnn.ConnectionString = Conn '设置数据库连接字符串 
        cnn.Open    '打开数据库连接 
        cnn.Execute (str1)  '执行UPDATE语句更新数据 
        cnn.Close   '关闭数据库连接 
        Form_Load 
    End If 
End Sub 
 
Private Sub cmdCancel_Click()   '“取消”按钮放弃输入的值 
    lstbus.Enabled = True   '允许用户操作列表框 
    cmdCancel.Visible = False   '隐藏“取消”按钮,使其不可见 
    cmdAddbus.Caption = "新增"  '修改“保存”按钮标题为“新增” 
     
    LockControl (True)  '锁定窗口中部分控件 
 
    lstbus_Click    '调用列表框的单击事件代码 
End Sub 
 
Private Sub cmdExit_Click() '退出当前窗体 
    Dim ret As Integer 
    If cmdModify.Caption = "保存" Then  '判断是否有输入的信息未保存 
        ret = MsgBox("新增数据还未保存,是否退出?", vbQuestion + vbYesNo)  '获取用户的选择 
        If ret = vbNo Then  '选择“否” 
            Exit Sub    '退出当前过程,则不退出当前窗体 
        End If 
    End If 
    Unload Me   '退出当前窗体 
End Sub 
 
 
 
Private Sub Form_Load() '窗体初始化代码 
    Dim cnn As New ADODB.Connection '定义数据库连接变量 
    Dim rst As New ADODB.Recordset  '定义记录集变量 
     
    LockControl (True)  '锁定窗口中部分控件 
     
    cnn.ConnectionString = Conn '设置数据库连接字符串 
    cnn.Open    '打开数据库连接 
     
    Set rst.ActiveConnection = cnn  '设置记录集的数据库连接 
    rst.Open "SELECT [bus] FROM [bus]"  '打开记录集,得到线路名数据 
     
    lstbus.Clear 
    Do While Not rst.EOF    '循环处理记录集中的数据 
        lstbus.AddItem rst(0).Value    '将线路名添加到列表框中 
        rst.MoveNext    '处理下一记录 
    Loop 
     
    If lstbus.ListCount > 0 Then    '列表框中有数据 
        lstbus.ListIndex = 0    '选中第1个数据 
    End If 
     
    rst.Close   '关闭记录集 
    cnn.Close   '关闭数据库连接 
End Sub 
 
Private Sub lstbus_Click()  '单击列表框时,更新右侧的显示数据 
    Dim cnn As New ADODB.Connection '定义数据库连接 
    Dim rst As New ADODB.Recordset  '定义记录集 
    Dim str1 As String, str2 As String  '临时字符串变量 
     
    str1 = lstbus.List(lstbus.ListIndex)    '获取列表框中的选中项(可介绍一下列表框) 
     
    cnn.ConnectionString = Conn '设置数据库连接字符串 
    cnn.Open    '打开数据库连接 
     
    Set rst.ActiveConnection = cnn  '设置记录集的数据库连接 
    str2 = "SELECT * FROM [BUS] WHERE BUS='" & Trim(str1) & "'"   '定义查询字符串 
    rst.Open str2   '打开记录集 
     
    If Not rst.EOF Then '若记录集不为空,显示内容 
        gID = rst("id") '记录关键字 
        txtbus.Text = rst("bus")  '线路名 
        txtBeginEnd.Text = rst("beginend")  '运行区间 
        cmbTickType.Text = rst("ticktype")  '售票类型 
        cmbPrice.Text = rst("price")    '票价 
        If rst("ic") = True Then    '支持IC卡 
            optIC1.Value = True 
        Else    '不支持IC卡 
            optIC2.Value = True 
        End If 
        txtRuntime.Text = rst("runtime")    '运行时间 
        txtCompany.Text = rst("company")    '公交公司 
        If Not IsNull(rst("memo")) Then '若备注不为空 
            txtMemo.Text = rst("memo")  '显示备注 
        End If 
    Else    '若记录集为空,清空显示内容 
        txtbus.Text = "" 
        txtBeginEnd.Text = "" 
        cmbTickType.Text = "" 
        cmbPrice.Text = "" 
        optIC2.Value = True 
        txtRuntime.Text = "" 
        txtCompany.Text = "" 
        txtMemo.Text = "" 
    End If 
 
    rst.Close   '关闭记录集 
    cnn.Close   '关闭数据库连接 
End Sub 
 
Function CheckInput() As Boolean    '检查用户输入的内容 
    CheckInput = False  '设置函数初始返回值为False 
     
    If Trim(txtbus.Text) = "" Then  '若“线路名”为空 
        MsgBox "请输入线路名称!", vbCritical + vbOKOnly, "警告"    '提示信息 
        txtbus.SetFocus '设置输入焦点 
        Exit Function   '退出函数 
    End If 
     
    If Trim(txtBeginEnd.Text) = "" Then '若“运行区间”为空 
        MsgBox "请输入该线路的运行区间!", vbCritical + vbOKOnly, "警告"    '提示信息 
        txtBeginEnd.SetFocus    '设置输入焦点 
        Exit Function   '退出函数 
    End If 
     
    If Trim(txtRuntime.Text) = "" Then  '若“运行时间”为空 
        MsgBox "请输入该线路的运行时间!", vbCritical + vbOKOnly, "警告"    '提示信息 
        txtRuntime.SetFocus '设置输入焦点 
        Exit Function   '退出函数 
    End If 
     
    If Trim(txtCompany.Text) = "" Then  '若“公交公司”为空 
        MsgBox "请输入该线路所属公司!", vbCritical + vbOKOnly, "警告"  '提示信息 
        txtCompany.SetFocus '设置输入焦点 
        Exit Function   '退出函数 
    End If 
     
    CheckInput = True   '设置函数返回值为True 
End Function 
 
Private Sub LockControl(bShow As Boolean)   '锁定窗体中的部分控件 
    txtbus.Locked = bShow 
    txtBeginEnd.Locked = bShow 
    cmbTickType.Locked = bShow 
    cmbPrice.Locked = bShow 
    optIC1.Enabled = Not bShow 
    optIC2.Enabled = Not bShow 
    txtRuntime.Locked = bShow 
    txtCompany.Locked = bShow 
    txtMemo.Locked = bShow 
End Sub