//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <mmsystem.h>
#include <string.h>
#include <iostream.h>
#include <stdlib.h>
#include <dstring.h>
#include <winuser.h>
#include <time.h>
#include <dos.h>
#include <winbase.h>
#include <math.h>
#include "m2.h"
#include "m1.h"
#include "user_fun.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
int i,i1;
TIMECAPS tmp_timecaps;
time_b=0;
txd_time_add=0;
rxd_time_add=0;
Timer1_b=0;
CELL_Y=0;
all_delay=0;
//-----
for (i=0;i<36;i++)
{
sc_rxd_st[i]=0;
sc_rxd_end[i]=0;
sc_tp_b[i]=0;
cell_draw_b[i]=0;
link_sta[i]=0;
link_num[i]=0;
link_delay[i]=20;
link_enb[i]=0;
link_time[i]=0;
loop_up_b[i]=0;
sc_t_all[i]=0;
sc_r_all[i]=0;
rxd_addr_err[i]=0;
}
//-------------------------------------
for (i = 0; i < 36; i++)
{
//Form2->set_StringGrid1->Cells[0][1+i]=i+1;
Form2->run_StringGrid1->Cells[0][1+i]=i+1;
//Form2->run_StringGrid1->Cells[2][1+i]=0;
//Form2->run_StringGrid1->Cells[3][1+i]=0;
Form2->run_StringGrid1->Cells[4][1+i]="";
Form2->run_StringGrid1->Cells[5][1+i]="";
}
//-------------------------------------------
for (i = 0; i < 4; i++)
{
Form2->set_StringGrid1->Cells[0][1+i]=i+1;
}
for (i = 0; i < 9; i++)
{
Form2->station_StringGrid1->Cells[0][1+i]=i+1;
}
station_StringGrid1->Cells[0][0]="序号";
station_StringGrid1->Cells[1][0]="站名";
set_StringGrid1->Cells[0][0]="序号";
set_StringGrid1->Cells[1][0]="主机名";
set_StringGrid1->Cells[2][0]="站号";
set_StringGrid1->Cells[3][0]="IP地址";
set_StringGrid1->Cells[4][0]="端口号";
//------------
run_StringGrid1->Cells[0][0]="序号";
run_StringGrid1->Cells[1][0]="站名";
run_StringGrid1->Cells[2][0]="主机命名";
run_StringGrid1->Cells[3][0]="发送次数";
run_StringGrid1->Cells[4][0]="接收次数";
run_StringGrid1->Cells[5][0]="丢包率";
run_StringGrid1->Cells[6][0]="连接时间";
run_StringGrid1->Cells[7][0]="连接次数";
//run_StringGrid1->Cells[6][0]="连接状态";
//--------------------------
for (i=0;i<36;i++)
{
net[i]=new TClientSocket(ClientSocket1);
net[i]->OnConnecting=ClientSocket1Connecting;
net[i]->OnConnect=ClientSocket1Connect;
net[i]->OnDisconnect=ClientSocket1Disconnect;
net[i]->OnError=ClientSocket1Error;
net[i]->OnLookup=ClientSocket1Lookup;
//StringGrid1->Cells[5][1+i]=0;
}
//---------------------
//--------------------------
for (i=0;i<9;i++)
{
run_label[i]=new TLabel(run_Label1);
//run_led[i]=new TImage(Black_Image1);
//if ((link_enb[4*i]==1)||(link_enb[(4*i)+1]==1)||(link_enb[(4*i)+2]==1)||(link_enb[(4*i)+3]==1))
{
run_label[i]->Parent=Panel1;
//run_label[i]->Caption=station_StringGrid1->Cells[1][1+i];
run_label[i]->Top=run_Label1->Top;
run_label[i]->Left=43+(i*80);
run_label[i]->Enabled=0;
run_label[i]->Visible=0;
//run_led[i]->Parent=Panel1;
// run_led[i]->Picture=Black_Image1->Picture;//->LoadFromFile("Open.ico");
// run_led[i]->Top=192;
// run_led[i]->Left=16+(i*80);
//run_led[i]->Height=Image2->Height;
//run_led[i]->Width=Image2->Width;
// run_led[i]->Enabled=1;
// run_led[i]->Visible=1;
}
}
//--------------------------------------
for (i=0;i<36;i++)
{
//run_label[i]=new TLabel(run_Label1);
run_led[i]=new TImage(Black_Image1);
//if (link_enb[i]==1)
{
run_led[i]->Parent=Panel1;
run_led[i]->Picture=Black_Image1->Picture;//->LoadFromFile("Open.ico");
run_led[i]->Top=200-((i%4)*24);
run_led[i]->Left=16+((i/4)*80);
//run_led[i]->Height=Image2->Height;
//run_led[i]->Width=Image2->Width;
run_led[i]->Enabled=0;
run_led[i]->Visible=0;
}
}
//-------------
read_sys_ini();
//------------
i1=0;
for (i = 0; i < 36; i++)
{
if (link_enb[i]==0) continue;
Form2->run_StringGrid1->Cells[3][1+i]=0;
Form2->run_StringGrid1->Cells[4][1+i]=0;
Form2->run_StringGrid1->Cells[7][1+i]="";
i1++;
}
if (i1<12) Form2->run_StringGrid1->ScrollBars=ssNone;
//-----------------------------------------------------------------------
if (timeGetDevCaps(&tmp_timecaps,sizeof(tmp_timecaps))==TIMERR_NOERROR)
{
//ShowMessage(tmp_timecaps.wPeriodMin);
timeBeginPeriod(tmp_timecaps.wPeriodMin);
//FirstTime=timeGetTime();
time_id=timeSetEvent(1,1,&dzb,1,TIME_PERIODIC);
} //设置ms定时器
//-------------------------
/*
for (i=0;i<36;i++)
{
if (link_enb[i]==0) continue;
//net[i]=new TClientSocket(ClientSocket1);
net[i]->Address=ip_port[i].IP;
net[i]->Port=ip_port[i].PORT;
net[i]->ClientType=ctNonBlocking;
net[i]->Active=false;
}*/
//---------------------
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormCreate(TObject *Sender)
{
int i;
i=(Screen->Height/2)-(Form2->Height/2);
if (i>=0) Form2->Top=i;
else Form2->Top=0;
i=(Screen->Width/2)-(Form2->Width/2);
if (i>=0) Form2->Left=i;
else Form2->Left=0;
//在任务栏显示
DWORD dwExStyle = GetWindowLong(Handle,GWL_EXSTYLE);
dwExStyle |= WS_EX_APPWINDOW;
SetWindowLong(Handle,GWL_EXSTYLE,dwExStyle);
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
//int i;
/*
timeKillEvent(time_id);
timeEndPeriod(1);
Timer1->Enabled=0;
for (i=0;i<32;i++)
{
if (net[i]->Active==true) net[i]->Active=false;
delete net[i];
delete run_label[i];
delete run_led[i];
}
*/
Form1->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ClientSocket1Connect(TObject *Sender, TCustomWinSocket *Socket)
{
int i,i1;
//TClientSocket *net_tmp;
//net_tmp=(TClientSocket *) Sender;
i1=0;
for (i = 0; i < 36; i++)
{
if (link_enb[i]==0) continue;
if ((Socket->RemotePort==ip_port[i].PORT)&&(Socket->RemoteAddress==ip_port[i].IP))
{
link_sta[i]=1;
link_num[i]++;
link_delay[i]=0;
link_time[i]=0;
Form2->run_StringGrid1->Cells[2][1+i1]=Socket->RemoteHost;
break;
}
i1++;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ClientSocket1Connecting(TObject *Sender, TCustomWinSocket *Socket)
{
int i,i1;
//TClientSocket *net_tmp;
//net_tmp=(TClientSocket *) Sender;
for (i = 0; i < 36; i++)
{
if (link_enb[i]==0) continue;
if ((Socket->RemotePort==ip_port[i].PORT)&&(Socket->RemoteAddress==ip_port[i].IP))
//if ((net_tmp->Port==ip_port[i].PORT)&&(net_tmp->Address==ip_port[i].IP))
{
link_sta[i]=2;
link_time[i]=0;
break;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ClientSocket1Disconnect(TObject *Sender, TCustomWinSocket *Socket)
{
int i,i1;
//TClientSocket *net_tmp;
//net_tmp=(TClientSocket *) Sender;
i1=0;
for (i = 0; i < 36; i++)
{
if (link_enb[i]==0) continue;
if ((Socket->RemotePort==ip_port[i].PORT)&&(Socket->RemoteAddress==ip_port[i].IP))
//if ((net_tmp->Port==ip_port[i].PORT)&&(net_tmp->Address==ip_port[i].IP))
{
link_sta[i]=0;
link_time[i]=0;
cell_draw_b[i1]=1;
run_StringGrid1->Cells[6][1+i1]=Date()+Time();
break;
}
i1++;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ClientSocket1Error(TObject *Sender, TCustomWinSocket *Socket,