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

#include <vcl.h>
#pragma hdrstop

#include "ZmenitBT.h"
#include "Katalog.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmZmenitBT *frmZmenitBT;
//---------------------------------------------------------------------------
__fastcall TfrmZmenitBT::TfrmZmenitBT(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmZmenitBT::btnKonecBTClick(TObject *Sender)
{
Edit1BT -> Clear();
Edit2BT -> Clear();
Edit3BT -> Clear();
Edit4BT -> Clear();
Edit5BT -> Clear();
Edit6BT -> Clear();
Memo1BT -> Clear();

frmZmenitBT -> Close();

}
//---------------------------------------------------------------------------
void __fastcall TfrmZmenitBT::FormShow(TObject *Sender)
{
Memo1BT -> Clear();

AnsiString pomocna = -10;
AnsiString zmenitBT;
if(Form1 -> DBListBox1 -> ItemIndex!= -1)

zmenitBT = Form1 -> DBListBox1 -> Items -> Strings[Form1 -> DBListBox1 -> ItemIndex];

else return;

DataSource1 -> DataSet = Query1;

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

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


Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Max_napeti_CE FROM Bipolarni_tranzistory WHERE Nazev_soucastky = '"+zmenitBT+"'");
Query1 -> Open();

Edit2BT -> Text = DataSource1->DataSet->FieldByName("Max_napeti_CE")-> AsString;

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

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Tranzitni_kmitocet FROM Bipolarni_tranzistory WHERE Nazev_soucastky = '"+zmenitBT+"'");
Query1 -> Open();

Edit3BT -> Text = DataSource1->DataSet->FieldByName("Tranzitni_kmitocet")->AsString;

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

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Max_proud_kolektorem FROM Bipolarni_tranzistory WHERE Nazev_soucastky = '"+zmenitBT+"'");
Query1 -> Open();

Edit4BT -> Text = DataSource1->DataSet->FieldByName("Max_proud_kolektorem")->AsString;

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

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Max_vykonova_ztrata FROM Bipolarni_tranzistory WHERE Nazev_soucastky = '"+zmenitBT+"'");
Query1 -> Open();

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

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

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Proudovy_zes_cinitel FROM Bipolarni_tranzistory WHERE Nazev_soucastky = '"+zmenitBT+"'");
Query1 -> Open();

Edit6BT -> Text = DataSource1->DataSet->FieldByName("Proudovy_zes_cinitel")->AsString;

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

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

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

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Polarita FROM Bipolarni_tranzistory WHERE Nazev_soucastky = '"+zmenitBT+"'");
Query1 -> Open();

}
//---------------------------------------------------------------------------

void __fastcall TfrmZmenitBT::btnZmenBTClick(TObject *Sender)
{
AnsiString a,b,c,d,e,f,g,TypBT;
AnsiString edity[] = {Edit2BT -> Text, Edit3BT -> Text, Edit4BT -> Text, Edit5BT -> Text, Edit6BT -> Text};
AnsiString promenne[] = {b,c,d,e,f};

a = Edit1BT -> Text;
b = Edit2BT -> Text;
c = Edit3BT -> Text;
d = Edit4BT -> Text;
e = Edit5BT -> Text;
f = Edit6BT -> Text;
g = Memo1BT -> Text;

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

TypBT = ComboBox1ZmenBT -> Items -> Strings[ComboBox1ZmenBT -> ItemIndex];

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("UPDATE Bipolarni_tranzistory SET Nazev_soucastky = '"+a+"', Max_napeti_CE = "+promenne[0]+", Tranzitni_kmitocet = "+promenne[1]+", Max_proud_kolektorem = "+promenne[2]+", Max_vykonova_ztrata = "+promenne[3]+", Proudovy_zes_cinitel = "+promenne[4]+", Popis = '"+g+"',Polarita = '"+TypBT+"' WHERE Nazev_soucastky = '"+a+"'");
Query1 -> ExecSQL();
}
//---------------------------------------------------------------------------

