예제 #1
0
 public void model_admin() {
   if (ajf != null) {
     ajf.dispose();
   }
   if (jf != null) {
     jf.dispose();
   }
   ajf = new AdminRunningFrame(this);
   ajf.startPage();
   if (DBfile.exists()) {
     try {
       cust = returnSavedData("p2.dat");
       if (cust.isEmpty()) {
         ajf.errorMessage("There are no customers in this database.");
       }
     } catch (ClassNotFoundException | IOException e) {
       e.printStackTrace();
     }
   }
   if (logFile.exists()) {
     try {
       adminLogs = returnLog("p2.log");
       if (adminLogs.isEmpty()) {
         ajf.errorMessage("No entries have been found!");
       }
     } catch (ClassNotFoundException | IOException e) {
       e.printStackTrace();
     }
   }
 }
예제 #2
0
  public void printTimeStamp() {
    ajf.dispose();
    ajf = new AdminRunningFrame(this);

    StringBuilder stringResults = new StringBuilder();
    // creates a new header
    String Tim = "[Time Stamp]";
    String transID = "[Transaction ID]";
    String CusID = "[ID #]";
    String CusAcct = "[Account #]";
    String transAmount = "[Amount]";
    String header =
        String.format("%-30s %-20s %-10s %10s %10s\n", Tim, transID, CusID, CusAcct, transAmount);
    stringResults.append(header);

    if (cust.isEmpty()) {
      ajf.errorMessage("There are no customers in this database.");
    }

    if (adminLogs.isEmpty()) {

      ajf.errorMessage("No entries have been found!");
    } else {
      Collections.sort(adminLogs, AdminLog.CompareTimeStamp);
      for (AdminLog a : adminLogs) {
        long timestamp = a.getTimestamp();
        String date = dateFormat.format(timestamp);
        int transactionID = a.getTransactionID();
        String customerID = a.getCustomerID();
        String accountID = a.getAccountNum();
        double amount = a.getAmount();
        String newLine =
            String.format(
                "%-30s %-20d %-10s %10s %10s\n",
                date, transactionID, customerID, accountID, amount);
        stringResults.append(newLine);
      }
      String resultsAsString = stringResults.toString();
      ajf.printInfo(resultsAsString);
    }
  }