📄 lastcontactdao.java
字号:
/* CRMS, customer relationship management system Copyright (C) 2003 Service To Youth Council This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information contact the SYC ICT department on GPL@syc.net.au 98 Kermode Street North Adelaide South Australia SA 5006 +61 (0)8 8367 0755 *//* * LastContactDAO.java * * Created on 5 May 2003, 10:10 */package crms.dao;import java.sql.*;import java.io.*;import crms.vo.LastContact;import crms.util.*;import java.util.*;import java.text.*;import org.apache.log4j.Logger;/** * * @author dmurphy */public class LastContactDAO extends crms.dao.AbstractDAO { static Logger logger = Logger.getLogger(LastContactDAO.class); public static SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); /** Creates a new instance of LastContactDAO */ public LastContactDAO() { } public List getLastContact(ContactType type, int contactID, String user) { ArrayList lastContacts = null; String sql = ""; sql += "SELECT * from \"LastContact\"\n"; sql += "WHERE \"ContactType\"=" + quoteSingle(type.getCode()) + "\n"; sql += " AND \"ContactID\"=" + contactID + "\n"; sql += " AND (\"Owner\" = '" + user + "' OR \"Level\" < 1)\n"; sql += "ORDER BY \"Date\" DESC\n"; lastContacts = (ArrayList) executeQuery(sql); return lastContacts; } public boolean lastContactExists(int contactID, ContactType type) { String sql = ""; sql += "SELECT * from \"LastContact\"\n"; sql += " WHERE \"ContactID\" = " + contactID + "\n"; sql += " AND \"ContactType\" + " + quoteSingle(type.getCode()) + "\n"; LastContact exists = (LastContact) ((ArrayList) executeQuery(sql)).get(0); return (exists != null); } public void updateLastContact(LastContact lc) { String sql = ""; sql = "UPDATE \"LastContact\"\n"; sql += " SET \"Date\" = " + quoteSingle(df.format(lc.getLastContactDate())) + ",\n"; sql += " \"Details\" = " + quoteSingle(encode(lc.getDetails())) + "\n"; sql += " \"ContactType\" = " + quoteSingle(lc.getContactType().getCode()) + "\n"; sql += " \"ContactID\" = " + lc.getContactID() + "\n"; sql += "WHERE \"LastContactRef\" + " + quoteSingle(lc.getContactType().getCode()) + "\n"; try { int rows = updateSQL(sql); if (rows != 1) { logger.error("Incorrect number of rows inserted executing:"); logger.error(sql); throw new Exception("Incorrect number of rows inserted!"); } } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } } /** * */ public LastContact addLastContact(LastContact lc, String user) { String sql = ""; // First see if any last-contact info exists... sql = "INSERT INTO \"LastContact\"\n"; sql += "(\"Date\", \"Details\", \"ContactID\", \"ContactType\", \"Level\", \"Owner\")"; sql += "VALUES\n"; sql += "(" + quoteSingle(df.format(lc.getLastContactDate())) + ", "; sql += quoteSingle(encode(lc.getDetails())) + ", "; sql += lc.getContactID() + ", "; sql += quoteSingle(lc.getContactType().getCode()) + ", "; sql += lc.getLevel() + ", "; sql += quoteSingle(lc.getOwner()); sql += ")\n"; try { int rows = updateSQL(sql); if (rows != 1) { logger.error("Incorrect number of rows inserted executing:"); logger.error(sql); throw new Exception("Incorrect number of rows inserted!"); } } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } LastContact saved = (LastContact) ((ArrayList)getLastContact(lc.getContactType(), lc.getContactID(), user)).get(0); return saved; } public Object createFromResultSet(ResultSet rs) throws SQLException, UnsupportedEncodingException { LastContact lc = new LastContact(); Timestamp ts = rs.getTimestamp("Date"); lc.setLastContactDate(new java.util.Date(ts.getTime())); lc.setContactID(rs.getInt("ContactID")); lc.setDetails(decode(rs.getString("Details"))); lc.setLastContactRef(rs.getInt("LastContactRef")); lc.setLevel(rs.getInt("Level")); lc.setOwner(rs.getString("Owner")); //lc.setContactType((ContactType)ContactType.decode(rs.getString("ContactType"), ContactType.class)); return lc; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -