您好,登錄后才能下訂單哦!
今天小編給大家分享一下Java網(wǎng)上書(shū)店管理系統(tǒng)如何實(shí)現(xiàn)的相關(guān)知識(shí)點(diǎn),內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識(shí),所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來(lái)了解一下吧。
用戶(hù)可以進(jìn)行注冊(cè)登陸系統(tǒng),在用戶(hù)的界面上,其可以進(jìn)行查看網(wǎng)上書(shū)店里的圖書(shū)類(lèi)別和所在類(lèi)別下的圖書(shū),根據(jù)自己的需求可在訂單項(xiàng)目里添加訂單購(gòu)買(mǎi)自己喜歡的圖書(shū);
管理員可以通過(guò)自己的賬號(hào)登錄到管理員系統(tǒng)對(duì)書(shū)店進(jìn)行管理,其可實(shí)現(xiàn)對(duì)圖書(shū)的添加,修改,查詢(xún),和刪除功能,可以查看用戶(hù)的訂單,修改和維護(hù)訂單。添家客戶(hù)的信息用以統(tǒng)計(jì)數(shù)據(jù)。
在構(gòu)造系統(tǒng)時(shí),首先從需求出發(fā)構(gòu)造數(shù)據(jù)庫(kù),然后再由數(shù)據(jù)庫(kù)表結(jié)合需求劃分系統(tǒng)功能模塊。這樣,就把一個(gè)大的系統(tǒng)解成了幾個(gè)小系統(tǒng)。這里把系統(tǒng)劃分為了三個(gè)模塊:用戶(hù)登錄模塊,管理員模塊,用戶(hù)購(gòu)買(mǎi)模塊。模塊分別能夠?qū)崿F(xiàn)以下功能:
登錄模塊:實(shí)現(xiàn)登錄,注冊(cè)功能。
管理員模塊:實(shí)現(xiàn)對(duì)圖書(shū)的添加修改和刪除以及對(duì)訂單的添加修改和刪除功能。
用戶(hù)購(gòu)買(mǎi)模塊:實(shí)現(xiàn)對(duì)圖書(shū)的查找以及對(duì)所需圖書(shū)的下單功能。
用戶(hù)正確輸入用戶(hù)名和密碼,連接到數(shù)據(jù)庫(kù),登錄成功!
private void loginActionPerformed(ActionEvent evt) { String userName=this.userNameTxt.getText(); String password=new String(this.passwordTxt.getPassword()); if(StringUtil.isEmpty(userName)){ JOptionPane.showMessageDialog(null, "用戶(hù)名不能為空!"); return; } if(StringUtil.isEmpty(password)){ JOptionPane.showMessageDialog(null, "密碼不能為空!"); return; } CUser cuser=new CUser(userName,password); Connection con=null; try { con=dbUtil.getCon(); CUser currentCUser =cuserDao.login(con,cuser); if(currentCUser!=null){ dispose(); new CMainFrm().setVisible(true); }else{ JOptionPane.showMessageDialog(null, "用戶(hù)名或者密碼錯(cuò)誤!"); } } catch (Exception e) { // TODO 自動(dòng)生成的 catch 塊 e.printStackTrace(); }
此模塊的核心是創(chuàng)建實(shí)例化對(duì)象。
private void registrationActionPerformed(ActionEvent evt) { String userName=this.userNameTxt.getText(); String password=this.passwordTxt.getText(); if(StringUtil.isEmpty(userName)){ JOptionPane.showMessageDialog(null, "用戶(hù)名不能為空!"); return; } if(StringUtil.isEmpty(password)){ JOptionPane.showMessageDialog(null, "密碼不能為空!"); return; } Registration registration= new Registration(userName,password); Connection con= null; try { con=dbUtil.getCon(); int n= registrationDao.add(con, registration); if(n==1){ JOptionPane.showMessageDialog(null, "注冊(cè)成功!"); resetValue(); }else{ JOptionPane.showMessageDialog(null, "注冊(cè)失??!"); } }catch(Exception e) { }finally { try { dbUtil.closeCon(con); } catch (Exception e) { // TODO 自動(dòng)生成的 catch 塊 e.printStackTrace(); JOptionPane.showMessageDialog(null, "注冊(cè)失敗!"); } } }
管理員在此界面上可對(duì)系統(tǒng)里的圖書(shū)進(jìn)行查詢(xún)修改和刪除。
public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { BookAddInterFrm frame = new BookAddInterFrm(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); }
此界面主要實(shí)現(xiàn)圖書(shū)的添加功能。
/** *圖書(shū)添加事件 */ private void bookAddActionPerformed(ActionEvent evt) { String bookName=this.bookNameTxt.getText(); String author=this.authorTxt.getText(); String price=this.priceTxt.getText(); String bookDesc=this.bookDescTxt.getText(); if(StringUtil.isEmpty(bookName)){ JOptionPane.showMessageDialog(null, "圖書(shū)名稱(chēng)不能為空!"); return; } if(StringUtil.isEmpty(author)){ JOptionPane.showMessageDialog(null, "圖書(shū)作者不能為空!"); return; } if(StringUtil.isEmpty(price)){ JOptionPane.showMessageDialog(null, "圖書(shū)價(jià)格不能為空!"); return; } String sex=""; if(manJrb.isSelected()){ sex="男"; }else if(femaleJrb.isSelected()){ sex="女"; } BookType bookType=(BookType) bookTypeJcb.getSelectedItem(); int bookTypeId=bookType.getId(); Book book=new Book(bookName,author, sex, Float.parseFloat(price) , bookTypeId, bookDesc); Connection con=null; try{ con=dbUtil.getCon(); int addNum=bookDao.add(con, book); if(addNum==1){ JOptionPane.showMessageDialog(null, "圖書(shū)添加成功!"); resetValue(); }else{ JOptionPane.showMessageDialog(null, "圖書(shū)添加失??!"); } }catch(Exception e){ e.printStackTrace(); JOptionPane.showMessageDialog(null, "圖書(shū)添加失敗!"); }finally{ try { dbUtil.closeCon(con); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } /** * 重置表單 */ private void resetValue(){ this.bookNameTxt.setText(""); this.authorTxt.setText(""); this.priceTxt.setText(""); this.manJrb.setSelected(true); this.bookDescTxt.setText(""); if(this.bookTypeJcb.getItemCount()>0){ this.bookTypeJcb.setSelectedIndex(0); } } /** * 初始化圖書(shū)類(lèi)別下拉框 */ private void fillBookType(){ Connection con=null; BookType bookType=null; try{ con=dbUtil.getCon(); ResultSet rs=bookTypeDao.list(con, new BookType()); while(rs.next()){ bookType=new BookType(); bookType.setId(rs.getInt("id")); bookType.setBookTypeName(rs.getString("bookTypeName")); this.bookTypeJcb.addItem(bookType); } }catch(Exception e){ e.printStackTrace(); }finally{ } } }
此模塊主要用于對(duì)買(mǎi)家信息的查找和維護(hù)。
/** * 買(mǎi)家信息搜索事件處理 */ protected void consumerSerachActionPerformed(ActionEvent evt) { String s_consumerName= this.s_consumerNameTxt.getText(); Consumer consumer=new Consumer(); consumer.setConsumerName(s_consumerName); this.fillTable(consumer); } private void fillTable(Consumer consumer){ DefaultTableModel dtm=(DefaultTableModel) consumerTable.getModel(); dtm.setRowCount(0); // 設(shè)置成0行 Connection con=null; try{ con=dbUtil.getCon(); ResultSet rs=consumerDao.list(con, consumer); while(rs.next()){ Vector v=new Vector(); v.add(rs.getString("id")); v.add(rs.getString("consumerName")); v.add(rs.getString("sex")); v.add(rs.getString("age")); v.add(rs.getString("number")); v.add(rs.getString("bookName")); dtm.addRow(v); } }catch(Exception e){ e.printStackTrace(); }finally { try { dbUtil.closeCon(con); } catch (Exception e) { // TODO 自動(dòng)生成的 catch 塊 e.printStackTrace(); } } } /** * 買(mǎi)家信息修改 */ private void consumerUpdateActionEvet(ActionEvent evt) { String id=idTxt.getText(); String consumerName=consumerNameTxt.getText(); String sex=sexTxt.getText(); String age=ageTxt.getText(); String number=numberTxt.getText(); String bookName=bookNameTxt.getText(); if(StringUtil.isEmpty(id)){ JOptionPane.showMessageDialog(null, "請(qǐng)選擇要修改的記錄"); return; } if(StringUtil.isEmpty(consumerName)){ JOptionPane.showMessageDialog(null, "購(gòu)書(shū)者名稱(chēng)不能為空"); return; } if(StringUtil.isEmpty(age)){ JOptionPane.showMessageDialog(null, "年齡不能為空"); return; } if(StringUtil.isEmpty(number)){ JOptionPane.showMessageDialog(null, "聯(lián)系方式不能為空"); return; } if(StringUtil.isEmpty(bookName)){ JOptionPane.showMessageDialog(null, "圖書(shū)名稱(chēng)不能為空"); return; } if(StringUtil.isEmpty(sex)){ JOptionPane.showMessageDialog(null, "性別不能為空"); return; } Consumer consumer=new Consumer(Integer.parseInt(id),consumerName,sex,age,number,bookName); Connection con=null; try { con=dbUtil.getCon(); con=dbUtil.getCon(); int modifyNum=consumerDao.update(con, consumer); if(modifyNum==1){ JOptionPane.showMessageDialog(null, "修改成功"); this.resetValue(); this.fillTable(new Consumer()); }else{ JOptionPane.showMessageDialog(null, "修改失敗"); } }catch(Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, "修改失敗"); }finally { try { dbUtil.closeCon(con); } catch (Exception e) { // TODO 自動(dòng)生成的 catch 塊 e.printStackTrace(); } } }
此模塊用于圖書(shū)訂單管理,查找,修改,刪除等功能的實(shí)現(xiàn)。
/** * 訂單修改事件 */ protected void orderUpdateActionPerformed(ActionEvent evt) { String id=this.idTxt.getText(); if(StringUtil.isEmpty(id)){ JOptionPane.showMessageDialog(null, "請(qǐng)選擇要修改的記錄"); return; } String addressee=this.addresseeTxt.getText(); String number=this.numberTxt.getText(); String deliveryMent=this.deliveryMentTxt.getText(); String paymentMethod=this.paymentMethodTxt.getText(); String shippingAddress=this.shippingAddressTxt.getText(); if(StringUtil.isEmpty(addressee)){ JOptionPane.showMessageDialog(null, "收件人不能為空!"); return; } if(StringUtil.isEmpty(number)){ JOptionPane.showMessageDialog(null, "購(gòu)買(mǎi)數(shù)量不能為空!"); return; } if(StringUtil.isEmpty(deliveryMent)){ JOptionPane.showMessageDialog(null, "運(yùn)送方式不能為空!"); return; } if(StringUtil.isEmpty(paymentMethod)){ JOptionPane.showMessageDialog(null, "支付方式不能為空!"); return; } if(StringUtil.isEmpty(paymentMethod)){ JOptionPane.showMessageDialog(null, "收件地址不能為空!"); return; } Book book=(Book) this.bookNameJcb.getSelectedItem(); int bookId=book.getId(); Order order =new Order(Integer.parseInt(id), addressee, number, deliveryMent, paymentMethod, shippingAddress, bookId); Connection con =null; try { con=dbUtil.getCon(); int addNum=orderDao.update(con, order); if(addNum==1) { JOptionPane.showMessageDialog(null, "訂單修改成功!"); resetValue(); this.fillTable(new Order()); }else { JOptionPane.showMessageDialog(null, "訂單修改失??!"); } }catch(Exception e) { e.printStackTrace(); }finally { try { dbUtil.closeCon(con); } catch (Exception e) { // TODO 自動(dòng)生成的 catch 塊 e.printStackTrace(); JOptionPane.showMessageDialog(null, "訂單添加失敗!"); } } }
使用sql語(yǔ)句查詢(xún)項(xiàng)目存儲(chǔ)數(shù)據(jù)用到的數(shù)據(jù)庫(kù)表格:
1.管理員信息表
列名 | 數(shù)據(jù)類(lèi)型 | 長(zhǎng)度 | 主鍵 | 非空 | 自增 |
---|---|---|---|---|---|
Id | Int | 11 | √ | √ | √ |
usename | varchar | 20 | |||
password | varchar | 20 |
2.圖書(shū)類(lèi)型信息表
列名 | 數(shù)據(jù)類(lèi)型 | 長(zhǎng)度 | 主鍵 | 非空 | 自增 |
---|---|---|---|---|---|
id | Int | 11 | √ | √ | √ |
BookTypeName | Varchar | 20 | |||
bookTypeDes | Varchar | 20 |
3.圖書(shū)信息表
列名 | 數(shù)據(jù)類(lèi)型 | 長(zhǎng)度 | 主鍵 | 非空 | 自增 |
---|---|---|---|---|---|
Bookname | Int | 11 | √ | √ | √ |
Author | Varchar | 20 | |||
Sex | Varchar | 10 | |||
Price | Float | 10 | |||
bookTypeId | Int | 11 | |||
bookDesc | Varchar | 1000 |
4.訂單信息表
列名 | 數(shù)據(jù)類(lèi)型 | 長(zhǎng)度 | 主鍵 | 非空 | 自增 |
---|---|---|---|---|---|
Buyid | Int | 11 | √ | √ | √ |
Name | Varchar | 20 | |||
Sex | Varchar | 20 | |||
Buybooknamtel | Varchar | 20 | |||
Way | Varchar | 20 | |||
Address | Varchar | 20 |
5.買(mǎi)家信息表
列名 | 數(shù)據(jù)類(lèi)型 | 長(zhǎng)度 | 主鍵 | 非空 | 自增 |
---|---|---|---|---|---|
Id | Int | 11 | √ | √ | √ |
Consumername | Varchar | 50 | |||
Sex | Varchar | 50 | |||
Age | Varchar | 50 | |||
Number | Varchar | 50 | |||
Bookname | Varchar | 50 |
一定要安裝數(shù)據(jù)庫(kù)jdbc驅(qū)動(dòng)包!
代碼展示:
package com.util; import java.sql.Connection; import java.sql.DriverManager; /** * 數(shù)據(jù)庫(kù)工具類(lèi) */ public class DbUtil { private String jdbcName="com.mysql.cj.jdbc.Driver"; // 驅(qū)動(dòng)名稱(chēng) 數(shù)據(jù)庫(kù)連接地址 由于數(shù)據(jù)庫(kù)為最新版本 導(dǎo)致驅(qū)動(dòng)名稱(chēng)已改為com.mysql.cj.jdbc.Driver //由于時(shí)區(qū)錯(cuò)亂 執(zhí)行命令給MySQL服務(wù)器設(shè)置時(shí)區(qū)為東八區(qū) serverTimezone=GMT%2B8 private String dbUrl="jdbc:mysql://localhost:3306/db_book?serverTimezone=GMT%2B8";// 數(shù)據(jù)庫(kù)連接地址 private String dbuserName = "root"; // 用戶(hù)名 private String dbpassWord = "abc123"; // 密碼 /** * 獲取數(shù)據(jù)庫(kù)連接 */ public Connection getCon()throws Exception{ Class.forName(jdbcName); Connection con=DriverManager.getConnection(dbUrl, dbuserName, dbpassWord); return con; } /** * 關(guān)閉數(shù)據(jù)庫(kù)連接 */ public void closeCon(Connection con)throws Exception{ if(con!=null){ con.close(); } } public static void main(String[] args) { DbUtil dbUtil=new DbUtil(); try { dbUtil.getCon(); System.out.println("數(shù)據(jù)庫(kù)連接成功!"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("數(shù)據(jù)庫(kù)連接失敗"); } } }
以上就是“Java網(wǎng)上書(shū)店管理系統(tǒng)如何實(shí)現(xiàn)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會(huì)為大家更新不同的知識(shí),如果還想學(xué)習(xí)更多的知識(shí),請(qǐng)關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。