예제 #1
0
  private void calculateManHours() {
    try {
      int indexSelected = display.getEstWeeksListBox().getSelectedIndex();

      // if user hasn't yet touched the listbox
      // we set first item as selected by default
      if (indexSelected == -1) display.getEstWeeksListBox().setSelectedIndex(0);

      int weeks = Integer.parseInt(display.getEstWeeksListBox().getItemText(indexSelected));

      int listSize = /*((SkillsResources)*/
          display
              .getSkillsResourceContainer()
              .getWidgetCount(); // 0)).getSkillsList().getItemCount();

      int totalResources = 0;

      for (int i = 0; i < listSize; ++i)
        totalResources +=
            Integer.parseInt(
                ((SkillsResources) display.getSkillsResourceContainer().getWidget(i))
                    .getNoOfResources()
                    .getText());

      // Field Work Man Hours = NoOfResources * EstimatedWeeks*40

      display.getFieldWorkManHours().setText(String.valueOf(weeks * 40 * totalResources));

    } catch (Exception e) {
      display.getMgmtHours().setText("");
      display.getTotalWorkingManHours().setText("");
      display.getTotalWorkingManHours().setText("Please enter a correct value");
    }
  }
예제 #2
0
  private void calculateHoursInclTravel() {

    try {
      int mgmtHours = Integer.parseInt(display.getMgmtHours().getText().toString());

      int workManHours = Integer.parseInt(display.getFieldWorkManHours().getText().toString());

      //		Total Working Man Hours = Field Work Man Hours + mgmt hrs
      display.getTotalWorkingManHours().setText(String.valueOf((mgmtHours + workManHours)));

      int travelDays =
          Integer.parseInt(
              display
                  .getTravelingDaysListBox()
                  .getItemText(display.getTravelingDaysListBox().getSelectedIndex()));

      // Hours inclusive of travel = Total working man hours + travelling days*8

      display
          .getHoursInclusiveOfTravel()
          .setText(String.valueOf(mgmtHours + workManHours + travelDays * 8));
    } catch (Exception e) {
      Window.alert("Please enter only numbers in numeric fields");
    }
  }
