コード例 #1
0
  private void selectFilebtnActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_selectFilebtnActionPerformed
    // TODO add your handling code here:
    SyntaxRule syntaxRule = new SyntaxRule();
    JFileChooser fileChooser = new JFileChooser();
    int returnValue = fileChooser.showOpenDialog(null);

    if (returnValue == JFileChooser.APPROVE_OPTION) {
      File selectedFile = fileChooser.getSelectedFile();
      sqlFile = selectedFile.getAbsolutePath();

      if (validation.checkIfFileExtensionIsSql(sqlFile, "sql")) {

        sqlSourceFile = file.readFileToString(sqlFile);
        //  boolean test =    validation.checkIfEqualAmountOfbraces(sqlSourceFile);

        // if (validation.checkIfEqualAmountOfsemeilcon(sqlSourceFile)) {
        String databaseName = syntaxRule.getDatabaseNameFromMySqlServerFile(sqlFile);
        syntaxRule.databaseName = databaseName;

        sqlSourceFile = syntaxRule.removeAlterDatabaseStatements(sqlSourceFile, databaseName);
        sqlSourceFile = syntaxRule.replaceSQLServerSymbols(sqlSourceFile);
        sqlSourceFile = syntaxRule.CreateDatabaseStatement(sqlSourceFile, databaseName);

        // validation.checkIfEqualInsertValues(sqlSourceFile);
        // ArrayList<Token> createSourceCodeTokens =
        // tokenization.createSourceCodeTokens(sqlSourceFile);
        // validation.checkIfInsertToken(createSourceCodeTokens);
        sourceFileWithOutComments = sqlSourceFile;

        String[] sourceCodeSplit = sourceFileWithOutComments.split(",");
        for (String x : sourceCodeSplit) {
          if (x.toLowerCase().contains("primary key")) {
            sqlServerSourceCodetxt.setText(sqlServerSourceCodetxt.getText() + " " + x + "\n");
          } else {
            sqlServerSourceCodetxt.setText(
                sqlServerSourceCodetxt.getText() + " " + x + " ," + "\n");
          }
        }
        //  }
      } else {
        JOptionPane.showMessageDialog(
            null,
            "Wrong file Type! Please Select A file Type ",
            "File Type Error",
            JOptionPane.ERROR_MESSAGE);
      }
    }
  } // GEN-LAST:event_selectFilebtnActionPerformed