Java之------单机版书店管理系统(设计思想和设计模式系列四)图书模块

书店管理系统

书店管理系统可以说是设计模式及设计思想的一个比较经典的例子。

本系列将分为多个部分讲述此输电管理系统。

书店管理系统将分为:用户、图书、进货、销售和库存五个模块,另外还有公共包、工具包和登录包,另外还有一个框架。

对于分层设计,都是表现层可以调用逻辑层,逻辑层调用数据层,数据层调用工具和公共包,方向不可打乱,必须严格按照这种模式。

本篇将做图书模块。


注:本篇需要使用到的框架在本系列二的用户模块:

链接:点击打开链接


同系列有:

系列一(概述):点击打开链接

系列二(用户):点击打开链接

系列三(工具包和公共类):点击打开链接

系列五(进货):点击打开链接

系列六(销售):点击打开链接

系列七(库存):点击打开链接

系列八(登录):点击打开链接


和用户模块相同的,图书模块分成了数据层、逻辑层、表现层和值对象层。


数据层:

接口:

[java]  view plain  copy
 
  1. package cn.hncu.book.dao.dao;  
  2.   
  3. import java.util.List;  
  4.   
  5. import cn.hncu.book.vo.BookModel;  
  6. import cn.hncu.book.vo.BookQueryModel;  
  7.   
  8. public interface BookDAO {  
  9.     public boolean create(BookModel book);  
  10.     public boolean delete(String uuid);  
  11.     public boolean upDate(BookModel book);  
  12.       
  13.     public BookModel getSingle(String uuid);  
  14.     public List<BookModel> getAll();  
  15.     public List<BookModel> getByCondition(BookQueryModel bqm);  
  16. }  
实现类:

[java]  view plain  copy
 
  1. package cn.hncu.book.dao.impl;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5.   
  6. import cn.hncu.book.dao.dao.BookDAO;  
  7. import cn.hncu.book.vo.BookModel;  
  8. import cn.hncu.book.vo.BookQueryModel;  
  9. import cn.hncu.utils.FileIo;  
  10.   
  11. public class BookDAOImpl implements BookDAO {  
  12.     private static final String FILE_NAME="book.txt";  
  13.     @Override  
  14.     public boolean create(BookModel book) {  
  15.         List<BookModel> list=FileIo.read(FILE_NAME);  
  16.         for (BookModel u:list){  
  17.             if (u.getUuid().equals(book.getUuid())){  
  18.                 return false;  
  19.             }  
  20.         }  
  21.         list.add(book);  
  22.         FileIo.write(list, FILE_NAME);  
  23.         return true;  
  24.     }  
  25.   
  26.     @Override  
  27.     public boolean delete(String uuid) {  
  28.         List<BookModel> list=FileIo.read(FILE_NAME);  
  29.         for (int i=0;i<list.size();i++){  
  30.             if (list.get(i).getUuid().equals(uuid)){  
  31.                 list.remove(i);  
  32.                 FileIo.write(list, FILE_NAME);  
  33.                 return true;  
  34.             }  
  35.         }  
  36.         return false;  
  37.     }  
  38.   
  39.     @Override  
  40.     public List<BookModel> getAll() {  
  41.         List<BookModel> list=FileIo.read(FILE_NAME);  
  42.         return list;  
  43.     }  
  44.   
  45.     @Override  
  46.     public List<BookModel> getByCondition(BookQueryModel bqm) {  
  47.         List<BookModel> list=getAll();  
  48.         List<BookModel> results=new ArrayList<BookModel>();  
  49.         for (BookModel book:list){  
  50.             //反逻辑,卫条件: 外层判断用户输入是否是查询条件;内层判断该对象是否符合查询条件  
  51.             if (bqm.getUuid()!=null&&bqm.getUuid().trim().length()>0){  
  52.                 if (!bqm.getUuid().equals(book.getUuid())){  
  53.                     continue;  
  54.                 }  
  55.             }  
  56.             if (bqm.getName()!=null&&bqm.getName().trim().length()>0){  
  57.                 if (book.getName().indexOf(bqm.getName())==-1){  
  58.                     continue;  
  59.                 }  
  60.             }  
  61.             if (bqm.getInPrice()>0){  
  62.                 if (bqm.getInPrice()>book.getInPrice()){  
  63.                     continue;  
  64.                 }  
  65.             }  
  66.             if (bqm.getHighInPrice()>0){  
  67.                 if (bqm.getHighInPrice()<book.getInPrice()){  
  68.                     continue;  
  69.                 }  
  70.             }  
  71.             if (bqm.getSalePrice()>0){  
  72.                 if (bqm.getSalePrice()>book.getSalePrice()){  
  73.                     continue;  
  74.                 }  
  75.             }  
  76.             if (bqm.getHighSalePrice()>0){  
  77.                 if (bqm.getHighSalePrice()<book.getSalePrice()){  
  78.                     continue;  
  79.                 }  
  80.             }  
  81.             results.add(book);  
  82.         }  
  83.         return results;  
  84.     }  
  85.   
  86.     @Override  
  87.     public BookModel getSingle(String uuid) {  
  88.         List<BookModel> list=FileIo.read(FILE_NAME);  
  89.         for (BookModel u:list){  
  90.             if (u.getUuid().equals(uuid)){  
  91.                 return u;  
  92.             }  
  93.         }  
  94.         return null;  
  95.     }  
  96.   
  97.     @Override  
  98.     public boolean upDate(BookModel book) {  
  99.         List<BookModel> list=FileIo.read(FILE_NAME);  
  100.         for (int i=0;i<list.size();i++){  
  101.             if (list.get(i).getUuid().equals(book.getUuid())){  
  102.                 list.set(i, book);  
  103.                 FileIo.write(list, FILE_NAME);  
  104.                 return true;  
  105.             }  
  106.         }  
  107.         return false;  
  108.     }  
  109. }  
工厂类:

[java]  view plain  copy
 
  1. package cn.hncu.book.dao.factory;  
  2.   
  3. import cn.hncu.book.dao.dao.BookDAO;  
  4. import cn.hncu.book.dao.impl.BookDAOImpl;  
  5.   
  6. public class BookDAOFactory {  
  7.     public static BookDAO getBookDAO(){  
  8.         return new BookDAOImpl();  
  9.     }  
  10. }  


逻辑层:

接口:

[java]  view plain  copy
 
  1. package cn.hncu.book.business.ebi;  
  2.   
  3. import java.util.List;  
  4.   
  5. import cn.hncu.book.vo.BookModel;  
  6. import cn.hncu.book.vo.BookQueryModel;  
  7.   
  8. public interface BookEbi {  
  9.     public boolean create(BookModel book);  
  10.     public boolean delete(String uuid);  
  11.     public boolean upDate(BookModel book);  
  12.       
  13.     public BookModel getSingle(String uuid);  
  14.     public List<BookModel> getAll();  
  15.     public List<BookModel> getByCondition(BookQueryModel bqm);  
  16.       
  17.     public BookModel getBookByName(String bookName);  
  18. }  
实现类:

[java]  view plain  copy
 
  1. package cn.hncu.book.business.ebo;  
  2.   
  3. import java.util.List;  
  4.   
  5. import cn.hncu.book.business.ebi.BookEbi;  
  6. import cn.hncu.book.dao.dao.BookDAO;  
  7. import cn.hncu.book.dao.factory.BookDAOFactory;  
  8. import cn.hncu.book.vo.BookModel;  
  9. import cn.hncu.book.vo.BookQueryModel;  
  10. import cn.hncu.common.UuidModelConstance;  
  11. import cn.hncu.common.uuid.dao.factory.UuidDAOFactory;  
  12.   
  13. public class BookEbo implements BookEbi {  
  14.     BookDAO dao=BookDAOFactory.getBookDAO();  
  15.       
  16.     @Override  
  17.     public boolean create(BookModel book) {  
  18.         String uuid=UuidDAOFactory.getUuidDAO().getNextUuid(UuidModelConstance.BOOK);  
  19.         book.setUuid(uuid);  
  20.         return dao.create(book);  
  21.     }  
  22.   
  23.     @Override  
  24.     public boolean delete(String uuid) {  
  25.         return dao.delete(uuid);  
  26.     }  
  27.   
  28.     @Override  
  29.     public List<BookModel> getAll() {  
  30.         return dao.getAll();  
  31.     }  
  32.   
  33.     @Override  
  34.     public List<BookModel> getByCondition(BookQueryModel bqm) {  
  35.         return dao.getByCondition(bqm);  
  36.     }  
  37.   
  38.     @Override  
  39.     public BookModel getSingle(String uuid) {  
  40.         return dao.getSingle(uuid);  
  41.     }  
  42.   
  43.     @Override  
  44.     public boolean upDate(BookModel book) {  
  45.         return dao.upDate(book);  
  46.     }  
  47.   
  48.     @Override  
  49.     public BookModel getBookByName(String bookName) {  
  50.         BookQueryModel bqm=new BookQueryModel();  
  51.         bqm.setName(bookName);  
  52.         return getByCondition(bqm).get(0);  
  53.     }  
  54. }  
工厂类:

[java]  view plain  copy
 
  1. package cn.hncu.book.business.factory;  
  2.   
  3. import cn.hncu.book.business.ebi.BookEbi;  
  4. import cn.hncu.book.business.ebo.BookEbo;  
  5.   
  6. public class BookEbiFactory {  
  7.     public static BookEbi getBookEbi(){  
  8.         return new BookEbo();  
  9.     }  
  10. }  


值对象层:
图书模型:

[java]  view plain  copy
 
  1. package cn.hncu.book.vo;  
  2.   
  3. import java.io.Serializable;  
  4.   
  5. public class BookModel implements Serializable{  
  6.     private String uuid;  
  7.     private String name;  
  8.     private double inPrice;  
  9.     private double salePrice;  
  10.       
  11.     public String getUuid() {  
  12.         return uuid;  
  13.     }  
  14.     public void setUuid(String uuid) {  
  15.         this.uuid = uuid;  
  16.     }  
  17.     public String getName() {  
  18.         return name;  
  19.     }  
  20.     public void setName(String name) {  
  21.         this.name = name;  
  22.     }  
  23.     public double getInPrice() {  
  24.         return inPrice;  
  25.     }  
  26.     public void setInPrice(double inPrice) {  
  27.         this.inPrice = inPrice;  
  28.     }  
  29.     public double getSalePrice() {  
  30.         return salePrice;  
  31.     }  
  32.     public void setSalePrice(double salePrice) {  
  33.         this.salePrice = salePrice;  
  34.     }  
  35.       
  36.     @Override  
  37.     public int hashCode() {  
  38.         final int prime = 31;  
  39.         int result = 1;  
  40.         result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());  
  41.         return result;  
  42.     }  
  43.     @Override  
  44.     public boolean equals(Object obj) {  
  45.         if (this == obj)  
  46.             return true;  
  47.         if (obj == null)  
  48.             return false;  
  49.         if (getClass() != obj.getClass())  
  50.             return false;  
  51.         BookModel other = (BookModel) obj;  
  52.         if (uuid == null) {  
  53.             if (other.uuid != null)  
  54.                 return false;  
  55.         } else if (!uuid.equals(other.uuid))  
  56.             return false;  
  57.         return true;  
  58.     }  
  59.     @Override  
  60.     public String toString() {  
  61.         return uuid + ", " + name + ", 进价="  
  62.         + inPrice + ", 售价=" + salePrice;  
  63.     }  
  64. }  
图书查询模型:

[java]  view plain  copy
 
  1. package cn.hncu.book.vo;  
  2.   
  3. public class BookQueryModel extends BookModel {  
  4.     private double highInPrice;  
  5.     private double highSalePrice;  
  6.       
  7.     public double getHighInPrice() {  
  8.         return highInPrice;  
  9.     }  
  10.     public void setHighInPrice(double highInPrice) {  
  11.         this.highInPrice = highInPrice;  
  12.     }  
  13.     public double getHighSalePrice() {  
  14.         return highSalePrice;  
  15.     }  
  16.     public void setHighSalePrice(double highSalePrice) {  
  17.         this.highSalePrice = highSalePrice;  
  18.     }  
  19. }  

表现层:
图书清单:

[java]  view plain  copy
 
  1. /* 
  2.  * BookListPanel.java 
  3.  * 
  4.  * Created on __DATE__, __TIME__ 
  5.  */  
  6.   
  7. package cn.hncu.book.ui;  
  8.   
  9. import java.util.List;  
  10.   
  11. import javax.swing.JFrame;  
  12. import javax.swing.JOptionPane;  
  13.   
  14. import cn.hncu.book.business.ebi.BookEbi;  
  15. import cn.hncu.book.business.factory.BookEbiFactory;  
  16. import cn.hncu.book.vo.BookModel;  
  17.   
  18. /** 
  19.  * 
  20.  * @author  __USER__ 
  21.  */  
  22. public class BookListPanel extends javax.swing.JPanel {  
  23.     private JFrame mainFrame = null;  
  24.   
  25.     /** Creates new form BookListPanel */  
  26.     public BookListPanel(JFrame mainFrame) {  
  27.         this.mainFrame = mainFrame;  
  28.         this.setOpaque(false);  
  29.         initComponents();  
  30.         myInit();  
  31.     }  
  32.   
  33.     public BookListPanel(JFrame mainFrame, List<BookModel> list) {  
  34.         this.mainFrame = mainFrame;  
  35.         initComponents();  
  36.         bookList.setListData(list.toArray());  
  37.     }  
  38.   
  39.     private void myInit() {  
  40.         BookEbi ebi = BookEbiFactory.getBookEbi();  
  41.         List<BookModel> list = ebi.getAll();  
  42.         bookList.setListData(list.toArray());  
  43.   
  44.     }  
  45.   
  46.     /** This method is called from within the constructor to 
  47.      * initialize the form. 
  48.      * WARNING: Do NOT modify this code. The content of this method is 
  49.      * always regenerated by the Form Editor. 
  50.      */  
  51.     //GEN-BEGIN:initComponents  
  52.     // <editor-fold defaultstate="collapsed" desc="Generated Code">  
  53.     private void initComponents() {  
  54.   
  55.         jLabel1 = new javax.swing.JLabel();  
  56.         jScrollPane1 = new javax.swing.JScrollPane();  
  57.         bookList = new javax.swing.JList();  
  58.         queryBtn = new javax.swing.JButton();  
  59.         addBtn = new javax.swing.JButton();  
  60.         deleteBtn = new javax.swing.JButton();  
  61.         btnUpdate = new javax.swing.JButton();  
  62.   
  63.         setLayout(null);  
  64.   
  65.         jLabel1.setFont(new java.awt.Font("Microsoft YaHei UI"124));  
  66.         jLabel1.setText("\u56fe\u4e66\u5217\u8868");  
  67.         add(jLabel1);  
  68.         jLabel1.setBounds(3505015070);  
  69.   
  70.         bookList.setModel(new javax.swing.AbstractListModel() {  
  71.             String[] strings = { "" };  
  72.   
  73.             public int getSize() {  
  74.                 return strings.length;  
  75.             }  
  76.   
  77.             public Object getElementAt(int i) {  
  78.                 return strings[i];  
  79.             }  
  80.         });  
  81.         jScrollPane1.setViewportView(bookList);  
  82.   
  83.         add(jScrollPane1);  
  84.         jScrollPane1.setBounds(250120300170);  
  85.   
  86.         queryBtn.setText("\u67e5\u8be2");  
  87.         queryBtn.addActionListener(new java.awt.event.ActionListener() {  
  88.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  89.                 queryBtnActionPerformed(evt);  
  90.             }  
  91.         });  
  92.         add(queryBtn);  
  93.         queryBtn.setBounds(5403406329);  
  94.   
  95.         addBtn.setText("\u6dfb\u52a0");  
  96.         addBtn.addActionListener(new java.awt.event.ActionListener() {  
  97.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  98.                 addBtnActionPerformed(evt);  
  99.             }  
  100.         });  
  101.         add(addBtn);  
  102.         addBtn.setBounds(2003406329);  
  103.   
  104.         deleteBtn.setText("\u5220\u9664");  
  105.         deleteBtn.addActionListener(new java.awt.event.ActionListener() {  
  106.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  107.                 deleteBtnActionPerformed(evt);  
  108.             }  
  109.         });  
  110.         add(deleteBtn);  
  111.         deleteBtn.setBounds(3203406329);  
  112.   
  113.         btnUpdate.setText("\u4fee\u6539");  
  114.         btnUpdate.addActionListener(new java.awt.event.ActionListener() {  
  115.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  116.                 btnUpdateActionPerformed(evt);  
  117.             }  
  118.         });  
  119.         add(btnUpdate);  
  120.         btnUpdate.setBounds(4203406329);  
  121.     }// </editor-fold>  
  122.     //GEN-END:initComponents  
  123.   
  124.     private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {  
  125.         BookModel book = (BookModel) bookList.getSelectedValue();  
  126.         if (book == null) {  
  127.             JOptionPane.showMessageDialog(null"请选择要修改的用户!");  
  128.             return;  
  129.         }  
  130.         String uuid = book.getUuid();  
  131.         mainFrame.setContentPane(new BookUpDatePanel(mainFrame, uuid));  
  132.         mainFrame.validate();  
  133.     }  
  134.   
  135.     private void deleteBtnActionPerformed(java.awt.event.ActionEvent evt) {  
  136.         BookModel book = (BookModel) bookList.getSelectedValue();  
  137.         if (book == null) {  
  138.             JOptionPane.showMessageDialog(null"请选择要删除的用户!");  
  139.             return;  
  140.         }  
  141.         String uuid = book.getUuid();  
  142.         mainFrame.setContentPane(new BookDeletePanel(mainFrame, uuid));  
  143.         mainFrame.validate();  
  144.     }  
  145.   
  146.     private void addBtnActionPerformed(java.awt.event.ActionEvent evt) {  
  147.         mainFrame.setContentPane(new BookAddPanel(mainFrame));  
  148.         mainFrame.validate();  
  149.     }  
  150.   
  151.     private void queryBtnActionPerformed(java.awt.event.ActionEvent evt) {  
  152.         mainFrame.setContentPane(new BookQueryPanel(mainFrame));  
  153.         mainFrame.validate();  
  154.     }  
  155.   
  156.     //GEN-BEGIN:variables  
  157.     // Variables declaration - do not modify  
  158.     private javax.swing.JButton addBtn;  
  159.     private javax.swing.JList bookList;  
  160.     private javax.swing.JButton btnUpdate;  
  161.     private javax.swing.JButton deleteBtn;  
  162.     private javax.swing.JLabel jLabel1;  
  163.     private javax.swing.JScrollPane jScrollPane1;  
  164.     private javax.swing.JButton queryBtn;  
  165.     // End of variables declaration//GEN-END:variables  
  166.   
  167. }  
添加图书:

[java]  view plain  copy
 
  1. /* 
  2.  * BookAddPanel.java 
  3.  * 
  4.  * Created on __DATE__, __TIME__ 
  5.  */  
  6.   
  7. package cn.hncu.book.ui;  
  8.   
  9. import javax.swing.JFrame;  
  10. import javax.swing.JOptionPane;  
  11.   
  12. import cn.hncu.book.business.ebi.BookEbi;  
  13. import cn.hncu.book.business.factory.BookEbiFactory;  
  14. import cn.hncu.book.vo.BookModel;  
  15.   
  16. /** 
  17.  * 
  18.  * @author  __USER__ 
  19.  */  
  20. public class BookAddPanel extends javax.swing.JPanel {  
  21.     private JFrame mainFrame = null;  
  22.   
  23.     /** Creates new form BookAddPanel */  
  24.     public BookAddPanel(JFrame mainFrame) {  
  25.         this.setOpaque(false);  
  26.         this.mainFrame = mainFrame;  
  27.         initComponents();  
  28.     }  
  29.   
  30.     //GEN-BEGIN:initComponents  
  31.     // <editor-fold defaultstate="collapsed" desc="Generated Code">  
  32.     private void initComponents() {  
  33.   
  34.         jLabel1 = new javax.swing.JLabel();  
  35.         jLabelName = new javax.swing.JLabel();  
  36.         tfdName = new javax.swing.JTextField();  
  37.         btnAdd = new javax.swing.JButton();  
  38.         btnBack = new javax.swing.JButton();  
  39.         jLabelName1 = new javax.swing.JLabel();  
  40.         tfdSalePrice = new javax.swing.JTextField();  
  41.         jLabel5 = new javax.swing.JLabel();  
  42.         tfdInPrice = new javax.swing.JTextField();  
  43.   
  44.         setLayout(null);  
  45.   
  46.         jLabel1.setFont(new java.awt.Font("Microsoft YaHei UI"124));  
  47.         jLabel1.setText("\u6dfb\u52a0\u56fe\u4e66");  
  48.         add(jLabel1);  
  49.         jLabel1.setBounds(3503014070);  
  50.   
  51.         jLabelName.setText("\u4e66\u540d\uff1a");  
  52.         add(jLabelName);  
  53.         jLabelName.setBounds(1801107030);  
  54.         add(tfdName);  
  55.         tfdName.setBounds(25011010030);  
  56.   
  57.         btnAdd.setText("\u6dfb\u52a0");  
  58.         btnAdd.addActionListener(new java.awt.event.ActionListener() {  
  59.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  60.                 btnAddActionPerformed(evt);  
  61.             }  
  62.         });  
  63.         add(btnAdd);  
  64.         btnAdd.setBounds(2903406329);  
  65.   
  66.         btnBack.setText("\u8fd4\u56de");  
  67.         btnBack.addActionListener(new java.awt.event.ActionListener() {  
  68.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  69.                 btnBackActionPerformed(evt);  
  70.             }  
  71.         });  
  72.         add(btnBack);  
  73.         btnBack.setBounds(4403406329);  
  74.   
  75.         jLabelName1.setText("\u552e\u4ef7\uff1a");  
  76.         add(jLabelName1);  
  77.         jLabelName1.setBounds(4202107030);  
  78.         add(tfdSalePrice);  
  79.         tfdSalePrice.setBounds(49021010030);  
  80.   
  81.         jLabel5.setText("\u8fdb\u4ef7\uff1a");  
  82.         add(jLabel5);  
  83.         jLabel5.setBounds(1802105220);  
  84.         add(tfdInPrice);  
  85.         tfdInPrice.setBounds(25021010030);  
  86.     }// </editor-fold>  
  87.     //GEN-END:initComponents  
  88.   
  89.     private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {  
  90.         //收集参数  
  91.         //      String uuid = tfdUuid.getText();  
  92.         String name = tfdName.getText();  
  93.         double inPrice = Double.parseDouble(tfdInPrice.getText());  
  94.         double salePrice = Double.parseDouble(tfdSalePrice.getText());  
  95.   
  96.         //组织参数  
  97.         BookModel book = new BookModel();  
  98.         book.setName(name);  
  99.         //      book.setUuid(uuid);  
  100.         book.setInPrice(inPrice);  
  101.         book.setSalePrice(salePrice);  
  102.   
  103.         //调用逻辑层  
  104.         BookEbi ebi = BookEbiFactory.getBookEbi();  
  105.         if (ebi.create(book)) {  
  106.             mainFrame.setContentPane(new BookListPanel(mainFrame));  
  107.             mainFrame.validate();  
  108.         } else {  
  109.             JOptionPane.showMessageDialog(null"该用户已存在!");  
  110.         }  
  111.     }  
  112.   
  113.     private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {  
  114.         mainFrame.setContentPane(new BookListPanel(mainFrame));  
  115.         mainFrame.validate();  
  116.     }  
  117.   
  118.     //GEN-BEGIN:variables  
  119.     // Variables declaration - do not modify  
  120.     private javax.swing.JButton btnAdd;  
  121.     private javax.swing.JButton btnBack;  
  122.     private javax.swing.JLabel jLabel1;  
  123.     private javax.swing.JLabel jLabel5;  
  124.     private javax.swing.JLabel jLabelName;  
  125.     private javax.swing.JLabel jLabelName1;  
  126.     private javax.swing.JTextField tfdInPrice;  
  127.     private javax.swing.JTextField tfdName;  
  128.     private javax.swing.JTextField tfdSalePrice;  
  129.     // End of variables declaration//GEN-END:variables  
  130.   
  131. }  
删除图书:

[java]  view plain  copy
 
  1. /* 
  2.  * BookDeletePanel.java 
  3.  * 
  4.  * Created on __DATE__, __TIME__ 
  5.  */  
  6.   
  7. package cn.hncu.book.ui;  
  8.   
  9. import javax.swing.JFrame;  
  10. import javax.swing.JOptionPane;  
  11.   
  12. import cn.hncu.book.business.ebi.BookEbi;  
  13. import cn.hncu.book.business.factory.BookEbiFactory;  
  14. import cn.hncu.book.vo.BookModel;  
  15.   
  16. /** 
  17.  * 
  18.  * @author  __USER__ 
  19.  */  
  20. public class BookDeletePanel extends javax.swing.JPanel {  
  21.     private JFrame mainFrame=null;  
  22.     private String uuid=null;  
  23.     /** Creates new form BookDeletePanel */  
  24.     public BookDeletePanel(JFrame mainFrame,String uuid) {  
  25.         this.mainFrame=mainFrame;  
  26.         this.setOpaque(false);  
  27.         this.uuid=uuid;  
  28.         initComponents();  
  29.         myInit();  
  30.     }  
  31.   
  32.     private void myInit() {  
  33.         BookModel book=BookEbiFactory.getBookEbi().getSingle(uuid);  
  34.         tfdUuid.setText(book.getUuid());  
  35.         tfdUuid.setEditable(false);  
  36.           
  37.         tfdName.setText(book.getName());  
  38.         tfdName.setEditable(false);  
  39.           
  40.         tfdInPrice.setText(""+book.getInPrice());  
  41.         tfdInPrice.setEditable(false);  
  42.           
  43.         tfdSalePrice.setText(""+book.getSalePrice());  
  44.         tfdSalePrice.setEditable(false);  
  45.           
  46.     }  
  47.   
  48.     /** This method is called from within the constructor to 
  49.      * initialize the form. 
  50.      * WARNING: Do NOT modify this code. The content of this method is 
  51.      * always regenerated by the Form Editor. 
  52.      */  
  53.     //GEN-BEGIN:initComponents  
  54.     // <editor-fold defaultstate="collapsed" desc="Generated Code">  
  55.     private void initComponents() {  
  56.   
  57.         jLabel1 = new javax.swing.JLabel();  
  58.         jLabelName = new javax.swing.JLabel();  
  59.         tfdName = new javax.swing.JTextField();  
  60.         btnDelete = new javax.swing.JButton();  
  61.         btnBack = new javax.swing.JButton();  
  62.         jLabel4 = new javax.swing.JLabel();  
  63.         tfdUuid = new javax.swing.JTextField();  
  64.         jLabelName1 = new javax.swing.JLabel();  
  65.         tfdSalePrice = new javax.swing.JTextField();  
  66.         jLabel5 = new javax.swing.JLabel();  
  67.         tfdInPrice = new javax.swing.JTextField();  
  68.   
  69.         setLayout(null);  
  70.   
  71.         jLabel1.setFont(new java.awt.Font("Microsoft YaHei UI"124));  
  72.         jLabel1.setText("\u5220\u9664\u56fe\u4e66");  
  73.         add(jLabel1);  
  74.         jLabel1.setBounds(2903014070);  
  75.   
  76.         jLabelName.setText("\u4e66\u540d\uff1a");  
  77.         add(jLabelName);  
  78.         jLabelName.setBounds(3601107030);  
  79.         add(tfdName);  
  80.         tfdName.setBounds(43011010030);  
  81.   
  82.         btnDelete.setText("\u5220\u9664");  
  83.         btnDelete.addActionListener(new java.awt.event.ActionListener() {  
  84.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  85.                 btnDeleteActionPerformed(evt);  
  86.             }  
  87.         });  
  88.         add(btnDelete);  
  89.         btnDelete.setBounds(2303406329);  
  90.   
  91.         btnBack.setText("\u8fd4\u56de");  
  92.         btnBack.addActionListener(new java.awt.event.ActionListener() {  
  93.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  94.                 btnBackActionPerformed(evt);  
  95.             }  
  96.         });  
  97.         add(btnBack);  
  98.         btnBack.setBounds(3803406329);  
  99.   
  100.         jLabel4.setText("uuid\uff1a");  
  101.         add(jLabel4);  
  102.         jLabel4.setBounds(1201105220);  
  103.         add(tfdUuid);  
  104.         tfdUuid.setBounds(19011010030);  
  105.   
  106.         jLabelName1.setText("\u552e\u4ef7\uff1a");  
  107.         add(jLabelName1);  
  108.         jLabelName1.setBounds(3602107030);  
  109.         add(tfdSalePrice);  
  110.         tfdSalePrice.setBounds(43021010030);  
  111.   
  112.         jLabel5.setText("\u8fdb\u4ef7\uff1a");  
  113.         add(jLabel5);  
  114.         jLabel5.setBounds(1202105220);  
  115.         add(tfdInPrice);  
  116.         tfdInPrice.setBounds(19021010030);  
  117.     }// </editor-fold>  
  118.     //GEN-END:initComponents  
  119.   
  120.     private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {  
  121.         mainFrame.setContentPane(new BookListPanel(mainFrame));  
  122.         mainFrame.validate();  
  123.     }  
  124.   
  125.     private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {  
  126.   
  127.         boolean flag = BookEbiFactory.getBookEbi().delete(uuid);  
  128.         if (flag) {  
  129.             mainFrame.setContentPane(new BookListPanel(mainFrame));  
  130.             mainFrame.validate();  
  131.         } else {  
  132.             JOptionPane.showMessageDialog(null"该用户已经不存在!");  
  133.         }  
  134.     }  
  135.   
  136.     //GEN-BEGIN:variables  
  137.     // Variables declaration - do not modify  
  138.     private javax.swing.JButton btnBack;  
  139.     private javax.swing.JButton btnDelete;  
  140.     private javax.swing.JLabel jLabel1;  
  141.     private javax.swing.JLabel jLabel4;  
  142.     private javax.swing.JLabel jLabel5;  
  143.     private javax.swing.JLabel jLabelName;  
  144.     private javax.swing.JLabel jLabelName1;  
  145.     private javax.swing.JTextField tfdInPrice;  
  146.     private javax.swing.JTextField tfdName;  
  147.     private javax.swing.JTextField tfdSalePrice;  
  148.     private javax.swing.JTextField tfdUuid;  
  149.     // End of variables declaration//GEN-END:variables  
  150.   
  151. }  
