Skip to content

Commit

Permalink
More azure
Browse files Browse the repository at this point in the history
  • Loading branch information
cool00geek committed Mar 13, 2017
1 parent bee0a99 commit f11c231
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 8 deletions.
3 changes: 1 addition & 2 deletions Clients/Java DB Manager/nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group name="NetBeansProjects">
<file>file:/D:/CPscoreboard/Clients/CTSBDB/src/ctsbdb/DBman.java</file>
<file>file:/D:/CPscoreboard/Clients/CTSBDB/src/ctsbdb/CTSBDB.java</file>
<file>file:/D:/CPscoreboard/Clients/Java%20DB%20Manager/src/ctsbdb/DBman.java</file>
</group>
</open-files>
</project-private>
5 changes: 4 additions & 1 deletion nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<file>file:/C:/Users/054457/Documents/CPscoreboard/src/cpscorereport/Score.java</file>
<file>file:/C:/Users/054457/Documents/CPscoreboard/src/cpscorereport/GUIHelper.java</file>
</group>
<group name="NetBeansProjects"/>
<group name="NetBeansProjects">
<file>file:/D:/CPscoreboard/src/cpscorereport/GUIHelper.java</file>
<file>file:/D:/CPscoreboard/src/cpscorereport/ServerHelper.java</file>
</group>
</open-files>
</project-private>
33 changes: 29 additions & 4 deletions src/cpscorereport/GUIHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
*/
public class GUIHelper {

Thread myServerThread; //The thread with the running server
Thread myJumpServerThread; //The thread with the running jump server
int myPort; //The port the server is running on
String myFilename; // The filename of the file to read
private Thread myServerThread; //The thread with the running server
private Thread myJumpServerThread; //The thread with the running jump server
private Thread myAzureServerThread; //The thread with the running Azure server
private int myPort; //The port the server is running on
private String myFilename; // The filename of the file to read
private final String myAzureDBUser = "";
private final String myAzureDBPass = "";

public GUIHelper(String filename) {
myServerThread = null;
Expand Down Expand Up @@ -120,6 +123,28 @@ public void handle(ActionEvent t) {
System.out.println("Server stopped!");
}
});

MenuItem startAz = new MenuItem("Start Azure server");
stopServer.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
textbox.setText("Stopping server...");
myAzureServerThread = ServerHelper.startAzureServer(myFilename, myAzureDBUser, myAzureDBPass);
textbox.setText("Server stopped!");
System.out.println("Server stopped!");
}
});

MenuItem stopAz = new MenuItem("Stop Azure server");
stopServer.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
textbox.setText("Stopping server...");
ServerHelper.stopAzureServer(myAzureServerThread);
textbox.setText("Server stopped!");
System.out.println("Server stopped!");
}
});

MenuItem export = new MenuItem("Export to xls");
export.setOnAction(new EventHandler<ActionEvent>() {
Expand Down
57 changes: 56 additions & 1 deletion src/cpscorereport/ServerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.logging.Level;
Expand Down Expand Up @@ -40,7 +46,7 @@ public void run() {
appender.write("\r\n" + cominginText);//appends the string to the file
//appends the string to the file
}
} catch (Exception ex) {
} catch (IOException ex) {
System.out.println("An issue....");
return;
}
Expand Down Expand Up @@ -88,6 +94,55 @@ public void run() {
stopper.start();
}

public static Thread startAzureServer(String fileName, String username, String password) {
final Thread server = new Thread(new Runnable() {
@Override
public void run() {
while (!Thread.interrupted()) {
System.out.println("Azure Server started!");
try {
System.out.print("Attempting connection...");
String url = "jdbc:sqlserver://ctsb.database.windows.net:1433;database=CPscores;user=" + username + "@ctsb;password=" + password + ";encrypt=true;trustServerCertificate=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(url);
System.out.println(" Conected!\n");

Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM TeamScores");
ResultSetMetaData rsmd = rs.getMetaData();
int columnsNumber = rsmd.getColumnCount();

FileWriter appender = new FileWriter(fileName, true);

while (rs.next()) {
appender.write("\r\n");
for (int i = 1; i <= columnsNumber; i++) {
appender.write(rs.getString(i) + " ");
}
}
} catch (ClassNotFoundException | IOException | SQLException ex) {
System.out.println("An issue....\n" + ex);
return;
}
}
}
}
);
server.start();
return server;
}

public static void stopAzureServer(Thread theServer) {
final Thread stopper = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Stopping server...");
theServer.interrupt();
}
});
stopper.start();
}

public static void exportToExcel(Text infoBox) {
String filename = "Scoreboard_";
filename += new SimpleDateFormat("MMddyy_HHmm").format(Calendar.getInstance().getTime());
Expand Down

0 comments on commit f11c231

Please sign in to comment.