/**************************************************************************
  Network Satellite Editor Program

                                                           2000. 10. 01
                                                                   이니


  Form       -  Main           (기본 폼)
                NetworkEditor  (Network 정보 수정 폼)
  Unit       -  Main           (기본 폼 설정 및 이벤트)
                File           (파일 입 출력 부분)
                Network        (Network 처리)
                NetworkEditor  (Network 정보 수정 폼)
                Transponder    (Transponder 처리)
                Program        (Program 처리)
                Miscellany     (기타 처리 부분)
                Import         (Database 처리)
  Component  -  Labal3D        (원래는 Delphi용 입니다. 컴파일 되어 있습니다)
                나머지 Component는 C++ Bulider에서 제공하는 기본 라이브러리 임


  최근 수정  -  2002년 4월 25일 (서승일 주임님 프로토콜)
***************************************************************************/


/**************************************************************************
  Include 및 시스템 설정
***************************************************************************/
#include <vcl.h>
#include <io.h>
#include <dir.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <fcntl.h>
#include <registry.hpp>
#pragma hdrstop

#include "Unit_Main.h"
#include "Unit_File.h"
#include "Unit_Network.h"
#include "Unit_NetworkEditor.h"
#include "Unit_Transponder.h"
#include "Unit_Program.h"
#include "Unit_Miscellany.h"
#include "Unit_Import.h"
#include "Unit_Transfer.h"

#pragma package(smart_init)
#pragma link "Label3D"
#pragma resource "*.dfm"

TMain      *Main;
bool       INITIALIZED = false;

/**************************************************************************
  TMain
  - OnCreate Method
***************************************************************************/
__fastcall TMain::TMain(TComponent* Owner) : TForm(Owner)
{

 CONNECTED         = false;
 DOWNLOADING       = false;
 CONNECTION_STATUS = 0;

}


/**************************************************************************
  FormActivate
  - Oncreate와 비슷하지만 폼이 모두 완성된 상태에서 시작된다는 차이가 있다
***************************************************************************/
void __fastcall TMain::FormActivate(TObject *Sender)
{

 int               itNetworkIndex, itNetworkTop, itTransponderIndex, itTransponderTop;



 if(INITIALIZED) return;


 TRegistry    *trRegistry = new TRegistry;


 trRegistry->RootKey = HKEY_LOCAL_MACHINE;
 trRegistry->LazyWrite = false;

 trRegistry->OpenKey("Software\\Network Editor", true);

 EditFileName = trRegistry->ReadString("LastFilename");

 if(trRegistry->ReadString("ComPort") != "")
   COMPORT    = trRegistry->ReadString("ComPort").ToInt();
  else
   COMPORT    = 0;

 if(trRegistry->ReadString("BaudRate") != "")
   BAUDRATE   = trRegistry->ReadString("BaudRate").ToInt();
  else
   BAUDRATE   = 0;


 trRegistry->CloseKey();

 delete trRegistry;

 
 LoadProcess(EditFileName);
 INITIALIZED = true;

}


/**************************************************************************
  TiTimerTimer
  - Timer Tick Thread
***************************************************************************/
void __fastcall TMain::TiTimerTimer(TObject *Sender)
{

 if(!CONNECTED)
   Main->Caption = "Digital Satellite Receiver Database Editor";
  else
   Main->Caption = "Digital Satellite Receiver Database Editor (Connected)";

 if(Modified) MiSave->Enabled = True;
         else MiSave->Enabled = False;

 if(Main->PnNetworkInsertLine->Tag) {
   if(ScrollDelay > SCROLL_DELAY_COUNT) {
     Main->LbNetworkList->TopIndex += Main->PnNetworkInsertLine->Tag;
     ScrollDelay = 0;
    } else {
     Main->ScrollDelay ++;
   }
 }

 if(Main->PnTransponderInsertLine->Tag) {
   if(Main->ScrollDelay > SCROLL_DELAY_COUNT) {
     Main->LbTransponderList->TopIndex += Main->PnTransponderInsertLine->Tag;
     Main->ScrollDelay = 0;
    } else {
     Main->ScrollDelay ++;
   }
 }

 if(Main->PnProgramTVInsertLine->Tag) {
   if(Main->ScrollDelay > SCROLL_DELAY_COUNT) {
     Main->LbProgramTVList->TopIndex += Main->PnProgramTVInsertLine->Tag;
     Main->ScrollDelay = 0;
    } else {
     Main->ScrollDelay ++;
   }
 }

 if(Main->PnProgramRadioInsertLine->Tag) {
   if(Main->ScrollDelay > SCROLL_DELAY_COUNT) {
     Main->LbProgramRadioList->TopIndex += Main->PnProgramRadioInsertLine->Tag;
     Main->ScrollDelay = 0;
    } else {
     Main->ScrollDelay ++;
   }
 }


}


