Example #1
0
int CProxy::SubstituteTags(CString *buf, int skAccept, int searchflag, char *searchstring, int startswithflag, char *startswithstring, char *errorcode, int adminFlag)
{
	int ret = 0;
	int	iError = 0;
	char	*pszSongTitle = (char *)1;
	char	szArtist[255] = "";
	int		playlistpos = 0;
	CString	substituted;
	char	tmpbuf[1024] = "";
	int		replaceflag = 0;
	CString tempArtist;
	int		foundit = 0;
	int		loop = 1;
	int		errorCode = 0;

	errorCode = atoi(errorcode);

	ret = buf->Find("%%ARTISTSELECT%%");

	if (ret != -1) {
		while(loop) {
			memset(szArtist, '\000', sizeof(szArtist));
			loop = getArtist(playlistpos, szArtist);
			if(loop) {
				tempArtist = szArtist;
				foundit = 0;
				for(int i=0;i <= ArtistList.GetUpperBound();i++) {
					if (ArtistList.GetAt(i) == tempArtist) {
						foundit = 1;
					}
				}
				if (!foundit) {
					if (strlen(tempArtist) > 0) {	
						ArtistList.Add(tempArtist);
					}
				}
			}
			playlistpos++;
		}

		CArray<CString, CString &> ArtistListSorted;

		for(int j=0;j <= ArtistList.GetUpperBound();j++) {
			int added = 0;
			for (int k=0;k <= ArtistListSorted.GetUpperBound();k++) {
				if (ArtistList.GetAt(j) < ArtistListSorted.GetAt(k)) {
					ArtistListSorted.InsertAt(k, ArtistList.GetAt(j));
					added = 1;
					break;
				}
			}
			if (!added) {
				ArtistListSorted.Add(ArtistList.GetAt(j));
			}
		}

		for(int i=0;i <= ArtistListSorted.GetUpperBound();i++) {
			substituted = *buf;
			substituted.Replace("%%ARTISTSELECT%%", ArtistListSorted.GetAt(i));
			iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
			iError = send(skAccept, "\r\n", strlen("\r\n"), 0);

		}
		return 1;
	}

	ret = buf->Find("%%ADMINWINAMPCONTROL%%");

	if (ret != -1) {
		substituted = *buf;
		if (adminFlag) {
			char	hiddenfield[1024] = "";
			sprintf(hiddenfield, "<table bordercolor=white border=1><tr><td colspan=5>Winamp Admin Control</td></tr><tr><td><a href=\"admin.cgi?pass=%s&action=prev\">Prev</td><td><a href=\"admin.cgi?pass=%s&action=play\">Play</td><td><a href=\"admin.cgi?pass=%s&action=pause\">Pause</td><td><a href=\"admin.cgi?pass=%s&action=stop\">Stop</td><td><a href=\"admin.cgi?pass=%s&action=next\">Next</td><tr><td colspan=5><a href=\"admin.cgi?pass=%s&action=refreshcache\">Refresh Playlist Cache</td></tr></table>", g_AdminPassword, g_AdminPassword, g_AdminPassword, g_AdminPassword, g_AdminPassword, g_AdminPassword);
			substituted.Replace("%%ADMINWINAMPCONTROL%%", hiddenfield);
		}
		else {
			substituted.Replace("%%ADMINWINAMPCONTROL%%", "");
		}
		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
		return 1;
	}

	ret = buf->Find("%%ADMINHIDDENFIELD%%");

	if (ret != -1) {
		substituted = *buf;
		if (adminFlag) {
			char	hiddenfield[1024] = "";
			sprintf(hiddenfield, "<input type=hidden name=pass value=\"%s\">", g_AdminPassword);
			substituted.Replace("%%ADMINHIDDENFIELD%%", hiddenfield);
		}
		else {
			substituted.Replace("%%ADMINHIDDENFIELD%%", "");
		}
		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
		return 1;
	}
	ret = buf->Find("%%ADMINPASSWORD%%");

	if (ret != -1) {
		substituted = *buf;
		if (adminFlag) {
			char	hiddenfield[1024] = "";
			sprintf(hiddenfield, "&pass=%s", g_AdminPassword);
			substituted.Replace("%%ADMINPASSWORD%%", hiddenfield);
		}
		else {
			substituted.Replace("%%ADMINPASSWORD%%", "");
		}
		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
		return 1;
	}

	ret = buf->Find("%%ERROR%%");

	if (ret != -1) {
		substituted = *buf;
		if (errorCode != 0) {
			substituted.Replace("%%ERROR%%", errorTable[errorCode]);
		}
		else {
			substituted.Replace("%%ERROR%%", "");
		}
		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
		return 1;
	}

	ret = buf->Find("%%HTTP_REFERRER%%");

	if (ret != -1) {
		substituted = *buf;
		if (errorCode != 0) {
			substituted.Replace("%%HTTP_REFERRER%%", m_Referrer);
		}
		else {
			substituted.Replace("URL=%%HTTP_REFERRER%%", "");
			substituted.Replace("%%HTTP_REFERRER%%", "");
		}
		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);

		return 1;
	}


	playlistpos = 0;
	ret = buf->Find("%%PLAYLISTENTRY%%");

	if (ret != -1) {
		int startingPos = 0;
		if (strlen(m_Current) > 0) {
			startingPos = atoi(m_Current);
		}

		int currentPos = 0;
		numDisplayed = 0;
		maxEntries = atoi(g_MaxEntries);
		while(pszSongTitle) {
			pszSongTitle = getSongTitle(playlistpos);
			if(pszSongTitle) {
				replaceflag = 1;
				if (searchflag) {
					if (CompareNonCase(pszSongTitle, searchstring, strlen(searchstring))) {
						replaceflag = 1;
					}
					else {
						replaceflag = 0;
					}
				}
				if (startswithflag) {
					if (CompareNonCaseBeginning(pszSongTitle, startswithstring, strlen(startswithstring))) {
						replaceflag = 1;
					}
					else {
						replaceflag = 0;
					}
				}

				if (replaceflag) {
					if ((currentPos >= startingPos) && (numDisplayed < maxEntries)) {
						substituted = *buf;
						substituted.Replace("%%PLAYLISTENTRY%%", pszSongTitle);
						memset(tmpbuf, '\000', sizeof(tmpbuf));
						if (adminFlag) {
							sprintf(tmpbuf, "%d&pass=%s", playlistpos, g_AdminPassword);
						}
						else {
							sprintf(tmpbuf, "%d", playlistpos);
						}

						substituted.Replace("%%PLAYLISTPOS%%", tmpbuf);
						iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
						iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
						numDisplayed++;
					}
					currentPos++;
				}
			}
			playlistpos++;
		}
		return 1;
	}
	ret = buf->Find("%%QUEUELISTENTRY%%");

	pszSongTitle = (char *)1;
	
	playlistpos = RequestQueue.GetUpperBound();

	int	queuepos = 1;
	if (ret != -1) {
		while(pszSongTitle) {
			pszSongTitle = GetQueueTitle(playlistpos);
			if(pszSongTitle) {
				substituted = *buf;
				substituted.Replace("%%QUEUELISTENTRY%%", pszSongTitle);
				memset(tmpbuf, '\000', sizeof(tmpbuf));
				if (adminFlag) {
					sprintf(tmpbuf, "<a href=\"admin.cgi?pass=%s&action=delete&listpos=%d\">Delete</a>&nbsp;%d", g_AdminPassword, queuepos, queuepos);
				}
				else {
					sprintf(tmpbuf, "%d", queuepos);
				}
				substituted.Replace("%%QUEUELISTPOS%%", tmpbuf);
				iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
				iError = send(skAccept, "\r\n", strlen("\r\n"), 0);

			}
			playlistpos--;
			queuepos++;
		}
		return 1;
	}

	ret = buf->Find("%%NAV_NEXT%%");

	if (ret != -1) {
		substituted = *buf;
		char	buff[255] = "";
		if (strchr(g_choppedrequest, '?')) {
			sprintf(buff, "<a href=\"%s&current=%d\">Next..></a>", g_choppedrequest, atoi(m_Current) + atoi(g_MaxEntries));
		}
		else {
			char	params[255] = "";

			if (startswithflag) {
				sprintf(params, "startswith=%s&current=%d", startswithstring, atoi(m_Current) + atoi(g_MaxEntries));
			}
			if (searchflag) {
				sprintf(params, "psearch=%s&current=%d", searchstring, atoi(m_Current) + atoi(g_MaxEntries));
			}
			if (strlen(params) == 0) {
				sprintf(params, "current=%d", atoi(m_Current) + atoi(g_MaxEntries));
			}
			if (adminFlag) {
				sprintf(buff, "<a href=\"admin.cgi?pass=%s&%s\">Next..></a>", g_AdminPassword, params);
			}
			else {
				sprintf(buff, "<a href=\"playlist.cgi?%s\">Next..></a>", params);
			}
		}
		if (numDisplayed < maxEntries) {
			substituted.Replace("%%NAV_NEXT%%", "");
		}
		else {
			substituted.Replace("%%NAV_NEXT%%", buff);
		}
		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);

		return 1;
	}
	ret = buf->Find("%%NAV_PREV%%");

	if (ret != -1) {
		substituted = *buf;
		char	buff[255] = "";
		if (strchr(g_choppedrequest, '?')) {
			sprintf(buff, "<a href=\"%s&current=%d\"><..Prev</a>", g_choppedrequest, atoi(m_Current) - atoi(g_MaxEntries));
		}
		else {
			char	params[255] = "";

			if (startswithflag) {
				sprintf(params, "startswith=%s&current=%d", startswithstring, atoi(m_Current) - atoi(g_MaxEntries));
			}
			if (searchflag) {
				sprintf(params, "psearch=%s&current=%d", searchstring, atoi(m_Current) - atoi(g_MaxEntries));
			}
			if (strlen(params) == 0) {
				sprintf(params, "current=%d",  atoi(m_Current) - atoi(g_MaxEntries));
			}
			if (adminFlag) {
				sprintf(buff, "<a href=\"admin.cgi?pass=%s&%s\"><...Prev</a>", g_AdminPassword, params);
			}
			else {
				sprintf(buff, "<a href=\"playlist.cgi?%s\"><...Prev</a>", params);
			}
		}
		if ((atoi(m_Current) - atoi(g_MaxEntries)) < 0) {
			substituted.Replace("%%NAV_PREV%%", "");
		}
		else {
			substituted.Replace("%%NAV_PREV%%", buff);
		}
		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);

		return 1;
	}

	ret = buf->Find("%%CURRENTSONG%%");

	if (ret != -1) {
		pszSongTitle = getCurrentSong();
		if(pszSongTitle) {
			substituted = *buf;
			substituted.Replace("%%CURRENTSONG%%", pszSongTitle);
			iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
			iError = send(skAccept, "\r\n", strlen("\r\n"), 0);

		}
		return 1;
	}

	ret = buf->Find("%%CONTENT_REFRESH%%");
	if (ret != -1) {
		substituted = *buf;
		GetSecondsLeft();
		char tmp[25] = "";
		sprintf(tmp, "%d", g_CurrentSongLeft + 5);
		
		substituted.Replace("%%CONTENT_REFRESH%%", tmp);

		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
		return 1;
	}
	ret = buf->Find("%%PCT_LEFT%%");
	if (ret != -1) {
		substituted = *buf;
		GetSecondsLeft();
		char tmp[25] = "";
		sprintf(tmp, "%d", g_CurrentPctLeft);
		
		substituted.Replace("%%PCT_LEFT%%", tmp);

		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
		return 1;
	}

	ret = buf->Find("%%SONG_LENGTH%%");
	if (ret != -1) {
		substituted = *buf;
		GetSecondsLeft();
		char tmp[25] = "";
		sprintf(tmp, "%d", g_CurrentSongLength);
		
		substituted.Replace("%%SONG_LENGTH%%", tmp);

		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
		return 1;
	}

	return 0;		
}
void CBase_SampleChart::OnExportData()
{
	CString file = _T("C:/Points.csv");

	CFileDialog mFileDlg(FALSE,_T("csv"),_T("Points"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("csv文件|*.csv||"),this);
	DWORD dwVersion = GetVersion();
	DWORD dwWindowsMajorVersion =  (DWORD)(LOBYTE(LOWORD(dwVersion)));
	DWORD dwWindowsMinorVersion =  (DWORD)(HIBYTE(LOWORD(dwVersion)));
	if (dwVersion < 0x80000000) mFileDlg.m_ofn.lStructSize=88;//显示新的文件对话框
	else mFileDlg.m_ofn.lStructSize=76;//显示老的文件对话框
	mFileDlg.m_ofn.lpstrTitle= _T("保存到文件");
	if(mFileDlg.DoModal() !=IDOK ) return;
	file = mFileDlg.GetPathName();

	CString strSep = _T(",");
	CFile f;
	BOOL ret = f.Open(file,CFile::modeCreate | CFile::modeReadWrite);
	if(!ret)
	{
		MessageBox(_T("打开文件失败,可能是文件为只读属性或被占用"));
		return;
	}
	CString line(_T("时间"));
	//
	CArray<CChartSerie*, CChartSerie*> series;
	series.Add(m_pcCurveMain);
	unsigned maxCount = 0;
	CChartSerie* pSerieOfMaxCount = NULL;
	for(int i=0; i<=series.GetUpperBound(); ++i)
	{
		CChartSerie* pS = series.GetAt(i);
		unsigned c = pS->GetPointsCount();
		if(c > maxCount)
		{
			maxCount = c;
			pSerieOfMaxCount = pS;
		}
		line = line + strSep + pS->GetName().c_str();
	}
	//标题列
	{
		TWen_USES_CONVERSION;
		LPCSTR s=TWen_CT2A(line + _T("\r\n"));
		f.Write(s,strlen(s));
	}
	for(size_t i=0; i<maxCount; i++)
	{
		line.Format(_T("%.15f"), pSerieOfMaxCount->m_vPoints.m_pPoints[i].x);
		for(int j=0; j<=series.GetUpperBound(); ++j)
		{
			CChartSerie* pS = GetSerieByIndex(j);
			unsigned c = pS->GetPointsCount();
			CString v;
			if(c > i) v.Format(_T("%.15f"), pS->m_vPoints.m_pPoints[i].y);
			line = line + strSep + v;
		}
		{
			TWen_USES_CONVERSION;
			LPCSTR s=TWen_CT2A(line + _T("\r\n"));
			f.Write(s,strlen(s));
		}
	}
	f.Close();
	MessageBox(_T("数据已保存到文件[")+file+_T("]"));
}
Example #3
0
void CProxy::AdminHandler(char *request, int *adminFlag)
{
	int	playlistpos = 0;
	char	suppliedPass[255] = "";

	char	msg[255] = "";
	int		valid = 0;
	int		errorCode = 0;
	char	variable[255] = "";
	char	value[255] = "";
	int		action = 0;
	char	tempRequest[1024] = "";

	strcpy(tempRequest, request);


//	if (!strncmp(tempRequest, "/admin.cgi", strlen("/admin.cgi"))) {
		char	*p1;
		p1 = strchr(tempRequest, '?');
		if (p1) {
			p1++;
			char	*token;
			token = strtok(p1, "&");
			while (token != NULL) {
				char	*p2;
				p2 = strchr(token, '=');
				if (p2) {
					memset(variable, '\000', sizeof(variable));
					memset(value, '\000', sizeof(value));

					int lengthtocopy = 0;
					if ((p2-token) > (sizeof(variable)-1)) {
						lengthtocopy = sizeof(variable)-1;
					}
					else {
						lengthtocopy = p2-token;
					}
					strncpy(variable, token, lengthtocopy);
					p2++;
					strncpy(value, p2, sizeof(value)-1);
					if (!strcmp(variable, "pass")) {
						strncpy(suppliedPass, value, sizeof(suppliedPass)-1);
					}
					if (!strcmp(variable, "action")) {
						if (!strcmp(value, "delete")) {
							action = 1;
						}
						if (!strcmp(value, "play")) {
							action = 2;
						}
						if (!strcmp(value, "prev")) {
							action = 3;
						}
						if (!strcmp(value, "pause")) {
							action = 4;
						}
						if (!strcmp(value, "stop")) {
							action = 5;
						}
						if (!strcmp(value, "next")) {
							action = 6;
						}
						if (!strcmp(value, "refreshcache")) {
							action = 7;
						}
					}
					if (!strcmp(variable, "listpos")) {
						playlistpos = atoi(value);
					}
				}
				token = strtok(NULL, "&");
			}
		}
		int passok = 0;

		if (strlen(g_AdminPassword) > 0) {
			if (!strcmp(suppliedPass, g_AdminPassword)) {
				*adminFlag = 1;
				passok = 1;
			}
			else {
				*adminFlag = 0;
				passok = 0;
			}
		}

		if (passok) {
			int winampCommand = 0;
			switch (action) {
			case 2:	PlayWinamp();
					winampCommand = 1;
					break;
			case 3:	PrevWinamp();
					winampCommand = 1;
					break;
			case 4:	PauseWinamp();
					winampCommand = 1;
					break;
			case 5:	StopWinamp();
					winampCommand = 1;
					break;
			case 6:	NextWinamp();
					winampCommand = 1;
					break;
			case 7:	repopulatePlaylistCache();
					winampCommand = 1;
					break;
			}
			if (winampCommand) {
				char buf[255] = "";
				_snprintf(buf, sizeof(buf)-1, "Location: /admin.cgi?pass=%s", g_AdminPassword);
				send_headers(302, "Moved Temporarily", (char*) buf, 0, -1, -1 );
			}
		}

//	}
//    if (sscanf(request, "/admin.cgi?pass=%s&action=delete&listpos=%d", suppliedPass, &playlistpos) == 2) {
	if (action == 1) {
		if (strlen(g_AdminPassword) > 0) {

			if (!strcmp(suppliedPass, g_AdminPassword)) {
				*adminFlag = 1;
				if (playlistpos-1 <= RequestQueue.GetUpperBound()) {
					RequestQueue.RemoveAt(RequestQueue.GetUpperBound() - playlistpos + 1);
					errorCode = DELETE_ACCEPTED;
				}
				else {
					errorCode = ERR_POSITION_OUT_OF_RANGE;
				}
			}
			else {
				*adminFlag = 0;
				errorCode = ERR_BAD_PASSWORD;
			}
		}

		char	location[1024] = "";
		if (strlen(m_Referrer) > 0) {
			if (errorCode == 0) {
				_snprintf(location, sizeof(location)-1, "Location: %s", m_Referrer);
			}
			else {
				_snprintf(location, sizeof(location)-1, "Location: %s&errorCode=%d", m_Referrer, errorCode);
			}
		}
		else {
			if (errorCode == 0) {
				_snprintf(location, sizeof(location)-1, "Location: /playlist.cgi");
			}
			else {
				_snprintf(location, sizeof(location)-1, "Location: /playlist.cgi?errorCode=%d", errorCode);
			}
		}
		send_headers(302, "Moved Temporarily", (char*) location, 0, -1, -1 );
	} 
	if (strlen(g_AdminPassword) > 0) {
		if (!strcmp(suppliedPass, g_AdminPassword)) {
				*adminFlag = 1;
		}
		else {
			*adminFlag = 0;
		}
	}
	return;
//    if (sscanf(request, "/admin.cgi?pass=%s&errorCode=%d", suppliedPass, &errorCode) == 2) {
}
Example #4
0
char* CHSDownloadData::MakeReqPacket( CodeInfo* pCode, short nPeriod , long &lReqLen)
{
	if ( pCode == NULL || IsBadReadPtr(pCode,1))
		return NULL;
	BOOL bChangeRange = FALSE;
	BOOL bDownLoaded = FALSE;
	CString str;
	str.Format("%d-%s",pCode->m_cCodeType,pCode->GetCode());
/*	TaskItem* m_pTaskItem = NULL;*/
	if( m_pTaskItem && !IsBadReadPtr(m_pTaskItem,1) && m_pTaskItem->m_TaskName.Compare(str) )
	{
		m_pTaskItem->SetDayTaskFinished();
		m_pTaskItem->SetMinute1TaskFinished();
		m_pTaskItem->SetMinute5TaskFinished();
		return NULL;
	}

	m_DownLoadCount = 0;
	int nAfterBegin = 1300,nAfterEnd = 1500;
	short nGZIndex = MakeGZIndex(pCode->m_cCodeType);
	short nQihuo = MakeMarket(pCode->m_cCodeType);
	if (nQihuo == FUTURES_MARKET)
	{
		if (nGZIndex)
		{
			nAfterEnd = 1515;
		}
		else
		{
			nAfterBegin = 1330;
		}
	}
	//取本地缓存中已有的数据
	GetLocalData(pCode,nPeriod,m_pTaskItem);

	CArray<DateRange,DateRange> ayDate;
	CTime t1 = GetNowTime(nPeriod);
	CTimeSpan tSpan = GetTimeStep(nPeriod);
	unsigned long nLimitTime = GetLimitDate(pCode,nPeriod,m_nLimitedDay);//修正2012时间问题
	unsigned long nEarliestTime = GetIntTimeFromTime(t1,nPeriod);//修正2012时间问题
	unsigned long nTodayTime = nEarliestTime;//修正2012时间问题

	long lCurDate = 10;	
	
	CTime tmNow = CTime::GetCurrentTime();
	lCurDate = tmNow.GetYear() * 10000 + tmNow.GetMonth() * 100 + tmNow.GetDay();
	
	bDownLoaded = IsDownLoaded(lCurDate,pCode,nPeriod);

	try
	{

		BOOL bExistLastData = FALSE;
		BOOL bFirstDayRange = TRUE;
		CString strCode = pCode->GetCode();
		StockDay* pStockDay = (StockDay*)m_pTaskItem->m_localData;
		for(int i =  m_pTaskItem->m_localDataCount - 1; i >= 0; i--)
		{
			if (bDownLoaded)
			{
				break;
			}

			if(pStockDay[i].m_lDate <= 0)
				continue;

			if(pStockDay[i].m_lDate < nEarliestTime)
				nEarliestTime = pStockDay[i].m_lDate;

			if (pStockDay[i].m_lDate == 20000000) //修正错误的日期时间
			{
				pStockDay[i].m_lDate = 19991231;
			}

			///////////////若本地一存在的数据日期在限制时间内 则挑过数据的缺失检查/////////////////////////////
			if (i == m_pTaskItem->m_localDataCount - 1)
			{
				CTime tmNow = t1;
				CTime tmLastData = GetTimeFromIntTime(pStockDay[i].m_lDate,nPeriod);
				int nNowYear = tmNow.GetYear();
				int nNowMonth = tmNow.GetMonth();
				int nNowDay = tmNow.GetDay();
				if ( nNowYear == tmLastData.GetYear() && nNowMonth == tmLastData.GetMonth() && tmLastData.GetDay() == nNowDay)
				{
					CTime tmlimit = GetTimeFromIntTime(nLimitTime,nPeriod);
					CTime tmFirstDate = GetTimeFromIntTime(pStockDay[0].m_lDate,nPeriod);
					if (m_nLimitedDay == 0)
					{
						if ( PERIOD_TYPE_DAY != nPeriod)
						{
							int nMaxDays = 0;
							if (nGZIndex)
								nMaxDays = 36 - 1;  //36 = (10000/240 * 240)/270
							else
								nMaxDays = 41 - 1; //41= 10000/240

							long lLastDate = tmLastData.GetYear() * 10000 + tmLastData.GetMonth() * 100 + tmLastData.GetDay();
						
							if (lLastDate != lCurDate)
							{
								nMaxDays --;
							}

							CTimeSpan tmSpan(1,0,0,0);
							int nCount = 0;
							while(nCount < nMaxDays)
							{
								tmLastData -= tmSpan;
								if (tmLastData.GetDayOfWeek() != 1&& tmLastData.GetDayOfWeek() != 7)
								{
									nCount ++;
								}
							}				
						}
						if (PERIOD_TYPE_DAY == nPeriod)
						{
							if (tmFirstDate.GetYear() <= tmlimit.GetYear() && tmFirstDate.GetMonth() <= tmlimit.GetMonth() 
								&& tmFirstDate.GetDay() <= tmlimit.GetDay())
							{
								bExistLastData = TRUE;
							}
						}
						else if (tmFirstDate.GetYear() <= tmLastData.GetYear() && tmFirstDate.GetMonth() <= tmLastData.GetMonth() 
							&& tmFirstDate.GetDay() <= tmLastData.GetDay())
						{
							bExistLastData = TRUE;
						}
					}
					else
					{
						if (tmFirstDate.GetYear() <= tmlimit.GetYear() && tmFirstDate.GetMonth() <= tmlimit.GetMonth() 
							&& tmFirstDate.GetDay() <= tmlimit.GetDay())
						{
							bExistLastData = TRUE;
						}
					}
					if (bExistLastData)
					{
						break;
					}
				}
			}
			//////////////////////////////////////////////////////////////////////////

			int nCount = 0;	
			long lEndDate = 0;
			long lBeginDate = 0;

			CTime t2 = GetTimeFromIntTime(pStockDay[i].m_lDate,nPeriod);
			CTime t = t2;
			if (i != m_pTaskItem->m_localDataCount - 1)
			{
				t = t + tSpan;
			}
			while(t < t1)
			{
				if(t.GetDayOfWeek() != 1 &&  t.GetDayOfWeek() != 7 && t < t1) //1 = Sunday, 2 = Monday, ..., 7 = Saturday
				{
					if(lBeginDate == 0)
						lBeginDate = GetIntTimeFromTime(t,nPeriod);

					if (!bFirstDayRange)
					{
						lEndDate = GetIntTimeFromTime(t1 - tSpan,nPeriod);
					}
					else
					{
						while(t1.GetDayOfWeek()==1 || t1.GetDayOfWeek() == 7)
						{
							CTimeSpan OneDay(1,0,0,0);
							t1 -= OneDay;
						}
						lEndDate = GetIntTimeFromTime(t1,nPeriod);
					}
					nCount ++;
					break;
				}
				t = t + tSpan;
			};

			t1 = t2;
			bFirstDayRange = FALSE;

			if(nCount > 0 && lBeginDate >= nLimitTime )
			{
				if( lEndDate < nLimitTime)
					lEndDate = nLimitTime;

				CTime tmBegin = GetTimeFromIntTime(lBeginDate,nPeriod);
				CTime tmEnd = GetTimeFromIntTime(lEndDate,nPeriod);
				if (tmBegin.GetYear() == tmEnd.GetYear() && tmBegin.GetMonth() == tmEnd.GetMonth() && tmBegin.GetDay() == tmEnd.GetDay())
				{
					if (tmBegin.GetHour()*100 + tmBegin.GetMinute() > 1130 && tmEnd.GetHour()*100 + tmEnd.GetMinute() < nAfterBegin)
					{
						continue;
					}
				}

				if (lBeginDate > lEndDate)
				{
					continue ;
				}

				DateRange dr;
				dr.m_nBeginDate = lBeginDate;
				dr.m_nEndDate = lEndDate;
				ayDate.Add(dr);
			}

			if (nCount == 0 && pStockDay[i].m_lDate <= nLimitTime)
			{
				break;
			}
		}

		//下载分钟线数据时按9840的倍数根往前下载,若没有最近41天的数据,则下载最近82天数据,依次类推,最多倒退41*18天
		int nLimitedDays = 0,nPermitCount = 9840;
		if (ayDate.GetCount() < 1)
		{
			if(nEarliestTime > nLimitTime && !bExistLastData) 			//加入最后一段时间
			{
				DateRange dr;
				dr.m_nBeginDate = nLimitTime;
				dr.m_nEndDate = nEarliestTime;
				ayDate.Add(dr);
			}
		}
		else
		{
			int nMaxDays = 0;
			DateRange LastDateRage = ayDate.GetAt(ayDate.GetUpperBound());
			long nPreDate = GetPreDataDate(pCode,LastDateRage.m_nBeginDate,nPeriod);
			if (nGZIndex)
				nMaxDays = 36 - 1;  //36 = (10000/240 * 240)/270
			else
				nMaxDays = 41 - 1;  //41= 10000/240

			long nEarlyLimitedDate = nLimitTime;
			if (PERIOD_TYPE_DAY != nPeriod)
			{
				nEarlyLimitedDate = GetPreDate(pStockDay[m_pTaskItem->m_localDataCount -1].m_lDate,nMaxDays,nPeriod);
				long nCheckDataCount = GetDayDataCount(pCode,nEarlyLimitedDate,nTodayTime,nPeriod);
				if (nCheckDataCount > nPermitCount)
				{
					int nSurplusCount = nCheckDataCount - nPermitCount;
					nEarlyLimitedDate = GetChangedBeginDate(pCode,nEarlyLimitedDate,nSurplusCount,nPeriod);
				}
			}
			if (nPreDate >= nEarlyLimitedDate)
			{
				DateRange dr;
				dr.m_nBeginDate = nEarlyLimitedDate > nLimitTime ? nEarlyLimitedDate : nLimitTime;
				dr.m_nEndDate = nPreDate;
				ayDate.Add(dr);
			}
		}

		CArray<DateRange,DateRange> ayDateChange;
		int nDateCount = ayDate.GetCount();
		nPermitCount = nPermitCount*(m_nReloadDegree + 1);
		for (int i = nDateCount - 1; i>= 0; i--)
		{
			DateRange dateRange = ayDate.GetAt(i);
			long nRangeCount = GetDayDataCount(pCode,dateRange.m_nBeginDate,dateRange.m_nEndDate,nPeriod);
			nLimitedDays += nRangeCount;
			if (nLimitedDays < nPermitCount)
			{
				ayDateChange.Add(dateRange);
			}
			else
			{
				int nSpillCount = nLimitedDays - nPermitCount;
				dateRange.m_nBeginDate = GetChangedBeginDate(pCode,dateRange.m_nBeginDate,nSpillCount,nPeriod);
				ayDateChange.Add(dateRange);
				bChangeRange = TRUE;
				break;
			}
		}
		if (bChangeRange)
		{
			nDateCount = ayDateChange.GetCount();
		}

		if (bDownLoaded)
		{
			bChangeRange = TRUE;
			ayDateChange.RemoveAll();
			long nOutRangeDateB = 20101001; //国庆放假无交易行情
			long nOutRangeDateE = 20101001;
			if (PERIOD_TYPE_DAY != nPeriod)
			{
				nOutRangeDateB = 2010010930;
				nOutRangeDateE = 2010010930;
			}		
			DateRange dr;
			dr.m_nBeginDate = nOutRangeDateB;
			dr.m_nEndDate = nOutRangeDateE;
			nDateCount = ayDateChange.GetCount();
		}

		short nCount = sizeof(ReqDayData) / sizeof(CodeInfo);
		if( sizeof(ReqDayData) % sizeof(CodeInfo) )
			nCount++;
		int lLen = sizeof(AskData) + sizeof(CodeInfo) * (nCount - 1) + nDateCount * sizeof(DateRange);
		lReqLen = lLen;
		AskData* ask = (AskData*)(new char[lLen]);
		memset(ask,0,lLen);

		ask->m_nType  = RT_TECHDATA_RANGE;
		ask->m_nSize  = nCount;
		ask->m_lKey = nPeriod;
		memcpy(&ask->m_nPrivateKey, pCode, sizeof(CodeInfo));

		ReqRangeDayData* pRequest = (ReqRangeDayData*)ask->m_pCode;
		pRequest->m_lBeginPosition = 0;
		pRequest->m_nDay = 0;
		pRequest->m_cPeriod = nPeriod;
		memcpy(&pRequest->m_ciCode, pCode, sizeof(CodeInfo));
		pRequest->m_nDataRangCount = nDateCount;
		DateRange *pRane = pRequest->m_dataRange;

		CString strRequest,strRang;
		for(int nIndex = 0; nIndex < nDateCount; nIndex++)
		{
			if (bChangeRange)
				pRane[nIndex] = ayDateChange.GetAt(nIndex);
			else
				pRane[nIndex] = ayDate.GetAt(nIndex);

			m_DownLoadCount += GetDayDataCount(pCode,pRane[nIndex].m_nBeginDate,pRane[nIndex].m_nEndDate,nPeriod);
			strRang.Format("%d-%d;",pRane[nIndex].m_nBeginDate,pRane[nIndex].m_nEndDate);
			strRequest += strRang;
		}
		return (char*)ask;

	}
	catch (...)
	{
	}
	return NULL;
}