數(shù)據(jù)庫課程設(shè)計概要_第1頁
數(shù)據(jù)庫課程設(shè)計概要_第2頁
數(shù)據(jù)庫課程設(shè)計概要_第3頁
數(shù)據(jù)庫課程設(shè)計概要_第4頁
數(shù)據(jù)庫課程設(shè)計概要_第5頁
已閱讀5頁,還剩32頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、信息工程學(xué)院課程設(shè)計報告設(shè)計名稱:數(shù)據(jù)庫課程設(shè)計姓 名:學(xué) 號:專業(yè)班級:系 (院):設(shè)計時間:設(shè)計地點:指導(dǎo)老師:一.課程設(shè)計目的 一 h* hB! m - hl! m n 一 hl! hK H h* :一!: nF m 一 H ! bl: -"七- FF ,!: n 0F 0-B"加, 0F hbBII數(shù)據(jù)庫課程設(shè)計是為數(shù)據(jù)庫原理及應(yīng)用課程而獨立開設(shè)的實踐性課程,對于鞏固數(shù)據(jù)庫知識,加強(qiáng)學(xué)生的實際動手能力和提高學(xué)生綜合素質(zhì)十分必要。通過本實驗達(dá)到以下目的:(1)培養(yǎng)學(xué)生具有C/S和B/S/S模式的數(shù)據(jù)庫應(yīng)用軟件系統(tǒng)的設(shè)計和開發(fā)能力。(2)熟練掌握一種數(shù)據(jù)庫系統(tǒng)(如SQL

2、 SERVER)的使用。(3)熟練掌握一種數(shù)據(jù)庫應(yīng)用軟件開發(fā)工具(如 POWERBUILDER 、ASP、VB.NET)的使用。(4)通過設(shè)計實際的數(shù)據(jù)庫系統(tǒng)應(yīng)用課題,進(jìn)一步熟悉數(shù)據(jù)庫管理系統(tǒng)的操作技術(shù),提高動手能力,提 高分析問題和解決問題的能力。二.課程設(shè)計任務(wù)與要求:1、任務(wù):學(xué)生選課系統(tǒng)問題描述:1)學(xué)?,F(xiàn)有課程若干門。2)課程表的信息有課程號、名字、學(xué)分、 、學(xué)期、課時等。3)學(xué)生表的信息有學(xué)生號、名字、性別、年齡、 。4)選課表的信息有選修課程號、學(xué)生的學(xué)號、課程學(xué)分。5)用戶表信息有用戶名、用戶密碼、用戶權(quán)限。2、設(shè)計要求:1)實現(xiàn)學(xué)生表中學(xué)生信息的插入、修改、刪除。2)實現(xiàn)課程

3、表中課程信息的插入、修改、刪除。3)實現(xiàn)選課表中得選修課程的選課信息查詢、進(jìn)行課程選擇。4)管理員進(jìn)行登陸后才能訪問此數(shù)據(jù)庫。5)設(shè)計一完整的數(shù)據(jù)庫。要求掌握數(shù)據(jù)庫的設(shè)計的每個步驟;掌握數(shù)據(jù)設(shè)計各階段的輸入、輸出、設(shè) 計環(huán)境、目標(biāo)和方法;熟練的使用SQL語言實現(xiàn)數(shù)據(jù)庫以及數(shù)據(jù)庫重要對象的建立、應(yīng)用和維護(hù)。三.課程設(shè)計說明書1需求分析(1)數(shù)據(jù)需求學(xué)生選修信息系統(tǒng)需要完成功能主要有:1、課程基本信息的輸入查詢、修改、刪除,包括課程號、課程名字、學(xué)期、課程學(xué)分等。2、學(xué)生基本信息的的輸入查詢、修改、刪除,包括學(xué)號、學(xué)生姓名、學(xué)生性別、學(xué)生年齡、系別等。3、學(xué)生選課的基本信息的選課信息查詢、學(xué)生進(jìn)行

4、課程選擇。4、管理員的基本信息的輸入、查詢、修改、包括用戶名、密碼。(2)事務(wù)需求在課程信息部分,要求:a.可以查詢課程信息。b.亙以對遽程信息進(jìn)行插修改及刪除的掾隹? 在學(xué)生信息部分,要求:a.可以查詢學(xué)生信息:b.可以對學(xué)生信息進(jìn)行維護(hù),包括插入、修改及刪除的操作。在學(xué)生選課信息管理部分,要求:。a.可以學(xué)生選課信息。b.可以對學(xué)生選課信息進(jìn)行查詢及學(xué)生選課操作。在用戶登錄信息管理部分,要求:a.能夠使用用戶信息進(jìn)行登錄訪問b.可以對用戶個人信息進(jìn)行修改、刪除維護(hù)操作(3)關(guān)系模式(1)課程類別(課程編號,課程名、課程學(xué)分、學(xué)期、課程學(xué)時)(2)學(xué)生類別(學(xué)生號,學(xué)生姓名,學(xué)生性別,學(xué)生年

5、齡,學(xué)生系別(3)學(xué)生選課類別(課程號,學(xué)生號,學(xué)生成績)(4)用戶類別(用戶名,用戶密碼,用戶權(quán)限 )(4)數(shù)據(jù)流程圖(DFD)用戶用戶用戶課程信息用戶查詢課程學(xué)生信息管理 系統(tǒng)分?jǐn)?shù)信息分?jǐn)?shù)查詢課程信息學(xué)生信息分?jǐn)?shù)信息用戶用戶圖1-1頂層數(shù)據(jù)流圖數(shù)據(jù)流數(shù)據(jù)處理數(shù)據(jù)存儲圖1-2 一層數(shù)據(jù)流圖F1注:DD1用戶表D2課程表D3成績表D4學(xué)生表F1登錄信息F3,F4, F5各種選課、學(xué)生信息F2理片值皂F6各種信息圖1-3二層數(shù)據(jù)流圖.一胤上匕三屋鰲型通!L(5為了使各數(shù)據(jù)流,數(shù)據(jù)處理過程,存儲過程不能反映其中的數(shù)據(jù)成,數(shù)據(jù)項目,數(shù)據(jù)特性,所以用數(shù)據(jù)字典來對數(shù)據(jù)流圖中的各成份進(jìn)行具體的定義,為系統(tǒng)

6、的分析,設(shè)計及以后的實現(xiàn)提供供有關(guān)元素一致性定義和詳細(xì)的描述數(shù)據(jù)流字典數(shù)據(jù)流名稱:讀者登錄標(biāo)志符:F1別名:無來源:用戶去向:查詢處理過程(P)數(shù)據(jù)組成:用戶名+密碼+用戶權(quán)限數(shù)據(jù)流名稱:學(xué)生信息查詢標(biāo)志符:F5.3別名:無來源:用戶去向:查詢處理過程(P2.3)數(shù)據(jù)組成:學(xué)號+姓名+性別+年齡+系別數(shù)據(jù)流名稱:課程信息查詢標(biāo)志符:F5.1別名:無來源:用戶去向:查詢處理過程(P2.1)數(shù)據(jù)組成:課程號+課程名+學(xué)分+學(xué)時+課時數(shù)據(jù)流名稱:成績信息查詢標(biāo)志符:F5.2別名:無來源:用戶去向:查詢處理過程(P2.2)數(shù)據(jù)組成:學(xué)號+課程號+分?jǐn)?shù)數(shù)據(jù)流名稱:學(xué)生信息管理標(biāo)志符:F4.2別名:無來源

7、:用戶去向:查詢處理過程(P4.2)數(shù)據(jù)組成:學(xué)號+姓名+性別+年齡+系別數(shù)據(jù)流名稱:課程信息管理標(biāo)志符:F4.3別名:無來源:用戶去向:查詢處理過程(P4.3)數(shù)據(jù)組成:課程號+課程名+學(xué)分+學(xué)時+課時數(shù)據(jù)流名稱:成績信息管理標(biāo)志符:F4.1別名:無.斐邂二一鬼0去向:查詢處理過程(P4.4)數(shù)據(jù)組成:學(xué)號+課程號+分?jǐn)?shù)數(shù)據(jù)存儲字典:數(shù)據(jù)存儲名稱:用戶數(shù)據(jù)庫標(biāo)志符:D1描述:所有用戶的信息流入數(shù)據(jù)流:F1涉及處理:P4 P5數(shù)據(jù)組成:用戶名+密碼+用戶權(quán)限數(shù)據(jù)存儲名稱:課程數(shù)據(jù)庫標(biāo)志符:D2描述:所有課程信息的詳細(xì)資料流入數(shù)據(jù)流:F3涉及處理:P4 P5數(shù)據(jù)組成:課程號+課程名+學(xué)分+學(xué)時+

8、課時數(shù)據(jù)存儲名稱:成績數(shù)據(jù)庫標(biāo)志符:D3描述:所有用戶的成績數(shù)據(jù)詳細(xì)資料流入數(shù)據(jù)流:F3涉及處理:P4 P5數(shù)據(jù)組成:學(xué)號+課程號+分?jǐn)?shù)數(shù)據(jù)存儲名稱:學(xué)生數(shù)據(jù)庫標(biāo)志符:D4描述:所有學(xué)生信息的詳細(xì)資料流入數(shù)據(jù)流:F3涉及處理:P4 P5數(shù)據(jù)組成:學(xué)號+姓名+性別+年齡+系別數(shù)據(jù)處理字典:數(shù)據(jù)處理名稱:用戶登錄標(biāo)志符:P1處理定義:登錄系統(tǒng)激發(fā)條件:所輸入用戶民和密碼正確輸入:F1輸出:F4,F5,F6數(shù)據(jù)處理名稱:查詢選擇標(biāo)志符:P2.1處理定義:選擇查詢方式激發(fā)條件:已選擇查詢方式輸入:F5輸出:F7數(shù)據(jù)處理名稱:學(xué)生查詢選擇標(biāo)志符:P2.2處理定義:選擇查詢方式激發(fā)條件:已選擇查詢方式輸入

9、:F4輸出:F7數(shù)據(jù)處理名稱:成績查詢選擇標(biāo)志符:P2.3處理定義:選擇查詢方式激發(fā)條件:已選擇查詢方式輸入:F4輸出:F7婺好您理芻登一:一迷隹直迎選建/走電-一吆土一處理定義:選擇查詢方式激發(fā)條件:已選擇查詢方式輸入:F4輸出:F7數(shù)據(jù)處理名稱:管理選擇標(biāo)志符:P4.1處理定義:選擇管理功能激發(fā)條件:選擇輸入:F4輸出:F8數(shù)據(jù)處理名稱:成績管理選擇標(biāo)志符:P4.2處理定義:選擇管理功能激發(fā)條件:選擇輸入:F4輸出:F8數(shù)據(jù)處理名稱:學(xué)生管理選擇標(biāo)志符:P4.3處理定義:選擇管理功能激發(fā)條件:選擇輸入:F4輸出:F8數(shù)據(jù)處理名稱:課程管理選擇標(biāo)志符:P4.4處理定義:選擇管理功能激發(fā)條件:

10、選擇輸入:F4輸出:F82概要設(shè)計(1)實體圖及E-R圖所要實現(xiàn)的功能設(shè)計,可能建立它們之間的關(guān)系,進(jìn)而實現(xiàn)邏輯結(jié)構(gòu)功能。該選課系統(tǒng)可以劃分的實體有:用戶實體,學(xué)生實體,課程實體,選課記錄實體。 用戶信息實體圖:所在系學(xué)生姓名學(xué)生性別課程編課時課程名成績課程編學(xué)生信息實體圖:學(xué)生信息圖2-2學(xué)生實體及其屬性圖課程信息實體圖課程信息學(xué)期圖2-3課程實體及其屬性圖選課記錄信息實體圖選課信息圖2-4選課記錄實體及其屬性圖圖2-5 總的E-R圖3邏輯設(shè)計表3-1課程表表中列名數(shù)據(jù)類型可否為空說明CnoVarchar(10)not null(主鍵)課程號 nCnameVarchar(20)not nul

11、l課程名Ccredtintnull學(xué)分Csemesterintnull學(xué)期Cperiodintnull課時表3-2學(xué)生表表中列名數(shù)據(jù)類型可否為空說明SnoVarchar(10)not null(主鍵)學(xué)生號Snamevarchar(8)not null姓名Ssexvarchar(2)not null性別Sageintnot null年齡SdeptVarchar(20)null院系表3-3 成績表表中列名數(shù)據(jù)類型可否為空說明CnoVarchar(10)Not null(主鍵)課程號SnoVarchar(10)Not null(主鍵)學(xué)”Igradeintnull成績表3-4用戶表表中列名數(shù)據(jù)類型

12、可否為空說明userNameVarchar(16)Not null(主鍵)用戶名userPasswordVarchar(16)Not null密碼userPurviewVarchar(8)null用戶權(quán)限4關(guān)系圖4-15物理設(shè)計數(shù)據(jù)庫物理設(shè)計階段的任務(wù)是根據(jù)具體計算機(jī)系統(tǒng)(DBMS和硬件等)的特點,為給定的數(shù)據(jù)庫模型確定合理的存儲結(jié)構(gòu)和存取方法。所謂的“合理”主要有兩個含義:一個是要使設(shè)計出的物理數(shù)據(jù)庫占用較 少的存儲空間,另一個對數(shù)據(jù)庫的操作具有盡可能高的速度。主要體現(xiàn)在后者。(1) 建立索引:對課程表在 Cno屬性列上建立聚集索引,在Cname, Ccredt, Csemester, Cp

13、eriod屬性列上建立非聚集索引。對學(xué)生表在 Sno屬性列上建立聚集索引,在Sname, Ssex, Sage, Sdept屬性列上建立非聚集索引 對成績表在Cno, Sno屬性列上建立聚集索引,在grade屬性列上建立非聚集索引對用戶表在 userName屬性列上建立聚集索引,在userPassword, userPurview屬性列上建立非聚集索引(2) 存儲結(jié)構(gòu)確定數(shù)據(jù)庫的存儲結(jié)構(gòu)主要指確定數(shù)據(jù)的存放位置和存儲結(jié)構(gòu),包括確定關(guān)系、索引、日志、備份 等的存儲安排及存儲結(jié)構(gòu),以及確定系統(tǒng)存儲參數(shù)的配置。將日志文件和數(shù)據(jù)庫對象(表、索引等)分別放在不同的磁盤可以改進(jìn)系統(tǒng)的性能。所以系統(tǒng)將日志文