/**************************************************************************
  BackupData
  - 데이터를 임시로 백업한다
***************************************************************************/
void __fastcall TMain::BackupData()
{

 int               itCount;


 for(itCount = 0; itCount < MAX_NETWORK_DATA; itCount ++) {
   Network_Backup_List[itCount]  = Network_List[itCount];
   Network_Backup_VList[itCount] = Network_VList[itCount];
 }

 for(itCount = 0; itCount < MAX_TRANSPONDER_DATA; itCount ++) {
   Transponder_Backup_List[itCount]  = Transponder_List[itCount];
   Transponder_Backup_VList[itCount] = Transponder_VList[itCount];
 }

 for(itCount = 0; itCount < MAX_PROGRAM_TV_DATA; itCount ++) {
   Program_TV_Backup_List[itCount]  = Program_TV_List[itCount];
   Program_TV_Backup_VList[itCount] = Program_TV_VList[itCount];
 }

 for(itCount = 0; itCount < MAX_PROGRAM_RADIO_DATA; itCount ++) {
   Program_Radio_Backup_List[itCount]  = Program_Radio_List[itCount];
   Program_Radio_Backup_VList[itCount] = Program_Radio_VList[itCount];
 }

}


/**************************************************************************
  BackupData
  - 데이터를 임시로 백업한다
***************************************************************************/
void __fastcall TMain::RecoveryData()
{

 int               itCount;


 for(itCount = 0; itCount < MAX_NETWORK_DATA; itCount ++) {
   Network_List[itCount]  = Network_Backup_List[itCount];
   Network_VList[itCount] = Network_Backup_VList[itCount];
 }

 for(itCount = 0; itCount < MAX_TRANSPONDER_DATA; itCount ++) {
   Transponder_List[itCount]  = Transponder_Backup_List[itCount];
   Transponder_VList[itCount] = Transponder_Backup_VList[itCount];
 }

 for(itCount = 0; itCount < MAX_PROGRAM_TV_DATA; itCount ++) {
   Program_TV_List[itCount]  = Program_TV_Backup_List[itCount];
   Program_TV_VList[itCount] = Program_TV_Backup_VList[itCount];
 }

 for(itCount = 0; itCount < MAX_PROGRAM_RADIO_DATA; itCount ++) {
   Program_Radio_List[itCount]  = Program_Radio_Backup_List[itCount];
   Program_Radio_VList[itCount] = Program_Radio_Backup_VList[itCount];
 }

}


/**************************************************************************
  ButtonDown
  - 버튼이 들어가 보이는 효과를 한다
***************************************************************************/
void __fastcall TMain::ButtonDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{

 if(Button == mbLeft) {
   dynamic_cast<TControl *>(Sender)->Top  = dynamic_cast<TControl *>(Sender)->Top  + 1;
   dynamic_cast<TControl *>(Sender)->Left = dynamic_cast<TControl *>(Sender)->Left + 1;
 }

}


/**************************************************************************
  ButtonUp
  - 버튼이 다시 나오는 효과를 한다
***************************************************************************/
void __fastcall TMain::ButtonUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{

 if(Button == mbLeft) {
   dynamic_cast<TControl *>(Sender)->Top  = dynamic_cast<TControl *>(Sender)->Top  - 1;
   dynamic_cast<TControl *>(Sender)->Left = dynamic_cast<TControl *>(Sender)->Left - 1;
 }

}


/**************************************************************************
  FormCloseQuery
  - 프로그램이 종료될 때 발생되는 이벤트
***************************************************************************/
void __fastcall TMain::FormCloseQuery(TObject *Sender, bool &CanClose)
{

 if(Modified)
   if(QuestionModified() == ID_CANCEL) CanClose = False;

}


