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

#include <vcl.h>
#pragma hdrstop

#include "Main.h"
#include "PsWd.h"
#include "Datain.h"
#include "Calc.h"
#include "JungSan.h"
#include "Part.h"
#include "Seller.h"
#include "InUser.h"
#include "Config.h"
#include "printSet.h"
#include "Customer.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
bool cal,datain,js,pt,sel,ur,cn,ba,cs=false;

//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
        : TForm(Owner)
{

        ReadCon();

}
//--------------------------------------------------------------------------
 __fastcall TMainForm::TMainForm(int inPass,TComponent* Owner)
        : TForm(Owner)
{

    switch (inPass)
    {

        case 0:
                CalForm = new TCalForm(this);
                CalForm->ShowModal();
                delete CalForm;
                break;

        case 1:
                DataInForm = new TDataInForm(this);
                DataInForm->ShowModal();
                delete DataInForm;
                break;

        case 2:
                JungSanForm = new TJungSanForm(this);
                JungSanForm->ShowModal();
                delete JungSanForm;
                break;
        case 3:
                PartForm = new TPartForm(this);
                PartForm->ShowModal();
                delete PartForm;
                break;

        case 4:
                SellerForm = new TSellerForm(this);
                SellerForm->ShowModal();
                delete SellerForm;
                break;

        case 5:
                InUserForm = new TInUserForm(this);
                InUserForm->ShowModal();
                delete InUserForm;
                break;

        case 6:
                ConfigForm = new TConfigForm(this);
                ConfigForm->ShowModal();
                delete ConfigForm;
                ReadCon();
                break;
        case 7:
                BarPrint = new TBarPrint(this);
                BarPrint->ShowModal();
                delete BarPrint;
                break;
        case 8:
                CustomerForm = new TCustomerForm(this);
                CustomerForm->ShowModal();
                delete CustomerForm;
                break;

    }

}
//---------------------------------------------------------------------------
void __fastcall TMainForm::DataInBtnClick(TObject *Sender)
{
 if(datain == true)
 {
      PsWdForm = new TPsWdForm(1,this);
      PsWdForm->ShowModal();
      delete  PsWdForm;
  }
  else
  {
      DataInForm = new TDataInForm(this);
      DataInForm->ShowModal();
      delete DataInForm;
  }
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::CalBtnClick(TObject *Sender)
{

if(cal==true)
{
    PsWdForm = new TPsWdForm(0,this);
    PsWdForm->ShowModal();
    delete  PsWdForm;
 }
 else
 {
        CalForm = new TCalForm(this);
        CalForm->ShowModal();
        delete CalForm;
  }
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::JungSanBtnClick(TObject *Sender)
{
if(js==true)
{
     PsWdForm = new TPsWdForm(2,this);
     PsWdForm->ShowModal();
     delete PsWdForm;
}
else
{
        JungSanForm = new TJungSanForm(this);
        JungSanForm->ShowModal();
        delete JungSanForm;

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

void __fastcall TMainForm::PartBtnClick(TObject *Sender)
{
if(pt==true)
{
        PsWdForm = new TPsWdForm(3,this);
        PsWdForm->ShowModal();
        delete PsWdForm;
 }
 else
 {
        PartForm = new TPartForm(this);
                PartForm->ShowModal();
                delete PartForm;
 }
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::SellerBtnClick(TObject *Sender)
{
if(sel==true)
{
     
      PsWdForm = new TPsWdForm(4,this);
      PsWdForm->ShowModal();
      delete PsWdForm;
}
else
{
 SellerForm = new TSellerForm(this);
                SellerForm->ShowModal();
                delete  SellerForm;
 }
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::UserBtnClick(TObject *Sender)
{
if(ur==true)
{
      PsWdForm = new TPsWdForm(5,this);
      PsWdForm->ShowModal();
      delete  PsWdForm;
}
else
{
        InUserForm = new TInUserForm(this);
        InUserForm->ShowModal();
        delete InUserForm;
        
}
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::ConfigBtnClick(TObject *Sender)
{
if(cn==true)
{
        PsWdForm = new TPsWdForm(6,this);
        PsWdForm->ShowModal();
        delete  PsWdForm;
}
else
{
        ConfigForm = new TConfigForm(this);
        ConfigForm->ShowModal();
        delete ConfigForm;
        ReadCon();
}
}
//---------------------------------------------------------------------------


void __fastcall TMainForm::BitBtn1Click(TObject *Sender)
{
if(ba==true)
{
        PsWdForm = new TPsWdForm(7,this);
        PsWdForm->ShowModal();
        delete  PsWdForm;
}
else
{
        BarPrint = new TBarPrint(this);
        BarPrint->ShowModal();
        delete BarPrint;
}
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::GuestBtnClick(TObject *Sender)
{
if(cs==true)
{
        PsWdForm = new TPsWdForm(8,this);
        PsWdForm->ShowModal();
        delete  PsWdForm;
}
else
{
        CustomerForm = new TCustomerForm(this);
        CustomerForm->ShowModal();
        delete CustomerForm;
}
}
//---------------------------------------------------------------------------

void TMainForm::ReadCon()
{
        //TODO: Add your source code here
        TStringList *pBuffer = new TStringList() ;
        pBuffer->LoadFromFile(ExtractFilePath(ParamStr(0))+"\data\\config.bin") ;
        cal = StrToBool(pBuffer->Strings[37]);
        datain = StrToBool(pBuffer->Strings[38]);
        js = StrToBool(pBuffer->Strings[39]);
        pt = StrToBool(pBuffer->Strings[40]);
        sel = StrToBool(pBuffer->Strings[41]);
        ur = StrToBool(pBuffer->Strings[42]);
        cn = StrToBool(pBuffer->Strings[43]);
        ba = StrToBool(pBuffer->Strings[44]);
        cs = StrToBool(pBuffer->Strings[45]);
        delete pBuffer ;
}

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

bool TMainForm::CheckLock()
{
        int Status_Value;
        unsigned int Return_Value1, Return_Value2;
        //연결된 포트 찾기
        Status_Value = sLock(1001, 0, 0, 0, 0, &Return_Value1, 0);
        //
        if(Status_Value==1)
        {
                if(MessageDlg ("USB락키를 설치하여 주십이오.", mtWarning, TMsgDlgButtons () << mbOK<<mbCancel, 0)==2)
                        MainForm->Close();
         }
         //포트에 정상적으로 연결 되었는지 확인
        //Status_Value = sLock(IS_SLOCK, 0, 0, 0, 0, &Return_Value1, 0);
        //락의 고유번호 점검
       // sLock(1003, Pass1, Pass2, 0, 0, &Return_Value1, &Return_Value2)
       //제품 버젼을 점검
       // sLock(1002, Pass1, Pass2, 0, 0, &Return_Value1, &Return_Value2)
       // 반환 값을 점검
       //sLock(1004, Pass1, Pass2, InPut1_Num, InPut2_Num,  &Return_Value1, &Return_Value2)
}


