码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-05-26 01:09:15      阅读:352      评论:0      收藏:0      [点我收藏+]

标签:

书店管理系统

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

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

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

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

本篇将做进货模块。


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

链接:http://blog.csdn.net/x121850182/article/details/51362269


和前面的模块相同的,进货模块分成了数据层、逻辑层、表现层和值对象层,但数据层要多出一个进货明细。


数据层:

接口:

InMainDAO

[java] view plain copy
 技术分享技术分享
  1. package cn.hncu.in.dao.dao;  
  2.   
  3. import java.util.List;  
  4.   
  5. import cn.hncu.in.vo.InMainModel;  
  6. import cn.hncu.in.vo.InMainQueryModel;  
  7.   
  8. public interface InMainDAO {  
  9.     public boolean create(InMainModel inMain);  
  10.     public boolean delete(String uuid);  
  11.     public boolean upDate(InMainModel inMain);  
  12.       
  13.     public InMainModel getSingle(String uuid);  
  14.     public List<InMainModel> getAll();  
  15.     public List<InMainModel> getByCondition(InMainQueryModel imqm);  
  16. }  
InDetailDAO

[java] view plain copy
 技术分享技术分享
  1. package cn.hncu.in.dao.dao;  
  2.   
  3. import java.util.List;  
  4.   
  5. import cn.hncu.in.vo.InDetailModel;  
  6. import cn.hncu.in.vo.InDetailQueryModel;  
  7.   
  8. public interface InDetailDAO {  
  9.     public boolean create(InDetailModel inDetail);  
  10.     public boolean delete(String uuid);  
  11.     public boolean upDate(InDetailModel inDetail);  
  12.       
  13.     public InDetailModel getSingle(String uuid);  
  14.     public List<InDetailModel> getAll();  
  15.     public List<InDetailModel> getByCondition(InDetailQueryModel idqm);  
  16. }  
实现类:

InMainDAOImpl

[java] view plain copy
 技术分享技术分享
  1. package cn.hncu.in.dao.impl;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5.   
  6. import cn.hncu.in.dao.dao.InMainDAO;  
  7. import cn.hncu.in.vo.InMainModel;  
  8. import cn.hncu.in.vo.InMainQueryModel;  
  9. import cn.hncu.utils.FileIo;  
  10.   
  11. public class InMainDAOImpl implements InMainDAO {  
  12.     private final String FILE_NAME="InMain.txt";  
  13.     @Override  
  14.     public boolean create(InMainModel inMain) {  
  15.         List<InMainModel> list=FileIo.read(FILE_NAME);  
  16.         for (InMainModel model:list){  
  17.             if (model.getUuid().equals(inMain.getUuid())){  
  18.                 return false;  
  19.             }  
  20.         }  
  21.         list.add(inMain);  
  22.         FileIo.write(list, FILE_NAME);  
  23.         return true;  
  24.     }  
  25.   
  26.     @Override  
  27.     public boolean delete(String uuid) {  
  28.         List<InMainModel> list=FileIo.read(FILE_NAME);  
  29.         for (InMainModel model:list){  
  30.             if (model.getUuid().equals(uuid)){  
  31.                 list.remove(model);  
  32.                 FileIo.write(list, FILE_NAME);  
  33.                 return true;  
  34.             }  
  35.         }  
  36.         return false;  
  37.     }  
  38.   
  39.     @Override  
  40.     public List<InMainModel> getAll() {  
  41.         List<InMainModel> list=FileIo.read(FILE_NAME);  
  42.         return list;  
  43.     }  
  44.   
  45.     @Override  
  46.     public List<InMainModel> getByCondition(InMainQueryModel imqm) {  
  47.         List<InMainModel> list=getAll();  
  48.         List<InMainModel> result=new ArrayList<InMainModel>();  
  49.         for (InMainModel inMain:list){  
  50.             if (imqm.getUuid()!=null&&imqm.getUuid().trim().length()>0){  
  51.                 if (!imqm.getUuid().equals(inMain.getUuid())){  
  52.                     continue;  
  53.                 }  
  54.             }  
  55.             if (imqm.getInUserId()!=null&&imqm.getInUserId().trim().length()>0){  
  56.                 if (!imqm.getInUserId().equals(inMain.getInUserId())){  
  57.                     continue;  
  58.                 }  
  59.             }  
  60.             if (imqm.getInDate()>0){  
  61.                 if (imqm.getInDate()>inMain.getInDate()){  
  62.                     continue;  
  63.                 }  
  64.             }  
  65.             if (imqm.getInDate2()>0){  
  66.                 if (imqm.getInDate2()<inMain.getInDate()){  
  67.                     continue;  
  68.                 }  
  69.             }  
  70.             result.add(inMain);  
  71.         }  
  72.           
  73.         return result;  
  74.     }  
  75.   
  76.     @Override  
  77.     public InMainModel getSingle(String uuid) {  
  78.         List<InMainModel> list=FileIo.read(FILE_NAME);  
  79.         for (InMainModel model:list){  
  80.             if (model.getUuid().equals(uuid)){  
  81.                 return model;  
  82.             }  
  83.         }  
  84.         return null;  
  85.     }  
  86.   
  87.     @Override  
  88.     public boolean upDate(InMainModel inMain) {  
  89.         List<InMainModel> list=FileIo.read(FILE_NAME);  
  90.         for (int i=0;i<list.size();i++){  
  91.             InMainModel model=list.get(i);  
  92.             if (model.getUuid().equals(inMain.getUuid())){  
  93.                 list.set(i, inMain);  
  94.                 return true;  
  95.             }  
  96.         }  
  97.         return false;  
  98.     }  
  99. }  
InDetailDAOImpl

