排球比赛计分系统

一、设计思路

计分系统根据不同角色拥有不同的界面和展示效果:

1.管理员-----用户管理,赛事管理,赛事记录,队伍管理

2.比赛主办方-------赛事管理,队伍管理

3.裁判--------赛事记录

其他人员在管理员未分配权限时不具有任何权限,只能观看比赛信息

运用Struts2和hibernate框架,进行数据视图交互

二、代码部分(比赛计分,信息展示部分)

1.GamesDaoImpl.java

package com.dao.impl;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.bean.GamesInfo;
import com.bean.GamesNotice;
import com.bean.Users;
import com.dao.BaseDao;
import com.dao.GamesDao;

public class GamesDaoImpl extends BaseDao implements GamesDao {
/*
 * 插入比赛计分信息*/
    public boolean saveGames(GamesInfo games) {
        Session session=null;
        Transaction tr=null;
        try {
            session=getSession();
            tr=session.beginTransaction();
            session.save(games);
            tr.commit();
        } catch (HibernateException e) {
            e.printStackTrace();
            tr.rollback();
            return false;
        }finally{
            closeSession();
        }
        return true;
    }
    /*
     * 插入比赛计分信息成功更新赛事信息*/
    public boolean updateGames(GamesNotice gamesNotice) {
        Session session=null;
        Transaction tr=null;
        try {
            session=getSession();
            tr=session.beginTransaction();
            session.update(gamesNotice);
            tr.commit();
        } catch (HibernateException e) {
            e.printStackTrace();
            tr.rollback();
            return false;
        }finally{
            closeSession();
        }
        return true;
    }
    /*
     * 观看比赛计分信息,模糊查询*/
    public List SalChanceList(String Title) {
        List SalChanceList=null;
        Session session=null;
        Transaction tr=null;
        try {
            session = getSession();
            tr = session.beginTransaction();
            StringBuffer hql=new StringBuffer();
            hql.append("from GamesInfo where 1=1");
            if (!"".equals(Title)) {
                hql.append(" and GTitle like '%"+Title+"%' ");
            }
            Query query=session.createQuery(hql.toString());
            query.setFirstResult(1);
            query.setMaxResults(8);
            SalChanceList=query.list();
            tr.commit();
        } catch (Exception e) {
            tr.rollback();
        }
        return SalChanceList;
    }
/*
     * 根据id查询赛事信息*/
    public GamesNotice selectGamesNotice(int id) {
        GamesNotice gamesNotice=null;
        Session session=null;
        try {
            session=getSession();
            String hql="from GamesNotice where NId=?";
            Query query=session.createQuery(hql);
            query.setInteger(0, id);
            List list=query.list();
            if(list.size()>0){
                gamesNotice=list.get(0);
            }
        } catch (HibernateException e) {
            e.printStackTrace();
        }finally{
            closeSession();
        }
        return gamesNotice;
    }
    /*
     * 新建赛事信息*/
    public boolean saveGamesNotice(GamesNotice gamesNotice) {
        Session session=null;
        Transaction tr=null;
        try {
            session=getSession();
            tr=session.beginTransaction();
            session.save(gamesNotice);
            tr.commit();
        } catch (HibernateException e) {
            e.printStackTrace();
            tr.rollback();
            return false;
        }finally{
            closeSession();
        }
        return true;
    }
}

2.gamesAction.java

package com.action;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.bean.GamesInfo;
import com.bean.GamesNotice;
import com.dao.GamesDao;
import com.dao.impl.GamesDaoImpl;
import com.opensymphony.xwork2.ActionSupport;

public class gamesAction extends ActionSupport {
    private GamesInfo games;//计分信息类
    private GamesNotice gamesNotice;//赛事信息类
 public String addGames() {
     GamesDao gamesDao=new GamesDaoImpl();
     //拿到赛事表id查询title
     int id=Integer.parseInt(games.getGTitle());
     GamesNotice gamesNotice=gamesDao.selectGamesNotice(id);
     games.setGTitle(gamesNotice.getNName());
     //比赛信息数据写入数据库
    boolean flag=gamesDao.saveGames(games);
    if(flag=true){
        //执行成功,相应的赛事状态为2已比赛完成
        gamesNotice.setTState(2);
        gamesDao.updateGames(gamesNotice);
        return SUCCESS;
    }else {
        return "error";
    }
}
 public String NoticeAdd(){
     GamesDao gamesDao=new GamesDaoImpl();
     //添加赛事
     boolean flag=gamesDao.saveGamesNotice(gamesNotice);
        if(flag=true){
            return SUCCESS;
        }else {
            return ERROR;
        }
 }
public GamesInfo getGames() {
    return games;
}
public void setGames(GamesInfo games) {
    this.games = games;
}
public GamesNotice getGamesNotice() {
    return gamesNotice;
}
public void setGamesNotice(GamesNotice gamesNotice) {
    this.gamesNotice = gamesNotice;
}

}

3.js方法

     

三、运行效果

排球比赛计分系统_第1张图片

排球比赛计分系统_第2张图片

排球比赛计分系统_第3张图片

排球比赛计分系统_第4张图片排球比赛计分系统_第5张图片

排球比赛计分系统_第6张图片

排球比赛计分系统_第7张图片

排球比赛计分系统_第8张图片

你可能感兴趣的:(排球比赛计分系统)