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

#include <vcl.h>
#include <iostream>
#include <memory>
#pragma hdrstop
#include "Katalog.h"
#include "PridejBT.h"
#include "PridejUT.h"
#include "PridejOA.h"
#include "PridejCFOA.h"
#include "PridejTA.h"
#include "ZmenitBT.h"
#include "frmZmenitUT.h"
#include "ZmenitOA.h"
#include "ZmenitCFOA.h"
#include "ZmenitTA.h"
#include "string.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  AnsiString TypBT = ComboBox1BT -> Items -> Strings[ComboBox1BT -> ItemIndex];

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

  DBListBox1->Items->Clear();
  DataSource1->DataSet->FindFirst();
  do
      {
  DBListBox1->Items->Add(DataSource1->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource1->DataSet->Next();
      }
  while (!DataSource1->DataSet->Eof);

  DataSource1 -> DataSet = Table1;



  DataSource2 -> DataSet = Query2;

  AnsiString TypUT = ComboBox1UT -> Items -> Strings[ComboBox1UT -> ItemIndex];

  Query2 -> SQL -> Clear();
  Query2 -> SQL -> Add("SELECT Nazev_soucastky FROM Unipolarni_tranzistory WHERE Typ = '"+TypUT+"'");
  Query2 -> Open();

  DBListBox2->Items->Clear();
  DataSource2->DataSet->FindFirst();
  do
      {
  DBListBox2->Items->Add(DataSource2->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource2->DataSet->Next();
      }
  while (!DataSource2->DataSet->Eof);

  DataSource2 -> DataSet = Table2;


  DataSource3 -> DataSet = Query3;

  AnsiString PouzitiOA = ComboBox1OA -> Items -> Strings[ComboBox1OA -> ItemIndex];
  AnsiString NapajeniOA = ComboBox2OA -> Items -> Strings[ComboBox2OA -> ItemIndex];

  Query3 -> SQL -> Clear();
  Query3 -> SQL -> Add("SELECT Nazev_soucastky FROM Operacni_zesilovace WHERE "+PouzitiOA+" = 'a' AND "+NapajeniOA+" = 'a'");
  Query3 -> Open();

  DBListBox3->Items->Clear();
  DataSource3->DataSet->FindFirst();
  do
      {
  DBListBox3->Items->Add(DataSource3->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource3->DataSet->Next();
      }
  while (!DataSource3->DataSet->Eof);

  DataSource3 -> DataSet = Table3;



  DataSource4 -> DataSet = Query4;

  AnsiString NapajeniCFOA = ComboBox1CFOA -> Items -> Strings[ComboBox1CFOA -> ItemIndex];

  Query4 -> SQL -> Clear();
  Query4 -> SQL -> Add("SELECT Nazev_soucastky FROM CFOA WHERE "+NapajeniCFOA+" = 'a'");
  Query4 -> Open();
  
  DBListBox4->Items->Clear();
  DataSource4->DataSet->FindFirst();
  do
      {
  DBListBox4->Items->Add(DataSource4->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource4->DataSet->Next();
      }
  while (!DataSource4->DataSet->Eof);

  DataSource4 -> DataSet = Table4;


  DataSource5 -> DataSet = Query5;

  AnsiString NapajeniTA = ComboBox1TA -> Items -> Strings[ComboBox1TA -> ItemIndex];

  Query5 -> SQL -> Clear();
  Query5 -> SQL -> Add("SELECT Nazev_soucastky FROM Transadmitancni_zesilovace WHERE "+NapajeniTA+" = 'a'");
  Query5 -> Open();

  DBListBox5->Items->Clear();
  DataSource5->DataSet->FindFirst();
  do
      {
  DBListBox5->Items->Add(DataSource5->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource5->DataSet->Next();
      }
  while (!DataSource5->DataSet->Eof);

  DataSource5 -> DataSet = Table5;

}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnTriditBTClick(TObject *Sender)
{
Memo1 -> Clear();
AnsiString BTa,BTb,BTc,BTd,BTe,BTf,BTg,BTh,BTi,BTj;

BTa = Edit1BT -> Text;
BTb = Edit2BT -> Text;
BTc = Edit3BT -> Text;
BTd = Edit4BT -> Text;
BTe = Edit5BT -> Text;
BTf = Edit6BT -> Text;
BTg = Edit7BT -> Text;
BTh = Edit8BT -> Text;
BTi = Edit9BT -> Text;
BTj = Edit10BT -> Text;

AnsiString TypBT = ComboBox1BT -> Items -> Strings[ComboBox1BT -> ItemIndex];
AnsiString dotaz = "SELECT Nazev_soucastky FROM Bipolarni_tranzistory";
AnsiString texty[] = {"Max_napeti_CE >= "+BTa+" AND Max_napeti_CE <= "+BTb,"Tranzitni_kmitocet >= "+BTc+" AND Tranzitni_kmitocet <= "+BTd, "Max_proud_kolektorem >= "+BTe+" AND Max_proud_kolektorem <= "+BTf, "Max_vykonova_ztrata >= "+BTg+" AND Max_vykonova_ztrata <= "+BTh, "Proudovy_zes_cinitel >= "+BTi+" AND Proudovy_zes_cinitel <= "+BTj};
AnsiString pomocna_prom = {" AND Polarita = '"+TypBT+"'" };
bool checkboxy[] = {CheckBox1BT->Checked, CheckBox2BT->Checked, CheckBox3BT->Checked, CheckBox4BT->Checked, CheckBox5BT->Checked  };



int p = 0;
for (int i = 0; i < 5; i++)
 {
if (checkboxy[i])
   {
if (p==0)
     {
     dotaz += " WHERE ";
     }
   if (p >= 1)
      {
       dotaz += " AND ";
      }
    dotaz += texty[i];
    p++;
    }
  }
dotaz = dotaz + pomocna_prom;

DataSource1 -> DataSet = Query1;

if (p > 0)
 {
Query1 -> SQL -> Clear();
Query1 -> SQL -> Add(dotaz);
Query1 -> Open();
 }

if (p==0)
 {
Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Nazev_soucastky FROM Bipolarni_tranzistory WHERE Max_napeti_CE = -99");
Query1 -> Open();
 }

DBListBox1->Items->Clear();
DataSource1->DataSet->FindFirst();
do
      {
DBListBox1->Items->Add(DataSource1->DataSet->FieldByName("Nazev_soucastky")->AsString);
DataSource1->DataSet->Next();
      }
while (!DataSource1->DataSet->Eof);

DataSource1 -> DataSet = Table1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnPridatBTClick(TObject *Sender)
{
frmPridejBT -> Show();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnSmazBTClick(TObject *Sender)
{
AnsiString smazatBT;
AnsiString TypBT = ComboBox1BT -> Items -> Strings[ComboBox1BT -> ItemIndex];

if(DBListBox1 -> ItemIndex!= -1)

smazatBT = DBListBox1 -> Items -> Strings[DBListBox1 -> ItemIndex];

else return;

if(MessageDlg(AnsiString ("Opravdu chcete součástku "+smazatBT+" odstranit?"),
  mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes)
{
DataSource1 -> DataSet = Query1;
Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("DELETE FROM Bipolarni_tranzistory WHERE Nazev_soucastky = '"+smazatBT+"'");
Query1 -> ExecSQL();
}
Memo1 -> Clear();

DataSource1 -> DataSet = Query1;

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

DBListBox1->Items->Clear();
  DataSource1->DataSet->FindFirst();
  do
      {
  DBListBox1->Items->Add(DataSource1->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource1->DataSet->Next();
      }
  while (!DataSource1->DataSet->Eof);

DataSource1 -> DataSet = Table1;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnZobrazPdfBTClick(TObject *Sender)
{
AnsiString zobrazitBT;
if(DBListBox1 -> ItemIndex!= -1)

zobrazitBT = DBListBox1 -> Items -> Strings[DBListBox1 -> ItemIndex];

else return;
AnsiString Pdf = ExtractFilePath(Application->ExeName)+"/Datasheety/Bipolární tranzistory/"+zobrazitBT+".pdf";
ShellExecute(NULL,"open",Pdf.c_str(),NULL,NULL,SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnNactiBTClick(TObject *Sender)
{
  Memo1 -> Clear();

  AnsiString TypBT = ComboBox1BT -> Items -> Strings[ComboBox1BT -> ItemIndex];

  DataSource1 -> DataSet = Query1;

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

  DBListBox1->Items->Clear();
  DataSource1->DataSet->FindFirst();
  do
      {
  DBListBox1->Items->Add(DataSource1->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource1->DataSet->Next();
      }
  while (!DataSource1->DataSet->Eof);

  DataSource1 -> DataSet = Table1;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnSmazUTClick(TObject *Sender)
{
AnsiString TypUT = ComboBox1UT -> Items -> Strings[ComboBox1UT -> ItemIndex];
AnsiString smazatUT;

if(DBListBox2 -> ItemIndex!= -1)

smazatUT = DBListBox2 -> Items -> Strings[DBListBox2 -> ItemIndex];

else return;

if(MessageDlg(AnsiString ("Opravdu chcete součástku "+smazatUT+" odstranit?"),
  mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes)
{
DataSource2 -> DataSet = Query2;

Query2 -> SQL -> Clear();
Query2 -> SQL -> Add("DELETE FROM Unipolarni_tranzistory WHERE Nazev_soucastky = '"+smazatUT+"'");
Query2 -> ExecSQL();

Query2 -> SQL -> Clear();
Query2 -> SQL -> Add("SELECT Nazev_soucastky FROM Unipolarni_tranzistory WHERE Typ = '"+TypUT+"'");
Query2 -> Open();

Memo2 -> Clear();

DBListBox2->Items->Clear();

DataSource2->DataSet->FindFirst();
  do
      {
  DBListBox2->Items->Add(DataSource2->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource2->DataSet->Next();
      }
  while (!DataSource2->DataSet->Eof);

DataSource2 -> DataSet = Table2;

Memo2 -> Lines -> Clear();
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnZobrazPdfUTClick(TObject *Sender)
{
AnsiString zobrazitUT;

if(DBListBox2 -> ItemIndex!= -1)
    zobrazitUT = DBListBox2 -> Items -> Strings[DBListBox2 -> ItemIndex];
else return;

AnsiString Pdf = ExtractFilePath(Application->ExeName)+"/Datasheety/Unipolární tranzistory/"+zobrazitUT+".pdf";
ShellExecute(NULL,"open",Pdf.c_str(),NULL,NULL,SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnTriditUTClick(TObject *Sender)
{
Memo2 -> Clear();

AnsiString UTa,UTb,UTc,UTd,UTe,UTf;

UTa = Edit1UT -> Text;
UTb = Edit2UT -> Text;
UTc = Edit3UT -> Text;
UTd = Edit4UT -> Text;
UTe = Edit5UT -> Text;
UTf = Edit6UT -> Text;

AnsiString TypUT = ComboBox1UT -> Items -> Strings[ComboBox1UT -> ItemIndex];
AnsiString dotaz = "SELECT Nazev_soucastky FROM Unipolarni_tranzistory";
AnsiString texty[] = {"Napeti_drain_source >= "+UTa+" AND Napeti_drain_source <= "+UTb,"Proud_Id >= "+UTc+" AND Proud_Id <= "+UTd, "Max_vykonova_ztrata >= "+UTe+" AND Max_vykonova_ztrata <= "+UTf };
AnsiString pomocna_prom = {" AND Typ = '"+TypUT+"'" };
bool checkboxy[] = {CheckBox1UT->Checked, CheckBox2UT->Checked, CheckBox3UT->Checked};

int p = 0;

for (int i = 0; i < 3; i++)
 {
 if (checkboxy[i])
   {
  if (p==0)
     {
     dotaz += " WHERE ";
     }
   if (p >= 1)
      {
       dotaz += " AND ";
      }
    dotaz += texty[i];
    p++;
    }
  }
dotaz = dotaz + pomocna_prom;

if (p > 0)
{
DataSource2 -> DataSet = Query2;
Query2 -> SQL -> Clear();
Query2 -> SQL -> Add(dotaz);
Query2 -> Open();
}

if (p==0)
{
DataSource2 -> DataSet = Query2;
Query2 -> SQL -> Clear();
Query2 -> SQL -> Add("SELECT Nazev_soucastky FROM Unipolarni_tranzistory WHERE Napeti_drain_source = 99999999");
Query2 -> Open();
}

DBListBox2->Items->Clear();
DataSource2->DataSet->FindFirst();
do
      {
DBListBox2->Items->Add(DataSource2->DataSet->FieldByName("Nazev_soucastky")->AsString);
DataSource2->DataSet->Next();
      }
while (!DataSource2->DataSet->Eof);

DataSource2 -> DataSet = Table2;

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

void __fastcall TForm1::btnNactiUTClick(TObject *Sender)
{
  Memo2 -> Clear();
  AnsiString TypUT = ComboBox1UT -> Items -> Strings[ComboBox1UT -> ItemIndex];

  DataSource2 -> DataSet = Query2;
  
  Query2 -> SQL -> Clear();
  Query2 -> SQL -> Add("SELECT Nazev_soucastky FROM Unipolarni_tranzistory WHERE Typ = '"+TypUT+"'");
  Query2 -> Open();

  DBListBox2->Items->Clear();
  DataSource2->DataSet->FindFirst();
  do
      {
  DBListBox2->Items->Add(DataSource2->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource2->DataSet->Next();
      }
 while (!DataSource2->DataSet->Eof);

 DataSource2 -> DataSet = Table2;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnPridejUTClick(TObject *Sender)
{
frmPridejUT -> Show();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnSmazOAClick(TObject *Sender)
{
AnsiString PouzitiOA = ComboBox1OA -> Items -> Strings[ComboBox1OA -> ItemIndex];
AnsiString NapajeniOA = ComboBox2OA -> Items -> Strings[ComboBox2OA -> ItemIndex];
AnsiString SmazatOA;

if(DBListBox3 -> ItemIndex!= -1)

SmazatOA = DBListBox3 -> Items -> Strings[DBListBox3 -> ItemIndex];

else return;

if(MessageDlg(AnsiString ("Opravdu chcete součástku "+SmazatOA+" odstranit?"),
  mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes)
{
DataSource3 -> DataSet = Query3;
Query3 -> SQL -> Clear();
Query3 -> SQL -> Add("DELETE FROM Operacni_zesilovace WHERE Nazev_soucastky = '"+SmazatOA+"'");
Query3 -> ExecSQL();

Query3 -> SQL -> Clear();
Query3 -> SQL -> Add("SELECT Nazev_soucastky FROM Operacni_zesilovace WHERE "+PouzitiOA+" = 'a' AND "+NapajeniOA+" = 'a'");
Query3 -> Open();

Memo3 -> Clear();

DBListBox3->Items->Clear();

DataSource3->DataSet->FindFirst();
  do
      {
  DBListBox3->Items->Add(DataSource3->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource3->DataSet->Next();
      }
  while (!DataSource3->DataSet->Eof);

DataSource3 -> DataSet = Table3;

Memo3 -> Lines -> Clear();
} 
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnZobrazPdfOAClick(TObject *Sender)
{
AnsiString zobrazitOA;

if(DBListBox3 -> ItemIndex!= -1)
    zobrazitOA = DBListBox3 -> Items -> Strings[DBListBox3 -> ItemIndex];
else return;

AnsiString Pdf = ExtractFilePath(Application->ExeName)+"/Datasheety/Operační zesilovače/"+zobrazitOA+".pdf";
ShellExecute(NULL,"open",Pdf.c_str(),NULL,NULL,SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnTriditOAClick(TObject *Sender)
{
Memo3 -> Clear();
AnsiString OAa,OAb,OAc,OAd,OAe,OAf,OAg,OAh,OAi,OAj;

OAa = Edit1OA -> Text;
OAb = Edit2OA -> Text;
OAc = Edit3OA -> Text;
OAd = Edit4OA -> Text;
OAe = Edit5OA -> Text;
OAf = Edit6OA -> Text;
OAg = Edit7OA -> Text;
OAh = Edit8OA -> Text;
OAi = Edit9OA -> Text;
OAj = Edit10OA -> Text;

AnsiString PouzitiOA = ComboBox1OA -> Items -> Strings[ComboBox1OA -> ItemIndex];
AnsiString NapajeniOA = ComboBox2OA -> Items -> Strings[ComboBox2OA -> ItemIndex];
AnsiString pomocna_prom = {" AND "+PouzitiOA+" = 'a' AND "+NapajeniOA+" = 'a'"};

bool checkboxy[] = {CheckBox1OA->Checked, CheckBox2OA->Checked, CheckBox3OA->Checked, CheckBox4OA->Checked, CheckBox5OA->Checked };

AnsiString dotaz = "SELECT Nazev_soucastky FROM Operacni_zesilovace";
AnsiString texty[] = {"Zesileni >= "+OAa+" AND Zesileni <= "+OAb,"Sirka_pasma >= "+OAc+" AND Sirka_pasma <= "+OAd, "Rychlost_prebehu >= "+OAe+" AND Rychlost_prebehu <= "+OAf, "Napajeci_napeti >= "+OAg+" AND Napajeci_napeti <= "+OAh, "Proudovy_odber >= "+OAi+" AND Proudovy_odber <= "+OAj };


int p = 0;
for (int i = 0; i < 5; i++)
 {
if (checkboxy[i])
   {
if (p==0)
     {
     dotaz += " WHERE ";
     }
   if (p >= 1)
      {
       dotaz += " AND ";
      }
    dotaz += texty[i];
    p++;
    }
  }

dotaz = dotaz + pomocna_prom;
  
if (p > 0)
 {
DataSource3 -> DataSet = Query3;
Query3 -> SQL -> Clear();
Query3 -> SQL -> Add(dotaz);
Query3 -> Open();
 }

if (p==0)
 {
DataSource3 -> DataSet = Query3;
Query3 -> SQL -> Clear();
Query3 -> SQL -> Add("SELECT Nazev_soucastky FROM Operacni_zesilovace WHERE Napajeci_napeti = 0");
Query3 -> Open();
 }

DBListBox3->Items->Clear();
DataSource3->DataSet->FindFirst();
do
      {
DBListBox3->Items->Add(DataSource3->DataSet->FieldByName("Nazev_soucastky")->AsString);
DataSource3->DataSet->Next();
      }
while (!DataSource3->DataSet->Eof);

DataSource3 -> DataSet = Table3;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnNactiOAClick(TObject *Sender)
{
  Memo3 -> Clear();
  DataSource3 -> DataSet = Query3;

  AnsiString PouzitiOA = ComboBox1OA -> Items -> Strings[ComboBox1OA -> ItemIndex];
  AnsiString NapajeniOA = ComboBox2OA -> Items -> Strings[ComboBox2OA -> ItemIndex];

  Query3 -> SQL -> Clear();
  Query3 -> SQL -> Add("SELECT Nazev_soucastky FROM Operacni_zesilovace WHERE "+PouzitiOA+" = 'a' AND "+NapajeniOA+" = 'a'");
  Query3 -> Open();

  DBListBox3->Items->Clear();
  DataSource3->DataSet->FindFirst();
  do
      {
  DBListBox3->Items->Add(DataSource3->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource3->DataSet->Next();
      }
  while (!DataSource3->DataSet->Eof);

  DataSource3 -> DataSet = Table3;

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

void __fastcall TForm1::btnPridejCFOAClick(TObject *Sender)
{
frmPridejCFOA -> Show();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnPridejOAClick(TObject *Sender)
{
frmPridejOA -> Show();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnSmazCFOAClick(TObject *Sender)
{
AnsiString smazatCFOA;
AnsiString NapajeniCFOA = ComboBox1CFOA -> Items -> Strings[ComboBox1CFOA -> ItemIndex];

if(DBListBox4 -> ItemIndex!= -1)

smazatCFOA = DBListBox4 -> Items -> Strings[DBListBox4 -> ItemIndex];

else return;

if(MessageDlg(AnsiString ("Opravdu chcete součástku "+smazatCFOA+" odstranit?"),
  mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes)
{
DataSource4 -> DataSet = Query4;
Query4 -> SQL -> Clear();
Query4 -> SQL -> Add("DELETE FROM CFOA WHERE Nazev_soucastky = '"+smazatCFOA+"'");
Query4 -> ExecSQL();

Query4 -> SQL -> Clear();
Query4 -> SQL -> Add("SELECT  Nazev_soucastky FROM CFOA WHERE "+NapajeniCFOA+" = 'a'");
Query4 -> Open();

Memo4 -> Clear();

DBListBox4->Items->Clear();
DataSource4->DataSet->FindFirst();
  do
      {
  DBListBox4->Items->Add(DataSource4->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource4->DataSet->Next();
      }
  while (!DataSource4->DataSet->Eof);

  DataSource4->DataSet=Table4;

Memo4 -> Lines -> Clear();  
}  
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnZobrazPdfCFOAClick(TObject *Sender)
{
AnsiString zobrazitCFOA;

if(DBListBox4 -> ItemIndex!= -1)
    zobrazitCFOA = DBListBox4 -> Items -> Strings[DBListBox4 -> ItemIndex];
else return;

AnsiString Pdf = ExtractFilePath(Application->ExeName)+"/Datasheety/CFOA/"+zobrazitCFOA+".pdf";
ShellExecute(NULL,"open",Pdf.c_str(),NULL,NULL,SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnTriditCFOAClick(TObject *Sender)
{
Memo4 -> Clear();
AnsiString CFOAa,CFOAb,CFOAc,CFOAd,CFOAe,CFOAf,CFOAg,CFOAh,CFOAi,CFOAj;

CFOAa = Edit1CFOA -> Text;
CFOAb = Edit2CFOA -> Text;
CFOAc = Edit3CFOA -> Text;
CFOAd = Edit4CFOA -> Text;
CFOAe = Edit5CFOA -> Text;
CFOAf = Edit6CFOA -> Text;
CFOAg = Edit7CFOA -> Text;
CFOAh = Edit8CFOA -> Text;
CFOAi = Edit9CFOA -> Text;
CFOAj = Edit10CFOA -> Text;

AnsiString NapajeniCFOA = ComboBox1CFOA -> Items -> Strings[ComboBox1CFOA -> ItemIndex];
AnsiString pomocna_prom = {" AND "+NapajeniCFOA+" = 'a'"};

bool checkboxy[] = {CheckBox1CFOA->Checked, CheckBox2CFOA->Checked, CheckBox3CFOA->Checked, CheckBox4CFOA->Checked, CheckBox5CFOA->Checked};

AnsiString dotaz = "SELECT Nazev_soucastky FROM CFOA";
AnsiString texty[] = {"Sirka_pasma >= "+CFOAa+" AND Sirka_pasma <= "+CFOAb,"Rychlost_prebehu >= "+CFOAc+" AND Rychlost_prebehu <= "+CFOAd, "Napajeci_napeti >= "+CFOAe+" AND Napajeci_napeti <= "+CFOAf, "Rin+ >= "+CFOAg+" AND Rin+ <= "+CFOAh, "Rin- >= "+CFOAi+" AND Rin- <= "+CFOAj};


int p = 0;
for (int i = 0; i < 5; i++)
 {
if (checkboxy[i])
   {
if (p==0)
     {
     dotaz += " WHERE ";
     }
   if (p >= 1)
      {
       dotaz += " AND ";
      }
    dotaz += texty[i];
    p++;
    }
  }

dotaz = dotaz + pomocna_prom;

if (p > 0)
 {
DataSource4 -> DataSet = Query4;
Query4 -> SQL -> Clear();
Query4 -> SQL -> Add(dotaz);
Query4 -> Open();
 }

if (p==0)
 {
DataSource4 -> DataSet = Query4;
Query4 -> SQL -> Clear();
Query4 -> SQL -> Add("SELECT Nazev_soucastky FROM CFOA WHERE Sirka_pasma = 0");
Query4 -> Open();
 }

DBListBox4->Items->Clear();
DataSource4->DataSet->FindFirst();
do
      {
DBListBox4->Items->Add(DataSource4->DataSet->FieldByName("Nazev_soucastky")->AsString);
DataSource4->DataSet->Next();
      }
while (!DataSource4->DataSet->Eof);

DataSource4 -> DataSet = Table4;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnNactiCFOAClick(TObject *Sender)
{
  Memo4 -> Clear();
  DataSource4 -> DataSet = Query4;

  AnsiString NapajeniCFOA = ComboBox1CFOA -> Items -> Strings[ComboBox1CFOA -> ItemIndex];
  
  Query4 -> SQL -> Clear();
  Query4 -> SQL -> Add("SELECT Nazev_soucastky FROM CFOA WHERE "+NapajeniCFOA+" = 'a'");
  Query4 -> Open();

  DBListBox4->Items->Clear();
  DataSource4->DataSet->FindFirst();
  do
      {
  DBListBox4->Items->Add(DataSource4->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource4->DataSet->Next();
      }
 while (!DataSource4->DataSet->Eof);

  DataSource4 -> DataSet = Table4;

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

void __fastcall TForm1::btnSmazTAClick(TObject *Sender)
{
AnsiString smazatTA;
AnsiString NapajeniTA = ComboBox1TA -> Items -> Strings[ComboBox1TA -> ItemIndex];

if(DBListBox5 -> ItemIndex!= -1)

smazatTA = DBListBox5 -> Items -> Strings[DBListBox5 -> ItemIndex];

else return;

if(MessageDlg(AnsiString ("Opravdu chcete součástku "+smazatTA+" odstranit?"),
  mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes)
{
DataSource5 ->DataSet = Query5;

Query5 -> SQL -> Clear();
Query5 -> SQL -> Add("DELETE FROM Transadmitancni_zesilovace WHERE Nazev_soucastky = '"+smazatTA+"'");
Query5 -> ExecSQL();

Query5 -> SQL -> Clear();
Query5 -> SQL -> Add("SELECT Nazev_soucastky FROM Transadmitancni_zesilovace WHERE "+NapajeniTA+" = 'a'");
Query5 -> Open();

Memo5 -> Clear();

DBListBox5->Items->Clear();

DataSource5->DataSet->FindFirst();
  do
      {
  DBListBox5->Items->Add(DataSource5->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource5->DataSet->Next();
      }
  while (!DataSource5->DataSet->Eof);

DataSource5 ->DataSet = Table5;

Memo5 -> Lines -> Clear();
}

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

void __fastcall TForm1::btnZobrazPdfTAClick(TObject *Sender)
{
AnsiString zobrazitTA;

if(DBListBox5 -> ItemIndex!= -1)
    zobrazitTA = DBListBox5 -> Items -> Strings[DBListBox5 -> ItemIndex];
else return;

AnsiString Pdf = ExtractFilePath(Application->ExeName)+"/Datasheety/OTA/"+zobrazitTA+".pdf";
ShellExecute(NULL,"open",Pdf.c_str(),NULL,NULL,SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnTriditTAClick(TObject *Sender)
{
Memo5 -> Clear();
AnsiString TAa,TAb,TAc,TAd,TAe,TAf,TAg,TAh,TAi,TAj;

TAa = Edit1TA -> Text;
TAb = Edit2TA -> Text;
TAc = Edit3TA -> Text;
TAd = Edit4TA -> Text;
TAe = Edit5TA -> Text;
TAf = Edit6TA -> Text;
TAg = Edit7TA -> Text;
TAh = Edit8TA -> Text;
TAi = Edit9TA -> Text;
TAj = Edit10TA -> Text;

AnsiString NapajeniTA = ComboBox1TA -> Items -> Strings[ComboBox1TA -> ItemIndex];
AnsiString pomocna_prom = {" AND "+NapajeniTA+" = 'a'"};

bool checkboxy[] = {CheckBox1TA->Checked, CheckBox2TA->Checked, CheckBox3TA->Checked, CheckBox4TA->Checked, CheckBox5TA->Checked  };

AnsiString dotaz = "SELECT Nazev_soucastky FROM Transadmitancni_zesilovace";
AnsiString texty[] = {"Sirka_pasma >= "+TAa+" AND Sirka_pasma <= "+TAb,"Vstupni_odpor >= "+TAc+" AND Vstupni_odpor <= "+TAd, "Vystupni_odpor >= "+TAe+" AND Vystupni_odpor <= "+TAf, "Vystupni_proud >= "+TAg+" AND Vystupni_proud <= "+TAh, "Napajeci_napeti >= "+TAi+" AND Napajeci_napeti <= "+TAj};


int p = 0;
for (int i = 0; i < 5; i++)
 {
if (checkboxy[i])
   {
if (p==0)
     {
     dotaz += " WHERE ";
     }
   if (p >= 1)
      {
       dotaz += " AND ";
      }
    dotaz += texty[i];
    p++;
    }
  }

dotaz = dotaz + pomocna_prom;


if (p > 0)
 {
DataSource5 -> DataSet = Query5;
Query5 -> SQL -> Clear();
Query5 -> SQL -> Add(dotaz);
Query5 -> Open();
 }

if (p==0)
 {
DataSource5 -> DataSet = Query5;
Query5 -> SQL -> Clear();
Query5 -> SQL -> Add("SELECT Nazev_soucastky FROM Transadmitancni_zesilovace WHERE Napajeci_napeti = 0" );
Query5 -> Open();
 }

DBListBox5->Items->Clear();
DataSource5->DataSet->FindFirst();
do
      {
DBListBox5->Items->Add(DataSource5->DataSet->FieldByName("Nazev_soucastky")->AsString);
DataSource5->DataSet->Next();
      }
while (!DataSource5->DataSet->Eof);

DataSource5 -> DataSet = Table5;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnNactiTAClick(TObject *Sender)
{
  Memo5 -> Clear();
  DataSource5 -> DataSet = Query5;

  AnsiString Napajeni = ComboBox1TA -> Items -> Strings[ComboBox1TA -> ItemIndex];
  
  Query5 -> SQL -> Clear();
  Query5 -> SQL -> Add("SELECT Nazev_soucastky FROM Transadmitancni_zesilovace WHERE "+Napajeni+" = 'a'");
  Query5 -> Open();

  DBListBox5->Items->Clear();
  DataSource5->DataSet->FindFirst();
  do
      {
  DBListBox5->Items->Add(DataSource5->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource5->DataSet->Next();
      }
 while (!DataSource5->DataSet->Eof);

  DataSource5 -> DataSet = Table5;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnPridejTAClick(TObject *Sender)
{
frmPridejTA -> Show();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::DBListBox1Click(TObject *Sender)
{
AnsiString popisBT;

if (CheckBoxPopisBT->Checked)

if(DBListBox1 -> ItemIndex!= -1)

popisBT = DBListBox1 -> Items -> Strings[DBListBox1 -> ItemIndex];

else return;

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

Memo1 -> Lines -> Clear();
Memo1 -> Lines -> Add(DataSource6->DataSet->FieldByName("Popis")->AsString);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::DBListBox2Click(TObject *Sender)
{
AnsiString popisUT;

if (CheckBoxPopisUT->Checked)

if(DBListBox2 -> ItemIndex!= -1)

  popisUT = DBListBox2 -> Items -> Strings[DBListBox2 -> ItemIndex];

else return;

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

   Memo2 -> Lines -> Clear();
   Memo2 -> Lines -> Add(DataSource7->DataSet->FieldByName("Popis")->AsString);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::DBListBox3Click(TObject *Sender)
{
AnsiString popisOA;

if (CheckBoxPopisOA->Checked)

if(DBListBox3 -> ItemIndex!= -1)

  popisOA = DBListBox3 -> Items -> Strings[DBListBox3 -> ItemIndex];

else return;

  Query8 -> SQL -> Clear();
  Query8 -> SQL -> Add("SELECT Popis FROM Operacni_zesilovace WHERE Nazev_soucastky = '"+popisOA+"'");
  Query8 -> Open();

   Memo3 -> Lines -> Clear();
   Memo3 -> Lines -> Add(DataSource8->DataSet->FieldByName("Popis")->AsString);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::DBListBox4Click(TObject *Sender)
{
AnsiString popisCFOA;

if (CheckBoxPopisCFOA->Checked)

if(DBListBox4 -> ItemIndex!= -1)

  popisCFOA = DBListBox4 -> Items -> Strings[DBListBox4 -> ItemIndex];

else return;

  Query9 -> SQL -> Clear();
  Query9 -> SQL -> Add("SELECT Popis FROM CFOA WHERE Nazev_soucastky = '"+popisCFOA+"'");
  Query9 -> Open();

   Memo4 -> Lines -> Clear();
   Memo4 -> Lines -> Add(DataSource9->DataSet->FieldByName("Popis")->AsString);;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::DBListBox5Click(TObject *Sender)
{
AnsiString popisTA;

if (CheckBoxPopisTA->Checked)

if(DBListBox5 -> ItemIndex!= -1)

  popisTA = DBListBox5 -> Items -> Strings[DBListBox5 -> ItemIndex];

else return;

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

   Memo5 -> Lines -> Clear();
   Memo5 -> Lines -> Add(DataSource10->DataSet->FieldByName("Popis")->AsString);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ComboBox1BTChange(TObject *Sender)
{
  AnsiString TypBT = ComboBox1BT -> Items -> Strings[ComboBox1BT -> ItemIndex];

  DataSource1 -> DataSet = Query1;

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

  DBListBox1->Items->Clear();
  DataSource1->DataSet->FindFirst();
  do
      {
  DBListBox1->Items->Add(DataSource1->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource1->DataSet->Next();
      }
  while (!DataSource1->DataSet->Eof);

  DataSource1 -> DataSet = Table1;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::btnZmenitBTClick(TObject *Sender)
{
frmZmenitBT -> Show();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ComboBox1UTChange(TObject *Sender)
{
  AnsiString TypUT = ComboBox1UT -> Items -> Strings[ComboBox1UT -> ItemIndex];

  DataSource2 -> DataSet = Query2;

  Query2 -> SQL -> Clear();
  Query2 -> SQL -> Add("SELECT Nazev_soucastky FROM Unipolarni_tranzistory WHERE Typ = '"+TypUT+"'");
  Query2 -> Open();

  DBListBox2->Items->Clear();
  DataSource2->DataSet->FindFirst();
  do
      {
  DBListBox2->Items->Add(DataSource2->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource2->DataSet->Next();
      }
  while (!DataSource2->DataSet->Eof);

  DataSource2 -> DataSet = Table2;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ComboBox1OAChange(TObject *Sender)
{
  DataSource3 -> DataSet = Query3;

  AnsiString PouzitiOA = ComboBox1OA -> Items -> Strings[ComboBox1OA -> ItemIndex];
  AnsiString NapajeniOA = ComboBox2OA -> Items -> Strings[ComboBox2OA -> ItemIndex];

  Query3 -> SQL -> Clear();
  Query3 -> SQL -> Add("SELECT Nazev_soucastky FROM Operacni_zesilovace WHERE "+PouzitiOA+" = 'a' AND "+NapajeniOA+" = 'a'");
  Query3 -> Open();

  DBListBox3->Items->Clear();
  DataSource3->DataSet->FindFirst();
  do
      {
  DBListBox3->Items->Add(DataSource3->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource3->DataSet->Next();
      }
  while (!DataSource3->DataSet->Eof);

  DataSource3 -> DataSet = Table3;        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnZmenitUTClick(TObject *Sender)
{
Form2 -> Show();        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnZmenitOAClick(TObject *Sender)
{
frmZmenitOA -> Show();        
}
//---------------------------------------------------------------------------


void __fastcall TForm1::btnZmenitCFOAClick(TObject *Sender)
{
frmZmenitCFOA -> Show();        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnZmenitTAClick(TObject *Sender)
{
frmZmenitTA -> Show();        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ComboBox2OAChange(TObject *Sender)
{
  DataSource3 -> DataSet = Query3;

  AnsiString PouzitiOA = ComboBox1OA -> Items -> Strings[ComboBox1OA -> ItemIndex];
  AnsiString NapajeniOA = ComboBox2OA -> Items -> Strings[ComboBox2OA -> ItemIndex];

  Query3 -> SQL -> Clear();
  Query3 -> SQL -> Add("SELECT Nazev_soucastky FROM Operacni_zesilovace WHERE "+PouzitiOA+" = 'a' AND "+NapajeniOA+" = 'a'");
  Query3 -> Open();

  DBListBox3->Items->Clear();
  DataSource3->DataSet->FindFirst();
  do
      {
  DBListBox3->Items->Add(DataSource3->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource3->DataSet->Next();
      }
  while (!DataSource3->DataSet->Eof);

  DataSource3 -> DataSet = Table3;         
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ComboBox1CFOAChange(TObject *Sender)
{
  DataSource4 -> DataSet = Query4;

  AnsiString NapajeniCFOA = ComboBox1CFOA -> Items -> Strings[ComboBox1CFOA -> ItemIndex];

  Query4 -> SQL -> Clear();
  Query4 -> SQL -> Add("SELECT Nazev_soucastky FROM CFOA WHERE "+NapajeniCFOA+" = 'a'");
  Query4 -> Open();

  DBListBox4->Items->Clear();
  DataSource4->DataSet->FindFirst();
  do
      {
  DBListBox4->Items->Add(DataSource4->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource4->DataSet->Next();
      }
 while (!DataSource4->DataSet->Eof);

 DataSource4 -> DataSet = Table4;        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ComboBox1TAChange(TObject *Sender)
{
  DataSource5 -> DataSet = Query5;

  AnsiString NapajeniTA = ComboBox1TA -> Items -> Strings[ComboBox1TA -> ItemIndex];
  
  Query5 -> SQL -> Clear();
  Query5 -> SQL -> Add("SELECT Nazev_soucastky FROM Transadmitancni_zesilovace WHERE "+NapajeniTA+" = 'a'");
  Query5 -> Open();

  DBListBox5->Items->Clear();
  DataSource5->DataSet->FindFirst();
  do
      {
  DBListBox5->Items->Add(DataSource5->DataSet->FieldByName("Nazev_soucastky")->AsString);
  DataSource5->DataSet->Next();
      }
 while (!DataSource5->DataSet->Eof);

  DataSource5 -> DataSet = Table5;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BT_napovedaClick(TObject *Sender)
{
AnsiString Pdf = ExtractFilePath(Application->ExeName)+"/Help/BT.pdf";
ShellExecute(NULL,"open",Pdf.c_str(),NULL,NULL,SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::UT_napovedaClick(TObject *Sender)
{
AnsiString Pdf = ExtractFilePath(Application->ExeName)+"/Help/UT.pdf";
ShellExecute(NULL,"open",Pdf.c_str(),NULL,NULL,SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::OA_napovedaClick(TObject *Sender)
{
AnsiString Pdf = ExtractFilePath(Application->ExeName)+"/Help/OA.pdf";
ShellExecute(NULL,"open",Pdf.c_str(),NULL,NULL,SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::CFOA_napovedaClick(TObject *Sender)
{
AnsiString Pdf = ExtractFilePath(Application->ExeName)+"/Help/CFOA.pdf";
ShellExecute(NULL,"open",Pdf.c_str(),NULL,NULL,SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::TA_napovedaClick(TObject *Sender)
{
AnsiString Pdf = ExtractFilePath(Application->ExeName)+"/Help/OTA.pdf";
ShellExecute(NULL,"open",Pdf.c_str(),NULL,NULL,SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------