[java] view plain copy
 技术分享技术分享
  1. package cn.hncu.in.dao.impl;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5.   
  6. import cn.hncu.in.dao.dao.InDetailDAO;  
  7. import cn.hncu.in.vo.InDetailModel;  
  8. import cn.hncu.in.vo.InDetailQueryModel;  
  9. import cn.hncu.in.vo.InMainModel;  
  10. import cn.hncu.utils.FileIo;  
  11.   
  12. public class InDetailDAOImpl implements InDetailDAO {  
  13.     private final String FILE_NAME="InDetail.txt";  
  14.     @Override  
  15.     public boolean create(InDetailModel inDetail) {  
  16.         List<InDetailModel> list=FileIo.read(FILE_NAME);  
  17.         for (InDetailModel model:list){  
  18.             if (model.getUuid().equals(inDetail.getUuid())){  
  19.                 return false;  
  20.             }  
  21.         }  
  22.         list.add(inDetail);  
  23.         FileIo.write(list, FILE_NAME);  
  24.         return true;  
  25.     }  
  26.   
  27.     @Override  
  28.     public boolean delete(String uuid) {  
  29.         List<InDetailModel> list=FileIo.read(FILE_NAME);  
  30.         for (InDetailModel model:list){  
  31.             if (model.getUuid().equals(uuid)){  
  32.                 list.remove(model);  
  33.                 FileIo.write(list, FILE_NAME);  
  34.                 return true;  
  35.             }  
  36.         }  
  37.         return false;  
  38.     }  
  39.   
  40.     @Override  
  41.     public List<InDetailModel> getAll() {  
  42.         List<InDetailModel> list=FileIo.read(FILE_NAME);  
  43.         return list;  
  44.     }  
  45.   
  46.     @Override  
  47.     public List<InDetailModel> getByCondition(InDetailQueryModel idqm) {  
  48.         List<InDetailModel> list=getAll();  
  49.         List<InDetailModel> results=new ArrayList<InDetailModel>();  
  50.           
  51.         for (InDetailModel model:list){  
  52.             if (idqm.getUuid()!=null&&idqm.getUuid().trim().length()>0){  
  53.                 if (!model.getUuid().equals(idqm.getUuid())){  
  54.                     continue;  
  55.                 }  
  56.             }  
  57.             if (idqm.getInUuid()!=null&&idqm.getInUuid().trim().length()>0){  
  58.                 if (!model.getInUuid().equals(idqm.getInUuid())){  
  59.                     continue;  
  60.                 }  
  61.             }  
  62.             if (idqm.getBookUuid()!=null&&idqm.getBookUuid().trim().length()>0){  
  63.                 if (!model.getBookUuid().equals(idqm.getBookUuid())){  
  64.                     continue;  
  65.                 }  
  66.             }  
  67.             if (idqm.getSumNum()>0){  
  68.                 if (model.getSumNum()<idqm.getSumNum()){  
  69.                     continue;  
  70.                 }  
  71.             }  
  72.             if (idqm.getSumNum2()>0){  
  73.                 if (model.getSumNum()>idqm.getSumNum2()){  
  74.                     continue;  
  75.                 }  
  76.             }  
  77.             if (idqm.getSumMoney()>0){  
  78.                 if (model.getSumMoney()<idqm.getSumMoney()){  
  79.                     continue;  
  80.                 }  
  81.             }  
  82.             if (idqm.getSumMoney2()>0){  
  83.                 if (model.getSumMoney()>idqm.getSumMoney2()){  
  84.                     continue;  
  85.                 }  
  86.             }  
  87.             results.add(model);  
  88.         }  
  89.         return results;  
  90.     }  
  91.   
  92.     @Override  
  93.     public InDetailModel getSingle(String uuid) {  
  94.         List<InDetailModel> list=FileIo.read(FILE_NAME);  
  95.         for (InDetailModel model:list){  
  96.             if (model.getUuid().equals(uuid)){  
  97.                 return model;  
  98.             }  
  99.         }  
  100.         return null;  
  101.     }  
  102.   
  103.     @Override  
  104.     public boolean upDate(InDetailModel inDetail) {  
  105.         List<InDetailModel> list=FileIo.read(FILE_NAME);  
  106.         for (int i=0;i<list.size();i++){  
  107.             InDetailModel model=list.get(i);  
  108.             if (model.getUuid().equals(inDetail.getUuid())){  
  109.                 list.set(i, inDetail);  
  110.                 return true;  
  111.             }  
  112.         }  
  113.         return false;  
  114.     }  
  115. }  
工厂类:

InMainDAOFactory

[java] view plain copy
 技术分享技术分享
  1. package cn.hncu.in.dao.factory;  
  2.   
  3. import cn.hncu.in.dao.dao.InMainDAO;  
  4. import cn.hncu.in.dao.impl.InMainDAOImpl;  
  5.   
  6. public class InMainDAOFactory {  
  7.     public static InMainDAO getInMainDAO(){  
  8.         return new InMainDAOImpl();  
  9.     }  
  10. }  
InDetailDAOFactory

[java] view plain copy
 技术分享技术分享
  1. package cn.hncu.in.dao.factory;  
  2.   
  3. import cn.hncu.in.dao.dao.InDetailDAO;  
  4. import cn.hncu.in.dao.impl.InDetailDAOImpl;  
  5.   
  6. public class InDetailDAOFactory {  
  7.     public static InDetailDAO getInDetailDAO(){  
  8.         return new InDetailDAOImpl();  
  9.     }  
  10. }  

逻辑层:

接口:

[java] view plain copy
 技术分享技术分享
  1. package cn.hncu.in.business.ebi;  
  2.   
  3. import java.util.List;  
  4. import java.util.Map;  
  5.   
  6. import cn.hncu.in.vo.InDetailModel;  
  7. import cn.hncu.in.vo.InDetailQueryModel;  
  8. import cn.hncu.in.vo.InMainModel;  
  9. import cn.hncu.in.vo.InMainQueryModel;  
  10.   
  11. public interface InMainEbi {  
  12.     public boolean create(InMainModel inMain,List<InDetailModel> details);  
  13.     public Map<InMainModel, List<InDetailModel>> getAll();  
  14.     public Map<InMainModel, List<InDetailModel>> getByCondition(InMainQueryModel imqm,InDetailQueryModel idqm);  
  15. }  
实现类:

