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

📄 opengroupaction.java

📁 旅游自助系统
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package org.tshs.struts.action;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Vector;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.tshs.core.AuthenticationManager;
import org.tshs.core.CacheManager;
import org.tshs.entity.SightSpot;
import org.tshs.entity.TravelCorp;
import org.tshs.entity.TshsObject;

/** 
 * MyEclipse Struts
 * Creation date: 12-30-2006
 * 
 * XDoclet definition:
 * @struts.action validate="true"
 * @struts.action-forward name="success" path="/client/serchgroup.jsp"
 */
public class OpengroupAction extends Action {
	/*
	 * Generated Methods
	 */

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		Object obj = request.getSession().getAttribute("corp");
		if(obj == null){
			request.setAttribute("message", "你的操作需要以旅游公司身份登陆后才能执行!");
			return new ActionForward("/corp/travcorplogin.jsp");
		}
		TravelCorp corp = (TravelCorp)obj;
		if("get".equals(request.getMethod().toLowerCase())){
			Vector sights = AuthenticationManager.getAllSightspots();
			request.setAttribute("sights", sights);
			return new ActionForward("/corp/groupregiste.jsp");
		}
		String name = request.getParameter("name");
		String capacity = request.getParameter("capacity");
		String sights = request.getParameter("sights");
		String description = request.getParameter("description");
		String year = request.getParameter("year");
		String month = request.getParameter("month");
		String day = request.getParameter("day");
		Calendar c = new GregorianCalendar();
		c.set(Integer.valueOf(year), Integer.valueOf(month), Integer.valueOf(day));
		Date start = c.getTime();
		StringBuffer message = new StringBuffer();
		if(name == null||name.trim().length()==0){
			message.append("旅游团名称不能为空; ");
		} else{
			try {
				if (AuthenticationManager.existGroup(name)) {
					message.append("名为" + name + "的旅游团已经被注册; ");
				}
			} catch (Exception e1) {
				e1.printStackTrace();
				Vector v = new Vector();
				v.add("旅游团添加失败,请稍后重试!");
				request.setAttribute("error", v);
				return mapping.findForward("error");
			}
		}
		int cap = 0;
		if(capacity == null||capacity.trim().length()==0){
			message.append("人数上限不能为空; ");
		}else if(!Pattern.matches("[\\d]+$", capacity)){
			message.append("人数上限不是一个正整数; ");
		}else{
			cap = Integer.parseInt(capacity);
		}
		Vector<Long> sightids = new Vector<Long>(); 
		if(sights == null||sights.trim().length()==0){
			message.append("景点信息不能为空; ");
		}else{
			String[] temp = sights.split(" ");
			for(String s: temp){
				if(!Pattern.matches("[\\d]+$", s)){
					message.append("景点编号\""+ s +"\"填写有误; ");
				}else{
					Long tid = Long.parseLong(s);
					TshsObject tobj = null;
					try {
						tobj = CacheManager.getById(tid);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
						Vector v = new Vector();
						v.add("旅游团添加失败,请稍后重试!");
						request.setAttribute("error", v);
						return mapping.findForward("error");
					}
					if(tobj!=null&&tobj instanceof SightSpot){
						sightids.add(tid);
					}else{
						message.append("编号为\""+ s +"\"的景点不存在<br>");
					}
				}
			}
		}
		if(description == null||description.trim().length()==0){
			message.append("旅游团简介不能为空<br>");
		}
		if(message.length()!=0){
			request.setAttribute("message", message.toString());
			Vector info = new Vector();
			info.add(name);
			info.add(capacity);
			info.add(sights);
			info.add(description);
			request.setAttribute("information", info);
			request.setAttribute("sights", AuthenticationManager.getAllSightspots());
			ActionForward forward = mapping.findForward("fail");
			return forward;
		}
		if(AuthenticationManager.openGroup(corp.getId(), name, cap, start, sightids, description)){ 
			request.setAttribute("message","旅游团添加成功!");
			return mapping.findForward("success");
		}else{
			Vector v = new Vector();
			v.add("旅游团添加失败,请稍后重试!");
			request.setAttribute("error", v);
			return mapping.findForward("error");
		}
	}
}

⌨️ 快捷键说明

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