public void writeToFile(String invID, String carNumber, String carModel, String packName) {
    String separator = System.getProperty("line.separator");
    // variable declarations for storing the data from the database.
    String bookedBy = new String();
    String usedBy = new String();
    String branch = new String();
    int dd = 0, mm = 0, yyyy = 0, usedKms = 0, usedHours = 0, packKms = 0, packHours = 0;
    Double eKmsCharge = 0.0;
    Double eHoursCharge = 0.0;
    Double osaDays = 0.0;
    Double osaNights = 0.0;
    Double parking = 0.0;
    Double others = 0.0;
    Double subTotalA = 0.0;
    Double subTotalB = 0.0;
    Double serviceTax = 0.0;
    Double bookingAmount = 0.0;
    Double finalAmount = 0.0;

    String compName = new String();
    String compAddr = new String();
    String compPAN = new String();
    String compDD = new String();

    try {
      Connection con = db.createConnection();
      Connection con2 = db.createConnection();
      String retrieveStatement = "select * from invoices where invoiceno=?";
      String retrieveCompanyInfo = "select * from company";
      PreparedStatement ps = con.prepareStatement(retrieveStatement);
      Statement st = con2.createStatement();
      ps.setString(1, invID);
      ResultSet rs = ps.executeQuery();
      ResultSet rs2 = st.executeQuery(retrieveCompanyInfo);
      while (rs.next()) {
        bookedBy = rs.getString(2);
        usedBy = rs.getString(3);
        branch = rs.getString(4);
        dd = rs.getInt(5);
        mm = rs.getInt(6);
        yyyy = rs.getInt(7);
        usedKms = rs.getInt(8);
        usedHours = rs.getInt(9);
        packKms = rs.getInt(10);
        packHours = rs.getInt(11);
        eKmsCharge = rs.getDouble(13);
        eHoursCharge = rs.getDouble(14);
        osaDays = rs.getDouble(15);
        osaNights = rs.getDouble(16);
        parking = rs.getDouble(17);
        others = rs.getDouble(18);
        subTotalA = rs.getDouble(19);
        subTotalB = rs.getDouble(20);
        serviceTax = rs.getDouble(21);
        bookingAmount = rs.getDouble(22);
        finalAmount = rs.getDouble(23);
      }
      while (rs2.next()) {
        compName = rs2.getString(1);
        compAddr = rs2.getString(2);
        compPAN = rs2.getString(3);
        compDD = rs2.getString(4);
      }

      File file = new File("temp.txt");
      Writer writer = new BufferedWriter(new FileWriter(file));
      writer.write(separator + " Invoice ID: " + invID);
      writer.write(separator + " Company Name: " + compName);
      writer.write(
          separator
              + " Used By:   "
              + usedBy
              + separator
              + " Booked By: "
              + bookedBy
              + "                        Branch Requested: "
              + branch);
      writer.write(
          separator
              + "------------------------------------------------------------------------------------------------------------------");
      writer.write(separator + " Car No.: " + carNumber + "\t\tCar Alotted: " + carModel);
      writer.write(separator + " Package: " + packName);
      writer.write(
          separator
              + " Kms Used: "
              + usedKms
              + "                Extra Kms: "
              + (usedKms - packKms)
              + "             Extra Kms Charge(@10% extra rate): "
              + eKmsCharge);
      writer.write(
          separator
              + " Hours Used: "
              + usedHours
              + "                Extra Hours: "
              + (usedHours - packHours)
              + "          Extra Hours Charge(@Rs.50/hr): "
              + eHoursCharge);
      writer.write(
          separator
              + " Car Used On: "
              + dd
              + "-"
              + mm
              + "-"
              + yyyy
              + "                                                                    Sub Total (A): "
              + subTotalA);
      writer.write(
          separator
              + "------------------------------------------------------------------------------------------------------------------");
      writer.write(
          separator
              + " Parking & Toll: "
              + parking
              + "                                                    Others: "
              + others);
      writer.write(
          separator
              + " Out Station Allowance (in Rs.) for \t Days: "
              + osaDays
              + "                Nights: "
              + osaNights);
      writer.write(
          separator
              + "                                                                                                                      Sub Total (B): "
              + subTotalB);
      writer.write(
          separator
              + "------------------------------------------------------------------------------------------------------------------");
      writer.write(
          separator
              + "                                                                                                                      Total (A+B): "
              + (subTotalA + subTotalB));
      writer.write(
          separator
              + separator
              + " PAN: "
              + compPAN
              + "                                                                                 Service Tax: "
              + serviceTax);
      writer.write(separator + " Service Tax Category: Rent-a-Cab\t\tTotal: " + finalAmount);
      writer.write(
          separator
              + " All Cheques/Drafts to be drawn in favor of\t\tBooking Amount: "
              + bookingAmount
              + separator
              + " "
              + compDD
              + "\t\tNet Payable: "
              + (finalAmount - bookingAmount));
      writer.write(separator + separator + " Billing Address" + separator + " " + compAddr);

      writer.flush();
      con.close();
      con2.close();
      Invoice i = new Invoice();
      i.setVisible(true);

    } catch (Exception ee) {
      ee.printStackTrace();
    }
  }
