码迷,mamicode.com
首页 > 其他好文 > 详细

团队作业六

时间:2016-05-22 08:30:01      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

1、系统框架

 

 

2、系统结构图

  技术分享

3、各模块详细设计

  由于这次我们的项目主要是用来熟悉软件工程的流程,所以难度不大。

  1、帐号

技术分享
package cn.edu.sau.model;

public class User {
    private int id;
    private String userName;
    private String userPassword;
    private int role = 0; //默认为0->读者  1->图书管理员
    
    public User(){
        
    }
    
    public User(String userName, String userPassword) {
        super();
        this.userName = userName;
        this.userPassword = userPassword;
    }
    
    public User(String userName, String userPassword, int role) {
        super();
        this.userName = userName;
        this.userPassword = userPassword;
        this.role = role;
    }

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getUserPassword() {
        return userPassword;
    }
    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    public int getRole() {
        return role;
    }

    public void setRole(int role) {
        this.role = role;
    }
    
}
cn.edu.sau.model.User

  User类实现了对帐号的抽象描述,主要包括用户名,密码以及帐号角色。

技术分享
 1 package cn.edu.sau.dao;
 2 
 3 import java.sql.Connection;
 4 import java.sql.PreparedStatement;
 5 import java.sql.ResultSet;
 6 
 7 import cn.edu.sau.model.User;
 8 
 9 public class UserDao {
10     public User login(Connection con,User user) throws Exception{
11         User returnUser = null;
12         String sql = "select * from t_user where userName=? and password=?";
13         PreparedStatement pstmt = con.prepareStatement(sql);
14         pstmt.setString(1, user.getUserName());
15         pstmt.setString(2, user.getUserPassword());
16         ResultSet rs = pstmt.executeQuery();
17         if(rs.next()){
18             returnUser = new User(rs.getString("userName"),rs.getString("password"),rs.getInt("role"));
19         }
20         return returnUser;
21     }
22 }
cn.edu.sau.dao.UserDao

  UserDao提供帐号验证的方法并返回帐号对象,为空则帐号不存在。

技术分享
String userName = userNameTxt.getText();
                String userPassword = new String(userPasswordTxt.getPassword());
                if(StringUtil.isEmpty(userName)){
                    JOptionPane.showMessageDialog(null, "用户名不能为空");
                    return;
                }
                if(StringUtil.isEmpty(userPassword)){
                    JOptionPane.showMessageDialog(null, "密码不能为空");
                    return;
                }
                User user = new User(userName,userPassword);
                Connection con = null;
                
                try {
                    con = dbUtil.getCon();
                    User reUser = userDao.login(con, user);
                    if(reUser != null){
//                        JOptionPane.showMessageDialog(null, "登录成功");
                        dispose();//销毁登录框
                        if(1 == reUser.getRole()){
                            new MainFrm().setVisible(true);//创建管理员主界面Firme
                        }
                        else if(0 == reUser.getRole()){
                             new UserMainFrm().setVisible(true); //创建读者主界面
                        }
                    }else{
                        JOptionPane.showMessageDialog(null, "用户名或密码不正确");
                    }
                } catch (Exception e1) {
                    JOptionPane.showMessageDialog(null, "登录失败");
                    e1.printStackTrace();
                } finally{
                    try {
                        con.close();
                    } catch (SQLException e1) {
                        e1.printStackTrace();
                    }
                }
                
            }
cn.edu.sau.view.LogonFrm

  登录框界面通过验证逻辑层返回的帐号数据判断帐号是否存在,以及判断帐号权限,打开新的界面。

  2、图书类别维护

 未完待续...

  

团队作业六

标签:

原文地址:http://www.cnblogs.com/qmzmfteam/p/5516108.html

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