package com.vst.webapp.action;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import com.vst.model.Armature;
import com.vst.model.Diameter;
import com.vst.model.Flange;
import com.vst.model.Oborudovanie;
import com.vst.model.Pipe;
import com.vst.model.Tap;
import com.vst.model.Tee;
import com.vst.model.Transition;
import com.vst.model.Zaglushka;
import com.vst.model.internal.DiameterHelper;
import com.vst.service.DetailManager;
import com.vst.service.DiameterManager;
/**
* Created by IntelliJ IDEA.
* User: And Lilia
* Date: 13.05.2009
* Time: 18:20:43
* To change this template use File | Settings | File Templates.
*/
public class LookDiameterController implements Controller {
DiameterManager diameterManager;
DetailManager detailManager;
public void setDetailManager(DetailManager detailManager) {
this.detailManager = detailManager;
}
public void setDiameterManager(DiameterManager diameterManager) {
this.diameterManager = diameterManager;
}
public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
ModelAndView mav = new ModelAndView("lookDiameter");
String result = "";
if (httpServletRequest.getParameter("delete") != null) {
Integer id = (Integer) Integer.parseInt(httpServletRequest.getParameter("delete"));
Diameter diameter = diameterManager.getDiameterById(id);
List pipeList = detailManager.getPipeListByDiameterId(id);
List tapList = detailManager.getTapListByDiameterId(id);
List teeList = detailManager.getTeeListByDiameterId(id);
List transitionList = detailManager.getTransitionListByDiameterId(id);
List armatureList = detailManager.getArmatureListByDiameterId(id);
List oborList = detailManager.getOborudovaniListByDiameterId(id);
List zaglushkaList = detailManager.getZaglushkaListByDiameterId(id);
List flangeList = detailManager.getFlangeListByDiameterId(id);
int count = pipeList.size() + tapList.size() + teeList.size() + transitionList.size() + armatureList.size() + oborList.size() + zaglushkaList.size() + flangeList.size();
if (count > 0) {
result += "Диаметр не может быть удален, так как он используется " + count + " раз(а) в других справочниках:<br>";
result += "<table><tr><td>Спаравочник</td><td>Деталь</td></tr>";
for (int i = 0; i < pipeList.size(); i++) {
Pipe o = (Pipe) pipeList.get(i);
result += "<tr><td>" + o.getDetailTypes().getTypeName() + "</td><td><a href=\"" + httpServletRequest.getRequestURL().toString().replaceAll("/lookDiameter.html", "") + "/lookDetail.html?type=pipe\"><ul>" +
"<li>" + o.getGost().getGostName() +
"<li>Диаметр: " + o.getDiametr() +
"<li>Толщина: " + o.getThickness() +
"<li>Материал: " + o.getMaterial() + "</ul></a></td></tr>";
}
for (int i = 0; i < tapList.size(); i++) {
Tap o = (Tap) tapList.get(i);
result += "<tr><td>" + o.getDetailTypes().getTypeName() + "</td><td><a href=\"" + httpServletRequest.getRequestURL().toString().replaceAll("/lookDiameter.html", "") + "/lookDetail.html?type=tap\"><ul>" +
"<li>" + o.getGost().getGostName() +
"<li>Диаметр: " + o.getDiametr() +
"<li>Толщина: " + o.getThickness() +
"<li>Материал: " + o.getMaterial() +
"<li>Угол: " + o.getCorner() + "</ul></a></td></tr>";
}
for (int i = 0; i < transitionList.size(); i++) {
Transition o = (Transition) transitionList.get(i);
result += "<tr><td>" + o.getDetailTypes().getTypeName() + "</td><td><a href=\"" + httpServletRequest.getRequestURL().toString().replaceAll("/lookDiameter.html", "") + "/lookDetail.html?type=transition\"><ul>" +
"<li>" + o.getGost().getGostName() +
"<li>Первый диаметр: " + o.getFirstDiametr() +
"<li>Первая толщина: " + o.getFirstThickness() +
"<li>Второй длиаметр: " + o.getSecondDiametr() +
"<li>Вторая толщина: " + o.getSecondThickness() +
"<li>Материал: " + o.getMaterial() + "</ul></a></td></tr>";
}
for (int i = 0; i < teeList.size(); i++) {
Tee o = (Tee) teeList.get(i);
result += "<tr><td>" + o.getDetailTypes().getTypeName() + "</td><td><a href=\"" + httpServletRequest.getRequestURL().toString().replaceAll("/lookDiameter.html", "") + "/lookDetail.html?type=tee\"><ul>" +
"<li>" + o.getGost().getGostName() +
"<li>Первый диаметр: " + o.getFirstDiametr() +
"<li>Первая толщина: " + o.getFirstThickness() +
"<li>Второй длиаметр: " + o.getSecondDiametr() +
"<li>Вторая толщина: " + o.getSecondThickness() +
"<li>Материал: " + o.getMaterial() + "</ul></a></td></tr>";
}
for (int i = 0; i < zaglushkaList.size(); i++) {
Zaglushka o = (Zaglushka) zaglushkaList.get(i);
result += "<tr><td>" + o.getDetailTypes().getTypeName() + "</td><td><a href=\"" + httpServletRequest.getRequestURL().toString().replaceAll("/lookDiameter.html", "") + "/lookDetail.html?type=zaglushka\"><ul>" +
"<li>" + o.getGost().getGostName() +
"<li>Диаметр: " + o.getDiametr() +
"<li>Толщина: " + o.getThickness() +
"<li>Материал: " + o.getMaterial() + "</ul></a></td></tr>";
}
for (int i = 0; i < flangeList.size(); i++) {
Flange o = (Flange) flangeList.get(i);
result += "<tr><td>" + o.getDetailTypes().getTypeName() + "</td><td><a href=\"" + httpServletRequest.getRequestURL().toString().replaceAll("/lookDiameter.html", "") + "/lookDetail.html?type=flange\"><ul>" +
"<li>" + o.getGost().getGostName() +
"<li>Диаметр: " + o.getDiametr() +
"<li>Толщина: " + o.getThickness() +
"<li>Материал: " + o.getMaterial() +
"<li>Давление: " + o.getPressure() + "</ul></td></tr>";
}
for (int i = 0; i < armatureList.size(); i++) {
Armature o = (Armature) armatureList.get(i);
result += "<tr><td>" + o.getDetailTypes().getTypeName() + "</td><td><a href=\"" + httpServletRequest.getRequestURL().toString().replaceAll("/lookDiameter.html", "") + "/lookDetail.html?type=armature\"><ul>" +
"<li>" + o.getGost().getGostName() +
"<li>Название: " + o.getName() +
"<li>Диаметр: " + o.getDiametr() +
"<li>Материал: " + o.getMaterial() +
"<li>Маркировка: " + o.getMarks() +
"<li>Давление: " + o.getPressure() + "</ul</a></td></tr>";
}
for (int i = 0; i < oborList.size(); i++) {
Oborudovanie o = (Oborudovanie) oborList.get(i);
result += "<tr><td>" + o.getDetailTypes().getTypeName() + "</td><td><a href=\"" + httpServletRequest.getRequestURL().toString().replaceAll("/lookDiameter.html", "") + "/lookDetail.html?type=oborudovanie\"><ul>" +
"<li>" + o.getGost().getGostName() +
"<li>Диаметр: " + o.getDiametr() +
"<li>Название: " + o.getName() +
"<li>Стоимость: " + o.getExpenses() +
"<li>Давление: " + o.getPressure() + "</ul></a></td></tr>";
}
result += "</table>";
} else {
diameterManager.delete(diameter);
}
}
Integer page = new Integer(0);
Integer pageCount;
if (httpServletRequest.getParameter("page") != null) {
page = (Integer) Integer.parseInt(httpServletRequest.getParameter("page"));
}
List dList = diameterManager.getListDiameter(page);
List diameterList = new ArrayList();
for (int i = 0; i < dList.size(); i++) {
DiameterHelper diameterHelper = new DiameterHelper();
Diameter diameter = (Diameter) dList.get(i);
diameterHelper.setDiametrCount(diameter.getDiametrCount());
diameterHelper.setDiametrId(diameter.getDiametrId());
diameterHelper.setGost(diameter.getGost());
diameterHelper.setThicknessList(diameter.getThicknessList());
diameterHelper.setThCount(Integer.valueOf(diameter.getThicknessList().size()));
diameterList.add(diameterHelper);
}
mav.addObject("result", result);
mav.addObject("diameter", diameterList);
pageCount = (Integer) diameterManager.getListDiameter().size();
if ((pageCount.intValue() % 15) > 0) {
pageCount = (Integer) (1 + (pageCount.intValue() / 15));
} else {
pageCount = (Integer) (pageCount.intValue() / 15);
}
if (pageCount.intValue() == 0) {
pageCount = new Integer(1);
}
mav.addObject("page", page);
mav.addObject("pageCount", pageCount);
return mav;
}
}