[java] view plain copy
 技术分享技术分享
  1. package cn.hncu.in.business.ebo;  
  2.   
  3. import java.util.List;  
  4. import java.util.Map;  
  5. import java.util.TreeMap;  
  6.   
  7. import cn.hncu.book.business.ebi.BookEbi;  
  8. import cn.hncu.book.business.factory.BookEbiFactory;  
  9. import cn.hncu.common.UuidModelConstance;  
  10. import cn.hncu.common.uuid.dao.dao.UuidDAO;  
  11. import cn.hncu.common.uuid.dao.factory.UuidDAOFactory;  
  12. import cn.hncu.in.business.ebi.InMainEbi;  
  13. import cn.hncu.in.dao.dao.InDetailDAO;  
  14. import cn.hncu.in.dao.dao.InMainDAO;  
  15. import cn.hncu.in.dao.factory.InDetailDAOFactory;  
  16. import cn.hncu.in.dao.factory.InMainDAOFactory;  
  17. import cn.hncu.in.vo.InDetailModel;  
  18. import cn.hncu.in.vo.InDetailQueryModel;  
  19. import cn.hncu.in.vo.InMainModel;  
  20. import cn.hncu.in.vo.InMainQueryModel;  
  21. import cn.hncu.stock.dao.dao.StockDAO;  
  22. import cn.hncu.stock.dao.factory.StockDAOFactory;  
  23. import cn.hncu.stock.vo.StockModel;  
  24. import cn.hncu.stock.vo.StockQueryModel;  
  25.   
  26. public class InMainEbo implements InMainEbi {  
  27.     InMainDAO inMainDAO=InMainDAOFactory.getInMainDAO();  
  28.     InDetailDAO inDetailDAO=InDetailDAOFactory.getInDetailDAO();  
  29.     UuidDAO uuidDAO=UuidDAOFactory.getUuidDAO();  
  30.     BookEbi bookEbi=BookEbiFactory.getBookEbi();  
  31.   
  32.     @Override  
  33.     public boolean create(InMainModel inMain, List<InDetailModel> details) {  
  34.         //////////1存储inMain信息///////////  
  35.         //补全inMain中的数据  
  36.         //需要:inUuid,inDate,inUserUuid   已组织:inUserUuid  
  37.         //还缺(需补):inUuid,inDate  
  38.         String inUuid=uuidDAO.getNextUuid(UuidModelConstance.IN_MAIN);  
  39.         inMain.setUuid(inUuid);  
  40.         inMain.setInDate(System.currentTimeMillis());  
  41.         inMainDAO.create(inMain);  
  42.   
  43.         //////////2存储inDetail信息///////////  
  44.         for (InDetailModel inDetail:details){  
  45.             //补全每一个inDetail中的数据  
  46.             //需要:inDetailUuid,inMainUuid,bookUuid,sumNum,sumMoney   已组织:bookUuid,sumNum  
  47.             //还缺(需补):inDetailUuid,inMainUuid,sumMoney  
  48.             inDetail.setUuid(uuidDAO.getNextUuid(UuidModelConstance.IN_DETAIL));  
  49.             inDetail.setInUuid(inUuid);  
  50.             double sumMoney=inDetail.getSumNum()*bookEbi.getSingle(inDetail.getBookUuid()).getInPrice();  
  51.             inDetail.setSumMoney(sumMoney);  
  52.             inDetailDAO.create(inDetail);  
  53.             putIntoStock(inDetail.getBookUuid(), inDetail.getSumNum());  
  54.         }  
  55.           
  56.         return true;  
  57.     }  
  58.       
  59.     public void putIntoStock(String bookUuid,int sumNum){  
  60.         StockDAO stockDAO=StockDAOFactory.getStockDAO();  
  61.           
  62.         //查询库存,看看是否已经存在该bookUuid所对应的书,如果没有则库存数据为sumNum,否则为在原有基础上再加上sumNum  
  63.         StockQueryModel sqm=new StockQueryModel();  
  64.         sqm.setBookUuid(bookUuid);  
  65.         List<StockModel> list = stockDAO.getByCondition(sqm);  
  66.           
  67.         if (list==null||list.size()==0){  
  68.             StockModel stock=new StockModel();  
  69.             String uuid=UuidDAOFactory.getUuidDAO().getNextUuid(UuidModelConstance.STOCK);  
  70.             stock.setUuid(uuid);  
  71.             stock.setBookName(BookEbiFactory.getBookEbi().getSingle(bookUuid).getName());  
  72.             stock.setBookUuid(bookUuid);  
  73.             stock.setSumNum(sumNum);  
  74.               
  75.             stockDAO.create(stock);  
  76.         }else {//库存中已经存在该图书对应的库存记录  
  77.             StockModel stock=list.get(0);  
  78.             stock.setSumNum(stock.getSumNum()+sumNum);  
  79.             stockDAO.upDate(stock);  
  80.         }  
  81.     }  
  82.   
  83.     @Override  
  84.     public Map<InMainModel, List<InDetailModel>> getAll() {  
  85.         Map<InMainModel, List<InDetailModel>> map=new TreeMap<InMainModel, List<InDetailModel>>();  
  86.         List<InMainModel> inMains=inMainDAO.getAll();  
  87.           
  88.         for (InMainModel inMain:inMains){  
  89.             InDetailQueryModel idqm=new InDetailQueryModel();  
  90.             String inUuid=inMain.getUuid();  
  91.             idqm.setInUuid(inUuid);  
  92.               
  93.             List<InDetailModel> details=inDetailDAO.getByCondition(idqm);  
  94.             map.put(inMain, details);  
  95.         }  
  96.           
  97.         return map;  
  98.     }  
  99.   
  100.     @Override  
  101.     public Map<InMainModel, List<InDetailModel>> getByCondition(  
  102.             InMainQueryModel imqm, InDetailQueryModel idqm) {  
  103.         Map<InMainModel, List<InDetailModel>> map=new TreeMap<InMainModel, List<InDetailModel>>();  
  104.         List<InMainModel> inMains=InMainDAOFactory.getInMainDAO().getByCondition(imqm);  
  105.           
  106.         for (InMainModel inMain:inMains){  
  107.             idqm.setInUuid(inMain.getUuid());  
  108.             List<InDetailModel> details=InDetailDAOFactory.getInDetailDAO().getByCondition(idqm);  
  109.             if (details.size()!=0){  
  110.                 map.put(inMain, details);  
  111.             }  
  112.         }  
  113.         return map;  
  114.     }  
  115. }  
工厂类:

[java] view plain copy
 技术分享技术分享
  1. package cn.hncu.in.business.factory;  
  2.   
  3. import cn.hncu.in.business.ebi.InMainEbi;  
  4. import cn.hncu.in.business.ebo.InMainEbo;  
  5.   
  6. public class InMainEbiFactory {  
  7.     public static InMainEbi getInMainEbi(){  
  8.         return new InMainEbo();  
  9.     }  
  10. }  


值对象层:
InMainModel

[java] view plain copy
 技术分享技术分享
  1. package cn.hncu.in.vo;  
  2.   
  3. import java.io.Serializable;  
  4.   
  5. import cn.hncu.utils.DateUtil;  
  6.   
  7. public class InMainModel implements Serializable,Comparable<InMainModel>{  
  8.     private String uuid;  
  9.     private long inDate;  
  10.     private String inUserId;  
  11.     private String inUserName;  
  12.       
  13.     public String getInUserName() {  
  14.         return inUserName;  
  15.     }  
  16.     public void setInUserName(String inUserName) {  
  17.         this.inUserName = inUserName;  
  18.     }  
  19.     public String getUuid() {  
  20.         return uuid;  
  21.     }  
  22.     public void setUuid(String uuid) {  
  23.         this.uuid = uuid;  
  24.     }  
  25.     public long getInDate() {  
  26.         return inDate;  
  27.     }  
  28.     public void setInDate(long inDate) {  
  29.         this.inDate = inDate;  
  30.     }  
  31.     public String getInUserId() {  
  32.         return inUserId;  
  33.     }  
  34.     public void setInUserId(String inUserId) {  
  35.         this.inUserId = inUserId;  
  36.     }  
  37.       
  38.     @Override  
  39.     public int hashCode() {  
  40.         final int prime = 31;  
  41.         int result = 1;  
  42.         result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());  
  43.         return result;  
  44.     }  
  45.     @Override  
  46.     public boolean equals(Object obj) {  
  47.         if (this == obj)  
  48.             return true;  
  49.         if (obj == null)  
  50.             return false;  
  51.         if (getClass() != obj.getClass())  
  52.             return false;  
  53.         InMainModel other = (InMainModel) obj;  
  54.         if (uuid == null) {  
  55.             if (other.uuid != null)  
  56.                 return false;  
  57.         } else if (!uuid.equals(other.uuid))  
  58.             return false;  
  59.         return true;  
  60.     }  
  61.       
  62.     @Override  
  63.     public String toString() {  
  64.         return uuid + ", " + inUserName+ ", " + DateUtil.longToString(inDate);  
  65.     }  
  66.     @Override  
  67.     public int compareTo(InMainModel o) {  
  68.         return Integer.parseInt(uuid)-Integer.parseInt(o.getUuid());  
  69.     }  
  70. }  
InMainQueryModel

[java] view plain copy
 技术分享技术分享
  1. package cn.hncu.in.vo;  
  2.   
  3. public class InMainQueryModel extends InMainModel{  
  4.     private long inDate2;  
  5.   
  6.     public long getInDate2() {  
  7.         return inDate2;  
  8.     }  
  9.   
  10.     public void setInDate2(long inDate2) {  
  11.         this.inDate2 = inDate2;  
  12.     }  
  13. }  
InDetailModel

