long NewGroupID(int parentID, CString text) { long lID=0; CTime time; time = CTime::GetCurrentTime(); try { //sqlite doesn't like single quotes ' replace them with double '' if(text.IsEmpty()) text = time.Format("NewGroup %y/%m/%d %H:%M:%S"); text.Replace(_T("'"), _T("''")); CString cs; cs.Format(_T("insert into Main (lDate, mText, lDontAutoDelete, bIsGroup, lParentID) values(%d, '%s', %d, 1, %d);"), (long)time.GetTime(), text, (long)time.GetTime(), parentID); theApp.m_db.execDML(cs); lID = (long)theApp.m_db.lastRowId(); } CATCH_SQLITE_EXCEPTION_AND_RETURN(0) return lID; }
bool CTime::SetLocalTime(const CTime &time_to_set) { #ifdef WIN32 int tmp_time = time_to_set.GetTime(); struct tm *tmp_tm = CTime::EibTime(&tmp_time); if (!tmp_tm) return false; SYSTEMTIME systemTime; systemTime.wDay = tmp_tm->tm_mday; systemTime.wMonth = tmp_tm->tm_mon + 1; systemTime.wYear = tmp_tm->tm_year + 1900; systemTime.wHour = tmp_tm->tm_hour; systemTime.wMinute = tmp_tm->tm_min; systemTime.wSecond = tmp_tm->tm_sec; systemTime.wMilliseconds = 0; if (!::SetLocalTime(&systemTime)) return false; return true; #else struct timeval tv = { (int)(time_to_set.GetTime()), 0 }; if (settimeofday(&tv, NULL) < 0) { perror("settimeofday"); return false; } return true; #endif }
void CDlgUserManager::OnBnClickedOk() { // TODO: 在此添加控件通知处理程序代码 //OnOK(); UpdateData(); if ( m_strEditUserName.IsEmpty() ) { AfxMessageBox(_T("用户名不能空")); return;} else if( m_strEditPwd.IsEmpty() ) { AfxMessageBox(_T("密码不能空")); return;} tagAddUpdateUserInfo user;ZeroMemory(&user,sizeof(user)); _tcscpy( user.szUserName,m_strEditUserName); _tcscpy( user.szPassWord,m_strEditPwd); _tcscpy( user.szCompanyName,m_strEditCompany); // COleDateTime ot; // ot.ParseDateTime(m_strEditRegTime); CTime ct; m_regTime.GetTime(ct); user.nRegTimeStamp = ct.GetTime(); m_expireDate.GetTime(ct); user.nExpireTimeStamp = ct.GetTime(); user.byPower = m_comPower.GetCurSel(); g_LogicClient.AddUpdateUserInfo(user); }
int XgnExtDataDlg::Transfer5MinTimet(int tmIn) { CTime tmNow (tmIn); CTime tmb (tmNow.GetYear (),tmNow.GetMonth (),tmNow.GetDay (),9,35,0); if(tmNow<tmb) return (int)tmb.GetTime (); CTimeSpan sp = tmNow-tmb; int nMinute = sp.GetMinutes (); int nRtn = nMinute%5==0?(nMinute/5):(nMinute/5+1); nRtn = nRtn*5*60 + tmb.GetTime (); return nRtn; }
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(); }
CDumpContext& AFXAPI operator <<(CDumpContext& dc, CTime time) { char psz[32]; psz[0] = '\0'; __time64_t tmp = time.GetTime(); errno_t err = _ctime64_s(psz, sizeof(psz), &tmp); if ((err != 0) || (psz[0] == '\0') || (time.GetTime() == 0)) { return dc << "CTime(invalid #" << time.GetTime() << ")"; } // format it return dc << "CTime(\"" << psz << "\")"; }
void CReqPlayerInfoProtocol::Process(UINT32 dwConnID) { CAckPlayerInfoProtocol ptcPlayerInfoAck; ptcPlayerInfoAck.m_strName = ""; ptcPlayerInfoAck.m_iRMB = 0; CPlayer *pPlayer = CPlayerMgr::Instance()->GetPlayerByConnID(dwConnID); if(pPlayer!=NULL) { CTime tm; tm=CTime::GetCurrentTime(); __time64_t now = tm.GetTime(); ptcPlayerInfoAck.m_TimeNow = now; ptcPlayerInfoAck.m_strName = pPlayer->GetName(); ptcPlayerInfoAck.m_iRMB = pPlayer->GetRMB(); ptcPlayerInfoAck.m_iGold = pPlayer->GetGold(); ptcPlayerInfoAck.m_iOil = pPlayer->GetOil(); ptcPlayerInfoAck.m_iPopulation = pPlayer->GetPopulation(); ptcPlayerInfoAck.m_oBuildings = pPlayer->GetBuildingDataVec(); pPlayer->GetBuilderDataToClient(ptcPlayerInfoAck.m_oBuilderDataToClient); pPlayer->GetLabData(ptcPlayerInfoAck.m_labdata); pPlayer->GetSoldierData(ptcPlayerInfoAck.m_SoldierData); pPlayer->GetCampDataToClient(ptcPlayerInfoAck.m_mapUniID2CampDataToClient); } CProtocolLogic * pProtocol = CProtocolLogic::GetProtocolLogic(); pProtocol->SetSendMsg(dwConnID,ptcPlayerInfoAck); //CClientLink::Instance()->Send(dwConnID, ptcPlayerInfoAck); }
CArchive& AFXAPI operator <<(CArchive& ar, CTime time) { // This version serializes 32 bits of invalid time and after 64 bits // time64. New code will support both 64 serialization and 32/64 deserialization. __time64_t ttime = time.GetTime(); ar << (DWORD)cTime64Mark; return ar << (__int64) ttime; }
bool CTime::SetLocalDate(const CTime &into_set) { #ifdef WIN32 SYSTEMTIME systemTime; int tmp_time = into_set.GetTime(); struct tm *tmp_tm = EibTime(&tmp_time); if (!tmp_tm) return false; systemTime.wDay = tmp_tm->tm_mday; systemTime.wMonth = tmp_tm->tm_mon + 1; systemTime.wYear = tmp_tm->tm_year + 1900; int now_t = static_cast<int>(time(0)); tmp_tm = EibTime(&now_t); if (!tmp_tm) return false; systemTime.wHour = tmp_tm->tm_hour; systemTime.wMinute = tmp_tm->tm_min; systemTime.wSecond = tmp_tm->tm_sec; systemTime.wMilliseconds = 0; if (!::SetLocalTime(&systemTime)) return false; return true; #else int tmp_time = into_set.GetTime(); int cur_time = time(NULL); struct tm tmp_tm; struct tm cur_tm; EIBTtime_r(&tmp_time, &tmp_tm); EIBTtime_r(&cur_time, &cur_tm); tmp_tm.tm_sec = cur_tm.tm_sec; tmp_tm.tm_min = cur_tm.tm_min; tmp_tm.tm_hour = cur_tm.tm_hour; struct timeval tv = { mktime(&tmp_tm), 0 }; if (settimeofday(&tv, NULL) < 0) { perror("settimeofday"); return false; } return true; #endif }
//006bc220 //gObjUseImprovePotion long CPeriodItemEx::GetExpireDate(int iDuration) //~OK { CTime tExpireTime; CTime tCurrentTime(CTime::GetTickCount()); CTimeSpan tLeftTime(0,0,0,iDuration); tExpireTime = tCurrentTime + tLeftTime; long tReturnTime = tExpireTime.GetTime(); return tReturnTime; }
// 遍历文件以及子文件夹,这里不处理子文件夹 bool CLogMgr::BrowseDir(const TCHAR *dir,const TCHAR *filespec) { // 遍历文件 CFileFind logFind; CString strDir = dir; strDir.Format(_T("%s\\%s"), dir, filespec); try { // 查找第一个文件 BOOL IsFinded=(BOOL)logFind.FindFile(strDir); while(IsFinded) { IsFinded=(BOOL)logFind.FindNextFile(); if(!logFind.IsDots()) { TCHAR foundFileName[_MAX_FILE_PATH]; memset(foundFileName, 0, _MAX_FILE_PATH); CString strFileName = logFind.GetFileName(); T_STRNCPY(foundFileName, strFileName.GetBuffer(_MAX_FILE_PATH), (_MAX_FILE_PATH - 1)); strFileName.ReleaseBuffer(); if(logFind.IsDirectory()) // 如果是目录不处理 { continue; } else // 查找到文件 { TCHAR filename[_MAX_FILE_PATH]; memset(filename, 0x00, _MAX_FILE_PATH*sizeof(TCHAR)); T_STRCPY(filename,dir); T_STRCAT(filename,foundFileName); CTime lastWriteTime; logFind.GetLastWriteTime(lastWriteTime); if (!ProcessFile(filename, (time_t)lastWriteTime.GetTime())) return false; } } } logFind.Close(); } catch (...) { return false; } return true; }
//*******************************************************************************************************/ //* FileName: clPlot.cpp //* //* Contents: Implementation of clPlot, axis, legend, serie and timeaxis //* //* NOTE 1: Only a minimum of parameter validation is implemented to save time since this plot is //* time critical. //* //* NOTE 2: All functionality is not fully implemented. //* //* Author: Jan Vidar Berger //*******************************************************************************************************/ //* 12.feb.98 Jan Vidar Berger Implemented flicker free drawing. Thanks to John Kim for providing //* the CGridMemDC and to Keith Rule, the author of CMemDC. //*******************************************************************************************************/ #include "stdafx.h" #include "clPlot.h" #include "GridMemDC.h" #include "malloc.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif long clPlot::m_lMaxDataPrSerie; // max allowed data pr. serie. long clPlot::m_lMaxDataTotal; // max allowed data total. //*******************************************************************************************************/ //* time axis threshold. contains grid and label intervals to be used within specified //* seconds pr. pixels thresholds. The array is terminated by a 'bIAmInUse'=FALSE. //*******************************************************************************************************/ struct{ BOOL bIAmInUse; // indicate valid entry, last=FALSE long lgridinterval; // grid line interval in seconds long llabelinterval; // time label interval in seconds long lmodethreshold; // mode threshold in seconds pr. pixel }gridsetting[]={ TRUE, 1, 4, 0, // 0: pr. second FALSE, 1, 1,0, // last entry in table }; //*******************************************************************************************************/ //* Function: serie::serie //*******************************************************************************************************/ serie::serie() { m_bIAmInUse = FALSE; m_color = RGB(0,0,0); m_iLineStyle = PS_SOLID; m_bRightAxisAlign = FALSE; m_lNoValues = 0; m_lbegin = 0; m_lend = 0; m_pvalues = NULL; } //*******************************************************************************************************/ //* Function: serie::~serie //*******************************************************************************************************/ serie::~serie() { if(m_pvalues !=NULL) free(m_pvalues); } //*******************************************************************************************************/ //* Function: serie::AddPoint //* //* Description: AddPoint add new data to the end of a data serie. It will simply append the data, //* update the list index and get out. //* //* This function will also call realloc or malloc to re-size or create the plot array as //* needed. //* //* The nice thing about circular lists is that they are multi thread enabled as is. You //* must however implement a syncronization mechanism if more than one thread is supposed //* to enter data into the plot. //* //* Parameters: valuetime Time (x value). //* y y value //* //* Return Value: -none- //* //* Author: Jan Vidar Berger //*******************************************************************************************************/ void serie::AddPoint(CTime &valuetime , double &y) { if(m_lNoValues > 0) m_pvalues = (value*)realloc(m_pvalues, (m_lNoValues+1)*sizeof(value)); else m_pvalues = (value*)malloc((m_lNoValues+1)*sizeof(value)); m_pvalues[m_lend].ValueTime = valuetime; m_pvalues[m_lend].dValue = y; m_lNoValues++; m_lend++; if(m_lend >= clPlot::m_lMaxDataPrSerie) m_lend=0; if(m_lbegin == m_lend){ m_lbegin++; if(m_lbegin >= clPlot::m_lMaxDataPrSerie) m_lbegin=0; } } //*******************************************************************************************************/ //* Function: serie::Reset //* //* Description: Reset the serie. Remove data and reset indexes and pointers. //* //* Parameters: -none- //* //* Return Value: -none- //* //* Author: Jan Vidar Berger //*******************************************************************************************************/ void serie::Reset() { m_lNoValues=0; if(m_pvalues !=NULL) free(m_pvalues); m_pvalues = NULL; m_lbegin = 0; m_lend = 0; } //*******************************************************************************************************/ //*******************************************************************************************************/ clPlot::clPlot() { m_ctlBkColor = RGB(255,255,255); m_plotBkColor = RGB(255,255,255); m_legendBkColor = RGB(255,255,255); m_gridColor = RGB(127,127,127); m_bctlBorder = TRUE; m_bplotBorder = TRUE; m_blegendBorder = TRUE; m_bPrimaryLegend = FALSE; m_bSecondaryLegend = FALSE; m_bAxisLY = TRUE; m_bAxisRY = TRUE; m_bAxisBX = TRUE; m_bAutoScrollX = FALSE; m_bSimMode = FALSE; m_lMaxDataPrSerie = 10000; m_lMaxDataTotal = 100000; m_dNoData = 0.0; m_dzoom = 1.0; lArraySize = 1000; // only points with differebt x,y will be put into the array pLineArray = new CPoint[lArraySize]; SetBXRange(CTime::GetCurrentTime()-CTimeSpan(60),CTime::GetCurrentTime()); m_logFont.lfHeight = -13; m_logFont.lfWidth = 0; m_logFont.lfEscapement = 0; m_logFont.lfOrientation = 0; m_logFont.lfWeight = 400; m_logFont.lfItalic = FALSE; m_logFont.lfUnderline = FALSE; m_logFont.lfStrikeOut = FALSE; m_logFont.lfCharSet = ANSI_CHARSET; m_logFont.lfOutPrecision = OUT_DEFAULT_PRECIS; m_logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; m_logFont.lfQuality = PROOF_QUALITY; m_logFont.lfPitchAndFamily = DEFAULT_PITCH; wcscpy(m_logFont.lfFaceName,_T("Ariel")); m_zoomFont.lfHeight = -13; m_zoomFont.lfWidth = 0; m_zoomFont.lfEscapement = 0; m_zoomFont.lfOrientation = 0; m_zoomFont.lfWeight = 400; m_zoomFont.lfItalic = FALSE; m_zoomFont.lfUnderline = FALSE; m_zoomFont.lfStrikeOut = FALSE; m_zoomFont.lfCharSet = ANSI_CHARSET; m_zoomFont.lfOutPrecision = OUT_DEFAULT_PRECIS; m_zoomFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; m_zoomFont.lfQuality = PROOF_QUALITY; m_zoomFont.lfPitchAndFamily = DEFAULT_PITCH; wcscpy(m_zoomFont.lfFaceName,_T("Ariel")); m_font.CreateFontIndirect(&m_zoomFont); } //*******************************************************************************************************/ //*******************************************************************************************************/ clPlot::~clPlot() { delete [] pLineArray; } //*******************************************************************************************************/ //*******************************************************************************************************/ BEGIN_MESSAGE_MAP(clPlot, CWnd) //{{AFX_MSG_MAP(clPlot) ON_WM_PAINT() //}}AFX_MSG_MAP END_MESSAGE_MAP() //*******************************************************************************************************/ //*******************************************************************************************************/ BOOL clPlot::Create(DWORD dwstyle, CRect &rect, CWnd *pParent, UINT id) { DWORD style = dwstyle & (~WS_BORDER); if(dwstyle & WS_BORDER) m_bctlBorder=TRUE; else m_bctlBorder=FALSE; if(!CWnd::Create(NULL, _T(""), style, rect, pParent, id, NULL)) return FALSE; m_ctlRect = rect; pParent->ClientToScreen(m_ctlRect); ScreenToClient(m_ctlRect); ComputeRects(TRUE); return TRUE; } //*******************************************************************************************************/ //* Function : clPlot::ComputeRects //* //* Description : Compute rects used for internal possitioning of different objects. This function is //* called when the plot is created or sized. //* //* Return type : void //* //* Parameter(s) : bInitialization indicate wherever parameters that can be changed abu the user //* also should be computed. //* //* Author : Jan Vidar Berger //*******************************************************************************************************/ void clPlot::ComputeRects(BOOL bInitialization) { // adjust the client rect for borders //GetClientRect(m_ctlRect); CClientDC dc(this); int w = 0; int n=0; CSize z=dc.GetTextExtent(CString("A")); // m_TextHeight = z.cy; m_dzoom = ((double)m_ctlRect.Height()/(double)z.cy) / 25.0; m_zoomFont.lfWidth = (int)(m_logFont.lfWidth * m_dzoom); m_zoomFont.lfHeight = (int)(m_logFont.lfHeight * m_dzoom); m_font.Detach(); m_font.CreateFontIndirect(&m_zoomFont); CFont *oFont = dc.SelectObject(&m_font); // SetFont(&m_font); z=dc.GetTextExtent(CString("A")); m_TextHeight = z.cy; if(m_bctlBorder){ m_clientRect.left = m_ctlRect.left+2; m_clientRect.right = m_ctlRect.right-2; m_clientRect.top = m_ctlRect.top+2; m_clientRect.bottom = m_ctlRect.bottom-2; }else{ m_clientRect = m_ctlRect; } if(bInitialization) { m_iMtop = m_iMbottom = m_clientRect.Height()/10; m_iMleft = m_iMright = m_clientRect.Width()/10; } // compute plot rect. m_plotRect.left = m_clientRect.left + m_iMleft; m_plotRect.right = m_clientRect.right - m_iMright; m_plotRect.top = m_clientRect.top + m_iMtop; m_plotRect.bottom = m_clientRect.bottom - m_iMbottom; // compute default legend possition if(bInitialization) { m_legendRect.left = m_plotRect.left + (m_iMleft/5); m_legendRect.right = m_plotRect.left + (m_plotRect.Width()/5); m_legendRect.top = m_plotRect.top - (m_iMtop/2); m_legendRect.bottom = m_plotRect.top + (m_iMtop); int w = 0; int n=0; for(int x = 0; x< MAXLEGENDS;x++){ if(m_primarylegends[x].m_bIAmInUse){ n++; z=dc.GetTextExtent(CString(m_primarylegends[x].m_szTitle)); if(z.cx > w ) w=z.cx; // m_TextHeight = z.cy; } } m_legendRect.right = m_legendRect.left + 40 + w; m_legendRect.bottom = m_legendRect.top + 10 + (m_TextHeight*n); } // compute left axis area m_axisLYRect.left = m_clientRect.left + (m_iMleft/5); m_axisLYRect.right = m_plotRect.left; m_axisLYRect.top = m_plotRect.top; m_axisLYRect.bottom = m_plotRect.bottom; // compute right axis area m_axisRYRect.left = m_plotRect.left; m_axisRYRect.right = m_clientRect.right - (m_iMright/5); m_axisRYRect.top = m_plotRect.top; m_axisRYRect.bottom = m_plotRect.bottom; // compute bottom axis area m_axisBXRect.left = m_plotRect.left; m_axisBXRect.right = m_plotRect.right; m_axisBXRect.top = m_plotRect.bottom; m_axisBXRect.bottom = m_clientRect.bottom - (m_iMbottom/5); // if(bInitialization) // { m_timeaxis.m_dSecondsPrPixel = ((double)(m_timeaxis.m_maxtime.GetTime() - m_timeaxis.m_mintime.GetTime())) / (double)m_plotRect.Width(); m_leftaxis.m_dValuePrPixel = ((double)(m_leftaxis.maxrange- m_leftaxis.minrange) / (double)m_plotRect.Height()); m_rightaxis.m_dValuePrPixel = ((double)(m_rightaxis.maxrange- m_rightaxis.minrange) / (double)m_plotRect.Height()); // } dc.SelectObject(oFont); } //*******************************************************************************************************/ //* Function: clPlot::OnPaint //* //* Description: This function will create a memory image, call Draw to draw the plot on it, and when //* copy the image into memory. //* //* This is fast and provides flicker free plot update. //* //* Author: Jan Vidar Berger //*******************************************************************************************************/ void clPlot::OnPaint() { CPaintDC dc(this); // device context for painting CGridMemDC pdc(&dc); // non flickering painting Draw(&pdc); // Do not call CWnd::OnPaint() for painting messages } BOOL clPlot::OnEraseBkgnd(CDC* pDC) { return FALSE; } //*******************************************************************************************************/ //*******************************************************************************************************/ void clPlot::Draw(CDC * dc) { CFont *oFont = dc->SelectObject(&m_font); DrawBasic(dc); DrawGrid(dc); DrawPlot(dc); DrawLegend(dc); dc->SelectObject(oFont); } //*******************************************************************************************************/ //*******************************************************************************************************/ void clPlot::DrawBasic(CDC * dc) { CBrush brushctlBkColor(m_ctlBkColor); dc->FillRect(m_ctlRect,&brushctlBkColor); if(m_bctlBorder) { dc->DrawEdge(m_ctlRect,BDR_SUNKENINNER|BDR_SUNKENOUTER, BF_RECT); } dc->Rectangle(m_plotRect); DrawLegendShadow(dc); } //*******************************************************************************************************/ //*******************************************************************************************************/ void clPlot::DrawPlot(CDC * dc) { for(int s=0;s<MAXSERIES;s++) { if(m_series[s].m_bIAmInUse) { DrawSerie(dc, s); } } } //*******************************************************************************************************/ //*******************************************************************************************************/ void clPlot::DrawSerie(CDC *dc,int s) { BOOL bMore=TRUE; BOOL bDraw; CPoint p; int ly; // lets get some serie parameters now and save the time of indexing during the loop long y = m_series[s].m_lbegin; long m = m_series[s].m_lend; long a = m_series[s].m_lNoValues; BOOL bRightAxis = m_series[s].m_bRightAxisAlign; CPen pen(m_series[s].m_iLineStyle, 1, m_series[s].m_color); CPen *old = dc->SelectObject(&pen); while(bMore){ bDraw=FALSE; bMore=FALSE; ly=0; while(y != m && !bDraw){ if(m_series[s].m_pvalues[y].dValue == m_dNoData) { bDraw = TRUE; bMore = TRUE; }else{ // Scaling. We do scaling inline to save some time time_t valuetime = m_series[s].m_pvalues[y].ValueTime.GetTime(); p.x = (int)(m_plotRect.left + ((valuetime-m_timeaxis.m_mintime.GetTime())/m_timeaxis.m_dSecondsPrPixel)); if(bRightAxis){ p.y = (int)(m_plotRect.bottom - ((m_series[s].m_pvalues[y].dValue-m_rightaxis.minrange)/m_rightaxis.m_dValuePrPixel)); }else{ p.y = (int)(m_plotRect.bottom - ((m_series[s].m_pvalues[y].dValue-m_leftaxis.minrange)/m_leftaxis.m_dValuePrPixel)); } if((ly == 0 || p.x != pLineArray[ly].x || p.y != pLineArray[ly].y) && (p.x >= m_plotRect.left && p.x <= m_plotRect.right)) { pLineArray[ly].x = p.x; pLineArray[ly].y = p.y; ly++; } } y++; if(y > a) // wrap list index ? y=0; } if(ly > 0){ dc->Polyline(pLineArray, ly); } } dc->SelectObject(old); } //*******************************************************************************************************/ //* //*******************************************************************************************************/ void clPlot::DrawGrid(CDC * dc) { DrawXAxisGrid(dc); DrawYAxisGrid(dc); } //*******************************************************************************************************/ //*******************************************************************************************************/ void clPlot::DrawYAxisGrid(CDC * dc) { double yGrid = m_leftaxis.minrange; double delta = 25.0 + (long)(((m_leftaxis.m_dValuePrPixel)))*25; if((long)delta%50 != 0 && delta > 20.0) delta +=25; double d10 = delta / 5.0; // todo: delta switch long diff = ((long)yGrid)%((long)delta); yGrid = yGrid - diff; CPen *old, pen(PS_SOLID, 1, m_gridColor); CPen stick(PS_SOLID,0,RGB(0,0,0)); CPen mline(PS_SOLID,0,RGB(192,192,192)); for( long sy = (long)((long)(m_leftaxis.minrange) - diff); sy < m_leftaxis.maxrange; sy+=(long)d10) { int off=3; if((long)sy%(long)delta == 0){ off=5; } if(sy > m_leftaxis.minrange){ int y = (int)(m_plotRect.bottom - ((sy-m_leftaxis.minrange)/m_leftaxis.m_dValuePrPixel)); old = dc->SelectObject(&stick); dc->MoveTo(CPoint(m_plotRect.left,y)); dc->LineTo(CPoint(m_plotRect.left-off,y)); dc->MoveTo(CPoint(m_plotRect.right,y)); dc->LineTo(CPoint(m_plotRect.right+off,y)); dc->SelectObject(old); old = dc->SelectObject(&mline); dc->MoveTo(CPoint(m_plotRect.left+1,y)); dc->LineTo(CPoint(m_plotRect.right-1,y)); dc->SelectObject(old); } } old = dc->SelectObject(&pen); while(yGrid <= m_leftaxis.maxrange) { double yy = m_plotRect.bottom - ((yGrid-m_leftaxis.minrange)/m_leftaxis.m_dValuePrPixel); int y = (int)yy; if(yGrid > m_leftaxis.minrange && yGrid<m_leftaxis.maxrange){ dc->MoveTo(CPoint(m_plotRect.left+1,y)); dc->LineTo(CPoint(m_plotRect.right-1,y)); } TCHAR b[100]; swprintf(b, _T("%.0f"), yGrid); dc->DrawText(b, CRect(m_clientRect.left, y-m_TextHeight/2,m_plotRect.left-5,y+m_TextHeight/2), DT_RIGHT|DT_BOTTOM); double yr = (m_plotRect.bottom - yy) * m_rightaxis.m_dValuePrPixel + m_rightaxis.minrange; swprintf(b, _T("%.0f"), yr); dc->DrawText(b, CRect(m_plotRect.right+5, y-m_TextHeight/2,m_clientRect.right,y+m_TextHeight/2), DT_LEFT|DT_BOTTOM); yGrid += delta; } dc->SelectObject(old); } //*******************************************************************************************************/ //*******************************************************************************************************/ void clPlot::DrawXAxisGrid(CDC * dc) { long yGrid = m_timeaxis.m_mintime.GetTime(); long delta = (long)(10.0 + (long)(((m_timeaxis.m_dSecondsPrPixel)))*10); long d10 = (long)(delta / 10.0); // todo: delta switch long diff = ((long)yGrid)%((long)delta); yGrid = yGrid - diff; CPen *old, pen(PS_SOLID, 1, m_gridColor); CPen stick(PS_SOLID,0,RGB(0,0,0)); CPen mline(PS_SOLID,0,RGB(192,192,192)); for( long sx = m_timeaxis.m_mintime.GetTime() - diff; sx < m_timeaxis.m_maxtime.GetTime(); sx+=d10) { int off=3; if((long)sx%(long)delta == 0){ off=5; } if(sx > m_timeaxis.m_mintime.GetTime()){ int x = (int)(m_plotRect.left + ((sx-m_timeaxis.m_mintime.GetTime())/m_timeaxis.m_dSecondsPrPixel)); // int x = m_plotRect.right - ((sx-m_timeaxis.m_mintime.GetTime())/m_timeaxis.m_lSecondsPrPixel); old = dc->SelectObject(&stick); dc->MoveTo(CPoint(x,m_plotRect.bottom)); dc->LineTo(CPoint(x+off,m_plotRect.bottom)); dc->SelectObject(old); old = dc->SelectObject(&mline); dc->MoveTo(CPoint(x,m_plotRect.bottom-1)); dc->LineTo(CPoint(x,m_plotRect.top+1)); dc->SelectObject(old); } } old = dc->SelectObject(&pen); while(yGrid <= m_timeaxis.m_maxtime.GetTime()) { int x = (int)(m_plotRect.left + ((yGrid-m_timeaxis.m_mintime.GetTime())/m_timeaxis.m_dSecondsPrPixel)); if(yGrid > m_timeaxis.m_mintime.GetTime() && yGrid<m_timeaxis.m_maxtime.GetTime()){ dc->MoveTo(CPoint(x,m_plotRect.bottom-1)); dc->LineTo(CPoint(x,m_plotRect.top+1)); } // char b[100]; // sprintf(b, "%.0f", yGrid); // dc->DrawText(b, CRect(m_clientRect.left, y-m_TextHeight/2,m_plotRect.left-5,y+m_TextHeight/2), DT_RIGHT|DT_BOTTOM); yGrid += delta; } dc->SelectObject(old); } //*******************************************************************************************************/ //*******************************************************************************************************/ void clPlot::DrawLegendShadow(CDC * dc) { if(m_blegendBorder){ CPen pen(PS_SOLID, 1, RGB(127,127,127)); CPen *oPen = dc->SelectObject(&pen); CBrush *oBrush , brush(RGB(127,127,127)); oBrush = dc->SelectObject(&brush); dc->Rectangle(CRect(m_legendRect.left+5,m_legendRect.top+5,m_legendRect.right+5, m_legendRect.bottom+5)); dc->SelectObject(oBrush); dc->SelectObject(oPen); } } //*******************************************************************************************************/ //*******************************************************************************************************/ void clPlot::DrawLegend(CDC * dc) { if(m_blegendBorder){ CPen pen(PS_SOLID, 1, RGB(0,0,0)); CPen *oPen = dc->SelectObject(&pen); CBrush *oBrush , brush(m_legendBkColor); oBrush = dc->SelectObject(&brush); dc->Rectangle(m_legendRect); dc->SelectObject(oBrush); dc->SelectObject(oPen); } int y = m_legendRect.top + 5; int dx = m_legendRect.left + (2*m_TextHeight); int mh = m_TextHeight/2; for(int x = 0; x< MAXLEGENDS;x++){ if(m_primarylegends[x].m_bIAmInUse){ CRect lRect( dx + 5, y, m_legendRect.right - 5, y + m_TextHeight); CPen pen(m_primarylegends[x].m_istyle, 1, m_primarylegends[x].m_color); CPen *oPen = dc->SelectObject(&pen); dc->MoveTo(CPoint(m_legendRect.left+5, y + mh)); dc->LineTo(CPoint(dx, y+mh)); dc->SelectObject(oPen); dc->DrawText(m_primarylegends[x].m_szTitle, lRect, DT_LEFT); y+=m_TextHeight+1; } } } //*******************************************************************************************************/ //* Function: clPlot::AddPoint //*******************************************************************************************************/ BOOL clPlot::AddPoint(int serie, CTime &valuetime, double &value) { if(m_series[serie].m_lNoValues < m_lMaxDataPrSerie){ m_series[serie].AddPoint(valuetime, value); if(m_bAutoScrollX && valuetime > m_timeaxis.m_maxtime){ time_t span = m_timeaxis.m_maxtime.GetTime() - m_timeaxis.m_mintime.GetTime(); time_t mintime = valuetime.GetTime() - span; SetBXRange(CTime(mintime), valuetime); } return TRUE; } return FALSE; }
void CTabpageLend::UpdateTimeLight(CString gunId) { vector<CBorrowRecord*> records; CBorrowLogManager::GetInstance().GetRecordByGunId(gunId, records); for (vector<CBorrowRecord*>::const_iterator iter = records.begin(); iter != records.end(); ++iter) { if ((*iter)->mEndTime == 0) { mCurrentRecord = *iter; break; } } __time64_t expectSeconds = 0; CTime now = CTime::GetCurrentTime(); if (mCurrentRecord){ expectSeconds = mCurrentRecord->mExpectTime; mCurrentRecord->mEndTime = now.GetTime(); } CTime expectTime(expectSeconds); mExpectDateCtrl.SetTime(&expectTime); mExpectTimeCtrl.SetTime(&expectTime); mEndDateCtrl.SetTime(&now); mEndTimeCtrl.SetTime(&now); if (expectTime.GetTime() > now.GetTime()) { HBITMAP hTimeLight = (HBITMAP)mBmpPass.GetSafeHandle(); mTimeLight.SetBitmap(hTimeLight); }else{ HBITMAP hTimeLight = (HBITMAP)mBmpFail.GetSafeHandle(); mTimeLight.SetBitmap(hTimeLight); } }
/** * get the modification date of the file * * @param fileName the file name * @param timeStamp the timestamp * @return TRUE if file exists, * else FALSE * @exception * @see */ BOOL CEFile::GetTimeStamp(LPCTSTR fileName, time_t* pTimeStamp) { CFileFind finder; BOOL bWorking = finder.FindFile(fileName); if (bWorking) { CTime refTime; bWorking = finder.FindNextFile(); finder.GetLastWriteTime( refTime ) ; *pTimeStamp = refTime.GetTime(); return TRUE; } else return FALSE; }
CTime GMTtoLocalTime( CTime CTgmt) { static boolean NotGotDiff = true; static time_t diff = 0; time_t gmt = CTgmt.GetTime(); if( NotGotDiff) { // Get GMT to Local time difference by looking at current time time_t Now = time(NULL); struct tm* TM = gmtime(&Now); CTime gmtNow(TM->tm_year+1900,TM->tm_mon+1,TM->tm_mday,TM->tm_hour,TM->tm_min,TM->tm_sec); diff = gmtNow.GetTime()-Now; NotGotDiff = false; } return CTime(gmt-diff); }
void TorrentCreator::WriteHashToDatabase(void) { TRACE( "Start updating bt_generator_maininfo database\n" ); CTime currentTime = CTime::GetCurrentTime(); m_pIPData->SetCreationTime( (time_t)currentTime.GetTime() ); DBInterface db; string torrentfilename = m_pIPData->GetTorrentFileName(); db.OpenConnection(IP_BITTORRENT_DATABASE, "onsystems", "ebertsux37", "bittorrent_data"); char aQuery[1024]; sprintf( aQuery, "UPDATE bt_generator_maininfo SET info_hash = '%s', generate='F', creation_date = %s WHERE auto_torrent_id = %u", GetHashString(m_pIPData->GetInfohash()).c_str(), currentTime.Format( "%Y%m%d%H%M%S" ), m_pIPData->GetTorrentID() ); int ret = db.executeQuery(aQuery); TRACE( "Done updating bt_generator_maininfo database\n" ); }
void CDailyOpsHO::OnRemove() { int nI = pListCtrlLIST->GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); if(nI < 0) { return; } long DAILYOPSrecordID = pListCtrlLIST->GetItemData(nI); CTime time = CTime::GetCurrentTime(); int rcode2; // // "Unregister" this previous record // rcode2 = btrieve(B_GETLAST, TMS_DAILYOPS, &DAILYOPS, &DAILYOPSKey0, 0); DAILYOPS.recordID = AssignRecID(rcode2, DAILYOPS.recordID); DAILYOPS.entryDateAndTime = time.GetTime(); DAILYOPS.pertainsToDate = NO_RECORD; DAILYOPS.pertainsToTime = NO_TIME; DAILYOPS.recordTypeFlag = (char)DAILYOPS_FLAG_DATE; DAILYOPS.recordFlags = DAILYOPS_FLAG_DATECLEAR; DAILYOPS.userID = m_UserID; DAILYOPS.DRIVERSrecordID = NO_RECORD; DAILYOPS.DAILYOPSrecordID = DAILYOPSrecordID; memset(DAILYOPS.DOPS.associatedData, 0x00, DAILYOPS_ASSOCIATEDDATA_LENGTH); rcode2 = btrieve(B_INSERT, TMS_DAILYOPS, &DAILYOPS, &DAILYOPSKey0, 0); if(rcode2 == 0) { m_LastDAILYOPSRecordID = DAILYOPS.recordID; } // // Kill the item from the list // pListCtrlLIST->DeleteItem(nI); // // Disable Remove and Update 'till he picks something // pButtonIDREMOVE->EnableWindow(FALSE); pButtonIDUPDATE->EnableWindow(FALSE); }
void SwarmerSourceDll::SetRegistryTimer() { CHAR reg_sub_key[] = TEXT("Software\\Swarmer\\TimeStamp"); HKEY hkey; CTime time; time_t curtime; curtime = (time_t)time.GetTime(); DWORD cbData = sizeof(curtime); if (RegCreateKeyEx(HKEY_CURRENT_USER,reg_sub_key,0,NULL,REG_OPTION_NON_VOLATILE,KEY_QUERY_VALUE|KEY_SET_VALUE,NULL,&hkey,NULL)==ERROR_SUCCESS) { //RegQueryValueEx(hkey,"DownloadDir",NULL,NULL,(unsigned char *)downloaddir,&cbData); RegSetValueEx(hkey,"timestamp",NULL,REG_DWORD,(unsigned char *)curtime,cbData); } }
// get a time for the current cache mode setting CTime GUrlCache::getRefreshTime() { switch (cacheMode) { case GCACHE_ONCE : return sessionTime; case GCACHE_ALWAYS: return CTime::GetCurrentTime(); case GCACHE_DAYS : { CTime current = CTime::GetCurrentTime(); //CTimeSpan duration( expirationDays, 0, 0, 0 ); //current -=duration; current = current.GetTime() - expirationDays * 24 * 60 * 60; return current; } default : return (0); } }
void COptionSet::OnSetTime() { // TODO: Add your control notification handler code here time_t ltime; CTime ct; ct = CTime::GetCurrentTime(); ltime = ct.GetTime(); NET_PACKET *netpacket;//启动DSP01 netpacket = (NET_PACKET *)malloc(sizeof(NET_PACKET)); if(netpacket==NULL){ AfxMessageBox("申请NET_PACKET空间出现异常!"); } netpacket->FrmID = UWACCMD_SETTIME; netpacket->FrmLen = 32; netpacket->DestID = PC104ID; netpacket->HeadParam[0] = (DWORD)ltime; netpacket->pData = NULL; m_WzdNetpacketList.AddTail(netpacket); SetEvent(IsNetpacketEvent); }
// is the file to old gbool GFileInfo::toOld(long days) { CTime current = CTime::GetCurrentTime(); // CTimeSpan duration( days, 0, 0, 0 ); // current -= days * 24 * 60 * 60; current = current.GetTime() - days * 24 * 60 * 60; CTime old (creationTime); #ifdef _DEBUG_X CString s = current.Format( "%A, %B %d, %Y" ); CString t = old.Format( "%A, %B %d, %Y" ); TRACE(" current %s prev %s \n",(const char *)s,(const char *)t); #endif return ( old < current); }
void CVersionChecker::SetNextCheck(int nDays) { CTimeSpan tPeriod( nDays, 0, 0, 0 ); CTime tNextCheck = CTime::GetCurrentTime() + tPeriod; theApp.WriteProfileInt( _T("VersionCheck"), _T("NextCheck"), (DWORD)tNextCheck.GetTime() ); }
//-------------------------------------------------------------------------------- void CCertificateMaster::SetLastRefresh(CTime ctTime) { ::InterlockedExchange(reinterpret_cast<long*>(&m_ctLastRefresh), ctTime.GetTime()); #pragma message("Rich says: this is old, pre-64-bit-world code!") }
CTime::CTime(const CTime& time) { _time_val = time.GetTime(); }
EIB_STD_EXPORT CTime operator+(const CTime& t1, const int t2) { CTime res(t1.GetTime() + t2); return res; }
EIB_STD_EXPORT CTime operator-(const CTime& t1, const CTime& t2) { CTime res(t1.GetTime() - t2.GetTime()); return res; }
bool CTime::operator<=(const CTime& time2) const { return (GetTime() <= time2.GetTime()); }
bool CTime::operator>(const CTime& time2) const { return (GetTime() > time2.GetTime()); }
void DDX_DateTimeCtrl(CDataExchange* pDX, int nIDC, CSPTime& value) { CTime tm = value.GetTime(); DDX_DateTimeCtrl(pDX, nIDC,tm); value = tm.GetTime(); }
BOOL TRAFFIC_MONITOR(char *server, int port, char *community, int ifindex, int timeout, int retrydelay, CString strMonitorID, char *custpath, char *szReturn) { int s; struct sockaddr_in serv; int i = 0, ret = 0; int count = 1; struct snval *ptmp = NULL; struct snval *ptmpnext = NULL; long ifOperStatus = 0; Gauge ifSpeed = 0; Counter ifInOctets = 0, ifOutOctets = 0; Counter ifInErrors = 0, ifOutErrors = 0; if((ret = MakeSocket(server, port, s, serv)) < 0) { if(ret == -1) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_Traffic_1%>")); else if(ret == -2) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_Traffic_2%>")); else sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_Traffic_3%>")); return FALSE; } struct oid *poid = NULL, *ptmpoid = NULL; oid ifInOctets_oid = {{0x2b, 6, 1, 2, 1, 2, 2, 1, 10}, 9}; oid ifOutOctets_oid = {{0x2b, 6, 1, 2, 1, 2, 2, 1, 16}, 9}; ifInOctets_oid.id[ifInOctets_oid.len++] = ifindex; poid = ptmpoid = &ifInOctets_oid; ifOutOctets_oid.id[ifOutOctets_oid.len++] = ifindex; ptmpoid->next = &ifOutOctets_oid; ptmpoid = ptmpoid->next; struct snval *psnval = NULL; if((ret = SN_VALUES(s, serv, community, 1, poid, &psnval)) < 0) { if(ret == -1) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_Dynamo_4%>"));//<%IDS_Dynamo_4%> else if(ret == -2) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_Dynamo_5%>"));//<%IDS_Dynamo_5%> else if(ret == -3) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_Dynamo_6%>"));//<%IDS_Dynamo_6%> else if(ret == -4) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_Dynamo_7%>"));//<%IDS_Dynamo_7%> else if(ret == -5) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_Dynamo_8%>"));//<%IDS_Dynamo_8%> else if(ret == -6) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_Dynamo_9%>"));//<%IDS_Dynamo_9%> else if(ret == -7) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_Dynamo_10%>"));//<%IDS_Dynamo_10%> else if(ret == -8) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_Dynamo_11%>"));//<%IDS_Dynamo_11%> else sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_Dynamo_12%>"));//<%IDS_Dynamo_12%> goto w; } ptmp = psnval; ptmpnext = NULL; while(ptmp) { switch(count) { case 1: switch(ptmp->sv_type) { case ASN1_INT: case ASN1_COUNTER: case ASN1_GAUGE: case ASN1_TIMETICKS: case ASN1_COUNTER64: case ASN1_UINTEGER32: ifInOctets = ptmp->sv_val.sv_int; break; default: ifInOctets = 0; break; } break; case 2: switch(ptmp->sv_type) { case ASN1_INT: case ASN1_COUNTER: case ASN1_GAUGE: case ASN1_TIMETICKS: case ASN1_COUNTER64: case ASN1_UINTEGER32: ifOutOctets = ptmp->sv_val.sv_int; break; default: ifOutOctets = 0; break; } break; } count ++; ptmp = ptmp->next; } // computer the traffic { char ciniFile[256] = {0}, cinifile[256] = {0}; char cifIndex[256] = {0}; sprintf(cinifile, "snmp_%s_%s.ini", server, strMonitorID); sprintf(ciniFile, "%s\\%s", custpath, cinifile); sprintf(cifIndex, "ifIndex_%ld", ifindex); long ifTime = 0; Counter inOctets = 0, outOctets = 0; CTime curTime = CTime::GetCurrentTime(); ifTime = DFN_GetPrivateProfileInt(cifIndex, "ifTime", -99, ciniFile); inOctets = DFN_GetPrivateProfileInt(cifIndex, "ifInOctets", -99, ciniFile); outOctets = DFN_GetPrivateProfileInt(cifIndex, "ifOutOctets", -99, ciniFile); if(ifTime == -99 || inOctets == -99 || outOctets == -99) { CString strSection = _T(""); strSection.Format("ifIndex_%ld", ifindex); curTime = CTime::GetCurrentTime(); CString strMsg = _T(""); strMsg.Format("%ld", curTime.GetTime()); ::DFN_WritePrivateProfileString((LPCTSTR)strSection, "ifTime", (LPCTSTR)strMsg, ciniFile); strMsg.Format("%ld", ifInOctets); ::DFN_WritePrivateProfileString((LPCTSTR)strSection, "ifInOctets", (LPCTSTR)strMsg, ciniFile); strMsg.Format("%ld", ifOutOctets); ::DFN_WritePrivateProfileString((LPCTSTR)strSection, "ifOutOctets", (LPCTSTR)strMsg, ciniFile); WriteLogFile(strMonitorID, "读配置文件失败"); } else { float ifInOctetsRate = 0.0, ifOutOctetsRate = 0.0; Counter InOctets = 0, OutOctets = 0; CTime bTime(ifTime); curTime = CTime::GetCurrentTime(); CTimeSpan spanTime = curTime - bTime; long lInterval = spanTime.GetTotalSeconds(); if(lInterval == 0) lInterval = 1; if(lInterval <= 12 * 60 * 60 && lInterval >= 0) { InOctets = (unsigned int)(ifInOctets - inOctets < 0 ? (COUNTER_MAX - inOctets + ifInOctets) : (ifInOctets - inOctets)); //ifInOctetsRate = (float)InOctets / lInterval; //k ifInOctetsRate = (float)InOctets / lInterval/1024; OutOctets = (unsigned int)(ifOutOctets - outOctets < 0 ? (COUNTER_MAX - outOctets + ifOutOctets) : (ifOutOctets - outOctets)); // wang peng /1024 =k //Edit By Kevin.Yang PM: 14:55 2004.10.21 //Reason: 根据张鹏所提供的资料目前Cisio的MIF库中单位为KB,因此在 //得到的数据后不再需要除以1024 ifOutOctetsRate = (float)OutOctets / lInterval /1024; //ifOutOctetsRate = (float)OutOctets / lInterval; sprintf(szReturn, "ifIndex=%ld$ifInOctetsRate=%.2f$ifOutOctetsRate=%.2f$", ifindex, ifInOctetsRate * 8, ifOutOctetsRate * 8); } else { CString strLog; strLog.Format("时间总秒数%d", lInterval); // WriteLogFile(strMonitorID, strLog); } // WriteLogFile(strMonitorID, szReturn); //if(strlen(szReturn) == 0) //{ // printf("%d年%d月%d日 %d时%d分%d秒 \n%d年%d月%d日 %d时%d分%d秒 \n", // curTime.GetYear(), curTime.GetMonth(), curTime.GetDay(), // curTime.GetHour(), curTime.GetMinute(), curTime.GetSecond(), // bTime.GetYear(), bTime.GetMonth(), bTime.GetDay(), // bTime.GetHour(), bTime.GetMinute(), bTime.GetSecond()); //} char buff[256] = {0}; memset(buff, 0, 256); ltoa(curTime.GetTime(), buff, 10); DFN_WritePrivateProfileString(cifIndex, "ifTime", buff, ciniFile); memset(buff, 0, 256); ltoa(ifInOctets, buff, 10); DFN_WritePrivateProfileString(cifIndex, "ifInOctets", buff, ciniFile); memset(buff, 0, 256); ltoa(ifOutOctets, buff, 10); DFN_WritePrivateProfileString(cifIndex, "ifOutOctets", buff, ciniFile); } } w: ptmp = psnval; if(ptmp) ptmpnext = ptmp->next; while(ptmp) { free(ptmp); ptmp = ptmpnext; if(ptmp) ptmpnext = ptmp->next; } return !ret; }