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

#include <vcl.h>
#include <inifiles.hpp>
#pragma hdrstop

#include "configurador.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TprodConfig *prodConfig;
//---------------------------------------------------------------------------
__fastcall TprodConfig::TprodConfig(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TprodConfig::btLoadImageClick(TObject *Sender)
{

  OpenPictureDialog1->Title = "Delete File";
  if (OpenPictureDialog1->Execute())
  {
    if (FileExists(OpenPictureDialog1->FileName))
    {
      producto->imagen = OpenPictureDialog1->FileName;
      img->Picture->LoadFromFile(producto->imagen);
    }
  }

}
//---------------------------------------------------------------------------
void __fastcall TprodConfig::setProd(int idx, TProds *prod)
{
  idxProducto = idx;
  producto = prod;

  img->Picture->LoadFromFile(producto->imagen);
  edDescr->Text = producto->descr;
  edPVPmin->Text = producto->PVPmin;
  edPVPmax->Text = producto->PVPmax;
  edclicks->Text = producto->nclicks;
  UpDown1->Position = producto->nclicks;

}
//---------------------------------------------------------------------------


void __fastcall TprodConfig::Button1Click(TObject *Sender)
{
  producto->descr = edDescr->Text;
  producto->PVPmin = edPVPmin->Text.ToDouble();
  producto->PVPmax = edPVPmax->Text.ToDouble();
  producto->nclicks = edclicks->Text.ToIntDef(1);


  // actualizamos sus datos en el ini
  TIniFile *pIniFile = new TIniFile(ExtractFileDir(Application->ExeName)+"\\preciometro.ini");
  // cargamos desde archivo, la configuración para cada producto...
  pIniFile->WriteString("pvp","descr"+AnsiString(idxProducto),producto->descr);
  pIniFile->WriteString("pvp","imagen"+AnsiString(idxProducto),producto->imagen);

  pIniFile->WriteString("pvp","PVPmax"+AnsiString(idxProducto),producto->PVPmax);
//  pvp[i].PVPcurr = pIniFile->ReadString("pvp","descr"+AnsiString(i),"2,9").ToDouble();
  pIniFile->WriteString("pvp","PVPmin"+AnsiString(idxProducto),producto->PVPmin);

  pIniFile->WriteInteger("pvp","nclicks"+AnsiString(idxProducto),producto->nclicks);
//  pvp[i].clicks = pIniFile->ReadInteger("pvp","clicks"+AnsiString(i),0);
  delete pIniFile;

 Close();
}
//---------------------------------------------------------------------------