[java] view plain copy
 技术分享技术分享
  1. package cn.hncu.in.vo;  
  2.   
  3. import java.io.Serializable;  
  4.   
  5. public class InDetailModel implements Serializable{  
  6.     private String uuid;  
  7.     private String inUuid;  
  8.     private String bookUuid;  
  9.     private int sumNum;  
  10.     private double sumMoney;  
  11.     private String bookName;  
  12.       
  13.     public String getBookName() {  
  14.         return bookName;  
  15.     }  
  16.     public void setBookName(String bookName) {  
  17.         this.bookName = bookName;  
  18.     }  
  19.     public String getUuid() {  
  20.         return uuid;  
  21.     }  
  22.     public void setUuid(String uuid) {  
  23.         this.uuid = uuid;  
  24.     }  
  25.     public String getInUuid() {  
  26.         return inUuid;  
  27.     }  
  28.     public void setInUuid(String inUuid) {  
  29.         this.inUuid = inUuid;  
  30.     }  
  31.     public String getBookUuid() {  
  32.         return bookUuid;  
  33.     }  
  34.     public void setBookUuid(String bookUuid) {  
  35.         this.bookUuid = bookUuid;  
  36.     }  
  37.     public int getSumNum() {  
  38.         return sumNum;  
  39.     }  
  40.     public void setSumNum(int sumNum) {  
  41.         this.sumNum = sumNum;  
  42.     }  
  43.     public double getSumMoney() {  
  44.         return sumMoney;  
  45.     }  
  46.     public void setSumMoney(double sumMoney) {  
  47.         this.sumMoney = sumMoney;  
  48.     }  
  49.       
  50.     @Override  
  51.     public int hashCode() {  
  52.         final int prime = 31;  
  53.         int result = 1;  
  54.         result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());  
  55.         return result;  
  56.     }  
  57.     @Override  
  58.     public boolean equals(Object obj) {  
  59.         if (this == obj)  
  60.             return true;  
  61.         if (obj == null)  
  62.             return false;  
  63.         if (getClass() != obj.getClass())  
  64.             return false;  
  65.         InDetailModel other = (InDetailModel) obj;  
  66.         if (uuid == null) {  
  67.             if (other.uuid != null)  
  68.                 return false;  
  69.         } else if (!uuid.equals(other.uuid))  
  70.             return false;  
  71.         return true;  
  72.     }  
  73.       
  74.     @Override  
  75.     public String toString() {  
  76.         return uuid +", "+bookName + ", " + sumNum  
  77.         + "本, " + sumMoney + "元";  
  78.     }  
  79. }  
InDetailQueryModel

[java] view plain copy
 技术分享技术分享
  1. package cn.hncu.in.vo;  
  2.   
  3. public class InDetailQueryModel extends InDetailModel{  
  4.     private int sumNum2;  
  5.     private double sumMoney2;  
  6.     public int getSumNum2() {  
  7.         return sumNum2;  
  8.     }  
  9.     public void setSumNum2(int sumNum2) {  
  10.         this.sumNum2 = sumNum2;  
  11.     }  
  12.     public double getSumMoney2() {  
  13.         return sumMoney2;  
  14.     }  
  15.     public void setSumMoney2(double sumMoney2) {  
  16.         this.sumMoney2 = sumMoney2;  
  17.     }  
  18. }  


表现层:
销售模块的话在表现层只能有添加、查询和列表三个功能,不能删改,关于进货和销售的都要保留记录,不能删除,修改的话只能通过销售来进行。

列表:

[java] view plain copy
 技术分享技术分享
  1. /* 
  2.  * ListPanel.java 
  3.  * 
  4.  * Created on __DATE__, __TIME__ 
  5.  */  
  6.   
  7. package cn.hncu.in.ui;  
  8.   
  9. import java.util.List;  
  10. import java.util.Map;  
  11.   
  12. import javax.swing.JFrame;  
  13.   
  14. import cn.hncu.in.business.factory.InMainEbiFactory;  
  15. import cn.hncu.in.vo.InDetailModel;  
  16. import cn.hncu.in.vo.InMainModel;  
  17.   
  18. /** 
  19.  * 
  20.  * @author  __USER__ 
  21.  */  
  22. public class ListPanel extends javax.swing.JPanel {  
  23.     private JFrame mainFrame = null;  
  24.     private Map<InMainModel, List<InDetailModel>> map;  
  25.   
  26.     /** Creates new form ListPanel */  
  27.     public ListPanel(JFrame mainFrame) {  
  28.         this.mainFrame = mainFrame;  
  29.         this.setOpaque(false);  
  30.         initComponents();  
  31.         map = InMainEbiFactory.getInMainEbi().getAll();  
  32.         myInit();  
  33.     }  
  34.   
  35.     public ListPanel(JFrame mainFrame, Map<InMainModel, List<InDetailModel>> map) {  
  36.         this.mainFrame = mainFrame;  
  37.         this.map = map;  
  38.         this.setOpaque(false);  
  39.         initComponents();  
  40.         myInit();  
  41.     }  
  42.   
  43.     private void myInit() {  
  44.         jListInMain.setListData(map.keySet().toArray());  
  45.     }  
  46.   
  47.     //GEN-BEGIN:initComponents  
  48.     // <editor-fold defaultstate="collapsed" desc="Generated Code">  
  49.     private void initComponents() {  
  50.   
  51.         jLabel1 = new javax.swing.JLabel();  
  52.         btnAdd = new javax.swing.JButton();  
  53.         jScrollPane1 = new javax.swing.JScrollPane();  
  54.         jListInMain = new javax.swing.JList();  
  55.         jScrollPane2 = new javax.swing.JScrollPane();  
  56.         jListInDetails = new javax.swing.JList();  
  57.         btnQuery = new javax.swing.JButton();  
  58.   
  59.         setLayout(null);  
  60.   
  61.         jLabel1.setFont(new java.awt.Font("Microsoft YaHei UI"124));  
  62.         jLabel1.setForeground(new java.awt.Color(02550));  
  63.         jLabel1.setText("\u8fdb\u8d27\u5217\u8868");  
  64.         add(jLabel1);  
  65.         jLabel1.setBounds(3603013090);  
  66.   
  67.         btnAdd.setText("\u6dfb\u52a0\u8fdb\u8d27");  
  68.         btnAdd.addActionListener(new java.awt.event.ActionListener() {  
  69.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  70.                 btnAddActionPerformed(evt);  
  71.             }  
  72.         });  
  73.         add(btnAdd);  
  74.         btnAdd.setBounds(1604109350);  
  75.   
  76.         jListInMain.setModel(new javax.swing.AbstractListModel() {  
  77.             String[] strings = { "" };  
  78.   
  79.             public int getSize() {  
  80.                 return strings.length;  
  81.             }  
  82.   
  83.             public Object getElementAt(int i) {  
  84.                 return strings[i];  
  85.             }  
  86.         });  
  87.         jListInMain  
  88.                 .addListSelectionListener(new javax.swing.event.ListSelectionListener() {  
  89.                     public void valueChanged(  
  90.                             javax.swing.event.ListSelectionEvent evt) {  
  91.                         jListInMainValueChanged(evt);  
  92.                     }  
  93.                 });  
  94.         jScrollPane1.setViewportView(jListInMain);  
  95.   
  96.         add(jScrollPane1);  
  97.         jScrollPane1.setBounds(110140260240);  
  98.   
  99.         jListInDetails.setModel(new javax.swing.AbstractListModel() {  
  100.             String[] strings = { "" };  
  101.   
  102.             public int getSize() {  
  103.                 return strings.length;  
  104.             }  
  105.   
  106.             public Object getElementAt(int i) {  
  107.                 return strings[i];  
  108.             }  
  109.         });  
  110.         jScrollPane2.setViewportView(jListInDetails);  
  111.   
  112.         add(jScrollPane2);  
  113.         jScrollPane2.setBounds(460110250360);  
  114.   
  115.         btnQuery.setText("\u8fdb\u8d27\u67e5\u8be2");  
  116.         btnQuery.addActionListener(new java.awt.event.ActionListener() {  
  117.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  118.                 btnQueryActionPerformed(evt);  
  119.             }  
  120.         });  
  121.         add(btnQuery);  
  122.         btnQuery.setBounds(3104109350);  
  123.     }// </editor-fold>  
  124.     //GEN-END:initComponents  
  125.   
  126.     private void btnQueryActionPerformed(java.awt.event.ActionEvent evt) {  
  127.         mainFrame.setContentPane(new QueryPanel(mainFrame));  
  128.         mainFrame.validate();  
  129.     }  
  130.   
  131.     private void jListInMainValueChanged(  
  132.             javax.swing.event.ListSelectionEvent evt) {  
  133.         InMainModel inMain = (InMainModel) jListInMain.getSelectedValue();  
  134.         List<InDetailModel> details = map.get(inMain);  
  135.         jListInDetails.setListData(details.toArray());  
  136.     }  
  137.   
  138.     private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {  
  139.         mainFrame.setContentPane(new AddPanel(mainFrame));  
  140.         mainFrame.validate();  
  141.     }  
  142.   
  143.     //GEN-BEGIN:variables  
  144.     // Variables declaration - do not modify  
  145.     private javax.swing.JButton btnAdd;  
  146.     private javax.swing.JButton btnQuery;  
  147.     private javax.swing.JLabel jLabel1;  
  148.     private javax.swing.JList jListInDetails;  
  149.     private javax.swing.JList jListInMain;  
  150.     private javax.swing.JScrollPane jScrollPane1;  
  151.     private javax.swing.JScrollPane jScrollPane2;  
  152.     // End of variables declaration//GEN-END:variables  
  153.   
  154. }  
