Java-单机版的书店管理系统(练习设计模块和思想_系列 七 )

本系列前面博客的链接:

Java-单机版的书店管理系统(练习设计模块和思想_系列 六 )
http://blog.csdn.net/qq_26525215/article/details/51169277

Java-单机版的书店管理系统(练习设计模块和思想_系列 五 )
http://blog.csdn.net/qq_26525215/article/details/51136848

Java-单机版的书店管理系统(练习设计模块和思想_系列 四(2) ):
http://blog.csdn.net/qq_26525215/article/details/51117135

Java-单机版的书店管理系统(练习设计模块和思想_系列 四(1) ):
http://blog.csdn.net/qq_26525215/article/details/51116429

Java-单机版的书店管理系统(练习设计模块和思想_系列 三 ):
http://blog.csdn.net/qq_26525215/article/details/51099202

Java-单机版的书店管理系统(练习设计模块和思想_系列 二 ):
http://blog.csdn.net/qq_26525215/article/details/51089734

Java-单机版的书店管理系统(练习设计模块和思想_系列 一 ):
http://blog.csdn.net/qq_26525215/article/details/51073546

介绍:

现在已经将进货模块的查询写完了,

(进货模块只有添加和查询!没有删除和修改。
因为如果能随便修改进货的时间,进货的数量等,这不是乱套了嘛)

现在完成的模块有:用户模块,图书模块,进货模块。
新增写了一个日期类,将long型数字转换成某个日期格式显示给用户看。
将string型的日期格式转换成long型数字存储。
将前面的StringComparison类进行了修改。

现在剩下的模块还有销售模块,库存模块,还有登录界面,
库存模块是需要综合销售模块和进货模块来写的。
也就是模块与模块之间需要串接了。
现在我写的这3个模块,基本上是属于和对方没什么联系的,每个模块都能独自完成自己的功能。

只亮一张进货查询的图片吧。界面不好看(^-^)勿喷噢。

增加或修改的代码:

工具类StringComparison :

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;
    }

}

进货模块的逻辑层实现类InMainEbo:

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;
    }

}

表现层查询界面的代码InQueryPanel:

这里的代码初始化的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

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谙忆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值