//---------------------------------------------------------------------------
// For SELMA200, 20180223, moon, 예정
// Camera Index 변경 관련하여 추후 Text 변경해야할것(Language.dat)
// 에어브러쉬 위치확인 후 작업해야함(기계 완료후)
//--------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "MachineEnvSetup_Form.h"
#include "Keyboard_Form.h"
#include "Message_Form.h"
#include "MultiLanguage.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "TntExtCtrls"
#pragma link "TntStdCtrls"
#pragma resource "*.dfm"
TMachineEnvSetupForm *MachineEnvSetupForm;
//---------------------------------------------------------------------------
__fastcall TMachineEnvSetupForm::TMachineEnvSetupForm(TComponent* Owner)
    : TTntForm(Owner)
{
  if(DefaultLCID == 1028 || DefaultLCID == 2052 || DefaultLCID == 3076 || DefaultLCID == 4100)
    ComponentSetFontName(this, "SimSun");
  else if(DefaultLCID == 1041)
    ComponentSetFontName(this, "Meiryo UI");
  else if(DefaultLCID == 3082)
  {
    ComponentSetFontName(this, "Segoe UI");
    ComponentSetMultiLine(this);
  }

  GetDefaultString();
}
//---------------------------------------------------------------------------
void __fastcall TMachineEnvSetupForm::GetDefaultString()
{
  GroupBox1->Caption = MACHINEENVSETUPFORM_GROUPBOX_CAPTION_01;
  Label15->Caption = MACHINETESTFORM_LABEL_CAPTION_04;
  Label17->Caption = MACHINETESTFORM_LABEL_CAPTION_05;
  Label18->Caption = MACHINETESTFORM_LABEL_CAPTION_06;
  Label20->Caption = MACHINETESTFORM_LABEL_CAPTION_07;
  Label4->Caption = MACHINEENVSETUPFORM_LABEL_CAPTION_05;
  Label1->Caption = MACHINEENVSETUPFORM_LABEL_CAPTION_06;
  Label3->Caption = MACHINEENVSETUPFORM_LABEL_CAPTION_07;
  Label2->Caption = MACHINEENVSETUPFORM_LABEL_CAPTION_08;
  Label5->Caption = MACHINEENVSETUPFORM_LABEL_CAPTION_09;
  DustBlowerGlobalDisablePanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_01;
  DustBlowerGlobalEnablePanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_02;
  DustBlower1TempOnPanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_03;
  DustBlower2TempOnPanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_03;
  DustBlower3TempOnPanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_03;
  DustBlower4TempOnPanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_03;
  DustBlower5TempOnPanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_03;

  DustBlower1AlwaysOffPanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_04;
  DustBlower2AlwaysOffPanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_04;
  DustBlower3AlwaysOffPanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_04;
  DustBlower4AlwaysOffPanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_04;
  DustBlower5AlwaysOffPanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_04;

  DustBlower1AlwaysOnPanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_05;
  DustBlower2AlwaysOnPanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_05;
  DustBlower3AlwaysOnPanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_05;
  DustBlower4AlwaysOnPanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_05;
  DustBlower5AlwaysOnPanel->Caption = MACHINEENVSETUPFORM_PANEL_CAPTION_05;

  SetupButton->Caption 				= MACHINEENVSETUPFORM_BUTTON_CAPTION_01 + " & " + MACHINEENVSETUPFORM_BUTTON_CAPTION_02;
  ExitButton->Caption 				= MACHINEENVSETUPFORM_BUTTON_CAPTION_02;

}
void __fastcall TMachineEnvSetupForm::FormCreate(TObject *Sender)
{
    // read env data
    ReadUserMachineEnvData(GetUserMachineEnvDataFileName(), TempUserMachineEnv);
    RefreshComponents();



}
//---------------------------------------------------------------------------
void __fastcall TMachineEnvSetupForm::SetupButtonClick(TObject *Sender)
{
    // write env data
    WriteUserMachineEnvData(GetUserMachineEnvDataFileName(), TempUserMachineEnv);
    if (!Comm_Request(COMM_HCB, CMD_USER_MACHINE_ENV_SETUP, &TempUserMachineEnv, sizeof(TUserMachineEnv)))
    {
    	//ShowMessageFA(HCBConnection.GetLastErrorMessage());
    }
    else
    {
    	ShowMessageFA(INTERVALSETTINGFORM_MSG_01);// 임시
    }

}
//---------------------------------------------------------------------------
void __fastcall TMachineEnvSetupForm::RefreshComponents(void)
{
    if (TempUserMachineEnv.Enabled)
    {
        DustBlowerGlobalEnablePanel->Color = clGreen;
        DustBlowerGlobalDisablePanel->Color = clBlack;
    }
    else
    {
        DustBlowerGlobalEnablePanel->Color = clBlack;
        DustBlowerGlobalDisablePanel->Color = clRed;
    }

    if (TempUserMachineEnv.DustBlower1Interval == 0)
    {
        if (TempUserMachineEnv.DustBlower1BlowTime != 0)
        {
            DustBlower1AlwaysOnPanel->Color = clBlue;
            DustBlower1TempOnPanel->Color = clBlack;
            DustBlower1AlwaysOffPanel->Color = clBlack;
        }
        else
        {
            DustBlower1AlwaysOnPanel->Color = clBlack;
            DustBlower1TempOnPanel->Color = clBlack;
            DustBlower1AlwaysOffPanel->Color = clBlue;
        }
        Blower1IntervalEdit->Visible = false;
        Blower1DelayEdit->Visible = false;
        Blower1BlowTimeEdit->Visible = false;
    }
    else
    {
        DustBlower1AlwaysOnPanel->Color = clBlack;
        DustBlower1TempOnPanel->Color = clBlue;
        DustBlower1AlwaysOffPanel->Color = clBlack;
        Blower1IntervalEdit->Visible = true;
        Blower1DelayEdit->Visible = true;
        Blower1BlowTimeEdit->Visible = true;
    }

    if (TempUserMachineEnv.DustBlower2Interval == 0)
    {
        if (TempUserMachineEnv.DustBlower2BlowTime != 0)
        {
            DustBlower2AlwaysOnPanel->Color = clBlue;
            DustBlower2TempOnPanel->Color = clBlack;
            DustBlower2AlwaysOffPanel->Color = clBlack;
        }
        else
        {
            DustBlower2AlwaysOnPanel->Color = clBlack;
            DustBlower2TempOnPanel->Color = clBlack;
            DustBlower2AlwaysOffPanel->Color = clBlue;
        }
        Blower2IntervalEdit->Visible = false;
        Blower2DelayEdit->Visible = false;
        Blower2BlowTimeEdit->Visible = false;
    }
    else
    {
        DustBlower2AlwaysOnPanel->Color = clBlack;
        DustBlower2TempOnPanel->Color = clBlue;
        DustBlower2AlwaysOffPanel->Color = clBlack;
        Blower2IntervalEdit->Visible = true;
        Blower2DelayEdit->Visible = true;
        Blower2BlowTimeEdit->Visible = true;
    }

    if (TempUserMachineEnv.DustBlower3Interval == 0)
    {
        if (TempUserMachineEnv.DustBlower3BlowTime != 0)
        {
            DustBlower3AlwaysOnPanel->Color = clBlue;
            DustBlower3TempOnPanel->Color = clBlack;
            DustBlower3AlwaysOffPanel->Color = clBlack;
        }
        else
        {
            DustBlower3AlwaysOnPanel->Color = clBlack;
            DustBlower3TempOnPanel->Color = clBlack;
            DustBlower3AlwaysOffPanel->Color = clBlue;
        }
        Blower3IntervalEdit->Visible = false;
        Blower3DelayEdit->Visible = false;
        Blower3BlowTimeEdit->Visible = false;
    }
    else
    {
        DustBlower3AlwaysOnPanel->Color = clBlack;
        DustBlower3TempOnPanel->Color = clBlue;
        DustBlower3AlwaysOffPanel->Color = clBlack;
        Blower3IntervalEdit->Visible = true;
        Blower3DelayEdit->Visible = true;
        Blower3BlowTimeEdit->Visible = true;
    }

	if (TempUserMachineEnv.DustBlower4Interval == 0)
    {
        if (TempUserMachineEnv.DustBlower4BlowTime != 0)
        {
            DustBlower4AlwaysOnPanel->Color = clBlue;
            DustBlower4TempOnPanel->Color = clBlack;
            DustBlower4AlwaysOffPanel->Color = clBlack;
        }
        else
        {
            DustBlower4AlwaysOnPanel->Color = clBlack;
            DustBlower4TempOnPanel->Color = clBlack;
            DustBlower4AlwaysOffPanel->Color = clBlue;
        }
        Blower4IntervalEdit->Visible = false;
        Blower4DelayEdit->Visible = false;
        Blower4BlowTimeEdit->Visible = false;
    }
    else
    {
        DustBlower4AlwaysOnPanel->Color = clBlack;
        DustBlower4TempOnPanel->Color = clBlue;
        DustBlower4AlwaysOffPanel->Color = clBlack;
        Blower4IntervalEdit->Visible = true;
        Blower4DelayEdit->Visible = true;
        Blower4BlowTimeEdit->Visible = true;
	}

	if (TempUserMachineEnv.DustBlower5Interval == 0)
    {
        if (TempUserMachineEnv.DustBlower5BlowTime != 0)
        {
            DustBlower5AlwaysOnPanel->Color = clBlue;
            DustBlower5TempOnPanel->Color = clBlack;
            DustBlower5AlwaysOffPanel->Color = clBlack;
        }
        else
        {
            DustBlower5AlwaysOnPanel->Color = clBlack;
            DustBlower5TempOnPanel->Color = clBlack;
            DustBlower5AlwaysOffPanel->Color = clBlue;
        }
        Blower5IntervalEdit->Visible = false;
        Blower5DelayEdit->Visible = false;
        Blower5BlowTimeEdit->Visible = false;
    }
    else
    {
        DustBlower5AlwaysOnPanel->Color = clBlack;
        DustBlower5TempOnPanel->Color = clBlue;
        DustBlower5AlwaysOffPanel->Color = clBlack;
        Blower5IntervalEdit->Visible = true;
        Blower5DelayEdit->Visible = true;
		Blower5BlowTimeEdit->Visible = true;
	}

    Blower1IntervalEdit->Text = FloatToStr(TempUserMachineEnv.DustBlower1Interval / 1000.0);
    Blower2IntervalEdit->Text = FloatToStr(TempUserMachineEnv.DustBlower2Interval / 1000.0);
	Blower3IntervalEdit->Text = FloatToStr(TempUserMachineEnv.DustBlower3Interval / 1000.0);
	Blower4IntervalEdit->Text = FloatToStr(TempUserMachineEnv.DustBlower4Interval / 1000.0);
	Blower5IntervalEdit->Text = FloatToStr(TempUserMachineEnv.DustBlower5Interval / 1000.0);
	Blower1DelayEdit->Text = FloatToStr(TempUserMachineEnv.DustBlower1Delay / 1000.0);
	Blower2DelayEdit->Text = FloatToStr(TempUserMachineEnv.DustBlower2Delay / 1000.0);
	Blower3DelayEdit->Text = FloatToStr(TempUserMachineEnv.DustBlower3Delay / 1000.0);
	Blower4DelayEdit->Text = FloatToStr(TempUserMachineEnv.DustBlower4Delay / 1000.0);
	Blower5DelayEdit->Text = FloatToStr(TempUserMachineEnv.DustBlower5Delay / 1000.0);
	Blower1BlowTimeEdit->Text = IntToStr(TempUserMachineEnv.DustBlower1BlowTime);
	Blower2BlowTimeEdit->Text = IntToStr(TempUserMachineEnv.DustBlower2BlowTime);
	Blower3BlowTimeEdit->Text = IntToStr(TempUserMachineEnv.DustBlower3BlowTime);
	Blower4BlowTimeEdit->Text = IntToStr(TempUserMachineEnv.DustBlower4BlowTime);
	Blower5BlowTimeEdit->Text = IntToStr(TempUserMachineEnv.DustBlower5BlowTime);
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlower1AlwaysOnPanelClick(
      TObject *Sender)
{
    TempUserMachineEnv.DustBlower1Interval = 0;
    TempUserMachineEnv.DustBlower1Delay = 0;
    TempUserMachineEnv.DustBlower1BlowTime = 1000;
    RefreshComponents();
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlower2AlwaysOnPanelClick(
      TObject *Sender)
{
    TempUserMachineEnv.DustBlower2Interval = 0;
    TempUserMachineEnv.DustBlower2Delay = 0;
    TempUserMachineEnv.DustBlower2BlowTime = 1000;
    RefreshComponents();    
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlower3AlwaysOnPanelClick(
      TObject *Sender)
{
    TempUserMachineEnv.DustBlower3Interval = 0;
    TempUserMachineEnv.DustBlower3Delay = 0;
    TempUserMachineEnv.DustBlower3BlowTime = 1000;
    RefreshComponents();    
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlower4AlwaysOnPanelClick(
      TObject *Sender)
{
	TempUserMachineEnv.DustBlower4Interval = 0;
    TempUserMachineEnv.DustBlower4Delay = 0;
    TempUserMachineEnv.DustBlower4BlowTime = 1000;
    RefreshComponents();
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlower1TempOnPanelClick(
      TObject *Sender)
{
    TempUserMachineEnv.DustBlower1Interval = 60000;
    TempUserMachineEnv.DustBlower1Delay = 0;
    TempUserMachineEnv.DustBlower1BlowTime = 1000;
    RefreshComponents();
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlower2TempOnPanelClick(
      TObject *Sender)
{
    TempUserMachineEnv.DustBlower2Interval = 60000;
    TempUserMachineEnv.DustBlower2Delay = 0;
    TempUserMachineEnv.DustBlower2BlowTime = 1000;
    RefreshComponents();
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlower3TempOnPanelClick(
      TObject *Sender)
{
    TempUserMachineEnv.DustBlower3Interval = 60000;
    TempUserMachineEnv.DustBlower3Delay = 0;
    TempUserMachineEnv.DustBlower3BlowTime = 1000;
    RefreshComponents();    
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlower4TempOnPanelClick(
      TObject *Sender)
{
	TempUserMachineEnv.DustBlower4Interval = 60000;
    TempUserMachineEnv.DustBlower4Delay = 0;
    TempUserMachineEnv.DustBlower4BlowTime = 1000;
    RefreshComponents();
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlower1AlwaysOffPanelClick(
      TObject *Sender)
{
    TempUserMachineEnv.DustBlower1Interval = 0;
    TempUserMachineEnv.DustBlower1Delay = 0;
    TempUserMachineEnv.DustBlower1BlowTime = 0;
    RefreshComponents();
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlower2AlwaysOffPanelClick(
      TObject *Sender)
{
    TempUserMachineEnv.DustBlower2Interval = 0;
    TempUserMachineEnv.DustBlower2Delay = 0;
    TempUserMachineEnv.DustBlower2BlowTime = 0;
    RefreshComponents();
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlower3AlwaysOffPanelClick(
      TObject *Sender)
{
    TempUserMachineEnv.DustBlower3Interval = 0;
    TempUserMachineEnv.DustBlower3Delay = 0;
    TempUserMachineEnv.DustBlower3BlowTime = 0;
    RefreshComponents();    
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlower4AlwaysOffPanelClick(
      TObject *Sender)
{
	TempUserMachineEnv.DustBlower4Interval = 0;
    TempUserMachineEnv.DustBlower4Delay = 0;
    TempUserMachineEnv.DustBlower4BlowTime = 0;
    RefreshComponents();
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlowerGlobalDisablePanelClick(
      TObject *Sender)
{
    TempUserMachineEnv.Enabled = 0;
    RefreshComponents();
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlowerGlobalEnablePanelClick(
      TObject *Sender)
{
    TempUserMachineEnv.Enabled = 1;
    RefreshComponents();
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::BlowerEditClick(
      TObject *Sender)
{
    TTntEdit *theEdit = (TTntEdit *) Sender;
    KeyboardForm->Text = theEdit->Text;
    if (KeyboardForm->ShowKeypad() == mrOk)
    {
        theEdit->Text = KeyboardForm->Text;
    }
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::Blower1IntervalEditChange(
      TObject *Sender)
{
    try
    {
        TTntEdit *theEdit = (TTntEdit *) Sender;
        double value = StrToFloat(theEdit->Text);
        switch (theEdit->Tag)
        {
            case 0:
                TempUserMachineEnv.DustBlower1Interval = value * 1000;
                break;
            case 1:
                TempUserMachineEnv.DustBlower1Delay = value * 1000;
                break;
            case 2:
                TempUserMachineEnv.DustBlower1BlowTime = value;
                break;
            case 3:
                TempUserMachineEnv.DustBlower2Interval = value * 1000;
                break;
            case 4:
                TempUserMachineEnv.DustBlower2Delay = value * 1000;
                break;
            case 5:
                TempUserMachineEnv.DustBlower2BlowTime = value;
                break;
            case 6:
                TempUserMachineEnv.DustBlower3Interval = value * 1000;
                break;
            case 7:
                TempUserMachineEnv.DustBlower3Delay = value * 1000;
                break;
            case 8:
                TempUserMachineEnv.DustBlower3BlowTime = value;
                break;
            case 9:
                TempUserMachineEnv.DustBlower4Interval = value * 1000;
                break;
            case 10:
                TempUserMachineEnv.DustBlower4Delay = value * 1000;
                break;
            case 11:
                TempUserMachineEnv.DustBlower4BlowTime = value;
				break;
			case 12:
				TempUserMachineEnv.DustBlower5Interval = value * 1000;
				break;
			case 13:
				TempUserMachineEnv.DustBlower5Delay = value * 1000;
				break;
			case 14:
				TempUserMachineEnv.DustBlower5BlowTime = value;
				break;
        }
    }
    catch (...)
    {

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

void __fastcall TMachineEnvSetupForm::DustBlower5AlwaysOnPanelClick(
      TObject *Sender)
{
	TempUserMachineEnv.DustBlower5Interval = 0;
	TempUserMachineEnv.DustBlower5Delay = 0;
    TempUserMachineEnv.DustBlower5BlowTime = 1000;
	RefreshComponents();
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlower5TempOnPanelClick(
      TObject *Sender)
{
	TempUserMachineEnv.DustBlower5Interval = 60000;
	TempUserMachineEnv.DustBlower5Delay = 0;
    TempUserMachineEnv.DustBlower5BlowTime = 1000;
	RefreshComponents();
}
//---------------------------------------------------------------------------

void __fastcall TMachineEnvSetupForm::DustBlower5AlwaysOffPanelClick(
      TObject *Sender)
{
	TempUserMachineEnv.DustBlower5Interval = 0;
	TempUserMachineEnv.DustBlower5Delay = 0;
    TempUserMachineEnv.DustBlower5BlowTime = 0;
    RefreshComponents();	
}
//---------------------------------------------------------------------------

