Files
2026-09-03 10:50:01 +02:00

140 lines
5.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 ChoosePumpUnit : Form
{
public ChoosePumpUnit()
{
InitializeComponent();
}
private void LoadCurrentPumpUnit(string srcName = null)
{
bool brakDanychWystapil = false;
string query = "";
dataGridViewPumpUnit.Rows.Clear();
dataGridViewPumpUnit.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewPumpUnit.ColumnCount = 9;
dataGridViewPumpUnit.Columns[0].Name = "id";
dataGridViewPumpUnit.Columns[1].Name = "Typ pompy";
dataGridViewPumpUnit.Columns[2].Name = "Numer pompy";
dataGridViewPumpUnit.Columns[3].Name = "Typ silnika";
dataGridViewPumpUnit.Columns[4].Name = "Numer silnika";
dataGridViewPumpUnit.Columns[5].Name = "Napięcie [V]";
dataGridViewPumpUnit.Columns[6].Name = "Prąd znamionowy [A]";
dataGridViewPumpUnit.Columns[7].Name = "Kabel";
dataGridViewPumpUnit.Columns[8].Name = "Oddział";
dataGridViewPumpUnit.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
dataGridViewPumpUnit.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridViewPumpUnit.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridViewPumpUnit.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridViewPumpUnit.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridViewPumpUnit.Columns[5].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridViewPumpUnit.Columns[6].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridViewPumpUnit.Columns[7].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridViewPumpUnit.Columns[8].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
query = "SELECT * FROM tst_aggregate_remonty, seg_dev_resources LEFT JOIN seg_engines ON ENG_ID=DRS_DEV_ID WHERE TAR_ENG_DRS_ID=DRS_ID AND (TAR_PUP_NAME LIKE '%" + srcName + "%' OR TAR_PUP_SN_NO LIKE '%" + srcName + "%' OR TAR_ENG_NAME LIKE '%" + srcName + "%' OR TAR_ENG_SN_NO LIKE '%" + srcName + "%' OR ENG_VOLTAGE LIKE '%" + srcName + "%' OR ENG_ELECTRICITY LIKE '%" + srcName + "%') AND TAR_DEV_RESOURCES_ID=706 order by TAR_PUP_NAME, TAR_ENG_NAME";
//query = "SELECT * FROM tst_aggregate_remonty,seg_engines WHERE TAR_ENG_ID=ENG_ID AND (TAR_PUP_NAME LIKE '%" + srcName + "%' OR TAR_PUP_SN_NO LIKE '%" + srcName + "%' OR TAR_ENG_NAME LIKE '%" + srcName + "%' OR TAR_ENG_SN_NO LIKE '%" + srcName + "%' OR ENG_VOLTAGE LIKE '%" + srcName + "%' OR ENG_ELECTRICITY LIKE '%" + srcName + "%') AND TAR_DEV_RESOURCES_ID=706 order by TAR_PUP_NAME, TAR_ENG_NAME";
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(query, mySqlFunctions.connection);
MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read())
{
string kabelInfo = dataReader.IsDBNull(10) || string.IsNullOrWhiteSpace(dataReader[10].ToString())
? "Brak danych w bazie"
: dataReader[10].ToString();
int rowIndex = dataGridViewPumpUnit.Rows.Add(
dataReader["TAR_ID"],
dataReader["TAR_PUP_NAME"],
dataReader["TAR_PUP_SN_NO"],
dataReader["TAR_ENG_NAME"],
dataReader["TAR_ENG_SN_NO"],
dataReader["ENG_VOLTAGE"],
dataReader["ENG_ELECTRICITY"],
kabelInfo,
dataReader["TAR_DEPARTMENT"]
);
// Jeśli brak danych o kablu – podświetl wiersz na żółto
if (kabelInfo == "Brak danych w bazie")
{
dataGridViewPumpUnit.Rows[rowIndex].DefaultCellStyle.BackColor = Color.LightYellow;
brakDanychWystapil = true;
}
}
dataReader.Close();
if (brakDanychWystapil)
{
labelKabelComm.Text = "UWAGA! Dla niektórych agregatów brak danych o kablu - należy niezwłocznie przeprowadzić synchronizację z SEGAP Remonty.";
}
else
{
labelKabelComm.Text = string.Empty; // wyczyszczenie komunikatu, jeśli wszystko OK
}
}
private void ChoosePumpUnit_Load(object sender, EventArgs e)
{
mySqlFunctions.initConnection();
if (mySqlFunctions.OpenConnection())
{
LoadCurrentPumpUnit();
mySqlFunctions.CloseConnection();
}
}
private void textBoxSearchPumpUnit_TextChanged(object sender, EventArgs e)
{
mySqlFunctions.initConnection();
if (mySqlFunctions.OpenConnection())
{
LoadCurrentPumpUnit(textBoxSearchPumpUnit.Text);
mySqlFunctions.CloseConnection();
}
}
private void dataGridViewPumpUnit_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
try
{
int rowIndex = e.RowIndex;
DataGridViewRow row = dataGridViewPumpUnit.Rows[rowIndex];
vGlobal.ape_aggregate_id = Convert.ToInt32(row.Cells[0].Value);
this.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void buttonClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}