书店管理系统
书店管理系统可以说是设计模式及设计思想的一个比较经典的例子。
本系列将分为多个部分讲述此输电管理系统。
书店管理系统将分为:用户、图书、进货、销售和库存五个模块,另外还有公共包、工具包和登录包,另外还有一个框架。
对于分层设计,都是表现层可以调用逻辑层,逻辑层调用数据层,数据层调用工具和公共包,方向不可打乱,必须严格按照这种模式。
本篇将做进货模块。
注:本篇需要使用到的框架在本系列二的用户模块:
链接:http://blog.csdn.net/x121850182/article/details/51362269
和前面的模块相同的,进货模块分成了数据层、逻辑层、表现层和值对象层,但数据层要多出一个进货明细。
数据层:
接口:
InMainDAO
package cn.hncu.in.dao.dao; import java.util.List; import cn.hncu.in.vo.InMainModel; import cn.hncu.in.vo.InMainQueryModel; public interface InMainDAO { public boolean create(InMainModel inMain); public boolean delete(String uuid); public boolean upDate(InMainModel inMain); public InMainModel getSingle(String uuid); public List<InMainModel> getAll(); public List<InMainModel> getByCondition(InMainQueryModel imqm); }InDetailDAO
package cn.hncu.in.dao.dao; import java.util.List; import cn.hncu.in.vo.InDetailModel; import cn.hncu.in.vo.InDetailQueryModel; public interface InDetailDAO { public boolean create(InDetailModel inDetail); public boolean delete(String uuid); public boolean upDate(InDetailModel inDetail); public InDetailModel getSingle(String uuid); public List<InDetailModel> getAll(); public List<InDetailModel> getByCondition(InDetailQueryModel idqm); }实现类:
InMainDAOImpl
package cn.hncu.in.dao.impl; import java.util.ArrayList; import java.util.List; import cn.hncu.in.dao.dao.InMainDAO; import cn.hncu.in.vo.InMainModel; import cn.hncu.in.vo.InMainQueryModel; import cn.hncu.utils.FileIo; public class InMainDAOImpl implements InMainDAO { private final String FILE_NAME="InMain.txt"; @Override public boolean create(InMainModel inMain) { List<InMainModel> list=FileIo.read(FILE_NAME); for (InMainModel model:list){ if (model.getUuid().equals(inMain.getUuid())){ return false; } } list.add(inMain); FileIo.write(list, FILE_NAME); return true; } @Override public boolean delete(String uuid) { List<InMainModel> list=FileIo.read(FILE_NAME); for (InMainModel model:list){ if (model.getUuid().equals(uuid)){ list.remove(model); FileIo.write(list, FILE_NAME); return true; } } return false; } @Override public List<InMainModel> getAll() { List<InMainModel> list=FileIo.read(FILE_NAME); return list; } @Override public List<InMainModel> getByCondition(InMainQueryModel imqm) { List<InMainModel> list=getAll(); List<InMainModel> result=new ArrayList<InMainModel>(); for (InMainModel inMain:list){ if (imqm.getUuid()!=null&&imqm.getUuid().trim().length()>0){ if (!imqm.getUuid().equals(inMain.getUuid())){ continue; } } if (imqm.getInUserId()!=null&&imqm.getInUserId().trim().length()>0){ if (!imqm.getInUserId().equals(inMain.getInUserId())){ continue; } } if (imqm.getInDate()>0){ if (imqm.getInDate()>inMain.getInDate()){ continue; } } if (imqm.getInDate2()>0){ if (imqm.getInDate2()<inMain.getInDate()){ continue; } } result.add(inMain); } return result; } @Override public InMainModel getSingle(String uuid) { List<InMainModel> list=FileIo.read(FILE_NAME); for (InMainModel model:list){ if (model.getUuid().equals(uuid)){ return model; } } return null; } @Override public boolean upDate(InMainModel inMain) { List<InMainModel> list=FileIo.read(FILE_NAME); for (int i=0;i<list.size();i++){ InMainModel model=list.get(i); if (model.getUuid().equals(inMain.getUuid())){ list.set(i, inMain); return true; } } return false; } }InDetailDAOImpl
package cn.hncu.in.dao.impl; import java.util.ArrayList; import java.util.List; import cn.hncu.in.dao.dao.InDetailDAO; import cn.hncu.in.vo.InDetailModel; import cn.hncu.in.vo.InDetailQueryModel; import cn.hncu.in.vo.InMainModel; import cn.hncu.utils.FileIo; public class InDetailDAOImpl implements InDetailDAO { private final String FILE_NAME="InDetail.txt"; @Override public boolean create(InDetailModel inDetail) { List<InDetailModel> list=FileIo.read(FILE_NAME); for (InDetailModel model:list){ if (model.getUuid().equals(inDetail.getUuid())){ return false; } } list.add(inDetail); FileIo.write(list, FILE_NAME); return true; } @Override public boolean delete(String uuid) { List<InDetailModel> list=FileIo.read(FILE_NAME); for (InDetailModel model:list){ if (model.getUuid().equals(uuid)){ list.remove(model); FileIo.write(list, FILE_NAME); return true; } } return false; } @Override public List<InDetailModel> getAll() { List<InDetailModel> list=FileIo.read(FILE_NAME); return list; } @Override public List<InDetailModel> getByCondition(InDetailQueryModel idqm) { List<InDetailModel> list=getAll(); List<InDetailModel> results=new ArrayList<InDetailModel>(); for (InDetailModel model:list){ if (idqm.getUuid()!=null&&idqm.getUuid().trim().length()>0){ if (!model.getUuid().equals(idqm.getUuid())){ continue; } } if (idqm.getInUuid()!=null&&idqm.getInUuid().trim().length()>0){ if (!model.getInUuid().equals(idqm.getInUuid())){ continue; } } if (idqm.getBookUuid()!=null&&idqm.getBookUuid().trim().length()>0){ if (!model.getBookUuid().equals(idqm.getBookUuid())){ continue; } } if (idqm.getSumNum()>0){ if (model.getSumNum()<idqm.getSumNum()){ continue; } } if (idqm.getSumNum2()>0){ if (model.getSumNum()>idqm.getSumNum2()){ continue; } } if (idqm.getSumMoney()>0){ if (model.getSumMoney()<idqm.getSumMoney()){ continue; } } if (idqm.getSumMoney2()>0){ if (model.getSumMoney()>idqm.getSumMoney2()){ continue; } } results.add(model); } return results; } @Override public InDetailModel getSingle(String uuid) { List<InDetailModel> list=FileIo.read(FILE_NAME); for (InDetailModel model:list){ if (model.getUuid().equals(uuid)){ return model; } } return null; } @Override public boolean upDate(InDetailModel inDetail) { List<InDetailModel> list=FileIo.read(FILE_NAME); for (int i=0;i<list.size();i++){ InDetailModel model=list.get(i); if (model.getUuid().equals(inDetail.getUuid())){ list.set(i, inDetail); return true; } } return false; } }工厂类:
InMainDAOFactory
package cn.hncu.in.dao.factory; import cn.hncu.in.dao.dao.InMainDAO; import cn.hncu.in.dao.impl.InMainDAOImpl; public class InMainDAOFactory { public static InMainDAO getInMainDAO(){ return new InMainDAOImpl(); } }InDetailDAOFactory
package cn.hncu.in.dao.factory; import cn.hncu.in.dao.dao.InDetailDAO; import cn.hncu.in.dao.impl.InDetailDAOImpl; public class InDetailDAOFactory { public static InDetailDAO getInDetailDAO(){ return new InDetailDAOImpl(); } }
接口:
package cn.hncu.in.business.ebi; import java.util.List; import java.util.Map; import cn.hncu.in.vo.InDetailModel; import cn.hncu.in.vo.InDetailQueryModel; import cn.hncu.in.vo.InMainModel; import cn.hncu.in.vo.InMainQueryModel; public interface InMainEbi { public boolean create(InMainModel inMain,List<InDetailModel> details); public Map<InMainModel, List<InDetailModel>> getAll(); public Map<InMainModel, List<InDetailModel>> getByCondition(InMainQueryModel imqm,InDetailQueryModel idqm); }实现类:
package cn.hncu.in.business.ebo; import java.util.List; import java.util.Map; import java.util.TreeMap; import cn.hncu.book.business.ebi.BookEbi; import cn.hncu.book.business.factory.BookEbiFactory; import cn.hncu.common.UuidModelConstance; import cn.hncu.common.uuid.dao.dao.UuidDAO; import cn.hncu.common.uuid.dao.factory.UuidDAOFactory; import cn.hncu.in.business.ebi.InMainEbi; import cn.hncu.in.dao.dao.InDetailDAO; import cn.hncu.in.dao.dao.InMainDAO; import cn.hncu.in.dao.factory.InDetailDAOFactory; import cn.hncu.in.dao.factory.InMainDAOFactory; import cn.hncu.in.vo.InDetailModel; import cn.hncu.in.vo.InDetailQueryModel; import cn.hncu.in.vo.InMainModel; import cn.hncu.in.vo.InMainQueryModel; import cn.hncu.stock.dao.dao.StockDAO; import cn.hncu.stock.dao.factory.StockDAOFactory; import cn.hncu.stock.vo.StockModel; import cn.hncu.stock.vo.StockQueryModel; public class InMainEbo implements InMainEbi { InMainDAO inMainDAO=InMainDAOFactory.getInMainDAO(); InDetailDAO inDetailDAO=InDetailDAOFactory.getInDetailDAO(); UuidDAO uuidDAO=UuidDAOFactory.getUuidDAO(); BookEbi bookEbi=BookEbiFactory.getBookEbi(); @Override public boolean create(InMainModel inMain, List<InDetailModel> details) { //////////1存储inMain信息/////////// //补全inMain中的数据 //需要:inUuid,inDate,inUserUuid 已组织:inUserUuid //还缺(需补):inUuid,inDate String inUuid=uuidDAO.getNextUuid(UuidModelConstance.IN_MAIN); inMain.setUuid(inUuid); inMain.setInDate(System.currentTimeMillis()); inMainDAO.create(inMain); //////////2存储inDetail信息/////////// for (InDetailModel inDetail:details){ //补全每一个inDetail中的数据 //需要:inDetailUuid,inMainUuid,bookUuid,sumNum,sumMoney 已组织:bookUuid,sumNum //还缺(需补):inDetailUuid,inMainUuid,sumMoney inDetail.setUuid(uuidDAO.getNextUuid(UuidModelConstance.IN_DETAIL)); inDetail.setInUuid(inUuid); double sumMoney=inDetail.getSumNum()*bookEbi.getSingle(inDetail.getBookUuid()).getInPrice(); inDetail.setSumMoney(sumMoney); inDetailDAO.create(inDetail); putIntoStock(inDetail.getBookUuid(), inDetail.getSumNum()); } return true; } public void putIntoStock(String bookUuid,int sumNum){ StockDAO stockDAO=StockDAOFactory.getStockDAO(); //查询库存,看看是否已经存在该bookUuid所对应的书,如果没有则库存数据为sumNum,否则为在原有基础上再加上sumNum StockQueryModel sqm=new StockQueryModel(); sqm.setBookUuid(bookUuid); List<StockModel> list = stockDAO.getByCondition(sqm); if (list==null||list.size()==0){ StockModel stock=new StockModel(); String uuid=UuidDAOFactory.getUuidDAO().getNextUuid(UuidModelConstance.STOCK); stock.setUuid(uuid); stock.setBookName(BookEbiFactory.getBookEbi().getSingle(bookUuid).getName()); stock.setBookUuid(bookUuid); stock.setSumNum(sumNum); stockDAO.create(stock); }else {//库存中已经存在该图书对应的库存记录 StockModel stock=list.get(0); stock.setSumNum(stock.getSumNum()+sumNum); stockDAO.upDate(stock); } } @Override public Map<InMainModel, List<InDetailModel>> getAll() { Map<InMainModel, List<InDetailModel>> map=new TreeMap<InMainModel, List<InDetailModel>>(); List<InMainModel> inMains=inMainDAO.getAll(); for (InMainModel inMain:inMains){ InDetailQueryModel idqm=new InDetailQueryModel(); String inUuid=inMain.getUuid(); idqm.setInUuid(inUuid); List<InDetailModel> details=inDetailDAO.getByCondition(idqm); map.put(inMain, details); } return map; } @Override public Map<InMainModel, List<InDetailModel>> getByCondition( InMainQueryModel imqm, InDetailQueryModel idqm) { Map<InMainModel, List<InDetailModel>> map=new TreeMap<InMainModel, List<InDetailModel>>(); List<InMainModel> inMains=InMainDAOFactory.getInMainDAO().getByCondition(imqm); for (InMainModel inMain:inMains){ idqm.setInUuid(inMain.getUuid()); List<InDetailModel> details=InDetailDAOFactory.getInDetailDAO().getByCondition(idqm); if (details.size()!=0){ map.put(inMain, details); } } return map; } }工厂类:
package cn.hncu.in.business.factory; import cn.hncu.in.business.ebi.InMainEbi; import cn.hncu.in.business.ebo.InMainEbo; public class InMainEbiFactory { public static InMainEbi getInMainEbi(){ return new InMainEbo(); } }
package cn.hncu.in.vo; import java.io.Serializable; import cn.hncu.utils.DateUtil; public class InMainModel implements Serializable,Comparable<InMainModel>{ private String uuid; private long inDate; private String inUserId; private String inUserName; public String getInUserName() { return inUserName; } public void setInUserName(String inUserName) { this.inUserName = inUserName; } public String getUuid() { return uuid; } public void setUuid(String uuid) { this.uuid = uuid; } public long getInDate() { return inDate; } public void setInDate(long inDate) { this.inDate = inDate; } public String getInUserId() { return inUserId; } public void setInUserId(String inUserId) { this.inUserId = inUserId; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((uuid == null) ? 0 : uuid.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; InMainModel other = (InMainModel) obj; if (uuid == null) { if (other.uuid != null) return false; } else if (!uuid.equals(other.uuid)) return false; return true; } @Override public String toString() { return uuid + ", " + inUserName+ ", " + DateUtil.longToString(inDate); } @Override public int compareTo(InMainModel o) { return Integer.parseInt(uuid)-Integer.parseInt(o.getUuid()); } }InMainQueryModel
package cn.hncu.in.vo; public class InMainQueryModel extends InMainModel{ private long inDate2; public long getInDate2() { return inDate2; } public void setInDate2(long inDate2) { this.inDate2 = inDate2; } }InDetailModel
package cn.hncu.in.vo; import java.io.Serializable; public class InDetailModel implements Serializable{ private String uuid; private String inUuid; private String bookUuid; private int sumNum; private double sumMoney; private String bookName; public String getBookName() { return bookName; } public void setBookName(String bookName) { this.bookName = bookName; } public String getUuid() { return uuid; } public void setUuid(String uuid) { this.uuid = uuid; } public String getInUuid() { return inUuid; } public void setInUuid(String inUuid) { this.inUuid = inUuid; } public String getBookUuid() { return bookUuid; } public void setBookUuid(String bookUuid) { this.bookUuid = bookUuid; } public int getSumNum() { return sumNum; } public void setSumNum(int sumNum) { this.sumNum = sumNum; } public double getSumMoney() { return sumMoney; } public void setSumMoney(double sumMoney) { this.sumMoney = sumMoney; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((uuid == null) ? 0 : uuid.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; InDetailModel other = (InDetailModel) obj; if (uuid == null) { if (other.uuid != null) return false; } else if (!uuid.equals(other.uuid)) return false; return true; } @Override public String toString() { return uuid +", "+bookName + ", " + sumNum + "本, " + sumMoney + "元"; } }InDetailQueryModel
package cn.hncu.in.vo; public class InDetailQueryModel extends InDetailModel{ private int sumNum2; private double sumMoney2; public int getSumNum2() { return sumNum2; } public void setSumNum2(int sumNum2) { this.sumNum2 = sumNum2; } public double getSumMoney2() { return sumMoney2; } public void setSumMoney2(double sumMoney2) { this.sumMoney2 = sumMoney2; } }
列表:
/* * ListPanel.java * * Created on __DATE__, __TIME__ */ package cn.hncu.in.ui; import java.util.List; import java.util.Map; import javax.swing.JFrame; import cn.hncu.in.business.factory.InMainEbiFactory; import cn.hncu.in.vo.InDetailModel; import cn.hncu.in.vo.InMainModel; /** * * @author __USER__ */ public class ListPanel extends javax.swing.JPanel { private JFrame mainFrame = null; private Map<InMainModel, List<InDetailModel>> map; /** Creates new form ListPanel */ public ListPanel(JFrame mainFrame) { this.mainFrame = mainFrame; this.setOpaque(false); initComponents(); map = InMainEbiFactory.getInMainEbi().getAll(); myInit(); } public ListPanel(JFrame mainFrame, Map<InMainModel, List<InDetailModel>> map) { this.mainFrame = mainFrame; this.map = map; this.setOpaque(false); initComponents(); myInit(); } private void myInit() { jListInMain.setListData(map.keySet().toArray()); } //GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jLabel1 = new javax.swing.JLabel(); btnAdd = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); jListInMain = new javax.swing.JList(); jScrollPane2 = new javax.swing.JScrollPane(); jListInDetails = new javax.swing.JList(); btnQuery = new javax.swing.JButton(); setLayout(null); jLabel1.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 24)); jLabel1.setForeground(new java.awt.Color(0, 255, 0)); jLabel1.setText("\u8fdb\u8d27\u5217\u8868"); add(jLabel1); jLabel1.setBounds(360, 30, 130, 90); btnAdd.setText("\u6dfb\u52a0\u8fdb\u8d27"); btnAdd.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAddActionPerformed(evt); } }); add(btnAdd); btnAdd.setBounds(160, 410, 93, 50); jListInMain.setModel(new javax.swing.AbstractListModel() { String[] strings = { "" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); jListInMain .addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged( javax.swing.event.ListSelectionEvent evt) { jListInMainValueChanged(evt); } }); jScrollPane1.setViewportView(jListInMain); add(jScrollPane1); jScrollPane1.setBounds(110, 140, 260, 240); jListInDetails.setModel(new javax.swing.AbstractListModel() { String[] strings = { "" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); jScrollPane2.setViewportView(jListInDetails); add(jScrollPane2); jScrollPane2.setBounds(460, 110, 250, 360); btnQuery.setText("\u8fdb\u8d27\u67e5\u8be2"); btnQuery.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnQueryActionPerformed(evt); } }); add(btnQuery); btnQuery.setBounds(310, 410, 93, 50); }// </editor-fold> //GEN-END:initComponents private void btnQueryActionPerformed(java.awt.event.ActionEvent evt) { mainFrame.setContentPane(new QueryPanel(mainFrame)); mainFrame.validate(); } private void jListInMainValueChanged( javax.swing.event.ListSelectionEvent evt) { InMainModel inMain = (InMainModel) jListInMain.getSelectedValue(); List<InDetailModel> details = map.get(inMain); jListInDetails.setListData(details.toArray()); } private void btnAddActionPerformed(java.awt.event.ActionEvent evt) { mainFrame.setContentPane(new AddPanel(mainFrame)); mainFrame.validate(); } //GEN-BEGIN:variables // Variables declaration - do not modify private javax.swing.JButton btnAdd; private javax.swing.JButton btnQuery; private javax.swing.JLabel jLabel1; private javax.swing.JList jListInDetails; private javax.swing.JList jListInMain; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; // End of variables declaration//GEN-END:variables }添加:
/* * AddPanel.java * * Created on __DATE__, __TIME__ */ package cn.hncu.in.ui; import java.util.ArrayList; import java.util.List; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import cn.hncu.book.business.factory.BookEbiFactory; import cn.hncu.book.vo.BookModel; import cn.hncu.in.business.factory.InMainEbiFactory; import cn.hncu.in.vo.InDetailModel; import cn.hncu.in.vo.InMainModel; import cn.hncu.user.business.factory.UserEbiFactory; import cn.hncu.user.vo.UserModel; /** * * @author __USER__ */ public class AddPanel extends JPanel { private JFrame mainFrame = null; private List<InDetailModel> details = new ArrayList<InDetailModel>(); /** Creates new form AddPanel */ public AddPanel(JFrame mainFrame) { this.setOpaque(false); this.mainFrame = mainFrame; initComponents(); myInit(); } private void myInit() { List<BookModel> books = BookEbiFactory.getBookEbi().getAll(); for (BookModel book : books) { combBook.addItem(book); } List<UserModel> users = UserEbiFactory.getUserEbi().getAllIn(); for (UserModel user : users) { combUser.addItem(user.getName()); } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ //GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); combBook = new javax.swing.JComboBox(); jLabel3 = new javax.swing.JLabel(); tfdInAmount = new javax.swing.JTextField(); btnAddDetails = new javax.swing.JButton(); jLabel4 = new javax.swing.JLabel(); combUser = new javax.swing.JComboBox(); jLabel5 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); inDetailList = new javax.swing.JList(); btnAdd = new javax.swing.JButton(); btnBack = new javax.swing.JButton(); setLayout(null); jLabel1.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 24)); jLabel1.setForeground(new java.awt.Color(51, 255, 51)); jLabel1.setText("\u6dfb\u52a0\u8fdb\u8d27"); add(jLabel1); jLabel1.setBounds(360, 10, 140, 90); jLabel2.setForeground(new java.awt.Color(51, 255, 51)); jLabel2.setText("\u56fe\u4e66\uff1a"); add(jLabel2); jLabel2.setBounds(150, 110, 60, 40); combBook.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "请选择..." })); combBook.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { combBookActionPerformed(evt); } }); add(combBook); combBook.setBounds(210, 120, 160, 26); jLabel3.setForeground(new java.awt.Color(51, 255, 51)); jLabel3.setText("\u8fdb\u8d27\u6570\u91cf\uff1a"); add(jLabel3); jLabel3.setBounds(120, 170, 80, 40); add(tfdInAmount); tfdInAmount.setBounds(210, 180, 130, 26); btnAddDetails.setText("\u6dfb\u52a0\u660e\u7ec6"); btnAddDetails.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAddDetailsActionPerformed(evt); } }); add(btnAddDetails); btnAddDetails.setBounds(530, 180, 93, 30); jLabel4.setForeground(new java.awt.Color(51, 255, 51)); jLabel4.setText("\u8fdb\u8d27\u4eba\uff1a"); add(jLabel4); jLabel4.setBounds(460, 110, 70, 40); combUser.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "请选择..." })); add(combUser); combUser.setBounds(530, 120, 130, 26); jLabel5.setForeground(new java.awt.Color(51, 255, 51)); jLabel5.setText("\u660e\u7ec6\u5217\u8868\uff1a"); add(jLabel5); jLabel5.setBounds(120, 220, 90, 30); inDetailList.setModel(new javax.swing.AbstractListModel() { String[] strings = { "" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); jScrollPane1.setViewportView(inDetailList); add(jScrollPane1); jScrollPane1.setBounds(210, 230, 270, 200); btnAdd.setText("\u6dfb\u52a0"); btnAdd.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAddActionPerformed(evt); } }); add(btnAdd); btnAdd.setBounds(280, 470, 63, 29); btnBack.setText("\u8fd4\u56de"); btnBack.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnBackActionPerformed(evt); } }); add(btnBack); btnBack.setBounds(450, 470, 63, 29); }// </editor-fold> //GEN-END:initComponents private void combBookActionPerformed(java.awt.event.ActionEvent evt) { tfdInAmount.setText(null); } private void btnAddDetailsActionPerformed(java.awt.event.ActionEvent evt) { //收集参数 BookModel book = (BookModel) combBook.getSelectedItem(); String bookUuid = book.getUuid(); int sumNum = 0; try { sumNum = Integer.parseInt(tfdInAmount.getText()); if (sumNum < 0) { throw new NumberFormatException(); } } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "进货数量信息输入格式不正确"); } //组织参数 InDetailModel detail = new InDetailModel(); detail.setBookUuid(bookUuid); detail.setSumNum(sumNum); detail.setBookName(book.getName()); details.add(detail); echoDetails(); } private void echoDetails() { String echoStrs[] = new String[details.size()]; for (int i = 0; i < details.size(); i++) { InDetailModel detail = details.get(i); String bookName = BookEbiFactory.getBookEbi().getSingle( detail.getBookUuid()).getName(); echoStrs[i] = "《" + bookName + "》," + detail.getSumNum() + "本"; } inDetailList.setListData(echoStrs); } private void btnBackActionPerformed(java.awt.event.ActionEvent evt) { mainFrame.setContentPane(new ListPanel(mainFrame)); mainFrame.validate(); } private void btnAddActionPerformed(java.awt.event.ActionEvent evt) { //收集参数 String inUserName = combUser.getSelectedItem().toString(); String inUserUuid = UserEbiFactory.getUserEbi().getUserByName( inUserName).getUuid(); //组织参数 InMainModel inMain = new InMainModel(); inMain.setInUserId(inUserUuid); inMain.setInUserName(inUserName); //调用逻辑层 InMainEbiFactory.getInMainEbi().create(inMain, details); mainFrame.setContentPane(new ListPanel(mainFrame)); mainFrame.validate(); } //GEN-BEGIN:variables // Variables declaration - do not modify private javax.swing.JButton btnAdd; private javax.swing.JButton btnAddDetails; private javax.swing.JButton btnBack; private javax.swing.JComboBox combBook; private javax.swing.JComboBox combUser; private javax.swing.JList inDetailList; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField tfdInAmount; // End of variables declaration//GEN-END:variables }查询:
/* * QueryPanel.java * * Created on __DATE__, __TIME__ */ package cn.hncu.in.ui; import java.util.List; import java.util.Map; import javax.swing.JFrame; import javax.swing.JOptionPane; import cn.hncu.book.business.factory.BookEbiFactory; import cn.hncu.book.vo.BookModel; import cn.hncu.in.business.factory.InMainEbiFactory; import cn.hncu.in.vo.InDetailModel; import cn.hncu.in.vo.InDetailQueryModel; import cn.hncu.in.vo.InMainModel; import cn.hncu.in.vo.InMainQueryModel; import cn.hncu.user.business.factory.UserEbiFactory; import cn.hncu.user.vo.UserModel; import cn.hncu.utils.DateUtil; /** * * @author __USER__ */ public class QueryPanel extends javax.swing.JPanel { private JFrame mainFrame = null; /** Creates new form QueryPanel */ public QueryPanel(JFrame mainFrame) { this.mainFrame = mainFrame; initComponents(); myInit(); } private void myInit() { List<UserModel> userList = UserEbiFactory.getUserEbi().getAllIn(); for (UserModel user : userList) { combInUser.addItem(user); } List<BookModel> books = BookEbiFactory.getBookEbi().getAll(); for (BookModel book : books) { combBook.addItem(book); } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ //GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); tfdSumMoney2 = new javax.swing.JTextField(); tfdUuid = new javax.swing.JTextField(); tfdInDetailUuid = new javax.swing.JTextField(); tfdDate = new javax.swing.JTextField(); tfdDate2 = new javax.swing.JTextField(); tfdInNum = new javax.swing.JTextField(); tfdInNum2 = new javax.swing.JTextField(); tfdSumMoney = new javax.swing.JTextField(); combBook = new javax.swing.JComboBox(); combInUser = new javax.swing.JComboBox(); btnQuery = new javax.swing.JButton(); btnBack = new javax.swing.JButton(); setLayout(null); jLabel1.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 24)); jLabel1.setForeground(new java.awt.Color(51, 255, 51)); jLabel1.setText("\u8fdb\u8d27\u67e5\u8be2"); add(jLabel1); jLabel1.setBounds(310, 10, 120, 60); jLabel2.setText("\u56fe\u4e66\uff1a"); add(jLabel2); jLabel2.setBounds(460, 250, 60, 20); jLabel3.setText("\u8fdb\u8d27\u8d77\u59cb\u65f6\u95f4\uff1a"); add(jLabel3); jLabel3.setBounds(90, 170, 120, 20); jLabel4.setText("\u8fdb\u8d27\u4eba\uff1a"); add(jLabel4); jLabel4.setBounds(450, 110, 80, 20); jLabel5.setText("\u8fdb\u8d27\u5355\u7f16\u53f7\uff1a"); add(jLabel5); jLabel5.setBounds(100, 110, 110, 20); jLabel6.setText("\u8fdb\u8d27\u6700\u5927\u91cf\uff1a"); add(jLabel6); jLabel6.setBounds(410, 330, 100, 20); jLabel7.setText("\u8fdb\u8d27\u6700\u5c0f\u91cf\uff1a"); add(jLabel7); jLabel7.setBounds(100, 330, 130, 20); jLabel8.setText("\u8fdb\u8d27\u660e\u7ec6\u7f16\u53f7\uff1a"); add(jLabel8); jLabel8.setBounds(90, 250, 130, 20); jLabel9.setText("\u8fdb\u8d27\u7ed3\u675f\u65f6\u95f4\uff1a"); add(jLabel9); jLabel9.setBounds(400, 170, 120, 20); jLabel11.setText("\u683c\u5f0f\u5982\uff1a2016-04-01"); add(jLabel11); jLabel11.setBounds(110, 200, 170, 20); jLabel12.setText("\u8fdb\u8d27\u603b\u4ef7\u6700\u5927\u503c\uff1a"); add(jLabel12); jLabel12.setBounds(380, 400, 140, 20); jLabel13.setText("\u8fdb\u8d27\u603b\u4ef7\u6700\u5c0f\u503c\uff1a"); add(jLabel13); jLabel13.setBounds(70, 400, 130, 20); add(tfdSumMoney2); tfdSumMoney2.setBounds(530, 400, 130, 30); add(tfdUuid); tfdUuid.setBounds(200, 110, 130, 30); add(tfdInDetailUuid); tfdInDetailUuid.setBounds(200, 250, 130, 30); add(tfdDate); tfdDate.setBounds(200, 170, 130, 30); add(tfdDate2); tfdDate2.setBounds(530, 170, 130, 30); add(tfdInNum); tfdInNum.setBounds(200, 330, 130, 30); add(tfdInNum2); tfdInNum2.setBounds(530, 330, 130, 30); add(tfdSumMoney); tfdSumMoney.setBounds(200, 400, 130, 30); combBook.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "查询所有" })); add(combBook); combBook.setBounds(530, 250, 130, 26); combInUser.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "查询所有" })); add(combInUser); combInUser.setBounds(530, 110, 130, 26); btnQuery.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 18)); btnQuery.setText("\u67e5\u8be2"); btnQuery.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnQueryActionPerformed(evt); } }); add(btnQuery); btnQuery.setBounds(210, 460, 80, 40); btnBack.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 18)); btnBack.setText("\u8fd4\u56de"); btnBack.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnBackActionPerformed(evt); } }); add(btnBack); btnBack.setBounds(420, 460, 80, 40); }// </editor-fold> //GEN-END:initComponents private void btnQueryActionPerformed(java.awt.event.ActionEvent evt) { //收集参数 String inUuid = tfdUuid.getText(); String inUserName = (String) combInUser.getSelectedItem(); String inUserUuid = null; if (combInUser.getSelectedIndex() > 0) { inUserUuid = UserEbiFactory.getUserEbi().getUserByName(inUserName) .getUuid(); } String txtInDate = tfdDate.getText(); long inDate = 0; if (txtInDate != null && txtInDate.trim().length() > 0) { txtInDate += " 00:00:00"; inDate = DateUtil.StringToLong(txtInDate, "进货起始时间输入格式错误!"); if (inDate == -1) { return; } } String txtInDate2 = tfdDate2.getText(); long inDate2 = 0; if (txtInDate2 != null && txtInDate2.trim().length() > 0) { txtInDate2 += " 23:59:59"; inDate2 = DateUtil.StringToLong(txtInDate2, "进货结束时间输入格式错误!"); if (inDate2 == -1) { return; } } String inDetailUuid = tfdInDetailUuid.getText(); String bookUuid = null; if (combBook.getSelectedIndex() > 0) { String bookName = combBook.getSelectedItem().toString(); bookUuid = BookEbiFactory.getBookEbi().getSingle(bookName) .getUuid(); } int sumNum = 0; if (tfdInNum.getText() != null && tfdInNum.getText().trim().length() > 0) { try { sumNum = Integer.parseInt(tfdInNum.getText()); if (sumNum < 0) { throw new NumberFormatException(); } } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "进货最小量格式输入错误!"); } } int sumNum2 = 0; if (tfdInNum2.getText() != null && tfdInNum2.getText().trim().length() > 0) { try { sumNum2 = Integer.parseInt(tfdInNum2.getText()); if (sumNum2 < 0) { throw new NumberFormatException(); } } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "进货最大量格式输入错误!"); } } double sumMoney = 0; if (tfdSumMoney.getText() != null && tfdSumMoney.getText().trim().length() > 0) { try { sumMoney = Integer.parseInt(tfdSumMoney.getText()); if (sumMoney < 0) { throw new NumberFormatException(); } } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "进货最小量格式输入错误!"); } } double sumMoney2 = 0; if (tfdSumMoney2.getText() != null && tfdSumMoney2.getText().trim().length() > 0) { try { sumMoney2 = Integer.parseInt(tfdSumMoney2.getText()); if (sumMoney2 < 0) { throw new NumberFormatException(); } } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "进货最小量格式输入错误!"); } } //组织参数-------分别组织InMainQueryModel和InDetailQueryModel InMainQueryModel imqm = new InMainQueryModel(); imqm.setInDate(inDate); imqm.setInDate2(inDate2); imqm.setInUserId(inUserUuid); imqm.setInUserName(inUserName); imqm.setUuid(inUuid); InDetailQueryModel idqm = new InDetailQueryModel(); idqm.setBookUuid(bookUuid); idqm.setUuid(inDetailUuid); idqm.setSumMoney(sumMoney); idqm.setSumMoney2(sumMoney2); idqm.setSumNum(sumNum); idqm.setSumNum2(sumNum2); //调用逻辑层 Map<InMainModel, List<InDetailModel>> map = InMainEbiFactory .getInMainEbi().getByCondition(imqm, idqm); //返回到结果页面 mainFrame.setContentPane(new ListPanel(mainFrame, map)); mainFrame.validate(); } private void btnBackActionPerformed(java.awt.event.ActionEvent evt) { mainFrame.setContentPane(new ListPanel(mainFrame)); mainFrame.validate(); } //GEN-BEGIN:variables // Variables declaration - do not modify private javax.swing.JButton btnBack; private javax.swing.JButton btnQuery; private javax.swing.JComboBox combBook; private javax.swing.JComboBox combInUser; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JTextField tfdDate; private javax.swing.JTextField tfdDate2; private javax.swing.JTextField tfdInDetailUuid; private javax.swing.JTextField tfdInNum; private javax.swing.JTextField tfdInNum2; private javax.swing.JTextField tfdSumMoney; private javax.swing.JTextField tfdSumMoney2; private javax.swing.JTextField tfdUuid; // End of variables declaration//GEN-END:variables }