Working mysql connection icon

This commit is contained in:
szporowolik
2019-09-13 13:31:03 +02:00
parent ddb2527eb8
commit 238f6e29ae
6 changed files with 76 additions and 53 deletions

View File

@@ -3,11 +3,13 @@ using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using System;
internal class DatabaseController
public class DatabaseController
{
public static string strMySQLConnectionString; // MySQL connection string
public string strMySQLConnectionString; // MySQL connection string
public MySqlConnection connMySQL;
public bool bStatus;
public static void SendToMySql(string strRawUDPFrame)
public void SendToMySql(string strRawUDPFrame)
{
// Main function to send data to mysql
dynamic strUDPFrame = JsonConvert.DeserializeObject(strRawUDPFrame); // Deserialize raw data
@@ -84,12 +86,12 @@ internal class DatabaseController
}
// Connect to mysql and execute sql
MySqlConnection connMySQL = new MySqlConnection(DatabaseController.strMySQLConnectionString);
connMySQL = new MySqlConnection(strMySQLConnectionString);
try
{
Console.WriteLine("Sending data to MySQL - Begin");
connMySQL.Open();
bStatus = true;
MySqlCommand cmdMySQL = new MySqlCommand(strSQLQueryTxt, connMySQL);
MySqlDataReader rdrMySQL = cmdMySQL.ExecuteReader();
@@ -105,6 +107,7 @@ internal class DatabaseController
// General exception found
Console.WriteLine(a_ex.ToString());
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - package type: " + strUDPFrameType);
bStatus = false;
}
catch (MySqlException m_ex)
{
@@ -122,6 +125,7 @@ internal class DatabaseController
PerunHelper.LogHistoryAdd(ref Globals.arrLogHistory, "ERROR MySQL - " + m_ex.Number);
break;
}
bStatus = false;
}
connMySQL.Close();
Console.WriteLine("Sending data to MySQL - Done");

View File

@@ -1,7 +1,10 @@
// This class gathers all global variables
// This class gathers all global variable
using MySql.Data.MySqlClient;
internal class Globals
{
public static string strPerunVersion = "DEBUG"; // Helper for pulling version definition
public static string[] arrLogHistory = new string[10]; // Log history for GUI
}
}

View File

@@ -46,12 +46,9 @@ internal class TCPController
{
try
{
// Start listening to UDP
// Start listening to TCP
tcpServer = new TcpListener(IPAddress.Any, intListenPort);
string strReceivedData;
byte[] arrReceiveByteArray;
// Start the main loop
TCPController.boolDone = false;