00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef Category_HPP
00012 #define Category_HPP
00013
00014 #include "read_write_base.hpp"
00015 enum category_direction
00016 {
00017 up,rgt,btm,lft
00018 };
00019
00020 class Category_Obj: public read_write_base
00021 {
00022 public:
00023 identifier Id;
00024 llong Parent_Id;
00025 string Name;
00026 int Display_Order;
00027 int Display_Level;
00028 string Description;
00029 string Base_URL;
00030
00031 Category_Obj():read_write_base()
00032 ,Id(0LL)
00033 ,Parent_Id(0LL)
00034 ,Name("")
00035 ,Display_Order(0)
00036 ,Display_Level(1)
00037 ,Description("")
00038 ,Base_URL("")
00039 {
00040
00041 data_name("Category");
00042
00043 addDXMap( new llongXfer("Id", &Id ));
00044 addDXMap( new llongXfer("Parent_Id", &Parent_Id ));
00045 addDXMap( new stringXfer("Name", &Name ));
00046 addDXMap( new intXfer("Display_Order", &Display_Order ));
00047 addDXMap( new intXfer("Display_Level", &Display_Level ));
00048 addDXMap( new stringXfer("Description", &Description ));
00049 addDXMap( new stringXfer("Base_URL", &Base_URL ));
00050 }
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 virtual bool ivalidate( void )
00065 {
00066 if( Display_Order == 0 )
00067 {
00068
00069 string sql="select max(Display_Order) from Category";
00070 if( rs.open(sql) )
00071 {
00072 Display_Order = 1+atoi(rs.getField(0).format().c_str());
00073 rs.close();
00074 }
00075 }
00076 return true;
00077 }
00078 virtual bool usupplemental( changeMap & changes )
00079 {
00080
00081
00082
00083
00084
00085 ocString sql = "select count(*) from Category where Display_Order = ";
00086 sql.append(Display_Order);
00087 sql += " and Id != ";
00088 sql.append(Id);
00089 if(rs.open(sql))
00090 {
00091 long count = atol(rs.getField(0).format().c_str());
00092 rs.close();
00093 if( count != 0 )
00094 {
00095 sql = "update Category set Display_Order = Display_Order+1 where "
00096 "Display_Order >= ";
00097 sql.append(Display_Order);
00098 sql += " and Id != ";
00099 sql.append(Id);
00100 cmd.execute(sql);
00101 }
00102 }
00103 return true;
00104 }
00105 virtual bool dsupplemental( void )
00106 {
00107
00108 ocString sql = "delete from Product_Categories where Category = ";
00109 sql.append(Id);
00110 cmd.execute(sql);
00111 return true;
00112 }
00113
00114
00115
00116
00117
00118
00119 bool move( long long cid, category_direction dir )
00120 {
00121 bool bret=false;
00122 int nplace_order=0;
00123 int oplace_order;
00124 long long oid=0;
00125
00126 Id=cid;
00127 key(cid);
00128 bret = get_data();
00129 ocString mvSql;
00130 if(bret)
00131 {
00132 oplace_order=Display_Order;
00133 changeMap changes;
00134
00135 switch(dir)
00136 {
00137 case up:
00138
00139 mvSql = "select Id, Display_Order from Category where Display_Order < ";
00140 mvSql.append(Display_Order);
00141 mvSql += " order by Display_Order desc limit 1";
00142 bret = false;
00143 if(rs.open(mvSql))
00144 {
00145 oid = atoi(rs.getField(0).format().c_str());
00146 Display_Order = atoll(rs.getField(1).format().c_str());
00147 }
00148 if( !oid ) Display_Order--;
00149 changes["Display_Order"]="Display_Order";
00150 bret = db_action( "u", changes );
00151 if( oid )
00152 {
00153 Id=oid;
00154 key(oid);
00155 bret = get_data();
00156 Display_Order=oplace_order;
00157 changes["pDisplay_Order"]="Display_Order";
00158 bret = db_action( "u", changes );
00159 }
00160 break;
00161
00162 case rgt:
00163 ++Display_Level;
00164 changes["Display_Level"]="Display_Level";
00165 bret = db_action( "u", changes );
00166 break;
00167
00168 case btm:
00169
00170 mvSql = "select Id, Display_Order from Category where Display_Order > ";
00171 mvSql.append(Display_Order);
00172 mvSql += " order by Display_Order asc limit 1";
00173 bret = false;
00174 if(rs.open(mvSql))
00175 {
00176 oid = atoi(rs.getField(0).format().c_str());
00177 Display_Order = atoll(rs.getField(1).format().c_str());
00178 }
00179 if( !oid ) Display_Order++;
00180 changes["Display_Order"]="Display_Order";
00181 bret = db_action( "u", changes );
00182 if( oid )
00183 {
00184 Id=oid;
00185 key(oid);
00186 bret = get_data();
00187 Display_Order=oplace_order;
00188 changes["Display_Order"]="Display_Order";
00189 bret = db_action( "u", changes );
00190 }
00191 break;
00192
00193 case lft:
00194
00195 if( Display_Level > 1 )
00196 {
00197 --Display_Level;
00198 changes["Display_Level"]="Display_Level";
00199 bret=db_action( "u", changes );
00200 }
00201 break;
00202 }
00203 }
00204 return bret;
00205 }
00206 };
00207 #endif
00208