摘要:文章從軟件設(shè)計的角度出發(fā),分別從編程語言的選用,數(shù)據(jù)流圖,數(shù)據(jù)庫,數(shù)據(jù)表的建立等方面介紹新生報名系統(tǒng)的建立過程。根據(jù)需求分析設(shè)計的要求,選擇相應(yīng)的算法設(shè)計系統(tǒng),在VB 6.0應(yīng)用程序的基礎(chǔ)上,實現(xiàn)如何建立數(shù)據(jù)庫,查詢數(shù)據(jù)庫,填寫數(shù)據(jù)庫。
關(guān)鍵詞:數(shù)據(jù)流圖;ER圖; Visual Basic; VisData
The Designation and Realization of Freshman Enrolled in System Based on Visual Basic
CAO Hui-ru1, ZHANG Xiao-jun2
(1.Guangzhou Huali Science and Technology Vocational College, Department of Computer Science,Guangzhou 511325,China;2.Guangdong University of Technology Institute,Department of Computer Science,Guangzhou 511325,China)
Abstract: From the perspective of software design, this paper introduces the building of a system for freshman enrolled in, in aspect of the choice of programming language, and the creation of DF diagram, database,database tables,etc. According to the needs of demand analysis and design, choose related algorithm design system.
Key words: Data flow diagram; ER diagram; Visual Basic; VisData
隨著數(shù)字化的來臨,各院校相繼建立了相應(yīng)的電子數(shù)據(jù),而新生報名注冊系統(tǒng)就成為首當(dāng)其沖需要建立的電子系統(tǒng)。
1 系統(tǒng)需求分析
1.1 軟件設(shè)計需求
新生報名系統(tǒng)軟件,1) 能夠在新生報名時,第一時間查詢其信息。2) 報名時其他信息的添加。3) 同時,該軟件有相應(yīng)的登錄保護(hù)系統(tǒng)。
1.2 軟件設(shè)計的流程圖
根據(jù)軟件需求分析,畫出相應(yīng)的流程圖(如圖1)。
2 系統(tǒng)相關(guān)數(shù)據(jù)的建立
2.1 數(shù)據(jù)庫的ER圖
根據(jù)系統(tǒng)設(shè)計要求,建立相應(yīng)的數(shù)據(jù)庫,在建立數(shù)據(jù)庫之前,應(yīng)先建立ER圖(如圖2),進(jìn)而確定關(guān)鍵字,由于學(xué)生準(zhǔn)考證無重復(fù)并且無相同,故選擇其作為關(guān)鍵字。
2.2數(shù)據(jù)庫的建立
使用VB 6.0系統(tǒng)自帶的“可視化數(shù)據(jù)管理器”來建立系統(tǒng)所需要的數(shù)據(jù),操作如下:1) 打開VB 6.0應(yīng)用程序,選擇“外接程序”,“可視化數(shù)據(jù)管理器”,進(jìn)入VisData窗口;
2) 利用菜單欄的“文件”-?“新建”命令創(chuàng)建數(shù)據(jù)庫(如圖3)。
3) 給數(shù)據(jù)庫命名并保存數(shù)據(jù)庫。
2.3 數(shù)據(jù)庫的表
在建立數(shù)據(jù)表之前先對系統(tǒng)所需要的數(shù)據(jù)進(jìn)行分析,確定需要的數(shù)據(jù)表的個數(shù);確定好數(shù)據(jù)表的個數(shù)之后,再針對每個表進(jìn)行整體規(guī)劃,確定各個字段的數(shù)據(jù)類型以及字段長度,保證數(shù)據(jù)在系統(tǒng)中的合理分配。將這些內(nèi)容確定好之后就開始數(shù)據(jù)表的創(chuàng)建。
2.4 VB和數(shù)據(jù)庫的連接
VB6.0與數(shù)據(jù)庫的連接方法有以下四種:
方法一:
當(dāng)數(shù)據(jù)源為DSN時,必須首先配置main1數(shù)據(jù)源,然后定義如下:
Public Sub ConnectionString_example()
Dim conn As ADODB.Connection
conn.ConnectionString = \"DSN=(此處填寫數(shù)據(jù)庫路徑)main1\"
End Sub
方法二:
當(dāng)數(shù)據(jù)源為main1.udl鏈接文件時,應(yīng)首先建立main1.udl數(shù)據(jù)文件,后定義:
Public Sub ConnectionString_example()
Dim conn As ADODB.Connection
conn.ConnectionString = \"FileName= main1\"
End Sub
方法三:
當(dāng)數(shù)據(jù)源為默認(rèn)的ODBC數(shù)據(jù)提供者時,首先知道數(shù)據(jù)源為main1,后定義:
Public Sub ConnectionString_example()
Dim conn As ADODB.Connection
conn.ConnectionString = \"Provider=MSDASQL.1;DataSource=(此處填寫數(shù)據(jù)庫路徑)main1\"
End Sub
方法四:
當(dāng)數(shù)據(jù)源為Micosoft jet3.51時,并指定將與Access數(shù)據(jù)文件鏈接時,定義如下:
Public Sub ConnectionString_example()
Dim conn As ADODB.Connection
connstring = \"provider=Microsoft.Jet.OLEDB.3.51;Data source =\" App.Path \"/main1.mdb\"
End Sub
3 系統(tǒng)設(shè)計過程
3.1 系統(tǒng)登錄窗口的設(shè)計以及在VB6.0應(yīng)用程序中的體現(xiàn)
3.1.1 系統(tǒng)登錄窗口的設(shè)計
為了保護(hù)系統(tǒng)安全,需要建立登錄窗口,具體的程序如下:
Private Sub cmd_login_Click()
If Trim(user_name.Text) = \"\" Then
MsgBox \"用戶名不能為空!\", vbExclamation + vbOKOnly, \"警告\"
user_name.SetFocus
Exit Sub
End If
'用戶名是否為空的判斷
If Trim(password.Text) = \"\" Then
MsgBox \"密碼不能為空!\", vbExclamation + vbOKOnly, \"警告\"
password.SetFocus
Exit Sub
End If
'密碼框是否為空的判斷
Dim conn As New ADODB.Connection
Dim mrc As ADODB.Recordset
txtsql = \"select name from user where name='\" Trim(user_name.Text) \"'\"
Set mrc = ExecuteSQL(txtsql)
If mrc.EOF = True Then
MsgBox \" 用戶名錯誤!\", vbExclamation + vbOKOnly, \"警告\"
user_name.SetFocus
user_name.SelStart = 0
user_name.SelLength = Len(user_name.Text)
Exit Sub
End If
txtsql = \"select sid from user where sid='\" Trim(password.Text) \"'\"
Set mrc = ExecuteSQL(txtsql)
If mrc.EOF = True Then
MsgBox \" 密碼錯誤!\", vbExclamation + vbOKOnly, \"警告\"
password.SetFocus
password.SelStart = 0
password.SelLength = Len(password.Text)
Exit Sub
End If
'用戶名和密碼的確認(rèn),即確認(rèn)輸入的用戶名和密碼是否與數(shù)據(jù)庫中的一致
frm_login.Hide
frm_main.Show
End Sub
3.1.2 在VB6.0中程序?qū)崿F(xiàn)的窗口
如圖4。
3.2 系統(tǒng)查詢窗口的實現(xiàn)
3.2.1 為了實現(xiàn)查詢,可以添加如下的程序
Private Sub cmd_look_Click()
Dim str1, str2 As String
str1 = Trim(InputBox(\"\", \"\"))
If str1 <> \"\" Then
str2 = \"number='\" str1 \"'\"
Data1.Recordset.FindFirst str2
If Data1.Recordset.NoMatch Then
MsgBox \"no match\"
Data1.Recordset.MoveLast
End If
End If
End Sub
3.2.2 在VB6.0中程序?qū)崿F(xiàn)的窗口
如圖5。
3.3 數(shù)據(jù)更新的實現(xiàn)
Private Sub cmd_submit_Click()
txt_time.Text = Date$ \" \" Time$
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
txtsql = \"select name from base_infor where name='\" Trim(txt_name.Text) \"'\"
Set mrc = ExecuteSQL(txtsql)
If mrc.EOF = False Then
MsgBox \"該同學(xué)已注冊 \", vbExclamation + vbOKOnly, \"警告\"
txt_name.SetFocus
txt_name.SelStart = 0
txt_name.SelLength = Len(txt_name.Text)
mrc.Update
Exit Sub
End If
‘此段程序的作用是判斷學(xué)生是否注冊。
rs.Open cmd.CommandText
rs.Fields(\"fee\") = \"¥10000\"
rs.Fields(\"roomtype\") = Combo1.Text
rs.Fields(\"roomnumber\") = Combo2.Text
rs.Fields(\"sum_fee\") = txt_totalfee.Text
rs.Fields(\"time\") = txt_time.Text
rs.Update
rs.Close
conn.Close
End Sub
‘此段程序用于更新數(shù)據(jù)庫。
3.2.3在VB6.0中程序?qū)崿F(xiàn)的窗口
如圖6。
4 結(jié)束語
以上新生報名系統(tǒng)功能是根據(jù)基本的需求設(shè)計的,對于窗體的選擇和具體內(nèi)容的安排上只是做了初步的計劃,但是在具體的使用過程,還需要根據(jù)不同單位的具體要求進(jìn)一步美化界面,豐富內(nèi)容,完善新增的功能。但設(shè)計思路是相似的。
參考文獻(xiàn):
[1] 佟偉光.Visual Basic程序設(shè)計教程[M].2版.北京:電子工業(yè)出版社,2005:184-208.
[2] 劉懷亮.Visual Basic 2005語言程序設(shè)計[M].廣州:研究出版社,2008:137-156.
[3] 趙萬龍.Visual Basic程序設(shè)計[M].2版.北京:中國鐵道出版社,2008:60-82
[3] 趙萬龍.Visual Basic程序設(shè)計習(xí)題解答與上機指導(dǎo)[M].2版.北京:中國鐵道出版社,2008:60-82.