Example #1
0
void CDlgStrategyHQ::OnOK() 
{
	if( m_pData == NULL )
		goto _Exit;
	CDlgFormulaMan* pParentDlg  = (CDlgFormulaMan*)AfxGetMainWnd();
	if( pParentDlg == NULL )
		goto _Exit;

	CTreeCtrlFormula* pCurTree = m_wndTab.GetTree();
	if( !pCurTree )
		goto _Exit;
	HTREEITEM hItem = pCurTree->GetSelectedItem();
	if( hItem == NULL )
		goto _Exit;

	CTreeGroup* pTreeGroup = (CTreeGroup*)pCurTree->GetItemData(hItem);
	if( (pTreeGroup == NULL)			|| 
		(pTreeGroup->GetData() == NULL) ||
		!pTreeGroup->IsStatus(hx_GroupItem) )
		goto _Exit;

	if(m_pData->m_wType & hxShowByExpressType)
	{
		CString csCode,csCycle,csBuyTimes,csSellTimes,csTriggertime,csTriggerNum,csGap;
		int buyTimes,sellTimes,trigTime,trigNum,gap, perType,perNum;
		m_wndCode.GetWindowText(csCode);//股票代码
		m_wndCycle.GetWindowText(csCycle);
		m_wndBuyTimes.GetWindowText(csBuyTimes);
		m_wndSellTimes.GetWindowText(csSellTimes);
		m_wndTriggerTime.GetWindowText(csTriggertime);
		m_wndTrigerNum.GetWindowText(csTriggerNum);
		m_wndGap.GetWindowText(csGap);
		if(csCode.IsEmpty())
		{
			::MessageBox( m_hWnd,_T(" 请填写代码! "),_T(" 提示 "), MB_OK);
			m_wndCode.SetFocus();
			return ;
		}
		if(csCycle.IsEmpty() || csCycle == "多日线")
		{
			if (csCycle.IsEmpty())
			{
				::MessageBox( m_hWnd,_T(" 请选择分析周期! "),_T(" 提示 "), MB_OK);
				m_wndCycle.SetFocus();
				return ;
			}
			CString cs;
			m_wndDay.GetWindowText(cs);
			if (cs.IsEmpty() || atoi(cs) <= 0)
			{
				::MessageBox( m_hWnd,_T(" 请填写多日天数! "),_T(" 提示 "), MB_OK);
				m_wndDay.SetFocus();
				return ;
			}
			perType = AnalisysForMoreDay;
			perNum = atoi(cs);
		}
		else
		{
			if (csCycle == "1分钟")
			{
				perType = AnalisysFor1;
				perNum = 0;
			}
			else if (csCycle == "5分钟")
			{
				perType = AnalisysFor5;
			}
			else if (csCycle == "15分钟")
			{
				perType = AnalisysFor15;
			}
			else if (csCycle == "30分钟")
			{
				perType = AnalisysFor30;
			}
			else if (csCycle == "60分钟")
			{
				perType = AnalisysFor60;
			}
			else if (csCycle == "日线")
			{
				perType = AnalisysForDay;
			}
			else if (csCycle == "周线")
			{
				perType = AnalisysForWeek;
			}
			else if (csCycle == "月线")
			{
				perType = AnalisysForMonth;
			}
			perNum = 0;
		}
		if(csBuyTimes.IsEmpty())
		{
			::MessageBox( m_hWnd,_T(" 请填写买入次数! "),_T(" 提示 "), MB_OK);
			m_wndBuyTimes.SetFocus();
			return ;
		}
		if(csSellTimes.IsEmpty())
		{
			::MessageBox( m_hWnd,_T(" 请填写卖出次数! "),_T(" 提示 "), MB_OK);
			m_wndSellTimes.SetFocus();
			return ;
		}
		if(csTriggertime.IsEmpty())
		{
			::MessageBox( m_hWnd,_T(" 请填写持续多少秒触发! "),_T(" 提示 "), MB_OK);
			m_wndTriggerTime.SetFocus();
			return ;
		}
		if(csTriggerNum.IsEmpty())
		{
			::MessageBox( m_hWnd,_T(" 请填写几次达标后触发! "),_T(" 提示 "), MB_OK);
			m_wndTrigerNum.SetFocus();
			return ;
		}
		strcpy(m_pStrategy->m_cCode,csCode);
		buyTimes = atoi(csBuyTimes);
		if(buyTimes < -1 || buyTimes > SHORT_MAX)//
		{
			::MessageBox( m_hWnd,_T(" 请正确填写买入次数! "),_T(" 提示 "), MB_OK);
			m_wndBuyTimes.SetFocus();
			return ;
		}
		sellTimes = atoi(csSellTimes);
		if( sellTimes < -1 || sellTimes > SHORT_MAX)//
		{
			::MessageBox( m_hWnd,_T(" 请正确填写卖出次数! "),_T(" 提示 "), MB_OK);
			m_wndSellTimes.SetFocus();
			return ;
		}	
		trigTime = atoi(csTriggertime);
		if (trigTime < -1 || trigTime > SHORT_MAX)//
		{
			::MessageBox( m_hWnd,_T(" 请正确填写持续多少秒触发! "),_T(" 提示 "), MB_OK);
			m_wndTriggerTime.SetFocus();
			return ;
		}	
		trigNum = atoi(csTriggerNum);
		if (trigNum < -1 || trigNum > SHORT_MAX)//
		{
			::MessageBox( m_hWnd,_T(" 请正确填写几次达标后触发! "),_T(" 提示 "), MB_OK);
			m_wndTrigerNum.SetFocus();
			return ;
		}	
		gap = atoi(csGap);
		if( gap < -1 || gap > SHORT_MAX)//
		{
			::MessageBox( m_hWnd,_T(" 请正确填写连续委托间隔! "),_T(" 提示 "), MB_OK);
			m_wndGap.SetFocus();
			return ;	
		}
		m_pStrategy->m_nPeriodType = perType;
		m_pStrategy->m_nPeriodNumber = perNum;
		m_pStrategy->m_nMaxBuyTimes = buyTimes;
		m_pStrategy->m_nMaxSellTimes = sellTimes;
		m_pStrategy->m_nTrigTimes = trigTime;
		m_pStrategy->m_nMaxTrigTimes = trigNum;
		m_pStrategy->m_nGap = gap;
		if(m_pStrategy->m_nGap == 0)//默认为30秒
		{
			m_pStrategy->m_nGap = 30;
		}
		if (m_wndCheck.GetCheck())
		{
			m_pStrategy->m_bFuQuan = 0;
		}
		else
		{
			m_pStrategy->m_bFuQuan = 1;
		}
		if (m_wndXD.GetCheck())
		{
			m_pStrategy->m_bXD = 1;
		}
		else
		{
			m_pStrategy->m_bXD = 0;
		}
		if (m_pStrategy->m_pData == NULL)
		{
			m_pStrategy->m_pData = new CLineProperty;
		}
		if (!m_pStrategy->m_pData->m_pCurVal)
		{
			m_pStrategy->m_pData->m_pCurVal = new CExpValue;
		}
		//只保存公式名和变量
		CExpression *pNew;
		if (!((CExpValue*)(m_pStrategy->m_pData->m_pCurVal))->GetExp())
		{
			pNew = new CExpression;
		}
 		else
			pNew = ((CExpValue*)(m_pStrategy->m_pData->m_pCurVal))->GetExp();
		CExpression *pTreeExp = pTreeGroup->GetData();
		if (pTreeExp)//复制参数值
		{
			CMapVariabile *pMv = pTreeExp->GetParamVar();
			//----------------------------------------------
			if (pMv)
			{
				CMapVariabile *pMap = new CMapVariabile;
				CString key;
				CValue *cvalue;
				POSITION pos;
				pos = pMv->GetStartPosition();
				while(pos)
				{
					pMv->GetNextAssoc(pos,key,cvalue);
					CNumericValue *pnum = new CNumericValue;
					double db = cvalue->GetValue();
					pnum->SetValue(db);
					pnum->SetStyle(cvalue->GetStyle());
					pnum->SetMaxValue(((CNumericValue*)cvalue)->GetMaxValue());
					pnum->SetMinValue(((CNumericValue*)cvalue)->GetMinValue());
					pnum->SetTestStepValue(((CNumericValue*)cvalue)->GetTestStepValue());
					pnum->SetDescribe(((CNumericValue*)cvalue)->GetDescribe());
					pMap->SetAt(key,pnum);
				}
				//===============================================================
				pNew->SetParamVar(pMap);//存储变量值
			}
			memcpy(m_pStrategy->m_sExpName,pTreeExp->GetName(),32);//存储公式名
		}
		((CExpValue*)(m_pStrategy->m_pData->m_pCurVal))->SetValue(pNew);
	}
	CWnd* pwnd = GetParent();
	if (pwnd && pwnd->IsKindOf(RUNTIME_CLASS(CDlgStrategyMain)))
	{
		CDlgStrategyMain *pMain = (CDlgStrategyMain*)pwnd;
		pMain->m_bHQOK = TRUE;
	}
	OnCancel();
	return ;

_Exit:
	::MessageBox( m_hWnd,_T(" 请选择一个公式! "),_T(" 提示 "), MB_OK);
	return ;
}