修改图书:

[java]  view plain  copy
 
  1. /* 
  2.  * BookUpDatePanel.java 
  3.  * 
  4.  * Created on __DATE__, __TIME__ 
  5.  */  
  6.   
  7. package cn.hncu.book.ui;  
  8.   
  9. import java.awt.event.ActionEvent;  
  10.   
  11. import javax.swing.JFrame;  
  12. import javax.swing.JOptionPane;  
  13.   
  14. import cn.hncu.book.business.ebi.BookEbi;  
  15. import cn.hncu.book.business.factory.BookEbiFactory;  
  16. import cn.hncu.book.vo.BookModel;  
  17.   
  18. /** 
  19.  * 
  20.  * @author  __USER__ 
  21.  */  
  22. public class BookUpDatePanel extends javax.swing.JPanel {  
  23.     private JFrame mainFrame = null;  
  24.     private String uuid = null;  
  25.   
  26.     /** Creates new form BookUpDatePanel */  
  27.     public BookUpDatePanel(JFrame mainFrame, String uuid) {  
  28.         this.mainFrame = mainFrame;  
  29.         this.uuid = uuid;  
  30.         this.setOpaque(false);  
  31.         initComponents();  
  32.         myInit();  
  33.     }  
  34.   
  35.     private void myInit() {  
  36.         BookModel book = BookEbiFactory.getBookEbi().getSingle(uuid);  
  37.         tfdUuid.setText(uuid);  
  38.         tfdUuid.setEditable(false);  
  39.         tfdName.setText(book.getName());  
  40.         tfdInPrice.setText("" + book.getInPrice());  
  41.         tfdSalePrice.setText("" + book.getSalePrice());  
  42.   
  43.     }  
  44.   
  45.     /** This method is called from within the constructor to 
  46.      * initialize the form. 
  47.      * WARNING: Do NOT modify this code. The content of this method is 
  48.      * always regenerated by the Form Editor. 
  49.      */  
  50.     //GEN-BEGIN:initComponents  
  51.     // <editor-fold defaultstate="collapsed" desc="Generated Code">  
  52.     private void initComponents() {  
  53.   
  54.         jLabel1 = new javax.swing.JLabel();  
  55.         jLabelName = new javax.swing.JLabel();  
  56.         tfdName = new javax.swing.JTextField();  
  57.         btnUpDate = new javax.swing.JButton();  
  58.         btnBack = new javax.swing.JButton();  
  59.         jLabel4 = new javax.swing.JLabel();  
  60.         tfdUuid = new javax.swing.JTextField();  
  61.         jLabelName1 = new javax.swing.JLabel();  
  62.         tfdSalePrice = new javax.swing.JTextField();  
  63.         jLabel5 = new javax.swing.JLabel();  
  64.         tfdInPrice = new javax.swing.JTextField();  
  65.   
  66.         setLayout(null);  
  67.   
  68.         jLabel1.setFont(new java.awt.Font("Microsoft YaHei UI"124));  
  69.         jLabel1.setText("\u4fee\u6539\u56fe\u4e66");  
  70.         add(jLabel1);  
  71.         jLabel1.setBounds(2903014070);  
  72.   
  73.         jLabelName.setText("\u4e66\u540d\uff1a");  
  74.         add(jLabelName);  
  75.         jLabelName.setBounds(3601107030);  
  76.         add(tfdName);  
  77.         tfdName.setBounds(43011010030);  
  78.   
  79.         btnUpDate.setText("\u4fee\u6539");  
  80.         btnUpDate.addActionListener(new java.awt.event.ActionListener() {  
  81.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  82.                 btnUpDateActionPerformed(evt);  
  83.             }  
  84.         });  
  85.         add(btnUpDate);  
  86.         btnUpDate.setBounds(2303406329);  
  87.   
  88.         btnBack.setText("\u8fd4\u56de");  
  89.         btnBack.addActionListener(new java.awt.event.ActionListener() {  
  90.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  91.                 btnBackActionPerformed(evt);  
  92.             }  
  93.         });  
  94.         add(btnBack);  
  95.         btnBack.setBounds(3803406329);  
  96.   
  97.         jLabel4.setText("uuid\uff1a");  
  98.         add(jLabel4);  
  99.         jLabel4.setBounds(1201105220);  
  100.         add(tfdUuid);  
  101.         tfdUuid.setBounds(19011010030);  
  102.   
  103.         jLabelName1.setText("\u552e\u4ef7\uff1a");  
  104.         add(jLabelName1);  
  105.         jLabelName1.setBounds(3602107030);  
  106.         add(tfdSalePrice);  
  107.         tfdSalePrice.setBounds(43021010030);  
  108.   
  109.         jLabel5.setText("\u8fdb\u4ef7\uff1a");  
  110.         add(jLabel5);  
  111.         jLabel5.setBounds(1202105220);  
  112.         add(tfdInPrice);  
  113.         tfdInPrice.setBounds(19021010030);  
  114.     }// </editor-fold>  
  115.     //GEN-END:initComponents  
  116.   
  117.     protected void btnUpDateActionPerformed(ActionEvent evt) {  
  118.         //收集参数  
  119.         String name = tfdName.getText();  
  120.         double inPrice = Double.parseDouble(tfdInPrice.getText());  
  121.         double salePrice = Double.parseDouble(tfdSalePrice.getText());  
  122.   
  123.         //组织参数  
  124.         BookModel book = new BookModel();  
  125.         book.setUuid(uuid);  
  126.         book.setName(name);  
  127.         book.setInPrice(inPrice);  
  128.         book.setSalePrice(salePrice);  
  129.   
  130.         //调用逻辑层  
  131.         BookEbi ebi = BookEbiFactory.getBookEbi();  
  132.         if (ebi.upDate(book)) {  
  133.             mainFrame.setContentPane(new BookListPanel(mainFrame));  
  134.             mainFrame.validate();  
  135.         } else {  
  136.             JOptionPane.showMessageDialog(null"该用户已经不存在!");  
  137.         }  
  138.     }  
  139.   
  140.     private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {  
  141.         mainFrame.setContentPane(new BookListPanel(mainFrame));  
  142.         mainFrame.validate();  
  143.     }  
  144.   
  145.     //GEN-BEGIN:variables  
  146.     // Variables declaration - do not modify  
  147.     private javax.swing.JButton btnBack;  
  148.     private javax.swing.JButton btnUpDate;  
  149.     private javax.swing.JLabel jLabel1;  
  150.     private javax.swing.JLabel jLabel4;  
  151.     private javax.swing.JLabel jLabel5;  
  152.     private javax.swing.JLabel jLabelName;  
  153.     private javax.swing.JLabel jLabelName1;  
  154.     private javax.swing.JTextField tfdInPrice;  
  155.     private javax.swing.JTextField tfdName;  
  156.     private javax.swing.JTextField tfdSalePrice;  
  157.     private javax.swing.JTextField tfdUuid;  
  158.     // End of variables declaration//GEN-END:variables  
  159.   
  160. }  
