List of usage examples for java.util GregorianCalendar add
@Override public void add(int field, int amount)
From source file:org.redis.shop.test.InitData.java
@Test public void bc_addTagAndTransaction() throws ParseException { Tag tag = null;//from ww w. j a va 2 s. c o m Transaction transaction = null; Category category1 = categoryService.getList("name", "?").get(1); Category category2 = categoryService.getList("name", "").get(0); Category category3 = categoryService.getList("name", "").get(0); Category category4 = categoryService.getList("name", "").get(1); Category category5 = categoryService.getList("name", "?").get(0); PlateformScale plateformScale = plateformScaleService.get("plateformScaleNum", "TB-0001"); Vechile vechile1 = vechileService.get("vechileNum", "CH-0001"); Vechile vechile2 = vechileService.get("vechileNum", "CH-0002"); Vechile vechile3 = vechileService.get("vechileNum", "CH-0003"); Vechile vechile4 = vechileService.get("vechileNum", "CH-0004"); Vechile vechile5 = vechileService.get("vechileNum", "CH-0005"); Site site1 = siteService.get("user.name", "s1"); Center center1 = centerService.get("user.name", "c1"); Site site2 = siteService.get("user.name", "s2"); Center center2 = centerService.get("user.name", "c2"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date before = sdf.parse("2015-01-01"); Date today = sdf.parse(sdf.format(new Date())); Calendar calendar = Calendar.getInstance(); calendar.setTime(before); long beforeTime = calendar.getTimeInMillis(); calendar.setTime(today); long todayTime = calendar.getTimeInMillis(); long betweenDays = (todayTime - beforeTime) / (1000 * 3600 * 24); GregorianCalendar cal = new GregorianCalendar(); float weight1 = 1000f; float weight2 = 2000f; float weight3 = 3000f; float weight4 = 2500f; float weight5 = 2800f; for (int i = 0; i <= betweenDays; i++) { cal.setTime(before); cal.add(Calendar.DATE, i); Date dateNow = cal.getTime(); List<Tag> tags = new ArrayList<>(); if (i % 5 == 0) { tag = new Tag(); tag.setTime(dateNow); tag.setWeight(weight1); tag.setPrice(10f); tag.setType(Enum_TagType.WR); tag.setCategory(category1); tag.setTagNum("RFID-1" + i); tag.setVechile(vechileService.get("vechileNum", "CH-0001")); tag.setPlateformScale(plateformScale); // String tagId = (String) tagService.save(tag); tags.add(tag); transaction = new Transaction(); transaction.setTags(tags); transaction.setPrice(tag.getPrice()); transaction.setTotalPrice(tag.getPrice() * tag.getWeight()); transaction.setState(Enum_Transaction.IT); transaction.setInTime(dateNow); transaction.setOutTime(dateNow); transaction.setVechile(vechile1); transaction.setTransactionProperty(Enum_TransactionProperty.HAO); if (i % 2 == 0) { transaction.setCenter(center1); transaction.setSite(site1); } else { transaction.setCenter(center2); transaction.setSite(site2); } tagService.save(tag); transactionService.save(transaction); tag.setTransaction(transaction); tagService.update(tag); } else if (i % 5 == 1) { tag = new Tag(); tag.setTime(dateNow); tag.setVechile(vechileService.get("vechileNum", "CH-0002")); tag.setWeight(weight2); tag.setPrice(10f); tag.setType(Enum_TagType.WR); tag.setCategory(category2); tag.setTagNum("RFID-2" + i); tag.setPlateformScale(plateformScale); // String tagId = (String) tagService.save(tag); tags.add(tag); transaction = new Transaction(); transaction.setTags(tags); transaction.setPrice(tag.getPrice()); transaction.setTotalPrice(tag.getPrice() * tag.getWeight()); transaction.setState(Enum_Transaction.IT); transaction.setInTime(dateNow); transaction.setOutTime(dateNow); transaction.setVechile(vechile2); transaction.setTransactionProperty(Enum_TransactionProperty.HAO); if (i % 2 == 0) { transaction.setCenter(center1); transaction.setSite(site1); } else { transaction.setCenter(center2); transaction.setSite(site2); } tagService.save(tag); transactionService.save(transaction); tag.setTransaction(transaction); tagService.update(tag); } else if (i % 5 == 2) { tag = new Tag(); tag.setTime(dateNow); tag.setWeight(weight3); tag.setPrice(10f); tag.setVechile(vechileService.get("vechileNum", "CH-0003")); tag.setType(Enum_TagType.AR); tag.setCategory(category3); tag.setTagNum("RFID-3" + i); tag.setPlateformScale(plateformScale); // String tagId = (String) tagService.save(tag); tags.add(tag); transaction = new Transaction(); transaction.setTags(tags); transaction.setPrice(tag.getPrice()); transaction.setTotalPrice(tag.getPrice() * tag.getWeight()); transaction.setState(Enum_Transaction.IT); transaction.setInTime(dateNow); transaction.setOutTime(dateNow); transaction.setVechile(vechile3); transaction.setTransactionProperty(Enum_TransactionProperty.HAO); if (i % 2 == 0) { transaction.setCenter(center1); transaction.setSite(site1); } else { transaction.setCenter(center2); transaction.setSite(site2); } tagService.save(tag); transactionService.save(transaction); tag.setTransaction(transaction); tagService.update(tag); } else if (i % 5 == 3) { tag = new Tag(); tag.setTime(dateNow); tag.setWeight(weight4); tag.setPrice(10f); tag.setType(Enum_TagType.AR); tag.setCategory(category4); tag.setVechile(vechileService.get("vechileNum", "CH-0004")); tag.setTagNum("RFID-4" + i); tag.setPlateformScale(plateformScale); // String tagId = (String) tagService.save(tag); tags.add(tag); transaction = new Transaction(); transaction.setTags(tags); transaction.setPrice(tag.getPrice()); transaction.setTotalPrice(tag.getPrice() * tag.getWeight()); transaction.setState(Enum_Transaction.IT); transaction.setInTime(dateNow); transaction.setOutTime(dateNow); transaction.setVechile(vechile4); transaction.setTransactionProperty(Enum_TransactionProperty.HAO); if (i % 2 == 0) { transaction.setCenter(center1); transaction.setSite(site1); } else { transaction.setCenter(center2); transaction.setSite(site2); } tagService.save(tag); transactionService.save(transaction); tag.setTransaction(transaction); tagService.update(tag); } else { tag = new Tag(); tag.setTime(dateNow); tag.setWeight(weight5); tag.setPrice(10f); tag.setType(Enum_TagType.WR); tag.setCategory(category5); tag.setVechile(vechileService.get("vechileNum", "CH-0005")); tag.setTagNum("RFID-5" + i); tag.setPlateformScale(plateformScale); // String tagId = (String) tagService.save(tag); tags.add(tag); transaction = new Transaction(); transaction.setTags(tags); transaction.setPrice(tag.getPrice()); transaction.setTotalPrice(tag.getPrice() * tag.getWeight()); transaction.setState(Enum_Transaction.IT); transaction.setInTime(dateNow); transaction.setOutTime(dateNow); transaction.setVechile(vechile5); transaction.setTransactionProperty(Enum_TransactionProperty.HAO); if (i % 2 == 0) { transaction.setCenter(center1); transaction.setSite(site1); } else { transaction.setCenter(center2); transaction.setSite(site2); } tagService.save(tag); transactionService.save(transaction); tag.setTransaction(transaction); tagService.update(tag); } weight1 += 3f; weight2 += 2f; weight3 += 2.5f; weight4 += 1.5f; weight5 += 1.7f; } /*List<Transaction> transactions = new ArrayList<Transaction>(); transactions = transactionService.getAll(); for(Transaction t : transactions){ if(t.getTags()!=null&&t.getTags().size()!=0){ for(Tag tt : t.getTags()){ if(tt.getCategory()!=null){ if(tt.getCategory().getParentCategory()!=null){ if(tt.getCategory().getParentCategory().getParentCategory()!=null){ if(tt.getCategory().getParentCategory().getParentCategory().getParentCategory()!=null){ t.setCategoryName(tt.getCategory().getParentCategory().getParentCategory().getParentCategory().getName()); }else{ t.setCategoryName(tt.getCategory().getParentCategory().getParentCategory().getName()); } }else{ t.setCategoryName(tt.getCategory().getParentCategory().getName()); } }else{ t.setCategoryName(tt.getCategory().getName()); } } transactionService.update(t); } } }*/ }
From source file:org.eevolution.form.CRP.java
/** * Create Category Dataset based on Weight , date start and resource * @param start//from w w w .j av a2s . com * @param resource * @return CategoryDataset */ protected CategoryDataset createWeightDataset(Timestamp start, MResource rosource) { GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND); gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); String nameload = Msg.translate(Env.getCtx(), "Load"); String namesummary = Msg.translate(Env.getCtx(), "Summary"); String namepossiblecapacity = "Possible Capacity"; MResourceType t = MResourceType.get(Env.getCtx(), rosource.getS_ResourceType_ID()); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); double currentweight = DB.getSQLValue(null, "SELECT SUM( (mo.qtyordered-mo.qtydelivered)*(SELECT mp.weight FROM M_Product mp WHERE mo.m_product_id=mp.m_product_id )) FROM PP_Order mo WHERE AD_Client_ID=?", rosource.getAD_Client_ID()); double dailyCapacity = rosource.getDailyCapacity().doubleValue(); double utilization = rosource.getPercentUtilization().doubleValue(); double summary = 0; int day = 0; while (day < 32) { day++; switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: if (t.isOnSunday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.MONDAY: if (t.isOnMonday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.TUESDAY: if (t.isOnTuesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.WEDNESDAY: if (t.isOnWednesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.THURSDAY: if (t.isOnThursday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.FRIDAY: if (t.isOnFriday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.SATURDAY: if (t.isOnSaturday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; } dataset.addValue(currentweight, nameload, new Integer(day)); dataset.addValue(summary, namesummary, new Integer(day)); gc1.add(Calendar.DATE, 1); } return dataset; }
From source file:org.sakaiproject.calendar.impl.BaseCalendarService.java
/** * Collect the fields that need to be stored outside the XML (for the resource). * // w ww .j a v a 2 s . c om * @return An array of field values to store in the record outside the XML (for the resource). */ public Object[] storageFields(Entity r) { Object[] rv = new Object[4]; TimeRange range = ((CalendarEvent) r).getRange(); rv[0] = range.firstTime(); // %%% fudge? rv[1] = range.lastTime(); // %%% fudge? // we use hours rather than ms for the range to reduce the index size in the database // I dont what to use days just incase we want sub day range finds long oneHour = 60L * 60L * 1000L; rv[2] = (int) (range.firstTime().getTime() / oneHour); rv[3] = (int) (range.lastTime().getTime() / oneHour); // find the end of the sequence RecurrenceRuleBase rr = (RecurrenceRuleBase) ((CalendarEvent) r).getRecurrenceRule(); if (rr != null) { Time until = rr.getUntil(); if (until != null) { rv[3] = (int) (until.getTime() / oneHour); } else { int count = rr.getCount(); int interval = rr.getInterval(); long endevent = range.lastTime().getTime(); if (count == 0) { rv[3] = Integer.MAX_VALUE - 1; // hours since epoch, this represnts 9 Oct 246953 07:00:00 } else { String frequency = rr.getFrequency(); GregorianCalendar c = new GregorianCalendar(); c.setTimeInMillis(endevent); c.add(rr.getRecurrenceType(), count * interval); rv[3] = (int) (c.getTimeInMillis() / oneHour); } } } return rv; }
From source file:org.eevolution.form.VCRP.java
public CategoryDataset createDataset(Timestamp start, MResource r) { //System.out.println("Create new data set"); GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND);/* w w w .ja va 2s . com*/ gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); Timestamp date = start; String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); System.out.println("\n Namecapacity :" + namecapacity); String nameload = Msg.translate(Env.getCtx(), "Load"); System.out.println("\n Nameload :" + nameload); String namesummary = Msg.translate(Env.getCtx(), "Summary"); System.out.println("\n Namesummary :" + namesummary); MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null); System.out.println("\n Resourcetype " + t); int days = 1; long hours = 0; if (t.isTimeSlot()) { hours = MMPCMRP.getHoursAvailable(t.getTimeSlotStart(), t.getTimeSlotEnd()); } else { //fjviejo e-evolution MachineQty if (r.getDailyCapacity().multiply(r.getMachineQty()).compareTo(Env.ZERO) != 0) hours = r.getDailyCapacity().multiply(r.getMachineQty()).longValue(); else //fjviejo e-evolution end hours = 24; } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Long Hours = new Long(hours); int C_UOM_ID = DB.getSQLValue(null, "SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? ", r.getS_Resource_ID()); MUOM uom = new MUOM(Env.getCtx(), C_UOM_ID, null); System.out.println("\n uom1 " + uom + "\n"); //System.out.println("um.isHour()"+ uom.isHour() ); if (!uom.isHour()) { System.out.println("\n uom2 " + uom + "\n"); return dataset; } System.out.println("\n Dataset " + dataset + "\n"); int summary = 0; //int cont = 1; DateFormat formatter = DateFormat.getDateInstance(); /* * Vit4B Modificado para que tome 28 dias y * * */ while (days < 29) { /* * VIT4B MODIFICACION PARA ACUMULADO DE DIAS * * * //System.out.println("Day Number" + days); String strday = formatter.format(date); //String day = new String(new Integer (date.getDate()).toString()); String day = new String(formatter.format(date)); //day = day.substring(0,5); int index = day.indexOf("/"); String str = day.substring(0,index); System.out.println("str: " + str + " index de / " + index); String str2 = day.substring(index+1,day.length()); System.out.println("str2 resto: " + str2); index = str2.indexOf("/"); System.out.println(index); String str3 = str2.substring(0,index); System.out.println("str3: " + str3 + " index de / " + index); String str4 = str2.substring(index+1,str2.length()); System.out.println(str4); System.out.println("dia: " + str); System.out.println("mes: " + str3); System.out.println("ao: " + str4); //day = str + str3; day = new String(str + str3); //day = day.substring(0,day.lastIndexOf("/")); //day =day.substring(0,3); //cont++; System.out.println("r.getS_Resource_ID()" + r.getS_Resource_ID()); System.out.println("Date: " + date + " day: " + day); int seconds = getLoad(r.getS_Resource_ID(),date ,date); Long Hours = new Long(hours); System.out.println("Summary "+ summary); System.out.println("Capacity "+ hours); System.out.println("Load "+ seconds); /* * * VIT4B MODIFICACION PARA ACUMULADO DE DIAS * * */ /* * ORIGINAL COMPIERE */ String day = new String(new Integer(date.getDate()).toString()); System.out.println("r.getS_Resource_ID()" + r.getS_Resource_ID()); System.out.println("Date:" + date); /* * VIT4B - Modificacin para calcular como se calcula el reporte CCRP * en funcion de la carga parcial * * */ int seconds = getLoad(r.getS_Resource_ID(), date, date); //BigDecimal value = calculateLoad(date, r, null); //int seconds = value.intValue(); Long Hours = new Long(hours); System.out.println("Summary " + summary); System.out.println("Load " + seconds); /* * FIN ORIGINAL COMPIERE * */ switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: days++; if (t.isOnSunday()) { //System.out.println("si Sunday"); //Msg.translate(Env.getCtx(), "OnSunday"); dataset.addValue(hours, namecapacity, day); dataset.addValue(seconds / 3600, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (seconds / 3600); //+ (Hours.intValue() - ((seconds / 3600))); gc1.add(Calendar.DATE, 1); date = org.compiere.util.TimeUtil.addDays(date, 1); break; } else { //System.out.println("no Sunday"); //String day = Msg.translate(Env.getCtx(), "OnSunday") ; dataset.addValue(0, namecapacity, day); dataset.addValue(seconds / 3600, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = org.compiere.util.TimeUtil.addDays(date, 1); break; } case Calendar.MONDAY: days++; if (t.isOnMonday()) { //System.out.println("si Monday"); //String day = Msg.translate(Env.getCtx(), "OnMonday") ; dataset.addValue(hours, namecapacity, day); dataset.addValue(seconds / 3600, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = org.compiere.util.TimeUtil.addDays(date, 1); break; } else { //System.out.println("no Monday"); //String day = Msg.translate(Env.getCtx(), "OnMonday") ; dataset.addValue(0, namecapacity, day); dataset.addValue(seconds / 3600, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = org.compiere.util.TimeUtil.addDays(date, 1); break; } case Calendar.TUESDAY: days++; if (t.isOnTuesday()) { //System.out.println("si TuesDay"); //String day = Msg.translate(Env.getCtx(), "OnTuesday"); dataset.addValue(hours, namecapacity, day); dataset.addValue(seconds / 3600, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = org.compiere.util.TimeUtil.addDays(date, 1); break; } else { //System.out.println("no TuesDay"); //String day = Msg.translate(Env.getCtx(), "OnTuesday"); dataset.addValue(0, namecapacity, day); dataset.addValue(seconds / 3600, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = org.compiere.util.TimeUtil.addDays(date, 1); break; } case Calendar.WEDNESDAY: days++; if (t.isOnWednesday()) { //String day = Msg.translate(Env.getCtx(), "OnWednesday"); dataset.addValue(hours, namecapacity, day); dataset.addValue(seconds / 3600, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = org.compiere.util.TimeUtil.addDays(date, 1); break; } else { //String day = Msg.translate(Env.getCtx(), "OnWednesday"); dataset.addValue(0, namecapacity, day); dataset.addValue(seconds / 3600, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = org.compiere.util.TimeUtil.addDays(date, 1); break; } case Calendar.THURSDAY: days++; if (t.isOnThursday()) { //String day = Msg.translate(Env.getCtx(), "OnThursday"); dataset.addValue(hours, namecapacity, day); dataset.addValue(seconds / 3600, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = org.compiere.util.TimeUtil.addDays(date, 1); break; } else { //String day = Msg.translate(Env.getCtx(), "OnThursday"); dataset.addValue(0, namecapacity, day); dataset.addValue(seconds / 3600, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = org.compiere.util.TimeUtil.addDays(date, 1); break; } case Calendar.FRIDAY: days++; if (t.isOnFriday()) { //String day = Msg.translate(Env.getCtx(), "OnFriday"); dataset.addValue(hours, namecapacity, day); dataset.addValue(seconds / 3600, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = org.compiere.util.TimeUtil.addDays(date, 1); break; } else { //String day = Msg.translate(Env.getCtx(), "OnFriday"); dataset.addValue(0, namecapacity, day); dataset.addValue(seconds / 3600, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = org.compiere.util.TimeUtil.addDays(date, 1); break; } case Calendar.SATURDAY: days++; if (t.isOnSaturday()) { //String day = Msg.translate(Env.getCtx(), "OnSaturday"); dataset.addValue(hours, namecapacity, day); dataset.addValue(seconds / 3600, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = org.compiere.util.TimeUtil.addDays(date, 1); break; } else { //String day = Msg.translate(Env.getCtx(), "OnSaturday"); dataset.addValue(0, namecapacity, day); dataset.addValue(seconds / 3600, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = org.compiere.util.TimeUtil.addDays(date, 1); break; } } } return dataset; }
From source file:ru.apertum.qsystem.client.forms.FAdmin.java
private void buttonExportToCSVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExportToCSVActionPerformed final JFileChooser fc = new JFileChooser(); fc.setDialogTitle(getLocaleMessage("save.statictic")); fc.setFileFilter(new FileFilter() { @Override// w w w. ja v a 2 s .co m public boolean accept(File f) { return !f.isFile() || f.getAbsolutePath().toLowerCase().endsWith(".csv"); } @Override public String getDescription() { return getLocaleMessage("files.type.csv"); } }); //fc.setCurrentDirectory(new File("config")); //fc.setSelectedFile(new File(configuration.getSystemName())); fc.setDialogType(JFileChooser.SAVE_DIALOG); if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { final File file; //This is where a real application would open the file. if (!fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".csv")) { file = new File(fc.getSelectedFile().getAbsoluteFile() + ".csv"); } else { file = fc.getSelectedFile(); } Spring.getInstance().getHt().getSessionFactory().openSession().doWork((Connection connection) -> { final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dateChooserStartCsv.getDate()); gc.set(GregorianCalendar.HOUR_OF_DAY, 0); gc.set(GregorianCalendar.MINUTE, 0); gc.set(GregorianCalendar.SECOND, 0); gc.set(GregorianCalendar.MILLISECOND, 0); final String std = Uses.format_for_rep.format(gc.getTime()); gc.setTime(dateChooserFinishCsv.getDate()); gc.set(GregorianCalendar.HOUR_OF_DAY, 0); gc.set(GregorianCalendar.MINUTE, 0); gc.set(GregorianCalendar.SECOND, 0); gc.set(GregorianCalendar.MILLISECOND, 0); gc.add(GregorianCalendar.HOUR, 24); final String find = Uses.format_for_rep.format(gc.getTime()); final String sql = " SELECT " + " s.client_id as id, " + " concat(c.service_prefix , c.number) as num, " + " c.input_data as inp, " + " DATE_FORMAT(s.client_stand_time, '%d.%m.%y %H:%i') as stnd, " + " sv.name as srv, " + " DATE_FORMAT(s.user_start_time, '%d.%m.%y %H:%i') as strt, " + " DATE_FORMAT(s.user_finish_time, '%d.%m.%y %H:%i') as fin, " + " u.name as usr, " + " s.client_wait_period as wt, " + " s.user_work_period as wrk, " + " IFNULL(r.name, '') as res " + " FROM statistic s left join results r on s.results_id=r.id, clients c, users u, services sv " + " WHERE s.client_id=c.id and s.user_id=u.id and s.service_id=sv.id " + " and s.client_stand_time>='" + std + "' and s.client_stand_time<='" + find + "'"; try (ResultSet set = connection.createStatement().executeQuery(sql)) { final Writer writer; try { writer = new OutputStreamWriter(new FileOutputStream(file), "cp1251").append(""); writer.append(""); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.number")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.data")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.stand_time")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.service_name")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.start_time")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.finish_time")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.user")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.wait")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.work")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.result")); writer.append('\n'); while (set.next()) { writer.append(set.getString("id")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("num")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("inp")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("stnd")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append( set.getString("srv").replace(cbSeparateCSV.getSelectedItem().toString(), " ")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("strt")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("fin")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("usr")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("wt")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("wrk")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("res")); writer.append('\n'); } //generate whatever data you want writer.flush(); writer.close(); } catch (IOException ex) { throw new ClientException(ex); } } JOptionPane.showMessageDialog(fc, getLocaleMessage("stat.saved"), getLocaleMessage("stat.saving"), JOptionPane.INFORMATION_MESSAGE); }); } }
From source file:org.eevolution.form.VSCRP.java
public CategoryDataset createWeightDataset(Timestamp start, MResource r) { GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND);// w w w .j a v a 2s.c om gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); String nameload = Msg.translate(Env.getCtx(), "Load"); String namesummary = Msg.translate(Env.getCtx(), "Summary"); String namepossiblecapacity = "Possible Capacity"; MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); double currentweight = DB.getSQLValue(null, "Select SUM( (mo.qtyordered-mo.qtydelivered)*(Select mp.weight From m_product mp Where mo.m_product_id=mp.m_product_id ) )From mpc_order mo Where ad_client_id=?", r.getAD_Client_ID()); // fjviejo e-evolution machineqty capacidad por el numero de maquinas // double dailyCapacity = DB.getSQLValue(null,"Select dailycapacity From s_resource Where s_resource_id=?",r.getS_Resource_ID()); double dailyCapacity = DB.getSQLValue(null, "Select dailycapacity*MachineQty From s_resource Where s_resource_id=?", r.getS_Resource_ID()); System.out.println("***** Capacidad diaria " + dailyCapacity); // e-evolution end double utilization = DB.getSQLValue(null, "Select percentutillization From s_resource Where s_resource_id=?", r.getS_Resource_ID()); double summary = 0; int day = 0; while (day < 32) { day++; switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: if (t.isOnSunday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.MONDAY: if (t.isOnMonday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.TUESDAY: if (t.isOnTuesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.WEDNESDAY: if (t.isOnWednesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.THURSDAY: if (t.isOnThursday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.FRIDAY: if (t.isOnFriday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.SATURDAY: if (t.isOnSaturday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; } dataset.addValue(currentweight, nameload, new Integer(day)); dataset.addValue(summary, namesummary, new Integer(day)); gc1.add(Calendar.DATE, 1); } return dataset; }
From source file:org.eevolution.form.VCRP.java
public CategoryDataset createWeightDataset(Timestamp start, MResource r) { GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND);/* w ww.ja v a 2 s . co m*/ gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); String nameload = Msg.translate(Env.getCtx(), "Load"); String namesummary = Msg.translate(Env.getCtx(), "Summary"); String namepossiblecapacity = "Possible Capacity"; MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); double currentweight = DB.getSQLValue(null, "Select SUM( (mo.qtyordered-mo.qtydelivered)*(Select mp.weight From m_product mp Where mo.m_product_id=mp.m_product_id ) )From mpc_order mo Where ad_client_id=?", r.getAD_Client_ID()); // fjviejo e-evolution machineqty capacidad por el numero de maquinas // double dailyCapacity = DB.getSQLValue(null,"Select dailycapacity From s_resource Where s_resource_id=?",r.getS_Resource_ID()); double dailyCapacity = DB.getSQLValue(null, "Select dailycapacity*MachineQty From s_resource Where s_resource_id=?", r.getS_Resource_ID()); System.out.println("***** Capacidad diaria " + dailyCapacity); // e-evolution end double utilization = DB.getSQLValue(null, "Select percentutillization From s_resource Where s_resource_id=?", r.getS_Resource_ID()); double summary = 0; int day = 0; /* * Vit4B Modificado para que tome 28 dias y * * */ while (day < 29) { day++; switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: if (t.isOnSunday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.MONDAY: if (t.isOnMonday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.TUESDAY: if (t.isOnTuesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.WEDNESDAY: if (t.isOnWednesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.THURSDAY: if (t.isOnThursday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.FRIDAY: if (t.isOnFriday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.SATURDAY: if (t.isOnSaturday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; } dataset.addValue(currentweight, nameload, new Integer(day)); dataset.addValue(summary, namesummary, new Integer(day)); gc1.add(Calendar.DATE, 1); } return dataset; }
From source file:v800_trainer.JCicloTronic.java
private void Datenliste_ZeitabschnittActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Datenliste_ZeitabschnittActionPerformed // Add your handling code here: if (Update == false) { return;// ww w . jav a 2 s . co m } int Tag, Monat, Jahr; int i, Zeitdifferenz = 0; String dummy; java.util.GregorianCalendar Kalendera; java.util.GregorianCalendar Kalenderb; SelectionChanged = true; Update = false; Datenliste_Monat.setEnabled(false); if (Datenliste_Monat.getItemCount() != 0) Datenliste_Monat.setSelectedIndex(0); if (Datenliste_Jahr.getItemCount() != 0) Datenliste_Jahr.setSelectedIndex(0); Update = true; Datentabelle.clearSelection(); if (Datenliste_Zeitabschnitt.getSelectedIndex() == 0) { // jTable1.addRowSelectionInterval(0,0); return; } if (Datenliste_Zeitabschnitt.getSelectedIndex() == 1) { Zeitdifferenz = 8; } if (Datenliste_Zeitabschnitt.getSelectedIndex() == 2) { Zeitdifferenz = 31; } if (Datenliste_Zeitabschnitt.getSelectedIndex() == 3) { Zeitdifferenz = 366; } if (Datenliste_Zeitabschnitt.getSelectedIndex() == 4) { Zeitdifferenz = -1; } Kalendera = (java.util.GregorianCalendar) java.util.GregorianCalendar.getInstance(); Kalenderb = (java.util.GregorianCalendar) java.util.GregorianCalendar.getInstance(); if (Zeitdifferenz != -1) { Kalendera.add(Calendar.DATE, -Zeitdifferenz); } for (i = 0; i < Datentabelle.getRowCount(); i++) { dummy = (String) (Datentabelle.getValueAt(i, 0)); Jahr = Integer.parseInt(dummy.substring(8)); Monat = Integer.parseInt(dummy.substring(5, 7)); Tag = Integer.parseInt(dummy.substring(2, 4)); Kalenderb.set(Jahr, Monat - 1, Tag - 1); if ((Kalendera.before(Kalenderb) || Zeitdifferenz == -1) & (Datenliste_TourTyp.getSelectedItem().toString().equals(sorter.getValueAt(i, 6).toString()) || Datenliste_TourTyp.getSelectedIndex() == 0)) { Datentabelle.addRowSelectionInterval(i, i); } jLabel69_Selektiert.setText(Datentabelle.getSelectedRowCount() + " / " + Datentabelle.getRowCount()); } }
From source file:org.sakaiproject.calendar.impl.BaseCalendarService.java
/** * Generates a list of time ranges for a week. Each range in the list is a day. * /*w ww. j av a 2s .co m*/ * @param timeRange start & end date range * @param calendarReferenceList list of calendar(s) * @param dailyTimeRange start and end hour/minute time range */ protected ArrayList getTimeRangeListForWeek(TimeRange timeRange, List calendarReferenceList, TimeRange dailyTimeRange) { TimeBreakdown startBreakdown = timeRange.firstTime().breakdownLocal(); GregorianCalendar startCalendarDate = (GregorianCalendar) GregorianCalendar .getInstance(m_timeService.getLocalTimeZone(), rb.getLocale()); startCalendarDate.set(startBreakdown.getYear(), startBreakdown.getMonth() - 1, startBreakdown.getDay(), 0, 0, 0); ArrayList weekDayTimeRanges = new ArrayList(); TimeBreakdown startBreakDown = dailyTimeRange.firstTime().breakdownLocal(); TimeBreakdown endBreakDown = dailyTimeRange.lastTime().breakdownLocal(); // Search all seven weekdays // Note: no assumption can be made regarding the first day being Sunday, // since in some locales, the first weekday is Monday. for (int i = 0; i <= 6; i++) { // // Use the same start/end times for all days. // Time curStartTime = m_timeService.newTimeLocal(startCalendarDate.get(GregorianCalendar.YEAR), startCalendarDate.get(GregorianCalendar.MONTH) + 1, startCalendarDate.get(GregorianCalendar.DAY_OF_MONTH), startBreakDown.getHour(), startBreakDown.getMin(), startBreakDown.getSec(), startBreakDown.getMs()); Time curEndTime = m_timeService.newTimeLocal(startCalendarDate.get(GregorianCalendar.YEAR), startCalendarDate.get(GregorianCalendar.MONTH) + 1, startCalendarDate.get(GregorianCalendar.DAY_OF_MONTH), endBreakDown.getHour(), endBreakDown.getMin(), endBreakDown.getSec(), endBreakDown.getMs()); TimeRange newTimeRange = m_timeService.newTimeRange(curStartTime, curEndTime, true, false); weekDayTimeRanges.add(newTimeRange); // Move to the next day. startCalendarDate.add(GregorianCalendar.DATE, 1); } return weekDayTimeRanges; }
From source file:gov.noaa.pfel.coastwatch.Projects.java
/** * Generate ncml which assigns "days since 1970-01-01" coordValue to a file for a range of times. * E.g., <netcdf location="V2013074.L3m_DAY_NPP_CHL_chlor_a_4km" coordValue="15779"/> * The string is displayed and put on the clipboard. * //ww w . jav a 2 s .c om * @param location with '*' where YYYYDDD goes. * @param startIso * @param stopIso (inclusive) * @param increment e.g., 1, 7, or 3 * @param field e.g. Calendar2.DAY_OF_YEAR, Calendar2.MONTH * @return ncml which assigns "days since 1970-01-01" coordValue to a file for a range of times. */ public static String makeNcmlCoordValues(String location, String startIso, String stopIso, int increment, int field) throws Exception { StringBuilder sb = new StringBuilder(); double baseFactor[] = Calendar2.getTimeBaseAndFactor("days since 1970-01-01"); GregorianCalendar gc = Calendar2.parseISODateTimeZulu(startIso); GregorianCalendar stopGc = Calendar2.parseISODateTimeZulu(stopIso); long stopMillis = stopGc.getTimeInMillis(); while (gc.getTimeInMillis() <= stopMillis) { int daysSince = Math2.roundToInt(Calendar2.epochSecondsToUnitsSince(baseFactor[0], baseFactor[1], Calendar2.gcToEpochSeconds(gc))); sb.append("<netcdf location=\"" + String2.replaceAll(location, "*", Calendar2.formatAsYYYYDDD(gc)) + "\" coordValue=\"" + daysSince + "\"/>\n"); gc.add(field, increment); } String s = sb.toString(); String2.setClipboardString(s); String2.log(s); return s; }