00001
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef _PRODUCT_H_
00040 #define _PRODUCT_H_
00041
00042
00043
00044
00045 #include <iosfwd>
00046 #include <list>
00047 #include <vector>
00048 #include <map>
00049 #include <string>
00050 #include <memory>
00051
00052
00053 #include "osberror.h"
00054 #include "osbid.h"
00055 #include "osbtype.h"
00056 #include "osbutils.h"
00057
00058
00059 namespace OSB_DB {
00060 class Session;
00061 class ProductGw;
00062 }
00063
00064 namespace OSB_LIB {
00065 class ProductItemBase;
00066 class ProductItem;
00067 class ProductCatalogue;
00068 class Pricelist;
00069 }
00070
00071
00072
00073 namespace OSB_LIB {
00074
00075
00076
00077
00078
00079
00080 class ProductNode;
00082 typedef std::list<ProductNode> ProductNodeParts;
00083
00088
00089
00090
00091
00092 class ProductNode {
00093 private:
00095 friend class Product;
00101 friend class OSB_DB::ProductGw;
00102
00103 public:
00110 typedef Id<ProductNode> Oid;
00111
00113
00114
00121 ProductNode(
00122 const Oid& id,
00123 std::auto_ptr<ProductItem> item,
00124 const EditStatus& es =
00125 EditStatus(EditStatus::esCreated)
00126 );
00127
00133 ProductNode(const ProductNode& node);
00134 ProductNode& operator=(const ProductNode& rhs);
00135
00141 ~ProductNode();
00143
00147 const Oid& oid() const;
00149 const Oid& parentId() const;
00151 int mandatory() const;
00153 const ProductItem* pItem() const;
00155 ProductItem* pItem();
00157 const ProductNodeParts& parts() const;
00159 ProductNodeParts& parts();
00161 EditStatus::Status editStatus() const;
00163
00167 void setParentId(const ProductNode::Oid& parentId);
00169 void setMandatory(const int& man);
00171
00173 std::ostream& prInfo(
00174 std::ostream& o,
00175 bool printParts = false,
00176 const std::string& indent = ""
00177 ) const;
00178
00179 private:
00181 bool setDelete();
00182
00183 private:
00184 Oid oid_;
00185 Oid parentId_;
00186 int mandatory_;
00187 ProductItem* pItem_;
00188 ProductNodeParts parts_;
00189
00196 EditStatus editStatus_;
00197 };
00198
00199
00200
00204 class Product {
00205 friend class OSB_DB::ProductGw;
00206 friend class ProductCatalogue;
00207 friend std::ostream& operator<<(std::ostream&, const Product&);
00208 public:
00210 typedef Id<Product> Oid;
00211
00217 Product(
00218 const Oid& oid,
00219 const std::string& name = "",
00220 const std::string& des = ""
00221 );
00222
00224
00225
00226 const Oid& oid() const;
00228 const std::string& name() const;
00230 const std::string& desc() const;
00239 const Id<Pricelist> getPricelistId() const;
00241 const ProductNodeParts& parts() const;
00243 ProductNodeParts& parts();
00245
00247
00248
00249 void setName(std::string& name);
00251 void setDesc(std::string& desc);
00253
00254 private:
00256 bool read(const OSB_DB::Session& session);
00257
00259
00260
00261 long nextTempNodeId();
00262
00264 void creProductNode(
00265 const OSB_DB::Session& session,
00266 ProductNode& node
00267 );
00268
00278 void delProductNode(
00279 const OSB_DB::Session& session,
00280 ProductNode& node
00281 );
00282
00284 void delNodeChildren(
00285 const OSB_DB::Session& session,
00286 ProductNode& parent
00287 );
00288
00290 void saveItem(
00291 const OSB_DB::Session& session,
00292 ProductItem* item
00293 );
00294
00307 bool saveNode(
00308 const OSB_DB::Session& session,
00309 ProductNode& node
00310 );
00311
00313 void saveNodes(
00314 const OSB_DB::Session& session
00315 );
00316
00318 void saveNodes(
00319 const OSB_DB::Session& session,
00320 ProductNodeParts& parts
00321 );
00323
00342 int buildNodeTree(
00343 const ProductNodeParts& nodes,
00344 std::vector<OsbError>& errors
00345 );
00346
00348 int buildNodeTree(
00349 const ProductNode::Oid& parentId,
00350 ProductNodeParts& parts,
00351 ProductNodeParts& tmpList,
00352 std::vector<OsbError>& errors,
00353 int numErrors
00354 );
00356
00358 void objVsPlus();
00359
00365 void delNode(ProductNode& node);
00366
00372 ProductNode* productNode(
00373 const ProductNode::Oid& nodeId,
00374 ProductNodeParts& parts
00375 );
00376
00377 public:
00379
00380
00394 ProductNode& addNode(
00395 const ProductNode::Oid& parentId,
00396 std::auto_ptr<ProductItem> item
00397 );
00398
00406 void delNode(const ProductNode::Oid& nodeId);
00407
00409 const ProductNode* findProductNode(
00410 const ProductNode::Oid& nodeId
00411 ) const;
00412
00414 ProductNode* productNode(const ProductNode::Oid& nodeId);
00415
00417 const ProductNode& getProductNode(
00418 const ProductNode::Oid& nodeId
00419 ) const;
00420
00427 void sortNodeByName(bool desc = false);
00428
00436 void sortNodeByName(
00437 ProductNodeParts& parts,
00438 bool desc = false
00439 );
00441
00442 private:
00443 Oid oid_;
00444 std::string name_;
00445 std::string des_;
00446 ProductNodeParts parts_;
00447 long objVs_;
00448 long tempNodeId_;
00449 };
00450
00452 typedef std::list<Product> Products;
00453 }
00454 #endif // #ifndef _PRODUCT_H_
00455