package src.java.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.ModelAndView;
import src.java.Sistema.Investimentos;

import javax.servlet.http.HttpServlet;

/**
 * Created by adrianewey on 15/05/17.
 */
@Controller
public class SystemControl{

    @RequestMapping("index")
    public String indexReturn(){
        return "formulario/TD";
    }


    @RequestMapping("calcular")
    public String identificarClasse(ParamHelper paramHelper,Model model){
        System.out.println(paramHelper.getClasse());

        String nomeDaClasse = "src.java.Sistema." + paramHelper.getClasse();

        try {

            Class created = Class.forName(nomeDaClasse);
            Investimentos investimentos = (Investimentos) created.newInstance();

            ActionHelper actionHelper = new ActionHelper();
            actionHelper.convertInvestimento(investimentos,paramHelper);

         /*   ModelAndView mav = new ModelAndView("formulario/resultado");
            mav.addObject("retornoInvestimento",actionHelper.caculated(investimentos));*/


            System.out.println("\n\n"+actionHelper.caculated(investimentos));
            model.addAttribute("retornoInvestimento",actionHelper.caculated(investimentos));
            return "formulario/resultado";

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }

        return null;
    }





}

@@ -264,16 +264,51 @@
 imentos;
+%0Aimport src.java.Sistema.Resultado;
 %0A%0Aimport
@@ -339,16 +339,44 @@
 Servlet;
+%0Aimport java.util.ArrayList;
 %0A%0A/**%0A *
@@ -454,16 +454,56 @@
 Control%7B
+%0A    private static Resultado resultado;
 %0A%0A    @R
@@ -578,21 +578,12 @@
 rn %22
-formulario/TD
+main
 %22;%0A 
@@ -698,61 +698,8 @@
 el)%7B
-%0A        System.out.println(paramHelper.getClasse());
 %0A%0A  
@@ -1074,75 +1074,146 @@
     
- /*   ModelAndView mav = new ModelAndView(%22formulario/resultado%22
+%0A            resultado = actionHelper.caculated(investimentos);%0A%0A            model.addAttribute(%22resultado%22,resultado.getSaldoMensal()
 );%0A
+%0A
     
@@ -1224,575 +1224,1647 @@
     
-mav.addObject(%22retornoInvestimento%22,actionHelper.caculated(investimentos));*/%0A%0A%0A            System.out.println(%22%5Cn%5Cn%22+actionHelper.caculated(investimentos));%0A            model.addAttribute(%22retornoInvestimento%22,actionHelper.caculated(investimentos));%0A            return %22formulario/resultado%22;%0A%0A        %7D catch (ClassNotFoundException e) %7B%0A            e.printStackTrace();%0A        %7D catch (IllegalAccessException e) %7B%0A            e.printStackTrace();%0A        %7D catch (InstantiationException e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A        return null
+return %22forms/resultado%22;%0A%0A        %7D catch (ClassNotFoundException e) %7B%0A            e.printStackTrace();%0A        %7D catch (IllegalAccessException e) %7B%0A            e.printStackTrace();%0A        %7D catch (InstantiationException e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A        return null;%0A    %7D%0A%0A   @RequestMapping(%22doChart%22)%0A    public String doChart(Model model)%7B%0A        model.addAttribute(%22saldoMensal%22,resultado.getSaldoMensal());%0A        model.addAttribute(%22adicionado%22,resultado.getAdicionado());%0A        model.addAttribute(%22mensal%22,resultado.getMensal());%0A        model.addAttribute(%22saldoAtual%22,resultado.getSaldoAtual());%0A        model.addAttribute(%22diferenca%22,resultado.getDiferencaMensal());%0A        return %22chart%22;%0A    %7D%0A%0A    @RequestMapping(%22doTable%22)%0A    public String doTable(Model model)%7B%0A        model.addAttribute(%22saldoMensal%22,resultado.getSaldoMensal());%0A        model.addAttribute(%22adicionado%22,resultado.getAdicionado());%0A        model.addAttribute(%22mensal%22,resultado.getMensal());%0A        model.addAttribute(%22saldoAtual%22,resultado.getSaldoAtual());%0A        model.addAttribute(%22diferenca%22,resultado.getDiferencaMensal());%0A        return %22table%22;%0A    %7D%0A%0A    @RequestMapping(%22doTableDetail%22)%0A    public String doTableDetail(Model model)%7B%0A        model.addAttribute(%22saldoMensal%22,resultado.getSaldoMensal());%0A        model.addAttribute(%22adicionado%22,resultado.getAdicionado());%0A        model.addAttribute(%22mensal%22,resultado.getMensal());%0A        model.addAttribute(%22saldoAtual%22,resultado.getSaldoAtual());%0A        model.addAttribute(%22diferenca%22,resultado.getDiferencaMensal());%0A        return %22tableDetalhada%22
 ;%0A    %7D%0A
 %0A%0A%0A%0A
@@ -2859,15 +2859,10 @@
 ;%0A    %7D%0A
-%0A%0A%0A%0A%0A
 %7D%0A

Update ControllerClasses