📄 mrpcalc.cpp
字号:
// MRPCalc.cpp : Implementation of CMRPCalc
#include "stdafx.h"
#include "Mrpcom.h"
#include "MRPCalc.h"
bool CBaseDB::Cnn_ERR;
_ConnectionPtr CBaseDB::pDBCnn;
/////////////////////////////////////////////////////////////////////////////
// CMRPCalc
STDMETHODIMP CMRPCalc::AddOrder(long argOrderID)
{
// TODO: Add your implementation code here
long lNodeID;
CalcNode *pNode1,*pNode2;
/*
RqMtrl *pMtrl1,*pMtrl2;
RqSeq *pSeq1,*pSeq2,*pSeq3;
*/
if (argOrderID<=0 )
{
m_OprtOK=false;
return S_OK;
}
pOrder->GetOrder(argOrderID);
if (pOrder->Cls_ERR==true)
{
m_OprtOK=false;
return S_OK;
}
lNodeID=pPrd->getMtrl(pOrder->MtrlID);
if (pPrd->Cls_ERR==true)
{
m_OprtOK=false;
return S_OK;
}
pNode1=new CalcNode;
pNode1->MtrlID=pPrd->MtrlID;
pNode1->NodeID=lNodeID;
pNode1->OrderID=argOrderID;
pNode1->PrvdQty=pOrder->Qty;
pNode1->RqQty=pOrder->Qty;
// pNode1->RqQty=-1;
pNode1->PchQty=0;
pNode1->Scale=1;
pNode1->Loss=0;
pNode1->RqDate=pOrder->RqDate;
pNode1->son=NULL;
pNode1->brother=NULL;
pNode1->Source="自制";
if (pRoot==NULL)
{
pRoot=pNode1;
}
else
{
for (pNode2=pRoot;pNode2->brother!=NULL;pNode2=pNode2->brother);
pNode2->brother=pNode1;
}
/*
for (pMtrl1=pRqMtrl;pMtrl1!=NULL;pMtrl1=pMtrl1->next)
if (pMtrl1->MtrlID==pNode1->MtrlID)
{
pSeq1=new RqSeq;
pSeq1->itself=pNode1;
pSeq1->parent=NULL;
pSeq1->next=NULL;
if (pMtrl1->firstRq==NULL)
{
pMtrl1->firstRq=pSeq1;
}
else
{
if (pMtrl1->firstRq->itself->RqDate>=pNode1->RqDate)
{
pSeq1->next=pMtrl1->firstRq;
pMtrl1->firstRq=pSeq1;
}
else
{
pSeq2=pMtrl1->firstRq;
for (pSeq3=pSeq2->next;pSeq3!=NULL;pSeq3=pSeq3->next)
if (pSeq3->itself->RqDate>=pNode1->RqDate)
{
pSeq1->next=pSeq3;
pSeq2->next=pSeq1;
break;
}
else
{
pSeq2=pSeq2->next;
}
}
}
pMtrl1->counter++;
break;
}
if (pMtrl1==NULL)
{
pMtrl1=new RqMtrl;
pMtrl1->MtrlID=pNode1->MtrlID;
pMtrl1->Storage=pPrd->Storage;
pMtrl1->counter=1;
pMtrl1->firstRq=pSeq1;
pMtrl1->next=NULL;
if (pRqMtrl==NULL)
{
pRqMtrl=pMtrl1;
}
else
{
for (pMtrl2=pRqMtrl;pMtrl2->next!=NULL;pMtrl2=pMtrl2->next);
pMtrl2->next=pMtrl1;
}
}
*/
return S_OK;
}
STDMETHODIMP CMRPCalc::get_OprtOK(BOOL *pVal)
{
// TODO: Add your implementation code here
*pVal=m_OprtOK;
return S_OK;
}
STDMETHODIMP CMRPCalc::ConnectDB()
{
// TODO: Add your implementation code here
_ConnectionPtr pCnn;
pPrd=new CPrdStruct;
if (pPrd->Cls_ERR==true)
{
m_OprtOK=false;
}
else
{
pOrder=new COrder;
if (pOrder->Cls_ERR==true)
{
m_OprtOK=false;
}
else
{
m_OprtOK=true;
pCnn=pPrd->pDBCnn;
try
{
pRstRslt.CreateInstance(__uuidof(Recordset));
pRstMtrlWare.CreateInstance(__uuidof(Recordset));
pRstAllocMx.CreateInstance(__uuidof(Recordset));
pRstRslt->Open("u_tmp_RqCalcRslt",pCnn.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdTable);
pRstMtrlWare->Open("u_MtrlWare",pCnn.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdTable);
pRstAllocMx->Open("u_AllocMx",pCnn.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdTable);
}
catch(...)
{
m_OprtOK=false;
}
}
}
return S_OK;
}
STDMETHODIMP CMRPCalc::ReleaseDB()
{
// TODO: Add your implementation code here
RqMtrl *pMtrl;
delete pOrder;
pRstRslt->Close();
pRstRslt.Release();
pRstMtrlWare->Close();
pRstMtrlWare.Release();
pRstAllocMx->Close();
pRstAllocMx.Release();
delete pPrd;
DestroyTree(pRoot);
if (pRqMtrl!=NULL)
{
while (pRqMtrl->next!=NULL)
{
pMtrl=pRqMtrl->next;
pRqMtrl->next=pMtrl->next;
delete(pMtrl);
}
delete(pRqMtrl);
pRqMtrl=NULL;
}
return S_OK;
}
CalcNode *CMRPCalc::GenLeftTree(CalcNode *parentNode)
{
CalcNode *pNode1;
RqMtrl *pMtrl1,*pMtrl2;
RqSeq *pSeq1,*pSeq2,*pSeq3;
_bstr_t src;
src="外购";
pPrd->getnode(parentNode->NodeID);
if (pPrd->Cls_ERR==true) return NULL;
if (pPrd->firstsonID==-1) return NULL;
pNode1=new CalcNode;
pNode1->NodeID=pPrd->firstsonID;
pNode1->MtrlID=pPrd->firstson;
pNode1->OrderID=parentNode->OrderID;
pNode1->Scale=pPrd->sonscale;
pNode1->Loss=pPrd->sonloss;
pNode1->RqDate=parentNode->RqDate - pPrd->sonahead;
pNode1->PrvdQty=0;
pNode1->RqQty=-1;
pNode1->PchQty=0;
pNode1->Source=pPrd->sonsource;
pSeq1=new RqSeq;
pSeq1->itself=pNode1;
pSeq1->parent=parentNode;
pSeq1->next=NULL;
for (pMtrl1=pRqMtrl;pMtrl1!=NULL;pMtrl1=pMtrl1->next)
if (pMtrl1->MtrlID==pNode1->MtrlID)
{
/*
pSeq1=new RqSeq;
pSeq1->itself=pNode1;
pSeq1->parent=parentNode;
pSeq1->next=NULL;
*/
if (pMtrl1->firstRq==NULL)
{
pMtrl1->firstRq=pSeq1;
}
else
{
if (pMtrl1->firstRq->itself->RqDate>=pNode1->RqDate)
{
pSeq1->next=pMtrl1->firstRq;
pMtrl1->firstRq=pSeq1;
}
else
{
pSeq2=pMtrl1->firstRq;
pSeq3=pSeq2->next;
if (pSeq3==NULL)
{
pSeq2->next=pSeq1;
}
else
for (;pSeq3!=NULL;pSeq3=pSeq3->next)
if (pSeq3->itself->RqDate>=pNode1->RqDate)
{
pSeq1->next=pSeq3;
pSeq2->next=pSeq1;
break;
}
else
{
pSeq2=pSeq2->next;
}
if (pSeq3==NULL)
{
pSeq2->next=pSeq1;
}
}
}
pMtrl1->counter++;
break;
}
if (pMtrl1==NULL)
{
pMtrl1=new RqMtrl;
pMtrl1->MtrlID=pNode1->MtrlID;
pMtrl1->Storage=pPrd->sonStorage;
pMtrl1->counter=1;
pMtrl1->firstRq=pSeq1;
pMtrl1->next=NULL;
if (pRqMtrl==NULL)
{
pRqMtrl=pMtrl1;
}
else
{
for (pMtrl2=pRqMtrl;pMtrl2->next!=NULL;pMtrl2=pMtrl2->next);
pMtrl2->next=pMtrl1;
}
}
if (pNode1->Source != src)
{
pNode1->son=GenLeftTree(pNode1);
}
else
{
pNode1->son=NULL;
}
pNode1->brother=GenRightTree(parentNode,pNode1->NodeID);
return pNode1;
}
CalcNode * CMRPCalc::GenRightTree(CalcNode *parentNode, long argNodeID)
{
CalcNode *pNode1;
RqMtrl *pMtrl1,*pMtrl2;
RqSeq *pSeq1,*pSeq2,*pSeq3;
_bstr_t src;
src="外购";
pPrd->getnode(argNodeID);
if (pPrd->Cls_ERR==true) return NULL;
if (pPrd->brotherID==-1) return NULL;
pNode1=new CalcNode;
pNode1->NodeID=pPrd->brotherID;
pNode1->MtrlID=pPrd->brother;
pNode1->OrderID=parentNode->OrderID;
pNode1->Scale=pPrd->brotherscale;
pNode1->Loss=pPrd->brotherloss;
pNode1->RqDate=parentNode->RqDate - pPrd->brotherahead;
pNode1->PrvdQty=0;
pNode1->RqQty=-1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -