【文章內容簡介】
cmd = New SqlCommand(sqlcmd, conn) 39。執(zhí)行查詢 Dim i As Integer i = () 39。操作完成關閉連接 () Return i Catch ex As Exception MsgBox() End Try End Function ( 3)添加引用。 為了能在基本界面的應用程序中 使用 db 類庫,就必須將其添加到基本界面程序的引用中。 16 基本界面應用程序 設計。 ( 1)主窗體 Form1 設計。 將 Form1 屬性 IsMdiContainer 設置為 Ture,即可為父窗體。 Ⅰ、工具 欄設置。 為了方便用戶在多個功能之間切換,系統(tǒng)在主窗體中設計了工具欄。 將各種功能以按鈕形式放置在工具欄上。 工具欄各個按鈕的圖標,用的是 ImageList 控件來存儲,將其命名為 Imltoolbar,再將要使用的圖片添加到“ Images”中。 從 工具欄中拖放一個 ToolBar 控件至 Form1 中,將其命名為 tlbmain。再在其屬性窗口將其 ImageList 屬性設置為 Imltoolbar。然后設置其 Buttons 屬性 如下: 其中 tbbsep 的 style 屬性為 separator。 添加成功! 在應用程序解決資源管理器中右鍵單擊選擇【添加引用】 17 Ⅱ、 界面預覽 。 Ⅲ、 代碼設計。 ⒈添加變量。 39。記錄登陸用戶權限名稱 ,據此確定工具欄顯示項 Public Shared strlogrole As String ⒉ main 過程 —— 啟動系統(tǒng)并驗證用戶身份。 39。main過程 Public Shared Sub main() 18 39。首先顯示登陸窗體以驗證用戶身份 Dim myfrm As New Frmlogin () () 39。將窗體顯示為沒有所有者窗口的模式對話框 = True 39。窗體顯示為應用程序的最頂層窗體 39。如果登陸成功則記錄下用戶權限并運行主窗體 If = True Then strlogrole = Dim myform1 As New Form1 (myform1) 39。用 application的 run方法運行主窗體對象 End If End Sub ⒊ howshowfrm 函數 —— 判斷窗體是否已打開 Public Function howshowfrm(ByVal strfrmname As String) As Boolean 39。strfrmname表示需要檢查的窗體名稱 39。返回 ture說明已有實例在運行 39。返回 false說明沒有此窗體的實例運行 Dim i As Integer 39。檢查主窗體所有的子窗體 For i = 0 To 1 39。如果子窗體中有窗體名稱和需要打開的窗體同名的 39。說明已經有此窗體的實例在運行 ,此時顯示這個實例即可 If (i).Name = strfrmname Then (i).Focus() Return True Exit Function End If Next 39。沒有找到同名的窗體 ,則說明沒有此實例在運行 Return False End Function ⒋ Form1_Load Private Sub Form1_Load(ByVal sender As , ByVal e As ) Handles Dim m, n As Integer 39。用 m,n記錄窗體的最大寬度和高度 = m = n = 39。將窗體正常顯示時的高度和寬度設為最大值 19 39。如此可保證窗體大小始終為最大 = = n = m = 0 = 0 39。根據用戶的類型設置使用權限 39。一般用戶不能使用資料管理和用戶管理功能 If strlogrole = guest Then (2).Enabled = False (4).Enabled = False ElseIf strlogrole = zladmin Then 39。資料管理用戶不能使用用戶管理功能 (4).Enabled = False End If 39。主窗體中默認打開最常用的橋梁查詢功能 Dim myfrm As New Frmsearch = Me () End Sub ⒌ tlbmain_ButtonClick—— 單擊工具欄按鈕事件響應程序 Private Sub tlbmain_ButtonClick(ByVal sender As , ByVal e As ) Handles 39。根據工具欄不同按鈕的序號打開 不同的窗體 Select Case () Case 0 39。打開橋梁查詢窗體 If howshowfrm(Frmsearch) = True Then Exit Sub End If Dim myfrm As New Frmsearch = Me () Dim myfrm2 As New Frmsearch2 = Me Case 2 39。打開資料管理窗體 If howshowfrm(Frmmanager) = True Then Exit Sub End If Dim myfrm As New Frmmanager = Me () 20 Case 4 39。打開用戶管理窗體 If howshowfrm(Frmuser) = True Then Exit Sub End If Dim myfrm As New Frmuser = Me () Case 6 39。退出系統(tǒng) () Case 8 39。關于 If howshowfrm(Frmabout) = True Then Exit Sub End If Dim myfrm As New Frmabout = Me () End Select End Sub ⒍ Form1_Closing—— 關閉主窗體時請求用戶確認 Private Sub Form1_Closing(ByVal sender As Object, ByVal e As ) Handles If MsgBox(確定要退出系統(tǒng)嗎 ?, + ) = Then 39。如果用戶選擇了否 則取消退出操作 = True 39。將系統(tǒng)參數 e的 cancel屬性設置為 true,就取消了關閉操作 End If End Sub ( 2)系統(tǒng)登陸窗體設計。 Ⅰ、 界面預覽 。 21 Ⅱ、代碼設計。 ⒈ 添加引用。 Imports ⒉ 添加全局變量。 39。定義一字符串變量 保存數據庫連接信息 Dim strcon As String = 39。記錄登陸用戶的權限 Public strloginrole As String 39。記錄用戶是否成功登陸 Public blnloginsucc As Boolean Dim try_times As Integer = 0 ⒊ Frmlogin_Load Private Sub Frmlogin_Load(ByVal sender As Object, ByVal e As ) Handles 39。定義 4個變量用于檢索用戶表的用戶名字段 Dim strsql As String = select 用戶名 from 用戶 Dim mycon As New SqlConnection(strcon) Dim my As New SqlCommand(strsql, mycon) Dim myreader As SqlDataReader Try 39。打開 數據庫連接 () 39。逐條讀取用戶表記錄的用戶名字段 myreader = 39。字段非空時將檢索值加到 cmbid組合框中 While () (myreader(0)) End While 39。操作完成關 閉數據庫連接 () () Catch ex As Exception MsgBox(, ) () () End Try 39。有帳戶信息時設置 guest為默認用戶名 If 0 Then = guest End If 22 39。將焦點設置到密碼輸入框 () End Sub ⒋ btnok_Click—— 單擊【確定】響應程序 Private Sub btnok_Click(ByVal sender As Object, ByVal e As ) Handles 39。定義 4個變量用于 檢索用戶表的權限字段 39。檢索條件是賬號和密碼都符合用戶輸入 Dim strsql As String = select 權限 from 用戶 where 用戶名 = 39。 amp。 amp。 39。and 密碼 = 39。 amp。 amp。 39。 Dim mycon As New SqlConnection(strcon) Dim my As New SqlCommand(