




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、2012年 11月17日實驗類型_驗證性_ 實驗室_軟件實驗室一_一、實驗題目 用戶管理及登錄程序設(shè)計二、實驗?zāi)康?通過本次實驗,使學(xué)生了解托盤程序的應(yīng)用及設(shè)計思想,利用Timer控件和NotifyIcon控件實現(xiàn)一個動態(tài)托盤程序。三、實驗內(nèi)容1、實現(xiàn)對用戶的各種管理,包括新增、修改、刪除、停用、啟用、重置密碼、查詢等。2、實現(xiàn)完整的用戶登錄系統(tǒng)。3、對敏感數(shù)據(jù)進行加密處理。4、用.NET分層架構(gòu)設(shè)計。四、實驗代碼(注明代碼所實現(xiàn)的功能)1.數(shù)據(jù)庫設(shè)計:數(shù)據(jù)庫的名字是:student management,在此數(shù)據(jù)庫下創(chuàng)建一張表:gg_User加密:Me.TextBox2.Text=Syste
2、m.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Me.TextBox1.Text & Me.TextBox2.Text, MD5)加密后:gg_User表內(nèi)的數(shù)據(jù)如圖:2. 登陸界面:(針對form1)Public Class form1 Dim o As New myData.ClsUser Dim f2 As New homepage Private Sub 登陸_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Ha
3、ndles 登陸.Click Dim dr As SqlClient.SqlDataReader dr = o.getall2dr(Me.TextBox1.Text) If dr.Read() Then If dr.Item(user_pwd) = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Me.TextBox2.Text, MD5) Then If dr.Item(User_state) = 啟用 Then MsgBox(登錄成功, MsgBoxStyle.MsgBoxRight) f
4、2.Show() Me.Close() Else MsgBox(此用戶未啟用) End If Else MsgBox(請輸入正確的密碼, MsgBoxStyle.Information) End If Else MsgBox(請輸入正確的用戶名, MsgBoxStyle.Critical) End If End SubEnd Class3.主界面:用到各種控件:DataGridView控件、GroupBox控件、textbox以及botton等DataGridView控件用于用來顯示數(shù)據(jù)。3創(chuàng)建類庫ClsUser,聯(lián)機式訪問數(shù)據(jù)庫:DataReader對象:Public Function ge
5、tall2dr(ByVal strWhere As String) As SqlClient.SqlDataReader Dim conn As New SqlClient.SqlConnection設(shè)定連接字符串 conn.ConnectionString = comm.clsStrconn.getStrConn Dim cmd As New SqlClient.SqlCommand cmd.CommandType = CommandType.Text cmd.Connection = conn If strWhere = Then cmd.CommandText = select * fr
6、om gg_user Else cmd.CommandText = select * from gg_user where & strWhere End If Dim dr As SqlClient.SqlDataReader conn.Open() dr = cmd.ExecuteReader(CommandBehavior.CloseConnection) Return drEnd Function4.創(chuàng)建類clsStrconn:Public Class clsStrconn server=ZGC-20111121JBZ;uid=sa;pwd=;database=jxsl Public S
7、hared Function getStrConn() As String Dim strConn As String strConn = server= & System.Configuration.ConfigurationManager.AppSettings(server) & ; strConn &= uid= & System.Configuration.ConfigurationManager.AppSettings(uid) & ; strConn &= pwd= & System.Configuration.ConfigurationManager.AppSettings(p
8、wd) & ; strConn &= database= & System.Configuration.ConfigurationManager.AppSettings(database) Return strConn End FunctionEnd Class5.用戶信息管理: a增加用戶信息:在類庫ClsUser中進行定義,Public Function delete() As String建立鏈接數(shù)據(jù)庫,數(shù)據(jù)庫名為student management Dim conn As New SqlClient.SqlConnection conn.ConnectionString = comm.
9、clsStrconn.getStrConn建立command對象 Dim cmd As New SqlClient.SqlCommand設(shè)定活動鏈接 cmd.Connection = conn設(shè)定要執(zhí)行的命令 cmd.CommandText = delete from gg_User where user_id= & duser_id & Try conn.Open() cmd.ExecuteNonQuery() conn.Close() Return 1 Catch ex As Exception conn.Close() Return -1 & ex.Message End Try End
10、 Function 在homepage.vb中進行操作。 Private Sub 增加_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 增加.Click Dim sr As Stringo為重新定義ClsUser o.duser_id = Me.userid.Text o.duser_name = Me.username.Text o.duser_pwd = Me.userpwd.Text o.duser_state = Me.state.Text sr = o.insert If sr = 1
11、 Then MsgBox(添加成功) Call Me.InitGrid() Else MsgBox(添加失敗 & sr) End IfEnd Sub下圖是增加用戶信息,增加“00”“admin”“admin”“啟用”b刪除信息: Public Function delete() As String Dim conn As New SqlClient.SqlConnection conn.ConnectionString = comm.clsStrconn.getStrConn Dim cmd As New SqlClient.SqlCommand cmd.Connection = conn c
12、md.CommandText = delete from gg_User where user_id= & duser_id & Try conn.Open() cmd.ExecuteNonQuery() conn.Close() Return 1 Catch ex As Exception conn.Close() Return -1 & ex.Message End TryEnd FunctionPrivate Sub 刪除_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 刪除.Click
13、Dim sr As String o.duser_id = Me.userid.Text sr = o.delete If sr = 1 Then MsgBox(刪除成功!) Call Me.InitGrid() Else MsgBox(刪除失??! & sr) End If End Sub c修改信息: Public Function update() As String Dim conn As New SqlClient.SqlConnection conn.ConnectionString = comm.clsStrconn.getStrConn Dim cmd As New SqlCli
14、ent.SqlCommand cmd.Connection = conn cmd.CommandText = update gg_user set user_pwd= & duser_pwd & where user_id= & duser_id & Try conn.Open() cmd.ExecuteNonQuery() conn.Close() Return 1 Catch ex As Exception conn.Close() Return -1 & ex.Message End TryEnd FunctionPrivate Sub 修改_Click(ByVal sender As
15、System.Object, ByVal e As System.EventArgs) Handles 修改.Click o.duser_name = Me.username.Text o.duser_id = Me.userid.Text o.duser_state = Me.state.Text Dim sr As String sr = o.update If sr = 1 Then MsgBox(修改成功!) Call Me.InitGrid() Else MsgBox(修改失??!) End If End Sub6.創(chuàng)建應(yīng)用程序配置文件:app.config便于修改 7.數(shù)據(jù)更新:當(dāng)點
16、擊增加(刪除、修改)按鈕,數(shù)據(jù)做一次更新Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Call Me.InitGrid() End SubSub InitGrid() dv = o.getall2ds().Tables(0).DefaultView Me.DataGridView1.DataSource = dv End Sub8.雙擊數(shù)據(jù)進入textbox中Private Sub DataGridView1_CellDoubleCli
17、ck(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClickMe.userid.Text=Me.DataGridView1.Rows(Me.DataGridView1.SelectedCells(0).RowIndex).Cells(user_id).ValueMe.username.Text=Me.DataGridView1.Rows(Me.DataGridView1.SelectedCells(0).RowIndex).Cells(user_name).ValueMe.userpwd.Text=Me.DataGridView1.Rows(Me.DataGridView1.SelectedCells(0).RowIndex).Cells(user_pwd).ValueMe.state.Text=Me.DataGridView1.Rows(Me.DataGridView1.Select
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年十大公務(wù)員培訓(xùn)機構(gòu)排行與選擇指南
- 《腦膜炎的護理》課件
- 沙場借用協(xié)議書
- 車輛轉(zhuǎn)租欠款合同協(xié)議
- 車輛置換買賣合同協(xié)議
- 母女友好協(xié)議書
- 車位銷售合同協(xié)議書模板
- 道路工程修路合同協(xié)議
- 債權(quán)擔(dān)保合同協(xié)議書
- 《手相與健康》課件
- 歌曲版權(quán)轉(zhuǎn)讓協(xié)議書樣式9篇
- 2025時政試題及答案(100題)
- 電力系統(tǒng)的穩(wěn)定性分析試題庫及答案解析
- 《把水變干凈》幼兒園大班科學(xué)課件
- 減震器知識培訓(xùn)課件圖片
- 燒燙傷健康宣教
- 醫(yī)院門診院感制度
- 2025固體礦產(chǎn)地質(zhì)調(diào)查規(guī)范1:25000
- 2025-2030中國具身智能行業(yè)研發(fā)創(chuàng)新策略與未來前景展望報告
- 臺球俱樂部創(chuàng)業(yè)計劃書
- 2025年入團積極分子培訓(xùn)考試題庫及答案
評論
0/150
提交評論