示例#2
0
  public synchronized void antColonyRequestProcesor(Request request) {

    int cloud1_avilabiltiy = 3;
    int cloud2_avilability = 4;
    int cloud3_availability = 5;

    String location = null;

    Image[] resources = null;

    DatabaseConnection db = new DatabaseConnection();
    User user = db.getUser(1);

    if (cloud1_avilabiltiy > cloud2_avilability && cloud1_avilabiltiy > cloud3_availability) {
      resources = db.getImagesFromCloud1();
      location = "Oregon";
    }

    if (cloud2_avilability > cloud1_avilabiltiy && cloud2_avilability > cloud3_availability) {
      resources = db.getImagesFromCloud2();
      location = "N.Virginia";
    }

    if (cloud3_availability > cloud1_avilabiltiy && cloud3_availability > cloud2_avilability) {
      resources = db.getImagesFromCloud3();
      location = "N.California";
    }

    if (cloud1_avilabiltiy == cloud2_avilability && cloud1_avilabiltiy == cloud3_availability) {
      if (user.getDistancefromCloud1() < user.getDistancefromCloud2()
          && user.getDistancefromCloud1() < user.getDistancefromCloud3()) {

        resources = db.getImagesFromCloud1();
        location = "Oregon";
        System.out.println("Cloud 1");
      }

      if (user.getDistancefromCloud2() < user.getDistancefromCloud1()
          && user.getDistancefromCloud2() < user.getDistancefromCloud3()) {

        resources = db.getImagesFromCloud2();
        location = "N.Virginia";
        System.out.println("Cloud 2");
      }

      if (user.getDistancefromCloud3() < user.getDistancefromCloud2()
          && user.getDistancefromCloud3() < user.getDistancefromCloud1()) {

        resources = db.getImagesFromCloud3();
        location = "N.California";
        System.out.println("Cloud 3");
      }
    }

    if (cloud1_avilabiltiy == cloud2_avilability) {
      if (user.getDistancefromCloud1() < user.getDistancefromCloud2()) {

        resources = db.getImagesFromCloud1();
        location = "Oregon";
        System.out.println("Cloud 1");

      } else {
        resources = db.getImagesFromCloud2();
        location = "N.Virginia";
        System.out.println("Cloud 2");
      }
    }

    if (cloud1_avilabiltiy == cloud3_availability) {
      if (user.getDistancefromCloud1() < user.getDistancefromCloud3()) {

        resources = db.getImagesFromCloud1();
        location = "Oregon";
        System.out.println("Cloud 1");

      } else {
        resources = db.getImagesFromCloud3();
        location = "N.California";
        System.out.println("Cloud 3");
      }
    }

    if (cloud2_avilability == cloud3_availability) {

      if (user.getDistancefromCloud2() < user.getDistancefromCloud3()) {

        resources = db.getImagesFromCloud2();
        location = "N.Virginia";
        System.out.println("Cloud 2");

      } else {
        resources = db.getImagesFromCloud3();
        location = "N.California";
        System.out.println("Cloud 3");
      }
    }

    String selectedImageId = null;

    while ((request.isAllocated() == false)) {

      for (int i = 0; i < resources.length; i++) {
        System.out.println("length:;" + resources.length);
        String resourceImageName = resources[i].getImageName();
        System.out.println("resourceImageName:" + resourceImageName);
        System.out.println("request.getOs():" + request.getOs());

        if (resourceImageName.equals(request.getOs())) {
          selectedImageId = resources[i].getImageId();

          // Set the request allocated to true
          request.setAllocated(true);
        }
        if (request.isAllocated() == true) {
          System.out.println("Request ID: " + request.getRequestId() + " is Allocated");
          break;
        }
      }
      // break;
    }

    AddInstances a = new AddInstances();
    try {
      a.addInstances(
          selectedImageId,
          location,
          request.getImageType(),
          request.getVolume(),
          request.getDuration(),
          request.getRequestId());
    } catch (InterruptedException e) {

      e.printStackTrace();
    }

    System.out.println("ImageId::::;" + selectedImageId);
  }