书店管理系统
书店管理系统可以说是设计模式及设计思想的一个比较经典的例子。
本系列将分为多个部分讲述此输电管理系统。
书店管理系统将分为:用户、图书、进货、销售和库存五个模块,另外还有公共包、工具包和登录包,另外还有一个框架。
对于分层设计,都是表现层可以调用逻辑层,逻辑层调用数据层,数据层调用工具和公共包,方向不可打乱,必须严格按照这种模式。
本篇将做销售模块。
注:本篇需要使用到的框架在本系列二的用户模块:
链接:http://blog.csdn.net/x121850182/article/details/51362269
和进货模块相同的,进货模块分成了数据层、逻辑层、表现层和值对象层,数据层也要多出一个进货明细。
销售模块和进货模块其实是一摸一样的,可以直接对拷,就只要更改里面的名字即可。
数据层:
接口:
OutMainDAO
-
package cn.hncu.out.dao.dao;
-
-
import java.util.List;
-
-
import cn.hncu.out.vo.OutMainModel;
-
import cn.hncu.out.vo.OutMainQueryModel;
-
-
public interface OutMainDAO {
-
public boolean create(OutMainModel outMain);
-
public boolean delete(String uuid);
-
public boolean upDate(OutMainModel outMain);
-
-
public OutMainModel getSingle(String uuid);
-
public List<OutMainModel> getAll();
-
public List<OutMainModel> getByCondition(OutMainQueryModel imqm);
-
}
OutDetailDAO
-
package cn.hncu.out.dao.dao;
-
-
import java.util.List;
-
-
import cn.hncu.out.vo.OutDetailModel;
-
import cn.hncu.out.vo.OutDetailQueryModel;
-
-
public interface OutDetailDAO {
-
public boolean create(OutDetailModel outDetail);
-
public boolean delete(String uuid);
-
public boolean upDate(OutDetailModel outDetail);
-
-
public OutDetailModel getSingle(String uuid);
-
public List<OutDetailModel> getAll();
-
public List<OutDetailModel> getByCondition(OutDetailQueryModel idqm);
-
}
实现类:
OutMainDAOImpl
-
package cn.hncu.out.dao.impl;
-
-
import java.util.ArrayList;
-
import java.util.List;
-
-
import cn.hncu.out.dao.dao.OutMainDAO;
-
import cn.hncu.out.vo.OutMainModel;
-
import cn.hncu.out.vo.OutMainQueryModel;
-
import cn.hncu.utils.FileIo;
-
-
public class OutMainDAOImpl implements OutMainDAO {
-
private final String FILE_NAME="OutMain.txt";
-
@Override
-
public boolean create(OutMainModel outMain) {
-
List<OutMainModel> list=FileIo.read(FILE_NAME);
-
for (OutMainModel model:list){
-
if (model.getUuid().equals(outMain.getUuid())){
-
return false;
-
}
-
}
-
list.add(outMain);
-
FileIo.write(list, FILE_NAME);
-
return true;
-
}
-
-
@Override
-
public boolean delete(String uuid) {
-
List<OutMainModel> list=FileIo.read(FILE_NAME);
-
for (OutMainModel model:list){
-
if (model.getUuid().equals(uuid)){
-
list.remove(model);
-
FileIo.write(list, FILE_NAME);
-
return true;
-
}
-
}
-
return false;
-
}
-
-
@Override
-
public List<OutMainModel> getAll() {
-
List<OutMainModel> list=FileIo.read(FILE_NAME);
-
return list;
-
}
-
-
@Override
-
public List<OutMainModel> getByCondition(OutMainQueryModel omqm) {
-
List<OutMainModel> list=getAll();
-
List<OutMainModel> result=new ArrayList<OutMainModel>();
-
for (OutMainModel outMain:list){
-
if (omqm.getUuid()!=null&&omqm.getUuid().trim().length()>0){
-
if (!omqm.getUuid().equals(outMain.getUuid())){
-
continue;
-
}
-
}
-
if (omqm.getOutUserId()!=null&&omqm.getOutUserId().trim().length()>0){
-
if (!omqm.getOutUserId().equals(outMain.getOutUserId())){
-
continue;
-
}
-
}
-
if (omqm.getOutDate()>0){
-
if (omqm.getOutDate()>outMain.getOutDate()){
-
continue;
-
}
-
}
-
if (omqm.getOutDate2()>0){
-
if (omqm.getOutDate2()<outMain.getOutDate()){
-
continue;
-
}
-
}
-
result.add(outMain);
-
}
-
-
return result;
-
}
-
-
@Override
-
public OutMainModel getSingle(String uuid) {
-
List<OutMainModel> list=FileIo.read(FILE_NAME);
-
for (OutMainModel model:list){
-
if (model.getUuid().equals(uuid)){
-
return model;
-
}
-
}
-
return null;
-
}
-
-
@Override
-
public boolean upDate(OutMainModel outMain) {
-
List<OutMainModel> list=FileIo.read(FILE_NAME);
-
for (int i=0;i<list.size();i++){
-
OutMainModel model=list.get(i);
-
if (model.getUuid().equals(outMain.getUuid())){
-
list.set(i, outMain);
-
return true;
-
}
-
}
-
return false;
-
}
-
}
OutDetailDAOImpl
工厂类:
OutMainDAOFactory
-
package cn.hncu.out.dao.factory;
-
-
import cn.hncu.out.dao.dao.OutMainDAO;
-
import cn.hncu.out.dao.impl.OutMainDAOImpl;
-
-
public class OutMainDAOFactory {
-
public static OutMainDAO getOutMainDAO(){
-
return new OutMainDAOImpl();
-
}
-
}
OutDetailDAOFactory
-
package cn.hncu.out.dao.factory;
-
-
import cn.hncu.out.dao.dao.OutDetailDAO;
-
import cn.hncu.out.dao.impl.OutDetailDAOImpl;
-
-
public class OutDetailDAOFactory {
-
public static OutDetailDAO getOutDetailDAO(){
-
return new OutDetailDAOImpl();
-
}
-
}
逻辑层:
接口:
-
package cn.hncu.out.business.ebi;
-
-
import java.util.List;
-
import java.util.Map;
-
-
import cn.hncu.out.vo.OutDetailModel;
-
import cn.hncu.out.vo.OutDetailQueryModel;
-
import cn.hncu.out.vo.OutMainModel;
-
import cn.hncu.out.vo.OutMainQueryModel;
-
-
public interface OutMainEbi {
-
public boolean create(OutMainModel outMain,List<OutDetailModel> details);
-
public Map<OutMainModel, List<OutDetailModel>> getAll();
-
public Map<OutMainModel, List<OutDetailModel>> getByCondition(OutMainQueryModel omqm,OutDetailQueryModel idqm);
-
}
实现类:
-
package cn.hncu.out.business.ebo;
-
-
import java.util.List;
-
import java.util.Map;
-
import java.util.TreeMap;
-
-
import javax.swing.JOptionPane;
-
-
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.out.business.ebi.OutMainEbi;
-
import cn.hncu.out.dao.dao.OutDetailDAO;
-
import cn.hncu.out.dao.dao.OutMainDAO;
-
import cn.hncu.out.dao.factory.OutDetailDAOFactory;
-
import cn.hncu.out.dao.factory.OutMainDAOFactory;
-
import cn.hncu.out.vo.OutDetailModel;
-
import cn.hncu.out.vo.OutDetailQueryModel;
-
import cn.hncu.out.vo.OutMainModel;
-
import cn.hncu.out.vo.OutMainQueryModel;
-
import cn.hncu.stock.business.factory.StockEbiFactory;
-
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 OutMainEbo implements OutMainEbi {
-
OutMainDAO outMainDAO=OutMainDAOFactory.getOutMainDAO();
-
OutDetailDAO outDetailDAO=OutDetailDAOFactory.getOutDetailDAO();
-
UuidDAO uuidDAO=UuidDAOFactory.getUuidDAO();
-
BookEbi bookEbi=BookEbiFactory.getBookEbi();
-
-
@Override
-
public boolean create(OutMainModel outMain, List<OutDetailModel> details) {
-
-
-
-
StockDAO stockDAO=StockDAOFactory.getStockDAO();
-
for (OutDetailModel detail:details){
-
StockQueryModel sqm=new StockQueryModel();
-
sqm.setBookUuid(detail.getBookUuid());
-
List<StockModel> list = stockDAO.getByCondition(sqm);
-
if (list==null||list.size()==0){
-
JOptionPane.showMessageDialog(null, "库存中不存在《"+detail.getBookName()+"》,本次销售添加失败!");
-
return false;
-
}else {
-
StockModel stock=list.get(0);
-
if (stock.getSumNum()<detail.getSumNum()){
-
JOptionPane.showMessageDialog(null, "库存中《"+detail.getBookName()+"》数量不足,本次销售添加失败!");
-
return false;
-
}
-
}
-
}
-
-
-
-
-
-
String outUuid=uuidDAO.getNextUuid(UuidModelConstance.OUT_MAIN);
-
outMain.setUuid(outUuid);
-
outMain.setOutDate(System.currentTimeMillis());
-
outMainDAO.create(outMain);
-
-
-
for (OutDetailModel outDetail:details){
-
-
-
-
outDetail.setUuid(uuidDAO.getNextUuid(UuidModelConstance.OUT_DETAIL));
-
outDetail.setOutUuid(outUuid);
-
double sumMoney=outDetail.getSumNum()*bookEbi.getSingle(outDetail.getBookUuid()).getSalePrice();
-
outDetail.setSumMoney(sumMoney);
-
outDetailDAO.create(outDetail);
-
-
-
StockQueryModel sqm=new StockQueryModel();
-
sqm.setBookUuid(outDetail.getBookUuid());
-
List<StockModel> list = StockEbiFactory.getStockEbi().getByCondition(sqm);
-
StockModel stock=list.get(0);
-
stock.setSumNum(stock.getSumNum()-outDetail.getSumNum());
-
stockDAO.upDate(stock);
-
}
-
-
return true;
-
}
-
-
@Override
-
public Map<OutMainModel, List<OutDetailModel>> getAll() {
-
Map<OutMainModel, List<OutDetailModel>> map=new TreeMap<OutMainModel, List<OutDetailModel>>();
-
List<OutMainModel> outMains=outMainDAO.getAll();
-
-
for (OutMainModel outMain:outMains){
-
OutDetailQueryModel odqm=new OutDetailQueryModel();
-
String outUuid=outMain.getUuid();
-
odqm.setOutUuid(outUuid);
-
-
List<OutDetailModel> details=outDetailDAO.getByCondition(odqm);
-
map.put(outMain, details);
-
}
-
-
return map;
-
}
-
-
@Override
-
public Map<OutMainModel, List<OutDetailModel>> getByCondition(
-
OutMainQueryModel omqm, OutDetailQueryModel odqm) {
-
Map<OutMainModel, List<OutDetailModel>> map=new TreeMap<OutMainModel, List<OutDetailModel>>();
-
List<OutMainModel> outMains=OutMainDAOFactory.getOutMainDAO().getByCondition(omqm);
-
-
for (OutMainModel outMain:outMains){
-
odqm.setOutUuid(outMain.getUuid());
-
List<OutDetailModel> details=OutDetailDAOFactory.getOutDetailDAO().getByCondition(odqm);
-
if (details.size()!=0){
-
map.put(outMain, details);
-
}
-
}
-
return map;
-
}
-
}
工厂类:
-
package cn.hncu.out.business.factory;
-
-
import cn.hncu.out.business.ebi.OutMainEbi;
-
import cn.hncu.out.business.ebo.OutMainEbo;
-
-
public class OutMainEbiFactory {
-
public static OutMainEbi getOutMainEbi(){
-
return new OutMainEbo();
-
}
-
}
值对象层:
OutMainModel
-
package cn.hncu.out.vo;
-
-
import java.io.Serializable;
-
-
import cn.hncu.utils.DateUtil;
-
-
public class OutMainModel implements Serializable,Comparable<OutMainModel>{
-
private String uuid;
-
private long outDate;
-
private String outUserId;
-
private String outUserName;
-
-
public String getOutUserName() {
-
return outUserName;
-
}
-
public void setOutUserName(String outUserName) {
-
this.outUserName = outUserName;
-
}
-
public String getUuid() {
-
return uuid;
-
}
-
public void setUuid(String uuid) {
-
this.uuid = uuid;
-
}
-
public long getOutDate() {
-
return outDate;
-
}
-
public void setOutDate(long outDate) {
-
this.outDate = outDate;
-
}
-
public String getOutUserId() {
-
return outUserId;
-
}
-
public void setOutUserId(String outUserId) {
-
this.outUserId = outUserId;
-
}
-
-
@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;
-
OutMainModel other = (OutMainModel) 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 + ", " + outUserName+ ", " + DateUtil.longToString(outDate);
-
}
-
@Override
-
public int compareTo(OutMainModel o) {
-
return Integer.parseInt(uuid)-Integer.parseInt(o.getUuid());
-
}
-
}
OutMainQueryModel
-
package cn.hncu.out.vo;
-
-
public class OutMainQueryModel extends OutMainModel{
-
private long outDate2;
-
-
public long getOutDate2() {
-
return outDate2;
-
}
-
-
public void setOutDate2(long outDate2) {
-
this.outDate2 = outDate2;
-
}
-
}
OutDetailModel
-
package cn.hncu.out.vo;
-
-
import java.io.Serializable;
-
-
public class OutDetailModel implements Serializable{
-
private String uuid;
-
private String outUuid;
-
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 getOutUuid() {
-
return outUuid;
-
}
-
public void setOutUuid(String outUuid) {
-
this.outUuid = outUuid;
-
}
-
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;
-
OutDetailModel other = (OutDetailModel) 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 + "元";
-
}
-
}
OutDetailQueryModel
-
package cn.hncu.out.vo;
-
-
public class OutDetailQueryModel extends OutDetailModel{
-
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;
-
}
-
}
表现层:
与进货模块相同的销售记录要保留所以不能有删除操作,也不能有修改操作,只能通过进货与销售来改变其中保存的值
列表:
-
-
-
-
-
-
-
package cn.hncu.out.ui;
-
-
import java.util.List;
-
import java.util.Map;
-
-
import javax.swing.JFrame;
-
-
import cn.hncu.out.business.factory.OutMainEbiFactory;
-
import cn.hncu.out.vo.OutDetailModel;
-
import cn.hncu.out.vo.OutMainModel;
-
-
-
-
-
-
public class ListPanel extends javax.swing.JPanel {
-
private JFrame mainFrame = null;
-
private Map<OutMainModel, List<OutDetailModel>> map;
-
-
-
public ListPanel(JFrame mainFrame) {
-
this.mainFrame = mainFrame;
-
this.setOpaque(false);
-
initComponents();
-
map = OutMainEbiFactory.getOutMainEbi().getAll();
-
myInit();
-
}
-
-
public ListPanel(JFrame mainFrame,
-
Map<OutMainModel, List<OutDetailModel>> map) {
-
this.mainFrame = mainFrame;
-
this.setOpaque(false);
-
this.map = map;
-
initComponents();
-
myInit();
-
}
-
-
private void myInit() {
-
jListOutMain.setListData(map.keySet().toArray());
-
}
-
-
-
-
private void initComponents() {
-
-
jLabel1 = new javax.swing.JLabel();
-
btnAdd = new javax.swing.JButton();
-
jScrollPane1 = new javax.swing.JScrollPane();
-
jListOutMain = new javax.swing.JList();
-
jScrollPane2 = new javax.swing.JScrollPane();
-
jListOutDetails = 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("\u9500\u552e\u5217\u8868");
-
add(jLabel1);
-
jLabel1.setBounds(360, 30, 130, 90);
-
-
btnAdd.setText("\u6dfb\u52a0\u9500\u552e");
-
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);
-
-
jListOutMain.setModel(new javax.swing.AbstractListModel() {
-
String[] strings = { "" };
-
-
public int getSize() {
-
return strings.length;
-
}
-
-
public Object getElementAt(int i) {
-
return strings[i];
-
}
-
});
-
jListOutMain
-
.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
-
public void valueChanged(
-
javax.swing.event.ListSelectionEvent evt) {
-
jListOutMainValueChanged(evt);
-
}
-
});
-
jScrollPane1.setViewportView(jListOutMain);
-
-
add(jScrollPane1);
-
jScrollPane1.setBounds(110, 140, 260, 240);
-
-
jListOutDetails.setModel(new javax.swing.AbstractListModel() {
-
String[] strings = { "" };
-
-
public int getSize() {
-
return strings.length;
-
}
-
-
public Object getElementAt(int i) {
-
return strings[i];
-
}
-
});
-
jScrollPane2.setViewportView(jListOutDetails);
-
-
add(jScrollPane2);
-
jScrollPane2.setBounds(460, 110, 250, 360);
-
-
btnQuery.setText("\u9500\u552e\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);
-
}
-
-
-
private void btnQueryActionPerformed(java.awt.event.ActionEvent evt) {
-
mainFrame.setContentPane(new QueryPanel(mainFrame));
-
mainFrame.validate();
-
}
-
-
private void jListOutMainValueChanged(
-
javax.swing.event.ListSelectionEvent evt) {
-
OutMainModel outMain = (OutMainModel) jListOutMain.getSelectedValue();
-
List<OutDetailModel> details = map.get(outMain);
-
jListOutDetails.setListData(details.toArray());
-
}
-
-
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
-
mainFrame.setContentPane(new AddPanel(mainFrame));
-
mainFrame.validate();
-
}
-
-
-
-
private javax.swing.JButton btnAdd;
-
private javax.swing.JButton btnQuery;
-
private javax.swing.JLabel jLabel1;
-
private javax.swing.JList jListOutDetails;
-
private javax.swing.JList jListOutMain;
-
private javax.swing.JScrollPane jScrollPane1;
-
private javax.swing.JScrollPane jScrollPane2;
-
-
-
}
添加:
-
-
-
-
-
-
-
package cn.hncu.out.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.out.business.factory.OutMainEbiFactory;
-
import cn.hncu.out.vo.OutDetailModel;
-
import cn.hncu.out.vo.OutMainModel;
-
import cn.hncu.user.business.factory.UserEbiFactory;
-
import cn.hncu.user.vo.UserModel;
-
-
-
-
-
-
public class AddPanel extends JPanel {
-
private JFrame mainFrame = null;
-
private List<OutDetailModel> details = new ArrayList<OutDetailModel>();
-
-
-
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().getAllOut();
-
for (UserModel user : users) {
-
combUser.addItem(user.getName());
-
}
-
}
-
-
-
-
-
-
-
-
-
private void initComponents() {
-
-
jLabel1 = new javax.swing.JLabel();
-
jLabel2 = new javax.swing.JLabel();
-
combBook = new javax.swing.JComboBox();
-
jLabel3 = new javax.swing.JLabel();
-
tfdOutAmount = 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();
-
outDetailList = 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("\u9500\u552e\u6570\u91cf\uff1a");
-
add(jLabel3);
-
jLabel3.setBounds(120, 170, 80, 40);
-
add(tfdOutAmount);
-
tfdOutAmount.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("\u9500\u552e\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);
-
-
outDetailList.setModel(new javax.swing.AbstractListModel() {
-
String[] strings = { "" };
-
-
public int getSize() {
-
return strings.length;
-
}
-
-
public Object getElementAt(int i) {
-
return strings[i];
-
}
-
});
-
jScrollPane1.setViewportView(outDetailList);
-
-
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, 70, 40);
-
-
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, 70, 40);
-
}
-
-
-
private void combBookActionPerformed(java.awt.event.ActionEvent evt) {
-
tfdOutAmount.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(tfdOutAmount.getText());
-
if (sumNum < 0) {
-
throw new NumberFormatException();
-
}
-
} catch (NumberFormatException e) {
-
JOptionPane.showMessageDialog(null, "进货数量信息输入格式不正确");
-
}
-
-
-
OutDetailModel detail = new OutDetailModel();
-
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++) {
-
OutDetailModel detail = details.get(i);
-
String bookName = BookEbiFactory.getBookEbi().getSingle(
-
detail.getBookUuid()).getName();
-
echoStrs[i] = "《" + bookName + "》," + detail.getSumNum() + "本";
-
}
-
outDetailList.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 outUserName = combUser.getSelectedItem().toString();
-
String outUserUuid = UserEbiFactory.getUserEbi().getUserByName(
-
outUserName).getUuid();
-
-
-
OutMainModel outMain = new OutMainModel();
-
outMain.setOutUserId(outUserUuid);
-
outMain.setOutUserName(outUserName);
-
-
-
OutMainEbiFactory.getOutMainEbi().create(outMain, details);
-
-
mainFrame.setContentPane(new ListPanel(mainFrame));
-
mainFrame.validate();
-
}
-
-
-
-
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.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.JList outDetailList;
-
private javax.swing.JTextField tfdOutAmount;
-
-
-
}
查询:
-
-
-
-
-
-
-
package cn.hncu.out.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.out.business.factory.OutMainEbiFactory;
-
import cn.hncu.out.vo.OutDetailModel;
-
import cn.hncu.out.vo.OutDetailQueryModel;
-
import cn.hncu.out.vo.OutMainModel;
-
import cn.hncu.out.vo.OutMainQueryModel;
-
import cn.hncu.user.business.factory.UserEbiFactory;
-
import cn.hncu.user.vo.UserModel;
-
import cn.hncu.utils.DateUtil;
-
-
-
-
-
-
public class QueryPanel extends javax.swing.JPanel {
-
private JFrame mainFrame = null;
-
-
-
public QueryPanel(JFrame mainFrame) {
-
this.mainFrame = mainFrame;
-
this.setOpaque(false);
-
initComponents();
-
myInit();
-
}
-
-
private void myInit() {
-
List<UserModel> userList = UserEbiFactory.getUserEbi().getAllOut();
-
for (UserModel user : userList) {
-
combOutUser.addItem(user);
-
}
-
-
List<BookModel> books = BookEbiFactory.getBookEbi().getAll();
-
for (BookModel book : books) {
-
combBook.addItem(book);
-
}
-
}
-
-
-
-
-
-
-
-
-
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();
-
tfdOutDetailUuid = new javax.swing.JTextField();
-
tfdDate = new javax.swing.JTextField();
-
tfdDate2 = new javax.swing.JTextField();
-
tfdOutNum = new javax.swing.JTextField();
-
tfdOutNum2 = new javax.swing.JTextField();
-
tfdSumMoney = new javax.swing.JTextField();
-
combBook = new javax.swing.JComboBox();
-
combOutUser = 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("\u9500\u552e\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("\u9500\u552e\u8d77\u59cb\u65f6\u95f4\uff1a");
-
add(jLabel3);
-
jLabel3.setBounds(90, 170, 120, 20);
-
-
jLabel4.setText("\u9500\u552e\u4eba\uff1a");
-
add(jLabel4);
-
jLabel4.setBounds(450, 110, 80, 20);
-
-
jLabel5.setText("\u9500\u552e\u5355\u7f16\u53f7\uff1a");
-
add(jLabel5);
-
jLabel5.setBounds(100, 110, 110, 20);
-
-
jLabel6.setText("\u9500\u552e\u6700\u5927\u91cf\uff1a");
-
add(jLabel6);
-
jLabel6.setBounds(410, 330, 100, 20);
-
-
jLabel7.setText("\u9500\u552e\u6700\u5c0f\u91cf\uff1a");
-
add(jLabel7);
-
jLabel7.setBounds(100, 330, 130, 20);
-
-
jLabel8.setText("\u9500\u552e\u660e\u7ec6\u7f16\u53f7\uff1a");
-
add(jLabel8);
-
jLabel8.setBounds(90, 250, 130, 20);
-
-
jLabel9.setText("\u9500\u552e\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("\u9500\u552e\u603b\u4ef7\u6700\u5927\u503c\uff1a");
-
add(jLabel12);
-
jLabel12.setBounds(380, 400, 140, 20);
-
-
jLabel13.setText("\u9500\u552e\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(tfdOutDetailUuid);
-
tfdOutDetailUuid.setBounds(200, 250, 130, 30);
-
add(tfdDate);
-
tfdDate.setBounds(200, 170, 130, 30);
-
add(tfdDate2);
-
tfdDate2.setBounds(530, 170, 130, 30);
-
add(tfdOutNum);
-
tfdOutNum.setBounds(200, 330, 130, 30);
-
add(tfdOutNum2);
-
tfdOutNum2.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);
-
-
combOutUser.setModel(new javax.swing.DefaultComboBoxModel(
-
new String[] { "查询所有" }));
-
add(combOutUser);
-
combOutUser.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);
-
}
-
-
-
private void btnQueryActionPerformed(java.awt.event.ActionEvent evt) {
-
-
String outUuid = tfdUuid.getText();
-
String outUserName = (String) combOutUser.getSelectedItem();
-
String outUserUuid = null;
-
if (combOutUser.getSelectedIndex() > 0) {
-
outUserUuid = UserEbiFactory.getUserEbi().getUserByName(outUserName)
-
.getUuid();
-
}
-
-
String txtOutDate = tfdDate.getText();
-
long outDate = 0;
-
if (txtOutDate != null && txtOutDate.trim().length() > 0) {
-
txtOutDate += " 00:00:00";
-
outDate = DateUtil.StringToLong(txtOutDate, "进货起始时间输入格式错误!");
-
if (outDate == -1) {
-
return;
-
}
-
}
-
-
String txtOutDate2 = tfdDate2.getText();
-
long outDate2 = 0;
-
if (txtOutDate2 != null && txtOutDate2.trim().length() > 0) {
-
txtOutDate2 += " 23:59:59";
-
outDate2 = DateUtil.StringToLong(txtOutDate2, "进货结束时间输入格式错误!");
-
if (outDate2 == -1) {
-
return;
-
}
-
}
-
-
String outDetailUuid = tfdOutDetailUuid.getText();
-
-
String bookUuid = null;
-
if (combBook.getSelectedIndex() > 0) {
-
String bookName = combBook.getSelectedItem().toString();
-
bookUuid = BookEbiFactory.getBookEbi().getSingle(bookName)
-
.getUuid();
-
}
-
-
int sumNum = 0;
-
if (tfdOutNum.getText() != null
-
&& tfdOutNum.getText().trim().length() > 0) {
-
try {
-
sumNum = Integer.parseInt(tfdOutNum.getText());
-
if (sumNum < 0) {
-
throw new NumberFormatException();
-
}
-
} catch (NumberFormatException e) {
-
JOptionPane.showMessageDialog(null, "进货最小量格式输入错误!");
-
}
-
}
-
-
int sumNum2 = 0;
-
if (tfdOutNum2.getText() != null
-
&& tfdOutNum2.getText().trim().length() > 0) {
-
try {
-
sumNum2 = Integer.parseInt(tfdOutNum2.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, "进货最小量格式输入错误!");
-
}
-
}
-
-
-
OutMainQueryModel imqm = new OutMainQueryModel();
-
imqm.setOutDate(outDate);
-
imqm.setOutDate2(outDate2);
-
imqm.setOutUserId(outUserUuid);
-
imqm.setOutUserName(outUserName);
-
imqm.setUuid(outUuid);
-
-
OutDetailQueryModel idqm = new OutDetailQueryModel();
-
idqm.setBookUuid(bookUuid);
-
idqm.setUuid(outDetailUuid);
-
idqm.setSumMoney(sumMoney);
-
idqm.setSumMoney2(sumMoney2);
-
idqm.setSumNum(sumNum);
-
idqm.setSumNum2(sumNum2);
-
-
-
Map<OutMainModel, List<OutDetailModel>> map = OutMainEbiFactory
-
.getOutMainEbi().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();
-
}
-
-
-
-
private javax.swing.JButton btnBack;
-
private javax.swing.JButton btnQuery;
-
private javax.swing.JComboBox combBook;
-
private javax.swing.JComboBox combOutUser;
-
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 tfdOutDetailUuid;
-
private javax.swing.JTextField tfdOutNum;
-
private javax.swing.JTextField tfdOutNum2;
-
private javax.swing.JTextField tfdSumMoney;
-
private javax.swing.JTextField tfdSumMoney2;
-
private javax.swing.JTextField tfdUuid;
-
-
-
}
Java之------单机版书店管理系统(设计思想和设计模式系列六)销售模块
原文:http://blog.csdn.net/x121850182/article/details/51496635