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

#include <vcl.h>
#pragma hdrstop

#include "Config.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TConfigForm *ConfigForm;
String q,w,e,r,t,y,u,i,o,p,a,s,d,f,g,h,j,k,l,z,x,c,v,b,n,m,s1,s2,s3,s4,s5,s6,s7,plus1="";
//---------------------------------------------------------------------------
__fastcall TConfigForm::TConfigForm(TComponent* Owner)
        : TForm(Owner)
{
  TStringList *pBuffer = new TStringList() ;
  pBuffer->LoadFromFile(ExtractFilePath(ParamStr(0))+"\data\\config.bin") ;

  PointSaveRG->ItemIndex = StrToInt(pBuffer->Strings[0]) ;
  CashED->Text = pBuffer->Strings[1];
  CardED->Text = pBuffer->Strings[2];
  q = pBuffer->Strings[3];
  w = pBuffer->Strings[4];
  e = pBuffer->Strings[5];
  r = pBuffer->Strings[6];
  t = pBuffer->Strings[7];
  y = pBuffer->Strings[8];
  u = pBuffer->Strings[9];
  i = pBuffer->Strings[10];
  o = pBuffer->Strings[11];
  p = pBuffer->Strings[12];
  a = pBuffer->Strings[13];
  s = pBuffer->Strings[14];
  d = pBuffer->Strings[15];
  f = pBuffer->Strings[16];
  g = pBuffer->Strings[17];
  h = pBuffer->Strings[18];
  j = pBuffer->Strings[19];
  k = pBuffer->Strings[20];
  l = pBuffer->Strings[21];
  z = pBuffer->Strings[22];
  x = pBuffer->Strings[23];
  c = pBuffer->Strings[24];
  v = pBuffer->Strings[25];
  b = pBuffer->Strings[26];
  n = pBuffer->Strings[27];
  m = pBuffer->Strings[28];
  s1 = pBuffer->Strings[29];
  s2 = pBuffer->Strings[30];
  s3 = pBuffer->Strings[31];
  s4 = pBuffer->Strings[32];
  s5 = pBuffer->Strings[33];
  s6 = pBuffer->Strings[34];
  s7 = pBuffer->Strings[35];
  plus1 = pBuffer->Strings[36];
  CheckBox1->Checked = StrToBool(pBuffer->Strings[37]);
  CheckBox2->Checked = StrToBool(pBuffer->Strings[38]);
  CheckBox3->Checked = StrToBool(pBuffer->Strings[39]);
  CheckBox4->Checked = StrToBool(pBuffer->Strings[40]);
  CheckBox5->Checked = StrToBool(pBuffer->Strings[41]);
  CheckBox6->Checked = StrToBool(pBuffer->Strings[42]);
  CheckBox7->Checked = StrToBool(pBuffer->Strings[43]);
  CheckBox8->Checked = StrToBool(pBuffer->Strings[44]);
  CheckBox9->Checked = StrToBool(pBuffer->Strings[45]);
  SaupED1->Text =  pBuffer->Strings[46];
  SaupED2->Text =  pBuffer->Strings[47];
  SaupED3->Text =  pBuffer->Strings[48];
  SaupED4->Text =  pBuffer->Strings[49];
  SaupED5->Text =  pBuffer->Strings[50];
  YSuRG->ItemIndex = StrToInt(pBuffer->Strings[51]);

  delete pBuffer ;

  
  q_Bt->Hint = q;
  w_Bt->Hint = w;
  e_Bt->Hint = e;
  r_Bt->Hint = r;
  t_Bt->Hint = t;
  y_Bt->Hint = y;
  u_Bt->Hint = u;
  i_Bt->Hint = i;
  o_Bt->Hint = o;
  p_Bt->Hint = p;
  a_Bt->Hint = a;
  s_Bt->Hint = s;
  d_Bt->Hint = d;
  f_Bt->Hint = f;
  g_Bt->Hint = g;
  h_Bt->Hint = h;
  j_Bt->Hint = j;
  k_Bt->Hint = k;
  l_Bt->Hint = l;
  z_Bt->Hint = z;
  x_Bt->Hint = x;
  c_Bt->Hint = c;
  v_Bt->Hint = v;
  b_Bt->Hint = b;
  n_Bt->Hint = n;
  m_Bt->Hint = m;
  Sim1_Bt->Hint = s1;
  Sim2_Bt->Hint = s2;
  Sim3_Bt->Hint = s3;
  Sim4_Bt->Hint = s4;
  Sim5_Bt->Hint = s5;
  Sim6_Bt->Hint = s6;
  Sim7_Bt->Hint = s7;
  Plus_Bt->Hint = plus1;



}

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


