13,825
社区成员
发帖
与我相关
我的任务
分享
void __fastcall LEDDataBuffer::Execute()
{
while(!Terminated)
{
ExecSQL();
::Sleep(10000);
}
}
void __fastcall TMainForm::FormShow(TObject *Sender)
{
//多LED刷新第一个页面
TimerPageChangeTimer(Sender);
LEDDataBufferThread->Resume();
}
//线程部分(里面的循环,每次循环都在2000数据左右)
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "LEDDataBufferUnit.h"
#include "datamodule.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall LEDDataBuffer::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
//---------------------------------------------------------------------------
__fastcall LEDDataBuffer::LEDDataBuffer(bool CreateSuspended)
: TThread(CreateSuspended)
{
//Timer1->Interval=10000;
}
//---------------------------------------------------------------------------
/*
void __fastcall LEDDataBuffer::Timer1Timer(TObject *Sender)
{
//Synchronize(ExecSQL);
}
*/
void __fastcall LEDDataBuffer::ExecSQL()
{
sql="select L.BufferID,T.* from (select showno,count(showno)as [Count] from LEDDataBuffer \
group by showno having count(showno) >1)T join LEDSendData L on T.ShowNo=L.ShowNo";
DataModule1->show(sql,DataModule1->ADOQLEDDataBufferThirdShow);
//循环检索这个区域在缓存的数据
while(!DataModule1->ADOQLEDDataBufferThirdShow->Eof)
{
//检索1--检索按照ID排序大约正在播放ID的数据
sql="select top 1* from LEDDataBuffer where ShowNo="+DataModule1->ADOQLEDDataBufferThirdShow->FieldByName("ShowNo")->AsString+" \
and ID>"+DataModule1->ADOQLEDDataBufferThirdShow->FieldByName("Bufferid")->AsString;
DataModule1->show(sql,DataModule1->ADOQLEDDataBufferThirdShow1);
//检索1---无结果--表示已经是最后一个了,要返回到第一个数据
if(DataModule1->ADOQLEDDataBufferThirdShow1->Eof)
{
//检索2---检索这个区域在缓存的第一个数据
sql="select top 1* from LEDDataBuffer where ShowNo="+DataModule1->ADOQLEDDataBufferThirdShow->FieldByName("ShowNo")->AsString+"\
order by ID asc";
DataModule1->show(sql,DataModule1->ADOQLEDDataBufferThirdShow1);
if(DataModule1->ADOQLEDDataBufferThirdShow1->Eof)
{
//检索2---无结果--表示已经是已经没有数据,返回空!!
sql="select top 1 0 as ID ,'' as ShowNo,'' as SendData,'红色' as Color from LEDDataBuffer ";
DataModule1->show(sql,DataModule1->ADOQLEDDataBufferThirdShow1);
}
}
//将检索的数据更新到发送表,并将发送状态改为“未发送”
sql="update LEDSendData set SendData='"+DataModule1->ADOQLEDDataBufferThirdShow1->FieldByName("SendData")->AsString+"',\
FontColor='"+DataModule1->ADOQLEDDataBufferThirdShow1->FieldByName("Color")->AsString+"',\
Bufferid="+DataModule1->ADOQLEDDataBufferThirdShow1->FieldByName("ID")->AsString+",IsSend=0 \
where Showno="+DataModule1->ADOQLEDDataBufferThirdShow->FieldByName("ShowNo")->AsString;
DataModule1->exec(sql,DataModule1->ADOQLEDDataBufferThirdExec);
::Sleep(1000);
DataModule1->ADOQLEDDataBufferThirdShow->Next();
}
}
void __fastcall LEDDataBuffer::Execute()
{
//---- Place thread code here ----
//Timer1->OnTimer=Timer1Timer;
while(!Terminated)
{
Synchronize(ExecSQL);
::Sleep(10000);
}
}
//---------------------------------------------------------------------------