Initial commit
This commit is contained in:
@@ -0,0 +1,450 @@
|
||||
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 motorsCatalogueAdd : Form
|
||||
{
|
||||
public int silnID;
|
||||
public string selectedProd = "";
|
||||
public int selectedProdID = 0;
|
||||
|
||||
public motorsCatalogueAdd()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void motorsCatalogueAdd_Load(object sender, EventArgs e)
|
||||
{
|
||||
// Dla RAMBu
|
||||
buttonDelete.Visible = false;
|
||||
buttonSave.Visible = false;
|
||||
|
||||
loadProducent();
|
||||
if (silnID>0)
|
||||
{
|
||||
//wpisuje odpowiednie parametry dla poszczególnych pól
|
||||
mySqlFunctions.initConnection();
|
||||
if (mySqlFunctions.OpenConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select * from seg_engines left join seg_manufacturers on MCF_ID=ENG_MCF_ID where ENG_ID=" + silnID.ToString(), mySqlFunctions.connection);
|
||||
MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader();
|
||||
while (dataReader.Read())
|
||||
{
|
||||
textBoxTypSilnika.Text = dataReader["ENG_NAME"].ToString();
|
||||
textBoxMoc.Text = dataReader["ENG_POWER"].ToString();
|
||||
textBoxNapiecie.Text = dataReader["ENG_VOLTAGE"].ToString();
|
||||
textBoxPrad.Text = dataReader["ENG_ELECTRICITY"].ToString();
|
||||
textBoxETA.Text = dataReader["ENG_ETA"].ToString();
|
||||
textBoxCosFi.Text = dataReader["ENG_COS_FI"].ToString();
|
||||
textBoxObroty.Text = dataReader["ENG_RPM"].ToString();
|
||||
textBoxDlugosc.Text = dataReader["ENG_LENGTH"].ToString();
|
||||
textBoxMasa.Text = dataReader["ENG_WEIGHT"].ToString();
|
||||
textBoxSrednica.Text = dataReader["ENG_DIAMETER"].ToString();
|
||||
textBoxPrzewody.Text = dataReader["ENG_WIRES"].ToString();
|
||||
|
||||
if (dataReader["MCF_ID"].ToString().Length>0)
|
||||
{
|
||||
selectedProdID = Convert.ToInt32(dataReader["MCF_ID"].ToString());
|
||||
//selectedProd = dataReader["MCF_NAME"].ToString();
|
||||
}
|
||||
|
||||
}
|
||||
mySqlFunctions.CloseConnection();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonDelete.Visible = false;
|
||||
}
|
||||
|
||||
if (checkFillFields()) buttonSave.Enabled = true;
|
||||
else buttonSave.Enabled = false;
|
||||
|
||||
loadPumpStockConnection();
|
||||
}
|
||||
|
||||
public void loadProducent()
|
||||
{
|
||||
this.comboBoxProd.Items.Clear();
|
||||
|
||||
mySqlFunctions.initConnection();
|
||||
if (mySqlFunctions.OpenConnection())
|
||||
{
|
||||
int index = 0;
|
||||
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select MCF_ID,MCF_NAME from seg_manufacturers order by MCF_NAME", mySqlFunctions.connection);
|
||||
MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader();
|
||||
while (dataReader.Read())
|
||||
{
|
||||
comboBoxProd.Items.Insert(index, dataReader["MCF_NAME"].ToString());
|
||||
if (dataReader["MCF_NAME"].ToString() == selectedProd)
|
||||
comboBoxProd.SelectedIndex = comboBoxProd.Items.Count - 1;
|
||||
index++;
|
||||
|
||||
|
||||
}
|
||||
mySqlFunctions.CloseConnection();
|
||||
//comboBoxStanowisko.SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
//mysql_query("INSERT INTO seg_engines SET ENG_MCF_ID=".$_POST['inEngNManufID'].",ENG_NAME='".$_POST['inEngName']."',ENG_VOLTAGE=".str_replace(",",".",$_POST['inEngVolt']).",ENG_LENGTH=".str_replace(",",".",$_POST['inEngDl']).",ENG_WEIGHT=".str_replace(",",".",$_POST['inEngMass']).",ENG_DIAMETER=".str_replace(",",".",$_POST['inEngDiam']).",ENG_WIRES='".str_replace(",",".",$_POST['inEngPrzew'])."',ENG_POWER=".str_replace(",",".",$_POST['inEngPower']).",ENG_ELECTRICITY=".str_replace(",",".",$_POST['inEngPrad']).",ENG_RPM=".str_replace(",",".",$_POST['inEngObrot']).",ENG_COS_FI=".str_replace(",",".",$_POST['inEngCosFi']).",ENG_ETA=".str_replace(",",".",$_POST['inEngSpraw']).",ENG_STATUS='1'");
|
||||
string query_insert;
|
||||
string prodID = "9";
|
||||
|
||||
try
|
||||
{
|
||||
prodID = mySqlFunctions.sqlStringValue("select MCF_ID from seg_manufacturers where MCF_NAME='" + comboBoxProd.SelectedItem.ToString() + "'", "MCF_ID");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
|
||||
mySqlFunctions.initConnection();
|
||||
if (mySqlFunctions.OpenConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
if (silnID > 0)
|
||||
query_insert = "update seg_engines SET ENG_MCF_ID='" + prodID
|
||||
+ "',ENG_NAME='" + textBoxTypSilnika.Text
|
||||
+ "',ENG_VOLTAGE='" + textBoxNapiecie.Text.Replace(",", ".")
|
||||
+ "',ENG_LENGTH='" + textBoxDlugosc.Text.Replace(",", ".")
|
||||
+ "',ENG_WEIGHT='" + textBoxMasa.Text.Replace(",", ".")
|
||||
+ "',ENG_DIAMETER='" + textBoxSrednica.Text.Replace(",", ".")
|
||||
+ "',ENG_WIRES='" + textBoxPrzewody.Text
|
||||
+ "',ENG_POWER='" + textBoxMoc.Text.Replace(",", ".")
|
||||
+ "',ENG_ELECTRICITY='" + textBoxPrad.Text.Replace(",", ".")
|
||||
+ "',ENG_RPM='" + textBoxObroty.Text.Replace(",", ".")
|
||||
+ "',ENG_COS_FI='" + textBoxCosFi.Text.Replace(",", ".")
|
||||
+ "',ENG_ETA='" + textBoxETA.Text.Replace(",", ".")
|
||||
+ "',ENG_STATUS='1' where ENG_ID=" + silnID.ToString();
|
||||
|
||||
else
|
||||
query_insert = "INSERT INTO seg_engines SET ENG_MCF_ID='" + prodID
|
||||
+ "',ENG_NAME='" + textBoxTypSilnika.Text
|
||||
+ "',ENG_VOLTAGE='" + textBoxNapiecie.Text.Replace(",", ".")
|
||||
+ "',ENG_LENGTH='" + textBoxDlugosc.Text.Replace(",", ".")
|
||||
+ "',ENG_WEIGHT='" + textBoxMasa.Text.Replace(",", ".")
|
||||
+ "',ENG_DIAMETER='" + textBoxSrednica.Text.Replace(",", ".")
|
||||
+ "',ENG_WIRES='" + textBoxPrzewody.Text
|
||||
+ "',ENG_POWER='" + textBoxMoc.Text.Replace(",", ".")
|
||||
+ "',ENG_ELECTRICITY='" + textBoxPrad.Text.Replace(",", ".")
|
||||
+ "',ENG_RPM='" + textBoxObroty.Text.Replace(",", ".")
|
||||
+ "',ENG_COS_FI='" + textBoxCosFi.Text.Replace(",", ".")
|
||||
+ "',ENG_ETA='" + textBoxETA.Text.Replace(",", ".")
|
||||
+ "',ENG_STATUS='1'";
|
||||
|
||||
|
||||
MySql.Data.MySqlClient.MySqlCommand cmd_01 = new MySql.Data.MySqlClient.MySqlCommand(query_insert, mySqlFunctions.connection);
|
||||
cmd_01.ExecuteNonQuery();
|
||||
|
||||
mySqlFunctions.CloseConnection();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.Close();
|
||||
|
||||
}
|
||||
|
||||
private void textBoxMoc_Leave(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
textBoxMoc.Text = textBoxMoc.Text.Replace(".", ",");
|
||||
double myInt;
|
||||
bool isNumerical = double.TryParse(textBoxMoc.Text, out myInt);
|
||||
|
||||
if (!isNumerical && textBoxMoc.Text.Length > 0)
|
||||
{
|
||||
MessageBox.Show("Wprowadzona wartość musi być liczbą!\nWprowadź proszę ponownie.");
|
||||
textBoxMoc.Focus();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void textBoxNapiecie_Leave(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
textBoxNapiecie.Text = textBoxNapiecie.Text.Replace(".", ",");
|
||||
double myInt;
|
||||
bool isNumerical = double.TryParse(textBoxNapiecie.Text, out myInt);
|
||||
|
||||
if (!isNumerical && textBoxNapiecie.Text.Length > 0)
|
||||
{
|
||||
MessageBox.Show("Wprowadzona wartość musi być liczbą!\nWprowadź proszę ponownie.");
|
||||
textBoxNapiecie.Focus();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void textBoxPrad_Leave(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
textBoxPrad.Text = textBoxPrad.Text.Replace(".", ",");
|
||||
double myInt;
|
||||
bool isNumerical = double.TryParse(textBoxPrad.Text, out myInt);
|
||||
|
||||
if (!isNumerical && textBoxPrad.Text.Length > 0)
|
||||
{
|
||||
MessageBox.Show("Wprowadzona wartość musi być liczbą!\nWprowadź proszę ponownie.");
|
||||
textBoxPrad.Focus();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void textBoxETA_Leave(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
textBoxETA.Text = textBoxETA.Text.Replace(".", ",");
|
||||
double myInt;
|
||||
bool isNumerical = double.TryParse(textBoxETA.Text, out myInt);
|
||||
|
||||
if (!isNumerical && textBoxETA.Text.Length > 0)
|
||||
{
|
||||
MessageBox.Show("Wprowadzona wartość musi być liczbą!\nWprowadź proszę ponownie.");
|
||||
textBoxETA.Focus();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Convert.ToDouble(textBoxETA.Text) >1)
|
||||
{
|
||||
MessageBox.Show("Wprowadzona wartość nie może być większa od 1!\nWprowadź proszę ponownie.");
|
||||
textBoxETA.Focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void textBoxCosFi_Leave(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
textBoxCosFi.Text = textBoxCosFi.Text.Replace(".", ",");
|
||||
double myInt;
|
||||
bool isNumerical = double.TryParse(textBoxCosFi.Text, out myInt);
|
||||
|
||||
if (!isNumerical && textBoxCosFi.Text.Length > 0)
|
||||
{
|
||||
MessageBox.Show("Wprowadzona wartość musi być liczbą!\nWprowadź proszę ponownie.");
|
||||
textBoxCosFi.Focus();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Convert.ToDouble(textBoxCosFi.Text) > 1)
|
||||
{
|
||||
MessageBox.Show("Wprowadzona wartość nie może być większa od 1!\nWprowadź proszę ponownie.");
|
||||
textBoxCosFi.Focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void textBoxObroty_Leave(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
textBoxObroty.Text = textBoxObroty.Text.Replace(".", ",");
|
||||
double myInt;
|
||||
bool isNumerical = double.TryParse(textBoxObroty.Text, out myInt);
|
||||
|
||||
if (!isNumerical && textBoxObroty.Text.Length > 0)
|
||||
{
|
||||
MessageBox.Show("Wprowadzona wartość musi być liczbą!\nWprowadź proszę ponownie.");
|
||||
textBoxObroty.Focus();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void textBoxDlugosc_Leave(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
textBoxDlugosc.Text = textBoxDlugosc.Text.Replace(".", ",");
|
||||
double myInt;
|
||||
bool isNumerical = double.TryParse(textBoxDlugosc.Text, out myInt);
|
||||
|
||||
if (!isNumerical && textBoxDlugosc.Text.Length > 0)
|
||||
{
|
||||
MessageBox.Show("Wprowadzona wartość musi być liczbą!\nWprowadź proszę ponownie.");
|
||||
textBoxDlugosc.Focus();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void textBoxMasa_Leave(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
textBoxMasa.Text = textBoxMasa.Text.Replace(".", ",");
|
||||
double myInt;
|
||||
bool isNumerical = double.TryParse(textBoxMasa.Text, out myInt);
|
||||
|
||||
if (!isNumerical && textBoxMasa.Text.Length > 0)
|
||||
{
|
||||
MessageBox.Show("Wprowadzona wartość musi być liczbą!\nWprowadź proszę ponownie.");
|
||||
textBoxMasa.Focus();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void textBoxSrednica_Leave(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
textBoxSrednica.Text = textBoxSrednica.Text.Replace(".", ",");
|
||||
double myInt;
|
||||
bool isNumerical = double.TryParse(textBoxSrednica.Text, out myInt);
|
||||
|
||||
if (!isNumerical && textBoxSrednica.Text.Length > 0)
|
||||
{
|
||||
MessageBox.Show("Wprowadzona wartość musi być liczbą!\nWprowadź proszę ponownie.");
|
||||
textBoxSrednica.Focus();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
|
||||
private bool checkFillFields()
|
||||
{
|
||||
bool isCloseActive = false;
|
||||
|
||||
if (
|
||||
textBoxTypSilnika.Text.Length > 0
|
||||
&&
|
||||
textBoxMoc.Text.Length > 0
|
||||
&&
|
||||
textBoxNapiecie.Text.Length > 0
|
||||
&&
|
||||
textBoxPrad.Text.Length > 0
|
||||
&&
|
||||
textBoxETA.Text.Length > 0
|
||||
&&
|
||||
textBoxCosFi.Text.Length > 0
|
||||
)
|
||||
isCloseActive = true;
|
||||
|
||||
return isCloseActive;
|
||||
}
|
||||
|
||||
private void buttonClose_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void textBoxTypSilnika_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (checkFillFields()) buttonSave.Enabled = true;
|
||||
}
|
||||
|
||||
private void comboBoxProd_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (checkFillFields()) buttonSave.Enabled = true;
|
||||
}
|
||||
|
||||
private void textBoxMoc_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (checkFillFields()) buttonSave.Enabled = true;
|
||||
}
|
||||
|
||||
private void textBoxNapiecie_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (checkFillFields()) buttonSave.Enabled = true;
|
||||
}
|
||||
|
||||
private void textBoxPrad_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (checkFillFields()) buttonSave.Enabled = true;
|
||||
}
|
||||
|
||||
private void textBoxETA_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (checkFillFields()) buttonSave.Enabled = true;
|
||||
}
|
||||
|
||||
private void textBoxCosFi_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (checkFillFields()) buttonSave.Enabled = true;
|
||||
}
|
||||
|
||||
|
||||
// sprawdzanie, czy nie ma powiązanego silnika w stanach
|
||||
//
|
||||
private void loadPumpStockConnection()
|
||||
{
|
||||
int ile = 0;
|
||||
|
||||
mySqlFunctions.initConnection();
|
||||
if (mySqlFunctions.OpenConnection())
|
||||
{
|
||||
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select count(*) ILE from seg_dev_resources where DRS_DEV_TYPE=11 and DRS_DEV_ID=" + silnID.ToString(), mySqlFunctions.connection);
|
||||
MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader();
|
||||
while (dataReader.Read())
|
||||
{
|
||||
try
|
||||
{
|
||||
ile = Convert.ToInt32(dataReader["ILE"].ToString());
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
mySqlFunctions.CloseConnection();
|
||||
}
|
||||
|
||||
if (ile > 0) buttonDelete.Enabled = false;
|
||||
}
|
||||
|
||||
private void buttonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (silnID <= 0) silnID = 0;
|
||||
|
||||
if (MessageBox.Show("UWAGA!\nProces nieodwracalny.\nCzy na pewno chcesz usunąć silnik z katalogu?", "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("DELETE FROM seg_engines WHERE ENG_ID=" + silnID.ToString(), mySqlFunctions.connection);
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
mySqlFunctions.CloseConnection();
|
||||
}
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user