14、件和數(shù)據(jù)文件存放在不同磁盤上。6 .數(shù)據(jù)庫建立(1)創(chuàng)建數(shù)據(jù)庫create database lllon(name=lll_data,filename='E:sqllll_data.mdf, size=5MB, maxsize=20MB, filegrowth=2MB) log on(name=lll_log,filename='E:sqllll_log.ldf, size=1MB, maxsize=20MB, filegrowth=20%)(2)創(chuàng)建學(xué)生信息表 create table 學(xué)生表(Sno char(10) primary key,Sname char(10) u

15、nique,Ssex char(5),Sage int,Sdept char(8);(3)創(chuàng)建課程信息表 create table 課程表(Cno char(10),Primary key (cno),Cname char(10),Ccredt char(10)Csemester char(10)Cperiod char(10);(4)創(chuàng)建成績表create table 成績表(Sno char(10),Cno char(10), grade smallint, Primary key(sno,cno), foreign key(sno) references student(sno), fo

16、reign key(cno) references course(cno) );(5)創(chuàng)建用戶表 create table 用戶表(userName char(10) userPassword char(20) userPurview char(10) )7 .數(shù)據(jù)初始化(1)往學(xué)生信息表插入數(shù)據(jù)insert into 學(xué)生表(Sno,Sname,Ssex,Sage,Sdept)values('11341',李晨','男',20,'cs');insert into 學(xué)生表 values('11342','劉晨

17、9;,'女',19,'cs');insert into 學(xué)生表 values('11343','王敏','女',18,'ma');insert into 學(xué)生表 values('11344','張立','男',20,'is');(2)往課程信息表插入數(shù)據(jù)insert into 課程表(Cno Cname Ccredt Csemeste Cperiod)values('1001','數(shù)據(jù)庫','4&

18、#39;,'3','80');insert into 課程表 values('1002','數(shù)學(xué)',5,'2','75');insert into 課程表 values('1003','信息系統(tǒng)','4','2','65');insert into 課程表 values('1004','操作系統(tǒng)','3','3','90');(3)往成績表插

19、入數(shù)據(jù)insert into 成績表(sno,cno,grade)values('11341','1001',92);insert into 成績表 values('11342','1002',85);insert into 成績表 values('11343','1003',88);insert into 成績表 values('11344','1004',90);(4)往用戶表插入數(shù)據(jù)insert into 用戶表(username userPassword us

20、erPurview)values(姚春振','123','超級用戶)insert into 用戶表 values(李龍龍','123','管理員')insert into 用戶表 values(毋康康','123','一般用戶')insert into 用戶表 values(呂斌','123','管理員')8.數(shù)據(jù)庫權(quán)限管理該系統(tǒng)設(shè)置三種類型的用戶(1) 管理員:李龍龍,呂斌(2) 超級用戶:姚春振(3) 一般用戶:毋康康9、建立觸發(fā)器,存儲過

21、程 -建立學(xué)生信息管理的存貯過程create procedure studentmessageasbeginselect sno,sname from tbl_ 學(xué)生表 endgoexec studentmessagego建立課程信息的存貯過程create procedure coursemessageasbeginselect sno,sname from tbl_ 課程表 endgoexec coursemessagego創(chuàng)建觸發(fā)器 score_grade_tricreate trigger score_grade_trion sc for insert,update asdeclare

22、score_read intselect score_read=grade from insertedif score_read>=0 and score_read<=100beginprint '操作完成returnendelsebeginprint '成績輸入不合法,請重新輸入!rollback transactionend創(chuàng)建觸發(fā)器triscsnocreate trigger triscsnoon sc for updateasif update(sno)begindeclare sno_old char(10),count intselect sno_old

23、=sno from deletedselect count=count(*) from student where sno=sno_old if count>0rollback transactionEnd10系統(tǒng)實現(xiàn)(1)系統(tǒng)功能模塊圖:系統(tǒng)功能模塊圖如圖 10-1學(xué)生選課管理系統(tǒng)圖10-1系統(tǒng)功能模塊圖 四個子系統(tǒng)的功能如下:登錄子系統(tǒng):可以實現(xiàn)學(xué)生選課系統(tǒng)管理員。學(xué)生信息管理子系統(tǒng):主要用于管理員對學(xué)生信息添加、修改、刪除操作,實現(xiàn)學(xué)生信息數(shù)據(jù)的更新。課程信息管理子系統(tǒng):主要用于管理員對選修課程信息的添加、修改、刪除管理,實現(xiàn)課程信息數(shù)據(jù)的更新。 成績表管理子系統(tǒng):主要用于管理員對

24、選課信息的查詢和學(xué)生進(jìn)行選課操作。(2) 前臺開發(fā)平臺的選擇:VB.NET(3) VB.NET與數(shù)據(jù)庫的連接ADO.NET VB.NET訪問數(shù)據(jù)庫的主要方式。ADO.NET勺數(shù)據(jù)訪問方式ADO.NET的數(shù)據(jù)存取API提供3種數(shù)據(jù)訪問方式:a)通過ODBC相連,訪問支持早期 ODBCS議的數(shù)據(jù)庫。b) 通過 OLEDB相連,訪問 SQLServer2005 , MicrosoftAccess , Oracle 或者其他有提供 OLEDB 連 接能力的數(shù)據(jù)庫c) 使用 SqlConnection 直接 SQL Server2005 相連VB.NE昉問數(shù)據(jù)庫的具體過程a)創(chuàng)建數(shù)據(jù)庫連接ADO.NET

25、中使用sqlConnection 類對SQLServer2005以及更高版本進(jìn)行連接,這個類的構(gòu)造函數(shù)接受一個可選參數(shù),稱為連接字符串,該字符串用于定義正在連接的數(shù)據(jù)庫的類型、位置以及其他信息,這些屬 性用分號分隔,通常該字符串包含如下信息: Data Source 特性:指定SQL Server數(shù)據(jù)庫所在計算機(jī)名 稱;Initial Catalog 特性: 指定連接的SQL Server數(shù)據(jù)庫的名稱; userName和userPassword 特性:指定用SQL SERVER錄方式的有效帳戶名和密碼或設(shè)置為:integrated security=SSPI 設(shè)置為Windows登錄方式。b