/**************************************************************************
  ImExitClick
  - 프로그램을 종료한다
***************************************************************************/
void __fastcall TMain::ImExitClick(TObject *Sender)
{

 Main->Close();

}


/**************************************************************************
  FormClose
  - 프로그램 종료시 메모리 해제 루틴
***************************************************************************/
void __fastcall TMain::FormClose(TObject *Sender, TCloseAction &Action)
{

 // 포인터에서 배열로 바뀜. 사용할 필요 없음
 // free(Network_List);
 // free(Transponder_List);
 // free(Program_List);

}


/**************************************************************************
  ImNewClick
  - 불러오기 버튼을 눌렀을 경우의 처리
***************************************************************************/
void __fastcall TMain::MiNewClick(TObject *Sender)
{

 if(Modified)
   if(QuestionModified() == ID_CANCEL) return;


 Initialize();

 PrintNetwork();
 PrintTransponder();

 WriteLastFile("");

}


/**************************************************************************
  ImLoadClick
  - 불러오기 버튼을 눌렀을 경우의 처리
***************************************************************************/
void __fastcall TMain::ImLoadClick(TObject *Sender)
{

 int     itTemp;


 if(Modified)
   if(QuestionModified() == ID_CANCEL) return;


 if(OdAsk->Execute())
   LoadProcess(OdAsk->FileName);

}


/**************************************************************************
  ImSaveAsClick
  - 저장 버튼을 눌렀을 경우의 처리
***************************************************************************/
void __fastcall TMain::ImSaveAsClick(TObject *Sender)
{

 if(SdAsk->Execute())
   WriteDataFile(SdAsk->FileName, false);

}


/**************************************************************************
  ImSaveClick
  - 파일 저장 처리 부분
***************************************************************************/
void __fastcall TMain::ImSaveClick(TObject *Sender)
{

 if(EditFileName == "") {
   // 파일 이름이 없을 경우
   ImSaveAsClick(NULL);

  } else {

   // 파일 이름이 있을 경우
   WriteDataFile(EditFileName, false);
 }

}


/**************************************************************************
  MiImportClick
  - Database Import를 클릭했을때 발생되는 이벤트
***************************************************************************/
void __fastcall TMain::MiImportClick(TObject *Sender)
{

 if(Modified)
   if(QuestionModified() == ID_CANCEL) return;

 ImportData();

}


/**************************************************************************
  CbPolarizationChange
  - Polarization 변경시에 데이터를 갱신한다
***************************************************************************/
void __fastcall TMain::CbPolarizationChange(TObject *Sender)
{
/*
 Transponder_List->Data[CbPolarization->Tag].Polarization = CbPolarization->ItemIndex;

 RefreshProcess = RefreshProcess | REFRESH_TRANSPONDER;
 Modified = True;
*/
}


/**************************************************************************
  CbFECChange
  - Polarization 변경시에 데이터를 갱신한다
***************************************************************************/
void __fastcall TMain::CbFECChange(TObject *Sender)
{
/*
 Transponder_List->Data[CbFEC->Tag].PunctureRate = CbFEC->ItemIndex;

 RefreshProcess = RefreshProcess | REFRESH_TRANSPONDER;
 Modified = True;
*/
}


/**************************************************************************
  FormKeyPress
  - 키가 눌리면 그 키 값을 저장한다
***************************************************************************/
void __fastcall TMain::FormKeyPress(TObject *Sender, char &Key)
{

 switch(Key) {
   case 26 : { // Ctrl + Z 처리
     RecoveryData();
     PrintNetwork();
     PrintTransponder();

     break;
   }

   case 13 : { // Manager Mode 처리
     if(InputString.UpperCase() == MANAGER_PASSWORD) {
       ShowMessage ("Turn to management mode");
       MiImport->Visible = True;
     }

     break;
   }

   default : {
     InputString = InputString + Key;

     if(InputString.Length() > 20)
       InputString = "";

     break;
   }
 }

}


/**************************************************************************
  MiDownloadClick
  - Download 처리
***************************************************************************/
void __fastcall TMain::MiDownloadClick(TObject *Sender)
{

 Transfer->Show();

}


