mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 15:55:39 +02:00
Working mysql connection icon
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -65,18 +65,18 @@
|
||||
this.con_txt_dcs_instance = new System.Windows.Forms.MaskedTextBox();
|
||||
this.label7 = new System.Windows.Forms.Label();
|
||||
this.con_txt_dcs_server_port = new System.Windows.Forms.MaskedTextBox();
|
||||
this.con_img_db = new System.Windows.Forms.PictureBox();
|
||||
this.con_img_dcs = new System.Windows.Forms.PictureBox();
|
||||
this.con_img_srs = new System.Windows.Forms.PictureBox();
|
||||
this.con_img_lotATC = new System.Windows.Forms.PictureBox();
|
||||
this.con_img_srs = new System.Windows.Forms.PictureBox();
|
||||
this.con_img_dcs = new System.Windows.Forms.PictureBox();
|
||||
this.con_img_db = new System.Windows.Forms.PictureBox();
|
||||
this.con_GroupBox_1.SuspendLayout();
|
||||
this.con_GroupBox_2.SuspendLayout();
|
||||
this.con_GroupBox_3.SuspendLayout();
|
||||
this.groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.con_img_db)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.con_img_dcs)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.con_img_srs)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.con_img_lotATC)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.con_img_srs)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.con_img_dcs)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.con_img_db)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// con_List_Received
|
||||
@@ -383,37 +383,42 @@
|
||||
this.con_txt_dcs_server_port.Size = new System.Drawing.Size(207, 20);
|
||||
this.con_txt_dcs_server_port.TabIndex = 3;
|
||||
//
|
||||
// con_img_db
|
||||
// con_img_lotATC
|
||||
//
|
||||
this.con_img_db.Location = new System.Drawing.Point(12, 335);
|
||||
this.con_img_db.Name = "con_img_db";
|
||||
this.con_img_db.Size = new System.Drawing.Size(29, 28);
|
||||
this.con_img_db.TabIndex = 10;
|
||||
this.con_img_db.TabStop = false;
|
||||
//
|
||||
// con_img_dcs
|
||||
//
|
||||
this.con_img_dcs.Location = new System.Drawing.Point(47, 335);
|
||||
this.con_img_dcs.Name = "con_img_dcs";
|
||||
this.con_img_dcs.Size = new System.Drawing.Size(29, 28);
|
||||
this.con_img_dcs.TabIndex = 11;
|
||||
this.con_img_dcs.TabStop = false;
|
||||
this.con_img_lotATC.Location = new System.Drawing.Point(307, 335);
|
||||
this.con_img_lotATC.Name = "con_img_lotATC";
|
||||
this.con_img_lotATC.Size = new System.Drawing.Size(29, 28);
|
||||
this.con_img_lotATC.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
||||
this.con_img_lotATC.TabIndex = 13;
|
||||
this.con_img_lotATC.TabStop = false;
|
||||
//
|
||||
// con_img_srs
|
||||
//
|
||||
this.con_img_srs.Location = new System.Drawing.Point(82, 335);
|
||||
this.con_img_srs.Location = new System.Drawing.Point(272, 335);
|
||||
this.con_img_srs.Name = "con_img_srs";
|
||||
this.con_img_srs.Size = new System.Drawing.Size(29, 28);
|
||||
this.con_img_srs.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
||||
this.con_img_srs.TabIndex = 12;
|
||||
this.con_img_srs.TabStop = false;
|
||||
//
|
||||
// con_img_lotATC
|
||||
// con_img_dcs
|
||||
//
|
||||
this.con_img_lotATC.Location = new System.Drawing.Point(117, 335);
|
||||
this.con_img_lotATC.Name = "con_img_lotATC";
|
||||
this.con_img_lotATC.Size = new System.Drawing.Size(29, 28);
|
||||
this.con_img_lotATC.TabIndex = 13;
|
||||
this.con_img_lotATC.TabStop = false;
|
||||
this.con_img_dcs.Location = new System.Drawing.Point(237, 335);
|
||||
this.con_img_dcs.Name = "con_img_dcs";
|
||||
this.con_img_dcs.Size = new System.Drawing.Size(29, 28);
|
||||
this.con_img_dcs.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
||||
this.con_img_dcs.TabIndex = 11;
|
||||
this.con_img_dcs.TabStop = false;
|
||||
//
|
||||
// con_img_db
|
||||
//
|
||||
this.con_img_db.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
|
||||
this.con_img_db.Location = new System.Drawing.Point(202, 335);
|
||||
this.con_img_db.Name = "con_img_db";
|
||||
this.con_img_db.Size = new System.Drawing.Size(29, 28);
|
||||
this.con_img_db.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
||||
this.con_img_db.TabIndex = 10;
|
||||
this.con_img_db.TabStop = false;
|
||||
//
|
||||
// form_Main
|
||||
//
|
||||
@@ -449,10 +454,10 @@
|
||||
this.con_GroupBox_3.PerformLayout();
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.con_img_db)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.con_img_dcs)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.con_img_srs)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.con_img_lotATC)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.con_img_srs)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.con_img_dcs)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.con_img_db)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using Newtonsoft.Json;
|
||||
@@ -11,6 +12,7 @@ namespace Perun_v1
|
||||
// Variable definitions
|
||||
public string[] arrSendBuffer = new string[65534]; // Mysql send buffer
|
||||
public bool boolLetMeOut = false; // Helper to handle system tray
|
||||
public DatabaseController dbConnection = new DatabaseController();
|
||||
|
||||
// ################################ Main ################################
|
||||
private void form_Main_Load(object sender, EventArgs e)
|
||||
@@ -94,7 +96,7 @@ namespace Perun_v1
|
||||
con_txt_mysql_database.Enabled = true;
|
||||
con_txt_mysql_username.Enabled = true;
|
||||
con_txt_mysql_password.Enabled = true;
|
||||
//con_txt_mysql_port.Enabled = true; // TBD - protect against writting text in the port field
|
||||
con_txt_mysql_port.Enabled = true;
|
||||
con_txt_mysql_server.Enabled = true;
|
||||
con_txt_3rd_lotatc.Enabled = true;
|
||||
con_txt_3rd_srs.Enabled = true;
|
||||
@@ -109,12 +111,7 @@ namespace Perun_v1
|
||||
private void con_Button_Listen_ON_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Start listening
|
||||
//UDPController.Create(48620, ref Globals.arrLogHistory, ref arrSendBuffer);
|
||||
//UDPController.thrUDPListener = new Thread(UDPController.StartListen);
|
||||
//UDPController.thrUDPListener.Start();
|
||||
//UDPController.thrUDPListener.Name = "UDPThread";
|
||||
|
||||
TCPController.Create(48620, ref Globals.arrLogHistory, ref arrSendBuffer);
|
||||
TCPController.Create(Int32.Parse(con_txt_dcs_server_port.Text), ref Globals.arrLogHistory, ref arrSendBuffer);
|
||||
TCPController.thrTCPListener = new Thread(TCPController.StartListen);
|
||||
TCPController.thrTCPListener.Start();
|
||||
TCPController.thrTCPListener.Name = "TCPThread";
|
||||
@@ -123,7 +120,7 @@ namespace Perun_v1
|
||||
form_Main_SaveSettings(); // Save settings
|
||||
|
||||
// Prepare connection string
|
||||
DatabaseController.strMySQLConnectionString = "server=" + con_txt_mysql_server.Text + ";user=" + con_txt_mysql_username.Text + ";database=" + con_txt_mysql_database.Text + ";port=" + con_txt_mysql_port.Text + ";password=" + con_txt_mysql_password.Text;
|
||||
dbConnection.strMySQLConnectionString = "server=" + con_txt_mysql_server.Text + ";user=" + con_txt_mysql_username.Text + ";database=" + con_txt_mysql_database.Text + ";port=" + con_txt_mysql_port.Text + ";password=" + con_txt_mysql_password.Text;
|
||||
|
||||
// Start timmers
|
||||
tim_200ms.Enabled = true;
|
||||
@@ -136,7 +133,6 @@ namespace Perun_v1
|
||||
// Stop listening
|
||||
try
|
||||
{
|
||||
//UDPController.StopListen();
|
||||
TCPController.StopListen();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -283,10 +279,22 @@ namespace Perun_v1
|
||||
{
|
||||
if (arrSendBuffer[i] != null)
|
||||
{
|
||||
DatabaseController.SendToMySql(arrSendBuffer[i]);
|
||||
dbConnection.SendToMySql(arrSendBuffer[i]);
|
||||
arrSendBuffer[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Update icons
|
||||
if (dbConnection.bStatus)
|
||||
{
|
||||
con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("ico_db");
|
||||
} else
|
||||
{
|
||||
con_img_db.Image = (Image)Properties.Resources.ResourceManager.GetObject("ico_error");
|
||||
}
|
||||
con_img_dcs.Image = (Image)Properties.Resources.ResourceManager.GetObject("ico_game");
|
||||
con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("ico_srs");
|
||||
con_img_lotATC.Image = (Image)Properties.Resources.ResourceManager.GetObject("ico_lotatc");
|
||||
}
|
||||
|
||||
private void tim_10000ms_Tick(object sender, EventArgs e)
|
||||
@@ -361,7 +369,7 @@ namespace Perun_v1
|
||||
{
|
||||
strSRSJson = "{'type':'100','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':{'ignore':'true'}}";
|
||||
}
|
||||
DatabaseController.SendToMySql(strSRSJson);
|
||||
dbConnection.SendToMySql(strSRSJson);
|
||||
|
||||
// Handle LotATC - TBD clean code for multiinstance
|
||||
if (con_check_3rd_lotatc.Checked)
|
||||
@@ -386,7 +394,7 @@ namespace Perun_v1
|
||||
{
|
||||
strLotATCJson = "{'type':'101','instance':'" + Int32.Parse(con_txt_dcs_instance.Text) + "','payload':{'ignore':'true'}}"; // No LotATC controller connected
|
||||
}
|
||||
DatabaseController.SendToMySql(strLotATCJson);
|
||||
dbConnection.SendToMySql(strLotATCJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,6 +181,12 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="03_Resources\perun_logo.ico" />
|
||||
<None Include="Resources\ico_error.png" />
|
||||
<None Include="Resources\ico_srs.png" />
|
||||
<None Include="Resources\ico_lotatc.png" />
|
||||
<None Include="Resources\ico_game.png" />
|
||||
<None Include="Resources\ico_db.png" />
|
||||
<None Include="Resources\img_db.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
Reference in New Issue
Block a user