String TConfigForm::FindData(String ba,String va)
{
        if(ba.Length()!=0)
        {
                ListBox1->Visible=false;

                Query1->Close();
                Query1->SQL->Clear();
                Query1->SQL->Add("select * from goodslist where barcord like '%"+ba+"%' or goods like '%"+ba+"%'");
              //  Query1->ParamByName("barcode")->AsString = ba;

                Query1->Prepare();
                if(Query1->Prepared)
                        Query1->Open();
                if(Query1->RecordCount == 1)
                {

                        BaED->Text = Query1->FieldByName("barcord")->AsString;
                        GnED->Text = Query1->FieldByName("goods")->AsString;
                        ba =  BaED->Text;
                        ba+= ",";
                        ba+=  GnED->Text;
                        return ba;
                }
                else if(Query1->RecordCount > 1)
                {
                       ListBox1->Clear();
                       ListBox1->Visible=true;
                        while(!Query1->Eof)
                        {
                                ListBox1->Items->Add(Query1->FieldByName("barcord")->AsString+"/"+Query1->FieldByName("goods")->AsString);
                                Query1->Next();
                        }

                }
                else
                {
                        ShowMessage("등록하지 않은 상품입니다.");
                        return va;
                }
        }
        else
        {
                ShowMessage("13자리 바코드를 입력하세요.");
                return va;
         }
         
}
//---------------------------------------------------------------------------
void __fastcall TConfigForm::BitBtn38Click(TObject *Sender)
{
  TStringList *pBuffer = new TStringList() ;
    pBuffer->Add(PointSaveRG->ItemIndex) ;
    pBuffer->Add(CashED->Text) ;
    pBuffer->Add(CardED->Text) ;
    pBuffer->Add(q) ;
    pBuffer->Add(w) ;
    pBuffer->Add(e) ;
    pBuffer->Add(r) ;
    pBuffer->Add(t) ;
    pBuffer->Add(y) ;
    pBuffer->Add(u) ;
    pBuffer->Add(i) ;
    pBuffer->Add(o) ;
    pBuffer->Add(p) ;
    pBuffer->Add(a) ;
    pBuffer->Add(s) ;
    pBuffer->Add(d) ;
    pBuffer->Add(f) ;
    pBuffer->Add(g) ;
    pBuffer->Add(h) ;
    pBuffer->Add(j) ;
    pBuffer->Add(k) ;
    pBuffer->Add(l) ;
    pBuffer->Add(z) ;
    pBuffer->Add(x) ;
    pBuffer->Add(c) ;
    pBuffer->Add(v) ;
    pBuffer->Add(b) ;
    pBuffer->Add(n) ;
    pBuffer->Add(m) ;
    pBuffer->Add(s1) ;
    pBuffer->Add(s2) ;
    pBuffer->Add(s3) ;
    pBuffer->Add(s4) ;
    pBuffer->Add(s5) ;
    pBuffer->Add(s6) ;
    pBuffer->Add(s7) ;
    pBuffer->Add(plus1) ;
    pBuffer->Add(BoolToStr(CheckBox1->Checked)) ;
    pBuffer->Add(BoolToStr(CheckBox2->Checked)) ;
    pBuffer->Add(BoolToStr(CheckBox3->Checked)) ;
    pBuffer->Add(BoolToStr(CheckBox4->Checked)) ;
    pBuffer->Add(BoolToStr(CheckBox5->Checked)) ;
    pBuffer->Add(BoolToStr(CheckBox6->Checked)) ;
    pBuffer->Add(BoolToStr(CheckBox7->Checked)) ;
    pBuffer->Add(BoolToStr(CheckBox8->Checked)) ;
    pBuffer->Add(BoolToStr(CheckBox9->Checked)) ;
    pBuffer->Add(SaupED1->Text) ;
    pBuffer->Add(SaupED2->Text) ;
    pBuffer->Add(SaupED3->Text) ;
    pBuffer->Add(SaupED4->Text) ;
    pBuffer->Add(SaupED5->Text) ;
    pBuffer->Add(YSuRG->ItemIndex) ;

pBuffer->SaveToFile(ExtractFilePath(ParamStr(0))+"\data\\config.bin") ;
delete pBuffer ;
Close();
}
//---------------------------------------------------------------------------


void __fastcall TConfigForm::q_BtClick(TObject *Sender)
{
        q = FindData(BaED->Text,q);
        q_Bt->Hint = q;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::w_BtClick(TObject *Sender)
{
        w = FindData(BaED->Text,w);
        w_Bt->Hint = w;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::e_BtClick(TObject *Sender)
{
        e = FindData(BaED->Text,e);
        e_Bt->Hint = e;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::r_BtClick(TObject *Sender)
{
        r = FindData(BaED->Text,r);
        r_Bt->Hint = r;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::t_BtClick(TObject *Sender)
{
        t = FindData(BaED->Text,t);
        t_Bt->Hint = t;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::y_BtClick(TObject *Sender)
{
        y = FindData(BaED->Text,y);
        y_Bt->Hint = y;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::u_BtClick(TObject *Sender)
{
        u = FindData(BaED->Text,u);
        u_Bt->Hint = u;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::i_BtClick(TObject *Sender)
{
        i = FindData(BaED->Text,i);
        i_Bt->Hint = i;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::o_BtClick(TObject *Sender)
{
        o = FindData(BaED->Text,o);
        o_Bt->Hint = o;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::p_BtClick(TObject *Sender)
{
        p = FindData(BaED->Text,p);
        p_Bt->Hint = p;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::a_BtClick(TObject *Sender)
{
        a = FindData(BaED->Text,a);
        a_Bt->Hint = a;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::s_BtClick(TObject *Sender)
{
        s = FindData(BaED->Text,s);
        s_Bt->Hint = s;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::d_BtClick(TObject *Sender)
{
        d = FindData(BaED->Text,d);
        d_Bt->Hint = d;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::f_BtClick(TObject *Sender)
{
        f = FindData(BaED->Text,f);
        f_Bt->Hint = f;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::g_BtClick(TObject *Sender)
{
        g = FindData(BaED->Text,g);
        g_Bt->Hint = g;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::h_BtClick(TObject *Sender)
{
        h = FindData(BaED->Text,h);
        h_Bt->Hint = h;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::j_BtClick(TObject *Sender)
{
        j = FindData(BaED->Text,j);
        j_Bt->Hint = j;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::k_BtClick(TObject *Sender)
{
        k = FindData(BaED->Text,k);
        k_Bt->Hint = k;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::l_BtClick(TObject *Sender)
{
        l = FindData(BaED->Text,l);
        l_Bt->Hint = l;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::z_BtClick(TObject *Sender)
{
        z = FindData(BaED->Text,z);
        z_Bt->Hint = z;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::x_BtClick(TObject *Sender)
{
        x = FindData(BaED->Text,x);
        x_Bt->Hint = x;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::c_BtClick(TObject *Sender)
{
        c = FindData(BaED->Text,c);
        c_Bt->Hint = c;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::v_BtClick(TObject *Sender)
{
        v = FindData(BaED->Text,v);
        v_Bt->Hint = v;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::b_BtClick(TObject *Sender)
{
        b = FindData(BaED->Text,b);
        b_Bt->Hint = b;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::n_BtClick(TObject *Sender)
{
        n = FindData(BaED->Text,n);
        n_Bt->Hint = n;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::m_BtClick(TObject *Sender)
{
        m = FindData(BaED->Text,m);
        m_Bt->Hint = m;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::Sim1_BtClick(TObject *Sender)
{
        s1 = FindData(BaED->Text,s1);
        Sim1_Bt->Hint = s1;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::Sim2_BtClick(TObject *Sender)
{
        s2 = FindData(BaED->Text,s2);
        Sim2_Bt->Hint = s2;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::Sim3_BtClick(TObject *Sender)
{
        s3 = FindData(BaED->Text,s3);
        Sim3_Bt->Hint = s3;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::Sim4_BtClick(TObject *Sender)
{
        s4 = FindData(BaED->Text,s4);
        Sim4_Bt->Hint = s4;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::Sim5_BtClick(TObject *Sender)
{
        s5 = FindData(BaED->Text,s5);
        Sim5_Bt->Hint = s5;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::Sim6_BtClick(TObject *Sender)
{
        s6 = FindData(BaED->Text,s6);
        Sim6_Bt->Hint = s6;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::Sim7_BtClick(TObject *Sender)
{
        s7 = FindData(BaED->Text,s7);
        Sim7_Bt->Hint = s7;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::Plus_BtClick(TObject *Sender)
{
        plus1 = FindData(BaED->Text,plus1);
        Plus_Bt->Hint = plus1;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::ListBox1KeyPress(TObject *Sender, char &Key)
{
        if(Key==0x0D)
        {
                BaED->Text=ListBox1->Items->Strings[ListBox1->ItemIndex].SubString(0,13);
                GnED->Text=ListBox1->Items->Strings[ListBox1->ItemIndex].SubString(15,ListBox1->Items->Strings[ListBox1->ItemIndex].Length());
                ListBox1->Visible=false;
                ListBox1->Clear();
        }
        if(Key== 0x1b)
        {
                ListBox1->Items->Clear();
               ConfigForm->FocusControl(BaED);
               ListBox1->Visible=false;
        }
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::BaEDKeyPress(TObject *Sender, char &Key)
{
        if(Key==0x0D)
                FindData(BaED->Text,"");

        if(Key== 0x1b)
        {
                ListBox1->Items->Clear(); 
               ListBox1->Visible=false;
        }
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::ListBox1DblClick(TObject *Sender)
{
        ListBox1->OnKeyPress(this,0x0D);
}
//---------------------------------------------------------------------------