예제 #3
0
  private void bind() {
    // if a record is foung in db- then I create widgets acc to db record
    // set the values of form fields accordingly

    rpcService.fetchJobTime(
        display.getStrategicDTO().getStrategicId(),
        new AsyncCallback<JobTimeEstimationDTO>() {

          @Override
          public void onSuccess(JobTimeEstimationDTO result) {

            //
            //	display.getEstimatedWeeks().setText(String.valueOf(result.getJobTimeEstimation().getEstimatedWeeks()));

            if (result != null) {
              // Window.alert("not null");

              display.setJobEstimationId(result.getJobTimeEstimation().getJobTimeEstimationId());

              for (int i = 0; i < display.getEstWeeksListBox().getItemCount(); i++) {
                if (display
                    .getEstWeeksListBox()
                    .getItemText(i)
                    .equals(String.valueOf(result.getJobTimeEstimation().getEstimatedWeeks()))) {
                  display.getEstWeeksListBox().setSelectedIndex(i);
                  break;
                }
              }

              display
                  .getJobTimeEstId()
                  .setText(String.valueOf(result.getJobTimeEstimation().getJobTimeEstimationId()));

              display
                  .getEstWeeksListBox()
                  .addItem(String.valueOf(result.getJobTimeEstimation().getEstimatedWeeks()));

              // display.getFieldWorkManHours().setText(
              // String.valueOf(result.getJobTimeEstimation().getManagementHours() ));

              display
                  .getTotalWorkingManHours()
                  .setText(String.valueOf(result.getJobTimeEstimation().getHoursInclTravel()));

              display
                  .getFieldWorkManHours()
                  .setText(String.valueOf(result.getJobTimeEstimation().getFieldWorkManHours()));

              display
                  .getMgmtHours()
                  .setText(String.valueOf(result.getJobTimeEstimation().getManagementHours()));

              display
                  .getHoursInclusiveOfTravel()
                  .setText(String.valueOf(result.getJobTimeEstimation().getHoursInclTravel()));

              for (int i = 0; i < display.getPlaceofWorkListBox().getItemCount(); i++) {
                if (display
                    .getPlaceofWorkListBox()
                    .getItemText(i)
                    .equals(String.valueOf(result.getJobTimeEstimation().getTravelDays()))) {
                  display.getPlaceofWorkListBox().setSelectedIndex(i);
                  break;
                }
              }

              // display.getPlaceofWorkListBox().addItem(
              // result.getJobTimeEstimation().getPlaceOfWork());

              display
                  .getHighLevelScopeOfWork()
                  .setText(result.getJobTimeEstimation().getScopeOfWork());

              for (int i = 0; i < display.getTravelingDaysListBox().getItemCount(); i++) {
                if (display
                    .getTravelingDaysListBox()
                    .getItemText(i)
                    .equals(String.valueOf(result.getJobTimeEstimation().getTravelDays())))
                  display.getTravelingDaysListBox().setSelectedIndex(i);
              }

              display
                  .getTotalWorkingManHoursTextBox()
                  .setText(String.valueOf(result.getJobTimeEstimation().getTotalWorkingManHours()));
              display.getSkillsResourceContainer().clear();

              fetchSkillResources(result.getResourceUse(), true);
            }
          }

          @Override
          public void onFailure(Throwable caught) {
            System.out.println("fail");
          }
        });

    display
        .getBackButton()
        .addClickHandler(
            new ClickHandler() {

              @Override
              public void onClick(ClickEvent event) {
                // TODO Auto-generated method stub
                History.newItem("auditScheduling");
              }
            });
    display.getHeading().setText(display.getStrategicDTO().getStrategicObjective());

    display.getFieldWorkManHours().setText("0");

    display
        .getSaveJobTimeEst()
        .addClickHandler(
            new ClickHandler() {

              @Override
              public void onClick(ClickEvent event) {

                // store the current state of form in DTO

                JobTimeEstimation jobTimeEstEntity = new JobTimeEstimation();
                ArrayList<ResourceUse> resourceAndNo = new ArrayList<ResourceUse>();
                ArrayList<SkillUpdateData> updateForSkills = new ArrayList<SkillUpdateData>();

                try {

                  jobTimeEstEntity.setJobTimeEstimationId(
                      Integer.parseInt(display.getJobTimeEstId().getText()));

                  jobTimeEstEntity.setJobId(display.getStrategicDTO().getStrategicId());

                  jobTimeEstEntity.setEstimatedWeeks(
                      Integer.parseInt(
                          display
                              .getEstWeeksListBox()
                              .getItemText(display.getEstWeeksListBox().getSelectedIndex())));

                  jobTimeEstEntity.setFieldWorkManHours(
                      Integer.parseInt(display.getFieldWorkManHours().getText().toString()));

                  jobTimeEstEntity.setTotalWorkingManHours(
                      Integer.parseInt(display.getTotalWorkingManHours().getText().toString()));

                  jobTimeEstEntity.setManagementHours(
                      Integer.parseInt(display.getMgmtHours().getText().toString()));

                  jobTimeEstEntity.setHoursInclTravel(
                      Integer.parseInt(display.getHoursInclusiveOfTravel().getText().toString()));

                  jobTimeEstEntity.setPlaceOfWork(
                      display
                          .getPlaceofWorkListBox()
                          .getItemText(display.getPlaceofWorkListBox().getSelectedIndex()));

                  jobTimeEstEntity.setScopeOfWork(
                      display.getHighLevelScopeOfWork().getText().toString());

                  jobTimeEstEntity.setTravelDays(
                      Integer.parseInt(
                          display
                              .getTravelingDaysListBox()
                              .getItemText(display.getTravelingDaysListBox().getSelectedIndex())));

                  jobTimeEstEntity.setHoursInclTravel(
                      jobTimeEstEntity.getTotalWorkingManHours()
                          + jobTimeEstEntity.getTravelDays() * 8);

                  // since the size of listbox is dynamic, we need to get it at the runtime
                  // 0th widget of the VerticalPanel is always a 'SkillResource'
                  // we cast it to the Type and get skilllist size
                  int listSize = /*((SkillsResources)*/
                      display
                          .getSkillsResourceContainer()
                          .getWidgetCount(); // (0)).getSkillsList().getItemCount();

                  boolean maxHoursReached = false;

                  // loop through all the list boxes and get the selected index and value / text
                  for (int i = 0; i < listSize; i++) {
                    // ith widget of Vpanel is always a 'SkillResource'
                    SkillsResources res =
                        ((SkillsResources) display.getSkillsResourceContainer().getWidget(i));

                    ResourceUse r = new ResourceUse();

                    int hoursReqd =
                        Integer.parseInt(res.getNoOfResources().getText().toString())
                            * 40
                            * jobTimeEstEntity.getEstimatedWeeks();

                    if (hoursReqd > res.getAvailableHours()) {
                      maxHoursReached = false;

                      System.out.println(
                          "You have selected more hours than available hours for "
                              + res.getSkillsList()
                                  .getItemText(res.getSkillsList().getSelectedIndex()));

                      // return;

                    }
                    // get id of skill

                    SkillUpdateData updatedInfoForSkill = new SkillUpdateData();

                    updatedInfoForSkill.setSkillId(
                        Integer.parseInt(res.getSkillsList().getValue(0)));
                    updatedInfoForSkill.setHoursToSubt(hoursReqd);

                    updateForSkills.add(updatedInfoForSkill);

                    // get spent hour

                    // update db

                    r.setNoOfResources(
                        Integer.parseInt(res.getNoOfResources().getText().toString()));

                    int index = res.getSkillsList().getSelectedIndex();

                    // how to set this ? ..
                    Skills skills = new Skills();
                    skills.setSkillId(Integer.parseInt(res.getSkillsList().getValue(index)));
                    r.setSkillId(skills);

                    resourceAndNo.add(r);
                  }

                } catch (NumberFormatException e) {

                  Window.alert("Please enter a number, characters are not allowed");
                  return;
                }

                JobTimeEstimationDTO dto = new JobTimeEstimationDTO();

                dto.setJobTimeEstimation(jobTimeEstEntity);
                dto.setResourceUse(resourceAndNo);

                rpcService.saveJobTimeEstimation(
                    dto,
                    updateForSkills,
                    new AsyncCallback<Boolean>() {

                      @Override
                      public void onSuccess(Boolean savedSuccess) {

                        if (savedSuccess) {
                          new DisplayAlert("Job Estimation Saved");
                          History.newItem("auditScheduling");
                        } else Window.alert("There are not enough number of Resources available");
                      }

                      @Override
                      public void onFailure(Throwable caught) {}
                    });

                // History.newItem("jobCreation");

              }
            });

    display
        .getEstWeeksListBox()
        .addChangeHandler(
            new ChangeHandler() {

              @Override
              public void onChange(ChangeEvent event) {
                calculateManHours();
              }
            });

    display
        .getPlaceofWorkListBox()
        .addChangeHandler(
            new ChangeHandler() {

              @Override
              public void onChange(ChangeEvent event) {

                int index = display.getPlaceofWorkListBox().getSelectedIndex();

                String place = display.getPlaceofWorkListBox().getItemText(index);

                if (place.equals("Outstation")) {
                  display.getTravelingDaysListBox().setEnabled(true);
                  display.getTravelingDaysListBox().setSelectedIndex(0);
                }

                if (place.equals("Inhouse")) {
                  // as we have inhouse work, we dont need to go wandering
                  display.getTravelingDaysListBox().setEnabled(false);

                  // if the user previously selected outstation, this will recalculate the traveling
                  // hours and
                  // hours incl travel

                  int hoursToSubt =
                      Integer.parseInt(
                          display
                              .getTravelingDaysListBox()
                              .getItemText(display.getTravelingDaysListBox().getSelectedIndex()));

                  int currentHoursForTravel =
                      Integer.parseInt(display.getHoursInclusiveOfTravel().getText());

                  display
                      .getHoursInclusiveOfTravel()
                      .setText(String.valueOf(currentHoursForTravel - hoursToSubt * 8));

                  display.getTravelingDaysListBox().setSelectedIndex(0);
                }
              }
            });

    display
        .getMgmtHours()
        .addKeyUpHandler(
            new KeyUpHandler() { // for later

              @Override
              public void onKeyUp(KeyUpEvent event) {
                try {
                  calculateHoursInclTravel();

                } catch (Exception e) {
                  display.getMgmtHours().setText("");
                  display.getTotalWorkingManHours().setText("");
                  display.getTotalWorkingManHours().setText("Please enter a correct value");
                  event.preventDefault();
                }
              }
            });

    display
        .getTravelingDaysListBox()
        .addChangeHandler(
            new ChangeHandler() {

              @Override
              public void onChange(ChangeEvent event) {
                calculateHoursInclTravel();
              }
            });

    // this.

    // if ( ! display.isListCreated() )
    // {

    fetchSkillResources(null, false);
  }