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

#include <vcl.h>
#pragma hdrstop

#include "ZmenitCFOA.h"
#include "Katalog.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmZmenitCFOA *frmZmenitCFOA;
//---------------------------------------------------------------------------
__fastcall TfrmZmenitCFOA::TfrmZmenitCFOA(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmZmenitCFOA::FormShow(TObject *Sender)
{
Memo1CFOA -> Clear();

AnsiString ZmenitCFOA;
AnsiString Sym, Nesym;
AnsiString pomocna= -10;

if(Form1 -> DBListBox4 -> ItemIndex!= -1)

ZmenitCFOA = Form1 -> DBListBox4 -> Items -> Strings[Form1 -> DBListBox4 -> ItemIndex];

else return;


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

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


Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Sirka_pasma FROM CFOA WHERE Nazev_soucastky = '"+ZmenitCFOA+"'");
Query1 -> Open();

Edit2CFOA -> Text = DataSource1->DataSet->FieldByName("Sirka_pasma")-> AsString;

if( Edit2CFOA -> Text == pomocna)
 {
 Edit2CFOA -> Text = "";
 }

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Rychlost_prebehu FROM CFOA WHERE Nazev_soucastky = '"+ZmenitCFOA+"'");
Query1 -> Open();

Edit3CFOA -> Text = DataSource1->DataSet->FieldByName("Rychlost_prebehu")->AsString;

if( Edit3CFOA -> Text == pomocna)
 {
 Edit3CFOA -> Text = "";
 }

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Napajeci_napeti FROM CFOA WHERE Nazev_soucastky = '"+ZmenitCFOA+"'");
Query1 -> Open();

Edit4CFOA -> Text = DataSource1->DataSet->FieldByName("Napajeci_napeti")->AsString;

if( Edit4CFOA -> Text == pomocna)
 {
 Edit4CFOA -> Text = "";
 }

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Rin_neinv FROM CFOA WHERE Nazev_soucastky = '"+ZmenitCFOA+"'");
Query1 -> Open();

Edit5CFOA -> Text = DataSource1->DataSet->FieldByName("Rin_neinv")->AsString;

if( Edit5CFOA -> Text == pomocna)
 {
 Edit5CFOA -> Text = "";
 }

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Rin_inv FROM CFOA WHERE Nazev_soucastky = '"+ZmenitCFOA+"'");
Query1 -> Open();

Edit6CFOA -> Text = DataSource1->DataSet->FieldByName("Rin_inv")->AsString;

if( Edit6CFOA -> Text == pomocna)
 {
 Edit6CFOA -> Text = "";
 }

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

Memo1CFOA -> Text = DataSource1->DataSet->FieldByName("Popis")->AsString;

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Sym FROM CFOA WHERE Nazev_soucastky = '"+ZmenitCFOA+"'");
Query1 -> Open();

Sym = DataSource1->DataSet->FieldByName("Sym")->AsString;

if (Sym == "a")
  CheckBox1 -> Checked = true;
else
  {
  CheckBox1 -> Checked = false;
  }

Query1 -> SQL -> Clear();
Query1 -> SQL -> Add("SELECT Nesym FROM CFOA WHERE Nazev_soucastky = '"+ZmenitCFOA+"'");
Query1 -> Open();

Nesym = DataSource1->DataSet->FieldByName("Nesym")->AsString;

if (Nesym == "a")
  CheckBox2 -> Checked = true;
else
  {
  CheckBox2 -> Checked = false;
  }
}
//---------------------------------------------------------------------------
void __fastcall TfrmZmenitCFOA::btnPridejCFOAClick(TObject *Sender)
{
AnsiString a,b,c,d,e,f,g;
AnsiString Sym, Nesym;
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(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("UPDATE CFOA SET Nazev_soucastky = '"+a+"', Sirka_pasma = "+promenne[0]+", Rychlost_prebehu = "+promenne[1]+", Napajeci_napeti = "+promenne[2]+", Rin+ = "+promenne[3]+", Rin- = "+promenne[4]+", Popis = '"+g+"', Sym = '"+Sym+"', Nesym = '"+Nesym+"' WHERE Nazev_soucastky = '"+a+"'");
Query1 -> ExecSQL();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmZmenitCFOA::btnKonecCFOAClick(TObject *Sender)
{
frmZmenitCFOA -> Close();
Edit1CFOA -> Clear();
Edit2CFOA -> Clear();
Edit3CFOA -> Clear();
Edit4CFOA -> Clear();
Edit5CFOA -> Clear();
Edit6CFOA -> Clear();
Memo1CFOA -> Clear();
}
//---------------------------------------------------------------------------
