package com.ordobill.webapp.action;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.DispatchAction;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ordobill.webapp.beans.Oreda;
import com.ordobill.webapp.beans.OredaEqDB;
import com.ordobill.webapp.beans.OredaEqipment;
import com.ordobill.webapp.common.SqlMapClientManager;
import flex.remoteObjectTest.RemoteJava;
public class OredaAction extends DispatchAction {
private Log log = LogFactory.getFactory().getInstance(this.getClass().getName());
private SqlMapClient sqlMap = SqlMapClientManager.getSqlMapClient();
@SuppressWarnings("unchecked")
public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Oreda _Oreda = (Oreda)form;
ArrayList<Oreda> tableList = (ArrayList<Oreda>) sqlMap.queryForList("Oreda.tableList", _Oreda);
request.setAttribute("tableList", tableList);
request.setAttribute("oredaForm", _Oreda);
return mapping.findForward("list");
}
@SuppressWarnings("unchecked")
public ActionForward infoList(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Oreda _Oreda = (Oreda)form;
OredaEqipment _OredaEqipment = new OredaEqipment();
ArrayList<Oreda> oredaListInfo = (ArrayList<Oreda>) sqlMap.queryForList("Oreda.listInfo", _Oreda);
String taxono = "";
String title_item = "";
if (oredaListInfo.size()>0) {
title_item = oredaListInfo.get(0).getTop_item().replace("||", " ");
StringTokenizer strT = new StringTokenizer(oredaListInfo.get(0).getTop_taxonomyno() , "||");
int cnt = strT.countTokens();
while(strT.hasMoreTokens()){
String tempStr = strT.nextToken();
if(!tempStr.equals("") && !tempStr.equals(null)){
//taxono += (String) sqlMap.queryForObject("Oreda.getUid", Integer.parseInt(tempStr));
taxono += tempStr+".";
}
}
String Top_item = oredaListInfo.get(0).getTop_item().replace("||", "<br>");
oredaListInfo.get(0).setTop_item(Top_item);
}
String result = "";
ArrayList<OredaEqipment> oredaListEqipment = new ArrayList<OredaEqipment>();
if (oredaListInfo.size()>0) {
int cate_uid = oredaListInfo.get(0).getTop_category();
if (_Oreda.getStep0().equals("TopSide")) {
result = "listInfoTop";
oredaListEqipment = (ArrayList<OredaEqipment>)sqlMap.queryForList("Oreda.listTOPEqipment", cate_uid);
} else if (_Oreda.getStep0().equals("SubSea")) {
_OredaEqipment.setCategorytableUid(cate_uid);
result = "listInfoSub";
oredaListEqipment = (ArrayList<OredaEqipment>)sqlMap.queryForList("Oreda.listSUBEqipment", _OredaEqipment);
}
} else {
PrintWriter out = response.getWriter();
out.println("<script language='javascript'>");
out.println("if(confirm('검색 결과가 없습니다. 등록하시겟습니까?')){");
out.println("location.href = 'oreda-info.do?method=infoForm&mode=ins&categoryUid="+_Oreda.getCategoryUid()+"';");
out.println("} else {");
out.println("location.href = 'oreda-list.do?method=list';");
out.println("}");
out.println("</script>");
out.close();
result = "fail";
}
request.setAttribute("taxono", taxono);
request.setAttribute("title_item", title_item);
request.setAttribute("oredaListInfo", oredaListInfo);
request.setAttribute("oredaListEqipment", oredaListEqipment);
request.setAttribute("oredaForm", _Oreda);
return mapping.findForward(result);
}
@SuppressWarnings("unchecked")
public ActionForward tableData(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Oreda _Oreda = (Oreda)form;
int cateUid = 0;
String result = "";
ArrayList<Oreda> tableList = (ArrayList<Oreda>) sqlMap.queryForList("Oreda.tableList", _Oreda);
if (tableList.size() == 1) {
cateUid = tableList.get(0).getCategoryUid();
} else if (tableList.size() > 1) {
tableList = new ArrayList<Oreda>();
tableList.add(new Oreda());
tableList.get(0).setCateDepth(0);
tableList.get(0).setCategoryUid(0);
cateUid = 0;
}
if (_Oreda.getMode().equals("ins") || _Oreda.getMode().equals("upd")) {
result = "update";
} else if (_Oreda.getMode().equals("del")) {
result = "delete";
}
ArrayList<Oreda> nodeTableList = (ArrayList<Oreda>) sqlMap.queryForList("Oreda.nodeTableList",cateUid );
request.setAttribute("oredaForm", _Oreda);
request.setAttribute("tableList",tableList );
request.setAttribute("nodeTableList",nodeTableList );
return mapping.findForward(result);
}
@SuppressWarnings("unchecked")
public void tableMultiSQL(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Oreda _Oreda = (Oreda)form;
ActionMessages msg = new ActionMessages();
int message = -1;
String alertMsg = "";
String returnUrl = "opener.parent.location.href = 'oreda-list.do?method=list';window.close();";
if (_Oreda.getMode().equals("ins")) {
sqlMap.insert("Oreda.TableInsert", _Oreda);
alertMsg = "등록 되었습니다.";
} else if (_Oreda.getMode().equals("upd")) {//update
sqlMap.update("Oreda.TableUpdate", _Oreda);
alertMsg = "수정 되었습니다.";
} else if (_Oreda.getMode().equals("del")) {
int cateUid = _Oreda.getCategoryUid();
if(((ArrayList<Oreda>)sqlMap.queryForList("Oreda.nodeTableList",cateUid)).size()<1){
alertMsg = "삭제 되었습니다.";
sqlMap.delete("Oreda.TableDelete", _Oreda);
} else {
alertMsg = "삭제 중 오류가 발생 하였습니다.";
}
returnUrl = "location.href = 'oreda-list.do?method=list';";
}
PrintWriter out = response.getWriter();
out.println("<script language='javascript'>");
out.println("alert('"+alertMsg+"');");
out.println(returnUrl);
out.println("</script>");
out.close();
}
@SuppressWarnings("unchecked")
public ActionForward infoForm(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Oreda _Oreda = (Oreda)form;
ArrayList<Oreda> tableList = (ArrayList<Oreda>) sqlMap.queryForList("Oreda.tableList", _Oreda);
request.setAttribute("oredaForm", _Oreda);
request.setAttribute("tableList",tableList );
return mapping.findForward("ins");
}
@SuppressWarnings("unchecked")
public void infoInsert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Oreda _Oreda = (Oreda)form;
_Oreda.setCateName(_Oreda.getCateName().replace(" ", "||")+"||");
_Oreda.setCateFullCode(_Oreda.getCateFullCode().replace(".", "||")+"||");
sqlMap.insert("Oreda.infoInsert", _Oreda);
PrintWriter out = response.getWriter();
out.println("<script language='javascript'>");
out.println("location.href='/oreda-info.do?method=infoList&categoryUid="+_Oreda.getCategoryUid()+"&step0="+_Oreda.getStep0()+"';");
out.println("</script>");
out.close();
}
@SuppressWarnings("unchecked")
public ActionForward infoUpdate(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Oreda _Oreda = (Oreda)form;
sqlMap.update("Oreda.infoUpdate", _Oreda);
return mapping.findForward("infoUpdate");
}
@SuppressWarnings("unchecked")
public ActionForward eqTopData(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
OredaEqipment _OredaEqipment = (OredaEqipment)form;
//sqlMap.update("Oreda.infoUpdate", _Oreda);
ArrayList<OredaEqDB> oredaEqDBList = null;
if (_OredaEqipment.getMode().equals("upd")) {
oredaEqDBList = (ArrayList<OredaEqDB>) sqlMap.queryForList("Oreda.oredaEqipmentlist",_OredaEqipment);
}
request.setAttribute("oredaEqDBList", oredaEqDBList);
request.setAttribute("_Oreda", _OredaEqipment);
return mapping.findForward("TopeqData");
}
@SuppressWarnings("unchecked")
public void eqTopInsert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
OredaEqDB _OredaEqDB = (OredaEqDB)form;
if (_OredaEqDB.getTopeGubun().equals("this")) {
_OredaEqDB.setTopeGubun(_OredaEqDB.getTopeFailuremode());
sqlMap.insert("Oreda.topEqInsert", _OredaEqDB);
} else {
_OredaEqDB.setTopeParent(_OredaEqDB.getTopsideEqipmentUid());
sqlMap.update("Oreda.topEqoredernoUpdatePlus", _OredaEqDB);
sqlMap.insert("Oreda.topEqNodeInsert", _OredaEqDB);
}
PrintWriter out = response.getWriter();
out.println("<script language='javascript'>");
out.println("opener.parent.location.href='/oreda-info.do?method=infoList&categoryUid="+_OredaEqDB.getCategorytableUid()+"&step0=TopSide';");
out.println("window.close();");
out.println("</script>");
out.close();
}
@SuppressWarnings("unchecked")
public void eqTopUpdate(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
OredaEqDB _OredaEqDB = (OredaEqDB)form;
sqlMap.update("Oreda.topEqUpdate1",_OredaEqDB);
sqlMap.update("Oreda.topEqUpdate2",_OredaEqDB);
PrintWriter out = response.getWriter();
out.println("<script language='javascript'>");
out.println("opener.parent.location.reload();");
out.println("window.close();");
out.println("</script>");
out.close();
}
@SuppressWarnings("unchecked")
public void eqTopDelete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Oreda _Oreda = new Oreda();
OredaEqDB _OredaEqDB = (OredaEqDB)form;
int eqUid = 0;
eqUid = _OredaEqDB.getTopsideEqipmentUid2();
sqlMap.delete("Oreda.topEqDelete", eqUid);
eqUid = _OredaEqDB.getTopsideEqipmentUid1();
sqlMap.delete("Oreda.topEqDelete", eqUid);
sqlMap.delete("Oreda.topEqNodeDelete", eqUid);
sqlMap.update("Oreda.topEqoredernoUpdateMinus", _OredaEqDB);
_Oreda.setCategoryUid(_OredaEqDB.getCategorytableUid());
ArrayList<Oreda> oredaListInfo = (ArrayList<Oreda>) sqlMap.queryForList("Oreda.tableList", _Oreda);
String returnUrl = "location.href = 'oreda-info.do?method=infoList&categoryUid="+_OredaEqDB.getCategorytableUid()+"&step0="+oredaListInfo.get(0).getStep0()+"';";
PrintWriter out = response.getWriter();
out.println("<script language='javascript'>");
out.println(returnUrl);
out.println("</script>");
out.close();
}
@SuppressWarnings("unchecked")
public ActionForward eqSubData(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
OredaEqipment _OredaEqipment = (OredaEqipment)form;
//sqlMap.update("Oreda.infoUpdate", _Oreda);
ArrayList<OredaEqipment> oredaListEqipment = new ArrayList<OredaEqipment> ();
if (_OredaEqipment.getSubseaEqipmentUid() > 0) {
oredaListEqipment = (ArrayList<OredaEqipment>)sqlMap.queryForList("Oreda.listSUBEqipment", _OredaEqipment);
} else {
oredaListEqipment.add(new OredaEqipment());
}
request.setAttribute("oredaEqDBList", oredaListEqipment);
request.setAttribute("_Oreda", _OredaEqipment);
return mapping.findForward("SubeqData");
}
@SuppressWarnings("unchecked")
public void eqSubInsert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
OredaEqipment _OredaEqipment = (OredaEqipment)form;
if(_OredaEqipment.getEqipmentDepth() == 0) {
_OredaEqipment.setEqipmentDepth(1);
} else {
_OredaEqipment.setEqipmentDepth(_OredaEqipment.getEqipmentDepth()+1);
}
String subCode = (String) sqlMap.queryForObject("Oreda.getSubCode", _OredaEqipment);
_OredaEqipment.setSubsCode(subCode);
sqlMap.insert("Oreda.subSeaEQInsert", _OredaEqipment);
PrintWriter out = response.getWriter();
out.println("<script language='javascript'>");
out.println("opener.parent.location.reload();");
out.println("window.close();");
out.println("</script>");
out.close();
}
@SuppressWarnings("unchecked")
public void eqSubUpdate(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
OredaEqipment _OredaEqipment = (OredaEqipment)form;
sqlMap.update("Oreda.subSeaEQUpdate",_OredaEqipment);
PrintWriter out = response.getWriter();
out.println("<script language='javascript'>");
out.println("opener.parent.location.reload();");
out.println("window.close();");
out.println("</script>");
out.close();
}
@SuppressWarnings("unchecked")
public void eqSubDelete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
OredaEqipment _OredaEqipment = (OredaEqipment)form;
String returnUrl = "location.href = 'oreda-info.do?method=infoList&categoryUid="+_OredaEqipment.getCategorytableUid()+"&step0=SubSea';";
sqlMap.delete("Oreda.subSeaEQNodeDelete", _OredaEqipment);
sqlMap.delete("Oreda.subSeaEQDelete", _OredaEqipment);
PrintWriter out = response.getWriter();
out.println("<script language='javascript'>");
out.println(returnUrl);
out.println("</script>");
out.close();
}
}