C#與SQL數據庫學生成績管理系統完整代碼_第1頁
C#與SQL數據庫學生成績管理系統完整代碼_第2頁
C#與SQL數據庫學生成績管理系統完整代碼_第3頁
C#與SQL數據庫學生成績管理系統完整代碼_第4頁
C#與SQL數據庫學生成績管理系統完整代碼_第5頁
已閱讀5頁,還剩15頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、數據庫技術及應用項目設 計報告 學生成績管理系統 姓名:Celia Yan 2015-01-07 一. 設計目的及意義 在如今的高校日常管理中,學生成績管理系統是其中非常重要的一環, 特別是當前學校 規模不斷擴大,學生人數日益增加, 課程門類多,校區分散等實際情況,學生成績統計功能 越來越繁重,稍有疏忽就會出現差錯。因此,學生成績管理系統更具有非常大的實際應用意 義。在互聯網快速崛起的今天,改革傳統的手工錄入方式,公正,準確,及時反映學生的信 息和成績的情況,以適應信息時代的要求,是學生成績管理系統的一個新的理念。 通過成績 管理可以大大提高學校的工作效率。 學生成績管理系統應該完成以下兩個方

2、面的內容: 學生 檔案資料的管理、學生成績的管理。通過學生成績管理系統可以做到信息的規范管理, 科學 統計和快速查詢、修改、增加、刪除等,減少管理方面的工作量。 二. 主要功能 該系統主要用于學校學生信息管理, 總體任務是實現學生信息關系的系統化、 規范化和 自動化,其主要任務是用計算機對學生信息進行日常管理,如查詢、修改、增加、刪除,另 外還考慮到用戶登錄的權限,針對學生信息和權限登錄的學生成績管理系統。 本系統主要包括注冊管理、教師管理、學生信息查詢、添加、修改、刪除等部分。其主要功 能有: (1) 學生信息的添加,包括輸入學生基本信息和成績。 (2) 學生信息的查詢,包括查詢學生的基本信

3、息和成績。 (3) 學生信息的修改,包括修改學生基本信息和成績。 (4) 學生信息的刪除,包括刪除學生基本信息和成績。 (5) 登錄用戶密碼修改,用戶登錄到系統可進行相應的用戶密碼修改。 (6) 管理員用戶對用戶名的管理,包括添加新用戶、刪除用戶。 學生成績管理系統是典型的信息管理系統,其開發主要包括后臺數據庫的建立和維護 以及前端應用程序開發兩個方面。對于前者要求建立起數據一致性和完整性強、 數據安全性 好的數據庫。對于后者則要求應用程序功能完備,易使用。 該管理系統我使用的是 Microsoft Visual Studio 2012 及 Microsoft SQLServer 2008。系

4、統功能流程圖 圖2.1 系統功能流程 三. 數據庫設計 3.1本系統的數據庫采用的是 SQL Server2008 。該數據庫包括學生成績表、用戶登錄 表用于紀錄學生的基本信息數據庫表結構如下: 成績表物理結構 p DELL4-330342SQLE.ntfiCore dboxjb* 列名 數據類型 哀許Nui值 學號 char(10) |H| 姓名 |而餉 B 計算機同縮 m 口 教據庫實用教程 rt 面向對象程序設計 E n 高數 r.t n 英語 B 總分 ht 回 學生成績管理系統 教師管理系統 登錄管理員系統 圖3.1 口結果上消息 學號姓名計算機網絡融攜庫買用教程響寸象程序設訐高藏賣