/**************************************************************************
  CreateCommand
  - 프로세스로 인한 외부 파일 실행
***************************************************************************/
void __fastcall TMain::CreateCommand(String stCommand)
{

 HWND                   hdWindow;
 STARTUPINFO            siParam;
 PROCESS_INFORMATION    piParam;
 DWORD                  dwExitCode;


 // 초기화
 FillMemory(&siParam, sizeof(STARTUPINFO), 0);
 FillMemory(&piParam, sizeof(PROCESS_INFORMATION), 0);

 // Param 섯팅
 siParam.cb          = sizeof(STARTUPINFO);
 siParam.dwFlags     = STARTF_USESHOWWINDOW;
 siParam.wShowWindow = SW_HIDE;

 CreateProcess(NULL, stCommand.c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &siParam, &piParam);
 WaitForInputIdle(GetCurrentProcess(), INFINITE);

 // 프로세스가 종료될때까지 대기함
 if(piParam.hProcess) {
   dwExitCode = STILL_ACTIVE;

   while(dwExitCode == STILL_ACTIVE) {
     WaitForSingleObject(piParam.hProcess, 1000);
     GetExitCodeProcess(piParam.hProcess, &dwExitCode);
     UpdateWindow(Main->Handle);
   }
 }

}


/**************************************************************************
  Event 루틴
  - 각 이벤트 루틴으로 해당 Function으로 연결한다
***************************************************************************/
void __fastcall TMain::LbNetworkListEndDrag(TObject *Sender, TObject *Target, int X, int Y)
{
 PnNetworkInsertLine->Visible = False;
 Main->PnNetworkInsertLine->Tag = 0;
}

void __fastcall TMain::ImNetworkModifyClick(TObject *Sender)
{
 NetworkModifyClick(Sender);
}

void __fastcall TMain::ImNetworkAddClick(TObject *Sender)
{
 NetworkAddClick(Sender);
}

void __fastcall TMain::ImNetworkDeleteClick(TObject *Sender)
{
 NetworkDeleteClick(Sender);
}

void __fastcall TMain::ImSatelliteAddClick(TObject *Sender)
{
 NetworkAddClick(Sender);
}

void __fastcall TMain::ImSatelliteModifyClick(TObject *Sender)
{
 NetworkModifyClick(Sender);
}

void __fastcall TMain::SgTransponderGetEditText(TObject *Sender, int ACol, int ARow, AnsiString &Value)
{
 TransponderGetEditText(Sender, ACol, ARow, Value);
}

void __fastcall TMain::SgTransponderSetEditText(TObject *Sender, int ACol, int ARow, const AnsiString Value)
{
 TransponderSetEditText(Sender, ACol, ARow, Value);
}

void __fastcall TMain::SgTransponderKeyPress(TObject *Sender, char &Key)
{
 if((unsigned char)Key <= 128) TransponderKeyPress(Sender, Key);
}

void __fastcall TMain::SgTransponderDrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State)
{
 TransponderDrawCell(Sender, ACol, ARow, Rect);
}

void __fastcall TMain::SgProgramDrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State)
{
 ProgramDrawCell(Sender, ACol, ARow, Rect);
}

void __fastcall TMain::SgProgramGetEditText(TObject *Sender, int ACol, int ARow, AnsiString &Value)
{
 ProgramGetEditText(Sender, ACol, ARow, Value);
}

void __fastcall TMain::SgProgramKeyPress(TObject *Sender, char &Key)
{
 if((unsigned char)Key <= 128) ProgramKeyPress(Sender, Key);
}

void __fastcall TMain::SgProgramSetEditText(TObject *Sender, int ACol, int ARow, const AnsiString Value)
{
 ProgramSetEditText(Sender, ACol, ARow, Value);
}

void __fastcall TMain::ImProgramAddClick(TObject *Sender)
{
 ProgramAddClick(Sender);
}

void __fastcall TMain::ImProgramDeleteClick(TObject *Sender)
{
 ProgramDeleteClick(Sender);
}

void __fastcall TMain::MiLoadClick(TObject *Sender)
{
 ImLoadClick(Sender);
}

