//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "frmZmenitUT.h"
#include "Katalog.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::btnKonecUTClick(TObject *Sender)
{
Edit1UT -> Clear();
Edit2UT -> Clear();
Edit3UT -> Clear();
Edit4UT -> Clear();
Memo1UT -> Clear();

Form2 -> Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormShow(TObject *Sender)
{
Memo1UT -> Clear();

AnsiString zmenitUT;
AnsiString pomocna = -10;

if(Form1 -> DBListBox2 -> ItemIndex!= -1)

zmenitUT = Form1 -> DBListBox2 -> Items -> Strings[Form1 -> DBListBox2 -> ItemIndex];

else return;

DataSource1 -> DataSet = Query1;

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Nazev_soucastky FROM Unipolarni_tranzistory WHERE Nazev_soucastky = '"+zmenitUT+"'");
Query1 -> Open();

Edit1UT -> Text = DataSource1->DataSet->FieldByName("Nazev_soucastky")->AsString;

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Napeti_drain_source FROM Unipolarni_tranzistory WHERE Nazev_soucastky = '"+zmenitUT+"'");
Query1 -> Open();

Edit2UT -> Text = DataSource1->DataSet->FieldByName("Napeti_drain_source")-> AsString;

if( Edit2UT -> Text == pomocna)
 {
 Edit2UT -> Text = "";
 }

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Proud_Id FROM Unipolarni_tranzistory WHERE Nazev_soucastky = '"+zmenitUT+"'");
Query1 -> Open();

Edit3UT -> Text = DataSource1->DataSet->FieldByName("Proud_Id")->AsString;

if( Edit3UT -> Text == pomocna)
 {
 Edit3UT -> Text = "";
 }

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Max_Vykonova_ztrata FROM Unipolarni_tranzistory WHERE Nazev_soucastky = '"+zmenitUT+"'");
Query1 -> Open();

Edit4UT -> Text = DataSource1->DataSet->FieldByName("Max_vykonova_ztrata")->AsString;

if( Edit4UT -> Text == pomocna)
 {
 Edit4UT -> Text = "";
 }

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Popis FROM Unipolarni_tranzistory WHERE Nazev_soucastky = '"+zmenitUT+"'");
Query1 -> Open();

Memo1UT -> Text = DataSource1->DataSet->FieldByName("Popis")->AsString;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::btnPridejUTClick(TObject *Sender)
{
AnsiString a,b,c,d,e,TypUT;
AnsiString edity[] = {Edit2UT -> Text, Edit3UT -> Text, Edit4UT -> Text};
AnsiString promenne[] = {b,c,d};

a = Edit1UT -> Text;
b = Edit2UT -> Text;
c = Edit3UT -> Text;
d = Edit4UT -> Text;
e = Memo1UT -> Text;

for (int i=0; i<3; i++)
 {
 if(edity[i] == "")
   {
   promenne[i] = -10;
   }
 else
   promenne[i] = edity[i];
 }

if(Edit1UT -> Text =="")
 ShowMessage("Nezadali jste název součástky.");
else


TypUT = ComboBox1ZmenUT -> Items -> Strings[ComboBox1ZmenUT -> ItemIndex];

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("UPDATE Unipolarni_tranzistory SET Nazev_soucastky = '"+a+"', Napeti_drain_source = "+promenne[0]+", Proud_Id = "+promenne[1]+", Max_vykonova_ztrata = "+promenne[2]+", Popis = '"+e+"', Typ = '"+TypUT+"' WHERE Nazev_soucastky = '"+a+"'");
Query1 -> ExecSQL();
}
//---------------------------------------------------------------------------
