Old code under a C Builder. With a combination mode to implement organizational structure, Singleton's ORGTREEREPOSTORY is saved to save all objects. A slightly problematic place is part of the constructor's code to penetrate into the entity object - MakechildTreeView (), this is too clean because of the people in the initialization interface, it is not possible to resist this temptation. Other business methods are almost the same logic and remove it.
#ifndef OrganizationH
#define OrganizationH
#include
#include
#include
#include "global / global.h"
#include "MYLIB / MYLIB / OBJECT_MANAGER.H"
#include "datamodule / personisthome.h"
#include
#include "Datamodule / Persist.h"
#include "MYLIB / MyLog.h"
Using namespace std;
Using namespace mylib;
USING NAMESPACE PLANMANAGE;
/ / -------------------------------------------------------------------------------------------- ---------------------------
Class Party
{
PUBLIC:
Virtual Void MakechildTreeView (TTREEVIEW * TREE, TTREENODE * FNODE) = 0;
Void setName (const string & arg)
{
this-> m_name = arg;
}
Const string getname ()
{
Return M_Name;
}
Virtual bool isleaf () = 0;
Virtual Party * FindByname (const string & name) = 0;
Virtual Party * FindByid (const string & id) = 0;
Virtual Void AddChild (Party * Party) = 0;
Virtual string getparentId () = 0;
Virtual ~ party () {}
Virtual void dump () = 0;
Virtual void dumpChild () = 0;
Void setParent (Party * arg)
{
m_parent = arg;
}
Party * getParent ()
{
Return m_parent;
}
int GetLevel ()
{
INT RET = 0;
Party * cursor = this-> getparent ();
While (Cursor)
{
Cursor = CURSOR-> getParent ();
RET ;
}
Return Ret;
}
protected:
TTREENODE * AddTreeViewNode (TTREEVIEW * TREE, TTREENODE * FNODE)
{
TTREENODE * NODE = Tree-> Items-> AddChildObject (fnode, m_name, this);
Node-> imageIndex = isleaf ()? 1: 0;
Return node;
}
String m_name;
Party * m_parent;};
Class Organization: Public Party, Public PERSIST <>
{
PUBLIC:
Organization ()
{
}
Void MakechildTreeView (TtreeView * Tree, Ttreenode * fnode)
{
TTREENODE * NODE = AddTreeViewNode (Tree, FNode);
For (SIZE_T I = 0; I { M_Children [i] -> makechildtreeView (Tree, Node); } } Bool isleaf () { Return False; } Party * FindByname (const string & name) { IF (this-> getname () == Name) Return this; Else { For (SIZE_T I = 0; I { Party * Ret = m_children [i] -> FindByName (Name); IF (RET) Return Ret; } } Return NULL; } Party * FindbyId (const string & id) { IF (this-> getId () == id) returnid; Else { For (SIZE_T I = 0; I { Party * Ret = m_children [i] -> FindbyID (ID); IF (RET) Return Ret; } } Return NULL; } Void AddChild (Party * Party) { m_children.push_back (party); } String getParentID () { Return M_PID; } Organization () { ClearContainer (& M_Children); } Void dump () { LOG () << "Dep:" string (m_name.c_str ()) << endl; Log () << "-------------" << endl; For (SIZE_T I = 0; I { M_Children [i] -> dump (); } Log () << "-------------" << endl; } Void DumpChild () { Log () << "all children" << endl; For (SIZE_T I = 0; I { Log () << m_children [i] -> getname (). c_str () << endl; } } protected: void bind () { BindTable ("DOCMAN.DEPARTMENT", "ID"); Bindfield Bindfield } PRIVATE: Vector String m_pid; } Class Employee: Public Party, Public Persist { PUBLIC: Void MakechildTreeView (TtreeView * Tree, Ttreenode * fnode) { AddTreeViewNode (Tree, FNode); } Bool isleaf () { Return True; } Party * FindByname (const string & name) { IF (this-> getname () == name) Return this; Else Return NULL; } Party * FindbyId (const string & id) { IF (this-> getId () == id) Return this; Else Return NULL; } Void AddChild (Party * Party) { // do nothing } String getParentID () { Return M_DepID; } Void dump () { Log () << "staff:" string (m_name.c_str ()) << endl; } Void DumpChild () { Log () << "leaf node" << endl; } protected: void bind () { Bindtable ("DOCMAN.STAFFINFO", "Staffno"); Bindfield Bindfield } Private: String m_depid; } // singlton Class ORGTREEREPOSTORY: PUBLIC CLEANUP { PUBLIC: Static ORGTREEREPOSTORY * GETISTANCE () { IF (! m_instance) { m_instance = new orgtreeerepository (); MYLIB :: Object_manager :: at_exit (m_instance); } Return M_INSTANCE; } Party * gettreeroot () { Return M_Root; } Party * FindByname (const string & name) { Return M_Root-> FindbyName (Name); } Party * FindbyId (const string & id) { Return M_Root-> FindbyID (ID); } Organization * getJY () { Return Dynamic_cast } Organization * getzz () { Return Dynamic_cast } Organization * getsb () { Return Dynamic_cast Organization * gethz () { Return Dynamic_cast } Organization * getrootorg () { Return Dynamic_cast } Private: Static ORGTREEREPOSTORY * M_INSTANCE; ORGTREEREPOSTORY () { Initorgtree (); } ~ ORGTREEREPOSTORY () { Delete M_Root; } Party * m_root; void initrootnode () { Organization * org = new Organization (); Org-> setID (0); Org-> setParent (null); ORG-> LOAD (); m_root = org; } void initorgtree () { INITROOTNODE (); Auto_Ptr PersistHome ); AddkIndnodes (Orgs.get ()); ClearContainer (Orgs.get ()); Auto_PTR AddkindNodes (EMPS.GET ()); ClearContainer (EMPS.GET ()); } Template Void AddKindNodes (CollectionType * Collection) { TypedEf CollectionType :: item Iterator; IF (! collection) return; // Remove until the size is no longer changing SIZE_T VANE = 0; While (! Collection-> Empty () && collection-> size ()! = vane) { VANE = Collection-> size (); For (Iterator I = Collection-> Begin (); i! = Collection-> end (); i ) { Party * parent = m_root-> findbyid ((* i) -> getParentId ()); IF (PARENT) { Parent-> AddChild (* i); (* i) -> setParent (PARENT); I = Collection-> Erase (i); } } } } } #ENDIF> Orgs
> Emps (Persisthome