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

#include <vcl.h>
#pragma hdrstop

#include "PridejBT.h"
#include "Katalog.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmPridejBT *frmPridejBT;
//---------------------------------------------------------------------------
__fastcall TfrmPridejBT::TfrmPridejBT(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmPridejBT::btnKonecBTClick(TObject *Sender)
{
frmPridejBT -> Close();
}
//---------------------------------------------------------------------------

void __fastcall TfrmPridejBT::btnPridejBTClick(TObject *Sender)
{
AnsiString Typ = Form1 -> ComboBox1BT -> Items -> Strings[Form1 -> ComboBox1BT -> ItemIndex];
AnsiString TypBT = ComboBox1PridejBT -> Items -> Strings[ComboBox1PridejBT -> ItemIndex];
AnsiString a,b,c,d,e,f,g,h,Nazev;
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];
 }

if(Edit1BT -> Text == "")
 ShowMessage("Nezadali jste název součástky.");
else
{
Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Nazev_soucastky FROM Bipolarni_tranzistory WHERE Nazev_soucastky = '"+a+"' ");
Query1 -> Open();

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

if(a == Nazev)
{
ShowMessage("Součástka "+Nazev+" je již v databázi obsažena");
}
else
{
Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("INSERT INTO Bipolarni_tranzistory (Nazev_soucastky, Max_napeti_CE, Tranzitni_kmitocet, Max_proud_kolektorem, Max_vykonova_ztrata, Proudovy_zes_cinitel, Popis, Polarita) VALUES ('"+a+"', "+promenne[0]+", "+promenne[1]+", "+promenne[2]+", "+promenne[3]+", "+promenne[4]+",'"+g+"', '"+TypBT+"')");
Query1 -> ExecSQL();

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

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

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

