排球比赛计分系统
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了排球比赛计分系统相关的知识,希望对你有一定的参考价值。
一、设计思路
计分系统根据不同角色拥有不同的界面和展示效果:
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<GamesInfo> SalChanceList(String Title) {
List<GamesInfo> 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<GamesNotice> 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方法
<script type="text/javascript"> var Team1=0;<%--记录队伍1的胜利次数--%> var Team2=0;<%--记录队伍2的胜利次数--%> function add1(){ var num1 = parseInt(document.getElementById("txt1").value);<%--获取分数--%> var num=num1+1;<%--分数加1--%> document.getElementById("txt1").value=num;<%--把分数放到文本框--%> Team1=parseInt(document.getElementById("Team1").value);<%--获取胜利次数--%> if(num>=25){<%--判断当前分数是否大于25.大于25胜利次数加1--%> Team1=Team1+1; document.getElementById("Team1").value=Team1; } var num3 = parseInt(document.getElementById("txt2").value);<%--获取队伍2的分数--%> if(num>25||num3==25){<%--队伍1分数是否大于等于25。队伍二分数是否已经是25--%> alert("请开始下一局"); document.getElementById("txt1").value=num1;<%--是则不不能加分--%> document.getElementById("Team1").value=Team1-1;<%--刚加的胜利场数减掉--%> } if(num3==25){<%--对方先到25自己的胜利场次不加不减--%> document.getElementById("Team1").value=Team1 } } function add2(){ var num1 = parseInt(document.getElementById("txt2").value); var num=num1+1; document.getElementById("txt2").value=num; Team2=parseInt(document.getElementById("Team2").value); if(num>=25){ Team2=Team2+1; document.getElementById("Team2").value=Team2; } var num3 = parseInt(document.getElementById("txt1").value); if(num>25||num3==25){ alert("请开始下一局"); document.getElementById("txt2").value=num-1; document.getElementById("Team2").value=Team2-1; } if(num3==25){ document.getElementById("Team2").value=Team2; } } function add3(){ var num1 = parseInt(document.getElementById("txt3").value); var num=num1+1; document.getElementById("txt3").value=num; Team1=parseInt(document.getElementById("Team1").value); if(num>=25){ Team1=Team1+1; document.getElementById("Team1").value=Team1; } var num3 = parseInt(document.getElementById("txt4").value); if(num>25||num3==25){ alert("请开始下一局"); document.getElementById("txt3").value=num-1; document.getElementById("Team1").value=Team1-1; } if(num3==25){ document.getElementById("Team1").value=Team1; } } function add4(){ var num1 = parseInt(document.getElementById("txt4").value); var num=num1+1; document.getElementById("txt4").value=num; Team2=parseInt(document.getElementById("Team2").value); if(num>=25){ Team2=Team2+1; document.getElementById("Team2").value=Team2; } var num3 = parseInt(document.getElementById("txt3").value); if(num>25||num3==25){ alert("请开始下一局"); document.getElementById("txt4").value=num-1; document.getElementById("Team2").value=Team2-1; } if(num3==25){ document.getElementById("Team2").value=Team2; } } function add5(){ var num1 = parseInt(document.getElementById("txt5").value); var num=num1+1; document.getElementById("txt5").value=num; Team1=parseInt(document.getElementById("Team1").value); if(num>=25){ Team1=Team1+1; document.getElementById("Team1").value=Team1; } var num3 = parseInt(document.getElementById("txt6").value); if(num>25||num3==25){ alert("请开始下一局"); document.getElementById("txt5").value=num-1; document.getElementById("Team1").value=Team1-1; } if(num3==25){ document.getElementById("Team1").value=Team1; } } function add6(){ var num1 = parseInt(document.getElementById("txt6").value); var num=num1+1; document.getElementById("txt6").value=num; Team2=parseInt(document.getElementById("Team2").value); if(num>=25){ Team2=Team2+1; document.getElementById("Team2").value=Team2; } var num3 = parseInt(document.getElementById("txt5").value); if(num>25||num3==25){ alert("请开始下一局"); document.getElementById("txt6").value=num-1; document.getElementById("Team2").value=Team2-1; } if(num3==25){ document.getElementById("Team2").value=Team2}; } function add7(){ var num1 = parseInt(document.getElementById("txt7").value);<%--获取分数--%> var num=num1+1;<%--分数加1--%> document.getElementById("txt7").value=num;<%--把分数放到文本框--%> Team1=parseInt(document.getElementById("Team1").value);<%--获取队伍1胜利次数--%> Team2=parseInt(document.getElementById("Team2").value);<%--获取队伍2胜利次数--%> if(Team1==3||Team2==3){<%--判断当前场次是否有队伍胜3场--%> alert("比赛结束,请提交"); document.getElementById("txt7").value=num1; }else{ if(num>=25){<%--判断当前分数是否大于25.大于25胜利次数加1--%> Team1=Team1+1; document.getElementById("Team1").value=Team1; } var num3 = parseInt(document.getElementById("txt8").value);<%--获取队伍2的分数--%> if(num>25||num3==25){<%--队伍1分数是否大于等于25。队伍二分数是否已经是25--%> alert("请开始下一局"); document.getElementById("txt1").value=num1;<%--是则不不能加分--%> document.getElementById("Team1").value=Team1-1;<%--刚加的胜利场数减掉--%> } if(num3==25){<%--对方先到25自己的场次不加不减--%> document.getElementById("Team1").value=Team1 } } } function add8(){ var num1 = parseInt(document.getElementById("txt8").value); var num=num1+1; document.getElementById("txt8").value=num; Team1=parseInt(document.getElementById("Team1").value); Team2=parseInt(document.getElementById("Team2").value); if(Team1==3||Team2==3){ alert("比赛结束,请提交"); document.getElementById("txt8").value=num1; }else{ if(num>=25){ Team2=Team2+1; document.getElementById("Team2").value=Team2; } var num3 = parseInt(document.getElementById("txt7").value); if(num>25||num3==25){ alert("请开始下一局"); document.getElementById("txt8").value=num1; document.getElementById("Team2").value=Team2-1; } if(num3==25){ document.getElementById("Team2").value=Team2 } } } function add9(){ var num1 = parseInt(document.getElementById("txt9").value); var num=num1+1; document.getElementById("txt9").value=num; Team1=parseInt(document.getElementById("Team1").value); Team2=parseInt(document.getElementById("Team2").value); if(Team1==3||Team2==3){ alert("比赛结束,请提交"); document.getElementById("txt9").value=num1; }else{ if(num>=15){ Team1=Team1+1; document.getElementById("Team1").value=Team1; } var num3 = parseInt(document.getElementById("txt10").value); if(num>15||num3==15){ alert("请开始下一局"); document.getElementById("txt1").value=num1; document.getElementById("Team1").value=Team1-1; } if(num3==15){ document.getElementById("Team1").value=Team1 } } } function add10(){ var num1 = parseInt(document.getElementById("txt10").value); var num=num1+1; document.getElementById("txt10").value=num; Team1=parseInt(document.getElementById("Team1").value); Team2=parseInt(document.getElementById("Team2").value); if(Team1==3||Team2==3){ alert("比赛结束,请提交"); document.getElementById("txt10").value=num1; }else{ if(num>=25){ Team2=Team2+1; document.getElementById("Team2").value=Team2; } var num3 = parseInt(document.getElementById("txt9").value); if(num>15||num3==15){ alert("请开始下一局"); document.getElementById("txt10").value=num1; document.getElementById("Team2").value=Team2-1; } if(num3==15){ document.getElementById("Team2").value=Team2 } } }
</script>
三、运行效果
以上是关于排球比赛计分系统的主要内容,如果未能解决你的问题,请参考以下文章