⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 epgdeal.cpp

📁 得到本周内的电视节目预告! f
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			m_pRecordset->PutCollect("nNum", (long)pChan->m_nNum );
			m_pRecordset->PutCollect("tvSel", (long)pChan->tvSel);
			m_pRecordset->PutCollect("tvFav", (long)pChan->tvFav);
			m_pRecordset->Update();
			return TRUE;
		}catch(_com_error e)
		{
	//		AfxMessageBox(e.ErrorMessage());
		}
	}
	return FALSE;
}
//##ModelId=46676C97034B
BOOL CEpgDeal::DealDbDelChancel(LPChancel pChan)
{
	if(DealDbOpenChan())
	{
		try
		{
		LONG l;		// = m_pRecordset->GetRecordCount();
		if(pChan)
		{
			CString s;
			s.Format("select * from tv where RegCode=%d and nNum = %d",
				pChan->RegCode, pChan->m_nNum);
			l = DealDbLocate(s);
			if(l == 1)
			{
				m_pRecordset->MoveFirst();
				m_pRecordset->Delete(adAffectCurrent);
				//将后面的编号往前移
				s.Format("Select * from tv where RegCode=%d and nNum > %d",
					pChan->RegCode, pChan->m_nNum);
				if(DealDbLocate(s)>0)
				{	
					m_pRecordset->MoveFirst();
					l = pChan->m_nNum ;
					while(!m_pRecordset->adoEOF)
					{
						m_pRecordset->PutCollect("nNum", l++);
						m_pRecordset->Update();
						m_pRecordset->MoveNext();
					}		
				}
				return TRUE;

			}
			else
				return FALSE;
		}
		else
		{
			if(l>0)
			{
				if(!m_pRecordset->BOF)
					m_pRecordset->MoveFirst();
				while(!m_pRecordset->adoEOF)
				{
					m_pRecordset->Delete(adAffectCurrent);	
					m_pRecordset->MoveNext();
				}
				return TRUE;
			}
		}
		}catch(_com_error e)
		{
	//		AfxMessageBox(e.ErrorMessage());
		}
	}
	return FALSE;
}
//##ModelId=46676C98004E
BOOL CEpgDeal::DealDbChancelUpDown(int pos, LPChancel pChan)
{
	CString s;
	LONG lRet;

	s.Format("select * from tv where RegCode =%d order by nNum",
		pChan->RegCode);
	lRet = DealDbLocate(s);
	if(lRet > 0 && pChan->m_nNum>=0 && pChan->m_nNum < lRet)
	{
		pos += pChan->m_nNum;
		if(pos<0)
			pos += lRet;
		pos %= lRet;
		try{
		
			m_pRecordset->Move((long)pos);
			m_pRecordset->PutCollect("nNum", (long)pChan->m_nNum);
			m_pRecordset->Update();			
			m_pRecordset->Move((long)(pChan->m_nNum - pos));
			m_pRecordset->PutCollect("nNum", (long)pos);
			m_pRecordset->Update();	
			return TRUE;
		}catch(_com_error e)
		{	
		//	AfxMessageBox(e.ErrorMessage());
		}

	}
	return FALSE;
}
//##ModelId=46676C9702FD
BOOL CEpgDeal::DealDbEditChancel(LPChancel pChan)
{
	if(DealDbOpenChan())
	{
		//找到编号所在记录,然后,更新记录即可
		CString s;
		LONG lRet;
		BOOL bRept = TRUE;;
again:
		s.Format("select * from tv where RegCode= %d and nNum = %d", 
			pChan->RegCode, pChan->m_nNum);
		lRet = DealDbLocate(s);
		try
		{
		if(lRet == 1)
		{
			m_pRecordset->MoveFirst();
			m_pRecordset->PutCollect("tvName", _variant_t(pChan->szName));
			m_pRecordset->PutCollect("tvNum", (long)pChan->m_nEpgNum);
			m_pRecordset->PutCollect("tvFav", (long)pChan->tvFav);
			m_pRecordset->PutCollect("tvFrq", pChan->lfrequent);
			m_pRecordset->PutCollect("tvFName", _variant_t(pChan->tvFName));
			m_pRecordset->Update();
	
			if(bRept)
			{
				//如果文件名为空的话,就退出
				if(strlen(pChan->tvFName) == 0)
					return true;

				s.Format("select * from tv where RegCode = %d and tvFName = \"%s\"",
					0, pChan->tvFName);
				lRet = DealDbLocate(s);
				if(lRet == 0)	//没有找到,并文件加入到库存中
				{
					Chancel ch;
					memcpy(&ch, pChan, sizeof(Chancel));
					ch.RegCode = 0;
					ch.m_nNum = -1;
					if(!DealDbAddChancel(&ch))
					{
						return FALSE;
					}
					bRept = FALSE;
					goto again;
				}
				if(lRet ==1 )
				{
					VARIANT var;
					m_pRecordset->MoveFirst();
					var = m_pRecordset->GetCollect("tvNum");
					pChan->m_nEpgNum = var.iVal;
				}
				else
					pChan->m_nEpgNum = 0;
				bRept = FALSE;
				goto again;	
			}
			//搜索电台名称对应的库存的信息,要填上对应的名称或是对应内部的号
		}
		else
			return FALSE;
		}catch(_com_error e)
		{
		//	AfxMessageBox(e.ErrorMessage());
		}
	}
	return TRUE;	
}
//##ModelId=46676C99000F
BOOL CEpgDeal::DealDbLocateChancel(LPChancel pChan)
{
	if(bOpenRecord)
		m_pRecordset->Close();
	CString s;
	HRESULT hr;
	s.Format("SELECT * FROM tv where tvName = \"%s\"", pChan->szName);

	hr = m_pRecordset->Open(_variant_t(s.LockBuffer()),
		_variant_t((IDispatch*)m_pConnection,true),
		adOpenStatic,adLockOptimistic,adCmdText);


	if(FAILED(hr))
	{
		bOpenRecord = FALSE;
		return FALSE;
	}
	bOpenRecord = TRUE;
	return TRUE;
}
//##ModelId=46676C99006D
long CEpgDeal::DealDbLocate(CString s)
{
	long lret=0;
	try
	{
	if(bOpenRecord)
		m_pRecordset->Close();
	HRESULT hr;

	hr = m_pRecordset->Open(_variant_t(s.LockBuffer()),
		_variant_t((IDispatch*)m_pConnection,true),
		adOpenStatic,adLockOptimistic,adCmdText);
	
	
	if(FAILED(hr))
	{
		bOpenRecord = FALSE;
		return FALSE;
	}

	bOpenRecord = TRUE;
	lret = m_pRecordset->GetRecordCount();
	}catch(_com_error e)
	{	
	//	AfxMessageBox(e.ErrorMessage());
	}
	return lret;
}
//##ModelId=46676C990119
long CEpgDeal::ExeSql(CString s, _RecordsetPtr pRecrod)
{
	VARIANT vt;
	vt.vt = VT_I4;
	try
	{
		if(pRecrod != NULL)
			pRecrod = m_pConnection->Execute(s.AllocSysString(),&vt, adCmdText );
		else
			m_pConnection->Execute(s.AllocSysString(),&vt, adCmdText );
	}
	catch(_com_error e)
	{
	//	AfxMessageBox(e.ErrorMessage());
		return -1;
	}
	TRACE2("epg:Exesql(%s) lret = %ld", s.LockBuffer(), vt.lVal);
	return vt.lVal;
}
//##ModelId=46676C9900DA
BOOL CEpgDeal::DealDbDelete(CString s)
{
	try
	{
	if(bOpenRecord)
		m_pRecordset->Close();
	HRESULT hr;
	
	hr = m_pRecordset->Open(_variant_t(s.LockBuffer()),
		_variant_t((IDispatch*)m_pConnection,true),
		adOpenStatic,adLockOptimistic,adCmdText);
	
	bOpenRecord = FALSE;	
	if(FAILED(hr))
	{
		return FALSE;
	}
	}catch(_com_error e)
	{
	//	AfxMessageBox(e.ErrorMessage());
	}
	return TRUE;
}
//##ModelId=46676C980158
BOOL CEpgDeal::DealDbAddEpg(LPEpgInfo pEpg)
{
	if(DealDbOpenEpg())
	{
		try{
		//判断是否已经有数据了
		CString s, s1;
		COleDateTime oleDate(pEpg->startTime);
		_variant_t vtFld;
		vtFld.vt = VT_DATE;
		vtFld.date = oleDate;
		LONG lRet;

		s1 = oleDate.Format("%d/%m/%Y %H:%M:%S");
		s.Format("select * from epginf where tvnum =%d and datediff(\"n\", tvStartT, #%s#)=0 and datediff(\"h\", tvStartT, #%s#)=0 and datediff(\"d\", tvStartT, #%s#)=0 and datediff(\"m\", tvStartT, #%s#)=0 and datediff(\"y\", tvStartT, #%s#)=0", 
			pEpg->m_nNum, s1.LockBuffer(), s1.LockBuffer(), s1.LockBuffer(), s1.LockBuffer()
			,s1.LockBuffer());
		lRet = DealDbLocate(s);
		if(lRet > 0)
			return FALSE;

		m_pRecordset->AddNew();
		m_pRecordset->PutCollect("tvProgName", _variant_t(pEpg->szprogname));
		m_pRecordset->PutCollect("tvnum", (long)pEpg->m_nNum);
		m_pRecordset->PutCollect("tvStartT", vtFld);
		m_pRecordset->Update();
		}
		catch(_com_error e)
		{
		//	AfxMessageBox(e.ErrorMessage());
			return FALSE;
		}
	}	
	return TRUE;
}
//##ModelId=46676C9801B5
bool CEpgDeal::DealAddEpg(LPEpgInfo pEng)
{
		CString s, s1;
		COleDateTime oleDate(pEng->startTime);
		_variant_t vtFld;
		vtFld.vt = VT_DATE;
		vtFld.date = oleDate;
		s1 = oleDate.Format("%Y/%m/%d %H:%M:%S");

	s.Format(_T("insert into epginf(tvNum, tvStartT, tvProgName) values(%d, #%s#, \"%s\")"),
		pEng->m_nNum,s1.LockBuffer() , pEng->szprogname);
	if(ExeSql(s) == 1)
		return true;
	return false;
}
//##ModelId=46676C980242
BOOL CEpgDeal::DealDbDelEpg(LPEpgInfo pEpg)
{
	if(DealDbOpenEpg())
	{
		try{
		LONG l = m_pRecordset->GetRecordCount();
		if(!pEpg)
		{
			return FALSE;
		}
		else
		{
			if(l>0)
			{
				if(!m_pRecordset->BOF)
					m_pRecordset->MoveFirst();
				while(!m_pRecordset->adoEOF)
				{
					m_pRecordset->Delete(adAffectCurrent);	
					m_pRecordset->MoveNext();
				}
				
				l = m_pRecordset->GetRecordCount();
			}
		}
		}catch(_com_error e)
		{
		//	AfxMessageBox(e.ErrorMessage());
			return FALSE;
		}
	}
	return TRUE;
}
//##ModelId=46676C980203
BOOL CEpgDeal::DealDbEditEpg(LPEpgInfo pEpg)
{
	if(DealDbOpenEpg())
	{
		//查找到Epg信息
	}
	return FALSE;	
}
//##ModelId=46676C990290
BOOL CEpgDeal::DealBuildEpgFromFile(int num, CString strFile)
{
	DWORD dwRet = 0;

	if(bdownloading)
		return FALSE;
	
	CString s;

	CString strPrev, strNext, strCur;

	EpgInfo m_epg;

	if(!strFile.IsEmpty())
	{
		strFile = "\\节目单\\"+strFile;
		strFile = m_initParam.szZipPath + strFile;
		CStdioFile file;
		if(!file.Open(strFile, CFile::modeRead))
		{
			return TRUE;
		}
		
		CTime tm = CTime::GetCurrentTime();
		CString strWeek, strDate, strStartTime, strProgram;
		CString strLine, strTemp;
		CStringArray arrProgram;
		BOOL bNextDay = FALSE;
		int nYear = 0, nMon = 0, nDay = 0;
		int nHour = 0, nMin = 0, nSec = 0;
		int nPreHour = 0;
		int nPos = 0;

		CString strW = "星期";

		while(file.ReadString(strLine))
		{
			TCHAR ch = 0x09;	//tab
			
			while(strLine.Left(1) == _T(" ") || 
				strLine.Left(1) == ch)
				strLine = strLine.Mid(1);
			
			if(strLine.IsEmpty())
				continue;

			if(!strW.IsEmpty())
			{
				if(strLine.Find(strW) != -1)
				{
 					nYear = tm.GetYear();
					nMon  = atoi(strLine.Mid(3, 2));
					nDay  = atoi(strLine.Mid(6, 2));
					strDate.Format(_T("%04d-%02d-%02d"), nYear, nMon, nDay);
				}
				else
				{
					nPos = strLine.Find(ch);
					if(nPos == -1)
					{
						ch = ' ';	//空格
						nPos = strLine.Find(ch);
						if(nPos == -1)
							return FALSE;
					}

					strProgram = strLine.Mid(nPos);
					
					strTemp = strLine.Left(nPos);
					nPos = strTemp.Find(_T(":"));
					if(nPos != -1)
					{
						nHour = atoi(strTemp.Mid(0, 2));

						nHour = nHour % 24;					//有的文件竟然有27:30:00 这种格式
						nPreHour = nHour;
						nMin  = atoi(strTemp.Mid(3, 2));
						nSec  = 0;//atoi(strTemp.Mid(6, 2));//有的文件没有秒数的。
					}
					strStartTime.Format("%02d:%02d", nHour, nMin);
					while(strProgram.Left(1) == _T(" ") || strProgram.Left(1) == ch)
						strProgram = strProgram.Mid(1);
					TRACE("%s %s, %s", strDate, strStartTime, strProgram);
					COleDateTime time1(nYear,nMon,nDay, nHour,nMin,0); 
					ZeroMemory(&m_epg, sizeof(EpgInfo));
					time1.GetAsSystemTime(m_epg.startTime);
					strcpy(m_epg.szprogname, strProgram);
					m_epg.m_nNum = num;
					if(DealAddEpg(&m_epg)== FALSE);
				}
			}
		}
	}
	else	//找不到对应的文件
	{

	}
	return TRUE;
}
//##ModelId=46676C9902EE
BOOL CEpgDeal::DealBuildEpg()
{
	CString s;
	int num;
	CUIntArray arNum;
	CStringArray arFname;
	LONG lRet;
	
	s.Format("select * from tv where tvSel = TRUE");

	lRet = DealDbLocate(s);
	VARIANT var;
	int i;

	try
	{
	if(lRet>0)
		m_pRecordset->MoveFirst();
	for(i= 0; i< lRet; i++)
	{
		var = m_pRecordset->GetCollect("tvNum");
		arNum.Add(var.intVal);
		var = m_pRecordset->GetCollect("tvFName");
		arFname.Add(var.bstrVal);
		m_pRecordset->MoveNext();
	}
	}
	catch(_com_error e)
	{
	//	AfxMessageBox(e.ErrorMessage());
		return FALSE;
	}
	for(i = 0;i< lRet; i++)
	{
		num = arNum[i];
		s = arFname[i];
		DealBuildEpgFromFile(num, s);
	}
	return TRUE;
}
//##ModelId=46676C98037A
BOOL CEpgDeal::DealLocateTodayEpg(LPChancel pChan)
{
	CString s, s1;
	LONG lRet;

	ReleaseListEpg();

	if(!DealDbCheckHasEpg(pChan))
		return FALSE;

	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;

	lRet = DealDbLocate(s);
	try{
	if(lRet > 0)
		m_pRecordset->MoveFirst();
	else
		return FALSE;

	AllocListEpg(lRet);
	for(int i= 0;i < lRet; i++)
	{
		DealDbGetCurEpgRecrod();
		m_pRecordset->MoveNext();
	}
	}catch(_com_error e)
	{
	//	AfxMessageBox(e.ErrorMessage());
		return FALSE;
	}

	return TRUE;
}
bool CEpgDeal::DealLocateXXXEpg(LPVOID pVoid, LPChancel pchan)
{
	CString s, s1, s2;
	LONG lRet;
	LPEpgDay pday = (LPEpgDay)pVoid;
	ReleaseListEpg();

	if(!DealDbCheckHasEpg(pchan))
		return false;

	s1.Format(_T("%d/%d/%d"), pday->m_startday.wYear, pday->m_startday.wMonth, 
			pday->m_startday.wDay);

	if(pday->m_brange == 1)
	{
		s2.Format(_T("%d/%d/%d"), pday->m_endday.wYear, pday->m_endday.wMonth, 
			pday->m_endday.wDay);
		s.Format("select * from epginf where tvstartt between #%s# and #%s#  and tvNum =%d order by tvStartT"
		,  s1.LockBuffer(), s2.LockBuffer()	, pchan->m_nEpgNum);
	}
	else
		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;

	lRet = DealDbLocate(s);
	try{
	if(lRet > 0)
		m_pRecordset->MoveFirst();
	else
		return FALSE;

	AllocListEpg(lRet);
	for(int i= 0;i < lRet; i++)
	{
		DealDbGetCurEpgRecrod();
		m_pRecordset->MoveNext();
	}
	}catch(_com_error e)
	{
	//	AfxMessageBox(e.ErrorMessage());
		return FALSE;
	}

	return TRUE;
}
//##ModelId=46676C9803B9
BOOL CEpgDeal::DealLocateCur5Epg(LPChancel pChan)
{
	CString s, s1;
	LONG lRet;
	int nNum = 3;

	ReleaseListEpg();
	AllocListEpg(nNum);

	CTime t = CTime::GetCurrentTime();
	s1 = t.Format("%m/%d/%Y %H:%M:%S");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -