📄 treenode.cpp
字号:
pNode = pTreeNode->RightNode();
if( pNode )
{
while( !stack.IsEmptyStack() || pNode )
{
if( pNode )
{
stack.PushTreeNode( pNode );
if( pNode->IsAgent() ) lCount ++;
pNode = pNode->LeftNode();
}
else
{
pNode = stack.PopTreeNode()->RightNode();
}
}
}
return lCount;
}
int CTwoForkTree::CalcSupervisePrize(CString strStartDate, CString strEndDate, CListCtrl *pListCtrl)
{
int nCount = 0;
int nSubsidy = 0;
int nAegis = 0;
int nWelfare = 0;
int nLeftAgentCount = 0;
int nRightAgentCount = 0;
CTreeNode * pNode = NULL;
CStack stack;
CString strTmp;
pListCtrl->DeleteAllItems();
pNode = m_pTreeNode;
if( pNode )
{
while( !stack.IsEmptyStack() || pNode )
{
if( pNode )
{
stack.PushTreeNode( pNode );
nLeftAgentCount = LeftAgentCount( pNode );
nRightAgentCount = RightAgentCount( pNode );
if( nLeftAgentCount > 0 && nRightAgentCount > 0 )
{
nSubsidy = Subsidy( strStartDate, strEndDate, pNode );
nAegis = Aegis( strStartDate, strEndDate, pNode );
nWelfare = Welfare( strStartDate, strEndDate, pNode );
pListCtrl->InsertItem( nCount, pNode->m_strCode, 0 );
pListCtrl->SetItemData( nCount, pNode->m_lSequence );
pListCtrl->SetItemText( nCount, 1, pNode->m_strName );
strTmp.Format( "%.2f", ((double)nSubsidy) / 100 );
pListCtrl->SetItemText( nCount, 2, strTmp );
strTmp.Format( "%.2f", ((double)nAegis) / 100 );
pListCtrl->SetItemText( nCount, 3, strTmp );
strTmp.Format( "%.2f", ((double)nWelfare) / 100 );
pListCtrl->SetItemText( nCount, 4, strTmp );
nCount ++;
}
pNode = pNode->LeftNode();
}
else
{
pNode = stack.PopTreeNode()->RightNode();
}
}
}
return nCount;
}
// 督导津贴
int CTwoForkTree::Subsidy(CString strStartDate, CString strEndDate, CTreeNode *pTreeNode, int nPer)
{
int nSum = 0;
int nLeftAgentCount = 0;
int nRightAgentCount = 0;
CTreeNode * pNode = NULL;
CStack stack;
CString strTmp;
if( pTreeNode )
{
pNode = pTreeNode->LeftNode();
if( pNode )
{
while( !stack.IsEmptyStack() || pNode )
{
if( pNode )
{
if( pNode->IsAgent() )
nSum += AgentRetail( pNode->m_lAgent, strStartDate, strEndDate ) * nPer / 100;
if( !pNode->IsPlugger() ) // 不是宣传员
{
pNode = stack.PopTreeNode();
if( pNode ) pNode = pNode->RightNode();
}
else // 否则
{
nLeftAgentCount = LeftAgentCount( pNode );
nRightAgentCount = RightAgentCount( pNode );
if( !nLeftAgentCount && !nRightAgentCount )
{
pNode = stack.PopTreeNode();
if( pNode ) pNode = pNode->RightNode();
}
else
{
stack.PushTreeNode( pNode );
pNode = pNode->LeftNode();
}
}
}
else
{
pNode = stack.PopTreeNode()->RightNode();
}
}
}
pNode = pTreeNode->RightNode();
if( pNode )
{
stack.ClearStack();
while( !stack.IsEmptyStack() || pNode )
{
if( pNode )
{
if( pNode->IsAgent() )
nSum += AgentRetail( pNode->m_lAgent, strStartDate, strEndDate ) * nPer / 100;
if( !pNode->IsPlugger() ) // 不是宣传员
{
pNode = stack.PopTreeNode();
if( pNode ) pNode = pNode->RightNode();
}
else // 否则
{
nLeftAgentCount = LeftAgentCount( pNode );
nRightAgentCount = RightAgentCount( pNode );
if( !nLeftAgentCount && !nRightAgentCount )
{
pNode = stack.PopTreeNode();
if( pNode ) pNode = pNode->RightNode();
}
else
{
stack.PushTreeNode( pNode );
pNode = pNode->LeftNode();
}
}
}
else
{
pNode = stack.PopTreeNode()->RightNode();
}
}
}
}
return nSum;
}
// 品牌维护费
int CTwoForkTree::Aegis(CString strStartDate, CString strEndDate, CTreeNode *pTreeNode)
{
int i = 0, j = 0, k = 0;
int nSum = 0;
int nCount = 0, nCountOne = 0, nCountTwo = 0;
CTreeNode * pNode = NULL;
CTreeNode * pNodeOne = NULL;
CTreeNode * pNodeTwo = NULL;
CStack stack;
CString strTmp;
CPtrArray ptrArray;
CPtrArray ptrArrayOne;
CPtrArray ptrArrayTwo;
if( pTreeNode )
{
pNode = pTreeNode->LeftNode();
LeftOneGradeArray( ptrArray, pNode ); // 左子树下一层平级结点
nCount = ptrArray.GetSize();
for( i = 0; i < nCount; i ++ ) // 品牌维护费第一层平级 ( 左子树 )
{
pNode = (CTreeNode *)ptrArray.GetAt( i );
nSum += Subsidy( strStartDate, strEndDate, pNode, 1 );
LeftOneGradeArray( ptrArrayOne, pNode );
nCountOne = ptrArrayOne.GetSize();
for( j = 0; j < nCountOne; j ++ ) // 品牌维护费第二层平级 ( 左子树 )
{
pNodeOne = (CTreeNode *)ptrArrayOne.GetAt( j );
nSum += Subsidy( strStartDate, strEndDate, pNodeOne, 1 );
LeftOneGradeArray( ptrArrayTwo, pNodeOne );
nCountTwo = ptrArrayTwo.GetSize();
for( k = 0; k < nCountTwo; k ++ ) // 品牌维护费第三层平级 ( 左子树 )
{
pNodeTwo = (CTreeNode *)ptrArrayTwo.GetAt( k );
nSum += Subsidy( strStartDate, strEndDate, pNodeTwo, 1 );
}
RightOneGradeArray( ptrArrayTwo, pNodeOne );
nCountTwo = ptrArrayTwo.GetSize();
for( k = 0; k < nCountTwo; k ++ ) // 品牌维护费第三层平级 ( 右子树 )
{
pNodeTwo = (CTreeNode *)ptrArrayTwo.GetAt( k );
nSum += Subsidy( strStartDate, strEndDate, pNodeTwo, 1 );
}
}
RightOneGradeArray( ptrArrayOne, pNode );
nCountOne = ptrArrayOne.GetSize();
for( j = 0; j < nCountOne; j ++ ) // 品牌维护费第二层平级 ( 右子树 )
{
pNodeOne = (CTreeNode *)ptrArrayOne.GetAt( j );
nSum += Subsidy( strStartDate, strEndDate, pNodeOne, 1 );
LeftOneGradeArray( ptrArrayTwo, pNodeOne );
nCountTwo = ptrArrayTwo.GetSize();
for( k = 0; k < nCountTwo; k ++ ) // 品牌维护费第三层平级 ( 左子树 )
{
pNodeTwo = (CTreeNode *)ptrArrayTwo.GetAt( k );
nSum += Subsidy( strStartDate, strEndDate, pNodeTwo, 1 );
}
RightOneGradeArray( ptrArrayTwo, pNodeOne );
nCountTwo = ptrArrayTwo.GetSize();
for( k = 0; k < nCountTwo; k ++ ) // 品牌维护费第三层平级 ( 右子树 )
{
pNodeTwo = (CTreeNode *)ptrArrayTwo.GetAt( k );
nSum += Subsidy( strStartDate, strEndDate, pNodeTwo, 1 );
}
}
}
pNode = pTreeNode->RightNode();
RightOneGradeArray( ptrArray, pNode ); // 右子树下一层平级结点
nCount = ptrArray.GetSize();
for( i = 0; i < nCount; i ++ ) // 品牌维护费第一层平级 ( 左子树 )
{
pNode = (CTreeNode *)ptrArray.GetAt( i );
nSum += Subsidy( strStartDate, strEndDate, pNode, 1 );
LeftOneGradeArray( ptrArrayOne, pNode );
nCountOne = ptrArrayOne.GetSize();
for( j = 0; j < nCountOne; j ++ ) // 品牌维护费第二层平级 ( 左子树 )
{
pNodeOne = (CTreeNode *)ptrArrayOne.GetAt( j );
nSum += Subsidy( strStartDate, strEndDate, pNodeOne, 1 );
LeftOneGradeArray( ptrArrayTwo, pNodeOne );
nCountTwo = ptrArrayTwo.GetSize();
for( k = 0; k < nCountTwo; k ++ ) // 品牌维护费第三层平级 ( 左子树 )
{
pNodeTwo = (CTreeNode *)ptrArrayTwo.GetAt( k );
nSum += Subsidy( strStartDate, strEndDate, pNodeTwo, 1 );
}
RightOneGradeArray( ptrArrayTwo, pNodeOne );
nCountTwo = ptrArrayTwo.GetSize();
for( k = 0; k < nCountTwo; k ++ ) // 品牌维护费第三层平级 ( 右子树 )
{
pNodeTwo = (CTreeNode *)ptrArrayTwo.GetAt( k );
nSum += Subsidy( strStartDate, strEndDate, pNodeTwo, 1 );
}
}
RightOneGradeArray( ptrArrayOne, pNode );
nCountOne = ptrArrayOne.GetSize();
for( j = 0; j < nCountOne; j ++ ) // 品牌维护费第二层平级 ( 右子树 )
{
pNodeOne = (CTreeNode *)ptrArrayOne.GetAt( j );
nSum += Subsidy( strStartDate, strEndDate, pNodeOne, 1 );
LeftOneGradeArray( ptrArrayTwo, pNodeOne );
nCountTwo = ptrArrayTwo.GetSize();
for( k = 0; k < nCountTwo; k ++ ) // 品牌维护费第三层平级 ( 左子树 )
{
pNodeTwo = (CTreeNode *)ptrArrayTwo.GetAt( k );
nSum += Subsidy( strStartDate, strEndDate, pNodeTwo, 1 );
}
RightOneGradeArray( ptrArrayTwo, pNodeOne );
nCountTwo = ptrArrayTwo.GetSize();
for( k = 0; k < nCountTwo; k ++ ) // 品牌维护费第三层平级 ( 右子树 )
{
pNodeTwo = (CTreeNode *)ptrArrayTwo.GetAt( k );
nSum += Subsidy( strStartDate, strEndDate, pNodeTwo, 1 );
}
}
}
}
return nSum;
}
// 福利待遇
int CTwoForkTree::Welfare(CString strStartDate, CString strEndDate, CTreeNode *pTreeNode)
{
int nSum = 0;
int nLeftAgentCount = 0;
int nRightAgentCount = 0;
CTreeNode * pNode = pTreeNode;
CStack stack;
CString strTmp;
nLeftAgentCount = LeftAgentCount( pNode );
nRightAgentCount = RightAgentCount( pNode );
if( nLeftAgentCount >= 32 && nRightAgentCount >= 32 )
{
nSum += m_nCompanyRetail / 100;
}
if( nLeftAgentCount >= 64 && nRightAgentCount >= 64 )
{
nSum += m_nCompanyRetail / 100;
}
if( nLeftAgentCount >= 128 && nRightAgentCount >= 128 )
{
nSum += m_nCompanyRetail / 100;
}
return nSum;
}
// 代理商业绩
int CTwoForkTree::AgentRetail(int nAgent, CString strStartDate, CString strEndDate)
{
char szSQL[ 255 ];
CTabYJ tabyj;
CTabSP tabsp;
CString strTmp;
int nSumAcc = 0;
try
{
sprintf( szSQL, "where yjcdid = %d and yjjhsj between '%s' and '%s'", nAgent, strStartDate, strEndDate );
tabyj.Open( szSQL );
while( tabyj.IsOpen() && !tabyj.IsEOF() )
{
sprintf( szSQL, "where spspid = %s", tabyj.YJSPID.GetValue() );
tabsp.Open( szSQL );
nSumAcc += atoi( tabyj.YJJHSL.GetValue() ) * atoi( tabsp.SPDJDJ.GetValue() );
tabyj.MoveNext();
}
}
catch( _com_error &e )
{
strTmp = e.ErrorMessage();
}
catch( ... )
{
}
return nSumAcc;
}
int CTwoForkTree::CompanyRetail(CString strStartDate, CString strEndDate)
{
char szSQL[ 255 ];
CTabYJ tabyj;
CTabSP tabsp;
CString strTmp;
int m_nCompanyRetail = 0;
try
{
sprintf( szSQL, "where yjlsph = 1 and yjjhsj between '%s' and '%s'", strStartDate, strEndDate );
tabyj.Open( szSQL );
while( tabyj.IsOpen() && !tabyj.IsEOF() )
{
sprintf( szSQL, "where xcygid = %s", tabyj.YJSPID.GetValue() );
tabsp.Open( szSQL );
m_nCompanyRetail += atoi( tabyj.YJJHSL.GetValue() ) * atoi( tabsp.SPDJDJ.GetValue() );
tabyj.MoveNext();
}
}
catch( _com_error &e )
{
strTmp = e.ErrorMessage();
}
catch( ... )
{
}
return m_nCompanyRetail;
}
void CTwoForkTree::LeftOneGradeArray(CPtrArray &ptrArray, CTreeNode *pTreeNode)
{
int nLeftAgentCount = 0;
int nRightAgentCount = 0;
CTreeNode * pNode = NULL;
CStack stack;
CString strTmp;
ptrArray.RemoveAll();
if( pTreeNode )
{
pNode = pTreeNode->LeftNode();
while( !stack.IsEmptyStack() || pNode )
{
if( pNode )
{
if( !pNode->IsPlugger() ) // 不是宣传员
{
pNode = stack.PopTreeNode();
if( pNode ) pNode = pNode->RightNode();
}
else // 否则
{
nLeftAgentCount = LeftAgentCount( pNode );
nRightAgentCount = RightAgentCount( pNode );
if( !nLeftAgentCount && !nRightAgentCount )
{
ptrArray.Add( pNode );
pNode = stack.PopTreeNode();
if( pNode ) pNode = pNode->RightNode();
}
else
{
stack.PushTreeNode( pNode );
pNode = pNode->LeftNode();
}
}
}
else
{
pNode = stack.PopTreeNode()->RightNode();
}
}
}
}
void CTwoForkTree::RightOneGradeArray(CPtrArray &ptrArray, CTreeNode *pTreeNode)
{
int nLeftAgentCount = 0;
int nRightAgentCount = 0;
CTreeNode * pNode = NULL;
CStack stack;
CString strTmp;
ptrArray.RemoveAll();
if( pTreeNode )
{
pNode = pTreeNode->RightNode();
while( !stack.IsEmptyStack() || pNode )
{
if( pNode )
{
if( !pNode->IsPlugger() ) // 不是宣传员
{
pNode = stack.PopTreeNode();
if( pNode ) pNode = pNode->RightNode();
}
else // 否则
{
nLeftAgentCount = LeftAgentCount( pNode );
nRightAgentCount = RightAgentCount( pNode );
if( !nLeftAgentCount && !nRightAgentCount )
{
ptrArray.Add( pNode );
pNode = stack.PopTreeNode();
if( pNode ) pNode = pNode->RightNode();
}
else
{
stack.PushTreeNode( pNode );
pNode = pNode->LeftNode();
}
}
}
else
{
pNode = stack.PopTreeNode()->RightNode();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -