1
2
3
4 package ecar.dao;
5
6 import java.util.ArrayList;
7 import java.util.Iterator;
8 import java.util.List;
9
10 import javax.servlet.http.HttpServletRequest;
11
12 import org.apache.log4j.Logger;
13 import org.hibernate.HibernateException;
14 import org.hibernate.Query;
15
16 import comum.database.Dao;
17 import comum.util.Pagina;
18
19 import ecar.exception.ECARException;
20 import ecar.pojo.ConfigExecFinanCef;
21 import ecar.pojo.ConfigSisExecFinanCsef;
22 import ecar.pojo.ConfigSisExecFinanCsefv;
23
24
25
26
27 public class ConfigExecFinanDao extends Dao {
28
29
30
31
32 public ConfigExecFinanDao(HttpServletRequest request) {
33 super();
34 this.request = request;
35 }
36
37
38
39
40
41
42
43 public void excluir(ConfigSisExecFinanCsef csef) throws ECARException {
44 try {
45 boolean excluir = true;
46 if (contar(csef.getConfigSisExecFinanCsefvs()) > 0) {
47 excluir = false;
48 throw new ECARException("csef.exclusao.erro.configSisExecFinanCsefv");
49 }
50 if (excluir)
51 super.excluir(csef);
52 } catch (ECARException e) {
53 this.logger.error(e);
54 throw e;
55 }
56 }
57
58
59
60
61
62
63
64 public List getConfigExecFinanByVersao(ConfigSisExecFinanCsefv versao) throws ECARException {
65 List retorno = new ArrayList();
66 try {
67 StringBuilder sql = new StringBuilder("select config from ConfigExecFinanCef config").append(" join config.configSisExecFinanCsefv versao").append(" where versao.mesVersaoCsefv = :mesVersao").append(" and versao.anoVersaoCsefv = :anoVersao").append(" order by config.seqApresentacaoCef asc");
68
69 Query q = this.session.createQuery(sql.toString());
70
71 q.setLong("mesVersao", versao.getMesVersaoCsefv().longValue());
72 q.setLong("anoVersao", versao.getAnoVersaoCsefv().longValue());
73
74 retorno = q.list();
75
76 if (retorno == null)
77 retorno = new ArrayList();
78 } catch (HibernateException e) {
79 Logger logger = Logger.getLogger(this.getClass());
80 logger.error(e);
81 }
82
83 return retorno;
84 }
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99 public String geraHTMLLayoutConta(String conta, ConfigSisExecFinanCsefv versao, boolean disabled, HttpServletRequest request) throws ECARException {
100 StringBuilder retorno = new StringBuilder();
101 String strConta = conta;
102 List estruturasContabil = this.getConfigExecFinanByVersao(versao);
103 retorno.append("");
104 if (estruturasContabil != null) {
105 Iterator it = estruturasContabil.iterator();
106 String camposConta[] = new String[estruturasContabil.size()];
107 if (strConta != null)
108 camposConta = strConta.split(" ");
109
110 String hidEstruturasContabeis = "";
111
112 int i = 0;
113 while (it.hasNext()) {
114 String strValor = "";
115 ConfigExecFinanCef estruturaContabil = (ConfigExecFinanCef) it.next();
116
117
118
119
120 try {
121 if (camposConta[i] != null)
122 strValor = camposConta[i];
123 } catch (ArrayIndexOutOfBoundsException ex) {
124 strValor = "";
125
126 }
127 if (!"".equals(Pagina.getParamStr(request, "e" + estruturaContabil.getCodCef())))
128 strValor = Pagina.getParamStr(request, "e" + estruturaContabil.getCodCef());
129 retorno.append("<div class=\"tabelaaolado\">").append(estruturaContabil.getLabelCef()).append(" </br>").append("<input type=\"text\" size=\"").append(estruturaContabil.getNumCaracteresCef()).append("\" maxlength=\"").append(estruturaContabil.getNumCaracteresCef()).append("\" name=\"e").append(estruturaContabil.getCodCef()).append(String.valueOf(versao.getCodCsefv())).append("\" value=\"").append(strValor).append("\"");
130 hidEstruturasContabeis += estruturaContabil.getCodCef().toString() + "|";
131 if (disabled)
132 retorno.append(" disabled ");
133 retorno.append("></div>");
134 i++;
135 }
136 if (!"".equals(retorno.toString().trim()))
137 retorno.append("<input type=\"hidden\" name=\"layout" + String.valueOf(versao.getCodCsefv()) + "\" value=\"" + hidEstruturasContabeis + "\">");
138 }
139 return retorno.toString();
140 }
141 }