查询图书:

[java]  view plain  copy
 
  1. /* 
  2.  * BookQueryPanel.java 
  3.  * 
  4.  * Created on __DATE__, __TIME__ 
  5.  */  
  6.   
  7. package cn.hncu.book.ui;  
  8.   
  9. import java.util.List;  
  10.   
  11. import javax.swing.JFrame;  
  12. import javax.swing.JOptionPane;  
  13.   
  14. import cn.hncu.book.business.ebi.BookEbi;  
  15. import cn.hncu.book.business.factory.BookEbiFactory;  
  16. import cn.hncu.book.vo.BookModel;  
  17. import cn.hncu.book.vo.BookQueryModel;  
  18.   
  19. /** 
  20.  * 
  21.  * @author  __USER__ 
  22.  */  
  23. public class BookQueryPanel extends javax.swing.JPanel {  
  24.     private JFrame mainFrame = null;  
  25.   
  26.     /** Creates new form BookQueryPanel */  
  27.     public BookQueryPanel(JFrame mainFrame) {  
  28.         this.mainFrame = mainFrame;  
  29.         this.setOpaque(false);  
  30.         initComponents();  
  31.     }  
  32.   
  33.     /** This method is called from within the constructor to 
  34.      * initialize the form. 
  35.      * WARNING: Do NOT modify this code. The content of this method is 
  36.      * always regenerated by the Form Editor. 
  37.      */  
  38.     //GEN-BEGIN:initComponents  
  39.     // <editor-fold defaultstate="collapsed" desc="Generated Code">  
  40.     private void initComponents() {  
  41.   
  42.         jLabel1 = new javax.swing.JLabel();  
  43.         jLabelName = new javax.swing.JLabel();  
  44.         tfdHighPrice = new javax.swing.JTextField();  
  45.         btnQuery = new javax.swing.JButton();  
  46.         btnBack = new javax.swing.JButton();  
  47.         jLabel4 = new javax.swing.JLabel();  
  48.         tfdLowPrice = new javax.swing.JTextField();  
  49.         jLabelName1 = new javax.swing.JLabel();  
  50.         tfdName = new javax.swing.JTextField();  
  51.         jLabel5 = new javax.swing.JLabel();  
  52.         tfdUuid = new javax.swing.JTextField();  
  53.         jLabel2 = new javax.swing.JLabel();  
  54.         jLabel3 = new javax.swing.JLabel();  
  55.         tfdHighSalePrice = new javax.swing.JTextField();  
  56.         tfdLowSalePrice = new javax.swing.JTextField();  
  57.   
  58.         setLayout(null);  
  59.   
  60.         jLabel1.setFont(new java.awt.Font("Microsoft YaHei UI"124));  
  61.         jLabel1.setText("\u67e5\u8be2\u56fe\u4e66");  
  62.         add(jLabel1);  
  63.         jLabel1.setBounds(2801014070);  
  64.   
  65.         jLabelName.setText("\u6700\u9ad8\u8fdb\u4ef7\uff1a");  
  66.         add(jLabelName);  
  67.         jLabelName.setBounds(32017010030);  
  68.         add(tfdHighPrice);  
  69.         tfdHighPrice.setBounds(42017010030);  
  70.   
  71.         btnQuery.setText("\u67e5\u8be2");  
  72.         btnQuery.addActionListener(new java.awt.event.ActionListener() {  
  73.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  74.                 btnQueryActionPerformed(evt);  
  75.             }  
  76.         });  
  77.         add(btnQuery);  
  78.         btnQuery.setBounds(2403606330);  
  79.   
  80.         btnBack.setText("\u8fd4\u56de");  
  81.         btnBack.addActionListener(new java.awt.event.ActionListener() {  
  82.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  83.                 btnBackActionPerformed(evt);  
  84.             }  
  85.         });  
  86.         add(btnBack);  
  87.         btnBack.setBounds(3403606330);  
  88.   
  89.         jLabel4.setText("\u6700\u4f4e\u8fdb\u4ef7\uff1a");  
  90.         add(jLabel4);  
  91.         jLabel4.setBounds(901708020);  
  92.         add(tfdLowPrice);  
  93.         tfdLowPrice.setBounds(19017010030);  
  94.   
  95.         jLabelName1.setText("\u4e66\u540d\uff1a");  
  96.         add(jLabelName1);  
  97.         jLabelName1.setBounds(3501007030);  
  98.         add(tfdName);  
  99.         tfdName.setBounds(42010010030);  
  100.   
  101.         jLabel5.setText("uuid\uff1a");  
  102.         add(jLabel5);  
  103.         jLabel5.setBounds(1201005220);  
  104.         add(tfdUuid);  
  105.         tfdUuid.setBounds(19010010030);  
  106.   
  107.         jLabel2.setText("\u6700\u9ad8\u552e\u4ef7\uff1a");  
  108.         add(jLabel2);  
  109.         jLabel2.setBounds(32025010040);  
  110.   
  111.         jLabel3.setText("\u6700\u4f4e\u552e\u4ef7\uff1a");  
  112.         add(jLabel3);  
  113.         jLabel3.setBounds(902509040);  
  114.         add(tfdHighSalePrice);  
  115.         tfdHighSalePrice.setBounds(42026010030);  
  116.         add(tfdLowSalePrice);  
  117.         tfdLowSalePrice.setBounds(19026010030);  
  118.     }// </editor-fold>  
  119.     //GEN-END:initComponents  
  120.   
  121.     private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {  
  122.         mainFrame.setContentPane(new BookListPanel(mainFrame));  
  123.         mainFrame.validate();  
  124.     }  
  125.   
  126.     private void btnQueryActionPerformed(java.awt.event.ActionEvent evt) {  
  127.         //收集参数  
  128.         String uuid = tfdUuid.getText();  
  129.         String name = tfdName.getText();  
  130.   
  131.         double inPrice = 0;  
  132.         if (tfdLowPrice.getText() != null  
  133.                 && tfdLowPrice.getText().trim().length() > 0) {  
  134.             try {  
  135.                 inPrice = Double.parseDouble(tfdLowPrice.getText());  
  136.             } catch (NumberFormatException e) {  
  137.                 JOptionPane.showMessageDialog(null"最低进价格式输入错误");  
  138.                 return;  
  139.             }  
  140.         }  
  141.   
  142.         double highInPrice = 0;  
  143.         if (tfdHighPrice.getText() != null  
  144.                 && tfdHighPrice.getText().trim().length() > 0) {  
  145.             try {  
  146.                 highInPrice = Double.parseDouble(tfdHighPrice.getText());  
  147.             } catch (NumberFormatException e) {  
  148.                 JOptionPane.showMessageDialog(null"最高进价格式输入错误");  
  149.                 return;  
  150.             }  
  151.         }  
  152.   
  153.         double salePrice = 0;  
  154.         if (tfdLowSalePrice.getText() != null  
  155.                 && tfdLowSalePrice.getText().trim().length() > 0) {  
  156.             try {  
  157.                 salePrice = Double.parseDouble(tfdLowSalePrice.getText());  
  158.             } catch (NumberFormatException e) {  
  159.                 JOptionPane.showMessageDialog(null"最低售价格式输入错误");  
  160.                 return;  
  161.             }  
  162.         }  
  163.   
  164.         double highSalePrice = 0;  
  165.         if (tfdHighSalePrice.getText() != null  
  166.                 && tfdHighSalePrice.getText().trim().length() > 0) {  
  167.             try {  
  168.                 highSalePrice = Double.parseDouble(tfdHighSalePrice.getText());  
  169.             } catch (NumberFormatException e) {  
  170.                 JOptionPane.showMessageDialog(null"最高售价格式输入错误");  
  171.                 return;  
  172.             }  
  173.         }  
  174.   
  175.         //组织参数  
  176.         BookQueryModel bqm = new BookQueryModel();  
  177.         bqm.setName(name);  
  178.         bqm.setUuid(uuid);  
  179.         bqm.setInPrice(inPrice);  
  180.         bqm.setHighInPrice(highInPrice);  
  181.         bqm.setSalePrice(salePrice);  
  182.         bqm.setHighSalePrice(highSalePrice);  
  183.   
  184.         //调用逻辑层  
  185.         BookEbi ebi = BookEbiFactory.getBookEbi();  
  186.         List<BookModel> list = ebi.getByCondition(bqm);  
  187.         mainFrame.setContentPane(new BookListPanel(mainFrame, list));  
  188.         mainFrame.validate();  
  189.     }  
  190.   
  191.     //GEN-BEGIN:variables  
  192.     // Variables declaration - do not modify  
  193.     private javax.swing.JButton btnBack;  
  194.     private javax.swing.JButton btnQuery;  
  195.     private javax.swing.JLabel jLabel1;  
  196.     private javax.swing.JLabel jLabel2;  
  197.     private javax.swing.JLabel jLabel3;  
  198.     private javax.swing.JLabel jLabel4;  
  199.     private javax.swing.JLabel jLabel5;  
  200.     private javax.swing.JLabel jLabelName;  
  201.     private javax.swing.JLabel jLabelName1;  
  202.     private javax.swing.JTextField tfdHighPrice;  
  203.     private javax.swing.JTextField tfdHighSalePrice;  
  204.     private javax.swing.JTextField tfdLowPrice;  
  205.     private javax.swing.JTextField tfdLowSalePrice;  
  206.     private javax.swing.JTextField tfdName;  
  207.     private javax.swing.JTextField tfdUuid;  
  208.     // End of variables declaration//GEN-END:variables  
  209.   
  210. }


你可能感兴趣的:(java,设计模式,设计思想,面向接口编程,书店系统)