Initial commit

This commit is contained in:
2026-09-03 10:50:01 +02:00
commit f3d3a1c02a
234 changed files with 118368 additions and 0 deletions
+312
View File
@@ -0,0 +1,312 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace StacjaProb
{
public partial class SerialSetUpForm : Form
{
string[] ports;
public SerialSetUpForm()
{
InitializeComponent();
}
private void SerialSetUpForm_Load(object sender, EventArgs e)
{
int index = 0;
ports = System.IO.Ports.SerialPort.GetPortNames();
foreach (string port in ports)
{
//richTextBox1.AppendText(port);
comboBoxPort01.Items.Insert(index, port);
comboBoxPort02.Items.Insert(index, port);
comboBoxPort03.Items.Insert(index, port);
index++;
}
if (index <= 0) buttonSave.Visible = false;
loadSpeedPortsValues(comboBoxPredkosc01);
loadSpeedPortsValues(comboBoxPredkosc02);
loadSpeedPortsValues(comboBoxPredkosc03);
// przy założeniu, że jest jeden tor pomiarowy - dla AGH
//groupBox1.Visible = false;
//groupBox2.Visible = false;
mySqlFunctions.initConnection();
if (mySqlFunctions.OpenConnection())
{
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("SELECT * from tst_test_places", mySqlFunctions.connection);
MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read())
{
// dlatoru pierwszego
if (Convert.ToInt32(dataReader["TPL_ID"].ToString()) == 1)
{
comboBoxPort01.SelectedIndex = comboBoxPort01.Items.IndexOf(dataReader["TPL_PORT_NO"].ToString());
comboBoxPredkosc01.SelectedIndex = comboBoxPredkosc01.Items.IndexOf(dataReader["TPL_PORT_SPEED"].ToString());
textBoxAdresKonc01.Text = dataReader["TPL_ADDRESS"].ToString();
textBoxBezwladnosc01.Text = dataReader["TPL_FAST_LOOS"].ToString();
textBoxWygrzewanie01.Text = dataReader["TPL_BURN_TIME"].ToString();
textBoxSrednica01.Text = dataReader["TPL_PIPE_DIAMETER"].ToString();
textBoxCzlonGeo01.Text = dataReader["TPL_GEO"].ToString();
textBoxQ01.Text = dataReader["TPL_Q_RANGE"].ToString();
textBoxP01.Text = dataReader["TPL_P_RANGE"].ToString();
textBoxT01.Text = dataReader["TPL_T_RANGE"].ToString();
textBoxKrok01.Text = dataReader["TPL_DESC"].ToString();
}
// dlatoru drugiego
else if (Convert.ToInt32(dataReader["TPL_ID"].ToString()) == 2)
{
comboBoxPort02.SelectedIndex = comboBoxPort02.Items.IndexOf(dataReader["TPL_PORT_NO"].ToString());
comboBoxPredkosc02.SelectedIndex = comboBoxPredkosc02.Items.IndexOf(dataReader["TPL_PORT_SPEED"].ToString());
textBoxAdresKonc02.Text = dataReader["TPL_ADDRESS"].ToString();
textBoxBezwladnosc02.Text = dataReader["TPL_FAST_LOOS"].ToString();
textBoxWygrzewanie02.Text = dataReader["TPL_BURN_TIME"].ToString();
textBoxSrednica02.Text = dataReader["TPL_PIPE_DIAMETER"].ToString();
textBoxCzlonGeo02.Text = dataReader["TPL_GEO"].ToString();
textBoxQ02.Text = dataReader["TPL_Q_RANGE"].ToString();
textBoxP02.Text = dataReader["TPL_P_RANGE"].ToString();
textBoxT02.Text = dataReader["TPL_T_RANGE"].ToString();
textBoxKrok02.Text = dataReader["TPL_DESC"].ToString();
}
// dlatoru trzeciego
else if (Convert.ToInt32(dataReader["TPL_ID"].ToString()) == 3)
{
comboBoxPort03.SelectedIndex = comboBoxPort03.Items.IndexOf(dataReader["TPL_PORT_NO"].ToString());
comboBoxPredkosc03.SelectedIndex = comboBoxPredkosc03.Items.IndexOf(dataReader["TPL_PORT_SPEED"].ToString());
textBoxAdresKonc03.Text = dataReader["TPL_ADDRESS"].ToString();
textBoxBezwladnosc03.Text = dataReader["TPL_FAST_LOOS"].ToString();
textBoxWygrzewanie03.Text = dataReader["TPL_BURN_TIME"].ToString();
textBoxSrednica03.Text = dataReader["TPL_PIPE_DIAMETER"].ToString();
textBoxCzlonGeo03.Text = dataReader["TPL_GEO"].ToString();
textBoxQ03.Text = dataReader["TPL_Q_RANGE"].ToString();
textBoxP03.Text = dataReader["TPL_P_RANGE"].ToString();
textBoxT03.Text = dataReader["TPL_T_RANGE"].ToString();
textBoxKrok03.Text = dataReader["TPL_DESC"].ToString();
}
//comboBoxStanowisko.Items.Insert(Convert.ToInt32(dataReader["TPL_ID"]), dataReader["TPL_NAME"].ToString());
//pathID[index] = Convert.ToInt32(dataReader["TPP_ID"]);
//comboBoxTor.Items.Insert(index, dataReader["TPP_NAME"].ToString());
}
dataReader.Close();
mySqlFunctions.CloseConnection();
//comboBoxStanowisko.SelectedIndex = 0;
}
//buttonSave.Enabled = false;
}
private void loadSpeedPortsValues(System.Windows.Forms.ComboBox comboName)
{
comboName.Items.Clear();
comboName.Items.Insert(0, "2400");
comboName.Items.Insert(1, "4800");
comboName.Items.Insert(2, "9600");
comboName.Items.Insert(3, "19200");
}
private string getBezwValueHex(int bezwValue)
{
string out_bazwValueHex = "";
if (bezwValue == 11000) out_bazwValueHex = "A";
else if (bezwValue == 12000) out_bazwValueHex = "B";
else if (bezwValue == 13000) out_bazwValueHex = "C";
else if (bezwValue == 14000) out_bazwValueHex = "D";
else if (bezwValue == 15000) out_bazwValueHex = "E";
else if (bezwValue == 16000) out_bazwValueHex = "F";
else if (bezwValue == 17000) out_bazwValueHex = "G";
else if (bezwValue == 18000) out_bazwValueHex = "H";
else if (bezwValue == 19000) out_bazwValueHex = "I";
else if (bezwValue == 20000) out_bazwValueHex = "J";
else if (bezwValue == 21000) out_bazwValueHex = "K";
else if (bezwValue == 22000) out_bazwValueHex = "L";
return out_bazwValueHex;
}
private void buttonSave_Click(object sender, EventArgs e)
{
mySqlFunctions.initConnection();
if (mySqlFunctions.OpenConnection())
{
if ((comboBoxPort01.SelectedIndex >= 0 && comboBoxPredkosc01.SelectedIndex >= 0) || (comboBoxPort02.SelectedIndex >= 0 && comboBoxPredkosc02.SelectedIndex >= 0) || (comboBoxPort03.SelectedIndex >= 0 && comboBoxPredkosc03.SelectedIndex >= 0))
{
string query_insert_00 = "truncate table tst_test_places";
MySql.Data.MySqlClient.MySqlCommand cmd_00 = new MySql.Data.MySqlClient.MySqlCommand(query_insert_00, mySqlFunctions.connection);
cmd_00.ExecuteNonQuery();
}
if (comboBoxPort01.SelectedIndex >= 0 && comboBoxPredkosc01.SelectedIndex >= 0)
{
string query_insert_01 = "INSERT INTO tst_test_places SET TPL_NAME='Stanowisko 01'"
+ ",TPL_PORT_NO='" + comboBoxPort01.Text
+ "',TPL_PORT_SPEED=" + comboBoxPredkosc01.Text
+",TPL_ADDRESS='"+textBoxAdresKonc01.Text
+"',TPL_PIPE_DIAMETER="+textBoxSrednica01.Text.Replace(",",".")
+ ",TPL_FAST_LOOS=" + textBoxBezwladnosc01.Text.Replace(",", ".")
+ ",TPL_Q_RANGE=" + textBoxQ01.Text.Replace(",", ".")
+ ",TPL_P_RANGE=" + textBoxP01.Text.Replace(",", ".")
+ ",TPL_T_RANGE=" + textBoxT01.Text.Replace(",", ".")
+ ",TPL_GEO=" + textBoxCzlonGeo01.Text.Replace(",", ".")
+ ",TPL_BURN_TIME=" + textBoxWygrzewanie01.Text.Replace(",", ".")
+ ",TPL_DESC='" + textBoxKrok01.Text.Replace(",", ".")
+"',TPL_AUDIT_CU='admin"
+"',TPL_AUDIT_CD=now()";
MySql.Data.MySqlClient.MySqlCommand cmd_01 = new MySql.Data.MySqlClient.MySqlCommand(query_insert_01, mySqlFunctions.connection);
cmd_01.ExecuteNonQuery();
//aktualizauje długość otwierania zasuwy
int new_bazwValue = Convert.ToInt32(textBoxBezwladnosc01.Text) * 1000 + 1000;
string new_bazwValueHex = textBoxBezwladnosc01.Text;
if (new_bazwValue > 10000)
{
new_bazwValueHex = getBezwValueHex(new_bazwValue);
}
MySql.Data.MySqlClient.MySqlCommand cmd_02 = new MySql.Data.MySqlClient.MySqlCommand("UPDATE tst_steps SET STP_VALUE='" + new_bazwValueHex + "',STP_DELAY='" + new_bazwValue.ToString() + "' WHERE STP_CMD='(('", mySqlFunctions.connection);
cmd_02.ExecuteNonQuery();
//aktualizacja czasu wygrzewania
double new_burningValue = Convert.ToDouble(textBoxWygrzewanie01.Text) * 60000 + 1000;
MySql.Data.MySqlClient.MySqlCommand cmd_03 = new MySql.Data.MySqlClient.MySqlCommand("UPDATE tst_steps SET STP_DELAY='" + new_burningValue.ToString() + "' WHERE STP_CMD='sleep'", mySqlFunctions.connection);
cmd_03.ExecuteNonQuery();
}
if (comboBoxPort02.SelectedIndex >= 0 && comboBoxPredkosc02.SelectedIndex >= 0)
{
string query_insert_02 = "INSERT INTO tst_test_places SET TPL_NAME='Stanowisko 02'"
+ ",TPL_PORT_NO='" + comboBoxPort02.Text
+ "',TPL_PORT_SPEED=" + comboBoxPredkosc02.Text
+ ",TPL_ADDRESS='" + textBoxAdresKonc02.Text
+ "',TPL_PIPE_DIAMETER=" + textBoxSrednica02.Text.Replace(",", ".")
+ ",TPL_FAST_LOOS=" + textBoxBezwladnosc02.Text.Replace(",", ".")
+ ",TPL_Q_RANGE=" + textBoxQ02.Text.Replace(",", ".")
+ ",TPL_P_RANGE=" + textBoxP02.Text.Replace(",", ".")
+ ",TPL_T_RANGE=" + textBoxT02.Text.Replace(",", ".")
+ ",TPL_GEO=" + textBoxCzlonGeo02.Text.Replace(",", ".")
+ ",TPL_BURN_TIME=" + textBoxWygrzewanie02.Text.Replace(",", ".")
+ ",TPL_DESC='" + textBoxKrok02.Text.Replace(",", ".")
+ "',TPL_AUDIT_CU='admin"
+ "',TPL_AUDIT_CD=now()";
MySql.Data.MySqlClient.MySqlCommand cmd_02 = new MySql.Data.MySqlClient.MySqlCommand(query_insert_02, mySqlFunctions.connection);
cmd_02.ExecuteNonQuery();
}
if (comboBoxPort03.SelectedIndex >= 0 && comboBoxPredkosc03.SelectedIndex >= 0)
{
string query_insert_03 = "INSERT INTO tst_test_places SET TPL_NAME='Stanowisko 03'"
+ ",TPL_PORT_NO='" + comboBoxPort03.Text
+ "',TPL_PORT_SPEED=" + comboBoxPredkosc03.Text
+ ",TPL_ADDRESS='" + textBoxAdresKonc03.Text
+ "',TPL_PIPE_DIAMETER=" + textBoxSrednica03.Text.Replace(",", ".")
+ ",TPL_FAST_LOOS=" + textBoxBezwladnosc03.Text.Replace(",", ".")
+ ",TPL_Q_RANGE=" + textBoxQ03.Text.Replace(",", ".")
+ ",TPL_P_RANGE=" + textBoxP03.Text.Replace(",", ".")
+ ",TPL_T_RANGE=" + textBoxT03.Text.Replace(",", ".")
+ ",TPL_GEO=" + textBoxCzlonGeo03.Text.Replace(",", ".")
+ ",TPL_BURN_TIME=" + textBoxWygrzewanie03.Text.Replace(",", ".")
+ ",TPL_DESC='" + textBoxKrok03.Text.Replace(",", ".")
+ "',TPL_AUDIT_CU='admin"
+ "',TPL_AUDIT_CD=now()";
MySql.Data.MySqlClient.MySqlCommand cmd_03 = new MySql.Data.MySqlClient.MySqlCommand(query_insert_03, mySqlFunctions.connection);
cmd_03.ExecuteNonQuery();
}
mySqlFunctions.CloseConnection();
}
//dorobić update dla zakresów i czasu zwłoki zasówy
this.Close();
}
private void buttonClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void textBoxKrok01_Leave(object sender, EventArgs e)
{
try
{
textBoxKrok01.Text = textBoxKrok01.Text.Replace(".", ",");
int myInt;
bool isNumerical = int.TryParse(textBoxKrok01.Text, out myInt);
if (!isNumerical && textBoxKrok01.Text.Length > 0)
{
MessageBox.Show("Wprowadzona wartość musi być liczbą całkowitą!\nWprowadź proszę ponownie.");
textBoxKrok01.Focus();
}
}
catch { }
}
private void textBoxKrok02_Leave(object sender, EventArgs e)
{
try
{
textBoxKrok02.Text = textBoxKrok02.Text.Replace(".", ",");
int myInt;
bool isNumerical = int.TryParse(textBoxKrok02.Text, out myInt);
if (!isNumerical && textBoxKrok02.Text.Length > 0)
{
MessageBox.Show("Wprowadzona wartość musi być liczbą całkowitą!\nWprowadź proszę ponownie.");
textBoxKrok02.Focus();
}
}
catch { }
}
private void textBoxKrok03_Leave(object sender, EventArgs e)
{
try
{
textBoxKrok03.Text = textBoxKrok03.Text.Replace(".", ",");
int myInt;
bool isNumerical = int.TryParse(textBoxKrok03.Text, out myInt);
if (!isNumerical && textBoxKrok03.Text.Length > 0)
{
MessageBox.Show("Wprowadzona wartość musi być liczbą całkowitą!\nWprowadź proszę ponownie.");
textBoxKrok03.Focus();
}
}
catch { }
}
}
}