| 1 22 package com.geinuke.bizlogic; 23 24 import java.sql.SQLException ; 25 import java.util.ArrayList ; 26 27 import com.geinuke.dao.*; 28 import com.geinuke.middle.ISurveyBL; 29 import com.geinuke.vo.SurveyAnswerVO; 30 import com.geinuke.vo.SurveyVO; 31 import com.geinuke.vo.SurveyVoteVO; 32 33 34 public class SurveyBL implements ISurveyBL{ 35 36 public void delSurveyAnswerByAID(int aid) throws BLException { 37 try{ 38 SurveyDAO dao=new SurveyDAO(); 39 dao.delSurveyAnswerByAID(aid); 40 41 }catch(SQLException sqle){ 42 throw new DBException(sqle.getMessage()); 43 }catch(Throwable t){ 44 throw new BLException(t.getMessage()); 45 } 46 47 } 48 49 50 public void delSurveyAnswersByESID(int esid) throws BLException { 51 try{ 52 SurveyDAO dao=new SurveyDAO(); 53 dao.delSurveyAnswersByESID(esid); 54 55 }catch(SQLException sqle){ 56 throw new DBException(sqle.getMessage()); 57 }catch(Throwable t){ 58 throw new BLException(t.getMessage()); 59 } 60 61 } 62 63 64 public void delSurveyBySID(int sid) throws BLException { 65 try{ 66 SurveyDAO dao=new SurveyDAO(); 67 dao.delSurveyBySID(sid); 68 dao.delSurveyAnswersByESID(sid); 69 }catch(SQLException sqle){ 70 throw new DBException(sqle.getMessage()); 71 }catch(Throwable t){ 72 throw new BLException(t.getMessage()); 73 } 74 75 } 76 77 78 public SurveyVO getSurveyBySID(int sid) throws BLException { 79 SurveyVO s=null; 80 81 try{ 82 SurveyDAO dao=new SurveyDAO(); 83 s=dao.getSurveyBySID(sid); 84 s.setAnswers(dao.getSurveyAnswersByESID(s.getSid())); 85 86 }catch(SQLException sqle){ 87 throw new DBException(sqle.getMessage()); 88 }catch(Throwable t){ 89 throw new BLException(t.getMessage()); 90 } 91 return s; 92 } 93 94 95 public ArrayList getSurveys() throws BLException { 96 ArrayList ll=null; 97 try{ 98 SurveyDAO dao=new SurveyDAO(); 99 ll=dao.getSurveys(); 100 this.fillSurveys(ll); 101 }catch(SQLException sqle){ 102 throw new DBException(sqle.getMessage()); 103 }catch(Throwable t){ 104 throw new BLException(t.getMessage()); 105 } 106 return ll; 107 } 108 109 protected void fillSurvey(SurveyVO su)throws BLException{ 110 su.setAnswers(this.getSurveyAnswersByESID(su.getSid())); 111 } 112 113 protected void fillSurveys(ArrayList list)throws BLException{ 114 SurveyVO su=null; 115 for(int i=0;i<list.size();i++){ 116 su=(SurveyVO)list.get(i); 117 this.fillSurvey(su); 118 } 119 } 120 121 public ArrayList getSurveysByStatus(int status ) throws BLException { 122 ArrayList ll=null; 123 try{ 124 SurveyDAO dao=new SurveyDAO(); 125 ll=dao.getSurveysByStatus(status); 126 if(status==SurveyVO.STATUS_CURRENT){ 127 if(ll==null || ll.size()==0) 128 ll=dao.getSurveysByStatus(SurveyVO.STATUS_ENABLED); 129 } 130 131 }catch(SQLException sqle){ 132 throw new DBException(sqle.getMessage()); 133 }catch(Throwable t){ 134 throw new BLException(t.getMessage()); 135 } 136 return ll; 137 } 138 139 public ArrayList getSurveyAnswersByESID(int sid) throws BLException { 140 ArrayList ll=null; 141 try{ 142 SurveyDAO dao=new SurveyDAO(); 143 ll=dao.getSurveyAnswersByESID(sid); 144 145 }catch(SQLException sqle){ 146 throw new DBException(sqle.getMessage()); 147 }catch(Throwable t){ 148 throw new BLException(t.getMessage()); 149 } 150 return ll; 151 } 152 153 154 public void insertSurvey(SurveyVO s) throws BLException { 155 try{ 156 SurveyDAO dao=new SurveyDAO(); 157 dao.insertSurvey(s); 158 ArrayList list=s.getAnswers(); 159 SurveyAnswerVO sa=null; 160 for(int i=0;i<list.size();i++){ 161 sa=(SurveyAnswerVO)list.get(i); 162 sa.setEsid(s.getSid()); 163 this.insertSurveyAnswer(sa); 164 } 165 }catch(SQLException sqle){ 166 throw new DBException(sqle.getMessage()); 167 }catch(Throwable t){ 168 throw new BLException(t.getMessage()); 169 } 170 171 } 172 173 174 public void insertSurveyAnswer(SurveyAnswerVO sa) throws BLException { 175 try{ 176 SurveyDAO dao=new SurveyDAO(); 177 dao.insertSurveyAnswer(sa); 178 179 }catch(SQLException sqle){ 180 throw new DBException(sqle.getMessage()); 181 }catch(Throwable t){ 182 throw new BLException(t.getMessage()); 183 } 184 185 } 186 187 188 public void updateSurveyAnswerVO(SurveyAnswerVO sa) throws BLException { 189 try{ 190 SurveyDAO dao=new SurveyDAO(); 191 dao.updateSurveyAnswerVO(sa); 192 }catch(SQLException sqle){ 193 throw new DBException(sqle.getMessage()); 194 }catch(Throwable t){ 195 throw new BLException(t.getMessage()); 196 } 197 198 } 199 200 public void updateSurveyVO(SurveyVO su) throws BLException { 201 try{ 202 SurveyDAO dao=new SurveyDAO(); 203 dao.updateSurveyVO(su); 204 }catch(SQLException sqle){ 205 throw new DBException(sqle.getMessage()); 206 }catch(Throwable t){ 207 throw new BLException(t.getMessage()); 208 } 209 210 } 211 212 public void updateSurveyVOStatus(int sid) throws BLException { 213 try{ 214 SurveyDAO dao=new SurveyDAO(); 215 SurveyVO su=dao.getSurveyBySID(sid); 216 int cStatus=su.getSStatus(); 217 if(cStatus==0){ 218 su.setSStatus(cStatus+1); 219 }else if(cStatus==1){ 220 su.setSStatus(cStatus+1); 221 }else if(cStatus==2){ 222 su.setSStatus(0); 223 } 224 dao.updateSurveyVO(su); 225 }catch(SQLException sqle){ 226 throw new DBException(sqle.getMessage()); 227 }catch(Throwable t){ 228 throw new BLException(t.getMessage()); 229 } 230 231 } 232 233 234 public boolean checkVote(int sid, int uid) throws BLException { 235 try{ 236 SurveyDAO dao=new SurveyDAO(); 237 238 return dao.checkVote(sid,uid); 239 }catch(SQLException sqle){ 240 throw new DBException(sqle.getMessage()); 241 }catch(Throwable t){ 242 throw new BLException(t.getMessage()); 243 } 244 } 245 246 247 248 public boolean checkVote(int sid, String ip) throws BLException { 249 try{ 250 SurveyDAO dao=new SurveyDAO(); 251 252 return dao.checkVote(sid,ip); 253 }catch(SQLException sqle){ 254 throw new DBException(sqle.getMessage()); 255 }catch(Throwable t){ 256 throw new BLException(t.getMessage()); 257 } 258 } 259 260 public void insertVote(SurveyVoteVO vo) throws BLException{ 261 try{ 262 SurveyDAO dao=new SurveyDAO(); 263 dao.insertVote(vo); 264 }catch(SQLException sqle){ 265 throw new DBException(sqle.getMessage()); 266 }catch(Throwable t){ 267 throw new BLException(t.getMessage()); 268 } 269 } 270 271 } 272 | Popular Tags |