www.pudn.com > BeiJingBusSerchSystem.rar > frmadd.frm, change:2008-11-23,size:14606b


VERSION 5.00 
Begin VB.Form frmAddBus  
   Caption         =   "北京市公交查询系统" 
   ClientHeight    =   6525 
   ClientLeft      =   60 
   ClientTop       =   450 
   ClientWidth     =   7875 
   LinkTopic       =   "Form1" 
   ScaleHeight     =   6525 
   ScaleWidth      =   7875 
   StartUpPosition =   3  '窗口缺省 
   Begin VB.CommandButton cmdCancel  
      Caption         =   "取消" 
      Height          =   495 
      Left            =   4200 
      TabIndex        =   10 
      Top             =   5760 
      Visible         =   0   'False 
      Width           =   975 
   End 
   Begin VB.CommandButton cmdExit  
      Caption         =   "退出" 
      Height          =   495 
      Left            =   6480 
      TabIndex        =   12 
      Top             =   5760 
      Width           =   975 
   End 
   Begin VB.CommandButton cmdAddbus  
      Caption         =   "新增" 
      Height          =   495 
      Left            =   5340 
      TabIndex        =   11 
      Top             =   5760 
      Width           =   975 
   End 
   Begin VB.Frame Frame2  
      Caption         =   "线路信息" 
      Height          =   4575 
      Left            =   3480 
      TabIndex        =   15 
      Top             =   960 
      Width           =   4095 
      Begin VB.OptionButton optIC2  
         Caption         =   "否" 
         Height          =   255 
         Left            =   2160 
         TabIndex        =   6 
         Top             =   2431 
         Width           =   1215 
      End 
      Begin VB.OptionButton optIC1  
         Caption         =   "是" 
         Height          =   255 
         Left            =   1320 
         TabIndex        =   5 
         Top             =   2431 
         Value           =   -1  'True 
         Width           =   615 
      End 
      Begin VB.ComboBox cmbPrice  
         Height          =   300 
         ItemData        =   "frmadd.frx":0000 
         Left            =   1320 
         List            =   "frmadd.frx":000D 
         TabIndex        =   4 
         Text            =   "上车一元" 
         Top             =   1911 
         Width           =   2295 
      End 
      Begin VB.ComboBox cmbTickType  
         Height          =   300 
         ItemData        =   "frmadd.frx":002F 
         Left            =   1320 
         List            =   "frmadd.frx":0039 
         TabIndex        =   3 
         Text            =   "无人售票" 
         Top             =   1414 
         Width           =   2295 
      End 
      Begin VB.TextBox txtMemo  
         Height          =   375 
         Left            =   1320 
         TabIndex        =   9 
         Top             =   3863 
         Width           =   2295 
      End 
      Begin VB.TextBox txtCompany  
         Height          =   375 
         Left            =   1320 
         TabIndex        =   8 
         Top             =   3365 
         Width           =   2295 
      End 
      Begin VB.TextBox txtRuntime  
         Height          =   375 
         Left            =   1320 
         TabIndex        =   7 
         Top             =   2868 
         Width           =   2295 
      End 
      Begin VB.TextBox txtBeginEnd  
         Height          =   375 
         Left            =   1320 
         TabIndex        =   2 
         Top             =   880 
         Width           =   2295 
      End 
      Begin VB.TextBox txtbus  
         Height          =   375 
         Left            =   1320 
         TabIndex        =   1 
         Top             =   383 
         Width           =   2295 
      End 
      Begin VB.Label Label3  
         AutoSize        =   -1  'True 
         Caption         =   "备注:" 
         Height          =   180 
         Left            =   720 
         TabIndex        =   23 
         Top             =   3960 
         Width           =   540 
      End 
      Begin VB.Label Label11  
         AutoSize        =   -1  'True 
         Caption         =   "公交公司:" 
         Height          =   180 
         Left            =   360 
         TabIndex        =   22 
         Top             =   3462 
         Width           =   900 
      End 
      Begin VB.Label Label10  
         AutoSize        =   -1  'True 
         Caption         =   "运行时间:" 
         Height          =   180 
         Left            =   360 
         TabIndex        =   21 
         Top             =   2965 
         Width           =   900 
      End 
      Begin VB.Label Label9  
         AutoSize        =   -1  'True 
         Caption         =   "支持IC卡:" 
         Height          =   180 
         Left            =   360 
         TabIndex        =   20 
         Top             =   2468 
         Width           =   900 
      End 
      Begin VB.Label Label8  
         AutoSize        =   -1  'True 
         Caption         =   "票价:" 
         Height          =   180 
         Left            =   720 
         TabIndex        =   19 
         Top             =   1971 
         Width           =   540 
      End 
      Begin VB.Label Label7  
         AutoSize        =   -1  'True 
         Caption         =   "售票类型:" 
         Height          =   180 
         Left            =   360 
         TabIndex        =   18 
         Top             =   1474 
         Width           =   900 
      End 
      Begin VB.Label Label6  
         AutoSize        =   -1  'True 
         Caption         =   "运行区间:" 
         Height          =   180 
         Left            =   360 
         TabIndex        =   17 
         Top             =   977 
         Width           =   900 
      End 
      Begin VB.Label Label5  
         AutoSize        =   -1  'True 
         Caption         =   "线路名:" 
         Height          =   180 
         Left            =   540 
         TabIndex        =   16 
         Top             =   480 
         Width           =   720 
      End 
   End 
   Begin VB.Frame Frame1  
      Caption         =   "线路" 
      Height          =   4575 
      Left            =   240 
      TabIndex        =   14 
      Top             =   960 
      Width           =   3015 
      Begin VB.ListBox lstbus  
         Height          =   3840 
         Left            =   120 
         TabIndex        =   0 
         Top             =   360 
         Width           =   2655 
      End 
   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            =   3240 
      TabIndex        =   13 
      Top             =   360 
      Width           =   1140 
   End 
