本軟件系列到此,我已經全部寫完了。
1、Java應用程序基本分析
2、培養面向對象編程的基本思想
3、Java基本設計模式綜合應用
4、掌握分層和接口的基本設計
5、構建合理的Java應用程序包結構
6、綜合應用JSE所學習的知識
7、在應用中合理使用集合框架
8、在應用中綜合使用swing的常用組件
9、基本的表現層的實現機制
10、IO流和文件的基本操作
11、培養良好的Java編程習慣
12、培養調試Java程序的能力,培養改錯的能力
1、能進行操作用戶的注冊,修改基本信息,刪除和查詢。
2、能對圖書的基本信息進行增加、刪除、修改和查詢操作。
3、能填寫進貨單,一張進貨單帶有多條具體的進貨信息,進貨的書籍必須是圖書管理裡面已經有的;進貨的同時修改庫存對應書籍的存貨量。
4、能填寫銷售單,一張銷售單帶有多條具體的銷售信息,銷售的書籍必須是圖書管理裡面已經有的,而且銷售的數量不能超過當前庫存的數量;銷售的同時修改庫存對應書籍的存貨量。
5、可以查看庫存的明細,可以按照條件進行查找具體的圖書的庫存值。
6、權限方面進行簡化,做固定的權限控制。把用戶按照模塊分成不同操作權限的人員,特設一個admin的用戶,可以操作全部的功能。
★ 架構設計
整體框架、模塊劃分
模塊劃分:用戶、圖書、進貨、銷售和庫存5個模塊
★ 系統功能結構設計
每個功能模塊的具體功能子模塊
★ 數據庫設計
項目框架實現:分模塊、分層、分包、構建應用程序
這可以說是自己的第一個項目吧。小項目。O(∩_∩)O哈哈~、
寫到現在也有10多天了,自己比較享受寫項目的這個過程,不過因為這個項目是跟著老師指導來做的,所以呢,自己的感觸還不是很深,不過現在對分包啊,取名字啊,值對象封裝啊,工廠方法,面向接口編程啊,表現層,邏輯層,數據層啊,這些以前用都沒用過的,那時候完全不懂得怎麼回事,不過在自己寫了之後,感覺嘛、也就那麼回事。
O(∩_∩)O~,這種項目開發,還是得自己多練練手,寫得多了,自己就熟了。
以後就是手到擒來。
下面來看代碼吧:
/*
* BookStore.java
*
* Created on __DATE__, __TIME__
*/
package cn.hncu.bookStore;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import cn.hncu.bookStore.book.ui.BookListPanel;
import cn.hncu.bookStore.in.ui.InListPanel;
import cn.hncu.bookStore.login.ui.LoginPanel;
import cn.hncu.bookStore.out.ui.OutListPanel;
import cn.hncu.bookStore.stock.ui.StockListPanel;
import cn.hncu.bookStore.user.ui.ListPanel;
/**
*
* @author 陳浩翔
* @version 1.0 2016-4-20
*/
public class BookStore extends javax.swing.JFrame {
/** Creates new form BookStore */
public BookStore() {
super("書店管理系統---CHX---聯系QQ——619699629");
initComponents();
this.setContentPane(new LoginPanel(this));
this.setResizable(false);//不能縮放
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(scr.width / 5, scr.height / 5);
}
//GEN-BEGIN:initComponents
//
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
menuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
openMenuItem = new javax.swing.JMenuItem();
saveMenuItem = new javax.swing.JMenuItem();
saveAsMenuItem = new javax.swing.JMenuItem();
exitMenuItem = new javax.swing.JMenuItem();
editMenu = new javax.swing.JMenu();
cutMenuItem = new javax.swing.JMenuItem();
copyMenuItem = new javax.swing.JMenuItem();
pasteMenuItem = new javax.swing.JMenuItem();
deleteMenuItem = new javax.swing.JMenuItem();
helpMenu = new javax.swing.JMenu();
contentsMenuItem = new javax.swing.JMenuItem();
aboutMenuItem = new javax.swing.JMenuItem();
jMenu1 = new javax.swing.JMenu();
jMenuItemUser = new javax.swing.JMenuItem();
jMenuItemBook = new javax.swing.JMenuItem();
jMenuItemIn = new javax.swing.JMenuItem();
jMenuItemOut = new javax.swing.JMenuItem();
jMenuItemStock = new javax.swing.JMenuItem();
jMenuItem1 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setMinimumSize(new java.awt.Dimension(800, 600));
getContentPane().setLayout(null);
getContentPane().add(jLabel1);
jLabel1.setBounds(0, 0, 0, 0);
fileMenu.setText("File");
openMenuItem.setText("Open");
fileMenu.add(openMenuItem);
saveMenuItem.setText("Save");
fileMenu.add(saveMenuItem);
saveAsMenuItem.setText("Save As ...");
fileMenu.add(saveAsMenuItem);
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitMenuItemActionPerformed(evt);
}
});
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
editMenu.setText("Edit");
cutMenuItem.setText("Cut");
editMenu.add(cutMenuItem);
copyMenuItem.setText("Copy");
editMenu.add(copyMenuItem);
pasteMenuItem.setText("Paste");
editMenu.add(pasteMenuItem);
deleteMenuItem.setText("Delete");
editMenu.add(deleteMenuItem);
menuBar.add(editMenu);
helpMenu.setText("Help");
contentsMenuItem.setText("Contents");
helpMenu.add(contentsMenuItem);
aboutMenuItem.setText("About");
helpMenu.add(aboutMenuItem);
menuBar.add(helpMenu);
jMenu1.setForeground(new java.awt.Color(204, 0, 0));
jMenu1.setText("\u6a21\u5757");
jMenu1.setFont(new java.awt.Font("Dialog", 1, 14));
jMenuItemUser.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
java.awt.event.KeyEvent.VK_U,
java.awt.event.InputEvent.CTRL_MASK));
jMenuItemUser.setFont(new java.awt.Font("Dialog", 1, 14));
jMenuItemUser.setForeground(new java.awt.Color(0, 204, 0));
jMenuItemUser.setText("\u7528\u6237");
jMenuItemUser.setEnabled(false);
jMenuItemUser.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemUserActionPerformed(evt);
}
});
jMenu1.add(jMenuItemUser);
jMenuItemBook.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
java.awt.event.KeyEvent.VK_B,
java.awt.event.InputEvent.CTRL_MASK));
jMenuItemBook.setFont(new java.awt.Font("Dialog", 1, 14));
jMenuItemBook.setForeground(new java.awt.Color(0, 204, 51));
jMenuItemBook.setText("\u56fe\u4e66");
jMenuItemBook.setEnabled(false);
jMenuItemBook.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemBookActionPerformed(evt);
}
});
jMenu1.add(jMenuItemBook);
jMenuItemIn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
java.awt.event.KeyEvent.VK_I,
java.awt.event.InputEvent.CTRL_MASK));
jMenuItemIn.setFont(new java.awt.Font("Dialog", 1, 14));
jMenuItemIn.setForeground(new java.awt.Color(0, 204, 0));
jMenuItemIn.setText("\u8fdb\u8d27");
jMenuItemIn.setEnabled(false);
jMenuItemIn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemInActionPerformed(evt);
}
});
jMenu1.add(jMenuItemIn);
jMenuItemOut.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
java.awt.event.KeyEvent.VK_O,
java.awt.event.InputEvent.CTRL_MASK));
jMenuItemOut.setFont(new java.awt.Font("Dialog", 1, 14));
jMenuItemOut.setForeground(new java.awt.Color(0, 204, 0));
jMenuItemOut.setText("\u9500\u552e");
jMenuItemOut.setEnabled(false);
jMenuItemOut.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemOutActionPerformed(evt);
}
});
jMenu1.add(jMenuItemOut);
jMenuItemStock.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
java.awt.event.KeyEvent.VK_S,
java.awt.event.InputEvent.CTRL_MASK));
jMenuItemStock.setFont(new java.awt.Font("Dialog", 1, 14));
jMenuItemStock.setForeground(new java.awt.Color(0, 204, 0));
jMenuItemStock.setText("\u5e93\u5b58");
jMenuItemStock.setEnabled(false);
jMenuItemStock.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemStockActionPerformed(evt);
}
});
jMenu1.add(jMenuItemStock);
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
java.awt.event.KeyEvent.VK_DELETE,
java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setFont(new java.awt.Font("Dialog", 1, 14));
jMenuItem1.setForeground(new java.awt.Color(0, 204, 0));
jMenuItem1.setText("\u6ce8\u9500");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);
menuBar.add(jMenu1);
setJMenuBar(menuBar);
pack();
}//
//GEN-END:initComponents
/**
* 進入銷售模塊
* @param evt
*/
protected void jMenuItemOutActionPerformed(ActionEvent evt) {
this.setContentPane(new OutListPanel(this));
this.validate();
}
/**
* 進入庫存模塊
* @param evt
*/
protected void jMenuItemStockActionPerformed(ActionEvent evt) {
this.setContentPane(new StockListPanel(this));
this.validate();
}
/**
* 監聽進入進貨列表
* @param evt
*/
private void jMenuItemInActionPerformed(java.awt.event.ActionEvent evt) {
this.setContentPane(new InListPanel(this));
this.validate();
}
/**
* 注銷菜單項
* @param evt
*/
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
this.setContentPane(new LoginPanel(this));
this.validate();
jMenuItemUser.setEnabled(false);
jMenuItemBook.setEnabled(false);
jMenuItemIn.setEnabled(false);
jMenuItemOut.setEnabled(false);
jMenuItemStock.setEnabled(false);
}
/**
* 監聽進入圖書模塊
* @param evt
*/
private void jMenuItemBookActionPerformed(java.awt.event.ActionEvent evt) {
this.setContentPane(new BookListPanel(this));
this.validate();
}
/**
* 監聽進入用戶模塊
* @param evt
*/
private void jMenuItemUserActionPerformed(java.awt.event.ActionEvent evt) {
this.setContentPane(new ListPanel(this));
this.validate();
}
private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
System.exit(0);
}//GEN-LAST:event_exitMenuItemActionPerformed
/**
* @param 主函數 args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new BookStore().setVisible(true);
}
});
}
public javax.swing.JMenuItem getjMenuItemBook() {
return jMenuItemBook;
}
public javax.swing.JMenuItem getjMenuItemIn() {
return jMenuItemIn;
}
public javax.swing.JMenuItem getjMenuItemOut() {
return jMenuItemOut;
}
public javax.swing.JMenuItem getjMenuItemStock() {
return jMenuItemStock;
}
public javax.swing.JMenuItem getjMenuItemUser() {
return jMenuItemUser;
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JMenuItem aboutMenuItem;
private javax.swing.JMenuItem contentsMenuItem;
private javax.swing.JMenuItem copyMenuItem;
private javax.swing.JMenuItem cutMenuItem;
private javax.swing.JMenuItem deleteMenuItem;
private javax.swing.JMenu editMenu;
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JMenu fileMenu;
private javax.swing.JMenu helpMenu;
private javax.swing.JLabel jLabel1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItemBook;
private javax.swing.JMenuItem jMenuItemIn;
private javax.swing.JMenuItem jMenuItemOut;
private javax.swing.JMenuItem jMenuItemStock;
private javax.swing.JMenuItem jMenuItemUser;
private javax.swing.JMenuBar menuBar;
private javax.swing.JMenuItem openMenuItem;
private javax.swing.JMenuItem pasteMenuItem;
private javax.swing.JMenuItem saveAsMenuItem;
private javax.swing.JMenuItem saveMenuItem;
// End of variables declaration//GEN-END:variables
}
package cn.hncu.bookStore.login.business.ebi;
/**
* 用戶登錄模塊的邏輯層接口
* @author 陳浩翔
*
* @version 1.0 2016-4-20
*/
public interface LoginEbi {
/**
* 用戶登錄的方法
* @param name 用戶名
* @param pwd 密碼
* @return 返回字符串,若登錄成功則返回null,如果失敗則返回相應的錯誤信息如用戶名不存在或密碼不正確
*/
public String login(String name,String pwd);
}
package cn.hncu.bookStore.login.business.ebo;
import cn.hncu.bookStore.login.business.ebi.LoginEbi;
import cn.hncu.bookStore.user.business.ebi.UserEbi;
import cn.hncu.bookStore.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.vo.UserModel;
/**
* 登錄模塊的實現類
* @author 陳浩翔
*
* @version 1.0 2016-4-20
*/
public class LoginEbo implements LoginEbi{
@Override
public String login(String name, String pwd) {
UserEbi ebi = UserEbiFactory.getUserEbi();
UserModel user = ebi.getUserByName(name);
if(user==null){
return "對不起,該用戶不存在!";
}
if(!user.getPwd().equals(pwd)){
return "您輸入的密碼不正確!";
}
return null;
}
}
package cn.hncu.bookStore.login.business.factory;
import cn.hncu.bookStore.login.business.ebi.LoginEbi;
import cn.hncu.bookStore.login.business.ebo.LoginEbo;
/**
* 登錄模塊的工廠類
* @author 陳浩翔
*
* @version 1.0 2016-4-20
*/
public class LoginEbiFactory {
/**
* 工廠方法
* @return
*/
public static LoginEbi getLoginEbi(){
return new LoginEbo();
}
}
/*
* LoginPanel.java
*
* Created on __DATE__, __TIME__
*/
package cn.hncu.bookStore.login.ui;
import javax.swing.JOptionPane;
import cn.hncu.bookStore.BookStore;
import cn.hncu.bookStore.common.UserTypeEnum;
import cn.hncu.bookStore.login.business.factory.LoginEbiFactory;
import cn.hncu.bookStore.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.vo.UserModel;
/**
*
* @author 陳浩翔
*
* @version 1.0 2016-4-20
*/
public class LoginPanel extends javax.swing.JPanel {
private BookStore mainFrame = null;
/** Creates new form LoginPanel */
public LoginPanel(BookStore mainFrame) {
this.mainFrame = mainFrame;
initComponents();
}
//GEN-BEGIN:initComponents
//
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
tfdName = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
tfpPwd = new javax.swing.JPasswordField();
btnLogin = new javax.swing.JButton();
btnHelp = new javax.swing.JButton();
setMinimumSize(new java.awt.Dimension(800, 600));
setLayout(null);
jLabel1.setFont(new java.awt.Font("Dialog", 1, 48));
jLabel1.setForeground(new java.awt.Color(255, 51, 0));
jLabel1.setText("\u767b\u5f55");
add(jLabel1);
jLabel1.setBounds(320, 20, 140, 120);
jLabel2.setFont(new java.awt.Font("宋體", 1, 24));
jLabel2.setForeground(new java.awt.Color(51, 0, 255));
jLabel2.setText("\u5bc6 \u7801:");
add(jLabel2);
jLabel2.setBounds(210, 330, 80, 40);
tfdName.setFont(new java.awt.Font("微軟雅黑", 1, 24));
add(tfdName);
tfdName.setBounds(310, 220, 190, 40);
jLabel3.setFont(new java.awt.Font("宋體", 1, 24));
jLabel3.setForeground(new java.awt.Color(51, 0, 255));
jLabel3.setText("\u7528\u6237\u540d:");
add(jLabel3);
jLabel3.setBounds(200, 220, 120, 40);
tfpPwd.setFont(new java.awt.Font("宋體", 1, 24));
add(tfpPwd);
tfpPwd.setBounds(310, 330, 190, 40);
btnLogin.setFont(new java.awt.Font("Dialog", 1, 24));
btnLogin.setForeground(new java.awt.Color(51, 0, 255));
btnLogin.setText("\u767b\u5f55");
btnLogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnLoginActionPerformed(evt);
}
});
add(btnLogin);
btnLogin.setBounds(150, 440, 120, 70);
btnHelp.setFont(new java.awt.Font("Dialog", 1, 24));
btnHelp.setForeground(new java.awt.Color(0, 0, 255));
btnHelp.setText("\u5e2e\u52a9");
btnHelp.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnHelpActionPerformed(evt);
}
});
add(btnHelp);
btnHelp.setBounds(450, 440, 130, 70);
}//
//GEN-END:initComponents
private void btnHelpActionPerformed(java.awt.event.ActionEvent evt) {
mainFrame.setContentPane(new LoginHelp(mainFrame));
mainFrame.validate();
}
private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {
//1收集
String name = tfdName.getText();
String pwd = new String(tfpPwd.getPassword());
if(name.equals("admin")&&pwd.equals("123456")){
mainFrame.getjMenuItemUser().setEnabled(true);
mainFrame.getjMenuItemBook().setEnabled(true);
mainFrame.getjMenuItemIn().setEnabled(true);
mainFrame.getjMenuItemOut().setEnabled(true);
mainFrame.getjMenuItemStock().setEnabled(true);
mainFrame.setContentPane(new LoginWelcomePanel());
mainFrame.validate();
}
//2組織---沒有值對象,不組織了
//3調用邏輯層
String result = LoginEbiFactory.getLoginEbi().login(name, pwd);
//4返回到結果頁面
if (result != null) {
JOptionPane.showMessageDialog(mainFrame, result);
return;
}
//接下來,登錄成功的情況
//把該用戶類型所對應的模塊點亮
UserModel user = UserEbiFactory.getUserEbi().getUserByName(name);
//超級管理員,點亮所有模塊
if (user.getType() == UserTypeEnum.ADMIN.getType()) {
mainFrame.getjMenuItemUser().setEnabled(true);
mainFrame.getjMenuItemBook().setEnabled(true);
mainFrame.getjMenuItemIn().setEnabled(true);
mainFrame.getjMenuItemOut().setEnabled(true);
mainFrame.getjMenuItemStock().setEnabled(true);
}
//圖書管理員,點亮圖書模塊
if (user.getType() == UserTypeEnum.BOOK.getType()) {
mainFrame.getjMenuItemBook().setEnabled(true);
}
//進貨管理員,點亮進貨模塊
if (user.getType() == UserTypeEnum.IN.getType()) {
mainFrame.getjMenuItemIn().setEnabled(true);
}
//銷售管理員,點亮銷售模塊
if (user.getType() == UserTypeEnum.OUT.getType()) {
mainFrame.getjMenuItemOut().setEnabled(true);
}
//庫存管理員,點亮庫存模塊
if (user.getType() == UserTypeEnum.STOCK.getType()) {
mainFrame.getjMenuItemStock().setEnabled(true);
}
mainFrame.setContentPane(new LoginWelcomePanel());
mainFrame.validate();
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton btnHelp;
private javax.swing.JButton btnLogin;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField tfdName;
private javax.swing.JPasswordField tfpPwd;
// End of variables declaration//GEN-END:variables
}
/*
* LoginWelcomePanel.java
*
* Created on __DATE__, __TIME__
*/
package cn.hncu.bookStore.login.ui;
/**
*
* @author 陳浩翔
*
* @version 1.0 2016-4-20
*/
public class LoginWelcomePanel extends javax.swing.JPanel {
/** Creates new form LoginWelcomePanel */
public LoginWelcomePanel() {
initComponents();
}
/** 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
//
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
setMinimumSize(new java.awt.Dimension(800, 600));
setLayout(null);
jLabel1.setFont(new java.awt.Font("Dialog", 1, 36));
jLabel1.setForeground(new java.awt.Color(255, 0, 0));
jLabel1.setText("\u6b22\u8fce\u767b\u5f55\uff0c\u592a\u9633\u6bcf\u5929\u90fd\u662f\u65b0\u7684\uff01\uff01");
add(jLabel1);
jLabel1.setBounds(100, 190, 590, 170);
}//
//GEN-END:initComponents
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
// End of variables declaration//GEN-END:variables
}
/*
* LoginHelp.java
*
* Created on __DATE__, __TIME__
*/
package cn.hncu.bookStore.login.ui;
import javax.swing.JFrame;
import cn.hncu.bookStore.BookStore;
/**
*
* @author 陳浩翔
*
* @version 1.0 2016-4-20
*/
public class LoginHelp extends javax.swing.JPanel {
private JFrame mainFrame = null;
/** Creates new form LoginHelp
* @param mainFrame */
public LoginHelp(JFrame mainFrame) {
this.mainFrame = mainFrame;
initComponents();
}
/** 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
//
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
setMinimumSize(new java.awt.Dimension(800, 600));
setLayout(null);
jLabel1.setFont(new java.awt.Font("Dialog", 1, 14));
jLabel1.setText("\u5982\u679c\u4f60\u4e0d\u5c0f\u5fc3\u628a\u7528\u6237\u6587\u4ef6\u5220\u9664\u4e86\uff0c\u53ef\u4ee5\u5229\u7528admin\u8d85\u7ea7\u7ba1\u7406\u5458\u767b\u5f55\uff0c\u5bc6\u7801\u4e3a:123456");
add(jLabel1);
jLabel1.setBounds(90, 250, 590, 80);
}//
//GEN-END:initComponents
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
// End of variables declaration//GEN-END:variables
}
package cn.hncu.bookStore.stock.dao.dao;
import java.util.List;
import cn.hncu.bookStore.stock.vo.StockModel;
import cn.hncu.bookStore.stock.vo.StockQueryModel;
/**
* 庫存模塊的數據層接口
* @author 陳浩翔
*
* @version 1.0 2016-4-20
*/
public interface StockDao {
/**
* 創建一個庫存對象
* @param stock
* @return
*/
public boolean create(StockModel stock);
/**
*
* @return 返回所有的庫存對象數據
*/
public List getAl();
/**
* 根據uuid -- 修改為傳入的庫存對象
* @param stock
* @return
*/
public boolean update(StockModel stock);
/**
* 查詢 符合條件 的 庫存對象集合
* @param sqm---查詢條件
* @return---符合條件的庫存對象集合
*/
public List getByCondition(StockQueryModel sqm);
/**
* 根據uuid查找當前的uuid對應的庫存對象
* @param uuid
* @return
*/
public StockModel getSingle(String uuid);
}
package cn.hncu.bookStore.stock.dao.impl;
import java.util.ArrayList;
import java.util.List;
import cn.hncu.bookStore.stock.dao.dao.StockDao;
import cn.hncu.bookStore.stock.vo.StockModel;
import cn.hncu.bookStore.stock.vo.StockQueryModel;
import cn.hncu.bookStore.util.FileIoUtil;
import cn.hncu.bookStore.util.StringComparison;
/**
* 庫存模塊數據層的實現類
* @author 陳浩翔
*
* @version 1.0 2016-4-20
*/
public class StockDaoImpl implements StockDao{
private final String FILE_NAME = "Stock.txt";
@Override
public boolean create(StockModel stock) {
List lists = FileIoUtil.readFormFile(FILE_NAME);
for(StockModel model :lists){
if(model.getUuid().equals(stock.getUuid())){
return false;
}
}
lists.add(stock);
FileIoUtil.write2file(lists, FILE_NAME);
return true;
}
@Override
public List getAl() {
return FileIoUtil.readFormFile(FILE_NAME);
}
@Override
public boolean update(StockModel stock) {
List lists = FileIoUtil.readFormFile(FILE_NAME);
for(int i=0;i getByCondition(StockQueryModel sqm) {
List lists = FileIoUtil.readFormFile(FILE_NAME);
List results = new ArrayList();
for(StockModel model : lists){
//衛條件
//比較庫存ID
if(!StringComparison.stringEquals(model.getUuid(), sqm.getUuid())){
continue;
}
//比較圖書ID
if(!StringComparison.stringEquals(model.getBookUuid(), sqm.getBookUuid())){
continue;
}
//庫存查詢最小數量
if(sqm.getSumNum()>0){
if(sqm.getSumNum()>model.getSumNum()){
continue;
}
}
//庫存查詢最大數量
if(sqm.getSumNum2()>0){
if(sqm.getSumNum2() lists = FileIoUtil.readFormFile(FILE_NAME);
for(StockModel model : lists){
if(model.getUuid().equals(uuid)){
//找到uuid相同,直接返回庫存對象
return model;
}
}
return null;
}
}
package cn.hncu.bookStore.stock.dao.factory;
import cn.hncu.bookStore.stock.dao.dao.StockDao;
import cn.hncu.bookStore.stock.dao.impl.StockDaoImpl;
/**
* 工廠類-庫存
* @author 陳浩翔
*
* @version 1.0 2016-4-20
*/
public class StockDaoFactory {
/**
* 工廠方法
* @return --- new 一個數據層實例
*/
public static StockDao getStockDao(){
return new StockDaoImpl();
}
}
package cn.hncu.bookStore.stock.business.ebi;
import java.util.List;
import cn.hncu.bookStore.stock.vo.StockModel;
import cn.hncu.bookStore.stock.vo.StockQueryModel;
/**
* 庫存邏輯層的接口
* @author 陳浩翔
*
* @version 1.0 2016-4-20
*/
public interface StockEbi {
/**
* 得到所有的庫存對象
* @return---所有的庫存對象集合
*/
public List getAll();
/**
* 根據查詢條件,查詢所有符合條件的庫存對象
* @param sqm---查詢條件
* @return---所有符合條件的庫存對象集合
*/
public List getByCondition(StockQueryModel sqm);
}
package cn.hncu.bookStore.stock.business.ebo;
import java.util.List;
import cn.hncu.bookStore.stock.business.ebi.StockEbi;
import cn.hncu.bookStore.stock.dao.dao.StockDao;
import cn.hncu.bookStore.stock.dao.factory.StockDaoFactory;
import cn.hncu.bookStore.stock.vo.StockModel;
import cn.hncu.bookStore.stock.vo.StockQueryModel;
/**
* 庫存邏輯層實現類
* @author 陳浩翔
*
* @version 1.0 2016-4-20
*/
public class StockEbo implements StockEbi{
//注入 dao
StockDao dao = StockDaoFactory.getStockDao();
@Override
public List getAll() {
return dao.getAl();
}
@Override
public List getByCondition(StockQueryModel sqm) {
return dao.getByCondition(sqm);
}
}
package cn.hncu.bookStore.stock.business.factory;
import cn.hncu.bookStore.stock.business.ebi.StockEbi;
import cn.hncu.bookStore.stock.business.ebo.StockEbo;
/**
* 庫存邏輯層工廠類
* @author 陳浩翔
*
* @version 1.0 2016-4-20
*/
public class StockEbiFactory {
/**
* 工廠方法
* @return---new一個邏輯層實現類
*/
public static StockEbi getStockEbi(){
return new StockEbo();
}
}
package cn.hncu.bookStore.stock.vo;
import java.io.Serializable;
/**
* 庫存封裝值對象
* @author 陳浩翔
*
* @version 1.0
*/
public class StockModel implements Serializable{
//庫存編號
private String uuid;
//圖書編號
private String bookUuid;
//庫存數量
private int sumNum;
//為顯示給用戶看而補的
private String bookName;
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
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 String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
@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;
StockModel other = (StockModel) 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+"本";
}
}
package cn.hncu.bookStore.stock.vo;
/**
* 庫存查詢值對象封裝
* @author 陳浩翔
*
* @version 1.0
*/
public class StockQueryModel extends StockModel{
//最大的圖書庫存數量
private int sumNum2;
public int getSumNum2() {
return sumNum2;
}
public void setSumNum2(int sumNum2) {
this.sumNum2 = sumNum2;
}
}
/*
* StockListPanel.java
*
* Created on __DATE__, __TIME__
*/
package cn.hncu.bookStore.stock.ui;
import java.util.List;
import javax.swing.JFrame;
import cn.hncu.bookStore.stock.business.factory.StockEbiFactory;
import cn.hncu.bookStore.stock.vo.StockModel;
/**
*
* @author 陳浩翔
*
* @version 1.0 2016-4-20
*/
public class StockListPanel extends javax.swing.JPanel {
private JFrame mainFrame = null;
/** Creates new form StockListPanel */
public StockListPanel(JFrame mainFrame) {
this.mainFrame = mainFrame;
initComponents();
myInitData();
}
public StockListPanel(JFrame mainFrame, List results) {
this.mainFrame = mainFrame;
initComponents();
jListStocks.setListData(results.toArray());
}
private void myInitData() {
List lists = StockEbiFactory.getStockEbi().getAll();
jListStocks.setListData(lists.toArray());
}
/** 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
//
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jListStocks = new javax.swing.JList();
btnQuery = new javax.swing.JButton();
setMinimumSize(new java.awt.Dimension(800, 600));
setLayout(null);
jLabel1.setFont(new java.awt.Font("微軟雅黑", 1, 48));
jLabel1.setForeground(new java.awt.Color(255, 0, 0));
jLabel1.setText("\u5e93\u5b58\u5217\u8868");
add(jLabel1);
jLabel1.setBounds(280, 0, 220, 90);
jListStocks.setFont(new java.awt.Font("微軟雅黑", 1, 18));
jListStocks.setForeground(new java.awt.Color(0, 0, 153));
jListStocks.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "" };
public int getSize() {
return strings.length;
}
public Object getElementAt(int i) {
return strings[i];
}
});
jScrollPane1.setViewportView(jListStocks);
add(jScrollPane1);
jScrollPane1.setBounds(120, 100, 520, 320);
btnQuery.setFont(new java.awt.Font("Dialog", 1, 36));
btnQuery.setForeground(new java.awt.Color(255, 0, 51));
btnQuery.setText("\u67e5\u8be2\u5e93\u5b58");
btnQuery.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnQueryActionPerformed(evt);
}
});
add(btnQuery);
btnQuery.setBounds(270, 440, 190, 90);
}//
//GEN-END:initComponents
private void btnQueryActionPerformed(java.awt.event.ActionEvent evt) {
mainFrame.setContentPane(new StockQueryPanel(mainFrame));
mainFrame.validate();
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton btnQuery;
private javax.swing.JLabel jLabel1;
private javax.swing.JList jListStocks;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration//GEN-END:variables
}
/*
* StockQueryPanel.java
*
* Created on __DATE__, __TIME__
*/
package cn.hncu.bookStore.stock.ui;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import cn.hncu.bookStore.book.business.factory.BookEbiFactory;
import cn.hncu.bookStore.book.vo.BookModel;
import cn.hncu.bookStore.stock.business.factory.StockEbiFactory;
import cn.hncu.bookStore.stock.vo.StockModel;
import cn.hncu.bookStore.stock.vo.StockQueryModel;
/**
*
* @author 陳浩翔
*
* @version 1.0 2016-4-20
*/
public class StockQueryPanel extends javax.swing.JPanel {
private JFrame mainFrame = null;
/** Creates new form StockQueryPanel
* @param mainFrame */
public StockQueryPanel(JFrame mainFrame) {
this.mainFrame = mainFrame;
initComponents();
myInitData();
}
/**
* 初始化圖書box
*/
private void myInitData() {
List books = BookEbiFactory.getBookEbi().getAll();
for(BookModel book:books){
combBook.addItem(book.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
//
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
tfdStockUuid = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
combBook = new javax.swing.JComboBox();
jLabel8 = new javax.swing.JLabel();
tfdStockNum = new javax.swing.JTextField();
jLabel11 = new javax.swing.JLabel();
tfdStockNum2 = new javax.swing.JTextField();
btnQuery = new javax.swing.JButton();
btnBack = new javax.swing.JButton();
setMinimumSize(new java.awt.Dimension(800, 600));
setLayout(null);
jLabel1.setFont(new java.awt.Font("Dialog", 1, 48));
jLabel1.setForeground(new java.awt.Color(255, 0, 0));
jLabel1.setText("\u5e93\u5b58\u67e5\u8be2");
add(jLabel1);
jLabel1.setBounds(270, 0, 230, 90);
jLabel7.setFont(new java.awt.Font("微軟雅黑", 0, 18));
jLabel7.setText("\u5e93\u5b58\u7f16\u53f7:");
add(jLabel7);
jLabel7.setBounds(80, 160, 80, 30);
add(tfdStockUuid);
tfdStockUuid.setBounds(180, 160, 150, 30);
jLabel5.setFont(new java.awt.Font("微軟雅黑", 0, 18));
jLabel5.setText("\u56fe\u4e66:");
add(jLabel5);
jLabel5.setBounds(430, 150, 50, 30);
combBook.setFont(new java.awt.Font("Dialog", 1, 18));
combBook.setModel(new javax.swing.DefaultComboBoxModel(
new String[] { "查詢所有" }));
add(combBook);
combBook.setBounds(490, 150, 190, 30);
jLabel8.setFont(new java.awt.Font("微軟雅黑", 0, 18));
jLabel8.setText("\u5e93\u5b58\u6700\u5c0f\u6570\u91cf:");
add(jLabel8);
jLabel8.setBounds(50, 270, 140, 30);
add(tfdStockNum);
tfdStockNum.setBounds(180, 270, 150, 30);
jLabel11.setFont(new java.awt.Font("微軟雅黑", 0, 18));
jLabel11.setText("\u5e93\u5b58\u6700\u5927\u6570\u91cf:");
add(jLabel11);
jLabel11.setBounds(360, 270, 120, 30);
add(tfdStockNum2);
tfdStockNum2.setBounds(490, 270, 190, 30);
btnQuery.setFont(new java.awt.Font("Dialog", 1, 24));
btnQuery.setForeground(new java.awt.Color(255, 0, 51));
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(140, 410, 120, 70);
btnBack.setFont(new java.awt.Font("Dialog", 1, 24));
btnBack.setForeground(new java.awt.Color(255, 0, 51));
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(490, 410, 120, 70);
}//
//GEN-END:initComponents
private void btnQueryActionPerformed(java.awt.event.ActionEvent evt) {
// 1收集參數(且驗證輸入有效性)
//庫存編號
String uuid = tfdStockUuid.getText();
//圖書編號
String bookUuid = null;
if (combBook.getSelectedIndex() > 0) {
bookUuid = BookEbiFactory.getBookEbi()
.getBookByName(combBook.getSelectedItem().toString())
.getUuid();
}
//庫存最小數量
int sumNum = 0;
if (tfdStockNum.getText() != null
&& tfdStockNum.getText().trim().length() > 0) {
try {
sumNum = Integer.parseInt(tfdStockNum.getText());
if (sumNum < 0) {
throw new NumberFormatException();
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(mainFrame, "庫存最小數量必須輸入正整數!");
return;
}
}
//庫存最大數量
int sumNum2 = 0;
if (tfdStockNum2.getText() != null
&& tfdStockNum2.getText().trim().length() > 0) {
try {
sumNum2 = Integer.parseInt(tfdStockNum2.getText());
if (sumNum2 < 0) {
throw new NumberFormatException();
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(mainFrame, "庫存最大數量必須輸入正整數!");
return;
}
}
// 2組織參數----StockQueryModel
StockQueryModel sqm = new StockQueryModel();
sqm.setUuid(uuid);
sqm.setBookUuid(bookUuid);
sqm.setSumNum(sumNum);
sqm.setSumNum2(sumNum2);
// 3調用邏輯層
List results = StockEbiFactory.getStockEbi()
.getByCondition(sqm);
// 4返回到結果頁面
mainFrame.setContentPane(new StockListPanel(mainFrame, results));
mainFrame.validate();
}
private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
back();
}
private void back() {
mainFrame.setContentPane(new StockListPanel(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.JLabel jLabel1;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JTextField tfdStockNum;
private javax.swing.JTextField tfdStockNum2;
private javax.swing.JTextField tfdStockUuid;
// End of variables declaration//GEN-END:variables
}
進貨模塊的邏輯層接口,在寫了庫存模塊之後改了一點,增加了和庫存模塊的串接:
package cn.hncu.bookStore.in.business.ebo;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import cn.hncu.bookStore.book.business.ebi.BookEbi;
import cn.hncu.bookStore.book.business.factory.BookEbiFactory;
import cn.hncu.bookStore.common.UuidModelConstance;
import cn.hncu.bookStore.common.uuid.dao.dao.UuidDao;
import cn.hncu.bookStore.common.uuid.dao.factory.UuidDaoFactory;
import cn.hncu.bookStore.in.business.ebi.InMainEbi;
import cn.hncu.bookStore.in.business.factory.InMainEbiFactory;
import cn.hncu.bookStore.in.dao.dao.InDetailDao;
import cn.hncu.bookStore.in.dao.dao.InMainDao;
import cn.hncu.bookStore.in.dao.factory.InDetailDaoFactory;
import cn.hncu.bookStore.in.dao.factory.InMainDaoFactory;
import cn.hncu.bookStore.in.vo.InDetailModel;
import cn.hncu.bookStore.in.vo.InDetailQueryModel;
import cn.hncu.bookStore.in.vo.InMainModel;
import cn.hncu.bookStore.in.vo.InMainQueryModel;
import cn.hncu.bookStore.stock.dao.dao.StockDao;
import cn.hncu.bookStore.stock.dao.factory.StockDaoFactory;
import cn.hncu.bookStore.stock.vo.StockModel;
import cn.hncu.bookStore.stock.vo.StockQueryModel;
/**
*
* @author 陳浩翔
*
* @version 1.0
*/
public class InMainEbo implements InMainEbi{
//注入dao
InMainDao inMainDao = InMainDaoFactory.getInMainDao();
InDetailDao inDetailDao = InDetailDaoFactory.getInDetailDao();
UuidDao uuidDao = UuidDaoFactory.getUuidDao();
BookEbi bookEbi = BookEbiFactory.getBookEbi();
@Override
public boolean create(InMainModel inMain, List inDetails) {
//////////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 model:inDetails){
//補全每一個inDetail中的數據
//需要:inDetailUuid,inMainUuid,bookUuid,sumNum,sumMoney 已組織:bookUuid,sumNum
//還缺(需補):inDetailUuid,inMainUuid,sumMoney
model.setUuid(uuidDao.getNextUuid(UuidModelConstance.IN_DETAIL));
model.setInId(inUuid);
double sumMoney = model.getSumNum() * bookEbi.getSingle(model.getBookId()).getInPrice();
model.setSumMoney(sumMoney);
inDetailDao.create(model);
//////////※※※3 圖書入庫--到庫存表格///////////
putInStock(model.getBookId(),model.getSumNum());
}
return true;
}
/**
* 入庫動作
* @param bookId
* @param bookName
*/
private void putInStock(String bookId, int sumNum) {
//注入Stock模塊的dao
StockDao dao = StockDaoFactory.getStockDao();
//查詢庫存,看看是否已經存在該bookUuid所對應的書,如果沒有則庫存數據為sumNum,否則為在原有基礎上再加上sumNum
StockQueryModel sqm = new StockQueryModel();
sqm.setBookUuid(bookId);
List lists = dao.getByCondition(sqm);
//庫存中沒有這種書
if(lists==null||lists.size()==0){
//表現層只負責組織進貨模塊的值對象,庫存模塊我們在邏輯層自己補
StockModel stock = new StockModel();
//補:庫存編號 uuid
stock.setUuid(UuidDaoFactory.getUuidDao().getNextUuid(UuidModelConstance.STOCK));
//補: bookName 專為顯示給用戶看的書名
stock.setBookName(BookEbiFactory.getBookEbi().getSingle(bookId).getName());
stock.setBookUuid(bookId);
stock.setSumNum(sumNum);
dao.create(stock);
}else{//庫存中已經存在該圖書對應的庫存記錄
StockModel stock = lists.get(0);
stock.setSumNum( stock.getSumNum()+sumNum );
dao.update(stock);
}
}
@Override
public Map> getAll() {
Map> map = new TreeMap>();
List inMains = inMainDao.getAll();
for(InMainModel inMain: inMains ){
//查詢條件值對象的創建
InDetailQueryModel idqm = new InDetailQueryModel();
String inUuid = inMain.getUuid();
idqm.setInId(inUuid);
List details = inDetailDao.getbyCondition(idqm);
map.put(inMain, details);
}
return map;
}
@Override
public Map> getByCondition(
InMainQueryModel imqm, InDetailQueryModel idqm) {
Map> map = new TreeMap>();
List list = inMainDao.getbyCondition(imqm);
for(InMainModel inMain : list){
idqm.setInId(inMain.getUuid());
List details = inDetailDao.getbyCondition(idqm);
if(details.size()!=0){
map.put(inMain, details);
}
}
return map;
}
}
銷售模塊的邏輯層接口也增加了和庫存模塊的串接:
package cn.hncu.bookStore.out.business.ebo;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.swing.JOptionPane;
import cn.hncu.bookStore.book.business.ebi.BookEbi;
import cn.hncu.bookStore.book.business.factory.BookEbiFactory;
import cn.hncu.bookStore.common.UuidModelConstance;
import cn.hncu.bookStore.common.uuid.dao.dao.UuidDao;
import cn.hncu.bookStore.common.uuid.dao.factory.UuidDaoFactory;
import cn.hncu.bookStore.out.business.ebi.OutMainEbi;
import cn.hncu.bookStore.out.dao.dao.OutDetailDao;
import cn.hncu.bookStore.out.dao.dao.OutMainDao;
import cn.hncu.bookStore.out.dao.factory.OutDetailDaoFactory;
import cn.hncu.bookStore.out.dao.factory.OutMainDaoFactory;
import cn.hncu.bookStore.out.vo.OutDetailModel;
import cn.hncu.bookStore.out.vo.OutDetailQueryModel;
import cn.hncu.bookStore.out.vo.OutMainModel;
import cn.hncu.bookStore.out.vo.OutMainQueryModel;
import cn.hncu.bookStore.stock.business.factory.StockEbiFactory;
import cn.hncu.bookStore.stock.dao.dao.StockDao;
import cn.hncu.bookStore.stock.dao.factory.StockDaoFactory;
import cn.hncu.bookStore.stock.vo.StockModel;
import cn.hncu.bookStore.stock.vo.StockQueryModel;
/**
*
* @author 陳浩翔
*
* @version 1.0
*/
public class OutMainEbo implements OutMainEbi{
//注入dao
OutMainDao outMainDao = OutMainDaoFactory.getOutMainDao();
OutDetailDao outDetailDao = OutDetailDaoFactory.getOutDetailDao();
UuidDao uuidDao = UuidDaoFactory.getUuidDao();
BookEbi bookEbi = BookEbiFactory.getBookEbi();
@Override
public boolean create(OutMainModel outMain, List outDetails) {
//※※※庫存操作1:在添加銷售信息之前要進行防護:檢查庫存,看是否可能庫存不夠。如果不夠,本次添加直接失敗,不進行數據存儲---return false;
//檢查庫存----用明細單(outDetail)中的bookUuid
//注入Stock模塊的dao
StockDao stockDao = StockDaoFactory.getStockDao();
for(OutDetailModel detail : outDetails){
StockQueryModel sqm = new StockQueryModel();
sqm.setBookUuid(detail.getBookId());
List lists = stockDao.getByCondition(sqm);
if(lists==null||lists.size()==0){//庫存中沒有該圖書信息
JOptionPane.showMessageDialog(null, "庫存中不存在《"+detail.getBookName()+"》,本次銷售添加失敗!");
return false;
}else {
StockModel sm = lists.get(0);
if(sm.getSumNum() stocks = StockEbiFactory.getStockEbi().getByCondition(sqm);
//經過之前的防護,list裡面一定有一個值,而且庫存一定可以更新成功
StockModel stock = stocks.get(0);
stock.setSumNum(stock.getSumNum()-model.getSumNum());
StockDaoFactory.getStockDao().update(stock);
}
return true;
}
@Override
public Map> getAll() {
Map> map = new TreeMap>();
List outMains = outMainDao.getAll();
for(OutMainModel outMain: outMains ){
//查詢條件值對象的創建
OutDetailQueryModel odqm = new OutDetailQueryModel();
String inUuid = outMain.getUuid();
odqm.setOutId(inUuid);
List details = outDetailDao.getbyCondition(odqm);
map.put(outMain, details);
}
return map;
}
@Override
public Map> getByCondition(
OutMainQueryModel imqm, OutDetailQueryModel odqm) {
Map> map = new TreeMap>();
List list = outMainDao.getbyCondition(imqm);
for(OutMainModel outMain : list){
odqm.setOutId(outMain.getUuid());
List details = outDetailDao.getbyCondition(odqm);
if(details.size()!=0){
map.put(outMain, details);
}
}
return map;
}
}
菜單項,除了注銷是點亮之外,其他的都是暗的。
當用戶文件被刪除了之後,就只能通過這個賬號登錄了。
這個是管理員登錄的歡迎界面,可以看到所有的菜單項都被點亮了的。
可以看到,菜單項只有庫存那一項是點亮的。
可以看到,菜單項只有銷售那一項是點亮的。
其他的都是,一個模塊的用戶對應相應的模塊!
本系列就到此結束啦。
可能有一些小bug,我也就沒去改了,時間比較緊,O(∩_∩)O哈哈~,大家有興趣的可以去改改,做做。
所有代碼的百度雲鏈接:
鏈接: http://pan.baidu.com/s/1c2ob5r6 密碼: u6jv