26、 )填充數(shù)據(jù)創(chuàng)建數(shù)據(jù)源連接以后,接下來創(chuàng)建數(shù)據(jù)適配器,適配器在創(chuàng)建過程中需要向其傳遞兩個要素:用于包含結(jié)構(gòu)化查詢語句的數(shù)據(jù)描述和用于指明數(shù)據(jù)庫連接信息的連接描述,創(chuàng)建后可利用Fill方法,將所需的數(shù)據(jù)填充在一個數(shù)據(jù)集(DataSet)中。 c )關(guān)閉數(shù)據(jù)庫的連接由于DataSet采用是斷開連接的方式,所以當(dāng)把數(shù)據(jù)填充到數(shù)據(jù)集后即可斷開與數(shù)據(jù)庫的連接。 d)為控件指定數(shù)據(jù)源數(shù)據(jù)填充到數(shù)據(jù)集后,要在窗體上顯示出來,則必須把相應(yīng)的數(shù)據(jù)表綁定到數(shù)據(jù)控件上。 具體實現(xiàn)代碼如下:using System;using System.Collections.Generic;using System.Linq;

27、using System.Text;using System.Data;using System.Data.SqlClient;using System.Windows.Forms;namespace hcy public class DataBase public SqlConnection dataConnection = new SqlConnection ();public SqlDataAdapter dataAdapter;public DataSet dataSet = new DataSet ();string connstr = "server=PC-2010090

28、8TULP;database=mysql;integrated security=SSPI" ;public DataSet GetDataFormDB( string sqlStr) try dataConnection.ConnectionString = connstr;dataAdapter =new SqlDataAdapter (sqlStr, dataConnection);dataSet.Clear();dataAdapter.Fill(dataSet);dataConnection.Close(); catch ( Exception ex) MessageBoxS

