347 lines
18 KiB
C#
347 lines
18 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 AggregateStockEditForm : Form
|
|
{
|
|
public int apeID = 0;
|
|
public int pumpDevID = 0;
|
|
public int motorDevID = 0;
|
|
|
|
public string selectedStatus = "";
|
|
public string selectedCompanies = "";
|
|
|
|
public static int newPumpDevID = 0;
|
|
public static string newPumpDevName = "";
|
|
public static string newPumpDevSN = "";
|
|
public static string newPumpDevQn = "";
|
|
public static string newPumpDevHn = "";
|
|
|
|
public static int newMotorDevID = 0;
|
|
public static string newMotorDevName = "";
|
|
public static string newMotorDevSN = "";
|
|
public static string newMotorDevV = "";
|
|
public static string newMotorDevPe = "";
|
|
|
|
private int testID = 0;
|
|
|
|
public string formName = "";
|
|
public AggregateStockEditForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void AggregateStockEditForm_Load(object sender, EventArgs e)
|
|
{
|
|
this.Text += formName;
|
|
LoadStatuses();
|
|
LoadCompanies();
|
|
if (apeID>0)
|
|
{
|
|
newPumpDevID = pumpDevID;
|
|
newMotorDevID = motorDevID;
|
|
|
|
LoadConnectPump();
|
|
LoadConnectMotor();
|
|
buttonSave.Text = "Aktualizuj";
|
|
|
|
string getTestID = mySqlFunctions.sqlStringValue("select max(TST_ID) TST_ID from tst_tests where TST_PUP_NAME='"+ textBoxPumpName.Text + "' and TST_PUP_SN_NO='" + textBoxPumpSN.Text + "' and TST_ENG_NAME='" + textBoxMotorName.Text + "' and TST_ENG_SN_NO='" + textBoxMotorSN.Text + "'", "TST_ID");
|
|
|
|
if (getTestID.Length>0)
|
|
testID = Convert.ToInt32(getTestID);
|
|
else
|
|
{
|
|
testID = 0;
|
|
linkLabelProtokol.Visible = false;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
linkLabelHistory.Visible = false;
|
|
linkLabelDelConn.Visible = false;
|
|
linkLabelProtokol.Visible = false;
|
|
}
|
|
}
|
|
|
|
private void LoadStatuses()
|
|
{
|
|
mySqlFunctions.initConnection();
|
|
if (mySqlFunctions.OpenConnection())
|
|
{
|
|
int index = 0;
|
|
// Ładuje listę dostępnych Pomp
|
|
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select DIC_ID,DIC_POL_LANG from sys_dictionaries where DIC_TYPE_ID=1 order by DIC_POL_LANG", mySqlFunctions.connection);
|
|
MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader();
|
|
while (dataReader.Read())
|
|
{
|
|
comboBoxStatus.Items.Insert(index, dataReader["DIC_POL_LANG"].ToString());
|
|
|
|
// zaznacza jako selected
|
|
if (dataReader["DIC_POL_LANG"].ToString() == selectedStatus)
|
|
comboBoxStatus.SelectedIndex = comboBoxStatus.Items.Count - 1;
|
|
|
|
index++;
|
|
|
|
}
|
|
dataReader.Close();
|
|
mySqlFunctions.CloseConnection();
|
|
}
|
|
|
|
}
|
|
|
|
private void LoadCompanies()
|
|
{
|
|
mySqlFunctions.initConnection();
|
|
if (mySqlFunctions.OpenConnection())
|
|
{
|
|
int index = 0;
|
|
// Ładuje listę dostępnych Pomp
|
|
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select * from sys_participants order by PRT_NAME", mySqlFunctions.connection);
|
|
MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader();
|
|
while (dataReader.Read())
|
|
{
|
|
comboBoxCompany.Items.Insert(index, dataReader["PRT_DESCRIPTION"].ToString());
|
|
|
|
if (dataReader["PRT_DESCRIPTION"].ToString() == selectedCompanies)
|
|
comboBoxCompany.SelectedIndex = comboBoxCompany.Items.Count - 1;
|
|
|
|
index++;
|
|
}
|
|
dataReader.Close();
|
|
mySqlFunctions.CloseConnection();
|
|
}
|
|
}
|
|
|
|
|
|
private void LoadConnectPump()
|
|
{
|
|
try
|
|
{
|
|
mySqlFunctions.initConnection();
|
|
if (mySqlFunctions.OpenConnection())
|
|
{
|
|
// Ładuje listę dostępnych Pomp
|
|
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select * from seg_dev_resources,seg_pumps where DRS_DEV_TYPE=10 and DRS_DEV_ID=PUP_ID and DRS_ID=" + pumpDevID.ToString(), mySqlFunctions.connection);
|
|
MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader();
|
|
while (dataReader.Read())
|
|
{
|
|
textBoxPumpQn.Text = dataReader["PUP_Q_N"].ToString();
|
|
textBoxPumpHn.Text = dataReader["PUP_H_P"].ToString();
|
|
|
|
}
|
|
dataReader.Close();
|
|
mySqlFunctions.CloseConnection();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void LoadConnectMotor()
|
|
{
|
|
try
|
|
{
|
|
mySqlFunctions.initConnection();
|
|
if (mySqlFunctions.OpenConnection())
|
|
{
|
|
// Ładuje listę dostępnych Pomp
|
|
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select * from seg_dev_resources,seg_engines where DRS_DEV_TYPE=11 and DRS_DEV_ID=ENG_ID and DRS_ID=" + motorDevID.ToString(), mySqlFunctions.connection);
|
|
MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader();
|
|
while (dataReader.Read())
|
|
{
|
|
textBoxMotorV.Text = dataReader["ENG_VOLTAGE"].ToString();
|
|
textBoxMotorPower.Text = dataReader["ENG_POWER"].ToString();
|
|
}
|
|
dataReader.Close();
|
|
mySqlFunctions.CloseConnection();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void buttonCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
void pictureBoxSearchAggPump_FormClosed(object sender, FormClosedEventArgs e)
|
|
{
|
|
if (newPumpDevID>0)
|
|
{
|
|
textBoxPumpName.Text = newPumpDevName;
|
|
textBoxPumpSN.Text = newPumpDevSN;
|
|
textBoxPumpQn.Text = newPumpDevQn;
|
|
textBoxPumpHn.Text = newPumpDevHn;
|
|
}
|
|
}
|
|
void pictureBoxSearchAggMotor_FormClosed(object sender, FormClosedEventArgs e)
|
|
{
|
|
if (newMotorDevID>0)
|
|
{
|
|
textBoxMotorName.Text = newMotorDevName;
|
|
textBoxMotorSN.Text = newMotorDevSN;
|
|
textBoxMotorV.Text = newMotorDevV;
|
|
textBoxMotorPower.Text = newMotorDevPe;
|
|
}
|
|
}
|
|
|
|
private void pictureBoxSearchPump_Click(object sender, EventArgs e)
|
|
{
|
|
AggregateStockChPumpForm ascpForm = new AggregateStockChPumpForm();
|
|
ascpForm.FormClosed += new FormClosedEventHandler(pictureBoxSearchAggPump_FormClosed);
|
|
ascpForm.ShowDialog();
|
|
}
|
|
|
|
private void pictureBox1_Click(object sender, EventArgs e)
|
|
{
|
|
AggregateStockChMotorForm ascmForm = new AggregateStockChMotorForm();
|
|
ascmForm.FormClosed += new FormClosedEventHandler(pictureBoxSearchAggMotor_FormClosed);
|
|
ascmForm.ShowDialog();
|
|
}
|
|
|
|
private void buttonSave_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (newPumpDevID <= 0) newPumpDevID = pumpDevID;
|
|
if (newMotorDevID <= 0) newMotorDevID = motorDevID;
|
|
|
|
string statID = mySqlFunctions.sqlStringValue("select DIC_ID from sys_dictionaries where DIC_POL_LANG='" + comboBoxStatus.SelectedItem.ToString() + "'", "DIC_ID");
|
|
string partID = mySqlFunctions.sqlStringValue("select PRT_ID from sys_participants where PRT_DESCRIPTION ='" + comboBoxCompany.SelectedItem.ToString() + "'", "PRT_ID");
|
|
|
|
string pumpID = mySqlFunctions.sqlStringValue("select PUP_ID from seg_dev_resources,seg_pumps where DRS_DEV_TYPE=10 and DRS_DEV_ID=PUP_ID and DRS_ID=" + newPumpDevID.ToString(), "PUP_ID");
|
|
string engID = mySqlFunctions.sqlStringValue("select ENG_ID from seg_dev_resources,seg_engines where DRS_DEV_TYPE=11 and DRS_DEV_ID=ENG_ID and DRS_ID=" + newMotorDevID.ToString(), "ENG_ID");
|
|
|
|
if (apeID>0)
|
|
{
|
|
mySqlFunctions.initConnection();
|
|
if (mySqlFunctions.OpenConnection())
|
|
{
|
|
// aktualizuje agregat
|
|
// ===========================================
|
|
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("UPDATE seg_aggregate_pup_eng SET APE_PUP_ID="+ pumpID + ",APE_PUP_DRS_ID="+ newPumpDevID.ToString() + ",APE_PUP_NAME='"+ textBoxPumpName.Text + "',APE_PUP_NO='" + textBoxPumpSN.Text + "',APE_ENG_ID="+ engID + ",APE_ENG_DRS_ID="+ newMotorDevID.ToString() + ",APE_ENG_NAME='"+ textBoxMotorName.Text + "',APE_ENG_NO='" + textBoxMotorSN.Text + "',APE_WLL_NAME='"+ textBoxWellName.Text + "',APE_AUDIT_CU='"+ vGlobal.tst_login_name + "',APE_AUDIT_CD=now(),APE_PRT_ID="+ partID + ",APE_DESCRIPTION='"+ richTextBoxUwagi.Text + "' WHERE APE_ID=" + apeID.ToString(), mySqlFunctions.connection);
|
|
cmd.ExecuteNonQuery();
|
|
// tabela historyczna
|
|
MySql.Data.MySqlClient.MySqlCommand his = new MySql.Data.MySqlClient.MySqlCommand("insert into seg_aggregate_pup_eng_his select * from seg_aggregate_pup_eng WHERE APE_ID=" + apeID.ToString(), mySqlFunctions.connection);
|
|
his.ExecuteNonQuery();
|
|
// ===========================================
|
|
|
|
// aktualizuje pompe
|
|
// ===========================================
|
|
MySql.Data.MySqlClient.MySqlCommand cmd1 = new MySql.Data.MySqlClient.MySqlCommand("UPDATE seg_dev_resources SET DRS_STATUS_DIC_ID="+ statID + ",DRS_AUDIT_USR='"+ partID + "',DRS_AUDIT_DATE=now() WHERE DRS_ID=" + newPumpDevID.ToString(), mySqlFunctions.connection);
|
|
cmd1.ExecuteNonQuery();
|
|
// tabela historyczna
|
|
MySql.Data.MySqlClient.MySqlCommand his1 = new MySql.Data.MySqlClient.MySqlCommand("insert into seg_dev_resources_his select * from seg_dev_resources WHERE DRS_ID=" + newPumpDevID.ToString(), mySqlFunctions.connection);
|
|
his1.ExecuteNonQuery();
|
|
// ===========================================
|
|
|
|
// aktualizuje silnik
|
|
// ===========================================
|
|
MySql.Data.MySqlClient.MySqlCommand cmd2 = new MySql.Data.MySqlClient.MySqlCommand("UPDATE seg_dev_resources SET DRS_STATUS_DIC_ID=" + statID + ",DRS_AUDIT_USR='" + partID + "',DRS_AUDIT_DATE=now() WHERE DRS_ID=" + newMotorDevID.ToString(), mySqlFunctions.connection);
|
|
cmd2.ExecuteNonQuery();
|
|
// tabela historyczna
|
|
MySql.Data.MySqlClient.MySqlCommand his2 = new MySql.Data.MySqlClient.MySqlCommand("insert into seg_dev_resources_his select * from seg_dev_resources WHERE DRS_ID=" + newMotorDevID.ToString(), mySqlFunctions.connection);
|
|
his2.ExecuteNonQuery();
|
|
// ===========================================
|
|
|
|
mySqlFunctions.CloseConnection();
|
|
this.Close();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (newPumpDevID > 0 && newMotorDevID > 0)
|
|
{
|
|
|
|
mySqlFunctions.initConnection();
|
|
if (mySqlFunctions.OpenConnection())
|
|
{
|
|
// dodaje agregat
|
|
// ===========================================
|
|
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("INSERT INTO seg_aggregate_pup_eng SET APE_PUP_ID=" + pumpID + ",APE_PUP_DRS_ID=" + newPumpDevID.ToString() + ",APE_PUP_NAME='" + newPumpDevName + "',APE_PUP_NO='" + newPumpDevSN + "',APE_ENG_ID=" + engID + ",APE_ENG_DRS_ID=" + newMotorDevID.ToString() + ",APE_ENG_NAME='" + newMotorDevName + "',APE_ENG_NO='" + newMotorDevSN + "',APE_WLL_NAME='" + textBoxWellName.Text + "',APE_AUDIT_CU='" + vGlobal.tst_login_name + "',APE_AUDIT_CD=now(),APE_PRT_ID=" + partID + ",APE_DESCRIPTION='" + richTextBoxUwagi.Text + "'", mySqlFunctions.connection);
|
|
cmd.ExecuteNonQuery();
|
|
// tabela historyczna
|
|
MySql.Data.MySqlClient.MySqlCommand his = new MySql.Data.MySqlClient.MySqlCommand("insert into seg_aggregate_pup_eng_his select * from seg_aggregate_pup_eng where APE_ID=(select max(APE_ID) from seg_aggregate_pup_eng)", mySqlFunctions.connection);
|
|
his.ExecuteNonQuery();
|
|
// ===========================================
|
|
|
|
// aktualizuje pompe
|
|
// ===========================================
|
|
MySql.Data.MySqlClient.MySqlCommand cmd1 = new MySql.Data.MySqlClient.MySqlCommand("UPDATE seg_dev_resources SET DRS_STATUS_DIC_ID=" + statID + ",DRS_AUDIT_USR='" + partID + "',DRS_AUDIT_DATE=now() WHERE DRS_ID=" + newPumpDevID.ToString(), mySqlFunctions.connection);
|
|
cmd1.ExecuteNonQuery();
|
|
// tabela historyczna
|
|
MySql.Data.MySqlClient.MySqlCommand his1 = new MySql.Data.MySqlClient.MySqlCommand("insert into seg_dev_resources_his select * from seg_dev_resources WHERE DRS_ID=" + newPumpDevID.ToString(), mySqlFunctions.connection);
|
|
his1.ExecuteNonQuery();
|
|
// ===========================================
|
|
|
|
// aktualizuje silnik
|
|
// ===========================================
|
|
MySql.Data.MySqlClient.MySqlCommand cmd2 = new MySql.Data.MySqlClient.MySqlCommand("UPDATE seg_dev_resources SET DRS_STATUS_DIC_ID=" + statID + ",DRS_AUDIT_USR='" + partID + "',DRS_AUDIT_DATE=now() WHERE DRS_ID=" + newMotorDevID.ToString(), mySqlFunctions.connection);
|
|
cmd2.ExecuteNonQuery();
|
|
// tabela historyczna
|
|
MySql.Data.MySqlClient.MySqlCommand his2 = new MySql.Data.MySqlClient.MySqlCommand("insert into seg_dev_resources_his select * from seg_dev_resources WHERE DRS_ID=" + newMotorDevID.ToString(), mySqlFunctions.connection);
|
|
his2.ExecuteNonQuery();
|
|
// ===========================================
|
|
this.Close();
|
|
mySqlFunctions.CloseConnection();
|
|
}
|
|
}
|
|
else
|
|
MessageBox.Show("Przed zapisem należy wybrać dostępną pompę oraz silnik.");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show("Nie wybrano statusu agregatu lub kontrahenta.");
|
|
}
|
|
|
|
}
|
|
|
|
private void linkLabelDelConn_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
|
{
|
|
if (MessageBox.Show("UWAGA!\nCzy na pewno chcesz usunąć połączenie pompa/silnik?", "Potwierdzenie usunięcia z bazy", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
mySqlFunctions.initConnection();
|
|
if (mySqlFunctions.OpenConnection())
|
|
{
|
|
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("UPDATE seg_aggregate_pup_eng SET APE_PUP_ID=NULL,APE_PUP_DRS_ID=NULL,APE_PUP_NAME=NULL,APE_PUP_NO=NULL,APE_ENG_ID=NULL,APE_ENG_DRS_ID=NULL,APE_ENG_NAME=NULL,APE_ENG_NO=NULL,APE_AUDIT_CU='janek',APE_AUDIT_CD=now() WHERE APE_ID=" + apeID.ToString(), mySqlFunctions.connection);
|
|
cmd.ExecuteNonQuery();
|
|
|
|
mySqlFunctions.CloseConnection();
|
|
}
|
|
this.Close();
|
|
}
|
|
|
|
}
|
|
|
|
private void linkLabelHistory_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
|
{
|
|
AggregateStockHistoryForm ashForm = new AggregateStockHistoryForm();
|
|
ashForm.apeID = apeID;
|
|
ashForm.ShowDialog();
|
|
}
|
|
|
|
private void linkLabelProtokol_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
|
{
|
|
fullTestReportForm.spm_test_id = testID;
|
|
fullTestReportForm formfullTestReportForm = new fullTestReportForm();
|
|
formfullTestReportForm.ShowDialog();
|
|
|
|
}
|
|
}
|
|
}
|