1.引言
計(jì)算機(jī)科學(xué)技術(shù)、數(shù)據(jù)庫技術(shù)以及網(wǎng)絡(luò)技術(shù)的高速發(fā)展,為現(xiàn)代教育方式的改革提供了必要的技術(shù)基礎(chǔ),使得近年來教學(xué)的方法和手段多樣化。教學(xué)過程中大量引入當(dāng)今計(jì)算機(jī)方面的技術(shù),形成各具特色的、更加方便的智能計(jì)算機(jī)教學(xué)系統(tǒng)。而在其中,以計(jì)算機(jī)來輔助的題庫管理系統(tǒng)作為智能計(jì)算機(jī)教學(xué)系統(tǒng)的核心,受到人們廣泛的重視。采用先進(jìn)的計(jì)算機(jī)科學(xué)技術(shù)和數(shù)據(jù)庫技術(shù),利用計(jì)算機(jī)自動(dòng)生成試卷的功能,并通過積累逐步形成有效的、大量的試題庫,使試題和試卷的管理更加的高效和快捷,同時(shí)也使的教學(xué)和考試的方式有了更多的選擇,這對(duì)提高教學(xué)的效率,高效地利用有限的教學(xué)資源和使傳統(tǒng)的教學(xué)方式逐步走向自動(dòng)化具有顯而易見的促進(jìn)作用。
http://ukthesis.org/jsjwl/
2.相關(guān)知識(shí)介紹
2.1 Microsoft Visual Studio平臺(tái)簡(jiǎn)介
Visual Studio是微軟公司于1997年推出的一款軟件開發(fā)平臺(tái),是當(dāng)今應(yīng)用最廣泛的Windows平臺(tái)應(yīng)用程序開發(fā)環(huán)境。這個(gè)平臺(tái)目前已經(jīng)發(fā)展到10.0版本,也就是剛剛推出Visual Studio 2010。Visual Studio可以用來創(chuàng)建Windows平臺(tái)下的Windows應(yīng)用程序和網(wǎng)絡(luò)應(yīng)用程序,同時(shí)也可以用來創(chuàng)建網(wǎng)絡(luò)服務(wù)、智能設(shè)備應(yīng)用程序和Office插件。#p#分頁標(biāo)題#e#
2.2數(shù)據(jù)庫SQL Server簡(jiǎn)介
SQL(Structured Query Language)也就是結(jié)構(gòu)化查詢語言。SQL語言的主要功能就是同各種各樣的數(shù)據(jù)庫建立聯(lián)系,進(jìn)行溝通以及管理。按照ANSI(美國(guó)國(guó)家標(biāo)準(zhǔn)協(xié)會(huì))的規(guī)定,SQL被作為關(guān)系型數(shù)據(jù)庫管理系統(tǒng)的標(biāo)準(zhǔn)語言。SQL語句可以用來執(zhí)行各種數(shù)據(jù)庫操作,例如在數(shù)據(jù)庫中添加數(shù)據(jù),更新數(shù)據(jù)庫中的數(shù)據(jù),從數(shù)據(jù)庫中提取數(shù)據(jù)以及刪除數(shù)據(jù)庫中的數(shù)據(jù)等。絕大多數(shù)當(dāng)今流行的關(guān)系型數(shù)據(jù)庫管理系統(tǒng)都采用了SQL語言標(biāo)準(zhǔn)。很多數(shù)據(jù)庫都對(duì)SQL語句進(jìn)行了再次的發(fā)展,但是包括Insert, Delete, Update, Select, Create以及Drop在內(nèi)的標(biāo)準(zhǔn)的SQL命令依然能夠被用以完成所有的數(shù)據(jù)操作。SQL Server是一個(gè)關(guān)系數(shù)據(jù)庫的管理系統(tǒng)。它最初是由Microsoft、 Sybase 和Ashton-Tate三家公司共同開發(fā)的。
在本項(xiàng)目中,由于版權(quán)原因以及各種其他軟件的適應(yīng)性我們?nèi)匀徊捎肰isual Studio 2005+SQL Server 2005來完成本項(xiàng)目。
2.3高級(jí)程序語言C#簡(jiǎn)介
C#是微軟在2006年發(fā)布的一種為.NET Framework平臺(tái)做的重要的程序語言之一,它有著來源于C/C++的強(qiáng)大功能和Delphi、Visual Basic易用性,它吸收了其他程序語言的許多優(yōu)點(diǎn)卻只有大約80個(gè)關(guān)鍵字。C#是第一個(gè)組件導(dǎo)向的程序語言,同時(shí)也是精確、簡(jiǎn)單的面向?qū)ο缶幊陶Z言。C#語言的定義是從C和C++繼承而來的,從語言中的許多地方都反映出了這一點(diǎn),并且同時(shí)C#也有著自己新的特點(diǎn),比如說還能與其他語言交互操作,C#包含一系列稱之為“類”的獨(dú)立的程序設(shè)計(jì)單元,這些類可以相互作用和交互。它是編寫企業(yè)應(yīng)用程序的一種使用簡(jiǎn)單、功能強(qiáng)大、表達(dá)力豐富的編程語言。
3.系統(tǒng)設(shè)計(jì)分析
3.1開發(fā)模式分析
當(dāng)今的軟件體系架構(gòu),分層式結(jié)構(gòu)是應(yīng)用最為廣泛、最重要的一種結(jié)構(gòu)。分層式結(jié)構(gòu)一般來說可以分為三層,分別是:
(1) 表現(xiàn)層(UI):處于離用戶最近的位置,即表現(xiàn)給用戶的可視化界面,運(yùn)行應(yīng)用程序的時(shí)候用戶的所見所得,用來顯示業(yè)務(wù)邏輯層處理之后的數(shù)據(jù)和接受用戶輸入的數(shù)據(jù)并傳輸給業(yè)務(wù)邏輯層。
(2) 業(yè)務(wù)邏輯層(BLL):是系統(tǒng)架構(gòu)當(dāng)中最能體現(xiàn)其核心價(jià)值的部分。其重點(diǎn)在于對(duì)具體表現(xiàn)層、數(shù)據(jù)訪問層傳過來的數(shù)據(jù)進(jìn)行業(yè)務(wù)合法性驗(yàn)證以及邏輯處理。它處于表現(xiàn)層和數(shù)據(jù)訪問層的中間,在其中起到了承上啟下的關(guān)鍵作用。
(3) 數(shù)據(jù)訪問層(DAL):直接連接并操作數(shù)據(jù)庫中數(shù)據(jù),具體的來實(shí)現(xiàn)數(shù)據(jù)的增加、刪除、修改、查找、數(shù)據(jù)的持久化等,并將結(jié)果提交給業(yè)務(wù)邏輯層。
這種區(qū)分層次的方法是為了實(shí)現(xiàn)低耦合,高內(nèi)聚。三層結(jié)構(gòu)簡(jiǎn)單來說就是在客戶端和數(shù)據(jù)庫之間增加了一個(gè)中間層。所謂的三層體系,并非是指物理上的三層,不是簡(jiǎn)單的將三臺(tái)機(jī)器合在一起就是三層體系結(jié)構(gòu),三層體系結(jié)構(gòu)的應(yīng)用也不僅僅是在C/S、B/S應(yīng)用程序方面,這里的三層指的是邏輯上的三層。三層體系架構(gòu)的應(yīng)用程序?qū)I(yè)務(wù)邏輯、數(shù)據(jù)的處理、合法性驗(yàn)證等工作放到了中間層進(jìn)行處理。一般來說,客戶端是不會(huì)直接對(duì)數(shù)據(jù)庫進(jìn)行處理,而是通過數(shù)據(jù)訪問層來建立連接,再經(jīng)由業(yè)務(wù)邏輯層與數(shù)據(jù)庫進(jìn)行交互等工作。在三層結(jié)構(gòu)的設(shè)計(jì)中,遵循了面向接口設(shè)計(jì)的思想,也就意味著三層結(jié)構(gòu)之間的是向下依賴的,下一層對(duì)于上一層來說是“無知”的,當(dāng)改變上一層的設(shè)計(jì)而不改變下一層的接口定義時(shí)對(duì)于其調(diào)用下一層來說是沒有任何影響的。這樣開發(fā)人員就可以只關(guān)注其中的某一層,并且很容易用新的層來替換原有的,從而達(dá)到良好的分工協(xié)調(diào)、各層代碼的復(fù)用以及代碼更新的功能。但是這樣分層降低了系統(tǒng)的性能以及效率。因?yàn)槿绻徊捎眠@樣的分層式結(jié)構(gòu),那么很多業(yè)務(wù)便可以直接訪問數(shù)據(jù)庫。分層結(jié)構(gòu)有時(shí)也會(huì)導(dǎo)致自上而下的級(jí)聯(lián)的修改。#p#分頁標(biāo)題#e#
3.2關(guān)鍵技術(shù)存儲(chǔ)過程分析
Sql Server中的存儲(chǔ)過程是一組被命名的存儲(chǔ)在數(shù)據(jù)庫中的為了完成特定功能的Transacation-Sql語句集。存儲(chǔ)過程是可重復(fù)利用的一種方法,支持參數(shù)變量、條件執(zhí)行以及其他的編程功能。應(yīng)用程序能夠通過存儲(chǔ)過程的名字以及參數(shù)來調(diào)用執(zhí)行存儲(chǔ)過程。存儲(chǔ)過程是數(shù)據(jù)庫的一個(gè)重要的組成部分。
存儲(chǔ)過程是使用SQL Server提供的Transact-SQL語言編寫的程序語句。Transact-SQL語言主要提供變量說明、ANSI兼容的SQL命令、一般流程控制命令、內(nèi)部函數(shù)等功能來讓用戶設(shè)計(jì)出符合引用需求的程序。存儲(chǔ)過程由應(yīng)用程序通過調(diào)用來執(zhí)行,允許用戶聲明變量,可以輸入和輸出參數(shù)、返回執(zhí)行存儲(chǔ)過程的狀態(tài)值,也可以嵌套調(diào)用。存儲(chǔ)過程相對(duì)于其他的數(shù)據(jù)庫訪問方法有以下的優(yōu)點(diǎn):
(1) 可重用性。存儲(chǔ)過程可重復(fù)調(diào)用,因此減少了數(shù)據(jù)庫開發(fā)人員的工作量。
(2) 高效性。存儲(chǔ)過程在創(chuàng)建的時(shí)候就進(jìn)行了編譯,而一般的SQL語句每執(zhí)行一次就需要編譯一次,所以存儲(chǔ)過程能快速的執(zhí)行。
(3) 節(jié)省性。存儲(chǔ)過程編譯好之后存儲(chǔ)在數(shù)據(jù)庫中,當(dāng)網(wǎng)絡(luò)程序調(diào)用存儲(chǔ)過程的時(shí)候只需傳遞存儲(chǔ)過程的名稱及參數(shù),因此降低了網(wǎng)絡(luò)通信量。
(4) 安全性。參數(shù)化的存儲(chǔ)過程可以防止SQL注入式的攻擊,而且可以使沒有權(quán)限的用戶在控制下間接地存取數(shù)據(jù),可以使相關(guān)的數(shù)據(jù)操作結(jié)合事務(wù)處理以保證數(shù)據(jù)完整性。
存儲(chǔ)過程分為了三類:系統(tǒng)存儲(chǔ)過程、擴(kuò)展存儲(chǔ)過程以及用戶定義的存儲(chǔ)過程。其中,用戶定義的存儲(chǔ)過程分為CLR和Transaction-SQL兩種類型。Transaction-SQL存儲(chǔ)過程也就是的Transaction-SQL語句集合,可以輸入和輸出應(yīng)用程序提供的參數(shù)。
4.系統(tǒng)總體設(shè)計(jì)
4.1 系統(tǒng)面向的用戶
根據(jù)試題庫系統(tǒng)的需求并結(jié)合實(shí)際考察情況,試題庫系統(tǒng)主要用戶可分為四類。包括管理員用戶、教師用戶、學(xué)生用戶以及游客用戶。
其中管理員用戶具有登錄、管理用戶的功能,教師用戶具有登錄、添加刪除修改試題、自動(dòng)出卷、手動(dòng)出卷等功能,學(xué)生用戶具有登錄、抽卷、模擬測(cè)試并總分的功能、游客具有抽卷、模擬測(cè)試并總分的功能。
試題庫系統(tǒng)最終面向?qū)W院教學(xué)、行政、學(xué)工等管理人員(而且因工作責(zé)任不同而使用不同的系統(tǒng)功能),用戶能夠使用基本的計(jì)算機(jī)辦公軟件便能很好的使用試題庫系統(tǒng)。
4.2 系統(tǒng)流程圖
密碼錯(cuò)誤
數(shù)據(jù)庫
檢查
錯(cuò)誤信息
輸入用戶名和密碼
系統(tǒng)登錄界面#p#分頁標(biāo)題#e#
運(yùn)行程序
功能處理
功能界面
密碼正確
圖1 系統(tǒng)流程圖
4.3 系統(tǒng)的主要功能
VFP試題庫系統(tǒng)是專門用于用戶注冊(cè)、登錄、試題管理、模擬測(cè)試以及管理員進(jìn)行管理用戶的C#應(yīng)用程序。試題庫系統(tǒng)具有開放性、方便性和靈活性。而后臺(tái)題庫管理主要是教師用戶的一些操作,教師用戶可以輕松地向題庫添加、修改和查詢?cè)囶}。
試題庫系統(tǒng)的主要功能特點(diǎn)有以下幾點(diǎn):
(1) 用戶管理模塊:
用戶管理模塊主要是對(duì)由管理員對(duì)新用戶進(jìn)行注冊(cè)、刪除、密碼修改等操作。
(2) 用戶合法性驗(yàn)證模塊
該模塊的功能是在系統(tǒng)被訪問之前,要對(duì)進(jìn)入系統(tǒng)的用戶進(jìn)行安全性檢查,防止非法用戶進(jìn)入系統(tǒng)破壞數(shù)據(jù)及威脅系統(tǒng)安全,避免不必要的損失。只有合法的用戶在輸入正確的密碼后方可進(jìn)入系統(tǒng)使用相應(yīng)的功能。
(3) 后臺(tái)題庫管理模塊
在該界面窗口中,主要是由教師用戶來執(zhí)行對(duì)試題庫的管理(包括試題的錄入、刪除、修改、瀏覽、統(tǒng)計(jì)等)、試卷管理(包括手工、自動(dòng)組卷、試卷瀏覽統(tǒng)計(jì)等)等功能的操作。其中試題庫管理包括的子模塊有題目所屬的部分(VF程序設(shè)計(jì)和計(jì)算機(jī)軟件基礎(chǔ))、題目類型、題目?jī)?nèi)容、題目分值、條件查詢等。試卷管理包括的子模塊有分題目類型統(tǒng)計(jì)分?jǐn)?shù)、試卷總分、錯(cuò)題統(tǒng)計(jì)、查看題庫結(jié)構(gòu)、生成Word文檔、保存試卷等。
(4) 自動(dòng)出卷模擬測(cè)試模塊
該模塊主要實(shí)現(xiàn)了系統(tǒng)自動(dòng)從試題庫中按照一定的規(guī)則來取出一組試題并將之組合成一套試卷,用戶可以選擇輸出試卷(如Word文檔)、打印試卷或者是直接在模擬測(cè)試頁面答題,答題之后系統(tǒng)將自動(dòng)評(píng)分并自動(dòng)組成錯(cuò)題集。
4.4 系統(tǒng)類圖分析
(1) 系統(tǒng)總體類庫結(jié)構(gòu)
ExaminationSystem 表現(xiàn)層
ExaminationSystemBLL 業(yè)務(wù)邏輯
ExaminationSystemDAL 數(shù)據(jù)訪問層
ExaminationSystemModels 實(shí)體層
圖2 系統(tǒng)總體類庫結(jié)構(gòu)
(2) 表現(xiàn)層類圖
圖3 表現(xiàn)層類圖
(3) 業(yè)務(wù)邏輯層類圖
QuestionManager 試題類
TestManager 試卷類
UserManager 用戶類
ExaminationSystemBLL 業(yè)務(wù)邏輯
圖4 #p#分頁標(biāo)題#e#業(yè)務(wù)邏輯層類圖
(4) 數(shù)據(jù)訪問層類圖
QuestionService 試題類
TestService 試卷類
UserService 用戶類
ExaminationSystemDAL 數(shù)據(jù)訪問層
圖5數(shù)據(jù)訪問層類圖
(5) 實(shí)體類圖
Question 試題類
Test 試卷類
User 用戶類
ExaminationSystemModels 實(shí)體層
圖6 實(shí)體層類圖
4.5數(shù)據(jù)訪問層的設(shè)計(jì)與實(shí)現(xiàn)
數(shù)據(jù)訪問層ExaminationSystemDAL中由QuestionService提供和試題相關(guān)的數(shù)據(jù)庫訪問和操作,其中包括添加試題、通過試題編號(hào)來刪除試題、查詢所有試題、通過傳入條件來查詢?cè)囶}、通過編號(hào)來查詢?cè)囶}、通過傳入條件來查詢?cè)囶}并隨機(jī)排列、查詢?cè)囶}統(tǒng)計(jì)、修改試題;UserService提供和用戶相關(guān)的數(shù)據(jù)庫訪問和操作,其中包括通過用戶編號(hào)來刪除用戶、添加用戶、通過用戶名來查詢用戶密碼、查詢所有用戶、通過用戶名來查詢用戶、修改用戶密碼;TestService提供和試卷相關(guān)的數(shù)據(jù)庫訪問和操作,其中包括通過試卷編號(hào)來刪除試卷、添加試卷、查詢所有試卷、通過編號(hào)來查詢?cè)嚲?。?shù)據(jù)訪問層被設(shè)計(jì)于三層結(jié)構(gòu)的最底層,數(shù)據(jù)訪問層將直接面向數(shù)據(jù)庫。數(shù)據(jù)訪問層依賴于實(shí)體層,被業(yè)務(wù)邏輯層依賴。
4.6 實(shí)體層的設(shè)計(jì)與實(shí)現(xiàn)
對(duì)于大量的數(shù)據(jù)來說用變量做參數(shù)顯然是不合適的,于是在系統(tǒng)設(shè)計(jì)時(shí)創(chuàng)建了實(shí)體層,實(shí)體層是面向?qū)ο笤O(shè)計(jì)思想中最基本的類,把大量的數(shù)據(jù)進(jìn)行封裝,在這里起到數(shù)據(jù)的實(shí)體化存儲(chǔ)作用。在VFP試題庫系統(tǒng)中實(shí)體層定義為ExaminationSystemModels,其中包含了Question、User、Test三個(gè)實(shí)體類,將試題、用戶、試卷分別實(shí)體化。試題的屬性包含了試題編號(hào)、試題內(nèi)容、試題的正確答案、試題的問題數(shù)目、題型、試題所屬的部分、試題錄入者編號(hào)、添加試題的時(shí)間、最后修改試題的時(shí)間。用戶的屬性包括用戶編號(hào)、用戶名、用戶密碼、用戶類型。試卷的屬性包括試卷編號(hào)、判斷題集合、選擇題集合、程序閱讀題集合、填空題集合、創(chuàng)建試卷時(shí)間。實(shí)體層同時(shí)被表現(xiàn)層、業(yè)務(wù)邏輯層、數(shù)據(jù)訪問層引用。
4.7 業(yè)務(wù)邏輯層的設(shè)計(jì)與實(shí)現(xiàn)
業(yè)務(wù)邏輯層ExaminationSystemBLL中包含了QuestionManager、UserManager、TestManager三個(gè)類文件。在其中實(shí)現(xiàn)用戶合法性的驗(yàn)證、對(duì)數(shù)據(jù)的優(yōu)化、處理。VFP試題庫系統(tǒng)的數(shù)據(jù)結(jié)構(gòu)較為簡(jiǎn)單,不需要大量的數(shù)據(jù)處理就能直接存入數(shù)據(jù)庫。只有部分?jǐn)?shù)據(jù)訪問層傳入的數(shù)據(jù)需要經(jīng)過數(shù)據(jù)字典翻譯之后再呈現(xiàn)表現(xiàn)層。在VFP試題庫系統(tǒng)的數(shù)據(jù)字典中的定義了試題所屬部分、試題類型、用戶類型為INT類型的數(shù)字來表示。因此在業(yè)務(wù)邏輯層中將針對(duì)這些字段進(jìn)行翻譯為用戶能夠理解的表達(dá)方式。#p#分頁標(biāo)題#e#
5.數(shù)據(jù)庫分析
5.1 數(shù)據(jù)庫設(shè)計(jì)
VFP試題庫系統(tǒng)的數(shù)據(jù)庫在設(shè)計(jì)師應(yīng)該滿足用戶的各種應(yīng)用需求,并且能夠高效、安全的存儲(chǔ)數(shù)據(jù)。在概念設(shè)計(jì)階段針對(duì)試題、試卷、用戶等信息建立抽象的概念數(shù)據(jù)模型,使之能夠真實(shí)的反映試題、試卷等的屬性、聯(lián)系以及相互的制約情況。接下來在邏輯設(shè)計(jì)中將數(shù)據(jù)模型設(shè)計(jì)成數(shù)據(jù)庫的一種邏輯模式。最后根據(jù)SQL server提供的存儲(chǔ)結(jié)構(gòu)和存取方法選定具體的物理存儲(chǔ)結(jié)構(gòu)如下所示:
(1) 試題表(TblQuestion)
包括試題編號(hào)、試題進(jìn)制數(shù)、試題正確答案、試題答案數(shù)、題型、試題部分、錄入編號(hào)、添加試題時(shí)間、修改試題時(shí)間。
(2) 試卷結(jié)構(gòu)表(TblTest)
包括試卷編號(hào)、軟件基礎(chǔ)部分判斷題個(gè)數(shù)、軟件基礎(chǔ)部分選擇題個(gè)數(shù)、程序設(shè)計(jì)部分選擇題個(gè)數(shù)、程序設(shè)計(jì)部分讀程序題個(gè)數(shù)、程序設(shè)計(jì)部分填空題個(gè)數(shù)、添加試卷時(shí)間、最后修改時(shí)間。
(3) 試卷關(guān)系表(TblTestQuestion)
包括試卷編號(hào)、試題編號(hào)、試題分?jǐn)?shù)。
(4) 用戶表(TblUser)
包括用戶編號(hào)、用戶名、密碼、用戶類型。
5.2 數(shù)據(jù)庫的連接
在VFP試題庫系統(tǒng)中是通過配置app.config來實(shí)現(xiàn)連接數(shù)據(jù)庫的。當(dāng)數(shù)據(jù)庫的連接修改的時(shí)候,通過配置文件使得對(duì)數(shù)據(jù)庫連接字符串的修改更加容易與方便,而不用去修改應(yīng)用程序的代碼。首先,要導(dǎo)入configuration包,然后通過ConfigurationManager來獲取連接字符串并在數(shù)據(jù)訪問層中實(shí)現(xiàn)連接在SQL Server中創(chuàng)建的數(shù)據(jù)庫,并對(duì)數(shù)據(jù)庫中的數(shù)據(jù)進(jìn)行添加、刪除、修改、查詢等操作。具體實(shí)現(xiàn)的代碼在這里就不多做描述了。
5.3 存儲(chǔ)過程的設(shè)計(jì)與編寫
在VFP試題庫系統(tǒng)中一共設(shè)計(jì)了18組用戶自定義存儲(chǔ)過程,如下所示:
usp_DeleteQuestionById 通過試題編號(hào)來刪除試題
usp_DeleteTestById 通過試卷編號(hào)來刪除試卷
usp_DeleteUserById 通過用戶編號(hào)來刪除用戶
usp_InsertQuestion 添加試題
usp_InsertUser 添加用戶
usp_InsertTest 添加試卷
usp_SelectAllQuestion 查詢所有試題
usp_SelectPwdByName 通過用戶名來查詢用戶密碼
usp_SelectQuestionByCondition 通過傳入條件來查詢?cè)囶}
usp_SelectQuestionByQuestionID 通過編號(hào)來查詢?cè)囶}
usp_SelectQuestionRandomByCondition 通過傳入條件來查詢?cè)囶}并隨機(jī)排列
usp_SelectQuestionStatistics 查詢?cè)囶}統(tǒng)計(jì)
usp_SelectUserAll 查詢所有用戶
usp_SelectUserByName 通過用戶名來查詢用戶
usp_SelectTestAll 查詢所有試卷#p#分頁標(biāo)題#e#
usp_SelectTestByID 通過編號(hào)來查詢?cè)嚲?/div>
usp_UpdateQuestion 修改試題
usp_UpdateUserPassword 修改用戶密碼
具體的存儲(chǔ)過程代碼在這里就不多做描述了。
5.4 實(shí)現(xiàn)存儲(chǔ)過程的的調(diào)用
在應(yīng)用程序中調(diào)用存儲(chǔ)過程,首先應(yīng)該在程序中添加引用System.Data.SqlClient,然后聲明數(shù)據(jù)庫連接對(duì)象SqlConnection,并且聲明數(shù)據(jù)庫命令SqlCommand來執(zhí)行存儲(chǔ)過程。若調(diào)用的是第一類存儲(chǔ)過程就使用DataAdapter將結(jié)果填充到DataSet中,然后傳遞給業(yè)務(wù)邏輯層進(jìn)行處理之后再傳遞給表現(xiàn)層使用DataGridView之類的將結(jié)果呈現(xiàn)界面之上。若調(diào)用的是第二和第三種存儲(chǔ)過程則不需要此過程,只需根據(jù)特定的返回值傳遞給業(yè)務(wù)邏輯層進(jìn)行邏輯判定等操作。
(1)調(diào)用一個(gè)沒有參數(shù)的存儲(chǔ)過程的代碼如下:
SqlCommand objCommand = new SqlCommand("存儲(chǔ)過程的名字", 數(shù)據(jù)庫連接對(duì)象);
objCommand.CommandType = CommandType.StoredProcedure;
然后根據(jù)不同的需求來選擇適當(dāng)?shù)姆绞綀?zhí)行此處過程,如objCommand.ExecuteScalar()、objCommand.ExecuteNonQuery()。
(2)調(diào)用一個(gè)有參數(shù)的存儲(chǔ)過程的代碼如下:
SqlCommand objCommand = new SqlCommand("存儲(chǔ)過程的名字", 數(shù)據(jù)庫連接對(duì)象);
objCommand.CommandType = CommandType.StoredProcedure;
objCommand.Parameters.Add("@參數(shù)名", 參數(shù)類型).Value = 參數(shù)值;
這樣就添加了一個(gè)輸入?yún)?shù)。若需要添加輸出參數(shù):
SqlCommand objCommand = new SqlCommand("存儲(chǔ)過程的名字", 數(shù)據(jù)庫連接對(duì)象);
objCommand.CommandType = CommandType.StoredProcedure;
objCommand.Parameters.Add("@參數(shù)名", 參數(shù)類型);
objCommand.Parameters["@參數(shù)名"].Direction= ParameterDirection.Output;
6.展望及結(jié)束語
本文利用三層架構(gòu)在實(shí)際應(yīng)用程序開發(fā)中的實(shí)現(xiàn)以及存儲(chǔ)過程的實(shí)際運(yùn)用,開發(fā)出基于vs2005平臺(tái)的VFP試題庫系統(tǒng)。該系統(tǒng)功能基本符合需求,能夠完成題目的管理(選擇題、判斷題、填空題)、學(xué)生的管理、教師的管理、成績(jī)的管理、系統(tǒng)的管理和試卷的管理。但是由于系統(tǒng)是初步完成所以會(huì)存在許多的BUG,系統(tǒng)存在許多的不足之處,同時(shí)系統(tǒng)的功能僅僅通過代碼測(cè)試但尚未經(jīng)過實(shí)際運(yùn)行的測(cè)試,因此功能上會(huì)存在一些不完善之處。本系統(tǒng)目前僅作為單機(jī)的VFP試題管理,因此系統(tǒng)的應(yīng)用面還能有進(jìn)一步的擴(kuò)展,如試題科目上的擴(kuò)展與作為網(wǎng)絡(luò)應(yīng)用程序方面的擴(kuò)展等。
[參考文獻(xiàn)]
[1] 薩師煊,王珊著,《數(shù)據(jù)庫系統(tǒng)概論》,高等教育出版社,2006年5月#p#分頁標(biāo)題#e#
[2] 應(yīng)新洋,《基于SQL SERVER的數(shù)據(jù)庫安全性研究,數(shù)據(jù)庫及信息管理》
[3] 黃梯云,《管理信息系統(tǒng)導(dǎo)論》,機(jī)械工業(yè)出版社
[4] 張海藩,《軟件工程導(dǎo)論》,清華大學(xué)出版社,2003年12月
[5] 《使用C#開發(fā)數(shù)據(jù)庫應(yīng)用程序》,科學(xué)技術(shù)文獻(xiàn)出版社,2008年1月
[6] 《深入.NET平臺(tái)和C#編程》,科學(xué)技術(shù)文獻(xiàn)出版社,2008年1月
[7] 《SQL Server數(shù)據(jù)庫設(shè)計(jì)和高級(jí)查詢》,科學(xué)技術(shù)文獻(xiàn)出版社,2008年1月
[8] 《使用C#開發(fā)數(shù)據(jù)庫應(yīng)用程序》,科學(xué)技術(shù)文獻(xiàn)出版社,2008年1月
[9] Andrew Troelsen《Pro C#with .NET 3.0 Special Edition》,Apress,2007年1月
[10] Andrew Troelsen《C#與.NET高級(jí)程序設(shè)計(jì)》,Apress,2008年1月
VFP Test Database System Admin
Dong Yixiong
Department Of Computer Science Computer Science and Technology 07555012
[Abstract] VFP test database management system, which is developed under the platform of Microsoft Visual Studio 2005 and based on C #, mainly functions as the test item management and giving exams. In regard to database design, it strictly complies with the standardization of database design paradigm. Under the concept of the 3-tier application of MVC, the data access layer adopts Stored Procedures to achieve database management in a wide range. The business logic layer processes the data exchange procedure, which plays a role of a connecter.
[Key words] C# Programming Test Database System SQLServer 3-tier Application
如果您有論文代寫需求,可以通過下面的方式聯(lián)系我們
點(diǎn)擊聯(lián)系客服