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

#include <vcl.h>
#pragma hdrstop

#include "PridejOA.h"
#include "Katalog.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmPridejOA *frmPridejOA;
//---------------------------------------------------------------------------
__fastcall TfrmPridejOA::TfrmPridejOA(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmPridejOA::btnPridejOAClick(TObject *Sender)
{
AnsiString a,b,c,d,e,f,g,Nazev;
AnsiString High_speed, High_Zin, Hi_accuracy, Low_noise, Low_power, Other, Sym, Nesym;
AnsiString PouzitiOA = Form1 -> ComboBox1OA -> Items -> Strings[Form1 -> ComboBox1OA -> ItemIndex];
AnsiString Napajeni = Form1 -> ComboBox2OA -> Items -> Strings[Form1 -> ComboBox2OA -> ItemIndex];
AnsiString edity[] = {Edit2OA -> Text, Edit3OA -> Text, Edit4OA -> Text, Edit5OA -> Text, Edit6OA -> Text};
AnsiString promenne[] = {b,c,d,e,f};
AnsiString promenne2[] = {High_speed, High_Zin, Hi_accuracy, Low_noise, Low_power, Other, Sym, Nesym};
bool checkboxy[] = {CheckBox1->Checked, CheckBox2->Checked, CheckBox3->Checked, CheckBox4->Checked, CheckBox5->Checked, CheckBox6->Checked, CheckBox7->Checked, CheckBox8->Checked };
bool checkboxy1[] = {CheckBox1->Checked, CheckBox2->Checked, CheckBox3->Checked, CheckBox4->Checked, CheckBox5->Checked, CheckBox6->Checked  };
bool checkboxy2[] = {CheckBox7->Checked, CheckBox8->Checked};
int aa,bb;

a = Edit1OA -> Text;
b = Edit2OA -> Text;
c = Edit3OA -> Text;
d = Edit4OA -> Text;
e = Edit5OA -> Text;
f = Edit6OA -> Text;
g = Memo1OA -> Text;

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

for (int i=0; i<8; i++)
 {
 if(checkboxy[i] == true)
   {
   promenne2[i] = "a";
   }
 else
   promenne2[i] = " ";
 }

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

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

if(checkboxy1[0] || checkboxy1[1] || checkboxy1[2] || checkboxy1[3] || checkboxy1[4] || checkboxy1[5] == false)
aa = 0;

if(checkboxy1[0] || checkboxy1[1] || checkboxy1[2] || checkboxy1[3] || checkboxy1[4] || checkboxy1[5] == true)
aa = 1;

if(checkboxy2[0] || checkboxy2[1] == false)
bb = 0;

if(checkboxy2[0] || checkboxy2[1] == true)
bb = 1;

if(Edit1OA -> 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 žádnou kategorii použití.");
else
 {
if(bb == 0)
     ShowMessage("Nevybrali jste typ napájení.");
else
 {
 Query1 -> SQL -> Clear();
 Query1 -> SQL -> Add("INSERT INTO Operacni_zesilovace (Nazev_soucastky, Zesileni, Sirka_pasma, Rychlost_prebehu, Napajeci_napeti, Proudovy_odber, Popis, High_speed, High_Zin, Hi_accuracy, Low_noise, Low_power, Other, Sym, Nesym) VALUES ('"+a+"', "+promenne[0]+", "+promenne[1]+", "+promenne[2]+", "+promenne[3]+", "+promenne[4]+", '"+g+"', '"+promenne2[0]+"', '"+promenne2[1]+"', '"+promenne2[2]+"', '"+promenne2[3]+"', '"+promenne2[4]+"', '"+promenne2[5]+"', '"+promenne2[6]+"', '"+promenne2[7]+"')");
 Query1 -> ExecSQL();

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

 Form1->DBListBox3->Items->Clear();
 Form1->DataSource3->DataSet->FindFirst();
     do
      {
    Form1->DBListBox3->Items->Add(Form1->DataSource3->DataSet->FieldByName("Nazev_soucastky")->AsString);
    Form1->DataSource3->DataSet->Next();
      }
     while (!Form1->DataSource3->DataSet->Eof);
}
}
}
}
Form1 -> Memo3 -> Clear();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPridejOA::btnKonecOAClick(TObject *Sender)
{
Edit1OA -> Clear();
Edit2OA -> Clear();
Edit3OA -> Clear();
Edit4OA -> Clear();
Edit5OA -> Clear();
Edit6OA -> Clear();
Memo1OA -> Clear();

CheckBox1 -> Checked = false;
CheckBox2 -> Checked = false;
CheckBox3 -> Checked = false;
CheckBox4 -> Checked = false;
CheckBox5 -> Checked = false;
CheckBox6 -> Checked = false;

frmPridejOA -> Close();        
}
//---------------------------------------------------------------------------
void __fastcall TfrmPridejOA::FormShow(TObject *Sender)
{
Memo1OA -> Clear();        
}
//---------------------------------------------------------------------------

