95 lines
2.5 KiB
C++
95 lines
2.5 KiB
C++
#include "StdAfx.h"
|
|
#include "ProductItemList.h"
|
|
#include "SLM/ShopPackage.h"
|
|
|
|
namespace ConvenienceStore
|
|
{
|
|
|
|
ProductItemList::ProductItemList()
|
|
{
|
|
|
|
}
|
|
|
|
ProductItemList::~ProductItemList()
|
|
{
|
|
ClearProductArray();
|
|
}
|
|
|
|
void ProductItemList::ClearProductArray()
|
|
{
|
|
std::map<int,ProductItem*>::iterator begin = product_array_.begin();
|
|
std::map<int,ProductItem*>::iterator end = product_array_.end();
|
|
for(;begin!=end;++begin)
|
|
{
|
|
ProductItem* pProduct = begin->second;
|
|
SAFE_DELETE(pProduct);
|
|
}
|
|
product_array_.clear();
|
|
}
|
|
|
|
|
|
|
|
bool ProductItemList::IsValidProduct( ShopItemObject* pObject )
|
|
{
|
|
std::map<int,ProductItem*>::iterator iter = product_array_.find(pObject->GetPackageSeq());
|
|
if(iter == product_array_.end())
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
void ProductItemList::_FillProductList(CShopCategory* pShopCategory )
|
|
{
|
|
int category_seq = 0;
|
|
pShopCategory->SetChildCategorySeqFirst();
|
|
while (pShopCategory->GetChildCategorySeqNext(category_seq) == true)
|
|
{
|
|
CShopCategory* pShopSubCategory = NULL;
|
|
if ((ConvenienceStore::category_list()->GetValueByKey(category_seq, pShopSubCategory) == false) ||
|
|
(pShopSubCategory == NULL))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
_FillProductList(pShopSubCategory);
|
|
}
|
|
|
|
|
|
int package_seq = 0;
|
|
pShopCategory->SetChildPackagSeqFirst();
|
|
while (pShopCategory->GetChildPackagSeqNext(package_seq) == true)
|
|
{
|
|
CShopPackage* pShopPackage = NULL;
|
|
if ((ConvenienceStore::package_list()->GetValueByKey(package_seq, pShopPackage) == false) ||
|
|
(pShopPackage == NULL))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
if( ProductItem* pProduct = ProductItem::CreateProduct(pShopCategory, pShopPackage) )
|
|
{
|
|
pProduct->SetPackageSeq(pShopPackage->PackageProductSeq);
|
|
product_array_[pShopPackage->PackageProductSeq]=pProduct;
|
|
}
|
|
}
|
|
}
|
|
ProductItem* ProductItemList::GetProduct(int Seq)
|
|
{
|
|
std::map<int,ProductItem*>::iterator iter = product_array_.find(Seq);
|
|
if(iter!=product_array_.end())
|
|
return iter->second;
|
|
return NULL;
|
|
}
|
|
void ProductItemList::BuildProductList(CShopList* pShopList)
|
|
{
|
|
ClearProductArray();
|
|
pShopList->GetCategoryListPtr()->SetFirst();
|
|
CShopCategory* pShop_Category=NULL;
|
|
while(pShopList->GetCategoryListPtr()->GetNext(pShop_Category))
|
|
{
|
|
_FillProductList(pShop_Category);
|
|
}
|
|
}
|
|
}
|
|
|