Java-單機版的書店管理系統(練習設計模塊和思想_系列 六 )
http://blog.csdn.net/qq_26525215/article/details/51169277java
Java-單機版的書店管理系統(練習設計模塊和思想_系列 五 )
http://blog.csdn.net/qq_26525215/article/details/51136848markdown
Java-單機版的書店管理系統(練習設計模塊和思想_系列 四(2) ):
http://blog.csdn.net/qq_26525215/article/details/51117135ide
Java-單機版的書店管理系統(練習設計模塊和思想_系列 四(1) ):
http://blog.csdn.net/qq_26525215/article/details/51116429工具
Java-單機版的書店管理系統(練習設計模塊和思想_系列 三 ):
http://blog.csdn.net/qq_26525215/article/details/51099202ui
Java-單機版的書店管理系統(練習設計模塊和思想_系列 二 ):
http://blog.csdn.net/qq_26525215/article/details/51089734this
Java-單機版的書店管理系統(練習設計模塊和思想_系列 一 ):
http://blog.csdn.net/qq_26525215/article/details/51073546spa
如今已經將進貨模塊的查詢寫完了,.net
(進貨模塊只有添加和查詢!沒有刪除和修改。
由於若是能隨便修改進貨的時間,進貨的數量等,這不是亂套了嘛)設計
如今完成的模塊有:用戶模塊,圖書模塊,進貨模塊。
新增寫了一個日期類,將long型數字轉換成某個日期格式顯示給用戶看。
將string型的日期格式轉換成long型數字存儲。
將前面的StringComparison類進行了修改。code
如今剩下的模塊還有銷售模塊,庫存模塊,還有登陸界面,
庫存模塊是須要綜合銷售模塊和進貨模塊來寫的。
也就是模塊與模塊之間須要串接了。
如今我寫的這3個模塊,基本上是屬於和對方沒什麼聯繫的,每一個模塊都能獨自完成本身的功能。
只亮一張進貨查詢的圖片吧。界面很差看(^-^)勿噴噢。
package cn.hncu.bookStore.util;
/** * 工具類 * 字符串比較 * @author 陳浩翔 * * @version 1.0 */
public class StringComparison {
/** * str1和str2徹底(精確查找)匹配 * 這個精確匹配是在str2不爲null且str2去掉2端空格的狀況下比較的!!! * @param str1---被比較的字符串 * @param str2---比較的字符串 * @return---若是2個字符串相同或者str2所有是空格或者str2==null,就返回true,若是2個字符串不一樣,就返回false */
public static boolean stringEquals(String str1,String str2){
if(str2==null || str2.trim().length()<=0){
return true;
}
if(!str1.equals(str2.trim())){
return false;
}
return true;
}
/** * str1與str2模糊匹配 * 這個模糊匹配也是在str2不爲null且str2去掉2端空格的狀況下比較的!!! * @param str1---被比較的字符串 * @param str2---比較的字符串 * @return---若是str2是str1的子串或者str2所有是空格或str2==null,就返回true,若是str2不是str1的字串,就返回false */
public static boolean stringIndexOf(String str1,String str2){
if(str2==null || str2.trim().length()<=0){
return true;
}
if(str1.indexOf(str2.trim())==-1){
return false;
}
return true;
}
}
工具類DateUtil:
package cn.hncu.bookStore.util;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JOptionPane;
/** * 日期工具類 * @author 陳浩翔 * * @version 1.0 */
public class DateUtil {
/** * 根據傳入的long參數 ,把long值轉換爲固定的年月日格式輸出 * @param d---傳入的參數 * @return---一個字符串參數,格式爲:yyyy年MM月dd日 HH:mm:ss */
public static String long2String(long d){
Date date = new Date(d);
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
String str = df.format(date);
return str;
}
/* * 代碼抽取技術: * 首先不要想「抽出的方法」怎麼寫,而是把相似的代碼拷在一塊兒,觀察其中的變化部分和不變化部分。 * 把這段代碼中用到的「前面定義的變量」抽取成方法的參數--本例中爲txtInDate和erroInfo,把「留給後面使用的」將在這段代碼中新 * 建立的變量定義成方法的返回值---本例爲inDate。 */
/** * 根據傳入的日期格式,把String型的參數轉換成long型參數返回<br/> * 若是格式傳入錯誤,會根據傳入的erroInfo字符串彈出窗口給出提示! * @param txtInDate---傳入的日期。 * @param erroInfo----傳入的錯誤提示信息 * @return---long型的數字,若是格式轉換錯誤,返回-1; */
public static long string2Long(String txtInDate,String erroInfo){
DateFormat date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long inDate=0;
try {
Date d = date.parse(txtInDate);
inDate = d.getTime();
} catch (ParseException e) {
JOptionPane.showMessageDialog(null, erroInfo);
return -1;
}
return inDate;
}
}
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;
/** * * @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<InDetailModel> 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);
}
return true;
}
@Override
public Map<InMainModel, List<InDetailModel>> getAll() {
Map<InMainModel,List<InDetailModel>> map = new TreeMap<InMainModel, List<InDetailModel>>();
List<InMainModel> inMains = inMainDao.getAll();
for(InMainModel inMain: inMains ){
//查詢條件值對象的建立
InDetailQueryModel idqm = new InDetailQueryModel();
String inUuid = inMain.getUuid();
idqm.setInId(inUuid);
List<InDetailModel> details = inDetailDao.getbyCondition(idqm);
map.put(inMain, details);
}
return map;
}
@Override
public Map<InMainModel, List<InDetailModel>> getByCondition(
InMainQueryModel imqm, InDetailQueryModel idqm) {
Map<InMainModel, List<InDetailModel>> map = new TreeMap<InMainModel, List<InDetailModel>>();
List<InMainModel> list = inMainDao.getbyCondition(imqm);
for(InMainModel inMain : list){
idqm.setInId(inMain.getUuid());
List<InDetailModel> details = inDetailDao.getbyCondition(idqm);
if(details.size()!=0){
map.put(inMain, details);
}
}
return map;
}
}
這裏的代碼初始化的initComponents()方法是MyEclipse的Matisse from生成的。
核心代碼是查詢按鈕的監聽實現方法和myInitData()方法。
package cn.hncu.bookStore.in.ui;
import java.util.List;
import java.util.Map;
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.in.business.factory.InMainEbiFactory;
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.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.vo.UserModel;
import cn.hncu.bookStore.util.DateUtil;
/** * * @author 陳浩翔 * * @version 1.0 */
public class InQueryPanel extends javax.swing.JPanel {
private JFrame mainFrame = null;
/** Creates new form InQueryPanel * @param mainFrame */
public InQueryPanel(JFrame mainFrame) {
this.mainFrame = mainFrame;
initComponents();
myInitData();
}
/** * 初始化combo Box的數據 */
private void myInitData() {
//進貨人組合框內數據的初始化
List<UserModel> listUsers = UserEbiFactory.getUserEbi().getAllIn();
for (UserModel user : listUsers) {
combInUser.addItem(user.getName());
}
//圖書組合框內數據的初始化
List<BookModel> listBooks = BookEbiFactory.getBookEbi().getAll();
for (BookModel book : listBooks) {
combBook.addItem(book.getName());
}
}
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
combBook = new javax.swing.JComboBox();
jLabel7 = new javax.swing.JLabel();
tfdInUuid = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
combInUser = new javax.swing.JComboBox();
jLabel8 = new javax.swing.JLabel();
tfdInNum = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
tfdInDate = new javax.swing.JTextField();
jLabel10 = new javax.swing.JLabel();
tfdInDate2 = new javax.swing.JTextField();
jLabel11 = new javax.swing.JLabel();
tfdInNum2 = new javax.swing.JTextField();
jLabel12 = new javax.swing.JLabel();
tfdInDetailUuid = new javax.swing.JTextField();
jLabel13 = new javax.swing.JLabel();
tfdInSumMoney = new javax.swing.JTextField();
jLabel14 = new javax.swing.JLabel();
tfdInSumMoney2 = new javax.swing.JTextField();
jLabel15 = new javax.swing.JLabel();
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("微軟雅黑", 1, 36));
jLabel1.setForeground(new java.awt.Color(204, 0, 0));
jLabel1.setText("\u8fdb\u8d27\u67e5\u8be2");
add(jLabel1);
jLabel1.setBounds(290, 10, 170, 70);
jLabel5.setFont(new java.awt.Font("微軟雅黑", 0, 18));
jLabel5.setText("\u56fe\u4e66:");
add(jLabel5);
jLabel5.setBounds(460, 240, 50, 30);
combBook.setFont(new java.awt.Font("Dialog", 1, 18));
combBook.setForeground(new java.awt.Color(0, 0, 255));
combBook.setModel(new javax.swing.DefaultComboBoxModel(
new String[] { "查詢全部" }));
add(combBook);
combBook.setBounds(510, 240, 200, 30);
jLabel7.setFont(new java.awt.Font("微軟雅黑", 0, 18));
jLabel7.setText("\u8fdb\u8d27\u5355\u7f16\u53f7:");
add(jLabel7);
jLabel7.setBounds(100, 90, 100, 30);
add(tfdInUuid);
tfdInUuid.setBounds(210, 90, 150, 30);
jLabel4.setFont(new java.awt.Font("微軟雅黑", 0, 18));
jLabel4.setText("\u8fdb\u8d27\u4eba:");
add(jLabel4);
jLabel4.setBounds(440, 90, 80, 30);
combInUser.setFont(new java.awt.Font("Dialog", 1, 18));
combInUser.setForeground(new java.awt.Color(204, 204, 0));
combInUser.setModel(new javax.swing.DefaultComboBoxModel(
new String[] { "查詢全部" }));
add(combInUser);
combInUser.setBounds(510, 90, 200, 30);
jLabel8.setFont(new java.awt.Font("微軟雅黑", 0, 18));
jLabel8.setText("\u8fdb\u8d27\u6700\u5c0f\u6570\u91cf:");
add(jLabel8);
jLabel8.setBounds(80, 320, 120, 30);
add(tfdInNum);
tfdInNum.setBounds(210, 320, 150, 30);
jLabel9.setFont(new java.awt.Font("微軟雅黑", 0, 18));
jLabel9.setText("\u683c\u5f0f\u5982: 2016-04-13");
add(jLabel9);
jLabel9.setBounds(190, 190, 180, 30);
add(tfdInDate);
tfdInDate.setBounds(210, 160, 150, 30);
jLabel10.setFont(new java.awt.Font("微軟雅黑", 0, 18));
jLabel10.setText("\u8fdb\u8d27\u622a\u6b62\u65f6\u95f4:");
add(jLabel10);
jLabel10.setBounds(390, 160, 120, 30);
add(tfdInDate2);
tfdInDate2.setBounds(510, 160, 200, 30);
jLabel11.setFont(new java.awt.Font("微軟雅黑", 0, 18));
jLabel11.setText("\u8fdb\u8d27\u6700\u5927\u6570\u91cf:");
add(jLabel11);
jLabel11.setBounds(390, 320, 120, 30);
add(tfdInNum2);
tfdInNum2.setBounds(510, 320, 200, 30);
jLabel12.setFont(new java.awt.Font("微軟雅黑", 0, 18));
jLabel12.setText("\u8fdb\u8d27\u660e\u7ec6\u7f16\u53f7:");
add(jLabel12);
jLabel12.setBounds(80, 240, 120, 30);
add(tfdInDetailUuid);
tfdInDetailUuid.setBounds(210, 240, 150, 30);
jLabel13.setFont(new java.awt.Font("微軟雅黑", 0, 18));
jLabel13.setText("\u8fdb\u8d27\u603b\u4ef7\u6700\u5c0f\u503c:");
add(jLabel13);
jLabel13.setBounds(60, 400, 140, 30);
add(tfdInSumMoney);
tfdInSumMoney.setBounds(210, 400, 150, 30);
jLabel14.setFont(new java.awt.Font("微軟雅黑", 0, 18));
jLabel14.setText("\u8fdb\u8d27\u603b\u4ef7\u6700\u5927\u503c:");
add(jLabel14);
jLabel14.setBounds(370, 400, 140, 30);
add(tfdInSumMoney2);
tfdInSumMoney2.setBounds(510, 400, 200, 30);
jLabel15.setFont(new java.awt.Font("微軟雅黑", 0, 18));
jLabel15.setText("\u8fdb\u8d27\u8d77\u59cb\u65f6\u95f4:");
add(jLabel15);
jLabel15.setBounds(80, 160, 120, 30);
btnQuery.setFont(new java.awt.Font("Dialog", 1, 36));
btnQuery.setForeground(new java.awt.Color(255, 0, 0));
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(160, 490, 140, 60);
btnBack.setFont(new java.awt.Font("Dialog", 1, 36));
btnBack.setForeground(new java.awt.Color(255, 0, 0));
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(480, 490, 140, 60);
}// </editor-fold>
//GEN-END:initComponents
private void btnQueryActionPerformed(java.awt.event.ActionEvent evt) {
//1收集參數(且驗證輸入有效性)
//進貨單編號
String inUuid = tfdInUuid.getText();
//用戶姓名
String inUserName = combInUser.getSelectedItem().toString();
//用戶ID
String inUserUuid =null;
if(combInUser.getSelectedIndex()>0){
inUserUuid = UserEbiFactory.getUserEbi().getUserByName(inUserName).getUuid();
}
//進貨起始時間
String txtInDate = tfdInDate.getText();
long inDate = 0;
if(txtInDate!=null&txtInDate.trim().length()>0){
inDate = DateUtil.string2Long(txtInDate+" 00:00:00", "進貨起始時間格式錯誤!");
if(inDate==-1){
return ;
}
}
//進貨截止時間
String txtInDate2 = tfdInDate2.getText();
long inDate2 = 0;
if(txtInDate2!=null&txtInDate2.trim().length()>0){
inDate2 = DateUtil.string2Long(txtInDate2+ " 23:59:59", "進貨截止時間格式錯誤!");
if(inDate2==-1){
return ;
}
}
//進貨明細單編號
String inDetailUuid = tfdInDetailUuid.getText();
//書的Uuid
String bookUuid =null;
if(combBook.getSelectedIndex()>0){
String bookName = combBook.getSelectedItem().toString();
bookUuid = BookEbiFactory.getBookEbi().getBookByName(bookName).getUuid();
}
//進貨最小數量
int sumNum =0;
if(tfdInNum.getText()!=null && tfdInNum.getText().trim().length()>0){
try {
sumNum = Integer.parseInt( tfdInNum.getText() );
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(mainFrame, "進貨數量最小值格式錯誤");
return ;
}
}
//進貨最大數量
int sumNum2 =0;
if(tfdInNum2.getText()!=null && tfdInNum2.getText().trim().length()>0){
try {
sumNum2 = Integer.parseInt( tfdInNum2.getText() );
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(mainFrame, "進貨數量最大值格式錯誤");
return ;
}
}
//進貨最小總價
double sumMoney =0;
if(tfdInSumMoney.getText()!=null && tfdInSumMoney.getText().trim().length()>0){
try {
sumMoney = Double.parseDouble(tfdInSumMoney.getText());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(mainFrame, "進貨總價最小值格式錯誤");
return;
}
}
//進貨最大總價
double sumMoney2 =0;
if(tfdInSumMoney2.getText()!=null && tfdInSumMoney2.getText().trim().length()>0){
try {
sumMoney2 = Double.parseDouble(tfdInSumMoney2.getText());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(mainFrame, "進貨總價最小值格式錯誤");
return;
}
}
//2組織參數----分別組織InMainQueryModel和InDetailQueryModel
//組織InMainQueryModel
InMainQueryModel imqm = new InMainQueryModel();
imqm.setUuid(inUuid);
imqm.setInUserId(inUserUuid);
imqm.setInDate(inDate);
imqm.setInDate2(inDate2);
//組織InDetailQueryModel
InDetailQueryModel idqm = new InDetailQueryModel();
idqm.setUuid(inDetailUuid);
idqm.setBookId(bookUuid);
idqm.setSumMoney(sumMoney);
idqm.setSumMoney2(sumMoney2);
idqm.setSumNum(sumNum);
idqm.setSumNum2(sumNum2);
//3調用邏輯層
Map<InMainModel, List<InDetailModel>> map = InMainEbiFactory.getInMainEbi().getByCondition(imqm, idqm);
//4返回到結果頁面
mainFrame.setContentPane(new InListPanel(mainFrame,map));
mainFrame.validate();
}
private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
back();
}
private void back() {
mainFrame.setContentPane(new InListPanel(mainFrame));
mainFrame.validate();
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton btnBack;
private javax.swing.JButton btnQuery;
private javax.swing.JComboBox combBook;
private javax.swing.JComboBox combInUser;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JTextField tfdInDate;
private javax.swing.JTextField tfdInDate2;
private javax.swing.JTextField tfdInDetailUuid;
private javax.swing.JTextField tfdInNum;
private javax.swing.JTextField tfdInNum2;
private javax.swing.JTextField tfdInSumMoney;
private javax.swing.JTextField tfdInSumMoney2;
private javax.swing.JTextField tfdInUuid;
// End of variables declaration//GEN-END:variables
}
目前個人本系列全部源代碼已打包上傳至百度雲:
http://pan.baidu.com/s/1nv5ZZwX 2016.4.19