Example #1
0
long CHSDownloadData::GetPreDate( long lCurrentDate,int nDays,int nPeriodType )
{
	int nCount = 0;
	CTimeSpan tmOneDay(1,0,0,0);
	CTime tm = GetTimeFromIntTime(lCurrentDate,nPeriodType);
	while(nCount < nDays )
	{
		tm -= tmOneDay;
		if (tm.GetDayOfWeek() != 1 && tm.GetDayOfWeek() != 7 )
		{
			nCount ++;
		}
	}
	return GetIntTimeFromTime(tm,nPeriodType);
}
Example #2
0
void CConfigRecord::ShowWindow(int nChannel)
{	
	m_ctlRedundancy.SetCheck(m_RecordCfg.vRecordConfigAll[nChannel].bRedundancy);
	SetDlgItemInt(IDC_EDIT_PRERECLEN,m_RecordCfg.vRecordConfigAll[nChannel].iPreRecord);
	SetDlgItemInt(IDC_EDIT_RECORDLEN,m_RecordCfg.vRecordConfigAll[nChannel].iPacketLength);
	if ((m_RecordCfg.vRecordConfigAll[nChannel].iRecordMode == 1) || (m_RecordCfg.vRecordConfigAll[nChannel].iRecordMode == 0))
	{
		if (m_RecordCfg.vRecordConfigAll[nChannel].iRecordMode == 1)
		{
			CheckRadioButton(IDC_RADIO0,IDC_RADIO2,IDC_RADIO1);
		}else
		{
			CheckRadioButton(IDC_RADIO0,IDC_RADIO2,IDC_RADIO2);
		}
		ShowTime(FALSE);
	}else
	{
		CheckRadioButton(IDC_RADIO0,IDC_RADIO2,IDC_RADIO0);
		ShowTime(TRUE);
	}
	//ShowTime(FALSE);
	CTime time = CTime::GetCurrentTime();
	m_ctlRecordWeek.SetCurSel(time.GetDayOfWeek()-1);
	m_nLastWeek = 0;
}
Example #3
0
long GetWorkDays(long lBeginDate,long lEndDate,BOOL bCountHeadTail=TRUE)
{
	long lDays = 0;
	if (lBeginDate <= 0 || lEndDate <= 0)
		return -1;

	CTimeSpan tOneDay(1,0,0,0);
	CTime tBeginDate = LongToDate(lBeginDate);
	CTime tEndDate = LongToDate(lEndDate);

	if (tBeginDate > tEndDate)
		return -1;

	if (!bCountHeadTail)
	{
		tBeginDate += tOneDay;
		tEndDate -= tOneDay;
	}

	if (tBeginDate > tEndDate)
		return - 1;

	while( tBeginDate <= tEndDate)
	{
		long lWeekend = tBeginDate.GetDayOfWeek();
		tBeginDate += tOneDay;
		if (lWeekend == 1 || lWeekend == 7)
		{
			continue;
		}
		lDays++;		
	};

	return lDays;
}
Example #4
0
void CDlgFilterPanel::OnBnClickedStartQuery()
{
	// Get CTime from 1st DataTime Control on the dialog
	CTime SelTime;
	this->m_CtrlDataTime.GetTime(SelTime);

	// Get CTime from 2nd DataTime Control on the dialog
	CTime SaleWk1;
	this->m_CtrlDateTime2.GetTime(SaleWk1);

	// Check user select date, must be Monday
	if ( (SelTime.GetDayOfWeek() != 2) || (SaleWk1.GetDayOfWeek() != 2) )
	{
		::MessageBox(NULL,
			"Sorry, you selected date is not Monday.\nPlease try again.",
			"Warning", MB_OK | MB_ICONWARNING);
		return;
	}

	LPMAINWORKTHREADPARAM lpThreadParam = new MAINWORKTHREADPARAM;
	lpThreadParam->_StartingDate = SelTime.GetTime();
	lpThreadParam->_FirstWeekSale = SaleWk1.GetTime();
	CWinThread *pWinThread = AfxBeginThread(
		(AFX_THREADPROC) MainWorkThreadFunc, (LPVOID) lpThreadParam,
		THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
	pWinThread->m_bAutoDelete = TRUE;
	pWinThread->ResumeThread();

	OnOK();
}
Example #5
0
void CSnapStorageDlg::ShowWindow(int nChannel)
{
// 	m_ctlRedundancy.SetCheck(m_SnapCfg.vSnapshotConfigAll[nChannel].bRedundancy);
 	SetDlgItemInt(IDC_EDIT_LENGTH,m_SnapCfg.vSnapshotConfigAll[nChannel].iPreSnap);
// 	SetDlgItemInt(IDC_EDIT_RECORDLEN,m_SnapCfg.vSnapshotConfigAll[nChannel].iPacketLength);
	if ((m_SnapCfg.vSnapshotConfigAll[nChannel].iSnapMode == 1) || (m_SnapCfg.vSnapshotConfigAll[nChannel].iSnapMode == 0))
	{
		if (m_SnapCfg.vSnapshotConfigAll[nChannel].iSnapMode == 1)
		{
			CheckRadioButton(IDC_RADIO0,IDC_RADIO2,IDC_RADIO1);
		}else
		{
			CheckRadioButton(IDC_RADIO0,IDC_RADIO2,IDC_RADIO2);
		}
		ShowTime(FALSE);
	}else
	{
		CheckRadioButton(IDC_RADIO0,IDC_RADIO2,IDC_RADIO0);
		ShowTime(TRUE);
	}
	CTime time = CTime::GetCurrentTime();
	m_ctlRecordWeek.SetCurSel(time.GetDayOfWeek()-1);
	m_nLastWeek = 0;
	UpdateData(TRUE);
}
void cHappyHour::TickTimerHappyHour()
{
	if (HappyHourEnabled == 0) return;
	CTime t = CTime::GetCurrentTime();
	int Hour = t.GetHour();
	int Min = t.GetMinute();
	int WeekDay = t.GetDayOfWeek();
	
	if (!t.GetSecond())
	{
		for (int i=0; i<HappyHoursNumber; i++)
		{
			if (Hour == HappyStruct[i].S_Hour && Min == HappyStruct[i].S_Min && (WeekDay == HappyStruct[i].S_WeekDay || HappyStruct[i].S_WeekDay == -1))
			{
				Chat.MessageAll(0,0,NULL,"[Happy Hour] %s Event Started. Event Close in %d:%02d.",
					Utilits.GetMapName(HappyStruct[i].MapNum),HappyStruct[i].C_Hour,HappyStruct[i].C_Min);
				HappyStruct[i].Started = true;
			}

			if  (Hour == HappyStruct[i].C_Hour && Min == HappyStruct[i].C_Min && (WeekDay == HappyStruct[i].C_WeekDay || HappyStruct[i].C_WeekDay == -1))
			{
				Chat.MessageAll(0,0,NULL,"[Happy Hour] On %s Event Close.",Utilits.GetMapName(HappyStruct[i].MapNum));	
				HappyStruct[i].Started = false;
			}
			CheckNeedMessage(i);
		}
	}
}
void CRecordUpDlg::OnBnClickedUpdateLweek()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);

	m_radio = 2;

	CTime ct = CTime::GetCurrentTime();
	// 调时间         日  小时 分钟 秒
	ct -= CTimeSpan(ct.GetDayOfWeek()-1, 0, 0, 0);
	int m_ny = ct.GetYear();
	int m_nm = ct.GetMonth();
	int m_nd = ct.GetDay();
	ct -= CTimeSpan(7, 0, 0, 0);
	int m_fy = ct.GetYear();
	int m_fm = ct.GetMonth();
	int m_fd = ct.GetDay();

	CString ft, nt, cs;
	ft.Format(_T("'%d-%d-%d'"), m_fy, m_fm, m_fd);
	nt.Format(_T("'%d-%d-%d'"), m_ny, m_nm, m_nd);

	cs = _T("upTime between ");
	cs += ft;
	cs += _T(" and ");
	cs += nt;
	//MessageBox(cs);
	set.m_strFilter = cs;
	ListTheInfo();
}
void cHappyHour::CheckNeedMessage(int i)
{
	CTime t = CTime::GetCurrentTime();
	int Hour = t.GetHour();
	int Min = t.GetMinute();
	int WeekDay = t.GetDayOfWeek();

	for (int j = 0; j < MessageTimeBeforeCount; j++)
	{
		int TempMin = HappyStruct[i].S_Min - MessageTimeBefore[j];
		int TempHour = HappyStruct[i].S_Hour;
		int TempWeekday = HappyStruct[i].S_WeekDay;

		while(TempMin < 0)
		{
			TempMin += 60;
			TempHour --;
		}

		while(TempHour < 0)
		{
			TempHour += 24;
			TempWeekday --;
			if(TempWeekday == 0)
				TempWeekday = 7;
		}

		if(Hour == TempHour && Min == TempMin && WeekDay == TempWeekday)
			Chat.MessageAll(0,0,NULL,"[Happy Hour] %s will start in %d min.", Utilits.GetMapName(HappyStruct[i].MapNum), MessageTimeBefore[j]);	
	}

	for (int l = 0; l < MessageTimeAfterCount; l++)
	{
		if(HappyStruct[i].Started == false)
			continue;

		int TempMin = HappyStruct[i].C_Min - MessageTimeBefore[l];
		int TempHour = HappyStruct[i].C_Hour;
		int TempWeekday = HappyStruct[i].C_WeekDay;

		while(TempMin < 0)
		{
			TempMin += 60;
			TempHour --;
		}

		while(TempHour < 0)
		{
			TempHour += 24;
			TempWeekday --;
			if(TempWeekday == 0)
				TempWeekday = 7;
		}

		if(Hour == TempHour && Min == TempMin && WeekDay == TempWeekday)
			Chat.MessageAll(0,0,NULL,"[Happy Hour] %s will end in %d min.", Utilits.GetMapName(HappyStruct[i].MapNum), MessageTimeBefore[l]);	
	}
}
Example #9
0
void CTaiChuQuanSetDlg::OnDTNotify(NMHDR *pHdr, LRESULT * pRes)
{
	if(m_fromWhich == 1)//
	{
		CTaiShanDoc* pDoc=CMainFrame::m_taiShanDoc; 

		if(pView == NULL)return;

		CTime tm;
		m_DateTime .GetTime(tm);
		int nDy = tm.GetDayOfWeek ();
		if(nDy == 1|| nDy ==7)
		{
			this->GetDlgItem(IDC_STATIC_STATUS)->SetWindowText("所选日期是星期六或星期天,请重新选择!");
		}
		else
			this->GetDlgItem(IDC_STATIC_STATUS)->SetWindowText("");
		int nFinded=-1;
		int nYear=tm.GetYear ();
		int nMon=tm.GetMonth  ();
		int nDay=tm.GetDay  ();
		CTime tmB(1970,1,1,8,0,0);
		for(int i=0;i<pView->pKlineDrawing ->m_PowerArray .GetSize();i++)
		{
			CTime tmEnd=tmB+pView->pKlineDrawing ->m_PowerArray[i].nTime;
			if(tmEnd.GetDay()==nDay&&tmEnd.GetMonth()==nMon&&tmEnd.GetYear()==nYear)
			{
				 m_timet=pView->pKlineDrawing ->m_PowerArray[i].nTime;
				 m_fAlloc=pView->pKlineDrawing ->m_PowerArray[i].fAllocate*10;
				 m_fDivid=pView->pKlineDrawing ->m_PowerArray[i].fDividend*10;
				 m_fPrice=pView->pKlineDrawing ->m_PowerArray[i].fAllocatePrice;
				 m_fGive=pView->pKlineDrawing ->m_PowerArray[i].fGive*10;
				 m_kind=pView->pKlineDrawing ->m_PowerArray[i].nFlags;
				if( m_kind<0 || m_kind>2)
					 m_kind=0;
				nFinded=i;
				break;
			}
		}
		if(nFinded<0)
		{
			m_fAlloc =0.0f;
			m_fDivid =0.0f;
			m_fPrice =0.0f;
			m_fGive  =0.0f;
			m_kind = 0;
		}
		UpdateData(FALSE);
	}
}
Example #10
0
int CDataFactory::GetItemDayOfWeek(DWORD dwDataIndex)
{
	ASSERT(!m_bIsCurData);	// 必须是初始数据
	
	LPDATAITEM lpDataItem = _GetDataItem(dwDataIndex);
	if(lpDataItem == NULL)
	{
		return 0;
	}
	
	DWORD dwDateTime = lpDataItem->dwDataTime;
	
	CTime tmDateTime = CTime(2000 + dwDateTime / 100000000, (dwDateTime / 1000000) % 100, (dwDateTime / 10000) % 100, 0, 0, 0);
    
	return tmDateTime.GetDayOfWeek() - 1;
}
Example #11
0
WORD CScheduledTask::GetDayOfWeekFlag ( const CTime& time ) const
{
static WORD s_wDayFlags[] = { 0, TASK_SUNDAY, TASK_MONDAY, TASK_TUESDAY,
                              TASK_WEDNESDAY, TASK_THURSDAY, TASK_FRIDAY,
                              TASK_SATURDAY };
WORD wRet = 0;
int  nDayOfWeek = time.GetDayOfWeek();

    ASSERT ( nDayOfWeek >= 1  &&  nDayOfWeek <= 7 );

    wRet = s_wDayFlags [ nDayOfWeek ];

    ASSERT ( wRet != 0 );

    return wRet;
}
Example #12
0
void CXfilterDlg::OnLoad() 
{
	IpFilterDriver.init(IP_FILTER_DRIVER_NAME, FILE_ATTRIBUTE_NORMAL);	
	CString s;
	CTime time = CTime::GetCurrentTime();
	CTimeSpan ts;
	CTime t(0);
	ts = time - t;
	s.Format("CurrentTime: %u, %s DayCount:%u, TotalSec:%u, Week: %u\n"
		, CTime::GetCurrentTime().GetTime()
		, time.Format("%Y-%m-%d %H:%M:%S")
		, ts.GetDays()
		, ts.GetTotalSeconds()
		, time.GetDayOfWeek());
//	OutputDebugString(s);

	if (IpFilterDriver.getError() != NO_ERROR) 
		AfxMessageBox(_T("Can't load IpFilter Driver"));
}
Example #13
0
void CScheduler::SetWeekly(int action,bool activate)
{
	bool Currentactivated = HasWeekly(action);
    if (  Currentactivated == activate) 
		 return; // nothing to do. 

	if ( ( Currentactivated == false )&& (activate == true)) { // must we insert a new? 
     	Schedule_Struct* newschedule=new Schedule_Struct();
		struct tm tmTemp;
	    CTime tNow = CTime(safe_mktime(CTime::GetCurrentTime().GetLocalTm(&tmTemp)));
	
	    newschedule->day=tNow.GetDayOfWeek();
	    newschedule->enabled=true;
	    newschedule->time=time(NULL);
	    newschedule->time2=time(NULL);
	    newschedule->title=GetResString(IDS_SCHEDTEXT);
	    newschedule->ResetActions();
		newschedule->actions[0]=action;
		newschedule->values[0]=L"update";
		AddSchedule(newschedule);
		thePrefs.scheduler=true; // enable scheduler
	}
	if ((Currentactivated == true )&& (activate == false)) { // we must delete

		Schedule_Struct* curschedule;
		for (uint8 si=0;si< GetCount();si++) {
			curschedule=  GetSchedule(si);
			if (curschedule->actions[0]==0 || !curschedule->enabled) continue;
			if (curschedule->day!=DAY_DAYLY) { // not daily, so must be weekly ( or montly, good also) 
				for (int ai=0;ai<16;ai++) {
					if (curschedule->actions[ai]==action) {
						RemoveSchedule(si);
						return ;
					}
				}
			}
		}
		// not found? then schedule does not exist. ASSERT()?;
		return ;
	}
};
Example #14
0
void CMonitorPage::UpdateGameStatus(const i8desk::GameInfoMap& GameInfos)
{
	int nIdcCount = 0, nSvrCount = 0, nMatchCount = 0;
	int nAutoUptCount = 0, nNeedUptCount = 0;
	int nIdcAddInThisWeekCount = 0, nIdcUpdateCount = 0;
	int nIdcI8PlayCount = 0, nIdcI8PlayNotDownloadCount = 0;
	unsigned __int64 ullIdcSize = 0, ullSvrSize = 0;
	unsigned __int64 ullIdcI8PlaySize = 0, ullIdcI8PlayNotDownloadSize = 0;
	
	int nAddGameNoDownNum = 0; //近期新增资源(未下载)

	int nConVirRunGameNum = 0;	//配置为虚拟盘运行的资源数
	unsigned __int64 ullConVirRunGameSize = 0;

	int nConLocRunGameNum = 0;	//配置为本地更新运行的资源数
	unsigned __int64 ullConLocRunGameSize = 0;	

	int nConRunNotUptGameNum = 0;//配置为不更新,直接运行的资源数
	unsigned __int64 ullConRunNotUptGameSize = 0;

	CTime now = CTime::GetCurrentTime();
	int nowYear = now.GetYear();
	int nowMonth = now.GetMonth();
	int nowDay = now.GetDay();

	CTime start(now.GetYear(), now.GetMonth(), now.GetDay(), 0, 0, 0);
	start -= CTimeSpan(30,0,0,0); //30天算近期
	DWORD StartTime = (DWORD)start.GetTime();

	//得到本周开始的时刻,用于计算本周中心更新的游戏数
	int nowDayOfWeek = now.GetDayOfWeek();
	CTime ThisWeekStart = now - CTimeSpan(nowDayOfWeek);

	CTime ThisWeekStartDay(ThisWeekStart.GetYear(), 
		ThisWeekStart.GetMonth(), ThisWeekStart.GetDay(), 0, 0, 0);
	DWORD ThisWeekStartTime = (DWORD)ThisWeekStartDay.GetTime();

	i8desk::GameInfoMapCItr it = GameInfos.begin();
	for (; it != GameInfos.end(); ++it) 
	{
		if (it->second->GID >= MIN_IDC_GID) 
		{
			nIdcCount++;
			ullIdcSize += it->second->Size;

			if (it->second->Status == 1)
				nMatchCount++;

			if (it->second->AddDate > StartTime && it->second->Status == 0)
			{
				nAddGameNoDownNum++;
			}

			if (it->second->IdcVer > ThisWeekStartTime)
			{
				nIdcAddInThisWeekCount++;

				CTime IdcUpdateTime = it->second->IdcVer;
				if (IdcUpdateTime.GetDay() == nowDay
					&& IdcUpdateTime.GetMonth() == nowMonth
					&& IdcUpdateTime.GetYear() == nowYear)
				{
					nIdcUpdateCount++;
				}
			}

			if (it->second->I8Play == 1)
			{
				nIdcI8PlayCount++;
				ullIdcI8PlaySize += it->second->Size;

				if (it->second->Status == 0) 
				{
					nIdcI8PlayNotDownloadCount++;
					ullIdcI8PlayNotDownloadSize += it->second->Size;
				}
			}
		}

		if (it->second->Status == 1)
		{
			nSvrCount++;
			ullSvrSize += it->second->Size;

			if (it->second->AutoUpt == 1)
				nAutoUptCount++;
			if (it->second->GID >= MIN_IDC_GID 
				&& it->second->IdcVer != it->second->SvrVer)
				nNeedUptCount++;

			bool bConLocRunGame = false;
			bool bConVirRunGame = false;
			bool bConRunNotUptGame = false;

			for (size_t i = 0; i < it->second->RunTypes.size(); i++)
			{
				switch (it->second->RunTypes[i].RunType)
				{
				case ERT_LOCAL: 
					bConLocRunGame = true; 
					break;
				case ERT_VDISK:
					bConVirRunGame = true; 
					break;
				case ERT_DIRECT: 
					bConRunNotUptGame = true; 
					break;
				default: 
					break;
				}
			}

			if (bConLocRunGame)
			{
				nConLocRunGameNum++;
				ullConLocRunGameSize += it->second->Size;
			}

			if (bConVirRunGame)
			{
				nConVirRunGameNum++;
				ullConVirRunGameSize += it->second->Size;
			}

			if (bConRunNotUptGame)
			{
				nConRunNotUptGameNum++;
				ullConRunNotUptGameSize += it->second->Size;
			}
		}
	}

	sprintf(m_GameInfo.CGameNum, "%d个/%.2fG", nIdcCount, ullIdcSize/1024.0/1024.0);			//中心游戏数
	sprintf(m_GameInfo.MatchGameNum, "%d个", nMatchCount);		//本地己匹配到中心资源的游戏
	sprintf(m_GameInfo.LGameNum, "%d个/%.2fG", nSvrCount, ullSvrSize/1024.0/1024.0);			//本地游戏数
	
	sprintf(m_GameInfo.CAddGameNum, "%d个", nAddGameNoDownNum);	//近期新增资源(未下载)

	sprintf(m_GameInfo.ConLocRunGameNum, "%d个/%.2fG", nConLocRunGameNum, ullConLocRunGameSize/1024.0/1024.0);	//增值游戏本地未下载数
	sprintf(m_GameInfo.ConVirRunGameNum, "%d个/%.2fG", nConVirRunGameNum, ullConVirRunGameSize/1024.0/1024.0);	//增值游戏本地未下载数
	sprintf(m_GameInfo.ConRunNotUptGameNum, "%d个/%.2fG", nConRunNotUptGameNum, ullConRunNotUptGameSize/1024.0/1024.0);	//增值游戏本地未下载数

	sprintf(m_GameInfo.HaveUptGameNum, "%d个", nNeedUptCount);		//有更新的游戏数
}
Example #15
0
void CFoodMenuDlg::Load( BOOL bByOtherWnd) 
{
	int i = 0;
	// TODO: Add your control notification handler code here
	CTime iDT =  CTime::GetCurrentTime();						
		
	int nCurDay = iDT.GetDayOfWeek();	// 1 = Sunday, 2 = Monday, ..., 7 = Saturday
		
	if(nCurDay == 2)
	{
		//월요일		
	}
	else if(nCurDay == 3)
	{
		// 화요일
		iDT -= CTimeSpan(1, 0, 0, 0); 
	}
	else if(nCurDay == 4)
	{
		//수요일
		iDT -= CTimeSpan(2, 0, 0, 0); 
	}
	else if(nCurDay == 5)
	{
		//목
		iDT -= CTimeSpan(3, 0, 0, 0); 
	}
	else if(nCurDay == 6)
	{
		//금
		iDT -= CTimeSpan(4, 0, 0, 0); 
	}				
	
	//CString strFirstDayOfWeek = iDT.Format("%Y%m%d%H%M%S")	;
	if(!bByOtherWnd)
	{
		COleDateTime tmpOleTmDate;
		tmpOleTmDate.SetDate( atoi( (LPCSTR) iDT.Format("%Y")) , atoi( (LPCSTR) iDT.Format("%m")) , atoi( (LPCSTR) iDT.Format("%d") ));
		m_FoodMenuDateCtrl.SetTime(tmpOleTmDate);

		SetDateLabel() ;			
	}

	m_strMonDayOfWeek = iDT.Format("%Y%m%d")	;

	CString strFileName;
	char szWinDir[512];		
	char szDirTmp[512];
	char szDir[1024];

	memset(szWinDir, 0x00, sizeof(szWinDir));		
	memset(szDirTmp, 0x00, sizeof(szDirTmp));	
	memset(szDir, 0x00, sizeof(szDir));	

	GetWindowsDirectory(szWinDir, sizeof(szWinDir));	
	GetModuleFileName ( GetModuleHandle(IDMS_MSN_SVR_NAME), szDirTmp, sizeof(szDirTmp));	
	int nPos = 0;
	int nLen = strlen(szDirTmp);
	for( i = nLen; i>=0 ; i--)
	{
		if(szDirTmp[i] == '\\' && nPos <1 )
		{
			szDirTmp[i] = '\0';
			nPos++;
			break;
		}
	}
	
	strcat( szDirTmp, "\\food_menu\\" );

	if (_access( (LPCSTR)szDirTmp ,0) ==-1 ) 
	{
		CreateDirectory((LPCSTR)szDirTmp, NULL);		
	}
	
	m_strFileNameAll.Format("%s\\%s_FoodMenu.txt", szDirTmp ,m_strMonDayOfWeek );	

	TRACE("%s\n" , m_strFileNameAll);

	if (_access( (LPCSTR)m_strFileNameAll ,0) ==-1 ) 
	{
		return ;
	}

	CStdioFile fCmdDat(
						m_strFileNameAll,	CFile::modeNoTruncate | CFile::modeReadWrite | CFile::typeText | 
									CFile::shareDenyNone
					  );	
	
	CString rString = "";		

	//if( fCmdDat.ReadString(rString) )
	
	fCmdDat.ReadString(rString) ;
	
	if(rString.IsEmpty())
	{
		return;
	}

	TRACE("rString [%s]\n", rString );
	m_strMenu = rString ;
		
	if(!bByOtherWnd)
	{
		CString subString;
		
		i = 0; 	
		while( AfxExtractSubString(subString, (LPCTSTR)rString, i++, DELIM1 ))
		{
			TRACE("subString [%s]\n", subString );
			if( i<= 4)
			{
				//m_strDate11,DELIM1, '1', DELIM1, m_strMenu11, DELIM1, m_Cal11 , DELIM1 ,
				if(i == 3)
					m_strMenu11 = subString ;
				if(i == 4)
					m_Cal11     = subString ;			
			}
			else if(  i > 4 && i <= 8)
			{				
				if(i == 7)
					m_strMenu12 = subString ;
				if(i == 8)
					m_Cal12     = subString ;			
			}
			else if(  i > 8 && i <= 12)
			{				
				if(i == 11)
					m_strMenu21 = subString ;
				if(i == 12)
					m_Cal21     = subString ;			
			}
			else if(  i > 12 && i <= 16)
			{				
				if(i == 15)
					m_strMenu22 = subString ;
				if(i == 16)
					m_Cal22     = subString ;			
			}
			else if(  i > 16 && i <= 20)
			{				
				if(i == 19)
					m_strMenu31 = subString ;
				if(i == 20)
					m_Cal31     = subString ;			
			}
			else if(  i > 20 && i <= 24)
			{				
				if(i == 23)
					m_strMenu32 = subString ;
				if(i == 24)
					m_Cal32     = subString ;			
			}
			else if(  i > 24 && i <= 28)
			{				
				if(i == 27)
					m_strMenu41 = subString ;
				if(i == 28)
					m_Cal41     = subString ;			
			}
			else if(  i > 28 && i <= 32)
			{				
				if(i == 31)
					m_strMenu42 = subString ;
				if(i == 32)
					m_Cal42     = subString ;			
			}
			else if(  i > 32 && i <= 36)
			{				
				if(i == 35)
					m_strMenu51 = subString ;
				if(i == 36)
					m_Cal51     = subString ;			
			}
			else if(  i > 36 && i <= 40)
			{				
				if(i == 39)
					m_strMenu52 = subString ;
				if(i == 40)
					m_Cal52     = subString ;			
			}			
		} 
		
		UpdateData(FALSE);		
	}

	fCmdDat.Close();
}
Example #16
0
int CScheduler::Check(bool forcecheck){
	if (!thePrefs.IsSchedulerEnabled()
		|| theApp.scheduler->GetCount()==0
		|| !theApp.emuledlg->IsRunning()) return -1;

	Schedule_Struct* schedule;
	struct tm tmTemp;
	CTime tNow = CTime(safe_mktime(CTime::GetCurrentTime().GetLocalTm(&tmTemp)));
	
	if (!forcecheck && tNow.GetMinute()==m_iLastCheckedMinute) return -1;

	m_iLastCheckedMinute=tNow.GetMinute();
	theApp.scheduler->RestoreOriginals();

	for (uint8 si=0;si<theApp.scheduler->GetCount();si++) {
		schedule=theApp.scheduler->GetSchedule(si);
		if (schedule->actions[0]==0 || !schedule->enabled) continue;

		// check day of week
		if (schedule->day!=DAY_DAYLY) {
			int dow=tNow.GetDayOfWeek();
			switch (schedule->day) {
				case DAY_MO : if (dow!=2) continue;
					break;
				case DAY_DI : if (dow!=3) continue;
					break;
				case DAY_MI : if (dow!=4) continue;
					break;
				case DAY_DO : if (dow!=5) continue;
					break;
				case DAY_FR : if (dow!=6) continue;
					break;
				case DAY_SA : if (dow!=7) continue;
					break;
				case DAY_SO : if (dow!=1) continue;
					break;
				case DAY_MO_FR : if (dow==7 || dow==1 ) continue;
					break;
				case DAY_MO_SA : if (dow==1) continue;
					break;
				case DAY_SA_SO : if (dow>=2 && dow<=6) continue;
			}
		}

		//check time
		UINT h1,h2,m1,m2;
		CTime t1=CTime(schedule->time);
		CTime t2=CTime(schedule->time2);
		h1=t1.GetHour();	h2=t2.GetHour();
		m1=t1.GetMinute();	m2=t2.GetMinute();
		int it1,it2, itn;
		it1=h1*60 + m1;
		it2=h2*60 + m2;
		itn=tNow.GetHour()*60 + tNow.GetMinute();
		if (it1<=it2) { // normal timespan
			if ( !(itn>=it1 && itn<it2) ) continue;
		} else {		   // reversed timespan (23:30 to 5:10)  now 10
			if ( !(itn>=it1 || itn<it2)) continue;
		}

		// ok, lets do the actions of this schedule
		ActivateSchedule(si,schedule->time2==0);
	}

	return -1;
}
void cHappyHour::Load()
{
	HappyHourEnabled = Configs.GetInt(0,1,1,"HappyHour","EnableHappyHour",IAJuliaHappyHour);
	if (HappyHourEnabled == 0) return;

	char Buff[256];
	int Flag = 0;
	HappyHoursNumber = 0;
	MessageTimeBeforeCount = 0;
	MessageTimeAfterCount = 0;
	
	CTime t = CTime::GetCurrentTime();
	int Hour = t.GetHour();
	int Min = t.GetMinute();
	int WeekDay = t.GetDayOfWeek();

	FILE *conf = fopen(IAJuliaHappyHour,"r");

	if ( conf != NULL)
	{
		while ( !feof(conf))
		{
			fgets(Buff,256,conf);

			if(Utilits.IsBadFileLine(Buff, &Flag))
				continue;

			if (Flag == 1)
			{
				int n[7];
				sscanf(Buff, "%d %d %d %d %d %d %d %d", &n[0], &n[1], &n[2], &n[3], &n[4], &n[5], &n[6], &n[7]);
				HappyStruct[HappyHoursNumber].MapNum	= n[0];
				HappyStruct[HappyHoursNumber].P_Zen		= n[1];
				HappyStruct[HappyHoursNumber].P_Drop	= n[2];
				HappyStruct[HappyHoursNumber].P_Exp		= n[3];
				HappyStruct[HappyHoursNumber].S_WeekDay	= n[4];
				HappyStruct[HappyHoursNumber].S_Hour	= n[5];
				HappyStruct[HappyHoursNumber].S_Min		= n[6];
				HappyStruct[HappyHoursNumber].T_Delay	= n[7];

				HappyStruct[HappyHoursNumber].Started	= false;

				HappyStruct[HappyHoursNumber].C_Min		= HappyStruct[HappyHoursNumber].S_Min + HappyStruct[HappyHoursNumber].T_Delay;
				HappyStruct[HappyHoursNumber].C_Hour	= HappyStruct[HappyHoursNumber].S_Hour;
				if(HappyStruct[HappyHoursNumber].S_WeekDay == -1)
					HappyStruct[HappyHoursNumber].C_WeekDay = WeekDay;
				else
					HappyStruct[HappyHoursNumber].C_WeekDay = HappyStruct[HappyHoursNumber].S_WeekDay;

				while (HappyStruct[HappyHoursNumber].C_Min >=60)
				{
					HappyStruct[HappyHoursNumber].C_Hour++;
					HappyStruct[HappyHoursNumber].C_Min -= 60;
				}
				while (HappyStruct[HappyHoursNumber].C_Hour >= 24)
				{
					HappyStruct[HappyHoursNumber].C_WeekDay = HappyStruct[HappyHoursNumber].C_WeekDay % 7 + 1;
					HappyStruct[HappyHoursNumber].C_Hour -= 24;
				}
				HappyHoursNumber++;
			}

			if (Flag == 2)
			{
				sscanf(Buff, "%d", &MessageTimeBefore[MessageTimeBeforeCount++]);
			}

			if (Flag == 3)
			{
				sscanf(Buff, "%d", &MessageTimeAfter[MessageTimeAfterCount++]);
			}
		}

	}			  
	fclose(conf);

	Log.ConsoleOutPut(1, c_Magenta, t_Default, "[Happy Hour] Loaded %d locations." ,HappyHoursNumber);
}
Example #18
0
void COBDPNDDlgMainIdle::fRefreshData()
{
	CTime time = CTime::GetCurrentTime();
	m_strTime.Format(_T("%02d:%02d"),time.GetHour(),time.GetMinute());
	m_strDate.Format(_T("%04d-%02d-%02d"),time.GetYear(),time.GetMonth(),time.GetDay());
	m_strWeek = theMainDlg->fGetBinText(0x00011000+time.GetDayOfWeek());

	for (int i=0;i<6;i++)
	{
		m_tagDsInfo[i].strValue= theMainDlg->fGetDataStreamValue(m_tagDsInfo[i].dwDsID);
		//即时油耗1(动态)
		if (m_tagDsInfo[i].dwDsID == 0xFF010001 &&
			m_tagDsInfo[i].strValue == INVALID_DATASTREAM_VALUE_STR)
		{
			if (theMainDlg->fGetDataStreamValue(0xFF010003)!=INVALID_DATASTREAM_VALUE_STR)
			{
				CString strText = theMainDlg->fGetBinText(0xFF010003);
				m_tagDsInfo[i].dwDsID = 0xFF010003;
				m_tagDsInfo[i].strText = strText.Left(strText.Find(_T(" ")));
				m_tagDsInfo[i].strUnit = strText.Right(strText.GetLength() - strText.ReverseFind(' '));

				theMainDlg->m_pConfigReadWrite->fSetIdleUiData(i,0xFF010003);
			}
		}	
		//即时油耗1(静态)
		if (m_tagDsInfo[i].dwDsID == 0xFF010002 &&
			m_tagDsInfo[i].strValue == INVALID_DATASTREAM_VALUE_STR)
		{
			if (theMainDlg->fGetDataStreamValue(0xFF010004)!=INVALID_DATASTREAM_VALUE_STR)
			{
				CString strText = theMainDlg->fGetBinText(0xFF010004);
				m_tagDsInfo[i].dwDsID = 0xFF010004;
				m_tagDsInfo[i].strText = strText.Left(strText.Find(_T(" ")));
				m_tagDsInfo[i].strUnit = strText.Right(strText.GetLength() - strText.ReverseFind(' '));

				theMainDlg->m_pConfigReadWrite->fSetIdleUiData(i,0xFF010004);
			}
		}	
		//即时油耗2(动态)
		if (m_tagDsInfo[i].dwDsID == 0xFF010003 &&
			m_tagDsInfo[i].strValue == INVALID_DATASTREAM_VALUE_STR)
		{
			if (theMainDlg->fGetDataStreamValue(0xFF010001)!=INVALID_DATASTREAM_VALUE_STR)
			{
				CString strText = theMainDlg->fGetBinText(0xFF010001);
				m_tagDsInfo[i].dwDsID = 0xFF010001;
				m_tagDsInfo[i].strText = strText.Left(strText.Find(_T(" ")));
				m_tagDsInfo[i].strUnit = strText.Right(strText.GetLength() - strText.ReverseFind(' '));

				theMainDlg->m_pConfigReadWrite->fSetIdleUiData(i,0xFF010001);
			}
		}	
		//即时油耗2(静态)
		if (m_tagDsInfo[i].dwDsID == 0xFF010004 &&
			m_tagDsInfo[i].strValue == INVALID_DATASTREAM_VALUE_STR)
		{
			if (theMainDlg->fGetDataStreamValue(0xFF010002)!=INVALID_DATASTREAM_VALUE_STR)
			{
				CString strText = theMainDlg->fGetBinText(0xFF010002);
				m_tagDsInfo[i].dwDsID = 0xFF010002;
				m_tagDsInfo[i].strText = strText.Left(strText.Find(_T(" ")));
				m_tagDsInfo[i].strUnit = strText.Right(strText.GetLength() - strText.ReverseFind(' '));


				theMainDlg->m_pConfigReadWrite->fSetIdleUiData(i,0xFF010002);
			}
		}	
	}
	m_strWaterTempValue = theMainDlg->fGetDataStreamValue(0x00000500);
	if (m_strWaterTempValue == _T("------"))
		m_strWaterTempValue = _T("---");

	this->Invalidate();
}
Example #19
0
void COBDPNDDlgMainIdle::fInitUI()
{
	this->MoveWindow(theMainDlg->m_rectWin);

	switch (theMainDlg->m_dwScreenResolution)
	{
	case RESOLUTION_480X272:
		{

		}
		break;
	case RESOLUTION_800X480:
		{
			fSetBkImg(this->GetDC(),IDR_PNG_MODE_IDLE_800X480);

			WORD wUnitBmpHeight=55;
			WORD wUnitBmpWidth=61;

			m_tagDsInfo[0].rectData = CRect(37,41,230,102);  
			m_tagDsInfo[0].rectUnit = CRect(230-wUnitBmpWidth,102-wUnitBmpHeight,230,102);
			m_tagDsInfo[0].rectText = CRect(37,102,228,140);  

			m_tagDsInfo[1].rectData = CRect(37,153,230,214); 
			m_tagDsInfo[1].rectUnit = CRect(230-wUnitBmpWidth,214-wUnitBmpHeight,230,214);
			m_tagDsInfo[1].rectText = CRect(37,214,228,250); 

			m_tagDsInfo[2].rectData = CRect(37,265,230,328); 
			m_tagDsInfo[2].rectUnit = CRect(230-wUnitBmpWidth,328-wUnitBmpHeight,230,328);
			m_tagDsInfo[2].rectText = CRect(37,330,228,360); 

			m_tagDsInfo[3].rectData = CRect(570,41,762,102); 
			m_tagDsInfo[3].rectUnit = CRect(762-wUnitBmpWidth,102-wUnitBmpHeight,762,102);
			m_tagDsInfo[3].rectText = CRect(570,102,760,140); 

			m_tagDsInfo[4].rectData = CRect(570,153,762,214);
			m_tagDsInfo[4].rectUnit = CRect(762-wUnitBmpWidth,214-wUnitBmpHeight,762,214);
			m_tagDsInfo[4].rectText = CRect(570,214,760,250);

			m_tagDsInfo[5].rectData = CRect(570,265,762,328);	                                                         
			m_tagDsInfo[5].rectUnit = CRect(762-wUnitBmpWidth,328-wUnitBmpHeight,762,328);	                                                         
			m_tagDsInfo[5].rectText = CRect(570,330,760,360);

			m_rectDate = CRect(12,377,228,426);
			m_rectWeek = CRect(570,377,760,426);
			m_rectTime = CRect(228,360,570,420);

			m_rectWater = CRect(270,78,272+260,78+260);
			m_rectWaterTempValue = CRect(254,50,546,352);
			m_rectWaterTempText	= CRect(290,270,535,333);

			VERIFY(m_fontDsDataValue.CreateFont(
				60,                        // nHeight
				0,                         // nWidth
				0,                         // nEscapement
				0,                         // nOrientation
				FW_BOLD, //FW_BOLD,加粗        FW_NORMAL        // nWeight
				FALSE,                     // bItalic
				FALSE,                     // bUnderline
				0,                         // cStrikeOut
				ANSI_CHARSET,              // nCharSet
				OUT_DEFAULT_PRECIS,        // nOutPrecision
				CLIP_DEFAULT_PRECIS,       // nClipPrecision
				DEFAULT_QUALITY,           // nQuality
				DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
				_T("Arial Rounded MT")));              // lpszFacename

			VERIFY(m_fontDsDataText.CreateFont(
				19,                        // nHeight
				0,                         // nWidth
				0,                         // nEscapement
				0,                         // nOrientation
				FW_BOLD, //FW_BOLD,加粗        FW_NORMAL        // nWeight
				FALSE,                     // bItalic
				FALSE,                     // bUnderline
				0,                         // cStrikeOut
				ANSI_CHARSET,              // nCharSet
				OUT_DEFAULT_PRECIS,        // nOutPrecision
				CLIP_DEFAULT_PRECIS,       // nClipPrecision
				DEFAULT_QUALITY,           // nQuality
				DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
				_T("Arial Rounded MT")));              // lpszFacename

			VERIFY(m_fontWaterTempText.CreateFont(
				50,                        // nHeight
				0,                         // nWidth
				0,                         // nEscapement
				0,                         // nOrientation
				FW_BOLD, //FW_BOLD,加粗        FW_NORMAL        // nWeight
				FALSE,                     // bItalic
				FALSE,                     // bUnderline
				0,                         // cStrikeOut
				ANSI_CHARSET,              // nCharSet
				OUT_DEFAULT_PRECIS,        // nOutPrecision
				CLIP_DEFAULT_PRECIS,       // nClipPrecision
				DEFAULT_QUALITY,           // nQuality
				DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
				_T("Arial Rounded MT")));              // lpszFacename

			VERIFY(m_fontWaterTempValue.CreateFont(
				165,                        // nHeight
				0,                         // nWidth
				0,                         // nEscapement
				0,                         // nOrientation
				FW_BOLD, //FW_BOLD,加粗        FW_NORMAL        // nWeight
				FALSE,                     // bItalic
				FALSE,                     // bUnderline
				0,                         // cStrikeOut
				ANSI_CHARSET,              // nCharSet
				OUT_DEFAULT_PRECIS,        // nOutPrecision
				CLIP_DEFAULT_PRECIS,       // nClipPrecision
				DEFAULT_QUALITY,           // nQuality
				DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
				_T("Arial Rounded MT")));              // lpszFacename

			VERIFY(m_fontDate.CreateFont(
				35,                        // nHeight
				0,                         // nWidth
				0,                         // nEscapement
				0,                         // nOrientation
				FW_BOLD, //FW_BOLD,加粗        FW_NORMAL        // nWeight
				FALSE,                     // bItalic
				FALSE,                     // bUnderline
				0,                         // cStrikeOut
				ANSI_CHARSET,              // nCharSet
				OUT_DEFAULT_PRECIS,        // nOutPrecision
				CLIP_DEFAULT_PRECIS,       // nClipPrecision
				DEFAULT_QUALITY,           // nQuality
				DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
				_T("Arial Rounded MT")));              // lpszFacename

			VERIFY(m_fontTime.CreateFont(
				54,                        // nHeight
				0,                         // nWidth
				0,                         // nEscapement
				0,                         // nOrientation
				FW_BOLD, //FW_BOLD,加粗        FW_NORMAL        // nWeight
				FALSE,                     // bItalic
				FALSE,                     // bUnderline
				0,                         // cStrikeOut
				ANSI_CHARSET,              // nCharSet
				OUT_DEFAULT_PRECIS,        // nOutPrecision
				CLIP_DEFAULT_PRECIS,       // nClipPrecision
				DEFAULT_QUALITY,           // nQuality
				DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
				_T("Arial Rounded MT")));              // lpszFacename

			VERIFY(m_fontWeek.CreateFont(
				35,                        // nHeight
				0,                         // nWidth
				0,                         // nEscapement
				0,                         // nOrientation
				FW_BOLD, //FW_BOLD,加粗        FW_NORMAL        // nWeight
				FALSE,                     // bItalic
				FALSE,                     // bUnderline
				0,                         // cStrikeOut
				ANSI_CHARSET,              // nCharSet
				OUT_DEFAULT_PRECIS,        // nOutPrecision
				CLIP_DEFAULT_PRECIS,       // nClipPrecision
				DEFAULT_QUALITY,           // nQuality
				DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
				_T("Arial Rounded MT")));              // lpszFacename
		}
		break;
	}
	_TagUiDataIdle tagUiData= theMainDlg->m_pConfigReadWrite->fGetIdleUiData();
	
	m_tagDsInfo[0].dwDsID = tagUiData.dwLeftUpID;
	CString strText = theMainDlg->fGetBinText(tagUiData.dwLeftUpID);
	m_tagDsInfo[0].strText = strText.Left(strText.Find(_T(" ")));
	m_tagDsInfo[0].strUnit = strText.Right(strText.GetLength() - strText.ReverseFind(' '));

	strText = theMainDlg->fGetBinText(tagUiData.dwLeftMiddleID);
	m_tagDsInfo[1].dwDsID = tagUiData.dwLeftMiddleID;
	m_tagDsInfo[1].strText = strText.Left(strText.Find(_T(" ")));
	m_tagDsInfo[1].strUnit = strText.Right(strText.GetLength() - strText.ReverseFind(' '));

	strText = theMainDlg->fGetBinText(tagUiData.dwLeftDownID);
	m_tagDsInfo[2].dwDsID = tagUiData.dwLeftDownID;
	m_tagDsInfo[2].strText = strText.Left(strText.Find(_T(" ")));
	m_tagDsInfo[2].strUnit = strText.Right(strText.GetLength() - strText.ReverseFind(' '));

	strText = theMainDlg->fGetBinText(tagUiData.dwRightUpID);
	m_tagDsInfo[3].dwDsID = tagUiData.dwRightUpID;
	m_tagDsInfo[3].strText = strText.Left(strText.Find(_T(" ")));
	m_tagDsInfo[3].strUnit = strText.Right(strText.GetLength() - strText.ReverseFind(' '));

	strText = theMainDlg->fGetBinText(tagUiData.dwRightMiddleID);
	m_tagDsInfo[4].dwDsID = tagUiData.dwRightMiddleID;
	m_tagDsInfo[4].strText = strText.Left(strText.Find(_T(" ")));
	m_tagDsInfo[4].strUnit = strText.Right(strText.GetLength() - strText.ReverseFind(' '));

	strText = theMainDlg->fGetBinText(tagUiData.dwRightDownID);
	m_tagDsInfo[5].dwDsID = tagUiData.dwRightDownID;
	m_tagDsInfo[5].strText = strText.Left(strText.Find(_T(" ")));
	m_tagDsInfo[5].strUnit = strText.Right(strText.GetLength() - strText.ReverseFind(' '));

	for (int i=0;i<6;i++)
	{
		m_tagDsInfo[i].strValue = _T("------"); 
		m_tagDsInfo[i].iDecLen = _ttoi(m_tagDsInfo[i].strUnit.Right(1));
		DWORD dwUnitResID = theMainDlg->fGetUnitResID(m_tagDsInfo[i].strUnit);
		fCommDrawImage(&m_tagDsInfo[i].memdcUnit,&m_tagDsInfo[i].cBmpUnit,&m_memdcBkBmp,m_tagDsInfo[i].rectUnit,AfxGetResourceHandle(),dwUnitResID);
	}

	CTime time = CTime::GetCurrentTime();
	m_strTime.Format(_T("%02d:%02d"),time.GetHour(),time.GetMinute());
	m_strDate.Format(_T("%04d-%02d-%02d"),time.GetYear(),time.GetMonth(),time.GetDay());
	m_strWeek = theMainDlg->fGetBinText(0x00011000+time.GetDayOfWeek());

	m_strWaterTempText = theMainDlg->fGetBinText(0x00000500);
	m_strWaterTempText = m_strWaterTempText.Left(strText.Find(_T(" ")));
	m_strWaterTempValue  = _T("---");  

	m_clrTempText = RGB(0,0,0);
	m_clrTempValue = RGB(0,0,0);

	m_clrTempValueAlarm = RGB(255,0,0);

	this->Invalidate();
}
Example #20
0
long CSingInServer::ProcessData(TSSmartDocEx *pDocEx, TSSmartTask *pTask, TSCmdBuffer *pBuffer)
{
	bool          bResult = false;
	CTime		  tm;
	int			  len=0,i=0;
	int			  E_number=0;
	unsigned char Clock[16];
	unsigned char Plain[256],ID[16];
	char		  ErrMsg[256];

	
	memset(ID,    0x00,sizeof ID);
	memset(Clock, 0x00,sizeof Clock);
	memset(Plain, 0x00,sizeof Plain);	
	memset(ErrMsg,0x00,sizeof ErrMsg);
	
	sprintf(ErrMsg,"处理终端%.8X签到任务\n",pDocEx->pChildDoc[pDocEx->nPortNo]->m_nAuthID);
	printf(ErrMsg);
	WriteLog(ErrMsg);
	m_nIndex = pDocEx->nPortNo;

	memset(ErrMsg,0x00,sizeof ErrMsg);
	//由于需要金仕达确认是否可以签到,故将签到任务提前到前面
	int ret = 0;
	E_number = 1;	
	for(i=0; i<3; i++)
	{
		tm=CTime::GetCurrentTime();
		Clock[0] = tm.GetYear()-2000;
		Clock[1] = tm.GetMonth();
		Clock[2] = tm.GetDay();
		Clock[3] = tm.GetHour();
		Clock[4] = tm.GetMinute();
		Clock[5] = tm.GetSecond();
		Clock[6] = tm.GetDayOfWeek();

		MakeBuf_SetClock(&pDocEx->pChildDoc[pDocEx->nPortNo]->DeviceInfo, pBuffer,Clock);
		pBuffer->nTimeOut1 = 1000;
		pBuffer->nTimeOut2 = 1000;
		//Modified by hhd at 2006-01-20,added return code
		ret=SendRequest(pDocEx->pChildDoc[m_nIndex], pBuffer);
		if(ret==RET_OK)
		{
			ret=UnMakeDeviceBuffer(pBuffer);
			if(ret==RET_OK)
			{
				sprintf(ErrMsg,"下传终端%.8X时钟成功!\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID);
				printf(ErrMsg);
				WriteLog(ErrMsg);
				bResult = true;
				break;
			}
			else
			{
				sprintf(ErrMsg,"-----!!!!校验%.8X返回包失败-时钟!错误码=[%d]\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID,ret);
				printf(ErrMsg);	
				Sleep(1000);
			}
		}
		else
		{
			sprintf(ErrMsg,"-----!!!!下传终端%.8X时钟失败!错误码=[%d]\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID,ret);
			printf(ErrMsg);			
			Sleep(1000);
		}
	}

	if( !bResult )
	{
		printf("-----!!!!下传终端%.8X时钟失败!\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID);
		ReportLog(pDocEx->pChildDoc[m_nIndex], pTask, RET_CLOCK_ERROR, "终端机签到", "终端机签到 ---校对时钟失败!");
		pDocEx->pChildDoc[pDocEx->nPortNo]->m_nSignIn = RET_CLOCK_ERROR ;
		return RET_CLOCK_ERROR;
	}
	
	char szKeyBuf[256];
	memset(Plain,    0x00, sizeof(Plain));
	memset(szKeyBuf, 0x00, sizeof(szKeyBuf));
	GetAuthKey(szKeyBuf);
	if( !strlen(szKeyBuf) ) //向金仕达取授权密钥失败 add by dengjun 20060616
	{
		strcpy(ErrMsg,"向金仕达取授权密钥失败");
		printf("%s\n",ErrMsg);
		WriteLog(ErrMsg);
	}	
	len = strlen(szKeyBuf)/2;
	SVC_DSP_2_HEX((BYTE*)szKeyBuf, Plain, len);
	//设置授权信息
	bResult = false;
	Sleep(5000); //Modified by dengjun 20060616 update Sleep(250) to Sleep(5000)
	memset(ErrMsg,0x00,sizeof ErrMsg);
	//Modified by hhd at 2006-01-20,added return code
	for(i=0; i<3; i++)
	{
		SVC_DSP_2_HEX((unsigned char *)pDocEx->pChildDoc[pDocEx->nPortNo]->m_szDeviceID, ID, 4);
		//modified by lina 20050308 SmartEncrypt(E_number,ID,Plain);
		MakeBuf_SetWorkingKey(&pDocEx->pChildDoc[pDocEx->nPortNo]->DeviceInfo,pBuffer,Plain,E_number);
		pBuffer->nTimeOut1 = 1000 ;
		pBuffer->nTimeOut2 = 1000;
		ret=SendRequest(pDocEx->pChildDoc[pDocEx->nPortNo], pBuffer);
		if(ret==RET_OK)
		{
			ret=UnMakeDeviceBuffer(pBuffer);
			if(ret==RET_OK)
			{
				sprintf(ErrMsg,"-----设置终端%.8X授权信息成功!\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID);
				printf(ErrMsg);
				WriteLog(ErrMsg);
				bResult = true;
				break;
			}
			else
			{
				sprintf(ErrMsg,"-----!!!!校验%.8X返回包失败-授权!错误码=[%d]\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID,ret);
				printf(ErrMsg);					
				Sleep(2500);
			}
		}
		Sleep(1000); 
	}
	
	if( !bResult )
	{
		printf("-----!!!!设置终端%.8X授权信息失败!\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID);
		ReportLog(pDocEx->pChildDoc[m_nIndex], pTask, RET_NOT_AUTH, "终端机签到", "终端机签到 ---设置授权信息失败!");
		pDocEx->pChildDoc[pDocEx->nPortNo]->m_nSignIn = RET_NOT_AUTH ;
		return RET_NOT_AUTH;
	}	
	if((ret=SignIn(pDocEx->pChildDoc[pDocEx->nPortNo])) != RET_OK)
	{
		sprintf(ErrMsg,"后台不允许签到[ErrCode=%ld]!!!!!!!!!!!!!!!\n",ret);
		printf(ErrMsg);
		WriteLog(ErrMsg);		
		return  RET_ERROR_AUTH;//25:后台不允许签到;		
	}
	
	Sleep(3000);
	//设置消费开关
	bResult = false;
	for(i=0; i<3; i++)
	{
		MakeBuf_SetComsumeFlag(&pDocEx->pChildDoc[pDocEx->nPortNo]->DeviceInfo, pBuffer, 1);
		pBuffer->nTimeOut1 = 1000 ;
		pBuffer->nTimeOut2 = 1000;
		ret=SendRequest(pDocEx->pChildDoc[pDocEx->nPortNo], pBuffer);
		if(ret==RET_OK)
		{
			ret=UnMakeDeviceBuffer(pBuffer);
			if(ret==RET_OK)
			{
				bResult = true;
				break;
			}
			else
			{
				sprintf(ErrMsg,"-----!!!!校验%.8X返回包失败-消费开关!错误码=[%d]\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID,ret);
				printf(ErrMsg);
				WriteLog(ErrMsg);
				Sleep(1500);
			}
		}
		else
		{
			Sleep(200);
		}
	}

	if( !bResult )
	{
		printf(ErrMsg,"----!!!!设备%.8X签到失败!\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID);
		ReportLog(pDocEx->pChildDoc[m_nIndex], pTask, RET_REQU_SIGNIN, "终端机签到", "终端机签到--设置消费开关失败!");
		pDocEx->pChildDoc[pDocEx->nPortNo]->m_nSignIn = RET_REQU_SIGNIN ;
		WriteLog(ErrMsg);
		return RET_REQU_SIGNIN;
	}
	pDocEx->pChildDoc[pDocEx->nPortNo]->m_nSignIn = 1 ;
	GetCurDateTime(pDocEx->pChildDoc[pDocEx->nPortNo]->m_szSignInTime);
	printf(ErrMsg,"-----%.8X签到成功!\n",pDocEx->pChildDoc[pDocEx->nPortNo]->m_nAuthID);
	ReportLog(pDocEx->pChildDoc[m_nIndex], pTask, RET_OK, "终端机签到", "终端机签到成功!");
	WriteLog(ErrMsg);	
	return RET_OK;
}
Example #21
0
void Alarm::CheckAndTrigger()
{
    if (ValidFieldFlags == 0)
        return;

    BOOL Triggered = TRUE;

    CTime now = CTime::GetCurrentTime();

    if ((ValidFieldFlags & VF_TIMEOFDAY) != 0)
    {
        if ((now.GetHour() != TimeOfDayHour) ||
                (now.GetMinute() != TimeOfDayMinute))
        {
            Triggered = FALSE;
        }
    }

    if ((ValidFieldFlags & VF_DAYOFWEEK) != 0)
    {
        if (now.GetDayOfWeek() != DayOfWeek)
            Triggered = FALSE;
    }

    if ((ValidFieldFlags & VF_DAYOFMONTH) != 0)
    {
        if (now.GetDay() != DayOfMonth)
            Triggered = FALSE;
    }

    if ((ValidFieldFlags & VF_MONTHOFYEAR) != 0)
    {
        if (now.GetMonth() != MonthOfYear)
            Triggered = FALSE;
    }

    if (Triggered)
    {
        CTimeSpan timeSinceLastTrigger = now - TimeLastTriggered;

        if ((ValidFieldFlags & VF_TIMEOFDAY) != 0)
        {
            if (timeSinceLastTrigger.GetTotalMinutes() < 2)
                Triggered = FALSE;
        }
        else if (((ValidFieldFlags & VF_DAYOFWEEK) != 0) ||
                 ((ValidFieldFlags & VF_DAYOFMONTH) != 0))
        {
            if (timeSinceLastTrigger.GetTotalHours() < 26)
                Triggered = FALSE;
        }
        else
        {
            if (timeSinceLastTrigger.GetTotalHours() < (24*33))
                Triggered = FALSE;
        }
    }

    if (Triggered)
    {
        TimeLastTriggered = now;

        TRACE1("TRIGGER: %s\n", TextMessage);

        DAlarmNotify& dlg = *new DAlarmNotify;
        dlg.TextMessage = TextMessage;
        dlg.Create(IDD_ALARMNOTIFY);
        dlg.ShowWindow(SW_SHOW);

        sndPlaySound(((CAlarmsDlg*)theApp.m_pMainWnd)->alarmsSoundFile,SND_ASYNC);
    }
}
Example #22
0
long CSingInServer::ProcessSingIn(TSDeviceInfo *pDevInfo, TSSmartDoc *pDoc, TSCmdBuffer *pBuffer)
{
	bool          bResult = false;
	CTime		  tm;
	int			  E_number;
	unsigned char Clock[7];
	unsigned char Plain[256],ID[4];

	E_number = 1;

	//下传时钟
	for(int i=0; i<3; i++)
	{
		tm=CTime::GetCurrentTime();

		Clock[0] = tm.GetYear()-2000;	Clock[1] = tm.GetMonth();	Clock[2] = tm.GetDay();
		Clock[3] = tm.GetHour();	Clock[4] = tm.GetMinute();	Clock[5] = tm.GetSecond();
		Clock[6] = tm.GetDayOfWeek();

		MakeBuf_SetClock(pDevInfo, pBuffer, Clock);
		pBuffer->nTimeOut1 = 300;//1000 ;
		pBuffer->nTimeOut2 = 1000;
		if(SendRequest(pDoc, pBuffer) == RET_OK )
		{
			if(UnMakeDeviceBuffer(pBuffer) == RET_OK && !pBuffer->pBuffer[2])
			{
				bResult = true;
				break;
			}
		}
		Sleep(200);
	}

	if( !bResult )
	{
		printf("终端机签到--校对时钟失败!.\n");
		ReportLog(pDoc, m_pTask, RET_CLOCK_ERROR, "终端机签到", "终端机签到--校对时钟失败!");
		return RET_CLOCK_ERROR;
	}

	char szKeyBuf[256];

	memset(Plain, 0, sizeof(Plain));
	memset(szKeyBuf, 0, sizeof(szKeyBuf));

	GetAuthKey(szKeyBuf);

	SVC_DSP_2_HEX((unsigned char *)szKeyBuf, Plain, strlen(szKeyBuf)/2);
	Sleep(200);
	//设置授权信息
	bResult = false;
	for(i=0; i<3; i++)
	{
		SVC_DSP_2_HEX((unsigned char *)pDoc->m_szDeviceID, ID, 4);
		//modified by lina 20050308 SmartEncrypt(E_number,ID,Plain);
		MakeBuf_SetWorkingKey(pDevInfo, pBuffer, Plain, E_number);

		pBuffer->nTimeOut1 = 300 ;
		pBuffer->nTimeOut2 = 1000;
		//bResult = true;//debug 20050311
		if(SendRequest(pDoc, pBuffer) == RET_OK )
		{
			if(UnMakeDeviceBuffer(pBuffer) == RET_OK && !pBuffer->pBuffer[2] )
			{
				bResult = true;
				break;
			}
		}
		Sleep(200);
	}

	if( !bResult )
	{
		printf("终端机签到--设置授权信息失败!.\n");
		ReportLog(pDoc, m_pTask, RET_NOT_AUTH, "终端机签到", "终端机签到--设置授权信息失败!");
		return RET_NOT_AUTH;
	}

	//设置消费开关
	bResult = false;
	Sleep(200);
	for(i=0; i<3; i++)
	{
		MakeBuf_SetComsumeFlag(pDevInfo, pBuffer, 1);
		pBuffer->nTimeOut1 = 300;//1000 ;
		pBuffer->nTimeOut2 = 1000;
		if( SendRequest(pDoc, pBuffer) == RET_OK )
		{
			//debug 20050311
		//	ReportLog(pDoc, m_pTask, RET_REQU_SIGNIN, "终端机签到", "RETOK!");

			if( UnMakeDeviceBuffer(pBuffer) == RET_OK&& !pBuffer->pBuffer[2] )
			{
				bResult = true;
				break;
			}
		}
		Sleep(200);
	}

	if( !bResult )
	{
		printf("终端机签到失败!\n");
		ReportLog(pDoc, m_pTask, RET_REQU_SIGNIN, "终端机签到", "终端机签到--设置消费开关失败!");
		return RET_REQU_SIGNIN;
	}

	if( SignIn && pDoc->m_nSignIn != 1 )
	{
		SignIn(pDoc);
	}

	pDoc->m_nSignIn = 1 ;
	GetCurDateTime(pDoc->m_szSignInTime);

	ReportLog(pDoc, m_pTask, RET_OK, "终端机签到", "");
	return RET_OK;
}
Example #23
0
long CHSDownloadData::GetPreDataDate( CodeInfo *pCode,long nCurrentDate,int nPeriod )
{
	CTimeSpan oneDay(1,0,0,0);
	CTimeSpan tSpan = GetTimeStep(nPeriod);
	CTime tm =  GetTimeFromIntTime(nCurrentDate,nPeriod);

	short nGZIndex = MakeGZIndex(pCode->m_cCodeType);
	short nMainType  = MakeMarket(pCode->m_cCodeType);
	int nBeing1min = 931;
	int nBegin5min = 935;
	if (nMainType != STOCK_MARKET)
	{
		if (nGZIndex)
		{
			nBeing1min = 916;
			nBegin5min = 920;
		}
		else
		{
			nBeing1min = 901;
			nBegin5min = 905;
		}
	}

	switch(nPeriod)
	{
	case PERIOD_TYPE_DAY:
		tm -= tSpan;
		while(tm.GetDayOfWeek() == 1 || tm.GetDayOfWeek() ==7)
		{
			tm -= tSpan;
		}
		return GetIntTimeFromTime(tm,nPeriod);

	case PERIOD_TYPE_MINUTE1:
	case PERIOD_TYPE_MINUTE5:
		{
			int nMinute = nCurrentDate%10000;
			if (nPeriod == PERIOD_TYPE_MINUTE1)
			{
				if (nMinute != nBeing1min)
				{
					tm -= tSpan;
					return GetIntTimeFromTime(tm,nPeriod);
				}
			}
			if (nPeriod == PERIOD_TYPE_MINUTE5)
			{
				if (nMinute != nBegin5min)
				{
					tm -= tSpan;
					return GetIntTimeFromTime(tm,nPeriod);
				}
			}

			tm -= oneDay;
			while(tm.GetDayOfWeek() == 1 || tm.GetDayOfWeek() == 7)
			{
				tm -= oneDay;
			}
			long lPreDate = (tm.GetYear() - 1990)* 100000000 + tm.GetMonth() * 1000000 + tm.GetDay() * 10000;
			if (nGZIndex)
			{
				lPreDate += 1515;
			}
			else
			{
				lPreDate += 1500;
			}

			return lPreDate;
		}
	default:
		return nCurrentDate;
	}
}
Example #24
0
long CHSDownloadData::GetChangedBeginDate( CodeInfo *pCode,long lBeginDate,int nSpillDays,int nPeriod )
{
	if (nSpillDays <= 0)
	{
		return lBeginDate;
	}

	short nOneDayNums  = 240;
	short nGZIndex = MakeGZIndex(pCode->m_cCodeType);
	short nMainType  = MakeMarket(pCode->m_cCodeType);

	if (nGZIndex)
		nOneDayNums = 270;
	else
		nOneDayNums = 240;

	int nCount = 0,nGapDays =0, nYushu =0;
	CTimeSpan oneDay(1,0,0,0);
	CTime tmbg = GetTimeFromIntTime(lBeginDate,nPeriod);
	long lBeginMinite = lBeginDate%10000;
	switch(nPeriod)
	{
	case PERIOD_TYPE_DAY:
		while(nCount < nSpillDays)
		{
			tmbg += oneDay;
			int nWeekEnd = tmbg.GetDayOfWeek();
			if (nWeekEnd != 1 && nWeekEnd != 7)
			{
				nCount++;
			}
		}
		return GetIntTimeFromTime(tmbg,nPeriod);
	case PERIOD_TYPE_MINUTE1:
	case PERIOD_TYPE_MINUTE5:
		{
			int nIndex = 1,nQiHuoMorningBegin = 900,nQZQihuoMorningBegin = 915,nStockMorningBegin = 930;
			if (nPeriod == PERIOD_TYPE_MINUTE5)
			{
				nIndex = 5;
				nQiHuoMorningBegin = 905;
				nQZQihuoMorningBegin = 920;
				nStockMorningBegin = 935;
			}
			nGapDays = nSpillDays/(nOneDayNums/nIndex);
			nYushu = nSpillDays%(nOneDayNums/nIndex);
			while(nCount < nGapDays)
			{
				tmbg += oneDay;
				int nWeekEnd = tmbg.GetDayOfWeek();
				if (nWeekEnd != 1 && nWeekEnd != 7)
				{
					nCount++;
				}
			}

			CTime tmMoriningEnd;
			CTime tmNewTime;
			long lTmp = 0;
			CTimeSpan  tmTempSpan;
			CTimeSpan min1(0,(nYushu*nIndex)/60,(nYushu*nIndex)%60,0);
			CTime tmTemp = tmbg;
			tmTemp += min1;
			long lNewMini = GetIntTimeFromTime(tmTemp,nPeriod);
			tmNewTime = tmTemp;
			if (lBeginMinite < 1130)
			{	
				long ltailMini = lNewMini%10000;
				if (ltailMini <1130 )
				{
					return  lNewMini;
				}
				else
				{
					if (nMainType == STOCK_MARKET)
					{
						lTmp = (lNewMini/10000) * 10000 + 1300;
					}
					else
					{
						if (!nGZIndex)
							lTmp = (lNewMini/10000) * 10000 + 1330;
						else
							lTmp = (lNewMini/10000) * 10000 + 1300;
					}
					tmNewTime = GetTimeFromIntTime(lTmp,nPeriod);
					tmMoriningEnd = GetTimeFromIntTime((lNewMini/10000) * 10000 + 1130,nPeriod);
					tmTempSpan = tmTemp - tmMoriningEnd;
					tmNewTime += tmTempSpan;
					lNewMini = GetIntTimeFromTime(tmNewTime,nPeriod);
					goto minite1_5;
				}
			}
			else
			{
				goto minite1_5;
			}

minite1_5:
			if (nGZIndex)
			{
				if (lNewMini%10000 <= 1515)
				{
					return lNewMini;
				}
				else
				{
					lTmp = (lNewMini/10000) * 10000 + 1515;
					tmTemp = GetTimeFromIntTime(lTmp,nPeriod);
					tmTempSpan = tmNewTime - tmTemp;

					lNewMini = (lNewMini/10000) * 10000 + nQZQihuoMorningBegin;
					tmTemp =  GetTimeFromIntTime(lNewMini,nPeriod);
					tmTemp += oneDay;
					tmTemp += tmTempSpan;
					lNewMini = GetIntTimeFromTime(tmTemp,nPeriod);
					if (lNewMini%10000 <= 1130)
					{
						return lNewMini;
					}
					tmMoriningEnd = GetTimeFromIntTime((lNewMini/10000) * 10000 + 1130,nPeriod);
					tmTempSpan = tmTemp - tmMoriningEnd;
					lTmp = (lNewMini/10000) * 10000 + 1300;
					tmTemp = GetTimeFromIntTime(lTmp,nPeriod);
					tmTemp += tmTempSpan;
					return  GetIntTimeFromTime(tmTemp,nPeriod);
				}
			}
			else
			{
				if (lNewMini%10000 <= 1500)
				{
					return lNewMini;
				}
				else
				{
					lTmp = (lNewMini/10000) * 10000 + 1500;
					tmTemp = GetTimeFromIntTime(lTmp,nPeriod);
					tmTempSpan = tmNewTime - tmTemp;

					if (nMainType == STOCK_MARKET)						
						lNewMini = (lNewMini/10000) * 10000 + nStockMorningBegin;			
					else
						lNewMini = (lNewMini/10000) * 10000 + nQiHuoMorningBegin;

					tmTemp =  GetTimeFromIntTime(lNewMini,nPeriod);
					tmTemp += oneDay;
					tmTemp += tmTempSpan;
					lNewMini = GetIntTimeFromTime(tmTemp,nPeriod);
					if (lNewMini%10000 <= 1130)
					{
						return lNewMini;
					}
					tmMoriningEnd = GetTimeFromIntTime((lNewMini/10000) * 10000 + 1130,nPeriod);
					tmTempSpan = tmTemp - tmMoriningEnd;
					if (nMainType == STOCK_MARKET)	
						lTmp = (lNewMini/10000) * 10000 + 1300;
					else
						lTmp = (lNewMini/10000) * 10000 + 1330;

					tmTemp = GetTimeFromIntTime(lTmp,nPeriod);
					tmTemp += tmTempSpan;
					return  GetIntTimeFromTime(tmTemp,nPeriod);
				}
			}
		}
		break;
	default:
		return lBeginDate;
	}
}
Example #25
0
int CScheduler::Check(bool forcecheck){
	if (!thePrefs.IsSchedulerEnabled()
		|| theApp.scheduler->GetCount()==0
		|| !theApp.emuledlg->IsRunning()) return -1;

	Schedule_Struct* schedule;
	struct tm tmTemp;
	CTime tNow = CTime(safe_mktime(CTime::GetCurrentTime().GetLocalTm(&tmTemp)));
	
	if (!forcecheck && tNow.GetMinute()==m_iLastCheckedMinute) return -1;

	m_iLastCheckedMinute=tNow.GetMinute();
	theApp.scheduler->RestoreOriginals();

	for (uint8 si=0;si<theApp.scheduler->GetCount();si++) {
		schedule=theApp.scheduler->GetSchedule(si);
		if (schedule->actions[0]==0 || !schedule->enabled) continue;

		// check day of week
		if (schedule->day!=DAY_DAYLY) {
			int dow=tNow.GetDayOfWeek();
			switch (schedule->day) {
				case DAY_MO : if (dow!=2) continue;
					break;
				case DAY_DI : if (dow!=3) continue;
					break;
				case DAY_MI : if (dow!=4) continue;
					break;
				case DAY_DO : if (dow!=5) continue;
					break;
				case DAY_FR : if (dow!=6) continue;
					break;
				case DAY_SA : if (dow!=7) continue;
					break;
				case DAY_SO : if (dow!=1) continue;
					break;
				case DAY_MO_FR : if (dow==7 || dow==1 ) continue;
					break;
				case DAY_MO_SA : if (dow==1) continue;
					break;
				case DAY_SA_SO : if (dow>=2 && dow<=6) continue;
			}
		}

		//check time
		UINT h1,h2,m1,m2;
		CTime t1=CTime(schedule->time);
		CTime t2=CTime(schedule->time2);
		h1=t1.GetHour();	h2=t2.GetHour();
		m1=t1.GetMinute();	m2=t2.GetMinute();
		int it1,it2, itn;
		it1=h1*60 + m1;
		it2=h2*60 + m2;

		// ==> handling of one-time-events [Mighty Knife] - Stulle
		// if start-time=end-time, this is an event that should
		// occur once in that minute. In that case we add 1 to it2 to make sure
		// it happens (because of the timespan-comparison below, which happens
		// once per minute, too...)
		if (it2==it1) it2++;
		// <== handling of one-time-events [Mighty Knife] - Stulle

		itn=tNow.GetHour()*60 + tNow.GetMinute();
		if (it1<=it2) { // normal timespan
			if ( !(itn>=it1 && itn<it2) ) continue;
		} else {		   // reversed timespan (23:30 to 5:10)  now 10
			if ( !(itn>=it1 || itn<it2)) continue;
		}

		// ok, lets do the actions of this schedule
		ActivateSchedule(si,schedule->time2==0);
	}

	return -1;
}
BOOL TMonsterAIRuleInfo::CheckConditionSpecificDate()
{
	CTime tCurrentTime = CTime::GetTickCount();
	CTimeSpan tValidRange(0, 0, 0, this->m_iWaitTime+this->m_iContinuanceTime);

	int iYear = tCurrentTime.GetYear();
	int iMonth = tCurrentTime.GetMonth();
	int iDay = tCurrentTime.GetDay();
	int iDayOfWeek = tCurrentTime.GetDayOfWeek();
	int iHour = tCurrentTime.GetHour();
	int iMinute = tCurrentTime.GetMinute();

	if ( this->m_iMonth != -1 )
	{
		if ( this->m_iMonth != iMonth )
		{
			CTime tConditionTime(iYear, this->m_iMonth, 0, 0, 0, 0, -1) ;

			if ( tCurrentTime < tConditionTime  ||
				 tCurrentTime > tConditionTime+tValidRange )
			{
				return FALSE;
			}
		}
	}

	if ( this->m_iDay != -1 )
	{
		if ( this->m_iDay != iDay )
		{
			CTime tConditionTime(iYear, (this->m_iMonth == -1)?iMonth : this->m_iMonth , this->m_iDay, 0, 0, 0, -1);

			if ( tCurrentTime < tConditionTime  ||
				 tCurrentTime > tConditionTime+tValidRange )
			{
				return FALSE;
			}
		}
	}

	if ( this->m_iWeekDay != -1 )
	{
		if ( this->m_iWeekDay != iDayOfWeek )
		{
			return FALSE;
		}
	}

	if ( this->m_iHour != -1 )
	{
		if ( this->m_iHour != iHour )
		{
			CTime tConditionTime(iYear, (this->m_iMonth == -1)?iMonth : this->m_iMonth,
				(this->m_iDay == -1)?iDay : this->m_iDay, this->m_iHour, 0, 0, -1) ;

			if ( tCurrentTime < tConditionTime  ||
				 tCurrentTime > tConditionTime+tValidRange )
			{
				return FALSE;
			}
		}
	}

	if ( this->m_iMinute != -1 )
	{
		if ( this->m_iMinute != iMinute )
		{
			CTime tConditionTime(iYear, (this->m_iMonth == -1)?iMonth : this->m_iMonth,
										(this->m_iDay == -1)?iDay : this->m_iDay,
										(this->m_iHour == -1)?iHour : this->m_iHour,
										 this->m_iMinute, 0, -1) ;

			if ( tCurrentTime < tConditionTime  ||
				 tCurrentTime > tConditionTime+tValidRange )
			{
				return FALSE;
			}
		}
	}

	return TRUE;
}	
Example #27
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;
}
Example #28
0
BOOL CSuggestSuspension::OnInitDialog() 
{
	CDialog::OnInitDialog();
//
//  Set up pointers to the controls
//
  pListCtrlLIST = (CListCtrl *)GetDlgItem(SUGGESTSUSPENSION_LIST);
  
  DWORD dwExStyles = pListCtrlLIST->GetExtendedStyle();
  pListCtrlLIST->SetExtendedStyle(dwExStyles | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_INFOTIP);
//
//  Show the hourgalss
//
  HCURSOR hSaveCursor = SetCursor(hCursorWait);
//
//  Set up the columns on the list control
//
//
//  Set up the list controls
//
  LVCOLUMN LVC;
  LVC.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;

  LVC.cx = 120;
  LVC.fmt = LVCFMT_CENTER;
  LVC.pszText = "Date";
  pListCtrlLIST->InsertColumn(0, &LVC);

  LVC.cx = 60;
  LVC.pszText = "Run #";
  pListCtrlLIST->InsertColumn(1, &LVC);

  LVC.cx = 60;
  LVC.pszText = "On at";
  pListCtrlLIST->InsertColumn(2, &LVC);

  LVC.cx = 60;
  LVC.pszText = "Off at";
  pListCtrlLIST->InsertColumn(3, &LVC);
 
  LVC.cx = 60;
  LVC.pszText = "Pay";
  pListCtrlLIST->InsertColumn(4, &LVC);
//
//  Get his data from the roster
//
  typedef struct RosterPayStruct
  {
    int  num;
    long RUNSrecordIDs[10];
    long runNumber[10];
    long onTime[10];
    long offTime[10];
    long payTime[10];
    long flags[10];
  } RosterPayDef;

  RosterPayDef RD[7];

  int nI, nJ;

  for(nI = 0; nI < 7; nI++)
  {
    RD[nI].num = 0;
  }

  int rcode2;

  ROSTERKey1.DIVISIONSrecordID = m_DivisionRecordID;
  ROSTERKey1.rosterNumber = NO_RECORD;
  rcode2 = btrieve(B_GETGREATER, TMS_ROSTER, &ROSTER, &ROSTERKey1, 1);
  while(rcode2 == 0 &&
        ROSTER.DIVISIONSrecordID == m_DivisionRecordID)
  {
    if(ROSTER.DRIVERSrecordID == *m_pDRIVERSrecordID)
    {
      for(nI = 0; nI < 7; nI++)
      {
        if(ROSTER.WEEK[m_RosterWeek].RUNSrecordIDs[nI] == NO_RECORD)
        {
          continue;
        }
        nJ = RD[nI].num;
        RD[nI].RUNSrecordIDs[nJ] = ROSTER.WEEK[m_RosterWeek].RUNSrecordIDs[nI];
        RD[nI].flags[nJ] = ROSTER.WEEK[m_RosterWeek].flags;
        RD[nI].num++;
      }
    }
    rcode2 = btrieve(B_GETNEXT, TMS_ROSTER, &ROSTER, &ROSTERKey1, 1);
  }
//
//  Fill up the rest of the structure with run details
//
  PROPOSEDRUNDef PROPOSEDRUN;
  COSTDef COST;
  int     numPieces;

  for(nI = 0; nI < 7; nI++)
  {
    for(nJ = 0; nJ < RD[nI].num; nJ++)
    {
      RUNSKey0.recordID = RD[nI].RUNSrecordIDs[nJ];
      btrieve(B_GETEQUAL, TMS_RUNS, &RUNS, &RUNSKey0, 0);
      btrieve(B_GETPOSITION, TMS_RUNS, &RUNS, &RUNSKey0, 0);
      btrieve(B_GETDIRECT, TMS_RUNS, &RUNS, &RUNSKey1, 1);
      RD[nI].runNumber[nJ] = RUNS.runNumber;
      numPieces = GetRunElements(hWndMain, &RUNS, &PROPOSEDRUN, &COST, TRUE);
      RD[nI].onTime[nJ] = RUNSVIEW[0].runOnTime;
      RD[nI].offTime[nJ] = RUNSVIEW[numPieces - 1].runOffTime;
      RD[nI].payTime[nJ] = COST.TOTAL.payTime;
    }
  }
//
//  Start with today
//
  long yyyy, mm, dd;
  int indexToRoster[7] = {6, 0, 1, 2, 3, 4, 5};
  CTime firstDay = CTime::GetCurrentTime();
  long day = firstDay.GetDay();
  long month = firstDay.GetMonth();
  long year = firstDay.GetYear();
  long fDay = year * 10000 + month * 100 + day;
//
//  End with the "until date" on this pick
//
  GetYMD(untilDate, &yyyy, &mm, &dd);
  CTime lastDay(yyyy, mm, dd, 0, 0, 0);
//
//  Go through the assignments for each day
//
  CTime currentDate = firstDay;
  currentDate -= CTimeSpan(1, 0, 0, 0);
//
//  Display up until the untilDate
//
  LVITEM LVI;
  int    iItem;
  CString s;
  int today;

  for(;;)
  {
    currentDate += CTimeSpan(1, 0, 0, 0);
    day = currentDate.GetDay();
    month = currentDate.GetMonth();
    year = currentDate.GetYear();
    LVI.lParam = year * 10000 + month * 100 + day;
    if(LVI.lParam > untilDate)
    {
      break;
    }
    today = indexToRoster[currentDate.GetDayOfWeek() - 1];
 	  s = currentDate.Format(_T("%d-%b-%Y (%a)"));
//
//  Cycle through the number of Roster entries for today (typically 1)
//
    for(nI = 0; nI < RD[today].num; nI++)
    {
//
//  Output the date
//
      strcpy(tempString, s);
      if(IsHeAwayToday(LVI.lParam))
      {
        strcat(tempString, " *");
      }
      
      iItem = pListCtrlLIST->GetItemCount();

      LVI.mask = LVIF_TEXT | LVIF_PARAM;
      LVI.iItem = iItem;
      LVI.iSubItem = 0;
      LVI.pszText = tempString;
      LVI.iItem = pListCtrlLIST->InsertItem(&LVI);
//
//  Run number
//
      sprintf(tempString, "%ld", RD[today].runNumber[nI]);

      LVI.mask = LVIF_TEXT;
      LVI.iItem = iItem;
      LVI.iSubItem = 1;
      LVI.pszText = tempString;
      LVI.iItem = pListCtrlLIST->SetItem(&LVI);
//
//  On time
//
      strcpy(tempString, Tchar(RD[today].onTime[nI]));

      LVI.mask = LVIF_TEXT;
      LVI.iItem = iItem;
      LVI.iSubItem = 2;
      LVI.pszText = tempString;
      LVI.iItem = pListCtrlLIST->SetItem(&LVI);
//
//  Off time
//
      strcpy(tempString, Tchar(RD[today].offTime[nI]));

      LVI.mask = LVIF_TEXT;
      LVI.iItem = iItem;
      LVI.iSubItem = 3;
      LVI.pszText = tempString;
      LVI.iItem = pListCtrlLIST->SetItem(&LVI);
//
//  Pay time
//
      strcpy(tempString, chhmm(RD[today].payTime[nI]));

      LVI.mask = LVIF_TEXT;
      LVI.iItem = iItem;
      LVI.iSubItem = 4;
      LVI.pszText = tempString;
      LVI.iItem = pListCtrlLIST->SetItem(&LVI);
    }
  }
//
//  Restore the cursor
//
  SetCursor(hSaveCursor);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}