167 lines
7.1 KiB
C#
167 lines
7.1 KiB
C#
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 testConfig : Form
|
|
{
|
|
public testConfig()
|
|
{
|
|
InitializeComponent();
|
|
buttonSave.Click += buttonSave_Click;
|
|
buttonCancel.Click += buttonCancel_Click;
|
|
buttonDefault.Click += buttonDefault_Click;
|
|
LoadConfigFromDb();
|
|
}
|
|
|
|
private void buttonSave_Click(object sender, EventArgs e)
|
|
{
|
|
SaveConfigToDb();
|
|
MessageBox.Show("Konfiguracja została zapisana.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
this.Close();
|
|
}
|
|
|
|
private void buttonCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void buttonDefault_Click(object sender, EventArgs e)
|
|
{
|
|
SetDefaultValues();
|
|
}
|
|
|
|
private void SetDefaultValues()
|
|
{
|
|
textBoxBurnTime.Text = "15";
|
|
textBoxDN50Luz.Text = "18000";
|
|
textBoxDN50Step.Text = "250";
|
|
textBoxDN100Luz.Text = "4400";
|
|
textBoxDN100Step.Text = "250";
|
|
textBoxDN150Luz.Text = "6000";
|
|
textBoxDN150Step.Text = "750";
|
|
}
|
|
|
|
private void LoadConfigFromDb()
|
|
{
|
|
try
|
|
{
|
|
mySqlFunctions.initConnection();
|
|
if (!mySqlFunctions.OpenConnection())
|
|
{
|
|
SetDefaultValues();
|
|
return;
|
|
}
|
|
|
|
// DN50
|
|
string q50 = "SELECT TTC_BURN_TIME, TTC_ZAS, TTC_STEP FROM tst_test_config WHERE TTC_DN_TYPE='DN50' LIMIT 1";
|
|
string burnVal = mySqlFunctions.sqlStringValue(q50, "TTC_BURN_TIME");
|
|
string zas50 = mySqlFunctions.sqlStringValue(q50, "TTC_ZAS");
|
|
string step50 = mySqlFunctions.sqlStringValue(q50, "TTC_STEP");
|
|
textBoxBurnTime.Text = string.IsNullOrEmpty(burnVal) ? "15" : burnVal.Replace(',', '.');
|
|
textBoxDN50Luz.Text = string.IsNullOrEmpty(zas50) ? "18000" : zas50;
|
|
textBoxDN50Step.Text = string.IsNullOrEmpty(step50) ? "250" : step50;
|
|
|
|
// DN100
|
|
string q100 = "SELECT TTC_ZAS, TTC_STEP FROM tst_test_config WHERE TTC_DN_TYPE='DN100' LIMIT 1";
|
|
string zas100 = mySqlFunctions.sqlStringValue(q100, "TTC_ZAS");
|
|
string step100 = mySqlFunctions.sqlStringValue(q100, "TTC_STEP");
|
|
textBoxDN100Luz.Text = string.IsNullOrEmpty(zas100) ? "4400" : zas100;
|
|
textBoxDN100Step.Text = string.IsNullOrEmpty(step100) ? "250" : step100;
|
|
|
|
// DN150
|
|
string q150 = "SELECT TTC_ZAS, TTC_STEP FROM tst_test_config WHERE TTC_DN_TYPE='DN150' LIMIT 1";
|
|
string zas150 = mySqlFunctions.sqlStringValue(q150, "TTC_ZAS");
|
|
string step150 = mySqlFunctions.sqlStringValue(q150, "TTC_STEP");
|
|
textBoxDN150Luz.Text = string.IsNullOrEmpty(zas150) ? "6000" : zas150;
|
|
textBoxDN150Step.Text = string.IsNullOrEmpty(step150) ? "750" : step150;
|
|
|
|
mySqlFunctions.CloseConnection();
|
|
}
|
|
catch
|
|
{
|
|
SetDefaultValues();
|
|
}
|
|
}
|
|
|
|
private void SaveConfigToDb()
|
|
{
|
|
try
|
|
{
|
|
mySqlFunctions.initConnection();
|
|
if (!mySqlFunctions.OpenConnection())
|
|
{
|
|
MessageBox.Show("Brak połączenia z bazą danych.", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
|
|
string user = Environment.UserName;
|
|
string dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
string burnVal = textBoxBurnTime.Text.Replace(',', '.');
|
|
|
|
// DN50
|
|
string zas50 = textBoxDN50Luz.Text;
|
|
string step50 = textBoxDN50Step.Text;
|
|
string q50Check = "SELECT COUNT(*) FROM tst_test_config WHERE TTC_DN_TYPE='DN50'";
|
|
int dn50Exists = mySqlFunctions.sqlIntValue(q50Check);
|
|
string q50;
|
|
if (dn50Exists > 0)
|
|
q50 = $"UPDATE tst_test_config SET TTC_BURN_TIME={burnVal}, TTC_ZAS={zas50}, TTC_STEP={step50}, TTC_AUDIT_CU='{user}', TTC_AUDIT_CD='{dt}' WHERE TTC_DN_TYPE='DN50'";
|
|
else
|
|
q50 = $"INSERT INTO tst_test_config (TTC_BURN_TIME, TTC_DN_TYPE, TTC_ZAS, TTC_STEP, TTC_AUDIT_CU, TTC_AUDIT_CD) VALUES ({burnVal}, 'DN50', {zas50}, {step50}, '{user}', '{dt}')";
|
|
mySqlFunctions.Insert(q50);
|
|
|
|
// DN100
|
|
string zas100 = textBoxDN100Luz.Text;
|
|
string step100 = textBoxDN100Step.Text;
|
|
string q100Check = "SELECT COUNT(*) FROM tst_test_config WHERE TTC_DN_TYPE='DN100'";
|
|
int dn100Exists = mySqlFunctions.sqlIntValue(q100Check);
|
|
string q100;
|
|
if (dn100Exists > 0)
|
|
q100 = $"UPDATE tst_test_config SET TTC_BURN_TIME={burnVal}, TTC_ZAS={zas100}, TTC_STEP={step100}, TTC_AUDIT_CU='{user}', TTC_AUDIT_CD='{dt}' WHERE TTC_DN_TYPE='DN100'";
|
|
else
|
|
q100 = $"INSERT INTO tst_test_config (TTC_BURN_TIME, TTC_DN_TYPE, TTC_ZAS, TTC_STEP, TTC_AUDIT_CU, TTC_AUDIT_CD) VALUES ({burnVal}, 'DN100', {zas100}, {step100}, '{user}', '{dt}')";
|
|
mySqlFunctions.Insert(q100);
|
|
|
|
// DN150
|
|
string zas150 = textBoxDN150Luz.Text;
|
|
string step150 = textBoxDN150Step.Text;
|
|
string q150Check = "SELECT COUNT(*) FROM tst_test_config WHERE TTC_DN_TYPE='DN150'";
|
|
int dn150Exists = mySqlFunctions.sqlIntValue(q150Check);
|
|
string q150;
|
|
if (dn150Exists > 0)
|
|
q150 = $"UPDATE tst_test_config SET TTC_BURN_TIME={burnVal}, TTC_ZAS={zas150}, TTC_STEP={step150}, TTC_AUDIT_CU='{user}', TTC_AUDIT_CD='{dt}' WHERE TTC_DN_TYPE='DN150'";
|
|
else
|
|
q150 = $"INSERT INTO tst_test_config (TTC_BURN_TIME, TTC_DN_TYPE, TTC_ZAS, TTC_STEP, TTC_AUDIT_CU, TTC_AUDIT_CD) VALUES ({burnVal}, 'DN150', {zas150}, {step150}, '{user}', '{dt}')";
|
|
mySqlFunctions.Insert(q150);
|
|
|
|
mySqlFunctions.CloseConnection();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show("Błąd zapisu konfiguracji: " + ex.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void testConfig_Load(object sender, EventArgs e)
|
|
{
|
|
textBoxDN50Luz.Enabled = false;
|
|
textBoxDN100Luz.Enabled = false;
|
|
textBoxDN150Luz.Enabled = false;
|
|
|
|
textBoxDN50Step.Enabled = false;
|
|
textBoxDN100Step.Enabled = false;
|
|
textBoxDN150Step.Enabled = false;
|
|
|
|
buttonDefault.Enabled = false;
|
|
}
|
|
}
|
|
}
|