5、語總分 1 2 季二 即 B2 53 78 96 a 2 3 李三 45 2 7B S9 38 Q 3 1 李一 E5 63 7G 6S 62 0 4 65 52 &3 45 就 0 5 4 劉四 2 78 S9 82 63 foi HI II I 5 姬 75 S4 94 K 75 0 7 7 區B2 S5 31 就 的 0 8 弓RA 63 32 81 87 78 c 圖3.2 用戶登錄表物理結構: DELL4-330S42SQLE.ntscore dbo.dlb 列名 教據類型 允許Null用戶名 varcharO) n 密碼 var:har(50) B 甥 varchar(50

6、) 卜科目 I vane har(5O) 1 0 圖3.3 口滁_!消息 用戶名 密碼 科目 1 1234567B 計算機網絡 2 屈顫 23456789 頗 故鋸犀實用勒強 2 育思英 G121M2S 英語 A 曜平 1235fi7B9 頗 面聞勺象程庠律肝 s 李一 1234567B 學生 6 孚二 D0DM000 字生 S 1 1 _ _ _.J 7 李三 3G07Q7QQ 學生 8 制四 030W200 學生 9 D55600CM 學生 10 泌1 oeowiM 學生 11 區七 09140000 宇生 12 張川 BOOTOO&a 學生 13 弓時L (K0CW9Q 管理員

7、14 碰 2DDSOOOO ISA 15 a 瞄oa 官理員 圖3.4 3.2觸發器 刪除DLB中的記錄時同時刪除 CJB中姓名相同的記錄 USEstudentscore GO /* Object: Trigger dbo.dlb_delete Script Date: 01/07/2015 12:42:17 */ SETANSI_NULLSON GO SETQUOTED_IDENTIFIERON GO ALTERtrigger dbo .dlb_delete on dbo .dlb after delete as begin declare leib varchar(50) select l

8、eib=學生from deleted delete from cjb where 姓名 in (select 用戶名 from deleted) End 3.3數據庫連接 string constr = Password=617804;Persist Security Info=True;User ID=ywj;Initial Catalog=studentscore;Data Source=YANJING” ; | SqlConnection conn = new SqlConnection (constr); string sqlstr = select * from cjb ; SqlC

9、ommanotmd = new SqlCommandsqlstr, conn); SqlDataReader reader = cmd.ExecuteReader(); DataSet ds = new DataSet (); while (reader.Read() ( string id = reader學號.ToString(); string name = reader姓名.ToString(); MessageBoxShow(string .Format( id=0,name=1, 學號,姓名”); ) 四. 系統實現 4.1.登錄界面 圖4.1 該界面是學生成績管理系統的登錄界面,

10、 可以選擇作為學生,管理員或者教師身份登錄。 每一個進入系統的人都會看到當前的時間, 在登錄時只有用戶名, 密碼,與身份相符合時才 能進入系統,否則登錄無法成功。 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; usin

11、g System.Data.SqlClient; namespace WindowsFormsApplication1 public partial class Form1 : Form static public string sn, sub; public Form1() InitializeComponent(); Form2 fr2 = new Form2(); Form3 fr3 = new Form3(); Form4 fr4 = new Form4(); private void Form1_Load( object sender, EventArgs e) ( timer1.S

12、tart(); private void label1_Click( object sender, EventArgs e) ( private void button1_Click( object sender, EventArgs e) ( string constr = Password=617804;Persist Security Info=True;User ID=ywj;Initial Catalog=studentscore;Data Source=YANJING ; SqlConnection conn = new SqlConnection (constr); conn.O

13、pen(); if (textname.Text = | textpassword.Text = ) MessageBoxShow(信息不全,請不要遺漏信息! ); | if (rbtnmanager.Checked) ( string cstr = select * from dlb where 類別=管理員and 用戶名 =+ textname.Text.Trim() + and 密碼=+ textpassword.Text.Trim() + ; SqlCommancfcomm = new SqlCommandcstr, conn); SqlDataReader dr = comm.Exe

14、cuteReader(); if (dr.Read() ( sn = textname.Text.Trim(); fr4.Show(); this .Visible = false : ; e ( lse MessageBoxShow(笞碼或用戶名出錯,請重新輸入! ); textname.Text = ; textpassword.Text = ; if (rbtnteacher.Checked) ( string cstr = select * from dlb where 類別=教師and 用戶名= + textname.Text.Trim() + and 密碼=+ textpasswo

15、rd.Text.Trim() + ; SqlCommancfcomm = new SqlCommandcstr, conn); SqlDataReader dr = comm.ExecuteReader(); if (dr.Read() (sn = textname.Text.Trim(); sub = dr.GetValue(3).ToString(); fr3.Show(); this .Visible = false ; else MessageBoxShow(密碼或用戶名出錯,請重新輸入! ); textname.Text = ; textpassword.Text = ; if (r

16、btnstudent.Checked) string cstr = select * from dlb where 類別=學生and 用戶名= + textname.Text.Trim() + and 密碼=+ textpassword.Text.Trim() + ; SqlCommancComm = new SqlCommandcstr, conn); SqlDataReader dr = comm.ExecuteReader(); if (dr.Read() sn = textname.Text.Trim(); fr2.Show(); this .Visible = false ; els

17、e MessageBoxShow(密碼或用戶名出錯,請重新輸入! ); textname.Text = ; textpassword.Text = ; conn.Close(); conn.Dispose(); private void button2 Click( object sender, EventArgs e) Application .Exit(); | private void timer1 Tick( object sender, EventArgs e) label4.Text = ”當前時間:+ DateTime .Now.ToLongDateString() + + Da

18、teTime .Now.ToLongTimeString(); 4.2學生成績管理 心 Form2 詳汨信息分數修改密碼逗出 李二同學,歡迎你進入成績管理系鄉 當前時間:2015年1月7日11:03:46 圖4.2 設計過程: 此部分主要針對學生信息的管理, 可以查詢學生的所有成績信息,實現成績的添加、刪 除、修改、計算平均分等功能。還可以修改當前用戶下的密碼。 private void Form2 Load( object sender, EventArgs e) labell.Text = timer1.Start(); groupBox1.Visible = groupBox2.Visi

19、ble = private void button1 Click( object sender, EventArgs e) private void button3_Click( object sender, EventArgs e) ( / string constr = Password=null;Persist Security Info=True;User ID=BINIANDOUKOUadministrator;Initial Catalog=studentscore;Data Source=BINIANDOUKOUSQLEXPRESS”; /SqlConnection conn =

20、 new SqlConnection(constr); Form1.sn + ”同學,歡迎你進入成績管理系統! false false /conn.Open(); /SqlDataAdapter da = new SqlDataAdapter(Select * from cjb where 姓 名=+textBox1 .Text , conn); /DataSet ds = new DataSet(); /da.Fill(ds, usertable); /dataGridView1.DataSource =; private void toolStripButton1_Click( objec

21、t sender, EventArgs e) ( dataGridView1.Visible = true ; groupBox1.Visible = false ; groupBox2.Visible = false ; string constr = Password=617804;Persist Security Info=True;User ID=ywj;Initial Catalog=studentscore;Data Source=YANJING ; SqlConnection conn = new SqlConnection (constr); conn.Open(); SqlD

22、ataAdapter da = new SqlDataAdapter (select * from cjb where 姓名 =+ Form1.sn.Trim() + , , conn); /- 詳細信息 DataSet ds = new DataSet (); da.Fill(ds, usertable); dataGridViewl.DataSource = ds.Tables usertable .DefaultView; conn.Close(); conn.Dispose(); private void toolStripButton2 Click( object sender, E

23、ventArgs e) ( private void toolStripButton4 Click( object sender, EventArgs e) ( groupBox1.Visible = true ; private void button1_Click_1( object sender, EventArgs e) ( string constr = Password=617804;Persist Security Info=True;User ID=ywj;Initial Catalog=studentscore;Data Source=YANJING ; SqlConnect

24、ion conn = new SqlConnection (constr); conn.Open(); if (textnpd.Text != textpassword.Text) ( MessageBoxShow(密碼輸入有 誤,請重新輸入); if (textnpd.Text = & textpassword.Text = ) ( MessageBoxShow( 密碼不允許為空! ); if (textnpd.Text=textpassword.Text & textnpd.Text != ) ( SqlCommancfcom = new SqlCommand update

25、 dlb set 密碼=+ textpassword.Text.Trim() + where 用戶名=+ Form1.sn.Trim() + ”,conn); if (com.ExecuteNonQuery() = 1) ( MessageBoxShow(密碼更改成功);groupBox1.Visible = false ; conn.Close(); conn.Dispose(); private void dataGridView1_CellContentClick( object sender, DataGridViewCe llE ventArgs e) ( private void

26、toolStripButton5_Click( object sender, EventArgs e) ( this .Close(); Form1 l = new Form1(); l.Visible = true ; private void toolStripButton6_Click( object sender, EventArgs e) ( / string constr = Password=null;Persist Security Info=True;User ID=BINIANDOUKOUadministrator;Initial Catalog=studentscore;

27、Data Source=BINIANDOUKOUSQLEXPRESS”; /SqlConnection conn = new SqlConnection(constr); /conn.Open(); /SqlDataAdapter da = new SqlDataAdapter(Select * from cjb where 姓 名=+textBox1 .Text , conn); /DataSet ds = new DataSet(); /da.Fill(ds, usertable); /string s; /for(int i=2;i =6;i+) /( / if (int.Parse(d

28、s.Tablesusertable.Rows0i.ToString() 60) / s=int.Parse(ds.Tablesusertable.Rows0i.ToString(); / private void groupBox2_Enter( object sender, EventArgs e) ( dataGridView1.Visible = false ; groupBox1.Visible = false private void toolStripButton3_Click( object sender, EventArgs e) ( groupBox2 .Visible= t

29、rue ; string constr = Password=617804;Persist Security Info=True;User ID=ywj;Initial Catalog=studentscore;Data Source=YANJING ; SqlConnection conn = new SqlConnection (constr); conn.Open(); SqlDataAdapter da = new SqlDataAdapter (Select * from cjb where 姓名 =+Form1 .sn .Trim ()+ ”m , conn); DataSet d

30、s = new DataSet (); da.Fill(ds, usertable); int max=0,min=1001; double ave = 0.0; for (int i=2;i max) max=nt .Parse(ds.Tables usertable .Rows0i.ToString(); if (int .Parse(ds.Tables usertable .Rows0i.ToString()min ) min=int .Parse(ds.Tables usertable .Rows0i.ToString(); I txthscore.Text=max.ToString(

31、); txtlscore.Text=min.ToString(); txtall.Text=ds.Tables usertable .Rows0總分.ToString(); ave= int .Parse(ds.Tables usertable .Rows0總分 ”.ToString()/( double )5; txtave.Text=ave.ToString(); conn.Close();conn.Dispose(); private void timer1_Tick( object sender, EventArgs e) ( label2.Text= ”當前時間: +DateTime

32、 .Now.ToLongDateString()+ DateTime.Now.ToLongTimeString(); 4.3教師管理界面 設計過程: 此部分主要針對教師信息管理, 可以查詢學生的所有成績信息,實現成績的添加、 刪除、修 改、成績升序排序等功能。還可以修改當前用戶下的密碼。 private void button1 Click( object sender, EventArgs e) /查找 string constr = Password=617804;Persist Security Info=True;User 5 SqlConnection conn= new SqlCo

33、nnection (constr); conn.Open(); if (comboBox1.Text=學號) SqlCommandcm=newSqlCommand select 學號,+Form1 .sub + from cjb where 學號=+ textBox1.Text+ ,conn ); if (cm.ExecuteScalar ()= null ) MessageBoxShow(用戶名不存在”); else SqlDataAdapter da = new SqlDataAdapter (select 學 號,+Form1.sub+ from cjb where 學號=+textBo

34、x1.Text+ID=ywj;Initial Catalog=studentscore;Data Source=YANJING” ,conn); 圖4.3 DataSet ds = new DataSet (); da.Fill (ds , chaxun); dataGridView1.DataSource=ds.Tables chaxun .DefaultView; if (comboBox1.Text=姓名) SqlCommanccm=new SqlCommand select 姓名,+ Form1.sub + from cjb where 姓名=+ textBox1.Text+ ,con

35、n ); if (cm.ExecuteScalar()= null ) MessageBoxShow(該用戶不存在); else SqlDataAdapter da = new SqlDataAdapter (select 姓 名,+Form1.sub + from cjb where 姓名=+ textBox1.Text + ,conn ); DataSet ds = new DataSet (); da.Fill (ds, table); dataGridView1.DataSource=ds.Tables table .DefaultView; conn.Close();conn.Dis

36、pose(); private void textBox1_TextChanged( object sender, EventArgs e) private void toolStripButton2 Click( object sender, EventArgs e) / 查找 .Visible =false ; groupBox1.Enabled = true ; groupBox2.Enabled =false ; 所有成績 groupBox3.Visible = true ; string constr = Password=617804;Persist Security Info=T

37、rue;User ID=ywj;Initial Catalog=studentscore;Data Source=YANJING SqlConnection conn = new SqlConnection (constr); conn.Open(); SqlDataAdapter da = new SqlDataAdapter (select 學號,姓名,+ Form1.sub + from cjb ,conn); DataSet ds = new DataSet (); dataGridViewl .DataSource =ds.Tables table .DefaultView; con

38、n.Close ();conn .Dispose(); private void button2_Click( object sender, EventArgs e) / 修改成績 string constr = Password=617804;Persist Security Info=True;User ID=ywj;Initial Catalog=studentscore;Data Source=YANJING ; groupBox3 private void toolStripButton1 Click( object sender, EventArgs e) / da.Fill(ds

39、, table); SqlConnection conn = new SqlConnection (constr); conn.Open(); SqlCommandcom = new SqlCommand update cjb set + Form1.sub + = + textBox3.Text + where 姓名=+ textBox4.Text + , conn); if (com.ExecuteNonQuery() = 1) MessageBoxShow(修改成功); else MessageBoxShow(信息有誤,請重新輸入 ); conn.Close(); conn.Dispos

40、e(); private void toolStripButton3_Click( object sender, EventArgs e) / 修改 學生成績 groupBox3 .Visible = false ; groupBox2.Enabled = true ; groupBox1.Enabled = false ; groupBox3.Visible = false ; private void textBox3_TextChanged( object sender, EventArgs e) private void groupBox2_Enter( object sender,

41、EventArgs e) private void button3_Click( object sender, EventArgs e) / 確認修改密碼 string constr = Password=617804;Persist Security Info=True;User ID=ywj;Initial Catalog=studentscore;Data Source=YANJING ; SqlConnection conn = new SqlConnection (constr); conn.Open(); if (txtnpd.Text != txtnpassword.Text)

42、MessageBoxShow(兩次輸入密 碼不一致,請重新輸入); if (txtnpd.Text = & txtnpassword.Text = ) MessageBoxShow( 密碼不允許為空,請輸入密碼 ); if (txtnpd.Text = txtnpassword.Text & txtnpd.Text != ) ( SqlCommancfcom = new SqlCommand update dlb set 密碼= + txtnpassword.Text.Trim() + where 用戶名=+ Form1.sn.Trim() + , conn); if (com

43、.ExecuteNonQuery() = 1) ( MessageBoxShow(密碼更改成功);groupBox1.Visible = true ; conn.Close(); conn.Dispose(); private void toolStripButton5_Click( object sender, EventArgs e) ( groupBox4.Visible = true ; groupBox3.Visible = true ; dataGridView1.Visible = false ; private void toolStripButton4_Click( obje

44、ct sender, EventArgs e) / 升序排序 ( groupBox3.Visible = true ; string constr = Password=617804;Persist Security Info=True;User ID=ywj;Initial Catalog=studentscore;Data Source=YANJING ; SqlConnection conn = new SqlConnection (constr); conn.Open(); SqlDataAdapter da = new SqlDataAdapter (select 學號,姓名,+ F

45、orm1.sub + from cjb order by + Form1.sub + desc , conn); DataSet ds = new DataSet (); da.Fill(ds, table); dataGridView1.DataSource = ds.Tables table .DefaultView; | conn.Close(); conn.Dispose(); private void toolStripButton6_Click( object sender, EventArgs e) ( this .Close(); Form1 l = new Form1();

46、l.Visible = true ; _ private void timer1_Tick( object sender, EventArgs e) ( label8.Text = 當前時間:+ DateTime .Now.ToLongDateString() + DateTime .Now.ToLongTimeString(); 4.4管理員管理界面 圖4.4 設計過程: 此部分主要針對管理員的,可以添加和刪除所有用戶的賬號和密碼。 private void Form4_Load( object sender, EventArgs e) ( timer1.Start(); label1.Te

47、xt = Form1.sn + ”管理員,歡迎進入成績管理系統! ; groupBox2.Enabled = false ; private void label1 Click( object sender, EventArgs e) private void radioButton1_CheckedChanged( object sender, EventArgs e) ( if (radioButton1.Checked) ( groupBox2.Enabled = true ; txtkm.Enabled = true ; private void radioButton2 Checke

48、dChanged( object sender, EventArgs e) ( if (radioButton2.Checked) ( groupBox2.Enabled = true ; txtkm.Enabled = false ; private void txtyhm_TextChanged( object sender, EventArgs e) private void button2_Click( object sender, EventArgs e) ( txtkm.Text = txtmm.Text = txtyhm.Text = private void button3 C

49、lick( object sender, EventArgs e) ( this .Close(); Form1 l = new Form1(); l.Visible = true private void label5_Click( object sender, EventArgs e) ( private void timer1 Tick( object sender, EventArgs e) ( label5.Text = ”當前時間:+ DateTime.Now.ToLongDateString() + DateTime .Now.ToShortTimeString(); priva

50、te void button1_Click( object sender, EventArgs e) ( string constr = Password=617804;Persist Security Info=True;User ID=ywj;Initial Catalog=studentscore;Data Source=YANJING” ; SqlConnection conn = new SqlConnection (constr); conn.Open(); if (radioButton1 .Checked ) ( System. Console .Out.WriteLine(); if (txtyhm .Text != &txtmm .Text != & txtkm .Text != ) ( SqlCommancfcom = new SqlCommand( select * from dlb where 用戶名 =+ txtyhm .Text .Trim ()+ ,conn); if (com.ExecuteScalar () != null ) ( MessageBox .Show (用戶已存在 ); else ( SqlCommandcm =

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論