void __fastcall TMain::MiSaveClick(TObject *Sender)
{
 int               itPreviousTVIndex = LbProgramTVList->ItemIndex,
                   itPreviousTVTop = LbProgramTVList->TopIndex,
                   itPreviousRadioIndex = LbProgramRadioList->ItemIndex,
                   itPreviousRadioTop = LbProgramRadioList->TopIndex;

 WriteLastIndex();
 ImSaveClick(Sender);

 LbProgramTVList->ItemIndex    = itPreviousTVIndex;
 LbProgramTVList->TopIndex     = itPreviousTVTop;
 LbProgramRadioList->ItemIndex = itPreviousRadioIndex;
 LbProgramRadioList->TopIndex  = itPreviousRadioTop;
}

void __fastcall TMain::MiSaveAsClick(TObject *Sender)
{
 ImSaveAsClick(Sender);
}

void __fastcall TMain::MiExitClick(TObject *Sender)
{
 ImExitClick(Sender);
}

void __fastcall TMain::SgTransponderMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
 TransponderSelect(Sender);
}

void __fastcall TMain::LbNetworkListDblClick(TObject *Sender)
{
 ImSatelliteModifyClick(Sender);
}

void __fastcall TMain::LbNetworkListDragOver(TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool &Accept)
{
 Accept = NetworkListDragOver(Sender, Source, X, Y);
}

void __fastcall TMain::LbNetworkListDragDrop(TObject *Sender, TObject *Source, int X, int Y)
{
 NetworkListDragDrop(Sender, Source, X, Y);
}

void __fastcall TMain::LbTransponderListDragDrop(TObject *Sender, TObject *Source, int X, int Y)
{
 TransponderListDragDrop(Sender, Source, X, Y);
}

void __fastcall TMain::LbTransponderListDragOver(TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool &Accept)
{
 Accept = TransponderListDragOver(Sender, Source, X, Y);
}

void __fastcall TMain::LbTransponderListEndDrag(TObject *Sender, TObject *Target, int X, int Y)
{
 PnTransponderInsertLine->Visible = False;
 Main->PnTransponderInsertLine->Tag = 0;
}

void __fastcall TMain::LbProgramTVListDragDrop(TObject *Sender, TObject *Source, int X, int Y)
{
 ProgramTVListDragDrop(Sender, Source, X, Y);
}

void __fastcall TMain::LbProgramTVListDragOver(TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool &Accept)
{
 Accept = ProgramTVListDragOver(Sender, Source, X, Y);
}

void __fastcall TMain::LbProgramTVListEndDrag(TObject *Sender, TObject *Target, int X, int Y)
{
 PnProgramTVInsertLine->Visible = False;
 Main->PnProgramTVInsertLine->Tag = 0;
}

void __fastcall TMain::LbProgramRadioListDragDrop(TObject *Sender, TObject *Source, int X, int Y)
{
 ProgramRadioListDragDrop(Sender, Source, X, Y);
}

void __fastcall TMain::LbProgramRadioListDragOver(TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool &Accept)
{
 Accept = ProgramRadioListDragOver(Sender, Source, X, Y);
}

void __fastcall TMain::LbProgramRadioListEndDrag(TObject *Sender, TObject *Target, int X, int Y)
{
 PnProgramRadioInsertLine->Visible = False;
 Main->PnProgramRadioInsertLine->Tag = 0;
}

void __fastcall TMain::ImTransponderDeleteClick(TObject *Sender)
{
 TransponderDeleteClick(Sender);
}

