/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package pos.struts.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import pos.commons.CrossPageInfo;
import pos.hibernate.dao.TicketinfoDAO;
import pos.hibernate.dao.VbranchinfoDAO;
import pos.hibernate.orm.Agentinfo;
import pos.hibernate.orm.Branchinfo;
import pos.hibernate.orm.Subbranchinfo;
import pos.hibernate.orm.Ticketinfo;
import pos.hibernate.orm.Vbranchinfo;
/**
* MyEclipse Struts
* Creation date: 12-12-2007
*
* XDoclet definition:
* @struts.action path="/ticketinfo" name="ticketinfoForm" input="/jsp/TicketInfo/ticketinfo.jsp" parameter="action" scope="request" validate="true"
*/
public class TicketinfoAction extends DispatchAction{
/*
* Generated Methods
*/
private TicketinfoDAO ticketinfodao = null;
private VbranchinfoDAO vbranchinfodao = null;
private int p_Size= 14;
public TicketinfoDAO getTicketinfodao() {
return ticketinfodao;
}
public void setTicketinfodao(TicketinfoDAO ticketinfodao) {
this.ticketinfodao = ticketinfodao;
}
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
//初始化的时候显示所有的分公司名称 public ActionForward initgetbranchlist(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
//处理ajax返回乱码问题
response.setContentType("text/xml; charset=UTF-8");
StringBuffer responseXML = new StringBuffer("<domains>");
List branchlist = vbranchinfodao.getBranchInfo_ViewList();
if(branchlist!=null && branchlist.size()>0){
Iterator it =branchlist.iterator();
while (it.hasNext()) {
Vbranchinfo vbranch = (Vbranchinfo)it.next();
responseXML.append("<domain");
responseXML.append(" id='" + vbranch.getId().getBranchid());
responseXML.append("'>");
responseXML.append(vbranch.getId().getName());
responseXML.append("</domain>");
}
}
responseXML.append("</domains>");
try {
PrintWriter out = (PrintWriter)response.getWriter();
out.write(responseXML.toString());
//out.flush();
} catch (IOException e) {
//do nothing
e.printStackTrace();
}
return null;
}
public ActionForward changebranchinfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
//处理ajax返回乱码问题
response.setContentType("text/xml; charset=UTF-8");
String domainId = request.getParameter("domainId");//下拉列表值
String select_type = request.getParameter("select_type");//选择的是哪一个下拉
StringBuffer responseXML = new StringBuffer("<domains>");
if(select_type.equals("branch")){//如果是选择分公司
Branchinfo branchinfo = ticketinfodao.getBranchinfobyBranchID(domainId);
List list = ticketinfodao.getSubBranchInfoListByBranch(branchinfo);
if(list!=null && list.size()>0){
Iterator it = list.iterator();
while (it.hasNext()) {
Subbranchinfo subbranch = (Subbranchinfo)it.next();
responseXML.append("<domain");
responseXML.append(" id='" + subbranch.getSubbranchid());
responseXML.append("'>");
responseXML.append(subbranch.getName());
responseXML.append("</domain>");
}
}
}else if(select_type.equals("subbranch")){//如果是选择支公司
Subbranchinfo subbranch = ticketinfodao.getSubbranchinfoBySubBranchID(domainId);
List list = ticketinfodao.getAgentInfoListBySubBranch(subbranch);
if(list!=null && list.size()>0){
Iterator it = list.iterator();
while (it.hasNext()) {
Agentinfo agent = (Agentinfo)it.next();
responseXML.append("<domain");
if(request.getParameter("queryagentname")==null){
responseXML.append(" id='" + agent.getAgentid());
}else{
responseXML.append(" id='" + agent.getAgentname());
}
responseXML.append("'>");
responseXML.append(agent.getAgentname());
responseXML.append("</domain>");
}
}
}
responseXML.append("</domains>");
try {
PrintWriter out = (PrintWriter)response.getWriter();
out.write(responseXML.toString());
//out.flush();
} catch (IOException e) {
//do nothing
e.printStackTrace();
}
return null;
}
public VbranchinfoDAO getVbranchinfodao() {
return vbranchinfodao;
}
public void setVbranchinfodao(VbranchinfoDAO vbranchinfodao) {
this.vbranchinfodao = vbranchinfodao;
}
}