protected boolean actionUpdate(GenericWebFormData wfd) { UserData form = (UserData) wfd; Connection conn = null; PreparedStatement ps = null; String sql = "UPDATE USER SET USERNAME = ?, " + " TRANSACTION = ?, " + " ITEM = ?, " + " BANKCODE = ?, " + " COUNTRY = ?, " + " HOLIDAY = ?, " + " MESSAGE = ?, " + " REPORT = ?, " + " USER = ?, " + " PASSWORD = ?, " + " BACKUP = ? " + " WHERE USERID = ?"; try { conn = JdbcConnection.getConnection(); ps = conn.prepareStatement(sql); ps.setString(1, form.getData(UserData.userName)); ps.setString(2, form.getData(UserData.transaction)); ps.setString(3, form.getData(UserData.item)); ps.setString(4, form.getData(UserData.bankCode)); ps.setString(5, form.getData(UserData.country)); ps.setString(6, form.getData(UserData.holiday)); ps.setString(7, form.getData(UserData.message)); ps.setString(8, form.getData(UserData.report)); ps.setString(9, form.getData(UserData.user)); ps.setString(10, form.getData(UserData.password)); ps.setString(11, form.getData(UserData.backup)); ps.setString(12, form.getData(UserData.userId)); ps.executeUpdate(); } catch (Exception e) { e.printStackTrace(); System.out.print(new java.util.Date()); System.out.println("Cannot update User:" + form.getData(form.userName)); return false; } finally { if (ps != null) try { ps.close(); } catch (Exception e) { e.printStackTrace(); } if (conn != null) try { conn.close(); } catch (Exception e) { e.printStackTrace(); } } return true; }
public Vector actionSearch(GenericSearchFormData o) { HolidaySearchFormData iSearchData = (HolidaySearchFormData) o; Vector v = new Vector(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; String sql = "SELECT DATE_FORMAT(DATE, '%d/%m/%Y') AS DATE, DESCRIPTION FROM HOLIDAY WHERE STATUS = 'READY' "; if (!CircUtilities.isEmptyString(iSearchData.getData(HolidaySearchFormData.holidayDescription))) sql += "AND LCASE(DESCRIPTION) like LCASE('%" + iSearchData.getData(HolidaySearchFormData.holidayDescription) + "%') "; if (!CircUtilities.isEmptyString(iSearchData.getData(HolidaySearchFormData.holidayDate))) sql += "AND DATE = ? "; sql += "ORDER BY DATE_FORMAT(DATE, '%Y%m%d') "; try { System.out.println("HOLIDAY SEARCH=" + sql); conn = JdbcConnection.getConnection(); ps = conn.prepareStatement(sql); if (!CircUtilities.isEmptyString(iSearchData.getData(HolidaySearchFormData.holidayDate))) ps.setTimestamp(1, iSearchData.getTimestampByField(HolidaySearchFormData.holidayDate)); rs = ps.executeQuery(); while (rs.next()) { HolidayData iData = new HolidayData(rs); v.add((HolidayData) iData); } } catch (Exception e) { // ignore search error, just return empty vector } finally { if (rs != null) try { rs.close(); } catch (Exception e) { e.printStackTrace(); } if (ps != null) try { ps.close(); } catch (Exception e) { e.printStackTrace(); } if (conn != null) try { conn.close(); } catch (Exception e) { e.printStackTrace(); } } return v; }
protected GenericWebFormData actionLoadEditData(Object keyObjectForLoad) { String userId = (String) keyObjectForLoad; UserData iData = null; Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; String sql = "SELECT USERID, USERNAME, TRANSACTION, ITEM, BANKCODE, COUNTRY, HOLIDAY, MESSAGE, " + "REPORT, PASSWORD, BACKUP, USER FROM USER WHERE STATUS = 'READY' AND USERID = ?"; try { conn = JdbcConnection.getConnection(); ps = conn.prepareStatement(sql); ps.setString(1, userId); rs = ps.executeQuery(); if (rs.next()) { iData = new UserData(rs); } } catch (Exception e) { e.printStackTrace(); } return iData; }
public ByteArrayOutputStream getReportCode() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Document document = new Document(PageSize.B4, 40, 200, 120, 20); try { PdfWriter writer = PdfWriter.getInstance(document, baos); MyPageEvents events = new MyPageEvents(); writer.setPageEvent(events); document.open(); if (data.size() == 0) { PdfPTable table = new PdfPTable(1); table.addCell(printStr("", 6, 8, false, PdfPCell.NO_BORDER, 0)); document.add(table); } PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100); int border = 0; // Receipt Infos String row[] = (String[]) data.get(0); table.addCell(printStr("", 1, 18, false, border, 1)); table.addCell(printStr(row[17], 1, 22, false, border, 1)); table.addCell(printStr(" ", 1, 18, false, border, 1)); table.addCell(printStr(" ", 1, 18, false, border, 1)); table.addCell(printStr("Name: " + row[0], 1, 22, false, border, 0)); table.addCell(printStr(" " + row[13], 1, 22, false, border, 0)); table.addCell(printStr("Sex: " + row[14], 1, 22, false, border, 0)); table.addCell(printStr("DOB: " + row[15], 1, 22, false, border, 0)); if (row[12].equals("A")) table.addCell( printStr( "Nationality: " + GeneralDataInHtml.getCountryName(row[2]), 1, 22, false, border, 0)); table.addCell(printStr("PPT/Ref. No.: " + row[1], 1, 22, false, border, 0)); table.addCell(printStr(" ", 1, 18, false, border, 1)); table.addCell(printStr(" ", 1, 18, false, border, 1)); double cashTotal = 0; double chequeTotal = 0; table.addCell(printStr(row[3] + " x " + row[4] + " @$" + row[5], 1, 22, false, border, 0)); for (int i = 1; i < data.size(); i++) { String item[] = (String[]) data.get(i); table.addCell( printStr(item[3] + " x " + item[4] + " @$" + item[5], 1, 22, false, border, 0)); } table.addCell(printStr(" ", 1, 18, false, border, 1)); table.addCell(printStr(" ", 1, 18, false, border, 1)); double amt = Double.parseDouble(row[9]); if (row[7].equals("cash")) { table.addCell(printStr("Cash Total: HK$" + amt + "0", 1, 22, false, border, 0)); } else { table.addCell(printStr("Cheque: HK$" + amt + "0", 1, 22, false, border, 0)); table.addCell(printStr("--" + row[8], 1, 22, false, border, 0)); } table.addCell(printStr(" ", 1, 18, false, border, 1)); // Count Collection Date Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; int dayAdd = 2; int dayCount = 2; // int receiptDate = Integer.parseInt(row[18]); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); java.util.Date rDate = sdf.parse(row[18]); java.sql.Timestamp receiptDate = new java.sql.Timestamp(rDate.getTime()); // 86400000 milliseconds in a day long oneDay = 1 * 24 * 60 * 60 * 1000; try { conn = JdbcConnection.getConnection(); for (int k = 1; k <= dayCount; k++) { receiptDate.setTime(receiptDate.getTime() + oneDay); // System.out.println("select 1 from holiday where date = "+(receiptDate)); ps = conn.prepareStatement("select 1 from holiday where date = ?"); ps.setTimestamp(1, receiptDate); rs = ps.executeQuery(); if (rs.next()) { dayCount += 1; dayAdd += 1; } } } catch (Exception e) { e.printStackTrace(); } finally { if (rs != null) try { rs.close(); } catch (Exception e) { e.printStackTrace(); } if (ps != null) try { ps.close(); } catch (Exception e) { e.printStackTrace(); } if (conn != null) try { conn.close(); } catch (Exception e) { e.printStackTrace(); } } Calendar cal = Calendar.getInstance(); cal.set( Integer.parseInt(row[18].substring(0, 4)), Integer.parseInt(row[18].substring(4, 6)) - 1, Integer.parseInt(row[18].substring(6))); cal.add(cal.DATE, dayAdd); Date date = cal.getTime(); SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy (EEE)", Locale.US); table.addCell(printStr(" ", 1, 18, false, border, 1)); if (row[12].equals("A")) { table.addCell(printStr("Collection Date: " + df.format(date), 1, 22, false, border, 1)); table.addCell(printStr("Collection Time: 4:00pm to 5:00pm", 1, 22, false, border, 1)); table.addCell(printStr(" ", 1, 22, false, border, 1)); table.addCell(printStr(row[10] + " " + row[16], 1, 22, false, border, 1)); table.addCell(printStr(" ", 1, 22, false, border, 1)); table.addCell( printStr( "APPLICATION IS SUBJECTED TO APPROVAL, PLEASE BRING THIS RECEIPT ON COLLECTION DAY", 1, 22, false, border, 1)); table.addCell(printStr(row[11], 1, 32, false, border, 1)); table.addCell(printStr("(" + this.params + ")", 1, 22, false, border, 2)); } else { table.addCell(printStr("THANK YOU", 1, 22, false, border, 1)); table.addCell(printStr(row[10] + " " + row[16], 1, 22, false, border, 1)); table.addCell(printStr(" ", 1, 22, false, border, 1)); table.addCell(printStr(row[11], 1, 22, false, border, 1)); table.addCell(printStr("(" + this.params + ")", 1, 22, false, border, 2)); } float[] widths4 = {10}; table.setWidths(widths4); document.add(table); document.close(); } catch (Exception e) { e.printStackTrace(); } return baos; }