void __fastcall TMain::ImSatelliteDeleteClick(TObject *Sender)
{
 NetworkDeleteClick(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TMain::HcNetworkListSectionClick(THeaderControl *HeaderControl, THeaderSection *Section)
{
 NetworkListSort(Section->Index);
}
//---------------------------------------------------------------------------

void __fastcall TMain::ImTransponderAddClick(TObject *Sender)
{
 TransponderAddClick(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TMain::ImTransponderModifyClick(TObject *Sender)
{
 TransponderModify(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TMain::LbTransponderListDblClick(TObject *Sender)
{
 ImTransponderModifyClick(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TMain::HcTransponderListSectionClick(THeaderControl *HeaderControl, THeaderSection *Section)
{
 TransponderListSort(Section->Index);
}
//---------------------------------------------------------------------------
void __fastcall TMain::LbProgramTVListEnter(TObject *Sender)
{
 LbProgramRadioList->TopIndex  = 0;
 LbProgramRadioList->ItemIndex = -1;

 Main->SelectedProgram = PROGRAM_TV;
}
//---------------------------------------------------------------------------

void __fastcall TMain::LbProgramRadioListEnter(TObject *Sender)
{
 LbProgramTVList->TopIndex  = 0;
 LbProgramTVList->ItemIndex = -1;

 Main->SelectedProgram = PROGRAM_RADIO;
}
//---------------------------------------------------------------------------

void __fastcall TMain::LbProgramTVListClick(TObject *Sender)
{
 Main->SelectedProgram = PROGRAM_TV;
 LocateParentTransponder(LbProgramTVList->ItemIndex, PROGRAM_TV);
 WriteLastIndex();
}
//---------------------------------------------------------------------------

void __fastcall TMain::LbProgramRadioListClick(TObject *Sender)
{
 Main->SelectedProgram = PROGRAM_RADIO;
 LocateParentTransponder(LbProgramRadioList->ItemIndex, PROGRAM_RADIO);
 WriteLastIndex();
}
//---------------------------------------------------------------------------

void __fastcall TMain::ImProgramModifyClick(TObject *Sender)
{
 ProgramModifyClick(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TMain::LbProgramTVListDblClick(TObject *Sender)
{
 ProgramModifyClick(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TMain::LbProgramRadioListDblClick(TObject *Sender)
{
 ProgramModifyClick(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TMain::HcProgramTVListSectionClick(THeaderControl *HeaderControl, THeaderSection *Section)
{
 ProgramListSort(Section->Index, PROGRAM_TV);
}
//---------------------------------------------------------------------------

void __fastcall TMain::HcProgramRadioListSectionClick(THeaderControl *HeaderControl, THeaderSection *Section)
{
 ProgramListSort(Section->Index, PROGRAM_RADIO);
}
//---------------------------------------------------------------------------
void __fastcall TMain::LbNetworkListKeyUp(TObject *Sender, WORD &Key, TShiftState Shift)
{
 if(Key == 226 || Key == 229) return;

 LbTransponderList->TopIndex  = 0;
 LbTransponderList->ItemIndex = -1;

 PrintTransponder();
}
//---------------------------------------------------------------------------

void __fastcall TMain::LbTransponderListKeyUp(TObject *Sender, WORD &Key, TShiftState Shift)
{

 if(Key == 226 || Key == 229) return;

 if(Key == 27) {
   LbTransponderList->ItemIndex = -1;
   WriteLastIndex();
 }

 PrintProgram();
}
//---------------------------------------------------------------------------

void __fastcall TMain::LbTransponderListMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
 PrintProgram();
}
//---------------------------------------------------------------------------

void __fastcall TMain::ImProgramSortClick(TObject *Sender)
{
 ProgramListSort(99, PROGRAM_TV);
 ProgramListSort(99, PROGRAM_RADIO);
}
//---------------------------------------------------------------------------

void __fastcall TMain::MiUndoClick(TObject *Sender)
{

 RecoveryData();
 PrintNetwork();
 PrintTransponder();

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

void __fastcall TMain::PrintTVRadioData(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State)
{

 TListBox          *_lbListBox = dynamic_cast<TListBox *>(Control);


 if(_lbListBox->Items->Strings[Index].SubString(1, 1) == "!") {
   _lbListBox->Canvas->TextRect(Rect, Rect.Left, Rect.Top + 3, _lbListBox->Items->Strings[Index].SubString(2, 100));
   _lbListBox->Canvas->Font->Color = clMaroon;
   _lbListBox->Canvas->TextRect(::Rect(Rect.Right - 18, Rect.Top, Rect.Right, Rect.Bottom), Rect.Right - 18, Rect.Top + 3, "CA");
  } else {
   _lbListBox->Canvas->TextRect(Rect, Rect.Left, Rect.Top + 3, _lbListBox->Items->Strings[Index]);
 }

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

void __fastcall TMain::LbNetworkListClick(TObject *Sender)
{

 LbTransponderList->ItemIndex = -1;
 LbTransponderList->TopIndex  = 0;

 PrintTransponder();

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


