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

#include <vcl.h>
#pragma hdrstop

#include "PridejTA.h"
#include "Katalog.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmPridejTA *frmPridejTA;
//---------------------------------------------------------------------------
__fastcall TfrmPridejTA::TfrmPridejTA(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmPridejTA::btnPridejTAClick(TObject *Sender)
{
AnsiString a,b,c,d,e,f,g,Nazev;
AnsiString Sym, Nesym;
AnsiString Napajeni = Form1 -> ComboBox1TA -> Items -> Strings[Form1 -> ComboBox1TA -> ItemIndex];
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 (CheckBox1 -> Checked)

  {Sym = "a";}
else
  {Sym = " ";}

if (CheckBox2 -> Checked)

  {Nesym = "a";}
else
  {Nesym = " ";}

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

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

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(a == Nazev)
{
ShowMessage("Součástka "+Nazev+" je již v databázi obsažena");
}
else
{
if(aa == 0)
     ShowMessage("Nevybrali jste typ napájení.");
else
{
Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("INSERT INTO Transadmitancni_zesilovace (Nazev_soucastky, Sirka_pasma, Vstupni_odpor, Vystupni_odpor, Vystupni_proud, Napajeci_napeti, Popis, Sym, Nesym) VALUES ('"+a+"', "+promenne[0]+", "+promenne[1]+", "+promenne[2]+", "+promenne[3]+", "+promenne[4]+", '"+g+"', '"+Sym+"', '"+Nesym+"')");
Query1 -> ExecSQL();

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

Form1->DBListBox5->Items->Clear();
Form1->DataSource5->DataSet->FindFirst();
  do
      {
Form1->DBListBox5->Items->Add(Form1->DataSource5->DataSet->FieldByName("Nazev_soucastky")->AsString);
Form1->DataSource5->DataSet->Next();
      }
  while (!Form1->DataSource5->DataSet->Eof);
   }
  }
 }
Form1 -> Memo5 -> Clear(); 
}
//---------------------------------------------------------------------------
void __fastcall TfrmPridejTA::btnKonecTAClick(TObject *Sender)
{
frmPridejTA -> Close();
Edit1TA -> Clear();
Edit2TA -> Clear();
Edit3TA -> Clear();
Edit4TA -> Clear();
Edit5TA -> Clear();
Edit6TA -> Clear();
Memo1TA -> Clear();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPridejTA::FormShow(TObject *Sender)
{
Memo1TA -> Clear();        
}
//---------------------------------------------------------------------------

