📄 epgdeal.cpp
字号:
//判断当天有无Epg信息,无则加入到数据库中
if(!DealDbCheckHasEpg(pChan))
return FALSE;
//取当前的第一个,看有无相等的
s.Format("select * from epginf where tvnum =%d and datediff(\"n\", tvStartT, #%s#)=0 and datediff(\"d\", tvStartT, #%s#)=0 order by tvStartT"
, pChan->m_nEpgNum, s1.LockBuffer(), s1.LockBuffer());
lRet = DealDbLocate(s);
if(lRet == 0)
{
//取比当前时间稍早的一个
s.Format("select * from epginf where tvnum =%d and datediff(\"n\", tvStartT, #%s#)>0 and datediff(\"d\", tvStartT, #%s#)=0 order by tvStartT"
, pChan->m_nEpgNum, s1.LockBuffer(), s1.LockBuffer());
lRet = DealDbLocate(s);
}
if(lRet > 0)
{
m_pRecordset->MoveLast();
DealDbGetCurEpgRecrod();
nNum -= 1;
}
//取后面的几个
s.Format("select top %d * from epginf where tvnum =%d and datediff(\"n\", tvStartT, #%s#)<0 and datediff(\"d\", tvStartT, #%s#)=0 order by tvStartT"
, nNum , pChan->m_nEpgNum, s1.LockBuffer(), s1.LockBuffer());
lRet = DealDbLocate(s);
COleDateTime oleTime;
if(lRet > 0)
m_pRecordset->MoveFirst();
for(int i= 0;i < lRet; i++)
{
DealDbGetCurEpgRecrod();
m_pRecordset->MoveNext();
}
nNum -= lRet;
if(0 < nNum)
{
CTimeSpan tt(1, 0,0,0);
t += tt;
s1 = t.Format("%m/%d/%Y");
s1 += " 0:0:0";
s.Format("select top %d * from epginf where tvnum =%d and datediff(\"n\", tvStartT, #%s#)<0 and datediff(\"d\", tvStartT, #%s#)=0 order by tvStartT"
, nNum , pChan->m_nEpgNum, s1.LockBuffer(), s1.LockBuffer());
lRet = DealDbLocate(s);
if(lRet > 0)
m_pRecordset->MoveFirst();
for(int i= 0;i < lRet; i++)
{
DealDbGetCurEpgRecrod();
m_pRecordset->MoveNext();
}
}
return TRUE;
}
//##ModelId=46676C980280
BOOL CEpgDeal::DealDbGetCurEpgRecrod()
{
VARIANT var;
COleDateTime oletime;
CString s, s1;
var = m_pRecordset->GetCollect("tvProgName");
s = var.bstrVal;
strcpy(m_listEpg[m_nEpg].szprogname, s.LockBuffer());
var = m_pRecordset->GetCollect("tvStartT");
oletime = var.date;
oletime.GetAsSystemTime(m_listEpg[m_nEpg].startTime);
m_nEpg ++;
s1 = oletime.Format("%Y-%m-%d %H:%M:%S");
s += s1;
TRACE("%s", s);
return TRUE;
}
//##ModelId=46676C9703C8
BOOL CEpgDeal::DealDbGetCurChanRecrod()
{
_variant_t var;
CString s, s1;
try
{
var = m_pRecordset->GetCollect("tvName");
if(var.vt != VT_NULL)
{
s = var.bstrVal;
if(!s.IsEmpty())
strcpy(m_listChan[m_nChan].szName, s.LockBuffer());
}
var = m_pRecordset->GetCollect("tvFName");
if(var.vt != VT_NULL)
{
s = var.bstrVal;
if(!s.IsEmpty())
strcpy(m_listChan[m_nChan].tvFName, s.LockBuffer());
}
var = m_pRecordset->GetCollect("tvFrq");
m_listChan[m_nChan].lfrequent = var.lVal;
var = m_pRecordset->GetCollect("tvNum");
m_listChan[m_nChan].m_nEpgNum = var.iVal;
var = m_pRecordset->GetCollect("nNum");
m_listChan[m_nChan].m_nNum = var.iVal;
var = m_pRecordset->GetCollect("RegCode");
m_listChan[m_nChan].RegCode = var.iVal;
var = m_pRecordset->GetCollect("tvSel");
m_listChan[m_nChan].tvSel = var.bVal;
var = m_pRecordset->GetCollect("tvFav");
m_listChan[m_nChan].tvFav = var.bVal;
}catch(_com_error e)
{
// AfxMessageBox(e.ErrorMessage());
return FALSE;
}
s1.Format(" %d", m_listChan[m_nChan].lfrequent);
s += s1;
m_nChan ++;
TRACE("%s", s);
return TRUE;
}
//##ModelId=46676C990399
BOOL CEpgDeal::CheckCurChan()
{
CString s,s1;
LONG lRet;
CTime t = CTime::GetCurrentTime();
s1 = t.Format("%d/%m/%Y");
s.Format("select * from tv where RegCode = %d ",
1);
lRet = DealDbLocate(s);
if(lRet > 0)
return FALSE;
DealCopyAsCur(1, 0);
return TRUE;
}
//##ModelId=46676C99033C
BOOL CEpgDeal::CheckDownLoad()
{
CString s,s1;
LONG lRet;
CTime t = CTime::GetCurrentTime();
s1 = t.Format("%m/%d/%Y");
s.Format("select * from epginf where datediff(\"d\", tvStartT, #%s#)<=0 ",
s1.LockBuffer());
lRet = DealDbLocate(s);
if(lRet > 10)
return FALSE;
DownLoadEpg();
return TRUE;
}
UINT DownloadThread(void *pArg)
{
CEpgDeal *pWnd = (CEpgDeal*)pArg;
CString strInfo;
TCHAR szDir[255];
int nLen;
nLen = GetModuleFileName(NULL, szDir, 255);
CString strFileName;
strFileName = pWnd->m_initParam.szZipPath;
if(!strFileName.IsEmpty())
{
strFileName += "epg.zip";
}
else
{
pWnd->bdownloading = FALSE;
return 0;
}
CHttpSocket HttpSocket;
CString strServer,strObject;
unsigned short nPort;
DWORD dwServiceType;
long nLength;
const char *pRequestHeader = NULL;
CString strRequest = pWnd->m_initParam.szDownPath;
if(strRequest.IsEmpty())
strRequest = _T("http://www.cctv.com/download/showtime.zip");
AfxParseURL(strRequest,dwServiceType,strServer,strObject,nPort);
pRequestHeader = HttpSocket.FormatRequestHeader((LPTSTR)(LPCTSTR)strServer,(LPTSTR)(LPCTSTR)strObject,nLength);
HttpSocket.Socket();
BOOL bRes = FALSE;
bRes = HttpSocket.Connect((LPTSTR)(LPCTSTR)strServer);
if(!bRes)
{
pWnd->bdownloading = FALSE;
pWnd->DealCallBackDownPercent(-1);
return 0;
}
HttpSocket.SendRequest();
HttpSocket.SetTimeout(20000,0);
char szValue[30];
HttpSocket.GetField("content-length",szValue,30);
int nSvrState = HttpSocket.GetServerState();
int nFileSize = atoi(szValue);
int nCompletedSize = 0;
CFile DownloadFile;
try{
if(!DownloadFile.Open(strFileName,CFile::modeCreate | CFile::modeWrite))
{
pWnd->bdownloading = FALSE;
pWnd->DealCallBackDownPercent(-1);
return 0;
}
char pData[1024];
int nReceSize = 0;
DWORD dwStartTime,dwEndTime;
while(nCompletedSize < nFileSize)
{
dwStartTime = GetTickCount();
nReceSize = HttpSocket.Receive(pData,1024);
if(nReceSize == 0)
{
break;
}
if(nReceSize == -1)
{
break;
}
dwEndTime = GetTickCount();
DownloadFile.Write(pData,nReceSize);
nCompletedSize += nReceSize;
if(nCompletedSize != nFileSize)
pWnd->DealCallBackDownPercent((100.0*nCompletedSize)/nFileSize);
}
DownloadFile.Close();
}
catch(CFileException e)
{
pWnd->bdownloading = FALSE;
pWnd->DealCallBackDownPercent(-1);
return 0;
}
CPackManage pack;
BOOL bRet;
if(nCompletedSize == nFileSize)
{
//删除原来的epg目录
if(pack.LoadResourcePack(strFileName))
bRet = pack.ExtractPack();
}
if(bRet)
pWnd->DealCallBackDownPercent(100);
else
pWnd->DealCallBackDownPercent(-1);
pWnd->bdownloading = FALSE;
return 0;
}
//##ModelId=46676C99036B
BOOL CEpgDeal::DownLoadEpg()
{
//删除掉原来的epg文件目录
bdownloading = TRUE;
AfxBeginThread(DownloadThread,(void *)this);
return TRUE;
}
//##ModelId=46676C9703A9
BOOL CEpgDeal::DealDbLocateAllChancel(int ncode)
{
CString s;
LONG lRet;
ReleaseListChan();
if(m_curChan.tvFav && ncode == 1)
{
CString ss;
ss = "FALSE";
s.Format("select * from tv where RegCode = %d and tvFav=true order by nNum"
, ncode);
}
else
s.Format("select * from tv where RegCode = %d order by nNum"
, ncode);
lRet = DealDbLocate(s);
if(lRet > 0)
m_pRecordset->MoveFirst();
else
return FALSE;
AllocListChan(lRet);
for(int i=0;i< lRet; i++)
{
DealDbGetCurChanRecrod();
m_pRecordset->MoveNext();
}
return TRUE;
}
//##ModelId=46676C980000
BOOL CEpgDeal::DealCopyAsCur(int nRegCode, int srcReg, bool bRevse)
{
CString s;
LONG lRet;
int i;
if(!bRevse)
{
s.Format("delete * from tv where RegCode =%d", nRegCode);
lRet = ExeSql(s);
}
s.Format("select * from tv where RegCode = %d order by nNum", srcReg);
lRet = DealDbLocate(s);
TRACE("epg:DiskCopyAs(dest%d, src%d, lret=%d, %s", nRegCode, srcReg, lRet, s.LockBuffer());
if(lRet > 0)
m_pRecordset->MoveFirst();
else
return FALSE;
ReleaseListChan();
AllocListChan(lRet);
for(i= 0;i < lRet ; i++)
{
DealDbGetCurChanRecrod();
m_listChan[i].RegCode = nRegCode;
m_pRecordset->MoveNext();
}
for(i= 0;i < lRet; i++)
{
if(!bRevse)
m_listChan[i].m_nNum = -1;
DealDbAddChancel(&m_listChan[i]);
}
return TRUE;
}
//##ModelId=46676C98029F
BOOL CEpgDeal::DealDbCheckHasEpg(LPChancel pChan)
{
CString s, s1;
LONG lRet;
BOOL bRet = TRUE;
//更新频道编号
m_curChan.tvFav = pChan->tvFav;
m_curChan.lfrequent = pChan->lfrequent;
#ifdef MYFORREPORT //
lstrcpy(m_curChan.szName, pChan->szName);
s.Format(_T("select * from tv where tvname = '%s'"), m_curChan.szName);
#else
if(DealDbChancelXX(&m_curChan)== false)
return false;
memcpy(pChan, &m_curChan,sizeof(Chancel));
//先简单判断有无内部编号
s.Format("select * from tv where RegCode = %d and nNum = %d",
m_curChan.RegCode,m_curChan.m_nNum);
#endif
lRet = DealDbLocate(s);
if(lRet == 1) //有内部编号
{
ReleaseListChan();
AllocListChan(1);
DealDbGetCurChanRecrod();
pChan->m_nEpgNum = m_listChan[0].m_nEpgNum;
strcpy(pChan->tvFName, m_listChan[0].tvFName);
strcpy(pChan->szName, m_listChan[0].szName);
pChan->lfrequent = m_listChan[0].lfrequent;
m_curChan.m_nEpgNum = m_listChan[0].m_nEpgNum;
strcpy(m_curChan.tvFName, m_listChan[0].tvFName);
strcpy(m_curChan.szName, m_listChan[0].szName);
m_curChan.lfrequent = m_listChan[0].lfrequent;
}
// else //查找库存中的与之
{
//先找到电台内部编号
s.Format("select * from tv where tvFName= \"%s\" and RegCode= 0", pChan->tvFName);
lRet = DealDbLocate(s);
if(lRet == 1)
{
ReleaseListChan();
AllocListChan(1);
DealDbGetCurChanRecrod();
pChan->m_nEpgNum = m_listChan[0].m_nEpgNum;
strcpy(pChan->tvFName, m_listChan[0].tvFName);
}
else
return FALSE;
}
//判断有无Epg信息
CTime t = CTime::GetCurrentTime();
s1 = t.Format("%m/%d/%Y");
s.Format("select * from epginf where tvNum =%d and datediff(\"d\", tvStartT, #%s#)=0 order by tvStartT"
, pChan->m_nEpgNum, s1.LockBuffer());
int ncnt =2;
again:
lRet = DealDbLocate(s);
#ifdef NODOWNLOADEPG
if(lRet == 0)
{
//无Epg信息,则查找文件,将Epg信息写入到数据库中
CString s1, s2;
VecEpgInfo vcepg;
GetChlEpgInfo(pChan->tvFName, &vcepg);
AllocListEpg(2);
lRet = vcepg.size();
if(lRet == 2)
{
// lstrcpy(m_listEpg[0].szprogname, vvepg[i].sz);
// lstrcpy(m_listEpg[1].szprogname, s2.LockBuffer());
memcpy(m_listEpg, &vcepg[1], sizeof(EpgInfo) );
memcpy(&m_listEpg[1], &vcepg[0], sizeof(EpgInfo));
m_nEpg = 2;
}
return false;
// bRet = DealBuildEpgFromFile(pChan->m_nEpgNum, pChan->tvFName);
// ncnt --;
// if(ncnt == 1)
// goto again;
}
#endif
return bRet;
}
//##ModelId=46676C9802BF
BOOL CEpgDeal::DealAddBak()
{
CString s;
LONG lRet;
BakTv bakls;
//取得最大编号,
s.Format("select * from Baktv order by nLNum");
lRet = DealDbLocate(s);
if(lRet > 0)
m_pRecordset->MoveLast();
else
{
bakls.nRegCode = 100;
goto con;
}
DealDbGetCurrentBak(&bakls);
if(bakls.nRegCode < 100)
bakls.nRegCode = 100;
else
bakls.nRegCode ++;
con:
//加入信息到tv表中
DealCopyAsCur(bakls.nRegCode, 1);
//加入信息到baktv表中。
COleDateTime oledt = COleDateTime::GetCurrentTime();
oledt.GetAsSystemTime(bakls.startTime);
if(DealDbOpenBakTv())
{
_variant_t vtdate;
vtdate.vt = VT_DATE;
vtdate.date = oledt;
m_pRecordset->AddNew();
m_pRecordset->PutCollect("nLNum", (long)bakls.nRegCode);
m_pRecordset->PutCollect("BakDate", vtdate);
m_pRecordset->Update();
}
else
{
s.Format("delete * from tv where RegCode = %d", bakls.nRegCode);
DealDbDelete(s);
}
return TRUE;
}
//##ModelId=46676C9802DE
BOOL CEpgDeal::DealDbGetCurrentBak(LPBakTv pbak)
{
VARIANT var;
COleDateTime oledt;
var = m_pRecordset->GetCollect("nLNum");
pbak->nRegCode = var.iVal;
var = m_pRecordset->GetCollect("BakDate");
oledt = var.date;
oledt.GetAsSystemTime(pbak->startTime);
return TRUE;
}
//##ModelId=46676C9802FD
BOOL CEpgDeal::DealDbGetAllBak(CStringList *slist)
{
CString s;
LONG lRet;
BakTv bktv;
s.Format("select * from Baktv order by BakDate");
lRet = DealDbLocate(s);
if(lRet<1)
return FALSE;
m_pRecordset->MoveFirst();
for(int i= 0;i < lRet ;i ++)
{
DealDbGetCurrentBak(&bktv);
CTime t(bktv.startTime);
s = t.Format("%Y-%m-%d %H:%M:%S");
slist->AddTail(s);
m_pRecordset->MoveNext();
}
return TRUE;
}
//##ModelId=46676C98031C
BOOL CEpgDeal::DealGetNumBak(int nNum, LPBakTv ptv)
{
CString s;
LONG lRet;
s.Format("select * from Baktv order by BakDate");
lRet = DealDbLocate(s);
if(lRet<1)
return FALSE;
if(nNum<0 || nNum >= lRet)
return FALSE;
m_pRecordset->Move(nNum);
DealDbGetCurrentBak(ptv);
return TRUE;
}
//##ModelId=46676C98035B
BOOL CEpgDeal::DealDelBakTv(int nRegcode)
{
BOOL bRet;
CString s;
s.Format("delete * from tv where RegCode = %d", nRegcode);
bRet = DealDbDelete(s);
if(bRet)
{
s.Format("delete * from baktv where nLNum = %d", nRegcode);
bRet = DealDbDelete(s);
}
return bRet;
}
//##ModelId=46676C9700CB
LRESULT CEpgDeal::DealCallBack(UINT nID, WPARAM wParam, LPARAM lParam)
{
if(m_pfn)
return m_pfn(WM_MSG_EPG, nID, wParam, lParam);
else
return -1l;
}
//##ModelId=46676C9800CC
BOOL CEpgDeal::DealSearchStart()
{
CString s;
s = "delete from tv where regcode = 4";
if(ExeSql(s) == -1)
return FALSE;
if(m_initParam.bSearchSave)
{
s = _T("update tv set regcode=4 where regcode=1");
if(ExeSql(s) == -1)
return FALSE;
}
else
{
s = _T("delete from tv where regcode=1");
if(ExeSql(s) == -1)
return FALSE;
}
DealCallBack(MAKELONG(WM_SEARCH_START, WM_EPG_DONE), 0, 0);
return TRUE;
}
//##ModelId=46676C9800DA
BOOL CEpgDeal::DealSearchCance()
{
CString s;
if(m_initParam.bSearchSave)
DealCopyAsCur(1, 4, true);
s = _T("delete from tv where regcode=4");
ExeSql(s);
DealCallBack(MAKELONG(WM_SEARCH_CANCEL, WM_EPG_DONE), 0, 0);
return TRUE;
}
//##ModelId=46676C9800EA
BOOL CEpgDeal::DealSearchEnd()
{
CString s;
if(m_initParam.bSearchSave)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -