author | František Kučera <franta-hg@frantovo.cz> |
Sat, 14 Feb 2009 23:03:13 +0100 | |
changeset 27 | f410145eb680 |
parent 26 | feb4c3774c42 |
child 30 | 0ffc8c1b2b9c |
permissions | -rw-r--r-- |
franta-hg@3 | 1 |
package cz.frantovo.hrisniciSpameri; |
franta-hg@3 | 2 |
|
franta-hg@6 | 3 |
import cz.frantovo.hrisniciSpameri.dao.CilDAO; |
franta-hg@21 | 4 |
import cz.frantovo.hrisniciSpameri.dao.SouhrnDAO; |
franta-hg@4 | 5 |
import cz.frantovo.hrisniciSpameri.dto.Cil; |
franta-hg@4 | 6 |
import cz.frantovo.hrisniciSpameri.dto.Souhrn; |
franta-hg@3 | 7 |
import java.io.Serializable; |
franta-hg@4 | 8 |
import java.sql.Date; |
franta-hg@4 | 9 |
import java.text.DateFormat; |
franta-hg@4 | 10 |
import java.text.ParseException; |
franta-hg@4 | 11 |
import java.text.SimpleDateFormat; |
franta-hg@4 | 12 |
import java.util.Collection; |
franta-hg@4 | 13 |
import java.util.logging.Level; |
franta-hg@4 | 14 |
import java.util.logging.Logger; |
franta-hg@3 | 15 |
|
franta-hg@3 | 16 |
/** |
franta-hg@4 | 17 |
* Beana zprostředkovávající denní souhrn hříšníků. |
franta-hg@3 | 18 |
* @author fiki |
franta-hg@3 | 19 |
*/ |
franta-hg@3 | 20 |
public class DenniSouhrn implements Serializable { |
franta-hg@3 | 21 |
|
franta-hg@3 | 22 |
private static final long serialVersionUID = 7932392366943861342L; |
franta-hg@4 | 23 |
private static final Logger log = Logger.getLogger(DenniSouhrn.class.getName()); |
franta-hg@20 | 24 |
private static String formatDataVzor = "yyyy-MM-dd"; |
franta-hg@4 | 25 |
public static DateFormat formatData = new SimpleDateFormat(formatDataVzor); |
franta-hg@26 | 26 |
private Date zacatek; |
franta-hg@26 | 27 |
private Date konec; |
franta-hg@20 | 28 |
private int cil; |
franta-hg@20 | 29 |
|
franta-hg@26 | 30 |
public String getZacatekString() { |
franta-hg@26 | 31 |
return formatData.format(getZacatek()); |
franta-hg@20 | 32 |
} |
franta-hg@4 | 33 |
|
franta-hg@26 | 34 |
public Date getZacatek() { |
franta-hg@26 | 35 |
if (zacatek == null) { |
franta-hg@26 | 36 |
nastavVychoziZacatek(); |
franta-hg@20 | 37 |
} |
franta-hg@26 | 38 |
return zacatek; |
franta-hg@4 | 39 |
} |
franta-hg@4 | 40 |
|
franta-hg@26 | 41 |
public void setZacatek(Date zacatek) { |
franta-hg@26 | 42 |
if (zacatek == null) { |
franta-hg@26 | 43 |
nastavVychoziZacatek(); |
franta-hg@4 | 44 |
} else { |
franta-hg@26 | 45 |
this.zacatek = zacatek; |
franta-hg@4 | 46 |
} |
franta-hg@26 | 47 |
log.log(Level.FINE, "Začátek nastaven na: " + formatData.format(zacatek)); |
franta-hg@4 | 48 |
} |
franta-hg@4 | 49 |
|
franta-hg@26 | 50 |
public void setZacatekString(String zacatek) { |
franta-hg@26 | 51 |
if (zacatek == null) { |
franta-hg@26 | 52 |
nastavVychoziZacatek(); |
franta-hg@4 | 53 |
} |
franta-hg@4 | 54 |
|
franta-hg@4 | 55 |
try { |
franta-hg@26 | 56 |
this.zacatek = new Date(formatData.parse(zacatek).getTime()); |
franta-hg@4 | 57 |
} catch (ParseException e) { |
franta-hg@26 | 58 |
log.log(Level.FINE, "Chybně zadané datum – začátek: " + zacatek, e); |
franta-hg@26 | 59 |
nastavVychoziZacatek(); |
franta-hg@26 | 60 |
} |
franta-hg@26 | 61 |
} |
franta-hg@26 | 62 |
|
franta-hg@26 | 63 |
public Date getKonec() { |
franta-hg@26 | 64 |
return konec; |
franta-hg@26 | 65 |
} |
franta-hg@26 | 66 |
|
franta-hg@26 | 67 |
public void setKonec(Date konec) { |
franta-hg@26 | 68 |
this.konec = konec; |
franta-hg@26 | 69 |
} |
franta-hg@26 | 70 |
|
franta-hg@26 | 71 |
public void setKonecString(String konec) { |
franta-hg@26 | 72 |
try { |
franta-hg@26 | 73 |
this.konec = new Date(formatData.parse(konec).getTime()); |
franta-hg@26 | 74 |
} catch (Exception e) { |
franta-hg@26 | 75 |
/** konec může být null */ |
franta-hg@4 | 76 |
} |
franta-hg@4 | 77 |
} |
franta-hg@4 | 78 |
|
franta-hg@20 | 79 |
public void setCilString(String cil) { |
franta-hg@20 | 80 |
try { |
franta-hg@20 | 81 |
this.cil = Integer.parseInt(cil); |
franta-hg@20 | 82 |
} catch (Exception e) { |
franta-hg@20 | 83 |
this.cil = 0; |
franta-hg@20 | 84 |
} |
franta-hg@20 | 85 |
} |
franta-hg@20 | 86 |
|
franta-hg@20 | 87 |
public void setCil(int cil) { |
franta-hg@20 | 88 |
this.cil = cil; |
franta-hg@20 | 89 |
} |
franta-hg@20 | 90 |
|
franta-hg@20 | 91 |
public String getCilString() { |
franta-hg@20 | 92 |
return String.valueOf(cil); |
franta-hg@20 | 93 |
} |
franta-hg@20 | 94 |
|
franta-hg@20 | 95 |
public int getCil() { |
franta-hg@20 | 96 |
return cil; |
franta-hg@20 | 97 |
} |
franta-hg@20 | 98 |
|
franta-hg@26 | 99 |
private void nastavVychoziZacatek() { |
franta-hg@26 | 100 |
log.log(Level.FINE, "Nastavuji začátek na výchozí hodnotu."); |
franta-hg@26 | 101 |
setZacatek(SouhrnDAO.getVychoziDen()); |
franta-hg@4 | 102 |
} |
franta-hg@4 | 103 |
|
franta-hg@4 | 104 |
public Collection<Souhrn> getSouhrn() { |
franta-hg@26 | 105 |
Collection<Souhrn> souhrn = new SouhrnDAO().getSouhrn(zacatek, konec, cil); |
franta-hg@4 | 106 |
|
franta-hg@21 | 107 |
/** ne všechno musíme posílat do JSP vrstvy */ |
franta-hg@21 | 108 |
for (Souhrn s : souhrn) { |
franta-hg@21 | 109 |
s.getCil().setDatabaze(null); |
franta-hg@21 | 110 |
s.getCil().setSelekt(null); |
franta-hg@4 | 111 |
} |
franta-hg@4 | 112 |
|
franta-hg@4 | 113 |
return souhrn; |
franta-hg@4 | 114 |
} |
franta-hg@6 | 115 |
|
franta-hg@6 | 116 |
/** |
franta-hg@6 | 117 |
* @return Seznam všech cílů. Ale bez těchto hodnot: databáze a selekt. |
franta-hg@6 | 118 |
*/ |
franta-hg@6 | 119 |
public Collection<Cil> getSeznamCilu() { |
franta-hg@6 | 120 |
Collection<Cil> cile = new CilDAO().getCile(); |
franta-hg@6 | 121 |
|
franta-hg@6 | 122 |
/** ne všechno musíme posílat do JSP vrstvy */ |
franta-hg@6 | 123 |
for (Cil c : cile) { |
franta-hg@6 | 124 |
c.setDatabaze(null); |
franta-hg@6 | 125 |
c.setSelekt(null); |
franta-hg@6 | 126 |
} |
franta-hg@6 | 127 |
|
franta-hg@6 | 128 |
return cile; |
franta-hg@6 | 129 |
} |
franta-hg@3 | 130 |
} |