N8Process.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  1. #include "stdafx.h"
  2. #include "N8Process.h"
  3. #include "Markup.h"
  4. namespace N8Process
  5. {
  6. //////////////////////////////////////////////////////////////////////////
  7. // CProductList类实现;
  8. BOOL CProductList::LoadXML(IN LPCTSTR lpXMLPath /* = NULL */)
  9. {
  10. SetXMLPath(lpXMLPath);
  11. CMarkup xml;
  12. if ( !xml.Load(GetPath()) )
  13. {
  14. return FALSE;
  15. }
  16. m_bLoad = TRUE;
  17. m_AryItems.RemoveAll();
  18. if ( !xml.FindElem() )
  19. return FALSE;
  20. if ( xml.IntoElem() )
  21. {
  22. while( xml.FindElem(_T("product")) )
  23. {
  24. CItem tagitem;
  25. xml.FindChildElem(_T("ID"));
  26. tagitem.m_strProductID = xml.GetChildData();
  27. xml.FindChildElem(_T("name"));
  28. tagitem.m_strProductName = xml.GetChildData();
  29. xml.FindChildElem(_T("width"));
  30. tagitem.m_strProductWidth = xml.GetChildData();
  31. xml.FindChildElem(_T("height"));
  32. tagitem.m_strProductHeight = xml.GetChildData();
  33. // 未过滤相同项;
  34. m_AryItems.Add(tagitem);
  35. }
  36. xml.OutOfElem();
  37. }
  38. return TRUE;
  39. }
  40. BOOL CProductList::IsItemExists(IN LPCTSTR lpProductName)
  41. {
  42. if ( lpProductName == NULL || lpProductName[0] == _T('\0'))
  43. return FALSE;
  44. if ( m_AryItems.GetSize() == 0 )
  45. return FALSE;
  46. BOOL bExists = FALSE;
  47. for ( int i = 0; i < m_AryItems.GetSize(); i++ )
  48. {
  49. CItem &tagItem = m_AryItems.ElementAt(i);
  50. if ( tagItem.m_strProductName.CompareNoCase(lpProductName) == 0)
  51. {
  52. bExists = TRUE;
  53. break;
  54. }
  55. }
  56. return bExists;
  57. }
  58. BOOL CProductList::IsItemExists(IN LPCTSTR lpProductID, IN LPCTSTR lpProductName)
  59. {
  60. if ( lpProductID == NULL || lpProductID[0] == _T('\0') || lpProductName == NULL || lpProductName[0] == _T('\0'))
  61. return FALSE;
  62. if ( m_AryItems.GetSize() == 0 )
  63. return FALSE;
  64. BOOL bExists = FALSE;
  65. for ( int i = 0; i < m_AryItems.GetSize(); i++ )
  66. {
  67. CItem &tagItem = m_AryItems.ElementAt(i);
  68. if ( tagItem.m_strProductID.CompareNoCase(lpProductID) == 0 && tagItem.m_strProductName.CompareNoCase(lpProductName) == 0)
  69. {
  70. bExists = TRUE;
  71. break;
  72. }
  73. }
  74. return bExists;
  75. }
  76. BOOL CProductList::InsertItem(IN LPCTSTR lpProductID, IN LPCTSTR lpProductName, IN LPCTSTR lpProductWidth, IN LPCTSTR lpProductHeiht)
  77. {
  78. if ( !IsPathExists() )
  79. return FALSE;
  80. if ( lpProductID == NULL || lpProductID[0] == _T('\0') || lpProductName == NULL || lpProductName[0] == _T('\0'))
  81. return FALSE;
  82. if ( !m_bLoad )
  83. {
  84. if( !LoadXML() )
  85. return FALSE;
  86. }
  87. if ( IsItemExists(lpProductID, lpProductName) )
  88. {
  89. return FALSE;
  90. }
  91. CMarkup xml;
  92. if ( !xml.Load(GetPath()) )
  93. return FALSE;
  94. if ( !xml.FindElem() )
  95. return FALSE;
  96. if ( xml.IntoElem() )
  97. {
  98. xml.FindElem(_T("product")) ;
  99. // 1.添加元素;
  100. xml.AddElem(_T("product"));
  101. xml.AddChildElem(_T("ID"), lpProductID);
  102. xml.AddChildElem(_T("name"), lpProductName);
  103. if ( lpProductWidth )
  104. xml.AddChildElem(_T("width"), lpProductWidth);
  105. else
  106. xml.AddChildElem(_T("width"), _T("0"));
  107. if ( lpProductHeiht )
  108. xml.AddChildElem(_T("height"), lpProductHeiht);
  109. else
  110. xml.AddChildElem(_T("height"), _T("0"));
  111. xml.OutOfElem();
  112. if ( !xml.Save(GetPath()))
  113. {
  114. return FALSE;
  115. }
  116. CItem tagItem;
  117. tagItem.m_strProductID = lpProductID;
  118. tagItem.m_strProductName = lpProductName;
  119. if ( lpProductWidth )
  120. tagItem.m_strProductWidth = lpProductWidth;
  121. else
  122. tagItem.m_strProductWidth = _T("0");
  123. if ( lpProductHeiht )
  124. tagItem.m_strProductHeight = lpProductHeiht;
  125. else
  126. tagItem.m_strProductHeight = _T("0");
  127. m_AryItems.Add(tagItem);
  128. }
  129. return TRUE;
  130. }
  131. BOOL CProductList::RemoveItemByID(IN LPCTSTR lpProductID)
  132. {
  133. return TRUE;
  134. }
  135. BOOL CProductList::RemoveItemByName(IN LPCTSTR lpProductName)
  136. {
  137. return TRUE;
  138. }
  139. //////////////////////////////////////////////////////////////////////////
  140. // CStaff类实现;
  141. BOOL CStaff::LoadXML(IN LPCTSTR lpXMLPath /* = NULL */)
  142. {
  143. SetXMLPath(lpXMLPath);
  144. CMarkup xml;
  145. if ( !xml.Load(GetPath()) )
  146. {
  147. return FALSE;
  148. }
  149. m_bLoad = TRUE;
  150. m_AryItems.RemoveAll();
  151. if ( !xml.FindElem() )
  152. return FALSE;
  153. if ( xml.IntoElem() )
  154. {
  155. while( xml.FindElem(_T("Staff")) )
  156. {
  157. CItem tagitem;
  158. xml.FindChildElem(_T("id"));
  159. tagitem.m_strStaffID = xml.GetChildData();
  160. xml.FindChildElem(_T("name"));
  161. tagitem.m_strStaffName = xml.GetChildData();
  162. // 未过滤相同项;
  163. m_AryItems.Add(tagitem);
  164. }
  165. xml.OutOfElem();
  166. }
  167. return TRUE;
  168. }
  169. BOOL CStaff::IsItemExists(IN LPCTSTR lpStaffID)
  170. {
  171. if ( lpStaffID == NULL || lpStaffID[0] == _T('\0') )
  172. return FALSE;
  173. if ( m_AryItems.GetSize() == 0 )
  174. return FALSE;
  175. BOOL bExists = FALSE;
  176. for ( int i = 0; i < m_AryItems.GetSize(); i++ )
  177. {
  178. CItem &tagItem = m_AryItems.ElementAt(i);
  179. if ( tagItem.m_strStaffID.CompareNoCase(lpStaffID) == 0 )
  180. {
  181. bExists = TRUE;
  182. break;
  183. }
  184. }
  185. return bExists;
  186. }
  187. BOOL CStaff::InsertItem(IN LPCTSTR lpStaffID, IN LPCTSTR lpStaffName)
  188. {
  189. if ( !IsPathExists() )
  190. return FALSE;
  191. if ( lpStaffID == NULL || lpStaffID[0] == _T('\0') || lpStaffName == NULL || lpStaffName[0] == _T('\0'))
  192. return FALSE;
  193. if ( !m_bLoad )
  194. {
  195. if( !LoadXML() )
  196. return FALSE;
  197. }
  198. if ( IsItemExists(lpStaffID) )
  199. {
  200. return FALSE;
  201. }
  202. CMarkup xml;
  203. if ( !xml.Load(GetPath()) )
  204. return FALSE;
  205. if ( !xml.FindElem() )
  206. return FALSE;
  207. if ( xml.IntoElem() )
  208. {
  209. xml.FindElem(_T("product")) ;
  210. xml.AddElem(_T("Staff"));
  211. xml.AddChildElem(_T("id"), lpStaffID);
  212. xml.AddChildElem(_T("name"), lpStaffName);
  213. xml.OutOfElem();
  214. if ( !xml.Save(GetPath()))
  215. {
  216. return FALSE;
  217. }
  218. CItem tagItem;
  219. tagItem.m_strStaffID = lpStaffID;
  220. tagItem.m_strStaffName = lpStaffName;
  221. m_AryItems.Add(tagItem);
  222. }
  223. return TRUE;
  224. }
  225. BOOL CStaff::RemoveItemByID(IN LPCTSTR lpProductID)
  226. {
  227. return TRUE;
  228. }
  229. //////////////////////////////////////////////////////////////////////////
  230. // CResultProduct类实现;
  231. BOOL CResultProduct::LoadXML(IN LPCTSTR lpXMLPath /* = NULL */)
  232. {
  233. SetXMLPath(lpXMLPath);
  234. CMarkup xml;
  235. if ( !xml.Load(GetPath()) )
  236. {
  237. return FALSE;
  238. }
  239. m_bLoad = TRUE;
  240. m_AryItems.RemoveAll();
  241. if ( !xml.FindElem() )
  242. return FALSE;
  243. if ( xml.IntoElem() )
  244. {
  245. while( xml.FindElem(_T("product")) )
  246. {
  247. CItem tagitem;
  248. xml.FindChildElem(_T("id"));
  249. tagitem.m_strProductID = xml.GetChildData();
  250. xml.FindChildElem(_T("comment"));
  251. tagitem.m_strProductComment = xml.GetChildData();
  252. xml.FindChildElem(_T("name"));
  253. tagitem.m_strProductName = xml.GetChildData();
  254. xml.FindChildElem(_T("width"));
  255. tagitem.m_strProductWidth = xml.GetChildData();
  256. xml.FindChildElem(_T("height"));
  257. tagitem.m_strProductHeight = xml.GetChildData();
  258. xml.IntoElem();
  259. xml.FindElem(_T("items"));
  260. xml.IntoElem();
  261. while ( xml.FindElem(_T("item")) )
  262. {
  263. SubItem tagSubItem;
  264. xml.FindChildElem(_T("id"));
  265. tagSubItem.m_strID = xml.GetChildData();
  266. xml.FindChildElem(_T("comment"));
  267. tagSubItem.m_strComment = xml.GetChildData();
  268. xml.FindChildElem(_T("replaces"));
  269. tagSubItem.m_strReplease = xml.GetChildData();
  270. tagitem.m_ArySubItems.push_back(tagSubItem);
  271. }
  272. xml.OutOfElem();//退出item;
  273. xml.OutOfElem();//退出items;
  274. // 未过滤相同项;
  275. m_AryItems.Add(tagitem);
  276. }
  277. xml.OutOfElem();//退出product;
  278. }
  279. return TRUE;
  280. }
  281. BOOL CResultProduct::IsItemExists(IN LPCTSTR lpID, IN LPCTSTR lpName)
  282. {
  283. if ( lpID == NULL || lpID[0] == _T('\0') || lpName == NULL || lpName[0] == _T('\0'))
  284. return FALSE;
  285. BOOL bExists = FALSE;
  286. for ( int i = 0; i < m_AryItems.GetSize(); i++ )
  287. {
  288. CItem &tagItem = m_AryItems.ElementAt(i);
  289. if ( tagItem.m_strProductID.CompareNoCase(lpID) == 0 ||
  290. tagItem.m_strProductName.CompareNoCase(lpName) == 0 )
  291. {
  292. bExists = TRUE;
  293. break;
  294. }
  295. }
  296. return bExists;
  297. }
  298. BOOL CResultProduct::InsertItem(IN LPCTSTR lpID, IN LPCTSTR lpComment, IN LPCTSTR lpName, IN LPCTSTR lpWidth, IN LPCTSTR lpHeight)
  299. {
  300. if ( !IsPathExists() )
  301. return FALSE;
  302. if ( lpID == NULL || lpID[0] == _T('\0') || lpName == NULL || lpName[0] == _T('\0'))
  303. return FALSE;
  304. if ( !m_bLoad )
  305. {
  306. if( !LoadXML() )
  307. return FALSE;
  308. }
  309. if ( IsItemExists(lpID, lpName) )
  310. {
  311. return FALSE;
  312. }
  313. CMarkup xml;
  314. if ( !xml.Load(GetPath()) )
  315. return FALSE;
  316. if ( !xml.FindElem() )
  317. return FALSE;
  318. if ( xml.IntoElem() )
  319. {
  320. xml.FindElem(_T("product")) ;
  321. xml.AddElem(_T("product"));
  322. xml.AddChildElem(_T("id"), lpID);
  323. xml.AddChildElem(_T("comment"), lpComment);
  324. xml.AddChildElem(_T("name"), lpName);
  325. if (lpWidth)
  326. xml.AddChildElem(_T("width"), lpWidth);
  327. else
  328. xml.AddChildElem(_T("width"), _T("0"));
  329. if ( lpHeight)
  330. xml.AddChildElem(_T("height"), lpHeight);
  331. else
  332. xml.AddChildElem(_T("height"), _T("0"));
  333. xml.AddChildElem(_T("items"));
  334. xml.OutOfElem();//退出根元素;
  335. if ( !xml.Save(GetPath()))
  336. {
  337. return FALSE;
  338. }
  339. CItem tagItem;
  340. tagItem.m_strProductID = lpID;
  341. tagItem.m_strProductName = lpName;
  342. if ( lpComment )
  343. tagItem.m_strProductComment = lpComment;
  344. else
  345. tagItem.m_strProductComment = _T("");
  346. if ( lpWidth )
  347. tagItem.m_strProductWidth = lpWidth;
  348. else
  349. tagItem.m_strProductWidth = _T("0");
  350. if ( lpHeight )
  351. tagItem.m_strProductHeight = lpHeight;
  352. else
  353. tagItem.m_strProductHeight = _T("0");
  354. m_AryItems.Add(tagItem);
  355. }
  356. return TRUE;
  357. }
  358. BOOL CResultProduct::InsertSubItem(IN LPCTSTR lpID, IN LPCTSTR lpName, IN LPCTSTR lpSubID, IN LPCTSTR lpSubComment, IN LPCTSTR lpSubReplease)
  359. {
  360. if ( !IsPathExists() )
  361. return FALSE;
  362. if ( lpID == NULL || lpID[0] == _T('\0') || lpName == NULL || lpName[0] == _T('\0') || lpSubID == NULL || lpSubID[0] == _T('\0'))
  363. return FALSE;
  364. if ( !m_bLoad )
  365. {
  366. if( !LoadXML() )
  367. return FALSE;
  368. }
  369. if ( !IsItemExists(lpID, lpName) )
  370. {
  371. return FALSE;
  372. }
  373. CMarkup xml;
  374. if ( !xml.Load(GetPath()) )
  375. return FALSE;
  376. if ( !xml.FindElem() )
  377. return FALSE;
  378. if ( !xml.IntoElem() )
  379. return FALSE;
  380. while( xml.FindElem(_T("product")) )
  381. {
  382. CString strID;
  383. CString strName;
  384. if ( xml.FindChildElem(_T("id")) )
  385. {
  386. strID = xml.GetChildData();
  387. }
  388. if ( xml.FindChildElem(_T("name")) )
  389. {
  390. strName = xml.GetChildData();
  391. }
  392. if ( strID.CompareNoCase(lpID) == 0 && strName.CompareNoCase(lpName) == 0 )
  393. {
  394. xml.IntoElem(); // 进入product;
  395. xml.FindElem(_T("items"));
  396. xml.IntoElem();// 进入items;
  397. CString strSubID;
  398. CString strSubComment;
  399. CString strSubReplease;
  400. BOOL bSubItemExists = FALSE;
  401. while ( xml.FindElem(_T("item")) )
  402. {
  403. if ( xml.FindChildElem(_T("id")) )
  404. {
  405. strSubID = xml.GetChildData();
  406. if ( strSubID.CompareNoCase(lpSubID) == 0 )
  407. {// 存在子结点;
  408. bSubItemExists = TRUE;
  409. break;
  410. }
  411. }
  412. }
  413. if ( !bSubItemExists )
  414. {
  415. xml.AddElem(_T("item"));
  416. xml.AddChildElem(_T("id"), lpSubID);
  417. if ( lpSubComment )
  418. xml.AddChildElem(_T("comment"), lpSubComment);
  419. else
  420. xml.AddChildElem(_T("comment"), _T(""));
  421. if ( lpSubReplease )
  422. xml.AddChildElem(_T("replaces"), lpSubReplease);
  423. else
  424. xml.AddChildElem(_T("replaces"), _T(""));
  425. int nIndex = -1;
  426. for ( int i = 0; i < m_AryItems.GetSize(); i++ )
  427. {
  428. CItem &tagItem = m_AryItems.ElementAt(i);
  429. if ( tagItem.m_strProductID.CompareNoCase(lpID) == 0 && tagItem.m_strProductName.CompareNoCase(lpName) == 0 )
  430. {
  431. nIndex = i;
  432. break;
  433. }
  434. }
  435. SubItem tagSubItem;
  436. tagSubItem.m_strID = lpSubID;
  437. if ( lpSubComment )
  438. tagSubItem.m_strComment = lpSubComment;
  439. else
  440. tagSubItem.m_strComment = _T("");
  441. if ( lpSubReplease )
  442. tagSubItem.m_strReplease = lpSubReplease;
  443. else
  444. tagSubItem.m_strReplease = _T("");
  445. if ( nIndex != -1 )
  446. m_AryItems.ElementAt(nIndex).m_ArySubItems.push_back(tagSubItem);
  447. else
  448. AfxMessageBox(_T("锟斤拷锟截筹拷锟斤拷"));
  449. }
  450. xml.OutOfElem();// 退出items;
  451. xml.OutOfElem();// 退出product;
  452. break;
  453. }
  454. }
  455. xml.OutOfElem();// 退出根结点;
  456. if ( !xml.Save(GetPath()))
  457. {
  458. return FALSE;
  459. }
  460. return TRUE;
  461. }
  462. //////////////////////////////////////////////////////////////////////////
  463. // CResultVgProduct类实现;
  464. BOOL CResultVgProduct::LoadXML(IN LPCTSTR lpXMLPath /* = NULL */)
  465. {
  466. SetXMLPath(lpXMLPath);
  467. CMarkup xml;
  468. if ( !xml.Load(GetPath()) )
  469. {
  470. return FALSE;
  471. }
  472. m_bLoad = TRUE;
  473. m_AryItems.RemoveAll();
  474. if ( !xml.FindElem() )
  475. return FALSE;
  476. if ( !xml.IntoElem() )
  477. return FALSE;
  478. while( xml.FindElem(_T("n8vg_product")) )
  479. {
  480. CItem tagitem;
  481. xml.FindChildElem(_T("id"));
  482. tagitem.m_strProductID = xml.GetChildData();
  483. xml.FindChildElem(_T("comment"));
  484. tagitem.m_strProductComment = xml.GetChildData();
  485. xml.FindChildElem(_T("name"));
  486. tagitem.m_strProductName = xml.GetChildData();
  487. xml.FindChildElem(_T("width"));
  488. tagitem.m_strProductWidth = xml.GetChildData();
  489. xml.FindChildElem(_T("height"));
  490. tagitem.m_strProductHeight = xml.GetChildData();
  491. xml.IntoElem();
  492. xml.FindElem(_T("items"));
  493. xml.IntoElem();
  494. while ( xml.FindElem(_T("item")) )
  495. {
  496. CString strSubID;
  497. xml.FindChildElem(_T("id"));
  498. strSubID = xml.GetChildData();
  499. tagitem.m_ArySubItems.push_back(strSubID);
  500. }
  501. xml.OutOfElem();//退出item;
  502. xml.OutOfElem();//退出items;
  503. // 未过滤相同项;
  504. m_AryItems.Add(tagitem);
  505. }
  506. xml.OutOfElem();//退出product;
  507. return TRUE;
  508. }
  509. BOOL CResultVgProduct::IsItemExists(IN LPCTSTR lpID, IN LPCTSTR lpName)
  510. {
  511. if ( lpID == NULL || lpID[0] == _T('\0') || lpName == NULL || lpName[0] == _T('\0'))
  512. return FALSE;
  513. BOOL bExists = FALSE;
  514. for ( int i = 0; i < m_AryItems.GetSize(); i++ )
  515. {
  516. CItem &tagItem = m_AryItems.ElementAt(i);
  517. if ( tagItem.m_strProductID.CompareNoCase(lpID) == 0 ||
  518. tagItem.m_strProductName.CompareNoCase(lpName) == 0 )
  519. {
  520. bExists = TRUE;
  521. break;
  522. }
  523. }
  524. return bExists;
  525. }
  526. BOOL CResultVgProduct::InsertItem(IN LPCTSTR lpID, IN LPCTSTR lpComment, IN LPCTSTR lpName, IN LPCTSTR lpWidth, IN LPCTSTR lpHeight)
  527. {
  528. if ( !IsPathExists() )
  529. return FALSE;
  530. if ( lpID == NULL || lpID[0] == _T('\0') || lpName == NULL || lpName[0] == _T('\0'))
  531. return FALSE;
  532. if ( !m_bLoad )
  533. {
  534. if( !LoadXML() )
  535. return FALSE;
  536. }
  537. if ( IsItemExists(lpID, lpName) )
  538. {
  539. return FALSE;
  540. }
  541. CMarkup xml;
  542. if ( !xml.Load(GetPath()) )
  543. return FALSE;
  544. if ( !xml.FindElem() )
  545. return FALSE;
  546. if ( !xml.IntoElem() )
  547. return FALSE;
  548. xml.FindElem(_T("n8vg_product"));
  549. xml.AddElem(_T("n8vg_product"));
  550. xml.AddChildElem(_T("id"), lpID);
  551. xml.AddChildElem(_T("comment"), lpComment);
  552. xml.AddChildElem(_T("name"), lpName);
  553. if (lpWidth)
  554. xml.AddChildElem(_T("width"), lpWidth);
  555. else
  556. xml.AddChildElem(_T("width"), _T("0"));
  557. if ( lpHeight)
  558. xml.AddChildElem(_T("height"), lpHeight);
  559. else
  560. xml.AddChildElem(_T("height"), _T("0"));
  561. xml.AddChildElem(_T("items"));
  562. xml.OutOfElem();//退出根结点;
  563. if ( !xml.Save(GetPath()))
  564. {
  565. return FALSE;
  566. }
  567. CItem tagItem;
  568. tagItem.m_strProductID = lpID;
  569. tagItem.m_strProductName = lpName;
  570. if ( lpComment )
  571. tagItem.m_strProductComment = lpComment;
  572. else
  573. tagItem.m_strProductComment = _T("");
  574. if ( lpWidth )
  575. tagItem.m_strProductWidth = lpWidth;
  576. else
  577. tagItem.m_strProductWidth = _T("0");
  578. if ( lpHeight )
  579. tagItem.m_strProductHeight = lpHeight;
  580. else
  581. tagItem.m_strProductHeight = _T("0");
  582. m_AryItems.Add(tagItem);
  583. return TRUE;
  584. }
  585. BOOL CResultVgProduct::InsertSubItem(IN LPCTSTR lpID, IN LPCTSTR lpName, IN LPCTSTR lpSubID)
  586. {
  587. if ( !IsPathExists() )
  588. return FALSE;
  589. if ( lpID == NULL || lpID[0] == _T('\0') || lpName == NULL || lpName[0] == _T('\0') || lpSubID == NULL || lpSubID[0] == _T('\0'))
  590. return FALSE;
  591. if ( !m_bLoad )
  592. {
  593. if( !LoadXML() )
  594. return FALSE;
  595. }
  596. if ( !IsItemExists(lpID, lpName) )
  597. {
  598. return FALSE;
  599. }
  600. CMarkup xml;
  601. if ( !xml.Load(GetPath()) )
  602. return FALSE;
  603. if ( !xml.FindElem() )
  604. return FALSE;
  605. if ( !xml.IntoElem() )
  606. return FALSE;
  607. while( xml.FindElem(_T("n8vg_product")) )
  608. {
  609. CString strID;
  610. CString strName;
  611. if ( xml.FindChildElem(_T("id")) )
  612. {
  613. strID = xml.GetChildData();
  614. }
  615. if ( xml.FindChildElem(_T("name")) )
  616. {
  617. strName = xml.GetChildData();
  618. }
  619. if ( strID.CompareNoCase(lpID) == 0 && strName.CompareNoCase(lpName) == 0 )
  620. {
  621. xml.IntoElem(); // 进入product;
  622. xml.FindElem(_T("items"));
  623. xml.IntoElem();// 进入items;
  624. CString strSubID;
  625. CString strSubComment;
  626. CString strSubReplease;
  627. BOOL bSubItemExists = FALSE;
  628. while ( xml.FindElem(_T("item")) )
  629. {
  630. if ( xml.FindChildElem(_T("id")) )
  631. {
  632. strSubID = xml.GetChildData();
  633. if ( strSubID.CompareNoCase(lpSubID) == 0 )
  634. {// 存在子结点;
  635. bSubItemExists = TRUE;
  636. break;
  637. }
  638. }
  639. }
  640. if ( !bSubItemExists )
  641. {
  642. xml.AddElem(_T("item"));
  643. xml.AddChildElem(_T("id"), lpSubID);
  644. int nIndex = -1;
  645. for ( int i = 0; i < m_AryItems.GetSize(); i++ )
  646. {
  647. CItem &tagItem = m_AryItems.ElementAt(i);
  648. if ( tagItem.m_strProductID.CompareNoCase(lpID) == 0 && tagItem.m_strProductName.CompareNoCase(lpName) == 0 )
  649. {
  650. nIndex = i;
  651. break;
  652. }
  653. }
  654. if ( nIndex != -1 )
  655. m_AryItems.ElementAt(nIndex).m_ArySubItems.push_back(lpSubID);
  656. else
  657. AfxMessageBox(_T("锟斤拷锟截筹拷锟斤拷"));
  658. }
  659. xml.OutOfElem();// 退出items;
  660. xml.OutOfElem();// 退出product;
  661. break;
  662. }
  663. }
  664. xml.OutOfElem();// 退出根结点;
  665. if ( !xml.Save(GetPath()))
  666. {
  667. return FALSE;
  668. }
  669. return TRUE;
  670. }
  671. //////////////////////////////////////////////////////////////////////////
  672. // CReusltItem类实现;
  673. BOOL CResultItem::LoadXML(IN LPCTSTR lpXMLPath /* = NULL */ )
  674. {
  675. SetXMLPath(lpXMLPath);
  676. CMarkup xml;
  677. if ( !xml.Load(GetPath()) )
  678. {
  679. return FALSE;
  680. }
  681. m_bLoad = TRUE;
  682. m_AryItems.RemoveAll();
  683. if ( !xml.FindElem() )
  684. return FALSE;
  685. if ( xml.IntoElem() )
  686. {
  687. while ( xml.FindElem(_T("item")) )
  688. {
  689. CItem tagItem;
  690. xml.FindChildElem(_T("bDel"));
  691. tagItem.m_strDel = xml.GetChildData();
  692. xml.FindChildElem(_T("bPage"));
  693. tagItem.m_strPage = xml.GetChildData();
  694. xml.FindChildElem(_T("path"));
  695. tagItem.m_strPath = xml.GetChildData();
  696. xml.FindChildElem(_T("comment"));
  697. tagItem.m_strComment = xml.GetChildData();
  698. xml.FindChildElem(_T("deleted"));
  699. tagItem.m_strDeleted = xml.GetChildData();
  700. // 未过滤相同项;
  701. m_AryItems.Add(tagItem);
  702. }
  703. xml.OutOfElem();
  704. }
  705. return TRUE;
  706. }
  707. BOOL CResultItem::IsItemExists(IN LPCTSTR lpPath)
  708. {
  709. if ( lpPath == NULL || lpPath[0] == _T('\0'))
  710. return FALSE;
  711. BOOL bExists = FALSE;
  712. for ( int i = 0; i < m_AryItems.GetSize(); i++ )
  713. {
  714. CItem &tagItem = m_AryItems.ElementAt(i);
  715. if ( tagItem.m_strPath.CompareNoCase(lpPath) == 0 )
  716. {
  717. bExists = TRUE;
  718. break;
  719. }
  720. }
  721. return bExists;
  722. }
  723. BOOL CResultItem::InsertItem(IN LPCTSTR lpPath, IN LPCTSTR lpComment, IN LPCTSTR lpDel, IN LPCTSTR lpPage)
  724. {
  725. return TRUE;
  726. }
  727. //////////////////////////////////////////////////////////////////////////
  728. // CAlbum类实现;
  729. BOOL CAlbum::LoadXML(IN LPCTSTR lpXMLPath /* = NULL */ )
  730. {
  731. SetXMLPath(lpXMLPath);
  732. CMarkup xml;
  733. if ( !xml.Load(GetPath()) )
  734. {
  735. return FALSE;
  736. }
  737. m_bLoad = TRUE;
  738. m_AryPages.RemoveAll();
  739. if ( !xml.FindElem() )
  740. return FALSE;
  741. if ( !xml.IntoElem() )
  742. return FALSE;
  743. if ( xml.FindElem(_T("N8Pages")) )
  744. {
  745. xml.IntoElem();// 进入N8Pages;
  746. while( xml.FindElem(_T("N8Page")) )
  747. {
  748. CPageItem tagItem;
  749. tagItem.m_strFileName = xml.GetAttrib(_T("FileName"));
  750. tagItem.m_strtplid = xml.GetAttrib(_T("tplid"));
  751. tagItem.m_strtplname = xml.GetAttrib(_T("tplname"));
  752. xml.IntoElem();
  753. if ( xml.FindElem(_T("CellList")) )
  754. {
  755. while ( xml.FindChildElem(_T("Cell")) )
  756. {
  757. CString strImg = xml.GetChildAttrib(_T("FileName"));
  758. tagItem.m_vtImgs.push_back(strImg);
  759. }
  760. }
  761. xml.OutOfElem();//退出CellList;
  762. // 未过滤相同项;
  763. m_AryPages.Add(tagItem);
  764. }
  765. xml.OutOfElem();// 退出N8Pages;
  766. }
  767. xml.OutOfElem();//退出根结点;
  768. return TRUE;
  769. }
  770. };