溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

Java網(wǎng)上書(shū)店管理系統(tǒng)如何實(shí)現(xiàn)

發(fā)布時(shí)間:2022-06-08 09:11:09 來(lái)源:億速云 閱讀:195 作者:iii 欄目:開(kāi)發(fā)技術(shù)

今天小編給大家分享一下Java網(wǎng)上書(shū)店管理系統(tǒng)如何實(shí)現(xiàn)的相關(guān)知識(shí)點(diǎn),內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識(shí),所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來(lái)了解一下吧。

    1.效果展示

    Java網(wǎng)上書(shū)店管理系統(tǒng)如何實(shí)現(xiàn)

    Java網(wǎng)上書(shū)店管理系統(tǒng)如何實(shí)現(xiàn)

    2.需求功能

    用戶(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ū)的下單功能。

    3.系統(tǒng)總體設(shè)計(jì)及部分代碼

    Java網(wǎng)上書(shū)店管理系統(tǒng)如何實(shí)現(xiàn)

    3.1登錄模塊設(shè)計(jì)

    用戶(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();
    		}

    3.2新用戶(hù)的注冊(cè)

    此模塊的核心是創(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è)失敗!");
    			}
    		}
    	}

    3.3圖書(shū)添加模塊

    管理員在此界面上可對(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();
                    }
                }
            });
        }

    3.4圖書(shū)添加事件

    此界面主要實(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{
    
    		}
    	}
    }

    3.5買(mǎi)家信息維護(hù)

    此模塊主要用于對(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();
    
    			}
    		}
    	}

    3.6訂單管理模塊

    此模塊用于圖書(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, "訂單添加失敗!");
    			}
    		}
    	}

    4.數(shù)據(jù)庫(kù)設(shè)計(jì)

    4.1系統(tǒng)數(shù)據(jù)庫(kù)設(shè)計(jì)

    使用sql語(yǔ)句查詢(xún)項(xiàng)目存儲(chǔ)數(shù)據(jù)用到的數(shù)據(jù)庫(kù)表格:

    Java網(wǎng)上書(shū)店管理系統(tǒng)如何實(shí)現(xiàn)

    1.管理員信息表

    列名數(shù)據(jù)類(lèi)型長(zhǎng)度主鍵非空自增
    IdInt11√√√
    usenamevarchar20   
    passwordvarchar20   

    2.圖書(shū)類(lèi)型信息表

    列名數(shù)據(jù)類(lèi)型長(zhǎng)度主鍵非空自增






    idInt11√√√
    BookTypeNameVarchar20   
    bookTypeDesVarchar20   

    3.圖書(shū)信息表

    列名數(shù)據(jù)類(lèi)型長(zhǎng)度主鍵非空自增






    BooknameInt11√√√
    AuthorVarchar20   
    SexVarchar10   
    PriceFloat10   
    bookTypeIdInt11   
    bookDescVarchar1000   

    4.訂單信息表

    列名數(shù)據(jù)類(lèi)型長(zhǎng)度主鍵非空自增






    BuyidInt11√√√
    NameVarchar20   
    SexVarchar20   
    BuybooknamtelVarchar20   
    WayVarchar20   
    AddressVarchar20   

    5.買(mǎi)家信息表

    列名數(shù)據(jù)類(lèi)型長(zhǎng)度主鍵非空自增






    IdInt11√√√
    ConsumernameVarchar50   
    SexVarchar50   
    AgeVarchar50   
    NumberVarchar50   
    BooknameVarchar50   

    4.2系統(tǒng)E-R圖設(shè)計(jì)

    Java網(wǎng)上書(shū)店管理系統(tǒng)如何實(shí)現(xiàn)

    5.JDBC連接數(shù)據(jù)庫(kù)

    Java網(wǎng)上書(shū)店管理系統(tǒng)如何實(shí)現(xiàn)

    一定要安裝數(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è)資訊頻道。

    向AI問(wèn)一下細(xì)節(jié)

    免責(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)容。

    AI