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

#include <vcl.h>
#pragma hdrstop

#include "PridejCFOA.h"
#include "Katalog.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmPridejCFOA *frmPridejCFOA;
//---------------------------------------------------------------------------
__fastcall TfrmPridejCFOA::TfrmPridejCFOA(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TfrmPridejCFOA::btnPridejCFOAClick(TObject *Sender)
{
AnsiString a,b,c,d,e,f,g,Nazev;
AnsiString Sym,Nesym;
AnsiString NapajeniCFOA = Form1 -> ComboBox1CFOA -> Items -> Strings[Form1 -> ComboBox1CFOA -> ItemIndex];
AnsiString edity[] = {Edit2CFOA -> Text, Edit3CFOA -> Text, Edit4CFOA -> Text, Edit5CFOA -> Text, Edit6CFOA -> Text};
AnsiString promenne[] = {b,c,d,e,f};
bool checkboxy[] = {CheckBox1->Checked, CheckBox2->Checked};
int aa;

a = Edit1CFOA -> Text;
b = Edit2CFOA -> Text;
c = Edit3CFOA -> Text;
d = Edit4CFOA -> Text;
e = Edit5CFOA -> Text;
f = Edit6CFOA -> Text;
g = Memo1CFOA -> 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 = " ";}


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

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

if(Edit1CFOA -> 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("SELECT Nazev_soucastky FROM CFOA 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 CFOA (Nazev_soucastky, Sirka_pasma, Rychlost_prebehu, Napajeci_napeti, Rin_neinv, Rin_inv, 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 CFOA WHERE "+NapajeniCFOA+" = 'a'");
Query1 -> Open();

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

void __fastcall TfrmPridejCFOA::btnKonecCFOAClick(TObject *Sender)
{
frmPridejCFOA -> Close();
Edit1CFOA -> Clear();
Edit2CFOA -> Clear();
Edit3CFOA -> Clear();
Edit4CFOA -> Clear();
Edit5CFOA -> Clear();
Edit6CFOA -> Clear();
Memo1CFOA -> Clear();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPridejCFOA::FormShow(TObject *Sender)
{
Memo1CFOA -> Clear();        
}
//---------------------------------------------------------------------------

