UINT AfxRecalculateYield( int nDays, BOOL bReport ) { // 计算市场年平均收益率 double market_yield_average = 0.0, market_yield_d = 0.0; double market_dayyield_average = 0.0, market_dayyield_d = 0.0; CKData & kdayMain = AfxGetStockMain().GetKDataDay(); if( kdayMain.GetSize() <= nDays ) { if( bReport ) AfxMessageBox( IDS_RECALYIELD_NOSZZS, MB_OK | MB_ICONINFORMATION ); return 0; } BOOL bmarket_yield_ok = CalculateYieldYear( kdayMain, &market_yield_average, &market_yield_d, nDays ); BOOL bmarket_dayyield_ok = CalculateYieldDay( kdayMain, &market_dayyield_average, &market_dayyield_d, nDays ); if( !bmarket_yield_ok && !bmarket_dayyield_ok ) { if( bReport ) AfxMessageBox( IDS_RECALYIELD_NOSZZS, MB_OK | MB_ICONINFORMATION ); } // 开始生成结果数据 CStockContainer & container = AfxGetStockContainer(); int nCount = 0; // 等待对话框 CWaitDlg * pWait = NULL; if( bReport ) { pWait = new CWaitDlg( AfxGetMainWnd() ); pWait->SetProgressRange( 0, container.GetSize()-1 ); } for( int i=0; i<container.GetSize(); i++ ) { if( pWait ) { pWait->SetProgress( i ); if( pWait->WaitForCancel( ) ) break; } CStockInfo & info = container.ElementAt(i); LONG stocktype = info.GetType(); if( CStock::typeshIndex != stocktype && CStock::typeshA != stocktype && CStock::typeshB != stocktype && CStock::typeszIndex != stocktype && CStock::typeszA != stocktype && CStock::typeszB != stocktype ) continue; CStock stock; stock.SetStockInfo( &info ); AfxPrepareStockData(&AfxGetDB(),stock,CKData::ktypeDay,CKData::formatXDRup,CKData::mdtypeClose,TRUE,TRUE); CKData & kday = stock.GetKDataDay(); info.m_fYield_average = (float)STKLIB_DATA_INVALID; info.m_fYield_stddev = (float)STKLIB_DATA_INVALID; info.m_fBeite = (float)STKLIB_DATA_INVALID; double yield_average = 0., yield_d = 0., beite = 0. ; if( CalculateYieldYear( kday, &yield_average, &yield_d, nDays ) ) { info.m_fYield_average = (float)( 100. * yield_average ); info.m_fYield_stddev = (float)( 100. * yield_d ); if( bmarket_yield_ok && CalculateBeiteYear( kday, kdayMain, market_yield_average, market_yield_d, &beite, nDays ) ) info.m_fBeite = (float)( beite ); else if( bmarket_dayyield_ok && CalculateBeiteDay( kday, kdayMain, market_dayyield_average, market_dayyield_d, &beite, nDays ) ) info.m_fBeite = (float)( beite ); } else if( CalculateYieldDay( kday, &yield_average, &yield_d, nDays ) ) { info.m_fYield_average = (float)( 100. * (pow(1+yield_average,STKLIB_DAYS_INONEYEAR)-1) ); info.m_fYield_stddev = (float)( 100. * sqrt((double)STKLIB_DAYS_INONEYEAR) * yield_d ); if( bmarket_dayyield_ok && CalculateBeiteDay( kday, kdayMain, market_dayyield_average, market_dayyield_d, &beite, nDays ) ) info.m_fBeite = (float)( beite ); } nCount ++; } // 保存到硬盘文件 AfxGetDB().StoreBasetable( container ); // 关闭等待对话框和目标文件 if( pWait ) { pWait->DestroyWindow(); delete pWait; } return nCount; }
//--------------------------------------------------------------------------// //--------------------------------------------------------------------------// LRESULT CCtlPanel::OnPrint(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { if (m_pAGDoc) { AGDOCTYPE DocType = m_pAGDoc->GetDocType(); bool bSingleFold = (DocType == DOC_CARD_SINGLEFOLD_PORTRAIT || DocType == DOC_CARD_SINGLEFOLD_LANDSCAPE); PRINTDLG pd; memset(&pd, 0, sizeof(pd)); pd.lStructSize = sizeof(pd); pd.hwndOwner = GetParent(); pd.hDevMode = m_hDevMode; pd.hDevNames = m_hDevNames; pd.hInstance = _Module.GetResourceInstance(); pd.lCustData = (DWORD) &bSingleFold; pd.lpfnPrintHook = PrintHookProc; pd.lpPrintTemplateName = MAKEINTRESOURCE(PRINTDLGORD); pd.Flags = PD_ENABLEPRINTTEMPLATE | PD_ENABLEPRINTHOOK; if (PrintDlg(&pd)) { DEVNAMES *pDevNames = (DEVNAMES *) GlobalLock(pd.hDevNames); DEVMODE *pDevMode = (DEVMODE *) GlobalLock(pd.hDevMode); char *pszDriver = ((char *) pDevNames) + pDevNames->wDriverOffset; char *pszDevice = ((char *) pDevNames) + pDevNames->wDeviceOffset; char *pszOutput = ((char *) pDevNames) + pDevNames->wOutputOffset; int nDuplex; if (! GetRegistryDuplex(pszDevice, nDuplex)) nDuplex = -1; if (bSingleFold && nDuplex == -1) { CDblSideIntro Intro; CDblSideStep1 Step1; CDblSideStep2 Step2; CDblSideEnd End; PROPSHEETPAGE *pPropPages = new PROPSHEETPAGE[4]; pPropPages[0] = Intro.m_psp; pPropPages[1] = Step1.m_psp; pPropPages[2] = Step2.m_psp; pPropPages[3] = End.m_psp; Intro.m_pszDriver = Step1.m_pszDriver = pszDriver; Intro.m_pszDevice = Step1.m_pszDevice = pszDevice; Intro.m_pszOutput = Step1.m_pszOutput = pszOutput; Intro.m_pDevMode = Step1.m_pDevMode = pDevMode; PROPSHEETHEADER psh; psh.dwSize = sizeof(PROPSHEETHEADER); psh.dwFlags = PSH_WIZARD | PSH_PROPSHEETPAGE; psh.hwndParent = GetParent(); psh.hInstance = NULL; psh.hIcon = NULL; psh.pszCaption = NULL; psh.nPages = 4; psh.nStartPage = 0; psh.ppsp = pPropPages; psh.pfnCallback = NULL; ::PropertySheet(&psh); if (End.IsFinished()) { nDuplex = Step2.GetSelected(); SetRegistryDuplex(pszDevice, nDuplex); } delete [] pPropPages; } if (!(bSingleFold && nDuplex == -1)) { CWaitDlg WaitDlg; WaitDlg.Create(GetParent()); WaitDlg.UpdateWindow(); MSG msg; while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } bool bRotated; int nCopies = pd.nCopies; while (nCopies-- > 0) { if (bSingleFold) { m_pAGDoc->PrintCardSingle(PRINT_OUTSIDE, pszDriver, pszDevice, pszOutput, pDevMode, bRotated); } else { m_pAGDoc->PrintCardQuarter(pszDriver, pszDevice, pszOutput, pDevMode); } } WaitDlg.DestroyWindow(); if (bSingleFold) { char szFace[10]; if (nDuplex > 2) lstrcpy(szFace, "UP"); else lstrcpy(szFace, "DOWN"); DWORD dwOrientation = ::DeviceCapabilities(pszDevice, pszOutput, DC_ORIENTATION, NULL, pDevMode); bool bHorz = (DocType == DOC_CARD_SINGLEFOLD_LANDSCAPE || DocType == DOC_CARD_QUARTERFOLD_LANDSCAPE); if (!bHorz && dwOrientation == 270) bRotated = !bRotated; char szDirection[15]; int nDirection = PaperDirection[nDuplex % 2][bHorz][bRotated]; if (nDirection == 1) lstrcpy(szDirection, "AWAY FROM"); else lstrcpy(szDirection, "TOWARD"); char szMsg[256]; wsprintf(szMsg, "To print the inside of your card, reinsert the page with the printed side %s\nand the front panel of the card %s the printer.\n\n\nClick OK when you are ready to print the inside.", szFace, szDirection); if (MessageBox(szMsg, "Print inside", MB_OKCANCEL) == IDOK) { WaitDlg.Create(GetParent()); WaitDlg.UpdateWindow(); MSG msg; while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } nCopies = pd.nCopies; while (nCopies-- > 0) { m_pAGDoc->PrintCardSingle(PRINT_INSIDE, pszDriver, pszDevice, pszOutput, pDevMode, bRotated); } WaitDlg.DestroyWindow(); } } } GlobalUnlock(pd.hDevNames); GlobalUnlock(pd.hDevMode); } m_hDevMode = pd.hDevMode; m_hDevNames = pd.hDevNames; m_pMainWnd->SetFocus(); } return (TRUE); }