29、how(ex.Message);dataConnection.Close(); if (dataSet.Tables0.Rows.Count != 0) return dataSet;) else ( return null ;) )public bool UpdateDB( string sqlStr) (SqlConnection sqlConn = new SqlConnection (connstr); try (SqlCommandcmdTable = new SqlCommandsqlStr,sqlConn); cmdTable.CommandType =CommandTypTex

30、t;sqlConn.Open();cmdTable.ExecuteNonQuery(); sqlConn.Close();return true ; )catch ( Exception ex) (MessageBoxShow(ex.Message); return false ; ) ) )(4) 登錄系統(tǒng)模塊及代碼a)學(xué)生成績管理系統(tǒng)登錄界面如圖10-2圖10-2學(xué)生選課系統(tǒng)登錄界面圖 登陸代碼為:try(DataBase db = new DataBase();DataSet ds = new DataSet ();string sqlStr = "select userPas

31、sword,userPurview from 用戶表 where userName='" + txtuserName.Text.Trim() +""'ds = db.GetDataFormDB(sqlStr);string str1, str2,str3;str1 = ds.Tables0.Rows0.ItemArray0.ToString().Trim();str3 = ds.Tables0.Rows0.ItemArray1.ToString().Trim();str2 = txtPassWord.Text.Trim();if (str1 = s

32、t if (str3 = comboBox1.Text.ToString().Trim() Form2 ob_Form2 = new Form2();shuzu .userInfo0 = txtuserName.Text.Trim();shuzu .userInfo1 = ds.Tables0.Rows0.ItemArray1.ToString();ob_Form2.Show(); this .Hide(); else MessageBoxShow("用戶權(quán)限錯誤,請重新輸入 ");comboBox1.Text =""comboBox1.Focus();

33、 else MessageBoxShow("用戶名或密碼錯誤,請重新輸入");txtuserName.Text =""txtPassWord.Text =""txtuserName.Focus(); catch MessageBoxShow("用戶名或密碼錯誤","錯誤");學(xué)生選課系統(tǒng)主界面如圖10-3略圖10-3學(xué)生選課系統(tǒng)主界面學(xué)生信息管理界面如圖10-4JTWf 1 T, 融 叫電箭1赤嶼端|Sju£JjiWi4Seu£皿=在小布二J款三叫a網(wǎng)哂鉆.laaMCTK芋莊

34、烹LJ廣算與息.f±fl:Faarnaas包京a唱西zncroaiJi肘%ts(X 息系;1哥01切平岫=2倩且T伸薩4 出;-u*圖10-4學(xué)生信息管理界面 可以進(jìn)行學(xué)生信息的添加、修改、刪除操作。代碼如下:try(if (button1.Text.Trim()="添加")( buttonl.Text ="確定";ObjOpen(); Clear(); button2.Enabled =false;button3.Enabled =false;button4.Enabled =false; else ( button1.Text ="

35、;添加";if (txtID.Text.Trim() !=""&& txtName.Text.Trim() !="")( string sqlStr;sqlStr= "insert into 學(xué)生表 values。"+ txtID.Text.Trim() + "','"+ txtName.Text.Trim()+ "','"+ comSex.Text.Trim() +"','"+ txtAge.Text

36、.Trim() +"','"+ txtSdept.Text.Trim() +"')"DataBase db = new DataBase。; bool b;b = db.UpdataDB(sqlStr);if (b = true )if ( MessageBoxShow("添力口成功!繼續(xù)添加嗎?","添加學(xué)生",MessageBoxButtons .YesNo,MessageBoxIcon .Question, MessageBoxDefaultButton .Button1) = Dia

37、logResult .Yes)(/Clear();ObjClose();RefresData();/button1.Text =""Form3_Load(null ,null );button2.Enabled =true ;button3.Enabled =true ;button4.Enabled =true ;else(ObjClose();button2.Enabled =true ;button3.Enabled =true ;button4.Enabled =true ;dgrdvStudent.Enabled =true ;else(goto exit;els

38、e(MessageBoxShow("學(xué)號和姓名不能為空"txtID.Focus();button1.Text ="確定"RefresData();txtID.SelectAll();修改:try(if (button2.Text.Trim()="修改")(button2.Text ="確定";button3.Enabled =button1.Enabled =false ;false ;button4.Enabled =false ;txtName.Enabled =true ;txtAge.Enabled =tr

39、ue ;txtSdept.Enabled =true ;comSex.Enabled =true ;txtName.Focus(); elsebutton2.Text ="修改";button1.Enabled =true;button3.Enabled =true;button4.Enabled =true;ObjClose();string sqlStr;+ comSex.Text.Trim()+ txtID.Text.Trim() +sqlStr= "update 學(xué)生表 set Sname='" + txtName.Text.Trim()

40、 + "',Ssex='"+ "',Sage='"+ txtAge.Text.Trim() +"',Sdept='"+ txtSdept.Text.Trim() +"' where Sno='" ;DataBase db = new DataBase();db.UpdataDB(sqlStr); RefresData(); catch ( Exception ex)MessageBoxShow(ex.Message);刪除tryif (button3.

41、Text.Trim()="刪除")button3.Text ="確定"button1.Enabled =false ;button2.Enabled =false ;button4.Enabled =false ;elsebutton3.Text ="刪除";button1.Enabled =true ;button2.Enabled =true ;button4.Enabled =true ;ObjClose();string sqlStr;sqlStr ="delete from 學(xué)生表 where Sno= '

42、"+ txtID.Text.Trim() +DataBase db = new DataBase();db.UpdataDB(sqlStr);RefresData();Form3_Load(null , null );catch (Exception ex)MessageBoxShow(ex.Message);課程信息管理界面如圖10-5所示:圖10-5課程信息管理界面可以進(jìn)行被選擇課程信息的添加、修改、刪除操作。代碼如下:添加:tryif (button1.Text.Trim()="添加")button1.Text ="確定";ObjOpen

43、();Clear();button2.Enabled =false ;button3.Enabled =false)else(button1.Text ="添加";if (txtCno.Text.Trim() !="" && ss.Text.Trim() !="")(string sqlStr;sqlStr ="insert into課程表 values。"+ txtCno.Text.Trim() +"','"+ txtCname.Text +"'

44、;'"+ txtCredit.Text.Trim() +"','"+ comCsemester.Text.Trim() +"','"+ txtCperiod.Text.Trim() +"')"DataBase db = new DataBase(); bool b;b = db.UpdataDB(sqlStr); if (b = true )(if ( MessageBoxShow("添力口成功!繼續(xù)添加嗎?","添加學(xué)生",Messag

45、eBoxButtons .YesNo,MessageBoxIcon .Question, MessageBoxDefaultButton .Button1) = DialogResult .Yes)(Form4_Load(null , null );button2.Enabled =true ;button3.Enabled =true ;RefresData();)else(ObjClose();button2.Enabled =true ;button3.Enabled =true ;dgrdvCourse.Enabled =true)else(goto exit;)else(Messag

46、eBoxShow("課程號和課程姓名不能為空 ");txtCno.Focus();button1.Text ="確定";)RefresData();txtCno.SelectAll();)刪除ry(if (button2.Text.Trim()="刪除")(button2.Text ="確定";buttonl.Enabled =false;button3.Enabled =false; else(button2.Text ="刪除";button1.Enabled =true;button3.E

47、nabled =true;ObjClose();string sqlStr;sqlStr ="delete from 課程表 where Cno= '"+ txtCno.Text.Trim() +DataBase db = new DataBase();db.UpdataDB(sqlStr);RefresData();Form4_Load(null , null ); catch ( Exception ex)(MessageBoxShow(ex.Message);修改:try(if (button3.Text.Trim()="修改")(butt

48、on3.Text ="確定";button1.Enabled =false;button2.Enabled =false;txtCperiod.Enabled =true ;txtCredit.Enabled =true ;comCsemester.Enabled =true ;txtCredit.Focus();elsebutton3.Text ="修改";buttonl.Enabled =true;button2.Enabled =true;ObjClose();string sqlStr;sqlStr ="update 課程表 set C

49、credit='" + txtCredit.Text.Trim() +"',Csemester='"comCsemester.Text.Trim() + "',Cperiod='" +txtCperiod.Text.Trim()+ "' where Cno='" + txtCno.Text.Trim() + DataBase db = new DataBase();db.UpdataDB(sqlStr); RefresData(); catch ( Exception

50、ex) MessageBoxShow(ex.Message);學(xué)生選課 界面如圖10-6所示圖10-6學(xué)生選課界面可以根據(jù)課程號(cno)查詢選擇了該課程的學(xué)生信息、可以查詢?nèi)繉W(xué)生的選課信息情況、可以進(jìn)行學(xué)生 相應(yīng)的選課操作。代碼如下:查詢:switch (a)case 1:sqlStr ="select * from 學(xué)生表 where Sno='" + textBox1.Text.Trim() +""'break ;case 2:sqlStr =break ;case 3:"select * from學(xué)生表where Sn

51、ame='"+ textBox2.Text.Trim() +"'"sqlStr =break ;case 4:"select * from學(xué)生表where Ssex='"+ comboBox1.Text.Trim() +"'"sqlStr =break ;case 5:"select * from學(xué)生表where Sage='"+ textBox3.Text.Trim() +"'"sqlStr =break ;default :break

52、 ;"select * from學(xué)生表where Sdept='"+ textBox4.Text.Trim() +"'")try(DataBase db = new DataBase();DataSet ds = new DataSet ();ds = db.GetDataFormDB(sqlStr);if (ds = null )(MessageBoxShow("沒有任何記錄");)else(dataStudent.DataSource=ds.Tables0;)ObjOpen();Clear();)catch (Ex

53、ception ex)(MessageBoxShow(ex.ToString();)(6學(xué)生選課 界面如圖10-7所示圖10-7學(xué)生選課系統(tǒng)登錄界面圖代碼如下:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace privateQQpublic partial class Form

54、6 : Formpublic int a = 0;public int b = 0;public Form6() InitializeComponent();)void ObjOpen()(textBoxI.Enabled = true;textBox2.Enabled = true;textBox3.Enabled = true;)void ObjClose()(textBox3.Enabled = false;textBox2.Enabled = false;textBox1.Enabled = false;)void Clear()(textBox1.Text =""

55、textBox2.Text =""textBox3.Text ="")private void Form6_Load(object sender, EventArgs e)(ObjClose();DataBase db = new DataBase();DataSet ds = new DataSet();string sqlStr = "select * from成績表"ds = db.GetDataFormDB(sqlStr);try(if (ds = null)(MessageBox.Show("沒有任何數(shù)據(jù)"

56、;);)else(dataGridViewl.DataSource = ds.Tables0;dataGridView1_RowHeaderMouseClick(null, null);)catch (Exception ex)(MessageBox.Show(ex.Message);)void RefresData()( string comStr; DataBase db = new DataBase(); DataSet ds = new DataSet(); comStr = "select * from成績表"ds = db.GetDataFormDB(comStr); if (ds != null) (dataGridView1.DataSource = ds.Tables0; else (MessageBox.Show("沒有任何學(xué)生

溫馨提示

  • 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論