添加:

[java] view plain copy
 技术分享技术分享
  1. /* 
  2.  * AddPanel.java 
  3.  * 
  4.  * Created on __DATE__, __TIME__ 
  5.  */  
  6.   
  7. package cn.hncu.in.ui;  
  8.   
  9. import java.util.ArrayList;  
  10. import java.util.List;  
  11.   
  12. import javax.swing.JFrame;  
  13. import javax.swing.JOptionPane;  
  14. import javax.swing.JPanel;  
  15.   
  16. import cn.hncu.book.business.factory.BookEbiFactory;  
  17. import cn.hncu.book.vo.BookModel;  
  18. import cn.hncu.in.business.factory.InMainEbiFactory;  
  19. import cn.hncu.in.vo.InDetailModel;  
  20. import cn.hncu.in.vo.InMainModel;  
  21. import cn.hncu.user.business.factory.UserEbiFactory;  
  22. import cn.hncu.user.vo.UserModel;  
  23.   
  24. /** 
  25.  * 
  26.  * @author  __USER__ 
  27.  */  
  28. public class AddPanel extends JPanel {  
  29.     private JFrame mainFrame = null;  
  30.     private List<InDetailModel> details = new ArrayList<InDetailModel>();  
  31.   
  32.     /** Creates new form AddPanel */  
  33.     public AddPanel(JFrame mainFrame) {  
  34.         this.setOpaque(false);  
  35.         this.mainFrame = mainFrame;  
  36.         initComponents();  
  37.         myInit();  
  38.     }  
  39.   
  40.     private void myInit() {  
  41.         List<BookModel> books = BookEbiFactory.getBookEbi().getAll();  
  42.         for (BookModel book : books) {  
  43.             combBook.addItem(book);  
  44.         }  
  45.   
  46.         List<UserModel> users = UserEbiFactory.getUserEbi().getAllIn();  
  47.         for (UserModel user : users) {  
  48.             combUser.addItem(user.getName());  
  49.         }  
  50.     }  
  51.   
  52.     /** This method is called from within the constructor to 
  53.      * initialize the form. 
  54.      * WARNING: Do NOT modify this code. The content of this method is 
  55.      * always regenerated by the Form Editor. 
  56.      */  
  57.     //GEN-BEGIN:initComponents  
  58.     // <editor-fold defaultstate="collapsed" desc="Generated Code">  
  59.     private void initComponents() {  
  60.   
  61.         jLabel1 = new javax.swing.JLabel();  
  62.         jLabel2 = new javax.swing.JLabel();  
  63.         combBook = new javax.swing.JComboBox();  
  64.         jLabel3 = new javax.swing.JLabel();  
  65.         tfdInAmount = new javax.swing.JTextField();  
  66.         btnAddDetails = new javax.swing.JButton();  
  67.         jLabel4 = new javax.swing.JLabel();  
  68.         combUser = new javax.swing.JComboBox();  
  69.         jLabel5 = new javax.swing.JLabel();  
  70.         jScrollPane1 = new javax.swing.JScrollPane();  
  71.         inDetailList = new javax.swing.JList();  
  72.         btnAdd = new javax.swing.JButton();  
  73.         btnBack = new javax.swing.JButton();  
  74.   
  75.         setLayout(null);  
  76.   
  77.         jLabel1.setFont(new java.awt.Font("Microsoft YaHei UI"124));  
  78.         jLabel1.setForeground(new java.awt.Color(5125551));  
  79.         jLabel1.setText("\u6dfb\u52a0\u8fdb\u8d27");  
  80.         add(jLabel1);  
  81.         jLabel1.setBounds(3601014090);  
  82.   
  83.         jLabel2.setForeground(new java.awt.Color(5125551));  
  84.         jLabel2.setText("\u56fe\u4e66\uff1a");  
  85.         add(jLabel2);  
  86.         jLabel2.setBounds(1501106040);  
  87.   
  88.         combBook.setModel(new javax.swing.DefaultComboBoxModel(  
  89.                 new String[] { "请选择..." }));  
  90.         combBook.addActionListener(new java.awt.event.ActionListener() {  
  91.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  92.                 combBookActionPerformed(evt);  
  93.             }  
  94.         });  
  95.         add(combBook);  
  96.         combBook.setBounds(21012016026);  
  97.   
  98.         jLabel3.setForeground(new java.awt.Color(5125551));  
  99.         jLabel3.setText("\u8fdb\u8d27\u6570\u91cf\uff1a");  
  100.         add(jLabel3);  
  101.         jLabel3.setBounds(1201708040);  
  102.         add(tfdInAmount);  
  103.         tfdInAmount.setBounds(21018013026);  
  104.   
  105.         btnAddDetails.setText("\u6dfb\u52a0\u660e\u7ec6");  
  106.         btnAddDetails.addActionListener(new java.awt.event.ActionListener() {  
  107.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  108.                 btnAddDetailsActionPerformed(evt);  
  109.             }  
  110.         });  
  111.         add(btnAddDetails);  
  112.         btnAddDetails.setBounds(5301809330);  
  113.   
  114.         jLabel4.setForeground(new java.awt.Color(5125551));  
  115.         jLabel4.setText("\u8fdb\u8d27\u4eba\uff1a");  
  116.         add(jLabel4);  
  117.         jLabel4.setBounds(4601107040);  
  118.   
  119.         combUser.setModel(new javax.swing.DefaultComboBoxModel(  
  120.                 new String[] { "请选择..." }));  
  121.         add(combUser);  
  122.         combUser.setBounds(53012013026);  
  123.   
  124.         jLabel5.setForeground(new java.awt.Color(5125551));  
  125.         jLabel5.setText("\u660e\u7ec6\u5217\u8868\uff1a");  
  126.         add(jLabel5);  
  127.         jLabel5.setBounds(1202209030);  
  128.   
  129.         inDetailList.setModel(new javax.swing.AbstractListModel() {  
  130.             String[] strings = { "" };  
  131.   
  132.             public int getSize() {  
  133.                 return strings.length;  
  134.             }  
  135.   
  136.             public Object getElementAt(int i) {  
  137.                 return strings[i];  
  138.             }  
  139.         });  
  140.         jScrollPane1.setViewportView(inDetailList);  
  141.   
  142.         add(jScrollPane1);  
  143.         jScrollPane1.setBounds(210230270200);  
  144.   
  145.         btnAdd.setText("\u6dfb\u52a0");  
  146.         btnAdd.addActionListener(new java.awt.event.ActionListener() {  
  147.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  148.                 btnAddActionPerformed(evt);  
  149.             }  
  150.         });  
  151.         add(btnAdd);  
  152.         btnAdd.setBounds(2804706329);  
  153.   
  154.         btnBack.setText("\u8fd4\u56de");  
  155.         btnBack.addActionListener(new java.awt.event.ActionListener() {  
  156.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  157.                 btnBackActionPerformed(evt);  
  158.             }  
  159.         });  
  160.         add(btnBack);  
  161.         btnBack.setBounds(4504706329);  
  162.     }// </editor-fold>  
  163.     //GEN-END:initComponents  
  164.   
  165.     private void combBookActionPerformed(java.awt.event.ActionEvent evt) {  
  166.         tfdInAmount.setText(null);  
  167.     }  
  168.   
  169.     private void btnAddDetailsActionPerformed(java.awt.event.ActionEvent evt) {  
  170.         //收集参数  
  171.         BookModel book = (BookModel) combBook.getSelectedItem();  
  172.         String bookUuid = book.getUuid();  
  173.   
  174.         int sumNum = 0;  
  175.         try {  
  176.             sumNum = Integer.parseInt(tfdInAmount.getText());  
  177.             if (sumNum < 0) {  
  178.                 throw new NumberFormatException();  
  179.             }  
  180.         } catch (NumberFormatException e) {  
  181.             JOptionPane.showMessageDialog(null"进货数量信息输入格式不正确");  
  182.         }  
  183.   
  184.         //组织参数  
  185.         InDetailModel detail = new InDetailModel();  
  186.         detail.setBookUuid(bookUuid);  
  187.         detail.setSumNum(sumNum);  
  188.         detail.setBookName(book.getName());  
  189.         details.add(detail);  
  190.         echoDetails();  
  191.     }  
  192.   
  193.     private void echoDetails() {  
  194.         String echoStrs[] = new String[details.size()];  
  195.         for (int i = 0; i < details.size(); i++) {  
  196.             InDetailModel detail = details.get(i);  
  197.             String bookName = BookEbiFactory.getBookEbi().getSingle(  
  198.                     detail.getBookUuid()).getName();  
  199.             echoStrs[i] = "《" + bookName + "》," + detail.getSumNum() + "本";  
  200.         }  
  201.         inDetailList.setListData(echoStrs);  
  202.     }  
  203.   
  204.     private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {  
  205.         mainFrame.setContentPane(new ListPanel(mainFrame));  
  206.         mainFrame.validate();  
  207.     }  
  208.   
  209.     private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {  
  210.         //收集参数  
  211.         String inUserName = combUser.getSelectedItem().toString();  
  212.         String inUserUuid = UserEbiFactory.getUserEbi().getUserByName(  
  213.                 inUserName).getUuid();  
  214.   
  215.         //组织参数  
  216.         InMainModel inMain = new InMainModel();  
  217.         inMain.setInUserId(inUserUuid);  
  218.         inMain.setInUserName(inUserName);  
  219.   
  220.         //调用逻辑层  
  221.         InMainEbiFactory.getInMainEbi().create(inMain, details);  
  222.   
  223.         mainFrame.setContentPane(new ListPanel(mainFrame));  
  224.         mainFrame.validate();  
  225.     }  
  226.   
  227.     //GEN-BEGIN:variables  
  228.     // Variables declaration - do not modify  
  229.     private javax.swing.JButton btnAdd;  
  230.     private javax.swing.JButton btnAddDetails;  
  231.     private javax.swing.JButton btnBack;  
  232.     private javax.swing.JComboBox combBook;  
  233.     private javax.swing.JComboBox combUser;  
  234.     private javax.swing.JList inDetailList;  
  235.     private javax.swing.JLabel jLabel1;  
  236.     private javax.swing.JLabel jLabel2;  
  237.     private javax.swing.JLabel jLabel3;  
  238.     private javax.swing.JLabel jLabel4;  
  239.     private javax.swing.JLabel jLabel5;  
  240.     private javax.swing.JScrollPane jScrollPane1;  
  241.     private javax.swing.JTextField tfdInAmount;  
  242.     // End of variables declaration//GEN-END:variables  
  243.   
  244. }  
查询:

[java] view plain copy
 技术分享技术分享
  1. /* 
  2.  * QueryPanel.java 
  3.  * 
  4.  * Created on __DATE__, __TIME__ 
  5.  */  
  6.   
  7. package cn.hncu.in.ui;  
  8.   
  9. import java.util.List;  
  10. import java.util.Map;  
  11.   
  12. import javax.swing.JFrame;  
  13. import javax.swing.JOptionPane;  
  14.   
  15. import cn.hncu.book.business.factory.BookEbiFactory;  
  16. import cn.hncu.book.vo.BookModel;  
  17. import cn.hncu.in.business.factory.InMainEbiFactory;  
  18. import cn.hncu.in.vo.InDetailModel;  
  19. import cn.hncu.in.vo.InDetailQueryModel;  
  20. import cn.hncu.in.vo.InMainModel;  
  21. import cn.hncu.in.vo.InMainQueryModel;  
  22. import cn.hncu.user.business.factory.UserEbiFactory;  
  23. import cn.hncu.user.vo.UserModel;  
  24. import cn.hncu.utils.DateUtil;  
  25.   
  26. /** 
  27.  * 
  28.  * @author  __USER__ 
  29.  */  
  30. public class QueryPanel extends javax.swing.JPanel {  
  31.     private JFrame mainFrame = null;  
  32.   
  33.     /** Creates new form QueryPanel */  
  34.     public QueryPanel(JFrame mainFrame) {  
  35.         this.mainFrame = mainFrame;  
  36.         initComponents();  
  37.         myInit();  
  38.     }  
  39.   
  40.     private void myInit() {  
  41.         List<UserModel> userList = UserEbiFactory.getUserEbi().getAllIn();  
  42.         for (UserModel user : userList) {  
  43.             combInUser.addItem(user);  
  44.         }  
  45.   
  46.         List<BookModel> books = BookEbiFactory.getBookEbi().getAll();  
  47.         for (BookModel book : books) {  
  48.             combBook.addItem(book);  
  49.         }  
  50.     }  
  51.   
  52.     /** This method is called from within the constructor to 
  53.      * initialize the form. 
  54.      * WARNING: Do NOT modify this code. The content of this method is 
  55.      * always regenerated by the Form Editor. 
  56.      */  
  57.     //GEN-BEGIN:initComponents  
  58.     // <editor-fold defaultstate="collapsed" desc="Generated Code">  
  59.     private void initComponents() {  
  60.   
  61.         jLabel1 = new javax.swing.JLabel();  
  62.         jLabel2 = new javax.swing.JLabel();  
  63.         jLabel3 = new javax.swing.JLabel();  
  64.         jLabel4 = new javax.swing.JLabel();  
  65.         jLabel5 = new javax.swing.JLabel();  
  66.         jLabel6 = new javax.swing.JLabel();  
  67.         jLabel7 = new javax.swing.JLabel();  
  68.         jLabel8 = new javax.swing.JLabel();  
  69.         jLabel9 = new javax.swing.JLabel();  
  70.         jLabel11 = new javax.swing.JLabel();  
  71.         jLabel12 = new javax.swing.JLabel();  
  72.         jLabel13 = new javax.swing.JLabel();  
  73.         tfdSumMoney2 = new javax.swing.JTextField();  
  74.         tfdUuid = new javax.swing.JTextField();  
  75.         tfdInDetailUuid = new javax.swing.JTextField();  
  76.         tfdDate = new javax.swing.JTextField();  
  77.         tfdDate2 = new javax.swing.JTextField();  
  78.         tfdInNum = new javax.swing.JTextField();  
  79.         tfdInNum2 = new javax.swing.JTextField();  
  80.         tfdSumMoney = new javax.swing.JTextField();  
  81.         combBook = new javax.swing.JComboBox();  
  82.         combInUser = new javax.swing.JComboBox();  
  83.         btnQuery = new javax.swing.JButton();  
  84.         btnBack = new javax.swing.JButton();  
  85.   
  86.         setLayout(null);  
  87.   
  88.         jLabel1.setFont(new java.awt.Font("Microsoft YaHei UI"124));  
  89.         jLabel1.setForeground(new java.awt.Color(5125551));  
  90.         jLabel1.setText("\u8fdb\u8d27\u67e5\u8be2");  
  91.         add(jLabel1);  
  92.         jLabel1.setBounds(3101012060);  
  93.   
  94.         jLabel2.setText("\u56fe\u4e66\uff1a");  
  95.         add(jLabel2);  
  96.         jLabel2.setBounds(4602506020);  
  97.   
  98.         jLabel3.setText("\u8fdb\u8d27\u8d77\u59cb\u65f6\u95f4\uff1a");  
  99.         add(jLabel3);  
  100.         jLabel3.setBounds(9017012020);  
  101.   
  102.         jLabel4.setText("\u8fdb\u8d27\u4eba\uff1a");  
  103.         add(jLabel4);  
  104.         jLabel4.setBounds(4501108020);  
  105.   
  106.         jLabel5.setText("\u8fdb\u8d27\u5355\u7f16\u53f7\uff1a");  
  107.         add(jLabel5);  
  108.         jLabel5.setBounds(10011011020);  
  109.   
  110.         jLabel6.setText("\u8fdb\u8d27\u6700\u5927\u91cf\uff1a");  
  111.         add(jLabel6);  
  112.         jLabel6.setBounds(41033010020);  
  113.   
  114.         jLabel7.setText("\u8fdb\u8d27\u6700\u5c0f\u91cf\uff1a");  
  115.         add(jLabel7);  
  116.         jLabel7.setBounds(10033013020);  
  117.   
  118.         jLabel8.setText("\u8fdb\u8d27\u660e\u7ec6\u7f16\u53f7\uff1a");  
  119.         add(jLabel8);  
  120.         jLabel8.setBounds(9025013020);  
  121.   
  122.         jLabel9.setText("\u8fdb\u8d27\u7ed3\u675f\u65f6\u95f4\uff1a");  
  123.         add(jLabel9);  
  124.         jLabel9.setBounds(40017012020);  
  125.   
  126.         jLabel11.setText("\u683c\u5f0f\u5982\uff1a2016-04-01");  
  127.         add(jLabel11);  
  128.         jLabel11.setBounds(11020017020);  
  129.   
  130.         jLabel12.setText("\u8fdb\u8d27\u603b\u4ef7\u6700\u5927\u503c\uff1a");  
  131.         add(jLabel12);  
  132.         jLabel12.setBounds(38040014020);  
  133.   
  134.         jLabel13.setText("\u8fdb\u8d27\u603b\u4ef7\u6700\u5c0f\u503c\uff1a");  
  135.         add(jLabel13);  
  136.         jLabel13.setBounds(7040013020);  
  137.         add(tfdSumMoney2);  
  138.         tfdSumMoney2.setBounds(53040013030);  
  139.         add(tfdUuid);  
  140.         tfdUuid.setBounds(20011013030);  
  141.         add(tfdInDetailUuid);  
  142.         tfdInDetailUuid.setBounds(20025013030);  
  143.         add(tfdDate);  
  144.         tfdDate.setBounds(20017013030);  
  145.         add(tfdDate2);  
  146.         tfdDate2.setBounds(53017013030);  
  147.         add(tfdInNum);  
  148.         tfdInNum.setBounds(20033013030);  
  149.         add(tfdInNum2);  
  150.         tfdInNum2.setBounds(53033013030);  
  151.         add(tfdSumMoney);  
  152.         tfdSumMoney.setBounds(20040013030);  
  153.   
  154.         combBook.setModel(new javax.swing.DefaultComboBoxModel(  
  155.                 new String[] { "查询所有" }));  
  156.         add(combBook);  
  157.         combBook.setBounds(53025013026);  
  158.   
  159.         combInUser.setModel(new javax.swing.DefaultComboBoxModel(  
  160.                 new String[] { "查询所有" }));  
  161.         add(combInUser);  
  162.         combInUser.setBounds(53011013026);  
  163.   
  164.         btnQuery.setFont(new java.awt.Font("Microsoft YaHei UI"118));  
  165.         btnQuery.setText("\u67e5\u8be2");  
  166.         btnQuery.addActionListener(new java.awt.event.ActionListener() {  
  167.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  168.                 btnQueryActionPerformed(evt);  
  169.             }  
  170.         });  
  171.         add(btnQuery);  
  172.         btnQuery.setBounds(2104608040);  
  173.   
  174.         btnBack.setFont(new java.awt.Font("Microsoft YaHei UI"118));  
  175.         btnBack.setText("\u8fd4\u56de");  
  176.         btnBack.addActionListener(new java.awt.event.ActionListener() {  
  177.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  178.                 btnBackActionPerformed(evt);  
  179.             }  
  180.         });  
  181.         add(btnBack);  
  182.         btnBack.setBounds(4204608040);  
  183.     }// </editor-fold>  
  184.     //GEN-END:initComponents  
  185.   
  186.     private void btnQueryActionPerformed(java.awt.event.ActionEvent evt) {  
  187.         //收集参数  
  188.         String inUuid = tfdUuid.getText();  
  189.         String inUserName = (String) combInUser.getSelectedItem();  
  190.         String inUserUuid = null;  
  191.         if (combInUser.getSelectedIndex() > 0) {  
  192.             inUserUuid = UserEbiFactory.getUserEbi().getUserByName(inUserName)  
  193.                     .getUuid();  
  194.         }  
  195.   
  196.         String txtInDate = tfdDate.getText();  
  197.         long inDate = 0;  
  198.         if (txtInDate != null && txtInDate.trim().length() > 0) {  
  199.             txtInDate += " 00:00:00";  
  200.             inDate = DateUtil.StringToLong(txtInDate, "进货起始时间输入格式错误!");  
  201.             if (inDate == -1) {  
  202.                 return;  
  203.             }  
  204.         }  
  205.   
  206.         String txtInDate2 = tfdDate2.getText();  
  207.         long inDate2 = 0;  
  208.         if (txtInDate2 != null && txtInDate2.trim().length() > 0) {  
  209.             txtInDate2 += " 23:59:59";  
  210.             inDate2 = DateUtil.StringToLong(txtInDate2, "进货结束时间输入格式错误!");  
  211.             if (inDate2 == -1) {  
  212.                 return;  
  213.             }  
  214.         }  
  215.   
  216.         String inDetailUuid = tfdInDetailUuid.getText();  
  217.   
  218.         String bookUuid = null;  
  219.         if (combBook.getSelectedIndex() > 0) {  
  220.             String bookName = combBook.getSelectedItem().toString();  
  221.             bookUuid = BookEbiFactory.getBookEbi().getSingle(bookName)  
  222.                     .getUuid();  
  223.         }  
  224.   
  225.         int sumNum = 0;  
  226.         if (tfdInNum.getText() != null  
  227.                 && tfdInNum.getText().trim().length() > 0) {  
  228.             try {  
  229.                 sumNum = Integer.parseInt(tfdInNum.getText());  
  230.                 if (sumNum < 0) {  
  231.                     throw new NumberFormatException();  
  232.                 }  
  233.             } catch (NumberFormatException e) {  
  234.                 JOptionPane.showMessageDialog(null"进货最小量格式输入错误!");  
  235.             }  
  236.         }  
  237.   
  238.         int sumNum2 = 0;  
  239.         if (tfdInNum2.getText() != null  
  240.                 && tfdInNum2.getText().trim().length() > 0) {  
  241.             try {  
  242.                 sumNum2 = Integer.parseInt(tfdInNum2.getText());  
  243.                 if (sumNum2 < 0) {  
  244.                     throw new NumberFormatException();  
  245.                 }  
  246.             } catch (NumberFormatException e) {  
  247.                 JOptionPane.showMessageDialog(null"进货最大量格式输入错误!");  
  248.             }  
  249.         }  
  250.   
  251.         double sumMoney = 0;  
  252.         if (tfdSumMoney.getText() != null  
  253.                 && tfdSumMoney.getText().trim().length() > 0) {  
  254.             try {  
  255.                 sumMoney = Integer.parseInt(tfdSumMoney.getText());  
  256.                 if (sumMoney < 0) {  
  257.                     throw new NumberFormatException();  
  258.                 }  
  259.             } catch (NumberFormatException e) {  
  260.                 JOptionPane.showMessageDialog(null"进货最小量格式输入错误!");  
  261.             }  
  262.         }  
  263.   
  264.         double sumMoney2 = 0;  
  265.         if (tfdSumMoney2.getText() != null  
  266.                 && tfdSumMoney2.getText().trim().length() > 0) {  
  267.             try {  
  268.                 sumMoney2 = Integer.parseInt(tfdSumMoney2.getText());  
  269.                 if (sumMoney2 < 0) {  
  270.                     throw new NumberFormatException();  
  271.                 }  
  272.             } catch (NumberFormatException e) {  
  273.                 JOptionPane.showMessageDialog(null"进货最小量格式输入错误!");  
  274.             }  
  275.         }  
  276.   
  277.         //组织参数-------分别组织InMainQueryModel和InDetailQueryModel  
  278.         InMainQueryModel imqm = new InMainQueryModel();  
  279.         imqm.setInDate(inDate);  
  280.         imqm.setInDate2(inDate2);  
  281.         imqm.setInUserId(inUserUuid);  
  282.         imqm.setInUserName(inUserName);  
  283.         imqm.setUuid(inUuid);  
  284.   
  285.         InDetailQueryModel idqm = new InDetailQueryModel();  
  286.         idqm.setBookUuid(bookUuid);  
  287.         idqm.setUuid(inDetailUuid);  
  288.         idqm.setSumMoney(sumMoney);  
  289.         idqm.setSumMoney2(sumMoney2);  
  290.         idqm.setSumNum(sumNum);  
  291.         idqm.setSumNum2(sumNum2);  
  292.   
  293.         //调用逻辑层  
  294.         Map<InMainModel, List<InDetailModel>> map = InMainEbiFactory  
  295.                 .getInMainEbi().getByCondition(imqm, idqm);  
  296.   
  297.         //返回到结果页面  
  298.         mainFrame.setContentPane(new ListPanel(mainFrame, map));  
  299.         mainFrame.validate();  
  300.     }  
  301.   
  302.     private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {  
  303.         mainFrame.setContentPane(new ListPanel(mainFrame));  
  304.         mainFrame.validate();  
  305.     }  
  306.   
  307.     //GEN-BEGIN:variables  
  308.     // Variables declaration - do not modify  
  309.     private javax.swing.JButton btnBack;  
  310.     private javax.swing.JButton btnQuery;  
  311.     private javax.swing.JComboBox combBook;  
  312.     private javax.swing.JComboBox combInUser;  
  313.     private javax.swing.JLabel jLabel1;  
  314.     private javax.swing.JLabel jLabel11;  
  315.     private javax.swing.JLabel jLabel12;  
  316.     private javax.swing.JLabel jLabel13;  
  317.     private javax.swing.JLabel jLabel2;  
  318.     private javax.swing.JLabel jLabel3;  
  319.     private javax.swing.JLabel jLabel4;  
  320.     private javax.swing.JLabel jLabel5;  
  321.     private javax.swing.JLabel jLabel6;  
  322.     private javax.swing.JLabel jLabel7;  
  323.     private javax.swing.JLabel jLabel8;  
  324.     private javax.swing.JLabel jLabel9;  
  325.     private javax.swing.JTextField tfdDate;  
  326.     private javax.swing.JTextField tfdDate2;  
  327.     private javax.swing.JTextField tfdInDetailUuid;  
  328.     private javax.swing.JTextField tfdInNum;  
  329.     private javax.swing.JTextField tfdInNum2;  
  330.     private javax.swing.JTextField tfdSumMoney;  
  331.     private javax.swing.JTextField tfdSumMoney2;  
  332.     private javax.swing.JTextField tfdUuid;  
  333.     // End of variables declaration//GEN-END:variables  
  334.   
  335. }  



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

标签:

原文地址:http://blog.csdn.net/x121850182/article/details/51496622

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!