private void conversionBtnActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_conversionBtnActionPerformed
    // TODO add your handling code here:
    try {
      if (Validation.validationTypeOfSQL(
              sourceFileWithOutComments, tokenization, subtractValuesFromListSQL)
          == true) {
        // System.out.println("this is Sql Server");
        SyntaxRule rule = new SyntaxRule();

        ArrayList<Token> createSourceCodeTokens =
            tokenization.createSourceCodeTokens(sourceFileWithOutComments);
        if (Validation.tokenValidation(createSourceCodeTokens) == true) {
          createSourceCodeTokens = rule.replaceSQLServerFunctions(createSourceCodeTokens);
          createSourceCodeTokens = rule.replaceSQLServerDataType(createSourceCodeTokens);

          for (int i = 0; i < createSourceCodeTokens.size(); i++) {
            createSourceCodeTokens
                .get(i)
                .setToken(rule.changeForiegnKey(createSourceCodeTokens.get(i)));
          }
          file.writeToFile(
              "result.sql",
              createSourceCodeTokens,
              "C:/Users/dacorie/Documents/JavaProject/SqlServerToMySqlMitgrationTool/src/assets/");

          String list = "";
          for (Token x : createSourceCodeTokens) {
            list += x.getToken();
          }
          String[] listArray = list.split(",");

          for (String x : listArray) {
            mysqlSoucreCode.setText(
                (mysqlSoucreCode.getText() + " " + x + "," + "\n").replace(";,", ";"));
          }

          JOptionPane.showMessageDialog(
              null,
              "File Conversation Was successfull",
              "Successs",
              JOptionPane.INFORMATION_MESSAGE);
        }
      } else {
        JOptionPane.showMessageDialog(
            null,
            "Not Sql Server File ",
            "This is not Sql Server File",
            JOptionPane.WARNING_MESSAGE);
      }
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(
          null, "Not Sql Server File ", "This is not Sql Server File", JOptionPane.WARNING_MESSAGE);
    }
  } // GEN-LAST:event_conversionBtnActionPerformed
  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
  private void optimizationBtnActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_optimizationBtnActionPerformed
    // TODO add your handling code here:
    SyntaxRule syntaxRule = new SyntaxRule();
    JFileChooser fileChooser = new JFileChooser();
    int returnValue = fileChooser.showOpenDialog(null);
    String wtv = "";
    if (returnValue == JFileChooser.APPROVE_OPTION) {
      File selectedFile = fileChooser.getSelectedFile();
      sqlFile = selectedFile.getAbsolutePath();

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

        LinkedList<String> stringList = new LinkedList<String>();

        sqlSourceFile = file.readFileToString(sqlFile);
        // List<String> items = Arrays.asList(sqlSourceFile.split(";"));
        sqlSourceFile = file.readFileToString(sqlFile);

        sqlServerSourceCodetxt.setText("");

        String[] sourceCodeSplit = sqlSourceFile.split(",");
        for (String x : sourceCodeSplit) {
          if (x.toLowerCase().contains("primary key")) {
            sqlServerSourceCodetxt.setText(sqlServerSourceCodetxt.getText() + " " + x + "\n");
          } else {
            sqlServerSourceCodetxt.setText(
                sqlServerSourceCodetxt.getText() + " " + x + " ," + "\n");
          }
        }

        try {
          Scanner scn = new Scanner(selectedFile);

          FileWriter writer = new FileWriter("./src/assets/output.sql");
          while (scn.hasNextLine()) {
            String i = scn.nextLine(); // optimize
            // test for language rules
            // replace comments
            i = i.toLowerCase();
            if (i.startsWith("--") || i.contentEquals("")) {
              continue;
            }

            // Swap keywords
            if (i.contains("if exists")) {
              continue;
            }
            if (i.contains("insert")) {
              System.out.println("");
            }
            /*if(i.contains("auto_increment"))
            i = i.replace("auto_increment", "identity(1,1)");*/
            if (i.contains("auto_increment")) {
              i = i.replace("auto_increment", "");
            }
            if (i.contains("unsigned")) {
              i = i.replace("unsigned", "");
            }
            if (i.contains("bool")) {
              i = i.replace("bool", "varchar(4)");
            }
            if (i.contains("set autocommit=0;")) {
              i = i.replace("set autocommit=0;", "");
            }
            if (i.contains("engine=innodb default charset=utf8")) {
              i = i.replace("engine=innodb default charset=utf8", "");
            }
            if (i.contains("create schema ")) {
              i = i.replace("create schema ", "create database");
            }
            if (i.contains(
                "timestamp not null default current_timestamp on update current_timestamp")) {
              i =
                  i.replace(
                      "timestamp not null default current_timestamp on update current_timestamp",
                      "timestamp");
            }
            if (i.contains("n'")) {
              i = i.replace("n'", "N'");
            }

            // remove key
            /*if(!(i.contains("primary key")||i.contains("foreign key"))){
            if(i.contains("key "))
            continue;
            }*/
            writer.write(i + System.getProperty("line.separator"));
            wtv = wtv + i + System.getProperty("line.separator");

            // System.out.println(i);
          }

          scn.close();
          writer.close();

        } catch (FileNotFoundException e) {
          e.printStackTrace();
        } catch (Exception e) {
          e.printStackTrace();
        }
        String[] d = wtv.split(",");
        for (String x : d) {
          if (x.toLowerCase().contains("primary key")) {
            mysqlSoucreCode.setText(mysqlSoucreCode.getText() + " " + x + "\n");
          } else {
            mysqlSoucreCode.setText(mysqlSoucreCode.getText() + " " + x + " ," + "\n");
          }
        }
        /*// 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 Enter a file type",
            "File Type Error",
            JOptionPane.ERROR_MESSAGE);
      }
    }
  } // GEN-LAST:event_optimizationBtnActionPerformed