⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voteaction.java

📁 简易java框架开源论坛系统,简 易java框架开源论坛系统
💻 JAVA
字号:
package com.easyjf.bbs.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import com.easyjf.bbs.business.ActiveUser;
import com.easyjf.bbs.business.BBSDir;
import com.easyjf.bbs.business.BBSDoc;
import com.easyjf.bbs.business.BBSRights;
import com.easyjf.bbs.business.Vote;
import com.easyjf.bbs.business.util.VoteUtil;
import com.easyjf.util.CommUtil;
import com.easyjf.web.ActionContext;
import com.easyjf.web.Module;
import com.easyjf.web.Page;
import com.easyjf.web.WebForm;
import com.easyjf.web.tools.AbstractCmdAction;
import com.easyjf.web.tools.IPageList;
import com.easyjf.bbs.business.*;

public class VoteAction extends AbstractCmdAction {

	public Page doInit(WebForm form, Module module) {
		// TODO Auto-generated method stub
		return null;
	}

	public Page doList(WebForm form, Module module) {
		if (!BBSRights.checkRights(new Vote(), "list", getCurrentUser()))
			return new Page("popedomError", "/bbs/norights.htm", "page");
		return doQuery(form, module);
	}

	private ActiveUser getCurrentUser() {
		ActiveUser user = (ActiveUser) ActionContext.getContext().getSession()
				.getAttribute("bbsuser");
		return user;
	}

	public Page doVoting(WebForm form, Module module) {
		String voteitemid = CommUtil.null2String(form.get("chioc"));
		VoteItem vi = VoteItem.read(voteitemid);
		System.out.println(vi);
		if (vi != null) {
			int num = vi.getVotenum().intValue();
			vi.setVotenum(new Integer(num + 1));
			vi.update();
			//Vote vote=Vote.read(vi.getVoteid());
			//num=vote.getNum().intValue();
			//vote.setNum(new Integer(num+1));
			//vote.update();
			form.addResult("msg", "投票成功");
		}
		String cid=Vote.read(vi.getVoteid()).getDocid();
		return new Page("result","/bbsdoc.ejf?easyJWebCommand=show&&cid="+cid,"page");
	}
	
	public Page doResult(WebForm form, Module module){
		String cid=CommUtil.null2String(form.get("cid"));
		int max=0;
		if(cid!=null){
			Vote vote=Vote.read(cid);
			List vi=VoteUtil.resultById(cid);
			
			for(Iterator it=vi.iterator();it.hasNext();){
				max+=((VoteItem)it.next()).getVotenum().intValue();
			}
			System.out.println(max);
			form.addResult("vote",vote);
			form.addResult("voteitem",vi);
			form.addResult("max",new Integer(max));
		}
		return module.findPage("result");
	}

	public Page doQuery(WebForm form, Module module) {
		int currentPage = CommUtil.null2Int(form.get("page"));
		int pageSize = CommUtil.null2Int(form.get("pageSize"));
		if (currentPage < 1)
			currentPage = 1;
		if (pageSize < 1)
			pageSize = 15;

		IPageList pList = VoteUtil.queryVotes("1=1", pageSize, currentPage);
		/*
		List votes = pList.getResult();
		
		if (votes != null) {
			for (Iterator it = votes.iterator(); it.hasNext();) {
				Vote vote = (Vote) it.next();
				String docid = vote.getDocid();
				System.out.println(docid);
				BBSDoc doc=BBSDoc.read(docid);
				System.out.println(doc);
				String dirsn=doc.getDirSn();
				BBSDir dir = BBSDir.readBySN(dirsn);
				vote.setDocid(dir.getTitle());
			}
		}
		*/

		if (pList != null) {
			form.addResult("list", pList.getResult());
			form.addResult("pages", new Integer(pList.getPages()));
			form.addResult("rows", new Integer(pList.getRowCount()));
			form.addResult("page", new Integer(pList.getCurrentPage()));
			form.addResult("gotoPageHTML", CommUtil.showPageHtml(pList
					.getCurrentPage(), pList.getPages()));
		}
		return module.findPage("list");
	}

	public Page doDel(WebForm form, Module module) {
		String voteid = CommUtil.null2String(form.get("cid"));
		if (VoteUtil.delById(voteid)) {
			form.addResult("msg", "删除成功");
			return doQuery(form, module);
		}
		return null;
	}

	public Page doCreate(WebForm form, Module module) {
		List dirs = BBSUtil.listDir();
		form.addResult("dirs", dirs);
		return module.findPage("init");
	}

	public Page doAddItem(WebForm form, Module module) {
		String dirid = CommUtil.null2String(form.get("dirid"));
		int itemnum = CommUtil.null2Int(form.get("itemnum"));
		System.out.println(itemnum);
		List items = new ArrayList(itemnum);
		for (int i = 0; i < itemnum; i++) {
			items.add(i, new Integer(i));
		}
		form.addResult("itemnum", new Integer(itemnum));
		form.addResult("nums", items);
		form.addResult("dirid", dirid);
		return module.findPage("add");
	}

	public Page doAdd(WebForm form, Module module) {
		int itemnum = CommUtil.null2Int(form.get("itemnum"));
		String dirid = CommUtil.null2String(form.get("dirid"));
		String[] items = new String[itemnum];
		for (int i = 0; i < itemnum; i++) {
			items[i] = CommUtil.null2String(form.get("item" + i));
		}
		String votetitle = CommUtil.null2String(form.get("title"));
		String voteinfo = CommUtil.null2String(form.get("info"));
		Vote vote = new Vote();
		vote.setDate(new Date());
		vote.setInfo(voteinfo);
		vote.setTitle(votetitle);
		vote.setNum(new Integer(0));
		VoteUtil.add(dirid, vote, items);
		form.addResult("msg", "添加成功");
		return this.doQuery(form, module);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -