C# + MySQL 圖書管理系統(tǒng).doc
《C# + MySQL 圖書管理系統(tǒng).doc》由會(huì)員分享,可在線閱讀,更多相關(guān)《C# + MySQL 圖書管理系統(tǒng).doc(19頁(yè)珍藏版)》請(qǐng)?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ù) 年 級(jí): 2014級(jí) 學(xué)生姓名: // 學(xué) 號(hào): // 教 師: // 日 期: 2017年6月6日 開發(fā)和運(yùn)行環(huán)境 - 開發(fā)環(huán)境:Windows 10-1703; - 開發(fā)工具:Visual Studio 013 Update5; - 數(shù)據(jù)庫(kù)工具:Mysql 5.7 + NaviCat; - 運(yùn)行環(huán)境:Windows 10-1703; 需求分析 1.【角色】用戶通過【注冊(cè)】成為本系統(tǒng)的可訪問成員,通過【登陸】進(jìn)入系統(tǒng)。用戶可以操作的功能有: - 查看圖書館的所有圖書信息,圖書的是否可借閱信息; - 搜索功能:通過輸入關(guān)鍵字,來(lái)查找是否有自己需要的圖書; - 借閱功能:未被其他用戶借閱的書籍可以直接借閱; - 還書功能:若存在之前借閱的書籍,在未歸還的情況下,可以進(jìn)行還書操作,若未存在需要還的書籍,提示:未有需要?dú)w還的書籍; - 個(gè)人信息:修改除了【用戶名】以外之前注冊(cè)的全部信息; - 借閱信息:可以查看借閱歷史,曾經(jīng)的借書日期和還書日期,是否有未歸還的書等等; 2.【角色】管理員通過【登陸】進(jìn)入用戶進(jìn)入不了的管理系統(tǒng)。管理員可以操作的功能有: - 圖書信息修改:修改除了圖書名的現(xiàn)有的所有圖書信息; - 添加圖書:添加新的圖書; - 查看用戶信息:可以查看用戶表的部分用戶信息; 3.?dāng)?shù)據(jù)保存:需要長(zhǎng)期保存在數(shù)據(jù)庫(kù)的數(shù)據(jù)有: - 圖書信息:圖書的基本信息; - 讀者信息:讀者的基本信息; - 借閱信息:圖書的借閱信息; - 帳號(hào)信息:圖書管理員和讀者的登錄帳號(hào); ?? 系統(tǒng)流程圖(不包含注冊(cè)功能) 數(shù)據(jù)庫(kù)設(shè)計(jì)說明 - 管理員表:adminInfo; - 圖書信息表:bookInfo; - 借閱信息表:borrowed; - 用戶信息表:userInfo; adminInfo表 列名 數(shù)據(jù)類型 可否為空 長(zhǎng)度 說明 adminId int 否 11 管理員ID adminName varchar 否 255 管理員用戶名 adminPassword varchar 否 255 管理員密碼 bookInfo表 列名 數(shù)據(jù)類型 可否為空 長(zhǎng)度 說明 bookId int 否 11 圖書編號(hào)ID bookName varchar 否 255 圖書名 bookAuthor varchar 否 255 圖書作者 bookPrice int 否 11 圖書價(jià)格 bookPress varchar 否 255 圖書出版社 bookType varchar 是 255 圖書類型 isBorrowed tinyint 是 11 是否被借閱 borrowId int 是 11 借閱人的ID BorrowedTime datetime 是 0 被借閱的時(shí)間 borrowed表 列名 數(shù)據(jù)類型 可否為空 長(zhǎng)度 說明 borrowedId int 否 11 借閱信息ID userId int 是 11 操作人ID userName varchar 是 255 操作人用戶名 bookId int 是 11 圖書ID editTime datatime 是 0 操作時(shí)間 bookName varchar 是 255 圖書名 edit varchar 是 255 操作名 UserInfo表 列名 數(shù)據(jù)類型 可否為空 長(zhǎng)度 說明 userId int 否 11 用戶ID userName varchar 否 255 用戶名 userPassword varchar 否 255 用戶密碼 userSex varchar 是 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ù)庫(kù)連接 MySqlDataAdapter data1 = new MySqlDataAdapter();//實(shí)例化sqldataadpter MySqlCommand cmd1 = new MySqlCommand("SELECT bookName as '圖書名',bookAuthor as '作者',bookPrice as '圖書價(jià)格',bookPress as '出版社',bookType as '圖書類型',(CASE isBorrowed WHEN 0 THEN '未借閱' ELSE '已借閱' END) as'借閱情況' FROM `c#librarycenter`.bookinfo", conn);//sql語(yǔ)句 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ù)庫(kù)連接 MySqlDataAdapter data1 = new MySqlDataAdapter();//實(shí)例化sqldataadpter MySqlCommand cmd1 = new MySqlCommand("SELECT bookName as '圖書名',bookAuthor as '作者',bookPrice as '圖書價(jià)格',bookPress as '出版社',bookType as '圖書類型',(CASE isBorrowed WHEN 0 THEN '未借閱' ELSE '已借閱' END) as'借閱情況' FROM `c#librarycenter`.bookinfo where bookName like '%"+ so +"%' ", conn);//sql語(yǔ)句 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.Rows[r].Cells[1].Value.ToString(); string s = this.dataGridView1.Rows[r].Cells[2].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 + " \r\n恭喜你借" + " << " + s + " >> \r\n這本書" + "成功"); } else { MessageBox.Show("系統(tǒng)出了點(diǎn)問題,請(qǐng)聯(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.Rows[r].Cells[1].Value.ToString(); string s = this.dataGridView1.Rows[r].Cells[2].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 + " \r\n<< " + s + " >> \r\n這本書,還書成功"); } else { MessageBox.Show("系統(tǒng)出了點(diǎn)問題,請(qǐng)聯(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(); } 修改個(gè)人信息: 主要實(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 + "\r\n您的信息修改成功!\r\n請(qǐng)牢記您現(xiàn)在的密碼"); } else { MessageBox.Show("修改失敗,請(qǐng)聯(lián)系管理員~"); } } else { MessageBox.Show("你的原密碼輸入錯(cuò)誤,請(qǐng)重新輸入啊啊啊"); } } else { MessageBox.Show("新的密碼請(qǐng)不要填空!"); } } 查詢借閱信息: 主要實(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ù)庫(kù)連接 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 '圖書編號(hào)',bookName as '圖書名',editTime as '操作時(shí)間',edit as '操作' from borrowed where userId = '"+ userId +"'", conn);//sql語(yǔ)句 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ái)管理系統(tǒng): 主要實(shí)現(xiàn)代碼 – adminCenter.cs: private void 關(guān)于ToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show("制作者:Matthew Han\r\n完成時(shí)間: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ù)保存起來(lái),進(jìn)行數(shù)據(jù)傳輸。 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { int r = this.dataGridView1.CurrentRow.Index; string bn = this.dataGridView1.Rows[r].Cells[1].Value.ToString(); string ba = this.dataGridView1.Rows[r].Cells[2].Value.ToString(); string bp1 = this.dataGridView1.Rows[r].Cells[3].Value.ToString(); string bp2 = this.dataGridView1.Rows[r].Cells[4].Value.ToString(); string bt = this.dataGridView1.Rows[r].Cells[5].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(); } //接下來(lái)是edit1.cs中的提交新的數(shù)據(jù),update數(shù)據(jù)庫(kù)。 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)出錯(cuò)!"); } 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ù)庫(kù)連接 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語(yǔ)句 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ì)模式,只是簡(jiǎn)單的面向?qū)ο笤O(shè)計(jì),選的題目也是比較熟悉的,本系統(tǒng)提供兩種權(quán)限:用戶和管理員,其實(shí)應(yīng)該把【管理員】分成【圖書管理員】和【系統(tǒng)管理員】,提供不同的權(quán)限,【系統(tǒng)管理員】具有對(duì)所有用戶的操作權(quán)限,【圖書管理員】具有對(duì)所有圖書的操作權(quán)限。本次課題當(dāng)然還存在著許多不足,以后有機(jī)會(huì)的話,會(huì)加以改進(jìn)。 姓名:// 學(xué)號(hào):// -可編輯修改-- 1.請(qǐng)仔細(xì)閱讀文檔,確保文檔完整性,對(duì)于不預(yù)覽、不比對(duì)內(nèi)容而直接下載帶來(lái)的問題本站不予受理。
- 2.下載的文檔,不會(huì)出現(xiàn)我們的網(wǎng)址水印。
- 3、該文檔所得收入(下載+內(nèi)容+預(yù)覽)歸上傳者、原創(chuàng)作者;如果您是本文檔原作者,請(qǐng)點(diǎn)此認(rèn)領(lǐng)!既往收益都?xì)w您。
下載文檔到電腦,查找使用更方便
18 積分
下載 |
- 配套講稿:
如PPT文件的首頁(yè)顯示word圖標(biāo),表示該P(yáng)PT已包含配套word講稿。雙擊word圖標(biāo)可打開word文檔。
- 特殊限制:
部分文檔作品中含有的國(guó)旗、國(guó)徽等圖片,僅作為作品整體效果示例展示,禁止商用。設(shè)計(jì)者僅對(duì)作品中獨(dú)創(chuàng)性部分享有著作權(quán)。
- 關(guān) 鍵 詞:
- C# MySQL 圖書管理系統(tǒng) 圖書 管理 系統(tǒng)
鏈接地址:http://m.zhongcaozhi.com.cn/p-1124325.html