End 
Attribute VB_Name = "frmAddBus" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
Private Sub cmdAddbus_Click() 
    Dim str1 As String 
    Dim cnn As New ADODB.Connection '数据库连接 
    If cmdAddbus.Caption = "新增" Then  '按钮为“新增”状态 
        cmdAddbus.Caption = "保存"  '修改按钮标题为“保存”,提示用户保存数据 
        cmdCancel.Visible = True    '显示“取消”按钮 
        lstbus.Enabled = False  '禁止用户操作列表框 
         
        LockControl (False)  '允许用户操作窗口中部分控件 
 
        txtbus.Text = ""    '清除“线路名”文本框 
        txtBeginEnd.Text = ""    '清除“运行区间”文本框 
        cmbTickType.Text = "无人售票"    '设置售票类型的默认值 
        cmbPrice.Text = "上车一元"  '设置票价的默认值 
        optIC2.Value = True    '设置不支持IC卡 
        txtRuntime.Text = ""    '清除“运行时间”文本框 
        txtCompany.Text = ""    '清除“公交公司”文本框 
        txtMemo.Text = ""       '清除“备注”文本框 
    Else 
        If Not CheckInput Then Exit Sub '调用CheckInput函数检查输入数据 
        cmdAddbus.Caption = "新增"  '修改按钮标题为“新增” 
        cmdCancel.Visible = False   '隐藏“取消按钮" 
        lstbus.Enabled = True   '允许用户操作列表框 
         
        LockControl (True)  '锁定窗口中部分控件 
 
            '定义新增数据的SQL语句 
        str1 = "INSERT INTO [BUS]([busid],[beginend],[ticktype],[price]" 
        str1 = str1 + ",[ic],[runtime],[company],[memo]) VALUES("   'INSERT INTO语句 
        str1 = str1 + "'" + txtbus.Text + "','" '线路名 
        str1 = str1 + txtBeginEnd.Text + "','"  '运行区间 
        str1 = str1 + cmbTickType.Text + "','"  '售票类型 
        str1 = str1 + cmbPrice.Text + "',"  '票价 
        If optIC1.Value Then    '是否支持IC卡 
            str1 = str1 + "true,'"  '支持 
        Else 
            str1 = str1 + "false,'" '不支持 
        End If 
        str1 = str1 + txtRuntime.Text + "','"   '运行时间 
        str1 = str1 + txtCompany.Text + "','"   '公交公司 
        str1 = str1 + txtMemo.Text + "')"   '备注 
         
        cnn.ConnectionString = Conn '设置数据库连接字符串 
        cnn.Open    '打开数据库连接 
        cnn.Execute (str1)  '执行INSERT INTO语句插入数据 
        cnn.Close   '关闭数据库连接 
    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 cmdAddbus.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 [busid] FROM [bus]"  '打开记录集,得到线路名数据 
     
    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 BUSID='" & Trim(str1) & "'"   '定义查询字符串 
    rst.Open str2   '打开记录集 
     
    If Not rst.EOF Then '若记录集不为空,显示内容 
        txtbus.Text = rst("busid")  '线路名 
        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    '检查用户输入的内容 
    Dim str1 As String  '临时变量 
    Dim cnn As New ADODB.Connection '定义数据库连接 
    Dim rst As New ADODB.Recordset  '定义记录集 
    CheckInput = False  '设置函数初始返回值为False 
     
    If Trim(txtbus.Text) = "" Then  '若“线路名”为空 
        MsgBox "请输入线路名称!", vbCritical + vbOKOnly, "警告"    '提示信息 
        txtbus.SetFocus '设置输入焦点 
        Exit Function   '退出函数 
    End If 
    str1 = "SELECT COUNT(*) FROM [BUS] WHERE BUSID='" & Trim(txtbus.Text) + "'" '定义SQL语句,查询是否已有该线路 
    cnn.ConnectionString = Conn '设置数据库连接字符串 
    cnn.Open    '打开数据库连接 
    Set rst = cnn.Execute(str1) '执行SQL语句,返回结果 
    If rst(0) > 0 Then  '若满足条件的记录数大于0 
        MsgBox "系统中已有线路【" & Trim(txtbus.Text) + "】的资料!", 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