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

#include <vcl.h>
#pragma hdrstop

#include "ZmenitOA.h"
#include "Katalog.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmZmenitOA *frmZmenitOA;
//---------------------------------------------------------------------------
__fastcall TfrmZmenitOA::TfrmZmenitOA(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmZmenitOA::FormShow(TObject *Sender)
{
Memo1OA -> Clear();

AnsiString ZmenitOA;
AnsiString High_speed, High_Zin, Hi_accuracy, Low_noise, Low_power, Other, Sym, Nesym;
AnsiString pomocna = -10;

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

ZmenitOA = Form1 -> DBListBox3 -> Items -> Strings[Form1 -> DBListBox3 -> ItemIndex];

else return;


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

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


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

Edit2OA -> Text = DataSource1->DataSet->FieldByName("Zesileni")-> AsString;

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

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

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

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

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

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

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

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

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

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

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

Edit6OA -> Text = DataSource1->DataSet->FieldByName("Proudovy_odber")->AsString;

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

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

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

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

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

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

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

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

if (High_Zin == "a")
  CheckBox2 -> Checked = true;
else
  {
  CheckBox2 -> Checked = false;
  }

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

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

if (Hi_accuracy == "a")
  CheckBox3 -> Checked = true;
else
  {
  CheckBox3 -> Checked = false;
  }

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

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

if (Low_noise == "a")
  CheckBox4 -> Checked = true;
else
  {
  CheckBox4 -> Checked = false;
  }

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

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

if (Low_power == "a")
  CheckBox5 -> Checked = true;
else
  {
  CheckBox5 -> Checked = false;
  }

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

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

if (Other == "a")
  CheckBox6 -> Checked = true;
else
  {
  CheckBox6 -> Checked = false;
  }

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

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

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

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

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

if (Nesym == "a")
  CheckBox8 -> Checked = true;
else
  {
  CheckBox8 -> Checked = false;
  }
}
//---------------------------------------------------------------------------
void __fastcall TfrmZmenitOA::btnKonecOAClick(TObject *Sender)
{
frmZmenitOA -> Close();        
}
//---------------------------------------------------------------------------
void __fastcall TfrmZmenitOA::btnPridejOAClick(TObject *Sender)
{
AnsiString a,b,c,d,e,f,g,High_speed,High_Zin,Hi_accuracy,Low_noise,Low_power,Other, Sym, Nesym;
AnsiString edity[] = {Edit2OA -> Text, Edit3OA -> Text, Edit4OA -> Text, Edit5OA -> Text, Edit6OA -> Text};
AnsiString promenne[] = {b,c,d,e,f};
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];
 }

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(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("UPDATE Operacni_zesilovace SET Nazev_soucastky = '"+a+"', Zesileni = "+promenne[0]+", Sirka_pasma = "+promenne[1]+", Rychlost_prebehu = "+promenne[2]+", Napajeci_napeti = "+promenne[3]+", Proudovy_odber = "+promenne[4]+", Popis = '"+g+"', High_speed = '"+High_speed+"', High_Zin = '"+High_Zin+"', Hi_accuracy = '"+Hi_accuracy+"', Low_noise = '"+Low_noise+"', Low_power = '"+Low_power+"', Other = '"+Other+"', Sym = '"+Sym+"', Nesym = '"+Nesym+"' WHERE Nazev_soucastky = '"+a+"'");
Query1 -> ExecSQL();
}
}
}
}
//---------------------------------------------------------------------------
