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

#include <vcl.h>
#pragma hdrstop

#include "FrmVmsLogF.h"
#include "VMSCommLibF.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxControls"
#pragma link "cxGraphics"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxPC"
#pragma link "dxSkinBlack"
#pragma link "dxSkinMcSkin"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma resource "*.dfm"
TFrmVmsLog *FrmVmsLog = NULL;
//---------------------------------------------------------------------------
__fastcall TFrmVmsLog::TFrmVmsLog(TComponent* Owner)
    : TForm(Owner)
{
    FTrafDay = Now().FormatString("yyyyMMdd");

    PgLog->ActivePage = TabTraf;

    reTrf->Lines->Clear();
    reLog->Lines->Clear();
}
//---------------------------------------------------------------------------

void __fastcall TFrmVmsLog::btnClearClick(TObject *Sender)
{
    try
    {
        if (PgLog->ActivePage == TabTraf) {
            reTrf->Lines->Clear();
        }
        else {
            reLog->Lines->Clear();
        }
        Application->ProcessMessages();
    }
    catch(Exception &e)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TFrmVmsLog::btnCopyClick(TObject *Sender)
{
    try
    {
        if (PgLog->ActivePage == TabTraf) {
            reTrf->SelectAll();
            reTrf->CopyToClipboard();
        }
        else {
            reLog->SelectAll();
            reLog->CopyToClipboard();
        }
        Application->ProcessMessages();
    }
    catch(Exception &e)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TFrmVmsLog::FormClose(TObject *Sender, TCloseAction &Action)
{
    Hide();
}
//---------------------------------------------------------------------------

void __fastcall TFrmVmsLog::FormShow(TObject *Sender)
{
    Application->ProcessMessages();
}
//---------------------------------------------------------------------------

void TFrmVmsLog::LogTraffic(String ALogDay, String ATrafTime)
{
    if (FTrafDay != ALogDay) {
        FTrafDay = ALogDay;
        reTrf->Lines->Clear();
    }

	if (ATrafTime != "")
	{
		reTrf->Lines->Add(ATrafTime);
	}
}
//---------------------------------------------------------------------------
void TFrmVmsLog::LogMsg(String AMsg)
{
    if (reLog->Lines->Count >= g_AppCfg.nMaxLogLines) {
        //reLog->Lines->Clear();
        reLog->Lines->Delete(0);
    }

    reLog->Lines->Add(Now().FormatString("yyyy-MM-dd hh:nn:ss") + ": " + AMsg);
}
//---------------------------------------------------------------------------


