多级共享目录.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /************************************************************************/
  2. /*
  3. 1.导入时,选择可用的指定域名和相片类型的共享目录;
  4. 2.导出时,从所有共享目录中查找指定域名的订单文件夹;
  5. 3.查看相片时,从所有共享目录中查找指定域名的订单文件夹;
  6. 4.选片和选设计时,从所有共享目录中查找指定域名的订单文件夹;
  7. */
  8. /************************************************************************/
  9. BOOL g_bAllBranch = TRUE;
  10. CWnd g_pMainWnd = NULL;
  11. CString g_branchip = _T("");
  12. CString g_branchname = _T("");
  13. CArray<CStringArray,CStringArray> g_aryOfSharePathInfo;
  14. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  15. // 第一步,登陆时获取NetShareInfo表信息;
  16. /************************************************************************/
  17. /*
  18. Date: 2015-04-11
  19. Author: Jeff
  20. 函数:GetSharePathInfo
  21. 描述:获取共享目录表的所有信息;
  22. 参数:
  23. 返回:成功返回TRUE;
  24. 注意:获取的表记录存储在全局变量g_aryOfSharePathInfo中;
  25. 调用约定:在登陆软件时调用,且必须连接的服务器是本店的;
  26. */
  27. /************************************************************************/
  28. BOOL CMainFrame::GetSharePathInfo()
  29. {
  30. // 1.连接的数据库必须是本局域网的服务器;
  31. if ( g_bAllBranch || !g_branchname.IsEmpty() || !g_branchip.IsEmpty() )
  32. {
  33. // 非当前局域网服务器;
  34. return FALSE;
  35. }
  36. // 2.获取当前连接的分店域名是否与g_domain一致;
  37. g_sendhead.bsql = 0;
  38. g_sendhead.code[0] = 29;
  39. g_sendhead.tabcount = 1;
  40. g_pMainWnd->ProcessChatMessageRequest2(23);
  41. if ( !g_bSendOK )
  42. {
  43. // 连接服务器失败;
  44. return FALSE;
  45. }
  46. CArray<CStringArray,CStringArray> strArray;
  47. DataToArray(&strArray);
  48. CString strCurBranchDomain = _T("");
  49. if ( strArray.GetSize() )
  50. {
  51. strCurBranchDomain = strArray.ElementAt(0).ElementAt(0);
  52. if ( strCurBranchDomain.Find(_T(".ly.com")) == -1)
  53. {
  54. // 当前获取的域名有错;
  55. return FALSE;
  56. }
  57. }
  58. if ( g_domain.CompareNoCase(strCurBranchDomain) != 0)
  59. {
  60. // 当前连接的分店域名与局域网服务器域名不一致;
  61. return FALSE;
  62. }
  63. // 3.获取可用的共享信息;//select * from NetShareInfo where enable = 1;
  64. CString strFilter = _T("");
  65. strFilter.Format(_T("enable = 1"));
  66. int g_nYearposTemp=g_nYearpos;
  67. g_nYearpos=-1;
  68. g_bSendOK = 0;
  69. g_sendhead.bsql = 0;
  70. g_sendhead.code[0] = 236;
  71. g_sendhead.tabcount = 1;
  72. g_pMainWnd->ProcessChatMessageRequest2(strFilter);
  73. g_nYearpos = g_nYearposTemp;
  74. if ( !g_bSendOK )
  75. {
  76. // 获取共享信息失败;
  77. return FALSE;
  78. }
  79. g_aryOfSharePathInfo.RemoveAll();
  80. DataToArray(&g_aryOfSharePathInfo);
  81. return g_aryOfSharePathInfo.GetSize() ? TRUE : FALSE;
  82. }
  83. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  84. // 每次登陆本地服务器时,获取NetShareInfo表;
  85. void Login3::GetNetShareInfo()
  86. {
  87. #if 1
  88. if ( g_branchname.IsEmpty() ) // 如果是空域名,表示本店;
  89. {
  90. if ( g_aryOfSharePathInfo.GetSize() == 0 ) // 如果元素空,重新获取表;
  91. {
  92. g_pMainWnd->GetSharePathInfo();
  93. }
  94. }
  95. #else
  96. // 或者,移除之前的全部,重新获取;
  97. if ( g_branchname.IsEmpty() )
  98. {
  99. g_aryOfSharePathInfo.RemoveAll();
  100. g_pMainWnd->GetSharePathInfo();
  101. }
  102. #endif
  103. }
  104. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  105. // 第二步,在所有导入前,获取可用的共享目录;
  106. /************************************************************************/
  107. /*
  108. Date: 2015-04-10
  109. Author: Jeff
  110. 函数:GetEnableShareDirectory
  111. 描述:返回指定相片类型可用的共享目录;
  112. 参数:
  113. IN: nPhotoType 相片类型;
  114. IN: lpOrderNum 订单号;
  115. IN: lpDomain 分店域名;
  116. OUT: lpEnableShareDirectory 可用的共享目录;
  117. 返回:成功返回TRUE;
  118. 注意:用于导入相片,最后返回的共享目录,使用MakeSuerDirectoryPathExists函数创建目录;
  119. 调用约定:#
  120. 测试:通过;
  121. */
  122. /************************************************************************/
  123. BOOL GetEnableShareDirectory(IN const int &nPhotoType, IN LPCTSTR lpOrderNum, IN LPCTSTR lpDomain, OUT LPTSTR lpEnableShareDirectory)
  124. {
  125. // 需要判断域名有效性;
  126. if (lpDomain && strcmp(lpDomain, "") != 0)
  127. {
  128. TCHAR *szResult = strstr(lpDomain,".ly.com");
  129. if(szResult == NULL)
  130. {
  131. // 传入的域名有误;
  132. return FALSE;
  133. }
  134. }
  135. // 1.先判断当前局域网原始共享目录可用大小(是否小于20G);
  136. TCHAR szShare[MAX_PATH] = { 0 };
  137. GetLoaclShareDirectory(nPhotoType,szShare);// 获取本地指定相片类型的共享目录;
  138. // 如果订单号存在原始共享目录中,判断目录容量是否有5G大小,如果有则存入,否则存入到别的优先级高的共享目录;
  139. TCHAR szOrderNum[MAX_PATH] = { 0 };
  140. TCHAR szLocalOrder[MAX_PATH] = { 0 };
  141. if ( lpDomain == NULL || strcmp(lpDomain,"") == 0)
  142. {
  143. // 分店域名为空,则为本店;
  144. sprintf(szLocalOrder, "%s\\%s", szShare, lpOrderNum);
  145. }
  146. else
  147. {// 分店域名不为空;
  148. if ( strcmp(lpDomain, g_domain) == 0)
  149. {
  150. // 本店域名;
  151. sprintf(szLocalOrder, "%s\\%s", szShare, lpOrderNum);
  152. }
  153. else
  154. {
  155. sprintf(szLocalOrder, "%s\\%s\\%s", szShare, lpDomain, lpOrderNum);
  156. }
  157. }
  158. double dTotalNum = 0.0;
  159. double dFreeNum = 0.0;
  160. if ( !GetDiskSpaceInfo(szShare,dTotalNum,dFreeNum) )
  161. {
  162. // 获取硬盘大小失败;
  163. return FALSE;
  164. }
  165. // 订单文件夹存在且原始共享目录可用大小>5G 或者 订单文件夹不存在时,容量必须大于指定值;
  166. if ((PathFileExists(szLocalOrder) && dFreeNum > MINI_CAPACITY) || dFreeNum > 50)
  167. {
  168. // 返回原始共享目录;
  169. sprintf(lpEnableShareDirectory, "%s", szLocalOrder);
  170. return TRUE;
  171. }
  172. //////////////////////////////////////////////////////////////////////////
  173. // 原始共享目录不可用,使用其他高优先级共享目录;
  174. if ( g_aryOfSharePathInfo.GetSize() == 0)
  175. {
  176. // 记录为空,则仍旧使用原始共享目录;
  177. AfxMessageBox(_T("硬盘容量小于30G,请添加新共享硬盘!"));
  178. sprintf(lpEnableShareDirectory, "%s", szLocalOrder);
  179. return TRUE;
  180. }
  181. typedef struct _STNetSharePathInfo__
  182. {
  183. BYTE byPhotType;
  184. BYTE byminCapacity;
  185. BYTE bymaxCapacity;
  186. BYTE byPriority;
  187. CString strBranchId;
  188. CString strSharePath;
  189. }STNetSharePathInfo,*pSTNetSharePathInfo;
  190. BOOL bGetEnable = FALSE;
  191. BYTE byCurPriority = 0;
  192. int nSize = g_aryOfSharePathInfo.GetSize();
  193. // 如果没找到合适的共享目录,依旧使用原始共享目录或者使用优先级最高的那个;
  194. for ( int i = 0; i < nSize; i++)
  195. {
  196. // 域名是否与本店域名相同;
  197. if( g_aryOfSharePathInfo.ElementAt(i).ElementAt(1).CompareNoCase(g_domain) != 0 )
  198. continue;
  199. STNetSharePathInfo tempNetShaerInfo;
  200. // 获取高优先级共享目录,依次取低优先级目录,直到获取可用目录为止;
  201. tempNetShaerInfo.byPhotType = atoi(g_aryOfSharePathInfo.ElementAt(i).ElementAt(5));
  202. tempNetShaerInfo.byminCapacity = atoi(g_aryOfSharePathInfo.ElementAt(i).ElementAt(3));
  203. tempNetShaerInfo.bymaxCapacity = atoi(g_aryOfSharePathInfo.ElementAt(i).ElementAt(4));
  204. tempNetShaerInfo.byPriority = atoi(g_aryOfSharePathInfo.ElementAt(i).ElementAt(6));
  205. tempNetShaerInfo.strBranchId = g_aryOfSharePathInfo.ElementAt(i).ElementAt(1);
  206. tempNetShaerInfo.strSharePath = g_aryOfSharePathInfo.ElementAt(i).ElementAt(2);
  207. if ( tempNetShaerInfo.byPhotType == nPhotoType )
  208. {
  209. //////////////////////////////////////////////////////////////////////////
  210. // 判断目录下是否有订单文件夹;
  211. if (lpDomain && strcmp(lpDomain,"") != 0)
  212. {
  213. sprintf(szOrderNum,"%s\\%s\\%s",tempNetShaerInfo.strSharePath, lpDomain ,lpOrderNum);
  214. }
  215. else
  216. {
  217. sprintf(szOrderNum,"%s\\%s",tempNetShaerInfo.strSharePath, lpOrderNum);
  218. }
  219. // 存在且目录容量仍大于mincapacity可用;
  220. if ( PathFileExists(szOrderNum) )
  221. {
  222. if ( !GetDiskSpaceInfo(tempNetShaerInfo.strSharePath,dTotalNum,dFreeNum) )
  223. {
  224. // 获取硬盘大小失败;
  225. continue;
  226. }
  227. if ( dFreeNum > tempNetShaerInfo.byminCapacity )
  228. {
  229. bGetEnable = TRUE;
  230. break;
  231. }
  232. }
  233. // 判断共享路径是否可用;
  234. if ( GetDiskSpaceInfo(tempNetShaerInfo.strSharePath,dTotalNum,dFreeNum) )
  235. {
  236. if ( dFreeNum > tempNetShaerInfo.bymaxCapacity )
  237. {
  238. // 获取最高优先级的共享目录;
  239. if ( byCurPriority < tempNetShaerInfo.byPriority)
  240. {
  241. byCurPriority = tempNetShaerInfo.byPriority;
  242. if (lpDomain && strcmp(lpDomain, "") != 0)
  243. {
  244. sprintf(szOrderNum, "%s\\%s\\%s", tempNetShaerInfo.strSharePath, lpDomain, lpOrderNum);
  245. }
  246. else
  247. {
  248. sprintf(szOrderNum, "%s\\%s", tempNetShaerInfo.strSharePath, lpOrderNum);
  249. }
  250. bGetEnable = TRUE;
  251. }
  252. }
  253. }
  254. }
  255. }
  256. //////////////////////////////////////////////////////////////////////////
  257. // 返回结果;
  258. if(bGetEnable)
  259. sprintf(lpEnableShareDirectory,"%s",szOrderNum);
  260. else
  261. sprintf(lpEnableShareDirectory, "%s", szLocalOrder);
  262. return bGetEnable;
  263. }
  264. /************************************************************************/
  265. /*
  266. Date: 2015-04-15
  267. Author: Jeff
  268. 函数:GetLoaclShareDirectory
  269. 描述:获取指定相片类型的本地原始共享目录名;
  270. 参数:
  271. IN: nPhotoType 相片类型;
  272. 返回:成功返回TRUE;
  273. 注意:#;
  274. 调用约定:#
  275. */
  276. /************************************************************************/
  277. void GetLoaclShareDirectory(IN int const nPhotoType, OUT LPTSTR lpResultPath)
  278. {
  279. if ( g_serverbak.IsEmpty() )
  280. {
  281. // 主机名空;
  282. return;
  283. }
  284. switch( nPhotoType )
  285. {
  286. case 1:
  287. sprintf(lpResultPath, "\\\\%s\\%s", g_serverbak, "客户原片(管理软件)$");
  288. break;
  289. case 2:
  290. sprintf(lpResultPath, "\\\\%s\\%s", g_serverbak, "修好的片(管理软件)$");
  291. break;
  292. case 3:
  293. sprintf(lpResultPath, "\\\\%s\\%s", g_serverbak, "精修好的片(管理软件)$");
  294. break;
  295. case 4:
  296. sprintf(lpResultPath, "\\\\%s\\%s", g_serverbak, "设计好的片(管理软件)$");
  297. break;
  298. #ifdef ENTERPRISE_VERSION
  299. #ifndef CHILD_VERSION
  300. case 5:
  301. sprintf(lpResultPath, "\\\\%s\\%s", g_serverbak, "客户原片备份(管理软件)$");
  302. break;
  303. case 6:
  304. sprintf(lpResultPath,"\\\\%s\\%s", g_serverbak, "修好的片备份(管理软件)$");
  305. break;
  306. case 7:
  307. sprintf(lpResultPath,"\\\\%s\\%s", g_serverbak, "精修好的片备份(管理软件)$");
  308. break;
  309. case 8:
  310. sprintf(lpResultPath,"\\\\%s\\%s", g_serverbak, "设计好的片备份(管理软件)$");
  311. break;
  312. #else
  313. case 5:
  314. sprintf(lpResultPath, "\\\\%s\\%s", g_serverbak, "客户原片备份(儿童管理软件)$");
  315. break;
  316. case 6:
  317. sprintf(lpResultPath,"\\\\%s\\%s", g_serverbak, "修好的片备份(儿童管理软件)$");
  318. break;
  319. case 7:
  320. sprintf(lpResultPath,"\\\\%s\\%s", g_serverbak, "精修好的片备份(儿童管理软件)$");
  321. break;
  322. case 8:
  323. sprintf(lpResultPath,"\\\\%s\\%s", g_serverbak, "设计好的片备份(儿童管理软件)$");
  324. break;
  325. #endif
  326. #endif
  327. default:
  328. break;
  329. }
  330. }
  331. /************************************************************************/
  332. /*
  333. Date: 2015-04-08
  334. Author: Jeff
  335. 函数:GetDiskSpaceInfo
  336. 描述:获取指定目录或盘符的容量信息;
  337. 参数:
  338. IN: lpRootPathName 根目录名称;
  339. INOUT: dTotalNum 总容量;
  340. INOUT: dFreeNum 可用容量;
  341. 返回:
  342. 注意:
  343. GetDiskFreeSpace函数不能满足当前超过2T的硬盘容量,因为里面的数据类型是UINT,最大支持32位(4G);
  344. GetDiskFreeSpaceEx支持64位(16384P=1024*16384T)
  345. 只能获取本机硬盘信息,且路径必须包含":"冒号;
  346. 调用约定:
  347. */
  348. /************************************************************************/
  349. BOOL GetDiskSpaceInfo(IN LPCTSTR lpRootPathName,IN OUT double &dTotalNum, IN OUT double &dFreeNum)
  350. {
  351. // 校验参数有效性;
  352. if(lpRootPathName == NULL || _tcscmp(lpRootPathName,_T("")) == 0)
  353. {
  354. //_tprintf_s(_T("根目录为空!"));
  355. return FALSE;
  356. }
  357. // 如果长度==1;
  358. int nlen = _tcslen(lpRootPathName);
  359. if((1 == nlen) || ( 2 == nlen && lpRootPathName[nlen-1] != _T(':')))
  360. {
  361. //_tprintf_s(_T("根目录无效!\n"));
  362. return FALSE;
  363. }
  364. if ( !PathFileExists(lpRootPathName))
  365. {
  366. //_tprintf_s(_T("根目录不存在!\n"));
  367. return FALSE;
  368. }
  369. BOOL fResult = FALSE;
  370. DWORD dwSectPerClust; // 每簇的扇区数;
  371. DWORD dwBytesPerSect; // 每个扇区的字节数;
  372. DWORD dwFreeClusters; // 可用簇数;
  373. DWORD dwTotalClusters; // 总簇数;
  374. typedef BOOL (WINAPI *P_GDFSE)(LPCTSTR, PULARGE_INTEGER,PULARGE_INTEGER, PULARGE_INTEGER);
  375. P_GDFSE pGetDiskFreeSpaceEx = NULL;
  376. /*unsigned*/ __int64 i64FreeBytesToCaller;
  377. /*unsigned*/ __int64 i64TotalBytes;
  378. /*unsigned*/ __int64 i64FreeBytes;
  379. // 调用GetDiskFreeSpaceEx失败则调用GetDiskSpace;
  380. #ifdef UNICODE
  381. pGetDiskFreeSpaceEx = (P_GDFSE)GetProcAddress(GetModuleHandle(_T("kernel32.dll")),"GetDiskFreeSpaceExW");
  382. #else
  383. pGetDiskFreeSpaceEx = (P_GDFSE)GetProcAddress(GetModuleHandle("kernel32.dll"),"GetDiskFreeSpaceExA");
  384. #endif
  385. if ( pGetDiskFreeSpaceEx )
  386. {
  387. fResult = pGetDiskFreeSpaceEx(lpRootPathName,
  388. (PULARGE_INTEGER)&i64FreeBytesToCaller,
  389. (PULARGE_INTEGER)&i64TotalBytes,
  390. (PULARGE_INTEGER)&i64FreeBytes);
  391. if ( fResult )
  392. {
  393. // 将单位由byte转为G byte;
  394. dTotalNum = (double)i64TotalBytes/1024/1024/1024;
  395. dFreeNum = (double)i64FreeBytes/1024/1024/1024;
  396. }
  397. }
  398. else
  399. {
  400. fResult = GetDiskFreeSpace(lpRootPathName,
  401. &dwSectPerClust,
  402. &dwBytesPerSect,
  403. &dwFreeClusters,
  404. &dwTotalClusters);
  405. if ( fResult )
  406. {
  407. // 成功获得容量信息;
  408. i64TotalBytes = (__int64)dwTotalClusters * dwSectPerClust * dwBytesPerSect;
  409. i64FreeBytes = (__int64)dwFreeClusters * dwSectPerClust * dwBytesPerSect;
  410. // 将单位由byte转为G byte;
  411. dTotalNum = (double)i64TotalBytes/1024/1024/1024;
  412. dFreeNum = (double)i64FreeBytes/1024/1024/1024;
  413. }
  414. }
  415. return fResult;
  416. }
  417. /************************************************************************/
  418. /*
  419. 函数:LoadSpecifiedDirectory
  420. 描述:加载指定目录的相片;
  421. 参数:
  422. IN:lpSpecifiedDirectory指定的目录;
  423. 返回:
  424. 注意:
  425. 调用约定:
  426. */
  427. /************************************************************************/
  428. int LoadSpecifiedDirectoryImages(IN LPCTSTR lpSpecifiedDirectory, OUT CStringArray &AryOfImagePath)
  429. {
  430. // 1.判定目录有效性;
  431. if ( lpSpecifiedDirectory == NULL || strcmp(lpSpecifiedDirectory,_T("")) == 0)
  432. {
  433. // 目录无效;
  434. return -1;
  435. }
  436. using namespace helper_coffs;
  437. ffsco o;
  438. o.dirs(1);
  439. o.find(lpSpecifiedDirectory, LPCSTR("*.*"));
  440. ffsco::typeT cfs;
  441. ffsco::typeT::iterator it;
  442. cfs = o.co_file();
  443. CString strName;
  444. for (it = cfs.begin(); cfs.end() != it; it++)
  445. {
  446. // 去除目录级文件;
  447. // 去除ok文件;
  448. // 去除modifytime文件;
  449. // 去除s+m缩略图;
  450. strName = it->c_str();
  451. strName.MakeLower();
  452. if ( strName.Find('.') == -1)
  453. continue;
  454. else
  455. {
  456. CString str = strName.Mid( strName.ReverseFind('\\') + 1 );
  457. if ( str.Find('.') == -1)
  458. continue;
  459. }
  460. // 如果在相片前或后加修饰,都会有bug,最佳做法是缩略图放在另一子文件夹中;
  461. // 产生的bug:使用原名导入相片时,相片名可能第一个字母就是s或m;
  462. if ( strName.GetAt( strName.ReverseFind('\\') + 1 ) == 's' )continue;
  463. if ( strName.GetAt( strName.ReverseFind('\\') + 1 ) == 'm' )continue;
  464. if ( strName.Find(_T(".jpg")) == -1 )continue;
  465. AryOfImagePath.Add(strName);
  466. }
  467. }
  468. /************************************************************************/
  469. /*
  470. 函数:LoadSharedDirectoryPhotos
  471. 描述:加载指定相片类型、订单号、分店域名的相片路径集合;
  472. 参数:
  473. IN:nPhotoType 相片类型;
  474. IN:lpOrderNum 订单号;
  475. IN:lpDomain 分店域名(若域名空代表本店);
  476. OUT:AryOfImagesPath 返回的相片路径集合;
  477. 返回:
  478. 注意:
  479. 调用约定:
  480. */
  481. /************************************************************************/
  482. BOOL LoadSharedDirectoryPhotos(IN CONST INT &nPhotoType, IN LPCTSTR lpOrderNum, IN LPCTSTR lpDomain, OUT CStringArray &AryOfImagePath)
  483. {
  484. // 若域名非空,判断域名有效性;
  485. if ( lpDomain && strcmp(lpDomain, _T("")) != 0 )
  486. {
  487. TCHAR * szResult = strstr(lpDomain,_T(".ly.com"));
  488. if ( szResult == NULL )
  489. {
  490. // 传入域名错误;
  491. return FALSE;
  492. }
  493. }
  494. // 2.查找早期的固定的原始共享目录;
  495. TCHAR szShareDirectory[MAX_PATH] = {0};
  496. GetLoaclShareDirectory(nPhotoType, szShareDirectory);
  497. TCHAR szOrderPath[MAX_PATH] = {0};
  498. if ( lpDomain == NULL || lpDomain[0] == '\0')
  499. {
  500. // 分店域名空,代表本店;
  501. sprintf(szOrderPath, _T("%s\\%s"), lpOrderNum);
  502. }
  503. else
  504. {
  505. // 若域名非空,则与本店比较,防止域名仍为本店;
  506. if ( strcmp(lpDomain, g_domain) == 0 )
  507. {
  508. // 本店域名;
  509. sprintf(szOrderPath, _T("%s\\%s"), szShareDirectory, lpOrderNum);
  510. }
  511. else
  512. {
  513. sprintf(szOrderPath, _T("%s\\%s\\%s"), szShareDirectory, lpDomain, lpOrderNum);
  514. }
  515. }
  516. // #所有能被找到的共享目录;
  517. CStringArray aryOfOrderDirectory;
  518. if ( PathFileExists(szOrderPath) )
  519. {
  520. aryOfOrderDirectory.Add(szOrderPath);
  521. // 将该订单目录添加到数组中;
  522. LoadSpecifiedDirectoryImages(szOrderPath, AryOfImagePath);
  523. }
  524. // 3.查找NetShareInfo中的共享目录并加载;
  525. int nSize = aryOfOrderDirectory.GetSize();
  526. for ( int i = 0; i < nSize; i++ )
  527. {
  528. if ( nPhotoType != _ttoi(g_aryOfSharePathInfo.ElementAt(i).ElementAt(5)) )
  529. {
  530. continue;
  531. }
  532. // 遍历所有共享路径;
  533. sprintf(szShareDirectory, _T("%s"), g_aryOfSharePathInfo.ElementAt(i).ElementAt(2));
  534. if (lpDomain && strcmp(lpDomain,"") != 0)
  535. {
  536. sprintf(szOrderPath, _T("%s\\%s\\%s"), szShare,lpDomain, lpOrderNum);
  537. }
  538. else
  539. {
  540. sprintf(szOrderPath, _T("%s\\%s"), szShare, lpOrderNum);
  541. }
  542. if ( PathFileExists(szOrderPath) )
  543. {
  544. aryOfOrderDirectory.Add(szOrderPath);
  545. LoadSpecifiedDirectoryImages(szOrderPath, AryOfImagePath);
  546. }
  547. }
  548. return TRUE;
  549. }
  550. /************************************************************************/
  551. /*
  552. 函数:LoadSpecifiedDirectory
  553. 描述:加载指定目录的相片;
  554. 参数:
  555. IN:lpSpecifiedDirectory 指定的目录;
  556. IN:AryOfImage 要查找的相片名;
  557. 返回:
  558. 注意:
  559. 调用约定:
  560. */
  561. /************************************************************************/
  562. int LoadSpecifiedDirectoryImages(IN LPCTSTR lpSpecifiedDirectory, IN CStringArray &AryOfImage, OUT CStringArray &AryOfImagePath)
  563. {
  564. // 1.判定目录有效性;
  565. if ( lpSpecifiedDirectory == NULL || strcmp(lpSpecifiedDirectory,_T("")) == 0)
  566. {
  567. // 目录无效;
  568. return -1;
  569. }
  570. using namespace helper_coffs;
  571. ffsco o;
  572. o.dirs(1);
  573. o.find(lpSpecifiedDirectory, LPCSTR("*.*"));
  574. ffsco::typeT cfs;
  575. ffsco::typeT::iterator it;
  576. cfs = o.co_file();
  577. CString strName;
  578. for (it = cfs.begin(); cfs.end() != it; it++)
  579. {
  580. // 去除目录级文件;
  581. // 去除ok文件;
  582. // 去除modifytime文件;
  583. // 去除s+m缩略图;
  584. strName = it->c_str();
  585. strName.MakeLower();
  586. if ( strName.Find('.') == -1)
  587. {
  588. it = cfs.erase(it);
  589. continue;
  590. }
  591. else
  592. {
  593. CString str = strName.Mid( strName.ReverseFind('\\') + 1 );
  594. if ( str.Find('.') == -1)
  595. {
  596. it = cfs.erase(it);
  597. continue;
  598. }
  599. }
  600. // 如果在相片前或后加修饰,都会有bug,最佳做法是缩略图放在另一子文件夹中;\
  601. // 产生的bug:使用原名导入相片时,相片名可能第一个字母就是s或m;
  602. if ( strName.GetAt( strName.ReverseFind('\\') + 1 ) == 's' ){
  603. it = cfs.erase(it);
  604. continue;
  605. }
  606. if ( strName.GetAt( strName.ReverseFind('\\') + 1 ) == 'm' ){
  607. it = cfs.erase(it);
  608. continue;
  609. }
  610. if ( strName.Find(_T(".jpg")) == -1 ){
  611. it = cfs.erase(it);
  612. continue;
  613. }
  614. }
  615. // AryOfImage 从尾部开始查找,查找成功后并删除,最终查找完全部共享目录都没找到的,就是相片不存在;
  616. for ( it = cfs.begin(); it != cfs.end(); it++ )
  617. {
  618. strName = it->c_str();
  619. for ( int i = AryOfImage.GetSize() - 1; i > -1; i--)
  620. {
  621. if ( strName.CompareNoCase(AryOfImage.ElementAt(i)) == 0 )
  622. {
  623. }
  624. }
  625. }
  626. }
  627. /************************************************************************/
  628. /*
  629. 函数:LoadSpecifiedImagesDirectory
  630. 描述:加载指定相片类型、订单、域名的相片名的共享路径;
  631. 参数:
  632. IN:
  633. IN:
  634. IN:
  635. IN:
  636. OUT:
  637. 返回:
  638. 注意:
  639. 示例:
  640. */
  641. /************************************************************************/
  642. BOOL LoadSpecifiedImagesDirectory(IN CONST INT &nPhotoType, IN LPCTSTR lpOrderNum, IN LPCTSTR lpDomain, IN CStringArray &AryOfImage, OUT CStringArray &AryOfImagePath)
  643. {
  644. // 若域名非空,判断域名有效性;
  645. if ( lpDomain && strcmp(lpDomain,_T("")) != 0 )
  646. {
  647. TCHAR *szResult = strstr(lpDomain,_T(".ly.com"));
  648. return FALSE;
  649. }
  650. // 2.查找早期的固定的原始共享目录;
  651. TCHAR szShareDirectory[MAX_PATH] = {0};
  652. GetLoaclShareDirectory(nPhotoType, szShareDirectory);
  653. TCHAR szOrderPath[MAX_PATH] = {0};
  654. if ( lpDomain == NULL || lpDomain[0] == '\0')
  655. {
  656. // 分店域名空,代表本店;
  657. sprintf(szOrderPath, _T("%s\\%s"), lpOrderNum);
  658. }
  659. else
  660. {
  661. // 若域名非空,则与本店比较,防止域名仍为本店;
  662. if ( strcmp(lpDomain, g_domain) == 0 )
  663. {
  664. // 本店域名;
  665. sprintf(szOrderPath, _T("%s\\%s"), szShareDirectory, lpOrderNum);
  666. }
  667. else
  668. {
  669. sprintf(szOrderPath, _T("%s\\%s\\%s"), szShareDirectory, lpDomain, lpOrderNum);
  670. }
  671. }
  672. int nSize = 0;
  673. CString strImage = _T("");
  674. AryOfImagePath.RemoveAll(); // 清除数组;
  675. // #所有能被找到的共享目录;
  676. if ( PathFileExists(szOrderPath) )
  677. {
  678. nSize = AryOfImage.GetSize();
  679. for ( int i = 0; i < nSize; i++ )
  680. {
  681. strImage.Format(_T("%s\\%s.jpg"), lpOrderNum, AryOfImage.ElementAt(i));
  682. // 如果指定相片名的相片存在,记录路径;
  683. if ( PathFileExists(strImage) )
  684. {
  685. AryOfImagePath.Add(strImage);
  686. }
  687. }
  688. }
  689. //////////////////////////////////////////////////////////////////////////
  690. // 查找其他共享目录是否存在订单文件夹;
  691. nSize = g_aryOfSharePathInfo.GetSize();
  692. for ( int i = 0; i < nSize; i++)
  693. {
  694. if ( nPhotoType != atoi(g_aryOfSharePathInfo.ElementAt(i).ElementAt(5)) )
  695. {
  696. continue;
  697. }
  698. // 逐一加载其他共享目录;
  699. sprintf(szShareDirectory, _T("%s"), g_aryOfSharePathInfo.ElementAt(i).ElementAt(2));
  700. if (lpDomain && strcmp(lpDomain,"") != 0)
  701. {
  702. sprintf(szOrderPath, _T("%s\\%s\\%s"), szShareDirectory, lpDomain, lpOrderNum);
  703. }
  704. else
  705. {
  706. sprintf(szOrderPath, _T("%s\\%s"), szShareDirectory, lpOrderNum);
  707. }
  708. if ( !PathFileExists(szOrderPath))
  709. {
  710. continue;
  711. }
  712. for ( int n = 0; n < AryOfImage.GetSize(); n++)
  713. {
  714. strImage.Format(_T("%s\\%s.jpg"), szOrderPath, AryOfImage.ElementAt(n));
  715. if ( PathFileExists(strImage) )
  716. {
  717. AryOfImagePath.Add(strImage);
  718. }
  719. }
  720. }
  721. return TRUE;
  722. }