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

#include <vcl.h>
#pragma hdrstop

#include "ZmenitTA.h"
#include "Katalog.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmZmenitTA *frmZmenitTA;
//---------------------------------------------------------------------------
__fastcall TfrmZmenitTA::TfrmZmenitTA(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmZmenitTA::FormShow(TObject *Sender)
{
Memo1TA -> Clear();

AnsiString ZmenitTA;
AnsiString Sym, Nesym;
AnsiString pomocna = -10;
if(Form1 -> DBListBox5 -> ItemIndex!= -1)

ZmenitTA = Form1 -> DBListBox5 -> Items -> Strings[Form1 -> DBListBox5 -> ItemIndex];

else return;


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

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


Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Sirka_pasma FROM Transadmitancni_zesilovace WHERE Nazev_soucastky = '"+ZmenitTA+"'");
Query1 -> Open();

Edit2TA -> Text = DataSource1->DataSet->FieldByName("Sirka_pasma")-> AsString;

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

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Vstupni_odpor FROM Transadmitancni_zesilovace WHERE Nazev_soucastky = '"+ZmenitTA+"'");
Query1 -> Open();

Edit3TA -> Text = DataSource1->DataSet->FieldByName("Vstupni_odpor")->AsString;

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

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Vystupni_odpor FROM Transadmitancni_zesilovace WHERE Nazev_soucastky = '"+ZmenitTA+"'");
Query1 -> Open();

Edit4TA -> Text = DataSource1->DataSet->FieldByName("Vystupni_odpor")->AsString;

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

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Vystupni_proud FROM Transadmitancni_zesilovace WHERE Nazev_soucastky = '"+ZmenitTA+"'");
Query1 -> Open();

Edit5TA -> Text = DataSource1->DataSet->FieldByName("Vystupni_proud")->AsString;

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

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Napajeci_napeti FROM Transadmitancni_zesilovace WHERE Nazev_soucastky = '"+ZmenitTA+"'");
Query1 -> Open();

Edit6TA -> Text = DataSource1->DataSet->FieldByName("Napajeci_napeti")->AsString;

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

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

Memo1TA -> Text = DataSource1->DataSet->FieldByName("Popis")->AsString;

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Sym FROM Transadmitancni_zesilovace WHERE Nazev_soucastky = '"+ZmenitTA+"'");
Query1 -> Open();

Sym = DataSource1->DataSet->FieldByName("Sym")->AsString;

if (Sym == "a")
  CheckBox1 -> Checked = true;
else
  {
  CheckBox1 -> Checked = false;
  }

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Nesym FROM Transadmitancni_zesilovace WHERE Nazev_soucastky = '"+ZmenitTA+"'");
Query1 -> Open();

Nesym = DataSource1->DataSet->FieldByName("Nesym")->AsString;

if (Nesym == "a")
  CheckBox2 -> Checked = true;
else
  {
  CheckBox2 -> Checked = false;
  }
}
//---------------------------------------------------------------------------
void __fastcall TfrmZmenitTA::btnPridejTAClick(TObject *Sender)
{
AnsiString a,b,c,d,e,f,g;
AnsiString Sym, Nesym;
AnsiString edity[] = {Edit2TA -> Text, Edit3TA -> Text, Edit4TA -> Text, Edit5TA -> Text, Edit6TA -> Text};
AnsiString promenne[] = {b,c,d,e,f};
bool checkboxy[] = {CheckBox1->Checked, CheckBox2->Checked};
int aa;

a = Edit1TA -> Text;
b = Edit2TA -> Text;
c = Edit3TA -> Text;
d = Edit4TA -> Text;
e = Edit5TA -> Text;
f = Edit6TA -> Text;
g = Memo1TA -> Text;

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

if(checkboxy[0] || checkboxy[1] == false)
aa = 0;

if(checkboxy[0] || checkboxy[1] == true)
aa = 1;

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

if(aa == 0)
     ShowMessage("Nevybrali jste typ napájení.");
else
{
Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("UPDATE Transadmitancni_zesilovace SET Nazev_soucastky = '"+a+"', Sirka_pasma = "+promenne[0]+", Vstupni_odpor = "+promenne[1]+", Vystupni_odpor = "+promenne[2]+", Vystupni_proud = "+promenne[3]+", Napajeci_napeti = "+promenne[4]+", Popis = '"+g+"', Sym = '"+Sym+"', Nesym = '"+Nesym+"' WHERE Nazev_soucastky = '"+a+"'");
Query1 -> ExecSQL();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmZmenitTA::btnKonecTAClick(TObject *Sender)
{
frmZmenitTA -> Close();
Edit1TA -> Clear();
Edit2TA -> Clear();
Edit3TA -> Clear();
Edit4TA -> Clear();
Edit5TA -> Clear();
Edit6TA -> Clear();
Memo1TA -> Clear();
}
//---------------------------------------------------------------------------


