/** * @see * org.kuali.kfs.module.ar.document.service.InvoiceRecurrenceService#isValidEndDateAndTotalRecurrenceNumber(Date,Date,int,String) */ @Override public boolean isValidEndDateAndTotalRecurrenceNumber( Date recurrenceBeginDate, Date recurrenceEndDate, Integer totalRecurrenceNumber, String recurrenceIntervalCode) { if (ObjectUtils.isNull(recurrenceBeginDate) || ObjectUtils.isNull(recurrenceIntervalCode) || ObjectUtils.isNull(recurrenceEndDate) || ObjectUtils.isNull(totalRecurrenceNumber)) { return true; } Calendar beginCalendar = Calendar.getInstance(); beginCalendar.setTime(recurrenceBeginDate); Date beginDate = recurrenceBeginDate; Calendar endCalendar = Calendar.getInstance(); endCalendar.setTime(recurrenceEndDate); Date endDate = recurrenceEndDate; Calendar nextCalendar = Calendar.getInstance(); Date nextDate = beginDate; int totalRecurrences = 0; int addCounter = 0; String intervalCode = recurrenceIntervalCode; if (intervalCode.equals("M")) { addCounter = 1; } if (intervalCode.equals("Q")) { addCounter = 3; } /* perform this loop while begin_date is less than or equal to end_date */ while (!(beginDate.after(endDate))) { beginCalendar.setTime(beginDate); beginCalendar.add(Calendar.MONTH, addCounter); beginDate = KfsDateUtils.convertToSqlDate(beginCalendar.getTime()); totalRecurrences++; nextDate = beginDate; nextCalendar.setTime(nextDate); nextCalendar.add(Calendar.MONTH, addCounter); nextDate = KfsDateUtils.convertToSqlDate(nextCalendar.getTime()); if (endDate.after(beginDate) && endDate.before(nextDate)) { totalRecurrences++; break; } } if (totalRecurrences != totalRecurrenceNumber.intValue()) { return false; } return true; }
@Override protected boolean isValidDate() { Date startDate = Date.valueOf("2005-04-30"); Date endDate = Date.valueOf("2005-06-01"); Date parsingDate = Date.valueOf(getYear() + "-" + getMonth() + "-" + "01"); if (parsingDate.after(startDate) && parsingDate.before(endDate)) return true; else return false; }
private void validateHomework(Homework homework, Errors errors) { if (homework.getStartDate().after(homework.getEndDate())) errors.rejectValue("homework.endDate", "date", "Start date cannot be after end date"); java.sql.Date currDate = getCurrentDate(); if (currDate.after(homework.getStartDate())) errors.rejectValue("homework.startDate", "date", "Start date cannot be before today"); if (currDate.after(homework.getEndDate())) errors.rejectValue("homework.endDate", "date", "End date cannot be before today"); if (homework.getNumAttempts() < 0) errors.rejectValue("homework.numAttempts", "date", "Attempts should be 0 or more "); if (homework.getCorrectPts() <= 0) errors.rejectValue("homework.correctPts", "date", "Points cannot be less than 1"); if (homework.getIncorrectPts() < 0) errors.rejectValue("homework.incorrectPts", "date", "Points cannot be less than 0"); int maxQuestions = this.questionService.getNumberOfQuestionsInTheTopic(homework.getTopic(), errors); if (homework.getNumQuestions() > maxQuestions) errors.rejectValue( "homework.numQuestions", "date", "This topic has " + maxQuestions + "questions"); }
public static IntervalXYDataset createDatasetBar() throws Exception { IntervalXYDataset dataset1 = null; Object[][] chart = null; Object[][] chart_qu = null; TCarRecordDao tdao = new TCarRecordDao(); TimeSeries s1, s2; TimeSeriesCollection dataset = new TimeSeriesCollection(); try { if (type == 0) { // 从DAO层获得数据,以天为统计单位,数据线以天为单位 chart = tdao.getCarRecodebyTimearea_day(timefrom, timeto, 1); chart_qu = tdao.getCarRecodebyTimearea_day(timefrom, timeto, 0); s1 = new TimeSeries("入场柱形", Day.class); s2 = new TimeSeries("出场柱形", Day.class); } else { // 传进DAO层的数据是年月,数据线以月的单位 Date date = java.sql.Date.valueOf(timefrom); Date date_t = java.sql.Date.valueOf(timeto); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String newdate_from = sdf.format(date); String timefrom_temp = newdate_from.substring(0, 7); String newdate_to = sdf.format(date_t); String timeto_temp = newdate_to.substring(0, 7); chart = tdao.getCarRecodebyTimearea_month(timefrom_temp, timeto_temp, 1); chart_qu = tdao.getCarRecodebyTimearea_month(timefrom_temp, timeto_temp, 0); s1 = new TimeSeries("入场柱形", Month.class); s2 = new TimeSeries("出场柱形", Month.class); } s1.clear(); Date d, min_r = null, min_c = null, max_r = null, max_c = null; double h; if (chart != null && chart.length > 0) { // 数据为空的处理 System.out.println("ff"); min_r = (Date) chart[0][1]; max_r = (Date) chart[0][1]; for (int i = 0; i < chart.length; i++) { d = (Date) chart[i][1]; if (d.before(min_r)) min_r = d; if (d.after(max_r)) max_r = d; h = new Double(chart[i][0].toString()); // 添加数据,0是以天为单位,1是以月为单位 if (type == 0) s1.add(new Day(d.getDate(), (d.getMonth() + 1), (d.getYear() + 1900)), h); else s1.add(new Month((d.getMonth() + 1), (d.getYear() + 1900)), h); } dataset.addSeries(s1); } else s1 = null; s2.clear(); if (chart_qu != null && chart_qu.length > 0) { min_c = (Date) chart_qu[0][1]; max_c = (Date) chart_qu[0][1]; for (int i = 0; i < chart_qu.length; i++) { d = (Date) chart_qu[i][1]; if (d.before(min_c)) min_c = d; if (d.after(max_c)) max_c = d; h = new Double(chart_qu[i][0].toString()); if (type == 0) s2.add(new Day(d.getDate(), (d.getMonth() + 1), (d.getYear() + 1900)), h); else s2.add(new Month((d.getMonth() + 1), (d.getYear() + 1900)), h); } dataset.addSeries(s2); } else s2 = null; // 取得有数据的时间段的开始和结束 if (min_c != null && min_r != null) min = min_c.before(min_r) ? min_c : min_r; else if (min_c != null) min = min_c; else if (min_r != null) min = min_r; else min = null; if (max_c != null && max_r != null) max = max_c.before(max_r) ? max_r : max_c; else if (max_c != null) max = max_c; else if (max_r != null) max = max_r; else max = null; int seriesCount = dataset.getSeriesCount(); // 一共有多少个序列,目前为一个 for (int i = 0; i < seriesCount; i++) { int itemCount = dataset.getItemCount(i); // 每一个序列有多少个数据项 for (int j = 0; j < itemCount; j++) { if (highValue_Y < dataset.getYValue(i, j)) { // 取第i个序列中的第j个数据项的最大值 highValue_Y = (int) dataset.getYValue(i, j); } if (minValue_Y > dataset.getYValue(i, j)) { // 取第i个序列中的第j个数据项的最小值 minValue_Y = (int) dataset.getYValue(i, j); } } } dataset1 = dataset; return dataset1; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return dataset1; } }
/** * Launches the interactive account manager. * * @param args ignored */ public static void main(String[] args) { // LOW rework this crap Util.printSection("Account Management"); _log.info("Please choose:"); // _log.info("list - list registered accounts"); _log.info("reg - register a new account"); _log.info("rem - remove a registered account"); _log.info("prom - promote a registered account"); _log.info("dem - demote a registered account"); _log.info("ban - ban a registered account"); _log.info("unban - unban a registered account"); _log.info("quit - exit this application"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); L2AccountManager acm = new L2AccountManager(); String line; try { while ((line = br.readLine()) != null) { line = line.trim(); Connection con = null; switch (acm.getState()) { case USER_NAME: line = line.toLowerCase(); try { con = L2Database.getConnection(); PreparedStatement ps = con.prepareStatement("SELECT superuser FROM account WHERE username LIKE ?"); ps.setString(1, line); ResultSet rs = ps.executeQuery(); if (!rs.next()) { acm.setUser(line); _log.info("Desired password:"******"User name already in use."); acm.setState(ManagerState.INITIAL_CHOICE); } rs.close(); ps.close(); } catch (SQLException e) { _log.error("Could not access database!", e); acm.setState(ManagerState.INITIAL_CHOICE); } finally { L2Database.close(con); } break; case PASSWORD: try { MessageDigest sha = MessageDigest.getInstance("SHA"); byte[] pass = sha.digest(line.getBytes("US-ASCII")); acm.setPass(HexUtil.bytesToHexString(pass)); } catch (NoSuchAlgorithmException e) { _log.fatal("SHA1 is not available!", e); Shutdown.exit(TerminationStatus.ENVIRONMENT_MISSING_COMPONENT_OR_SERVICE); } catch (UnsupportedEncodingException e) { _log.fatal("ASCII is not available!", e); Shutdown.exit(TerminationStatus.ENVIRONMENT_MISSING_COMPONENT_OR_SERVICE); } _log.info("Super user: [y/n]"); acm.setState(ManagerState.SUPERUSER); break; case SUPERUSER: try { if (line.length() != 1) throw new IllegalArgumentException("One char required."); else if (line.charAt(0) == 'y') acm.setSuper(true); else if (line.charAt(0) == 'n') acm.setSuper(false); else throw new IllegalArgumentException("Invalid choice."); _log.info("Date of birth: [yyyy-mm-dd]"); acm.setState(ManagerState.DOB); } catch (IllegalArgumentException e) { _log.info("[y/n]?"); } break; case DOB: try { Date d = Date.valueOf(line); if (d.after(new Date(System.currentTimeMillis()))) throw new IllegalArgumentException("Future date specified."); acm.setDob(d); _log.info("Ban reason ID or nothing:"); acm.setState(ManagerState.SUSPENDED); } catch (IllegalArgumentException e) { _log.info("[yyyy-mm-dd] in the past:"); } break; case SUSPENDED: try { if (line.length() > 0) { int id = Integer.parseInt(line); acm.setBan(L2BanReason.getById(id)); } else acm.setBan(null); try { con = L2Database.getConnection(); PreparedStatement ps = con.prepareStatement( "INSERT INTO account (username, password, superuser, birthDate, banReason) VALUES (?, ?, ?, ?, ?)"); ps.setString(1, acm.getUser()); ps.setString(2, acm.getPass()); ps.setBoolean(3, acm.isSuper()); ps.setDate(4, acm.getDob()); L2BanReason lbr = acm.getBan(); if (lbr == null) ps.setNull(5, Types.INTEGER); else ps.setInt(5, lbr.getId()); ps.executeUpdate(); _log.info("Account " + acm.getUser() + " has been registered."); ps.close(); } catch (SQLException e) { _log.error("Could not register an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); } catch (NumberFormatException e) { _log.info("Ban reason ID or nothing:"); } break; case REMOVE: acm.setUser(line.toLowerCase()); try { con = L2Database.getConnection(); PreparedStatement ps = con.prepareStatement("DELETE FROM account WHERE username LIKE ?"); ps.setString(1, acm.getUser()); int cnt = ps.executeUpdate(); if (cnt > 0) _log.info("Account " + acm.getUser() + " has been removed."); else _log.info("Account " + acm.getUser() + " does not exist!"); ps.close(); } catch (SQLException e) { _log.error("Could not remove an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); break; case PROMOTE: acm.setUser(line.toLowerCase()); try { con = L2Database.getConnection(); PreparedStatement ps = con.prepareStatement("UPDATE account SET superuser = ? WHERE username LIKE ?"); ps.setBoolean(1, true); ps.setString(2, acm.getUser()); int cnt = ps.executeUpdate(); if (cnt > 0) _log.info("Account " + acm.getUser() + " has been promoted."); else _log.info("Account " + acm.getUser() + " does not exist!"); ps.close(); } catch (SQLException e) { _log.error("Could not promote an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); break; case DEMOTE: acm.setUser(line.toLowerCase()); try { con = L2Database.getConnection(); PreparedStatement ps = con.prepareStatement("UPDATE account SET superuser = ? WHERE username LIKE ?"); ps.setBoolean(1, false); ps.setString(2, acm.getUser()); int cnt = ps.executeUpdate(); if (cnt > 0) _log.info("Account " + acm.getUser() + " has been demoted."); else _log.info("Account " + acm.getUser() + " does not exist!"); ps.close(); } catch (SQLException e) { _log.error("Could not demote an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); break; case UNBAN: acm.setUser(line.toLowerCase()); try { con = L2Database.getConnection(); PreparedStatement ps = con.prepareStatement("UPDATE account SET banReason = ? WHERE username LIKE ?"); ps.setNull(1, Types.INTEGER); ps.setString(2, acm.getUser()); int cnt = ps.executeUpdate(); if (cnt > 0) _log.info("Account " + acm.getUser() + " has been unbanned."); else _log.info("Account " + acm.getUser() + " does not exist!"); ps.close(); } catch (SQLException e) { _log.error("Could not demote an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); break; case BAN: line = line.toLowerCase(); try { con = L2Database.getConnection(); PreparedStatement ps = con.prepareStatement("SELECT superuser FROM account WHERE username LIKE ?"); ps.setString(1, line); ResultSet rs = ps.executeQuery(); if (rs.next()) { acm.setUser(line); _log.info("Ban reason ID:"); acm.setState(ManagerState.REASON); } else { _log.info("Account does not exist."); acm.setState(ManagerState.INITIAL_CHOICE); } rs.close(); ps.close(); } catch (SQLException e) { _log.error("Could not access database!", e); acm.setState(ManagerState.INITIAL_CHOICE); } finally { L2Database.close(con); } break; case REASON: try { int ban = Integer.parseInt(line); con = L2Database.getConnection(); PreparedStatement ps = con.prepareStatement("UPDATE account SET banReason = ? WHERE username LIKE ?"); ps.setInt(1, ban); ps.setString(2, acm.getUser()); ps.executeUpdate(); _log.info("Account " + acm.getUser() + " has been banned."); ps.close(); } catch (NumberFormatException e) { _log.info("Ban reason ID:"); } catch (SQLException e) { _log.error("Could not ban an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); break; default: line = line.toLowerCase(); if (line.equals("reg")) { _log.info("Desired user name:"); acm.setState(ManagerState.USER_NAME); } else if (line.equals("rem")) { _log.info("User name:"); acm.setState(ManagerState.REMOVE); } else if (line.equals("prom")) { _log.info("User name:"); acm.setState(ManagerState.PROMOTE); } else if (line.equals("dem")) { _log.info("User name:"); acm.setState(ManagerState.DEMOTE); } else if (line.equals("unban")) { _log.info("User name:"); acm.setState(ManagerState.UNBAN); } else if (line.equals("ban")) { _log.info("User name:"); acm.setState(ManagerState.BAN); } else if (line.equals("quit")) Shutdown.exit(TerminationStatus.MANUAL_SHUTDOWN); else _log.info("Incorrect command."); break; } } } catch (IOException e) { _log.fatal("Could not process input!", e); } finally { IOUtils.closeQuietly(br); } }
/** * This is the main controller logic for item selection servlet. This determines whether to show a * list of items for a WorkOrder, add a item, edit a item's detail information, or delete a item. * The product_action parameter is past to this servlet to determine what action to perform. The * product_action parameter is a button defined by JSPs related to product presentation screens. * * <p>The default action is to show all product related to a parent WorkOrder. * * @param req HttpServlet request * @param resp HttpServlet response */ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { WorkOrderDetailRemote workorderdetEJBean = null; securityChecks(req, resp); // Get the current session HttpSession session = req.getSession(false); if (session == null) return; String sTmp = ""; // Get a new business logic EJB (custInfoEJBean) USFEnv.getLog().writeDebug("getting buslogic EJB", this, null); try { workorderdetEJBean = workorderdetHome.create(); USFEnv.getLog().writeDebug("EJBean Created", this, null); } catch (CreateException e) { String errorMsg = "Critical Exception in ItemsServlet"; USFEnv.getLog().writeCrit(errorMsg + " failed EJB creation", this, e); errorJSP(req, resp, errorMsg); return; } catch (RemoteException e) { String errorMsg = "Critical Exception in ItemsServlet"; USFEnv.getLog().writeCrit(errorMsg + " failed EJB connect", this, e); errorJSP(req, resp, errorMsg); return; } catch (Exception e) { String errorMsg = "Critical Exception no EJB created"; USFEnv.getLog().writeCrit(errorMsg + " failed EJB creation", this, e); errorJSP(req, resp, errorMsg); return; } try { // Button user pressed in the itemselection.jsp String sJSPAction = req.getParameter("product_action"); USFEnv.getLog().writeWarn("product_action from JSP: " + sJSPAction, this, null); short year = Short.valueOf((String) session.getValue("Iyear")).shortValue(); long customerId = Long.valueOf((String) session.getValue("rcustId")).longValue(); long applicationId = Long.valueOf((String) session.getValue("rappid")).longValue(); long workorderId = 0; long bkId = 0; long billkeyId = 0; long bsId = 0; long wodId = 0; String editflag = ""; String bsNm = ""; java.sql.Date strtDate = null; java.sql.Date endDate = null; String prodError = ""; // Check to make sure session does have an WorkOrder ID if (session.getValue("WorkOrderId") != null) { // If Yes get the parent WorkOrder ID from session workorderId = Long.valueOf((String) session.getValue("WorkOrderId")).longValue(); } // Button Action from JSP is empty then show the Default page of the // Product Listing. if (USFUtil.isBlank(sJSPAction)) { USFEnv.getLog().writeDebug("Display product list for FRN.", this, null); // list items for parent Work Order Number Vector billingsystems = null; WrkOrdrDets workorderdets = new WrkOrdrDets(); billingsystems = workorderdets.getBillingSystems(); req.setAttribute("BillingSystems", billingsystems); for (int s = 0; s < billingsystems.size(); s++) USFEnv.getLog() .writeDebug("INSIDE BILLING SYSTEMS " + billingsystems.elementAt(s), this, null); listProducts(workorderId, workorderdetEJBean, session, req, resp); return; } // Button action from JSP is to Add a new Item else if (sJSPAction.equals("add")) { // Remove the Product Object from session session.removeValue("prodObj"); editflag = "addnew"; req.setAttribute("editflag", editflag); // Read the Item and the Billing System for adding the New // Item. String formProdBsId = (String) req.getParameter("formProdId"); String formProdId = formProdBsId.substring(0, formProdBsId.indexOf("|")); String formProdName = formProdBsId.substring(formProdBsId.indexOf("|") + 1); long rscId = (new Long(formProdId).longValue()); // bsId = (new Long( formBsId ).longValue()) ; String billSystem = formProdName.substring(0, formProdName.indexOf("-")); String itemName = formProdName.substring(formProdName.indexOf("-") + 1); BlgSys blgSys = new BlgSys(); bsId = blgSys.getBsId(billSystem); // Create db connection for EJB workorderdetEJBean.connect(); // Get the WorkOrder Object. WorkOrder woObj = workorderdetEJBean.getWorkOrderInfo(workorderId); // Get the list of Billing Keys for the Billing System. String[] blgKeys = workorderdetEJBean.getBillingKeys(customerId, bsId); // Release db connection for EJB workorderdetEJBean.release(); // If no Billing Keys for the Billing System selected then redirect // to the List Items screen and show the error Message. if (blgKeys == null) { BlgSys blgsys = new BlgSys(); Hashtable bSysList = (Hashtable) blgsys.searchBlgSys(); // Hashtable bSysList = (Hashtable) USFEnv.getBillSystems(); // Set the JSP error message req.setAttribute("errorMsg", "No BTNs for Billing System " + billSystem); // list products for parent WorkOrder Number listProducts(workorderId, workorderdetEJBean, session, req, resp); return; } req.setAttribute("prodcredit", "N"); req.setAttribute("bsystem", String.valueOf(bsId)); req.setAttribute("bkList", blgKeys); req.setAttribute("prodId", formProdId); String wid = String.valueOf(workorderId); session.putValue("workorderId", wid); req.setAttribute("billingsystem", billSystem); req.setAttribute("itemname", itemName); // Include the JSP to Edit Product includeJSP(req, resp, ITEM_JSP_PATH, "editItem"); return; } // Button action from JSP is to Edit a Product else if (sJSPAction.equals("edit")) { String bsysid = req.getParameter("bsId"); session.putValue("bysysidforedit", bsysid); wodId = (new Long((String) req.getParameter("wodId"))).longValue(); // bkId = (new Long( (String) req.getParameter("bkId"))).longValue() ; session.putValue("workorderdetid", String.valueOf(wodId)); bsId = (new Long((String) req.getParameter("bsId"))).longValue(); BlgSys blgSys = new BlgSys(); bsNm = blgSys.getBsName(bsId); // Create db connection for EJB workorderdetEJBean.connect(); // WorkOrder woObj = workorderdetEJBean.getWorkOrderInfo(workorderId); // Get the WorkOrder Number Object WrkOrdrDets wodets_obj = new WrkOrdrDets(); wodets_obj = workorderdetEJBean.getProductInfo(wodId); // Get the List of Billing Keys for the Billing System. String[] blgKeys = workorderdetEJBean.getBillingKeys(customerId, bsId); // Check if the Item has any Credits. If any credits then Billing // Key is not Editable else Editable. if (workorderdetEJBean.hasCredits(wodId)) { req.setAttribute("prodcredit", "Y"); } else { req.setAttribute("prodcredit", "N"); } // Release db connection for EJB workorderdetEJBean.release(); // If Item Object is not null (which generally is the case) then // set the Attributes for the JSP. if (wodets_obj != null) { // Put the Item Object in session editflag = "edit"; session.putValue("wodets", wodets_obj); req.setAttribute("editflag", editflag); // Set the attributes for the Billing System, Billing Key List, req.setAttribute("bkList", blgKeys); req.setAttribute("bsname", bsNm); // Include the JSP to Edit the Item. includeJSP(req, resp, ITEM_JSP_PATH, "editItem"); return; } // If Item Object is null (which generally should not Occur) show // the Default page of Item List for the WorkOrder Number else { // Set the JSP error message req.setAttribute( "errorMsg", "Product Key - " + wodId + " Information not available in the Data Base"); // list items for parent WorkOrder Number listProducts(workorderId, workorderdetEJBean, session, req, resp); return; } } // Button action from JSP is to Delete an Item else if (sJSPAction.equals("delete")) { String formWodId = req.getParameter("wodId"); wodId = (new Long((String) req.getParameter("wodId"))).longValue(); // Create db connection for EJB workorderdetEJBean.connect(); // Delete the Item if (workorderdetEJBean.deleteProduct(wodId)) { req.setAttribute("errorMsg", "Product Key - " + wodId + " Deleted"); } else { req.setAttribute( "errorMsg", "Deletion Failed. Product Key - " + wodId + " is associated with amounts."); } // Release db connection for EJB workorderdetEJBean.release(); // Show the Item List screen listProducts(workorderId, workorderdetEJBean, session, req, resp); return; } // Button action from JSP is to Save a Product. This includes Insertion // of New Product or Updation of an Existing Product. else if (sJSPAction.equals("save")) { boolean save = false; boolean newProd = false; // long qty=0; // Read the Billing System Id String formBsId = (String) req.getParameter("bs_id"); String bsysid = (String) req.getParameter("bsysid"); /* String trans_type = (String) req.getParameter("trans_type"); //String quantity = (String) req.getParameter("qty"); String quantity=""; if (!(req.getParameter("qty").equals(""))) { quantity=(String) req.getParameter("qty"); qty = (new Long(quantity).longValue()); } */ String prod_stat = (String) req.getParameter("prod_stat"); double nrcg_dscnt = (new Double((String) req.getParameter("NonRecurringDiscount"))).doubleValue(); double rcg_dscnt = (new Double((String) req.getParameter("RecurringDiscount"))).doubleValue(); String start_month = (String) req.getParameter("strt_month"); String start_day = (String) req.getParameter("strt_day"); String start_year = (String) req.getParameter("strt_year"); String end_month = (String) req.getParameter("end_month"); String end_day = (String) req.getParameter("end_day"); String end_year = (String) req.getParameter("end_year"); String start_date = start_month + "-" + start_day + "-" + start_year; String end_date = end_month + "-" + end_day + "-" + end_year; long wrkordrid = (new Long((String) session.getValue("WorkOrderId"))).longValue(); String for_editing = req.getParameter("for_editing"); String for_new = req.getParameter("for_new"); String formBkId = (String) req.getParameter("bk_id"); String formBKId = formBkId.substring(0, formBkId.indexOf("|")); String formBTN = formBkId.substring(formBkId.indexOf("|") + 1); billkeyId = (new Long(formBKId)).longValue(); try { bsId = (new Long((String) req.getParameter("bs_id"))).longValue(); } catch (Exception e) { USFEnv.getLog().writeDebug("Exception is " + e, this, null); } RHCCBlgKeys blgkeys = new RHCCBlgKeys(); if (for_editing.equals("editing")) { blgkeys.setRbkId(billkeyId); blgkeys.setRbkKeys(formBTN); blgkeys.setBsId(new Long(bsysid).longValue()); } if (for_new.equals("new")) { blgkeys.setRbkId(billkeyId); blgkeys.setRbkKeys(formBTN); blgkeys.setBsId(bsId); } int index = 0; WrkOrdrDets wod_obj = new WrkOrdrDets(); // wod_obj.setTxTyp(trans_type); // wod_obj.setQty(qty); wod_obj.setNonRcrgDscnt(nrcg_dscnt); wod_obj.setRcrgDscnt(rcg_dscnt); wod_obj.setRBKID(billkeyId); wod_obj.setWodStat(prod_stat); wod_obj.setWOID(wrkordrid); if (!(start_date.equals(""))) { strtDate = new java.sql.Date((new SimpleDateFormat("MM-dd-yyyy")).parse(start_date).getTime()); wod_obj.setStrtDat(strtDate); } // Else if the Start Date is null update the Item Object Date to // null else { wod_obj.setStrtDat(null); } // If Item Service End Date is not null read the date and update // the Item Object with the date if (!(end_date.equals(""))) { endDate = new java.sql.Date((new SimpleDateFormat("MM-dd-yyyy")).parse(end_date).getTime()); wod_obj.setEndDat(endDate); } // Else if the End Date is null update the Item Object Date to null else { wod_obj.setEndDat(null); } // Check if the Start Date is after the End Date or equals End Date if ((strtDate != null) && (endDate != null) && (strtDate.after(endDate))) { prodError = "Product Service Start Date is after Product Service End Date. \n"; index = 1; } else if ((strtDate != null) && (endDate != null) && (strtDate.equals(endDate))) { prodError = "Product Service Start Date equals Product Service End Date. \n"; } workorderdetEJBean.connect(); if (for_editing.equals("editing")) { long workorderdetID = (new Long((String) session.getValue("workorderdetid"))).longValue(); wod_obj.setWODID(workorderdetID); if (index == 0) { save = workorderdetEJBean.saveProduct(wod_obj); } if (save) { prodError = prodError + "<BR> Product Key - " + wod_obj.getWODID() + " Information updated"; req.setAttribute("error", prodError); } else { prodError = prodError + "<BR> Failed to update Product Information"; req.setAttribute("error", prodError); } } if (for_new.equals("new")) { if (index == 0) { int prodId = Integer.parseInt(req.getParameter("prod_Id")); wod_obj.setProd_id(prodId); save = workorderdetEJBean.saveProduct(wod_obj); } if (save) { prodError = prodError + "<BR> Product Key - " + wod_obj.getWODID() + " Information Saved"; req.setAttribute("error", prodError); } else { prodError = prodError + "<BR> Failed to Save Product Information"; req.setAttribute("error", prodError); } } workorderdetEJBean.release(); listProducts(wrkordrid, workorderdetEJBean, session, req, resp); } } // End of try block catch (Exception e) { if (workorderdetEJBean != null) { // calling bean release method try { workorderdetEJBean.release(); } catch (Exception ex) { USFEnv.getLog().writeCrit(" Exception in calling release() method ", this, e); } } String errorMsg = "Processing Exception in Items Servlet: "; USFEnv.getLog().writeCrit(errorMsg, this, e); errorJSP(req, resp, errorMsg); } // End of catch block } // end of doPost()
/** Non-exception-aware version of the above. */ protected Status trySendRetentionEmail(int memberId, Date secondEmailCutoff, NewStuff filler) { SpamRecord spamRec = _spamRepo.loadSpamRecord(memberId); Date last = spamRec == null ? null : spamRec.retentionSent; Status status = last == null ? null : Status.lookup(spamRec.retentionStatus); if (last != null && last.after(secondEmailCutoff) && status != null && status.success) { // spammed recently, skip return Status.TOO_RECENTLY_SPAMMED; } // load the member MemberRecord mrec = _memberRepo.loadMember(memberId); if (mrec == null) { log.warning("Member deleted during retention mailing?", "memberId", memberId); return Status.MEMBER_DELETED; } // skip placeholder addresses if (MemberMailUtil.isPlaceholderAddress(mrec.accountName)) { return Status.PLACEHOLDER_ADDRESS; } // skip invalid addresses if (!MailUtil.isValidAddress(mrec.accountName)) { return Status.INVALID_ADDRESS; } // oh look, they've logged in! maybe the email(s) worked. clear counter boolean persuaded = (last != null) && mrec.lastSession.after(last); if (persuaded) { spamRec.retentionCountSinceLogin = 0; // fall through, we'll send a mail and save the record below } else if (status == Status.NOT_ENOUGH_FRIENDS || status == Status.NOT_ENOUGH_NEWS) { // reset legacy failures, we now send filler for these people spamRec.retentionCountSinceLogin = 0; // fall through, we'll send a mail and save the record below } else if (spamRec != null && spamRec.retentionCountSinceLogin >= 2) { // they are never coming back... oh well, there are plenty of other fish in the sea return Status.LOST_CAUSE; } // sending the email could take a while so update the spam record here to reduce window // where other peers may conflict with us. NOTE: we do plan to run this job on multiple // servers some day _spamRepo.noteRetentionEmailSending(memberId, spamRec); // choose a successful result based on previous attempts status = Status.SENT_DORMANT; if (persuaded) { status = Status.SENT_PERSUADED; } else if (spamRec == null || spamRec.retentionCount == 0) { status = Status.SENT_LAPSED; } // now send the email MailContent content = sendRetentionEmail(mrec, null, filler, true); // NOTE: this is sort of redundant but increases the integrity of the spam record and // reduces chance of a user getting two emails when we are 1M strong _spamRepo.noteRetentionEmailResult(memberId, status.value); // log an event for successes. the result is the lapse status if (status.success) { _eventLog.retentionMailSent( mrec.memberId, mrec.visitorId, status.name(), content.subjectLine, content.bucket.name, content.numFriends, content.numPersonalMessages, mrec.isValidated()); } return status; }
public static int addPlan(Plan plan) throws SQLException, TextFormatException, JSONException, NoSuchAlgorithmException, UnsupportedEncodingException { if (plan == null) { logger.error("Can't add empty plan"); return -1; } String SQLCommand = null; DBUtil du = DBUtil.getDBUtil(); ResultSet rs; String title = plan.getTitle(); String siteIDs = plan.getSiteIDs(); int organizer = plan.getOrganizer(); Date startTime = plan.getStartTime(); Date endTime = plan.getEndTime(); String describe = plan.getDescribe(); if (Util.isEmpty(siteIDs) || organizer < 0 || startTime == null || endTime == null || startTime.after(endTime)) { logger.error("illegal plan"); return -1; } SQLCommand = " insert into " + tableName + " ( title, siteIDs, startTime, endTime, organizer, participants, budget, groupNum, groupNumMax, isDone, information ) " + " values ( '" + title + "' , '" + siteIDs + "' , '" + startTime + "' , '" + endTime + "' , " + organizer + " , '" + plan.getParticipants() + "' , " + plan.getBudget() + " , " + plan.getGroupNum() + " , " + plan.getGroupNumMax() + " , false , '" + describe + "')"; System.out.println(SQLCommand); rs = du.executeUpdate(SQLCommand); rs.next(); int planID = rs.getInt(1); // Plan new_plan = new Plan(planID, title, siteIDs, startTime, endTime, organizer, // plan.getParticipants(), plan.getBudget(), plan.getGroupNum(), plan.getGroupNumMax(), // plan.getTalkStreamID(), false); /* User user = new User(); String orig_plans =new UserManager().selectUser(organizer).getPlans(); user.setPlans(new JSONHelper().addToArray(orig_plans, planID)); new UserManager().editUser(organizer, user); Vector<Integer> siteIDVector =new JSONHelper().convertToArray(siteIDs); for(int j=0;j<siteIDVector.size();j++){ int siteID = siteIDVector.get(j); SQLCommand = " insert into " + relationTableName +"( userID, siteID, startTime, endTime, planID )" + " values ( " + organizer + " , " + siteID + " , '" + startTime + "' , '" + endTime + "' , " + planID + ")"; du.executeUpdate(SQLCommand); } */ return planID; }
private void refresh() { // validasi input Date tanggalmulai = null; try { tanggalmulai = Date.valueOf(jTextFieldTanggalMulai.getText()); } catch (IllegalArgumentException e) { return; } Date tanggalselesai = null; try { tanggalselesai = Date.valueOf(jTextFieldTanggalSelesai.getText()); } catch (IllegalArgumentException e) { return; } if (tanggalmulai.after(tanggalselesai)) { JOptionPane.showMessageDialog(null, "tanggal mulai harus sebelum tanggal selesai"); return; } Ruang ruangterpilih = (Ruang) jComboBoxRuang.getModel().getSelectedItem(); int idruang = ruangterpilih.getId(); // refresh try { Transaksi[] alltransaksi = this.getMainMenu().getDbc().getTransaksi(idruang, tanggalmulai, tanggalselesai); DefaultTableModel model = new DefaultTableModel(); model.addColumn("id"); model.addColumn("Nama Kegiatan"); model.addColumn("Jenis Kegiatan"); model.addColumn("Tanggal"); model.addColumn("Waktu Mulai"); model.addColumn("Waktu Selesai"); model.addColumn(""); model.addColumn(""); // aksi hapus Action delete = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); int id = (int) table.getModel().getValueAt(modelRow, 0); int confirm = JOptionPane.showConfirmDialog( null, "Yakin menghapus transaksi ini?", "Konfirmasi", JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.YES_OPTION) { try { getMainMenu().getDbc().deleteTransaksiById(id); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "error: " + ex); Logger.getLogger(jPanelData.class.getName()).log(Level.SEVERE, null, ex); } } refresh(); } }; // aksi ubah Action edit = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); TableModel model = table.getModel(); final JDialog frame = new JDialog(getMainMenu(), "Ubah Data Transaksi", true); jPanelEditTransaksi panelinput = new jPanelEditTransaksi(frame, getMainMenu().getDbc()); panelinput.setTargetId((int) model.getValueAt(modelRow, 0)); Kuliah k; try { k = getMainMenu().getDbc().getKuliahTransaksi((int) model.getValueAt(modelRow, 0)); if (k != null) panelinput.setKuliah(k); } catch (SQLException ex) { Logger.getLogger(jPanelTransaksi.class.getName()).log(Level.SEVERE, null, ex); } panelinput.setNamaKegiatan((String) model.getValueAt(modelRow, 1)); panelinput.setJenisKegiatan((String) model.getValueAt(modelRow, 2)); panelinput.setTanggalMulai((Date) model.getValueAt(modelRow, 3)); panelinput.setWaktuMulai((Time) model.getValueAt(modelRow, 4)); panelinput.setWaktuSelesai((Time) model.getValueAt(modelRow, 5)); frame.getContentPane().add(panelinput); frame.pack(); frame.setVisible(true); refresh(); } }; for (int i = 0; i < alltransaksi.length; i++) { Object[] p = new Object[8]; p[0] = alltransaksi[i].getId(); p[1] = alltransaksi[i].getNama_kegiatan(); p[2] = alltransaksi[i].getJenis_kegiatan(); p[3] = alltransaksi[i].getTanggal(); p[4] = alltransaksi[i].getStart_time(); p[5] = alltransaksi[i].getFinish_time(); p[6] = "Ubah"; p[7] = "Hapus"; model.addRow(p); } jTable1.setModel(model); ButtonColumn buttonColumnDelete = new ButtonColumn(jTable1, delete, 7); buttonColumnDelete.setMnemonic(KeyEvent.VK_D); ButtonColumn buttonColumnEdit = new ButtonColumn(jTable1, edit, 6); buttonColumnEdit.setMnemonic(KeyEvent.VK_D); jTable1.removeColumn(jTable1.getColumnModel().getColumn(0)); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "Error" + ex); Logger.getLogger(jPanelData.class.getName()).log(Level.SEVERE, null, ex); } }