Package nu.lazy8.util.gen

Examples of nu.lazy8.util.gen.WorkingDialog


          -1, true);
      jTextArea.append(sbRow.toString());
      jTextArea.append(newline);
      double fDebitTotal = 0;
      double fCreditTotal = 0;
      IntHolder iType = new IntHolder();
      do {
        initializeRow(fieldAccSize, 8);

        addField(db.getObject("Amount.Account", iType),
            fieldAccSize, 2, iType.iValue, false);
View Full Code Here


        }//}}}
      };
    fileDialog.setFileFilter(filter);
    if (fileDialog.showOpenDialog(view) == JFileChooser.APPROVE_OPTION) {
      if (fileDialog.getSelectedFile().exists()) {
        WorkingDialog workDialog = new WorkingDialog(view);
        workDialog.setVisible(true);
        workDialog.SetProgress(0);
        try {
          ReadInFile(fileDialog.getSelectedFile());
          workDialog.dispose();
          //final adjustments
          JOptionPane.showMessageDialog(null,
              Translator.getTranslation("Successful"),
              "",
              JOptionPane.PLAIN_MESSAGE);
        } catch (Exception e) {
          e.printStackTrace();
          workDialog.dispose();
          JOptionPane.showMessageDialog(null,
              Translator.getTranslation("Failed to import") + " : " + e,
              "",
              JOptionPane.PLAIN_MESSAGE);
        }
View Full Code Here

            return;
          }
        } else if (JOptionPane.CANCEL_OPTION == changeReply) {
          return;
        }
        WorkingDialog workDialog = new WorkingDialog(view);
        workDialog.setVisible(true);
        workDialog.SetProgress(0);
        try {
          ReadInFile(fileDialog.getSelectedFile(), workDialog);
          workDialog.dispose();
          //final adjustments
          //version 2.20, fix the PeriodId field in Activity2
          lazy8ledger.Lazy8LedgerPlugin.AdjustAllPeriodIds(globalCompId);
          if (!foundAccountType) {
            new Upgrade20Dialogs(view, true, false, "", globalCompId);
          }
          JOptionPane.showMessageDialog(null,
              Translator.getTranslation("Successful"),
              "",
              JOptionPane.PLAIN_MESSAGE);
        } catch (Exception e) {
          e.printStackTrace();
          workDialog.dispose();
          if (globalCompId != 0 && iCompanyToResoreTo == 0) {
            DeleteCompany.RemoveCompanyFromDatabase(globalCompId, view, iCompanyToResoreTo == 0);
          }
          JOptionPane.showMessageDialog(null,
              Translator.getTranslation("Failed to import") + " : " + e,
View Full Code Here

    } catch (Exception ee) {
      //all is well, the file does not exist
    }
    //now lets open the file for output

    WorkingDialog workDialog = new WorkingDialog(null);
    //open a gzipped file stream
    try {
      DataOutputStream doOut;
      OutputStream out = new FileOutputStream(fileDialog.getSelectedFile());
      GZIPOutputStream gzipout = new GZIPOutputStream(out);
      OutputStream out2 = gzipout;
      if (SetupInfo.getBoolProperty(SetupInfo.REQUIRE_BACKUP_PASSWORD)) {
        out2 = createEncryptedOutputStream(gzipout);
      }
      doOut = new DataOutputStream(out2);
      //save version
      if (!bBackupOneCompanyOnly) {
        doOut.writeUTF(filedescriptor);
      } else {
        doOut.writeUTF(Companyfiledescriptor);
      }
      doOut.writeDouble(dVersionNumber);
      //save number of tables
      doOut.writeInt(sTables.length);
      //save each table
      workDialog.setVisible(true);
      workDialog.SetProgress(0);
      for (int i = 0; i < sTables.length; i++) {
        SaveTable(doOut, sTables[i], bBackupOneCompanyOnly, iCompanyToBackup);
        workDialog.SetProgress((i * 100) / (sTables.length));
      }
      SystemLog.ErrorPrintln("before clossing work dialog");
      workDialog.dispose();
      SystemLog.ErrorPrintln("after clossing work dialog");

      doOut.close();
      SystemLog.ErrorPrintln("after closeing file");

    } catch (Exception e2) {
      e2.printStackTrace();
      workDialog.dispose();
      SystemLog.ErrorPrintln("FAILED trying to backup: " +
          e2.getMessage());
      JOptionPane.showMessageDialog(null,
          Translator.getTranslation("Unable to create file. Error") +
          " : " + e2.getMessage(),
View Full Code Here

    //check if the file exists

    //this loop executes twice, first is just a test that the information
    //seems valid. The second is the real read

    WorkingDialog workDialog = new WorkingDialog(null);
    workDialog.setVisible(true);
    workDialog.SetProgress(0);
    Cipher myCipher = null;
    if (SetupInfo.getBoolProperty(SetupInfo.REQUIRE_BACKUP_PASSWORD)) {
      myCipher = createCipher(Cipher.DECRYPT_MODE);
    }
    for (int iTestFile = 0; iTestFile < 2; iTestFile++) {
      try {
        InputStream in = new FileInputStream(sFile);
        GZIPInputStream gzipin = new GZIPInputStream(in);
        InputStream in2 = gzipin;
        if (SetupInfo.getBoolProperty(SetupInfo.REQUIRE_BACKUP_PASSWORD)) {
          in2 = new CipherInputStream(gzipin, myCipher);
        }
        DataInputStream doIn = new DataInputStream(in2);

        //make sure file and descriptions are right
        String sFileDesc = doIn.readUTF();
        double dVersion = doIn.readDouble();
        if (bRestoreOneCompanyOnly) {
          if (Companyfiledescriptor.compareTo(sFileDesc) != 0
               || dVersion > dVersionNumber || dVersion < dVersionNumber
              ) {
            SystemLog.ErrorPrintln("Not a valid file, descriptor =" +
                sFileDesc + " should equal " + Companyfiledescriptor +
                " and version number " + dVersion + " should equal " + dVersionNumber);
            JOptionPane.showMessageDialog(null,
                Translator.getTranslation("Invalid file name."),
                Translator.getTranslation("Update not entered"),
                JOptionPane.PLAIN_MESSAGE);
            workDialog.dispose();
            return;
          }
        } else
            if (filedescriptor.compareTo(sFileDesc) != 0
             || dVersion > dVersionNumber || dVersion < dVersionNumber
            ) {
          SystemLog.ErrorPrintln("Not a valid file, descriptor =" +
              sFileDesc + " should equal " + filedescriptor +
              " and version number " + dVersion + " should equal " + dVersionNumber);
          JOptionPane.showMessageDialog(null,
              Translator.getTranslation("Invalid file name."),
              Translator.getTranslation("Update not entered"),
              JOptionPane.PLAIN_MESSAGE);
          workDialog.dispose();
          return;
        }

        //get  the number of tables
        int iNumTables = doIn.readInt();
        //call restoretable for each table to save each tables information
        boolean bIsTestOnly = true;
        if (iTestFile == 1) {
          bIsTestOnly = false;
        }
        isBadActivityTable=false;
        for (int i = 0; i < iNumTables; i++) {
          RestoreTable(doIn, bIsTestOnly, bRestoreOneCompanyOnly,
              iCompanyToResoreTo);
          workDialog.SetProgress((iTestFile * iNumTables + i) * 100 / (2 * iNumTables));
        }
        if ( ! bRestoreOneCompanyOnly) restoredCompId=0;
        if (iNumTables == (sTables.length - 1) && !bIsTestOnly) {
          //this is an old import.  We must add the AccountTypes Manually
          DataConnection.AddDefaultAccountTypes(restoredCompId);
        }
        if (isBadActivityTable && !bIsTestOnly) {
          //version 2.20, fix the PeriodId field in Activity2
          lazy8ledger.Lazy8LedgerPlugin.AdjustAllPeriodIds(restoredCompId);
        }
        doIn.close();
        EditBus.send(new CompanyListChanged(null, "no parameters"));
        EditBus.send(new CustomerListChanged(null, "no parameters"));
        EditBus.send(new AccountTypeListChanged(null, "no parameters"));
      } catch (Exception ee) {
        ee.printStackTrace();
        workDialog.dispose();
        //Cannot continue, the file does not exist
        JOptionPane.showMessageDialog(null,
            Translator.getTranslation("Invalid file name.") +
            " : " + ee.getMessage(),
            Translator.getTranslation("Update not entered"),
            JOptionPane.PLAIN_MESSAGE);
        SystemLog.ErrorPrintln("FAILED trying to backup: " +
            ee.getMessage());
        return;
      }
    }
    workDialog.dispose();
  }//}}}
View Full Code Here

   *
   * @param  b              Description of the Parameter
   * @exception  Exception  Description of the Exception
   */
  protected void doExport() {
    WorkingDialog workDialog=null;
    try{
      workDialog = new WorkingDialog(null);
      workDialog.setVisible(true);
      workDialog.SetProgress(0);
     
      BufferedWriter bufOut=new BufferedWriter(new OutputStreamWriter
        (new FileOutputStream(fileDialog.getSelectedFile()), "UTF-8"));     
     
      bufOut.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
      bufOut.newLine();
      bufOut.write("<lazy8webport version=\"1.00\">");
      bufOut.newLine();     
     
      Statement st = dc.con.createStatement();
      String select = "";
      int CompId=0;
      String CompName=(String)(comboBox.getSelectedItem());
      if(CompName.equals("--- " + Translator.getTranslation("All") + " ---")){
        select="SELECT CompId,Name FROM Company";
      }else{
        CompId=((Integer) comboBox.getSelectedItemsKey()).intValue();
        select="SELECT CompId,Name FROM Company WHERE CompId=" + CompId;
      }
      Log.log(Log.DEBUG, this, "doExport CompName =" + CompName);
      ResultSet rsCompany = st.executeQuery(dc.filterSQL(select));
      while(rsCompany.next()) {
        CompId=rsCompany.getInt(1);
        bufOut.write("  <company code=\"" + rsCompany.getInt(1) + "\" name=\"" + XmlEncode(rsCompany.getString(2)) +
          "\" lastAbsTransNum=\"" + (new UniqNumGenerator()).GetUniqueNumber("Act_Id", 1, 999999999, CompId) + "\" >");
        bufOut.newLine();  
        select="SELECT APP.Account.Account, AccDesc,AccTypeId, TypeName, SortOrder, IsInBalanceReport " +
          " FROM AccountType JOIN Account ON AccountType.AccTypeId=APP.Account.IsAsset WHERE " +
          " AccountType.CompId=" + CompId + " AND APP.Account.CompId=" + CompId +
          " ORDER BY AccTypeId,APP.Account.Account";
        Statement st2 = dc.con.createStatement();
        ResultSet rsAccount = st2.executeQuery(dc.filterSQL(select));
        int accountType=-99999;
        while(rsAccount.next()) {
          if (accountType!=rsAccount.getInt(3)){
            if (accountType != -99999){
              bufOut.write("    </accounttype>");
              bufOut.newLine();     
            }
            String isBalance="0";
            if(rsAccount.getInt(6)==1)
              isBalance="1";
            bufOut.write("    <accounttype code=\"" + rsAccount.getInt(3) + "\" name=\"" + XmlEncode(rsAccount.getString(4)) +
              "\" sortorder=\"" + rsAccount.getInt(5) + "\" isinbalance=\"" + isBalance + "\" >");
            bufOut.newLine();  
            accountType=rsAccount.getInt(3);
          }
          bufOut.write("      <account code=\"" + rsAccount.getInt(1) + "\" name=\"" + XmlEncode(rsAccount.getString(2)) + "\" />");
          bufOut.newLine();  
          bufOut.flush();
        }
        if(accountType!=-99999){
          bufOut.write("    </accounttype>");
          bufOut.newLine();     
        }
        select="SELECT CustId, CustName, CustDesc, DefaultAcc FROM Customer2 WHERE CompId=" + CompId;
        Statement st3 = dc.con.createStatement();
        ResultSet rsCustomer = st3.executeQuery(dc.filterSQL(select));
        while(rsCustomer.next()) {
          bufOut.write("    <customer code=\"" + rsCustomer.getInt(1) + "\" name=\"" + XmlEncode(rsCustomer.getString(2)) +
             "\" desc=\"" + XmlEncode(rsCustomer.getString(3))  + "\" accountcode=\"" + rsCustomer.getInt(4) + "\" />");
          bufOut.newLine();  
        }
        bufOut.flush();
        select="SELECT StartPeriod, EndPeriod FROM AccountingPeriods WHERE CompId=" + CompId + " ORDER BY StartPeriod";
        Statement st4 = dc.con.createStatement();
        ResultSet rsPeriod = st4.executeQuery(dc.filterSQL(select));
        while(rsPeriod.next()) {
          select="SELECT MAX(PeriodId) FROM " +
            " Activity2 JOIN APP.Amount on Activity2.Act_id=APP.Amount.Act_id WHERE Activity2.CompId=" + CompId +
            " AND APP.Amount.CompId=" + CompId + " AND InvDate>=DATE '" + rsPeriod.getDate(1) +
            "' AND InvDate<=DATE '" + rsPeriod.getDate(2) + "'";
          Statement st5 = dc.con.createStatement();
          ResultSet rsPeriodMaxPerId = st5.executeQuery(dc.filterSQL(select));
          rsPeriodMaxPerId.next();
          bufOut.write("    <period datestart=\"" + rsPeriod.getDate(1) + "\" dateend=\"" + rsPeriod.getDate(2) +
            "\" lastperiodtransnum=\"" + rsPeriodMaxPerId.getInt(1) + "\">");
          bufOut.newLine();  

          select="SELECT Activity2.Act_id, RegDate, InvDate, Activity2.Notes, FileInfo," +
            " Account, APP.Amount.Amount, IsDebit, Customer, APP.Amount.Notes, PeriodId FROM " +
            " Activity2 JOIN APP.Amount on Activity2.Act_id=APP.Amount.Act_id WHERE Activity2.CompId=" + CompId +
            " AND APP.Amount.CompId=" + CompId + " AND InvDate>=DATE '" + rsPeriod.getDate(1) +
            "' AND InvDate<=DATE '" + rsPeriod.getDate(2) + "' ORDER BY Activity2.Act_id,IsDebit";
          Statement st6 = dc.con.createStatement();
          ResultSet rsTrans = st6.executeQuery(dc.filterSQL(select));
          int actId=-99999;
          while(rsTrans.next()) {
            if (actId!=rsTrans.getInt(1)){
              if (actId != -99999){
                bufOut.write("      </transaction>");
                bufOut.newLine();     
              }
              bufOut.write("      <transaction code=\"" + rsTrans.getInt(1) + "\" regdate=\"" + rsTrans.getDate(2) +
                "\" invdate=\"" + rsTrans.getDate(3) + "\" notes=\"" + XmlEncode(rsTrans.getString(4)) +
                "\" fileinfo=\"" + XmlEncode(rsTrans.getString(5)) + "\" periodnum=\"" + rsTrans.getInt(11) + "\" >");
              bufOut.newLine();  
              actId=rsTrans.getInt(1);
            }
            double amount=rsTrans.getDouble(7);
            if(rsTrans.getInt(8)==0)
              amount= -amount;
           
            bufOut.write("        <amount accountcode=\"" + rsTrans.getInt(6) + "\" customercode=\"" + rsTrans.getInt(9) +
              "\" notes=\"" + XmlEncode(rsTrans.getString(10)) + "\" amount=\"" + amount + "\" />");
            bufOut.newLine();  
            bufOut.flush();
          }
          if(actId!=-99999){
            bufOut.write("      </transaction>");
            bufOut.newLine();     
          }


          bufOut.write("    </period>");
          bufOut.newLine();     
        }
        bufOut.flush();

       
        bufOut.write("  </company>");
        bufOut.newLine();     
      }
      bufOut.write("</lazy8webport>");
      bufOut.newLine();     
      bufOut.flush();
      bufOut.close();
      workDialog.dispose();
    }catch(Exception e){
      workDialog.dispose();
      Log.log(Log.DEBUG, this, "Failed to export" + e);
      e.printStackTrace();
      JOptionPane.showMessageDialog(null,
          Translator.getTranslation("Failed to export") + " : " + e,
          "",
View Full Code Here

    //setup the csv printer
    CSVPrint printer;
    OutputStream out;
    //create the export
    String sSelectString = getSelectString(selectedFields, fromDate, toDate);
    WorkingDialog workDialog = new WorkingDialog(null);
    workDialog.setVisible(true);
    workDialog.SetProgress(0);
    try {
      out = new FileOutputStream(outputFile);
      if (isExcel) {
        printer = new ExcelCSVPrinter(out);
      } else {
        printer = new CSVPrinter(out);
      }
      printer.changeDelimiter(delimiter);
      DataConnection dc = DataConnection.getInstance(view);
      if (dc == null || !dc.bIsConnectionMade) {
        return;
      }
      Statement st = dc.con.createStatement();
      ResultSet rs = st.executeQuery(dc.filterSQL(sSelectString));
      ResultSetMetaData rsmd = rs.getMetaData();
      if (rsmd == null) {
        return;
      }
      int iNumColumns = rsmd.getColumnCount();
      String[] outputStrings = new String[iNumColumns];

      //count how many rows
      int numRows = 0;
      if (rs.next()) {
        rs.last();
        numRows = rs.getRow();
      }
      rs.beforeFirst();
      //print out the rows
      int rowCountShowProgress = 0;
      int rowNum = 0;
      while (rs.next()) {
        rowNum++;
        rowCountShowProgress++;
        if (rowCountShowProgress >= 10) {
          workDialog.SetProgress(rowNum * 100 / numRows);
          rowCountShowProgress = 0;
        }
        for (int i = 1; i <= iNumColumns; i++) {
          switch (rsmd.getColumnType(i)) {
            case Types.VARCHAR:
              outputStrings[i - 1] = rs.getString(i);
              if (outputStrings[i - 1] == null) {
                outputStrings[i - 1] = "";
              }
              if (rsmd.getColumnName(i).equals("TypeName")) {
                //it needs to be translated...
                outputStrings[i - 1] = Translator.getTranslation(outputStrings[i - 1]);
              }
              break;
            case Types.INTEGER:
              outputStrings[i - 1] = formatNumPane.numPanels[formatNumPane.SHOW_INTEGER].format(new Integer(rs.getInt(i)));
              break;
            case Types.NUMERIC:
            case Types.REAL:
            case Types.FLOAT:
            case Types.DECIMAL:
            case Types.DOUBLE:
              outputStrings[i - 1] = formatNumPane.numPanels[formatNumPane.SHOW_WHOLE_NUMBER].format(new Double(rs.getDouble(i)));
              break;
            case Types.DATE:
              outputStrings[i - 1] = formatNumPane.numPanels[formatNumPane.SHOW_DATE].format(rs.getDate(i));
              break;
            default:
              outputStrings[i - 1] = StringBinaryConverter.BinaryToString(
                  rs.getBytes(i));
              break;
          }
          Log.log(Log.DEBUG, this, "outputStrings[i-1]=" + outputStrings[i - 1]);
        }
        //send to the output
        printer.println(outputStrings);
      }
      out.close();
    } catch (Exception e) {
      Log.log(Log.ERROR, this, "Error printing CSV file=" + e);
    }
    workDialog.dispose();
  }//}}}
View Full Code Here

    }
    int act_id = 0;
    int act_id_test = 0;
    int rowCount = 1;
    String errorMess;
    WorkingDialog workDialog = new WorkingDialog(null);
    workDialog.setVisible(true);
    workDialog.SetProgress(0);
    int numRows = 0;
    int rowCountShowProgress = 0;
    int numFields = -1;
    try {
      FileInputStream in = new FileInputStream(csvFile);
      CSVParse shredderRowCount = getParser(in);
      while ((line = shredderRowCount.getLine()) != null) {
        if (numFields == -1) {
          numFields = line.length;
        } else {
          if (numFields != line.length) {
            resultMessage.append("Failed row=" + (numRows + 1) + " : All rows must have the same number of Fields" + "\n");
            workDialog.dispose();
            in.close();
            return resultMessage;
          }
        }
        numRows++;
      }
      in.close();
      if (numRows == 0) {
        resultMessage.append("The file is empty");
        workDialog.dispose();
        return resultMessage;
      }
      FileInputStream in2 = new FileInputStream(csvFile);
      CSVParse shredder = getParser(in2);
      line = shredder.getLine();
      //add two extra fields for the isDebt/Amount conversion
      String[] expandedLine = new String[line.length + 2];
      for (int k = 0; k < line.length; k++) {
        expandedLine[k] = line[k];
      }
      expandedLine[line.length] = "";
      expandedLine[line.length + 1] = "";
      v.add(expandedLine);
      try {
        act_id = ((Integer) (formatNumPane.numPanels[formatNumPane.SHOW_INTEGER]
            .parse(line[tableMatchedIndexes[INDEX_ACT_ID]]))).intValue();
      } catch (Exception e) {
        resultMessage.append("Failed row=" + rowCount + " : Cannot continue processing this file.  Bad transaction number found="
             + line[tableMatchedIndexes[tableMatchedIndexes[INDEX_ACT_ID]]] + "\n");
        workDialog.dispose();
        in2.close();
        return resultMessage;
      }
      do {
        rowCount++;
        rowCountShowProgress++;
        if (rowCountShowProgress >= 10) {
          workDialog.SetProgress(rowCount * 100 / numRows);
          rowCountShowProgress = 0;
        }
        line = shredder.getLine();
        if (line != null) {
          try {
            act_id_test = ((Integer) (formatNumPane.numPanels[formatNumPane.SHOW_INTEGER]
                .parse(line[tableMatchedIndexes[INDEX_ACT_ID]]))).intValue();
          } catch (Exception e) {
            resultMessage.append("Failed row=" + rowCount + " : Cannot continue processing this file.  Bad transaction number found="
                 + line[tableMatchedIndexes[INDEX_ACT_ID]] + "\n");
            workDialog.dispose();
            in2.close();
            return resultMessage;
          }
        }
        if (line == null || act_id_test != act_id) {
          String[][] result = new String[v.size()][];
          processTransactionGroup((String[][]) v.toArray(result),
              resultMessage, testOnly, rowCount, act_id, dc.con, maxIndex);
          v = new Vector();
        }
        act_id = act_id_test;
        if (line != null) {
          //add two extra fields for the isDebt/Amount conversion
          String[] expandedLine2 = new String[line.length + 2];
          for (int k = 0; k < line.length; k++) {
            expandedLine2[k] = line[k];
          }
          expandedLine2[line.length] = "";
          expandedLine2[line.length + 1] = "";
          v.add(expandedLine2);
        }
      } while (line != null);
      in2.close();
    } catch (java.io.IOException e) {
      resultMessage.append("Failed row=" + rowCount + " : File error reading this row" + "\n");
    }
    workDialog.dispose();
    //version 2.20, fix the PeriodId field in Activity2
    lazy8ledger.Lazy8LedgerPlugin.AdjustAllPeriodIds(CompId);
    if (tableMatchedIndexes[INDEX_AMOUNT] != -1) {
      tableMatchedIndexes[INDEX_DEBIT] = -1;
      tableMatchedIndexes[INDEX_CREDIT] = -1;
View Full Code Here

    }
    String[] t;
    int rowCount = 0;
    String errorMess;
    StringBuffer resultMessage = new StringBuffer();
    WorkingDialog workDialog = new WorkingDialog(null);
    workDialog.setVisible(true);
    workDialog.SetProgress(0);
    int numRows = 0;
    int numFields = -1;
    int rowCountShowProgress = 0;
    try {
      FileInputStream in = new FileInputStream(csvFile);
      CSVParse shredderRowCount = getParser(in);
      while ((t = shredderRowCount.getLine()) != null) {
        if (numFields == -1) {
          numFields = t.length;
        } else {
          if (numFields != t.length) {
            resultMessage.append("Failed row=" + (numRows + 1) + " : All rows must have the same number of Fields" + "\n");
            workDialog.dispose();
            in.close();
            ErrorDialog showErrors = new ErrorDialog(resultMessage, false, null);
            return;
          }
        }
        numRows++;
      }
      in.close();
      FileInputStream in2 = new FileInputStream(csvFile);
      CSVParse shredder = getParser(in2);
      while ((t = shredder.getLine()) != null) {
        rowCount++;
        rowCountShowProgress++;
        if (rowCountShowProgress >= 10) {
          workDialog.SetProgress(rowCount * 100 / numRows);
          rowCountShowProgress = 0;
        }
        errorMess = IsRowUpdateable(t, rowCount, dc.con);
        if (errorMess.length() != 0) {
          resultMessage.append(errorMess + "\n");
        } else {
          executeUpdate(t, saveFields, tableMatchedIndexes, CompId, rowCount,
              tableName, dc.con, DataTypes, formatNumPane, resultMessage);
        }
      }
      in2.close();
    } catch (java.io.IOException e) {
      resultMessage.append("Failed row=" + rowCount + " : File error reading this row. Import aborted" + "\n");
    }
    workDialog.dispose();
    if (resultMessage.length() == 0) {
      JOptionPane.showMessageDialog(this,
          "No errors detected",
          "",
          JOptionPane.PLAIN_MESSAGE);
View Full Code Here

    }
    //load from the file
    String[] t;
    int rowCount = 0;
    String errorMess;
    WorkingDialog workDialog = new WorkingDialog(null);
    workDialog.setVisible(true);
    workDialog.SetProgress(0);
    int numRows = 0;
    int rowCountShowProgress = 0;
    int numFields = -1;
    try {
      FileInputStream in = new FileInputStream(csvFile);
      CSVParse shredderRowCount = getParser(in);
      while ((t = shredderRowCount.getLine()) != null) {
        if (numFields == -1) {
          numFields = t.length;
        } else {
          if (numFields != t.length) {
            resultMessage.append("Failed row=" + (numRows + 1) + " : All rows must have the same number of Fields" + "\n");
            workDialog.dispose();
            in.close();
            return resultMessage;
          }
        }
        numRows++;
      }
      in.close();
      FileInputStream in2 = new FileInputStream(csvFile);
      CSVParse shredder = getParser(in2);
      while ((t = shredder.getLine()) != null) {
        rowCount++;
        rowCountShowProgress++;
        if (rowCountShowProgress >= 10) {
          workDialog.SetProgress(rowCount * 100 / numRows);
          rowCountShowProgress = 0;
        }
        errorMess = IsRowUpdateable(t, rowCount, dc.con);
        if (errorMess.length() != 0) {
          resultMessage.append(errorMess + "\n");
        }
        for (int i = 0; i < tableMatchedIndexes.length; i++) {
          if (tableMatchedIndexes[i] != -1) {
            if (sqlUniqueTest[i].length() != 0) {
              //test uniqness locally in the file
              FileInputStream in3 = new FileInputStream(csvFile);
              CSVParse shredderSearch = getParser(in3);
              String[] t2;
              int rowCount2 = 0;
              while ((t2 = shredderSearch.getLine()) != null) {
                rowCount2++;
                if (t2[tableMatchedIndexes[i]].compareTo(t[tableMatchedIndexes[i]]) == 0 && rowCount != rowCount2) {
                  resultMessage.append("Failed row=" + rowCount + " :Field=" + importFields[i] +
                      " : Not allowed to have this field identical to same field in row=" + rowCount2 + "\n");
                }
              }
              in3.close();
            }
          }
        }
      }
      in2.close();
    } catch (java.io.IOException e) {
      resultMessage.append("Failed row=" + rowCount + " : File error reading this row" + "\n");
    }
    workDialog.dispose();
    return resultMessage;
  }//}}}
View Full Code Here

TOP

Related Classes of nu.lazy8.util.gen.WorkingDialog

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.