C# + MySQL 圖書管理系統(tǒng).doc
《C# + MySQL 圖書管理系統(tǒng).doc》由會員分享,可在線閱讀,更多相關(guān)《C# + MySQL 圖書管理系統(tǒng).doc(19頁珍藏版)》請?jiān)谘b配圖網(wǎng)上搜索。
_C#面向?qū)ο蟪绦蛟O(shè)計(jì)課程設(shè)計(jì)圖書借閱管理系統(tǒng)源碼下載地址:http:/pan.baidu.com/s/1eRCzK2m院 系:計(jì)算機(jī)學(xué)院專 業(yè):計(jì)算機(jī)科學(xué)與技術(shù)年 級:2014級學(xué)生姓名:/ 學(xué) 號:/教 師:/日 期: 2017年6月6日開發(fā)和運(yùn)行環(huán)境- 開發(fā)環(huán)境:Windows 10-1703;- 開發(fā)工具:Visual Studio 013 Update5;- 數(shù)據(jù)庫工具:Mysql 5.7 + NaviCat;- 運(yùn)行環(huán)境:Windows 10-1703;需求分析1.【角色】用戶通過【注冊】成為本系統(tǒng)的可訪問成員,通過【登陸】進(jìn)入系統(tǒng)。用戶可以操作的功能有:-查看圖書館的所有圖書信息,圖書的是否可借閱信息;-搜索功能:通過輸入關(guān)鍵字,來查找是否有自己需要的圖書;-借閱功能:未被其他用戶借閱的書籍可以直接借閱;-還書功能:若存在之前借閱的書籍,在未歸還的情況下,可以進(jìn)行還書操作,若未存在需要還的書籍,提示:未有需要?dú)w還的書籍;-個人信息:修改除了【用戶名】以外之前注冊的全部信息;-借閱信息:可以查看借閱歷史,曾經(jīng)的借書日期和還書日期,是否有未歸還的書等等;2.【角色】管理員通過【登陸】進(jìn)入用戶進(jìn)入不了的管理系統(tǒng)。管理員可以操作的功能有:-圖書信息修改:修改除了圖書名的現(xiàn)有的所有圖書信息;-添加圖書:添加新的圖書;-查看用戶信息:可以查看用戶表的部分用戶信息;3數(shù)據(jù)保存:需要長期保存在數(shù)據(jù)庫的數(shù)據(jù)有:-圖書信息:圖書的基本信息;-讀者信息:讀者的基本信息;-借閱信息:圖書的借閱信息;-帳號信息:圖書管理員和讀者的登錄帳號; 系統(tǒng)流程圖(不包含注冊功能)數(shù)據(jù)庫設(shè)計(jì)說明- 管理員表:adminInfo;- 圖書信息表:bookInfo;- 借閱信息表:borrowed;- 用戶信息表:userInfo;adminInfo表列名數(shù)據(jù)類型可否為空長度說明adminIdint否11管理員IDadminNamevarchar否255管理員用戶名adminPasswordvarchar否255管理員密碼bookInfo表列名數(shù)據(jù)類型可否為空長度說明bookIdint否11圖書編號IDbookNamevarchar否255圖書名bookAuthorvarchar否255圖書作者bookPriceint否11圖書價格bookPressvarchar否255圖書出版社bookTypevarchar是255圖書類型isBorrowedtinyint是11是否被借閱borrowIdint是11借閱人的IDBorrowedTimedatetime是0被借閱的時間borrowed表列名數(shù)據(jù)類型可否為空長度說明borrowedIdint否11借閱信息IDuserIdint是11操作人IDuserNamevarchar是255操作人用戶名bookIdint是11圖書IDeditTimedatatime是0操作時間bookNamevarchar是255圖書名editvarchar是255操作名UserInfo表列名數(shù)據(jù)類型可否為空長度說明userIdint否11用戶IDuserNamevarchar否255用戶名userPasswordvarchar否255用戶密碼userSexvarchar是255用戶性別模塊分析cs文件:主界面:主要顯示代碼 mainCenter.cs :public mainCenter() InitializeComponent(); string sql = server=localhost;user id=root;password=123456;database=C#librarycenter; /根據(jù)自己的設(shè)置 MySqlConnection conn = new MySqlConnection(sql); conn.Open();/打開數(shù)據(jù)庫連接 MySqlDataAdapter data1 = new MySqlDataAdapter();/實(shí)例化sqldataadpter MySqlCommand cmd1 = new MySqlCommand(SELECT bookName as 圖書名,bookAuthor as 作者,bookPrice as 圖書價格,bookPress as 出版社,bookType as 圖書類型,(CASE isBorrowed WHEN 0 THEN 未借閱 ELSE 已借閱 END) as借閱情況 FROM c#librarycenter.bookinfo, conn);/sql語句 data1.SelectCommand = cmd1;/設(shè)置為已實(shí)例化SqlDataAdapter的查詢命令 DataTable dt = new DataTable(); dt.Clear(); data1.Fill(dt);/把數(shù)據(jù)填充到datatable dataGridView1.DataSource = dt;/將數(shù)據(jù)集綁定datagridview,完成顯示 dataGridView1.AllowUserToAddRows = false; / login login = new login(); label1.Text = 這里是SMART-LIBRARY!用戶: + login.username; / 查找功能:主要實(shí)現(xiàn)代碼:private void button1_Click(object sender, EventArgs e) String so = textBox1.Text; String sql = server=localhost;user id=root;password=123456;database=C#librarycenter; /根據(jù)自己的設(shè)置 MySqlConnection conn = new MySqlConnection(sql); conn.Open();/打開數(shù)據(jù)庫連接 MySqlDataAdapter data1 = new MySqlDataAdapter();/實(shí)例化sqldataadpter MySqlCommand cmd1 = new MySqlCommand(SELECT bookName as 圖書名,bookAuthor as 作者,bookPrice as 圖書價格,bookPress as 出版社,bookType as 圖書類型,(CASE isBorrowed WHEN 0 THEN 未借閱 ELSE 已借閱 END) as借閱情況 FROM c#librarycenter.bookinfo where bookName like %+ so +% , conn);/sql語句 data1.SelectCommand = cmd1;/設(shè)置為已實(shí)例化SqlDataAdapter的查詢命令 /DataSet ds1 = new DataSet();/實(shí)例化dataset DataTable dt = new DataTable(); dt.Clear(); data1.Fill(dt);/把數(shù)據(jù)填充到datatable dataGridView1.DataSource = dt;/將數(shù)據(jù)集綁定datagridview,完成顯示 dataGridView1.AllowUserToAddRows = false; 借閱功能:主要實(shí)現(xiàn)代碼 - borrow.cs:private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) int r = this.dataGridView1.CurrentRow.Index; string h = this.dataGridView1.Rowsr.Cells1.Value.ToString(); string s = this.dataGridView1.Rowsr.Cells2.Value.ToString(); / login login = new login(); String userId = ; DateTime dt = DateTime.Now; String borrowedTime = dt.ToString(yyyy-MM-dd HH:mm:ss); string sql = server=localhost;user id=root;password=123456;database=C#librarycenter; /根據(jù)自己的設(shè)置 MySqlConnection conn = new MySqlConnection(sql); String updateBorrow1 = select userId from userInfo where userName = +login.username+; MySqlCommand mysqlcommand = new MySqlCommand(updateBorrow1,conn); conn.Open(); MySqlDataReader mdr = mysqlcommand.ExecuteReader(); if (mdr.Read() userId = mdr.GetString(0).ToString(); mdr.Close(); String updateBorrow2 = update bookInfo set isBorrowed = 1, borrowId = + userId + ,borrowedTime = + borrowedTime + where bookId = + h + ; / MySqlCommand mysqlcommand2 = new MySqlCommand(updateBorrow2, conn); int i = mysqlcommand2.ExecuteNonQuery(); if (i != -1) MessageBox.Show(login.username + rn恭喜你借 + rn這本書 + 成功); else MessageBox.Show(系統(tǒng)出了點(diǎn)問題,請聯(lián)系管理員!); /更新借閱表 String updateBorrow3 = insert into borrowed(userId,userName,bookId,editTime,bookName,edit) values( + userId + , + login.username + , + h + , + borrowedTime + , + s + ,借書); MySqlCommand mysqlcommand3 = new MySqlCommand(updateBorrow3, conn); mysqlcommand3.ExecuteNonQuery(); /刷新dataGridView1,重新綁定數(shù)據(jù)源 f5(); 歸還圖書功能:主要實(shí)現(xiàn)代碼 returnbook.cs:private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) int r = this.dataGridView1.CurrentRow.Index; string h = this.dataGridView1.Rowsr.Cells1.Value.ToString(); string s = this.dataGridView1.Rowsr.Cells2.Value.ToString(); DateTime dt = DateTime.Now; String returnedTime = dt.ToString(yyyy-MM-dd HH:mm:ss); String userId = ; string sql = server=localhost;user id=root;password=123456;database=C#librarycenter; /根據(jù)自己的設(shè)置 MySqlConnection conn = new MySqlConnection(sql); conn.Open(); / String updateBorrow1 = update bookInfo set isBorrowed = 0,borrowId = null,borrowedTime = null where bookId = +h+; MySqlCommand mysqlcommand2 = new MySqlCommand(updateBorrow1, conn); int i = mysqlcommand2.ExecuteNonQuery(); if (i != -1) MessageBox.Show(login.username + rn rn這本書,還書成功); else MessageBox.Show(系統(tǒng)出了點(diǎn)問題,請聯(lián)系管理員!); /更新借閱表 String updateBorrow = select userId from userInfo where userName = + login.username + ; MySqlCommand mysqlcommand = new MySqlCommand(updateBorrow, conn); MySqlDataReader mdr = mysqlcommand.ExecuteReader(); if (mdr.Read() userId = mdr.GetString(0).ToString(); mdr.Close(); String updateBorrow2 = insert into borrowed(userId,userName,bookId,editTime,bookName,edit) values( + userId + , + login.username + , + h + , + returnedTime + , + s + ,還書); MySqlCommand mysqlcommand3 = new MySqlCommand(updateBorrow2, conn); mysqlcommand3.ExecuteNonQuery(); /刷新dataGridView1,重新綁定數(shù)據(jù)源 f5(); 修改個人信息:主要實(shí)現(xiàn)代碼 editUser.cs:private void button1_Click(object sender, EventArgs e) login login = new login(); String pw = textBox1.Text; String npw = textBox2.Text; String un = login.username; String userPassword = ; String userId = ; if (male.Checked = true) ans = male; if (female.Checked = true) ans = female; String sql = server=localhost;user id=root;password=123456;database=C#librarycenter; /根據(jù)自己的設(shè)置 MySqlConnection conn = new MySqlConnection(sql); conn.Open(); / String yanzheng = SELECT userPassword FROM userinfo where userName = +login.username+; MySqlCommand yz = new MySqlCommand(yanzheng,conn); MySqlDataReader mdr2 = yz.ExecuteReader(); if (mdr2.Read() userPassword = mdr2.GetString(0); mdr2.Close(); if (textBox2.Text.Trim() != ) if (pw = userPassword) / String editsql1 = select userId from userInfo where userName = + login.username + ; MySqlCommand cmd1 = new MySqlCommand(editsql1, conn); MySqlDataReader mdr = cmd1.ExecuteReader(); if (mdr.Read() userId = mdr.GetString(0); else mdr.Close(); / String editsql2 = update userInfo set userPassword = + npw + , userSex = + ans + where userId = + userId + ; MySqlCommand cmd2 = new MySqlCommand(editsql2, conn); int i = cmd2.ExecuteNonQuery(); if (i = 1) MessageBox.Show(login.username + rn您的信息修改成功!rn請牢記您現(xiàn)在的密碼); else MessageBox.Show(修改失敗,請聯(lián)系管理員); else MessageBox.Show(你的原密碼輸入錯誤,請重新輸入啊啊啊); else MessageBox.Show(新的密碼請不要填空!); 查詢借閱信息:主要實(shí)現(xiàn)代碼 borrowedinfo.cs:public borrowedinfo() InitializeComponent(); label1.Text = login.username + ,以下是您的借閱記錄:; String sql = server=localhost;user id=root;password=123456;database=C#librarycenter; /根據(jù)自己的設(shè)置 MySqlConnection conn = new MySqlConnection(sql); conn.Open();/打開數(shù)據(jù)庫連接 String userId = ; MySqlCommand cmd = new MySqlCommand(select userId from borrowed where userName = + login.username +,conn); MySqlDataReader mdr = cmd.ExecuteReader(); if (mdr.Read() userId = mdr.GetString(0); mdr.Close(); MySqlDataAdapter data1 = new MySqlDataAdapter();/實(shí)例化sqldataadpter MySqlCommand cmd1 = new MySqlCommand(select bookId as 圖書編號,bookName as 圖書名,editTime as 操作時間,edit as 操作 from borrowed where userId = + userId +, conn);/sql語句 data1.SelectCommand = cmd1;/設(shè)置為已實(shí)例化SqlDataAdapter的查詢命令 /DataSet ds1 = new DataSet();/實(shí)例化dataset DataTable dt = new DataTable(); dt.Clear(); data1.Fill(dt);/把數(shù)據(jù)填充到datatable dataGridView1.DataSource = dt;/將數(shù)據(jù)集綁定datagridview,完成顯示 dataGridView1.AllowUserToAddRows = false; 后臺管理系統(tǒng):主要實(shí)現(xiàn)代碼 adminCenter.cs:private void 關(guān)于ToolStripMenuItem_Click(object sender, EventArgs e) MessageBox.Show(制作者:Matthew Hanrn完成時間:2017-6-4); private void 退出系統(tǒng)ToolStripMenuItem_Click(object sender, EventArgs e) System.Environment.Exit(0); private void 圖書管理ToolStripMenuItem_Click(object sender, EventArgs e) editMain editMain = new editMain(); editMain.FormBorderStyle = FormBorderStyle.None; editMain.Dock = DockStyle.Fill; editMain.TopLevel = false; this.panel1.Controls.Clear(); this.panel1.Controls.Add(editMain); editMain.Show(); private void 添加圖書ToolStripMenuItem_Click(object sender, EventArgs e) edit2 edit2 = new edit2(); edit2.Show(); private void 用戶管理ToolStripMenuItem_Click(object sender, EventArgs e) edit3 edit3 = new edit3(); edit3.FormBorderStyle = FormBorderStyle.None; edit3.Dock = DockStyle.Fill; edit3.TopLevel = false; this.panel1.Controls.Clear(); this.panel1.Controls.Add(edit3); edit3.Show(); 修改圖書信息:主要實(shí)現(xiàn)代碼 editMain.cs & edit1.cs:public static string bookname; public static string bookauthor; public static string bookprice; public static string bookpress; public static string booktype;/說明:這里用的是全局靜態(tài)變量,把表格獲取到的數(shù)據(jù)保存起來,進(jìn)行數(shù)據(jù)傳輸。private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) int r = this.dataGridView1.CurrentRow.Index; string bn = this.dataGridView1.Rowsr.Cells1.Value.ToString(); string ba = this.dataGridView1.Rowsr.Cells2.Value.ToString(); string bp1 = this.dataGridView1.Rowsr.Cells3.Value.ToString(); string bp2 = this.dataGridView1.Rowsr.Cells4.Value.ToString(); string bt = this.dataGridView1.Rowsr.Cells5.Value.ToString(); / editMain editMain = new editMain(); editMain.bookname = bn.ToString(); editMain.bookauthor = ba.ToString(); editMain.bookprice = bp1.ToString(); editMain.bookpress = bp2.ToString(); editMain.booktype = bt.ToString(); / edit1 edit1 = new edit1(); edit1.Show(); /接下來是edit1.cs中的提交新的數(shù)據(jù),update數(shù)據(jù)庫。public edit1() InitializeComponent(); editMain editMain = new editMain(); label6.Text = editMain.bookname; textBox1.Text = editMain.bookauthor; textBox2.Text = editMain.bookprice; textBox3.Text = editMain.bookpress; textBox4.Text = editMain.booktype; private void button1_Click(object sender, EventArgs e) String bn = editMain.bookname; String ba = textBox1.Text; String bp1 = textBox2.Text; String bp2 = textBox3.Text; String bt = textBox4.Text; / String sql = server=localhost;user id=root;password=123456;database=C#librarycenter; /根據(jù)自己的設(shè)置 MySqlConnection conn = new MySqlConnection(sql); conn.Open(); / String sql2 = update bookInfo set bookAuthor = + ba + , bookPrice = + bp1 + , bookPress = + bp2 + ,bookType = + bt + where bookName = + bn + ; MySqlCommand cmd = new MySqlCommand(sql2, conn); int i = cmd.ExecuteNonQuery(); if (i = 1) MessageBox.Show(圖書修改成功!); this.Hide(); 添加圖書:主要實(shí)現(xiàn)代碼 edit2.cs:private void button1_Click(object sender, EventArgs e) String bn = textBox5.Text; String ba = textBox1.Text; String bp1 = textBox2.Text; String bp2 = textBox3.Text; String bt = textBox4.Text; / String sql = server=localhost;user id=root;password=123456;database=C#librarycenter; /根據(jù)自己的設(shè)置 MySqlConnection conn = new MySqlConnection(sql); conn.Open(); String sql2 = insert into bookInfo(bookName,bookAuthor,bookPrice,bookPress,bookType,isBorrowed) values( + bn + , + ba + , + bp1 + , + bp2 + , + bt + ,0) ; MySqlCommand cmd = new MySqlCommand(sql2, conn); int i = cmd.ExecuteNonQuery(); if (i = 1) MessageBox.Show(圖書添加成功!); else MessageBox.Show(系統(tǒng)出錯!); this.Hide(); 用戶管理:主要實(shí)現(xiàn)代碼 edit3.cs:public edit3() InitializeComponent(); String sql = server=localhost;user id=root;password=123456;database=C#librarycenter; /根據(jù)自己的設(shè)置 MySqlConnection conn = new MySqlConnection(sql); conn.Open();/打開數(shù)據(jù)庫連接 MySqlDataAdapter data1 = new MySqlDataAdapter();/實(shí)例化sqldataadpter MySqlCommand cmd1 = new MySqlCommand(SELECT userId as 用戶ID,userName as 用戶名,(CASE userPassword WHEN null THEN * ELSE * END) as 用戶密碼,userSex as 用戶性別 FROM c#librarycenter.userInfo, conn);/sql語句 data1.SelectCommand = cmd1;/設(shè)置為已實(shí)例化SqlDataAdapter的查詢命令 DataTable dt = new DataTable(); dt.Clear(); data1.Fill(dt);/把數(shù)據(jù)填充到datatable dataGridView1.DataSource = dt;/將數(shù)據(jù)集綁定datagridview,完成顯示 dataGridView1.AllowUserToAddRows = false; 總結(jié)這次的圖書管理系統(tǒng),并未用到MVC設(shè)計(jì)模式,只是簡單的面向?qū)ο笤O(shè)計(jì),選的題目也是比較熟悉的,本系統(tǒng)提供兩種權(quán)限:用戶和管理員,其實(shí)應(yīng)該把【管理員】分成【圖書管理員】和【系統(tǒng)管理員】,提供不同的權(quán)限,【系統(tǒng)管理員】具有對所有用戶的操作權(quán)限,【圖書管理員】具有對所有圖書的操作權(quán)限。本次課題當(dāng)然還存在著許多不足,以后有機(jī)會的話,會加以改進(jìn)。姓名:/學(xué)號:/-可編輯修改-- 1.請仔細(xì)閱讀文檔,確保文檔完整性,對于不預(yù)覽、不比對內(nèi)容而直接下載帶來的問題本站不予受理。
- 2.下載的文檔,不會出現(xiàn)我們的網(wǎng)址水印。
- 3、該文檔所得收入(下載+內(nèi)容+預(yù)覽)歸上傳者、原創(chuàng)作者;如果您是本文檔原作者,請點(diǎn)此認(rèn)領(lǐng)!既往收益都?xì)w您。
下載文檔到電腦,查找使用更方便
18 積分
下載 |
- 配套講稿:
如PPT文件的首頁顯示word圖標(biāo),表示該P(yáng)PT已包含配套word講稿。雙擊word圖標(biāo)可打開word文檔。
- 特殊限制:
部分文檔作品中含有的國旗、國徽等圖片,僅作為作品整體效果示例展示,禁止商用。設(shè)計(jì)者僅對作品中獨(dú)創(chuàng)性部分享有著作權(quán)。
- 關(guān) 鍵 詞:
- C# MySQL 圖書管理系統(tǒng) 圖書 管理 系統(tǒng)
鏈接地址:http://m.italysoccerbets.com/p-1124325.html