ImportPhoto.cpp 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. // ImportPhoto.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "ImportPhoto.h"
  6. #include "MyLock.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. ImportPhoto::ImportPhoto(CWnd* pParent ): CDialog(ImportPhoto::IDD, pParent)
  14. {
  15. m_mode = 0;
  16. m_pArray2 = NULL;
  17. m_pDesArray = NULL;
  18. m_exitcode = 0;
  19. m_bOverWrite = 1;
  20. m_bBeautifySkinFrom = 0;
  21. m_bOrigin = 0;
  22. m_bSaveUploadTask = 0;
  23. m_bCopyToLocal = 0;
  24. m_nOutputSize = 0;
  25. m_bOfmat = 0;
  26. m_nphototype = -1;
  27. m_bAddname = 0;
  28. beginno = -1;
  29. m_bautono = 1;
  30. }
  31. void ImportPhoto::DoDataExchange(CDataExchange* pDX)
  32. {
  33. CDialog::DoDataExchange(pDX);
  34. DDX_Control(pDX, IDC_PROGRESS1, m_progress);
  35. }
  36. BEGIN_MESSAGE_MAP(ImportPhoto, CDialog)
  37. ON_WM_CLOSE()
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. void ImportPhoto::OnOK()
  41. {
  42. // TODO: Add extra validation here
  43. }
  44. void ImportPhoto::OnCancel()
  45. {
  46. // TODO: Add extra cleanup here
  47. }
  48. //----------------------------------------------------
  49. // remark by Jeff 2014.12.11 pm
  50. // 函数:GetFileNo
  51. // 描述:从订单文件夹中获取相片文件的最大编号值;
  52. // 参数:dir 订单文件夹;
  53. // 返回:返回订单文件夹中文件编号最大的值+1;
  54. //
  55. // 如果使用相片名来保存,就不需要这一步了;
  56. //----------------------------------------------------
  57. int ImportPhoto::GetFileNo(CString strOrderFolder)
  58. {
  59. if (m_bautono == 0)
  60. {
  61. int a = beginno;
  62. beginno++;
  63. return a;
  64. }
  65. CString path;
  66. CString path2;
  67. CString path3;
  68. CString path4;
  69. int begin = 1;
  70. CString temp;
  71. CStringArray array;
  72. // 1.查找订单文件夹下的所有文件夹,包括子文件夹下的文件夹;
  73. using namespace helper_coffs;
  74. ffsco o;
  75. o.dirs(1); // 子文件夹也查找;
  76. o.find(LPCSTR(strOrderFolder), LPCSTR("*.*"));
  77. ffsco::typeT coo;
  78. ffsco::typeT::iterator it;
  79. coo = o.co_dir();
  80. for (it = coo.begin(); coo.end() != it; it++)
  81. {
  82. temp = (*it).c_str();
  83. if (::FindArray(&array, temp) == -1)
  84. array.Add(temp);
  85. }
  86. // 2.查找出订单文件夹下最大编号值的相片名;
  87. BOOL bFind = 1;
  88. while (bFind)
  89. {
  90. bFind = 0;
  91. for (int i = 0; i < array.GetSize(); i++)
  92. {
  93. strOrderFolder = array.ElementAt(i);
  94. path.Format("%s%03d.jpg", strOrderFolder, begin);
  95. path2.Format("%s%03d.raw", strOrderFolder, begin);
  96. path3.Format("%s%03d.cr2", strOrderFolder, begin);
  97. path4.Format("%s%03d.NEF", strOrderFolder, begin);
  98. //while (PathFileExists(path) || PathFileExists(path2) || PathFileExists(path3) || PathFileExists(path4))PathFileExists
  99. while (PathFileExists(path) || PathFileExists(path2) || PathFileExists(path3) || PathFileExists(path4))
  100. {
  101. begin++;
  102. path.Format("%s%03d.jpg", strOrderFolder, begin);
  103. path2.Format("%s%03d.raw", strOrderFolder, begin);
  104. path3.Format("%s%03d.cr2", strOrderFolder, begin);
  105. path4.Format("%s%03d.NEF", strOrderFolder, begin);
  106. bFind = 1;
  107. }
  108. }
  109. }
  110. // 3.返回找到的最大编号值+1;
  111. beginno = begin + 1;
  112. return begin;
  113. }
  114. void FilterFileName(CString &str)
  115. {
  116. //printf("Jeff:保存目录old:%s\n\n",str);
  117. ///\:*?"<>|
  118. str.Replace("/", "");
  119. str.Replace("\\", "");
  120. str.Replace(":", "");
  121. str.Replace("*", "");
  122. str.Replace("?", "");
  123. str.Replace("\"", "");
  124. str.Replace("<", "");
  125. str.Replace(">", "");
  126. str.Replace("|", "");
  127. //printf("Jeff:保存目录last:%s\n\n",str);
  128. }
  129. UINT ImportPhotoThread(LPVOID lpParameter)
  130. {
  131. ImportPhoto *pThis = (ImportPhoto*)lpParameter;
  132. pThis->m_progress.SetRange(0, pThis->m_pArray->GetSize());
  133. CString filename, filename2;
  134. CString temp;
  135. int pos;
  136. BOOL bNeedGet;
  137. CString temp2;
  138. int fileno;
  139. INT nIndex = -1;
  140. if (pThis->m_pArray2) // m_pArray2:产品名;
  141. {
  142. if (pThis->m_bAddname) // 相片名包含产品名:不生成产品文件夹;
  143. {
  144. for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
  145. {
  146. filename = pThis->m_pArray->ElementAt(i);
  147. temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
  148. pos = temp.Find(".");
  149. temp = temp.Left(pos);
  150. temp += "(" + pThis->m_name + ",";
  151. temp2 = pThis->m_pArray2->ElementAt(i) + ").jpg";
  152. FilterFileName(temp2);
  153. // Jeff.add:拷贝文件失败,未做处理,最起码要日志记录失败原因;
  154. ::CopyFile(filename, pThis->m_savepath + temp + temp2, pThis->m_bOverWrite == 0);
  155. pThis->m_progress.SetPos(i + 1);
  156. }
  157. }
  158. else // 相片名不包含产品,另外生成产品文件夹。
  159. {
  160. for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
  161. {
  162. filename = pThis->m_pArray->ElementAt(i); //相片文件
  163. if(filename == _T(""))
  164. continue;
  165. filename2 = pThis->m_pArray2->ElementAt(i); //要导出的商品集
  166. pos = filename2.Find(";");
  167. while (pos != -1)
  168. {
  169. temp = filename2.Left(pos);
  170. FilterFileName(temp);
  171. filename2 = filename2.Right(filename2.GetLength() - pos - 1);
  172. pos = filename2.Find(";");
  173. // Jeff:生成产品文件夹,然后将与之关联的所有相片都复制一份.
  174. ::CreateDirectory(pThis->m_savepath + temp, NULL);
  175. pThis->MyCopyFile(filename, pThis->m_savepath + temp + filename.Right(filename.GetLength() - filename.ReverseFind('\\')), pThis->m_bOverWrite == 0);
  176. temp2 = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
  177. int pos2 = temp2.Find(".");
  178. if (pos2 != -1)
  179. {
  180. temp2 = temp2.Left(pos2);
  181. CString filename2;
  182. }
  183. }
  184. temp = filename2;
  185. FilterFileName(temp);
  186. ::CreateDirectory(pThis->m_savepath + temp, NULL);
  187. pThis->MyCopyFile(filename, pThis->m_savepath + temp + filename.Right(filename.GetLength() - filename.ReverseFind('\\')), pThis->m_bOverWrite == 0);
  188. temp2 = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
  189. pos = temp2.Find(".");
  190. if (pos != -1)
  191. {
  192. temp2 = temp2.Left(pos);
  193. }
  194. pThis->m_progress.SetPos(i + 1);
  195. }
  196. }
  197. }
  198. else if (pThis->m_pDesArray)
  199. {
  200. for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
  201. {
  202. filename = pThis->m_pArray->ElementAt(i);
  203. if (pThis->m_mode == 2)
  204. {
  205. temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
  206. pos = temp.Find(".");
  207. bNeedGet = 1;
  208. if (bNeedGet)// && (g_serverbak!="localserver"))
  209. filename2.Format("%s%03d.jpg", pThis->m_savepath, pThis->GetFileNo(pThis->m_calnopath));
  210. else
  211. filename2.Format("%s%s.jpg", pThis->m_savepath, temp);
  212. pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite == 0);
  213. }
  214. else
  215. pThis->MyCopyFile(filename, pThis->m_pDesArray->ElementAt(i), pThis->m_bOverWrite == 0);
  216. pThis->m_progress.SetPos(i + 1);
  217. }
  218. }
  219. //-----------------------------------------------------------------
  220. //-----------------------------------------------------------------
  221. // 1.拍照导入原片;
  222. // 2.初修导出原片;
  223. // 3.初修导入修好的修片;
  224. // 4.初修导出修好的片;
  225. // 5.选片缓存到本机;
  226. else
  227. {
  228. for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
  229. {
  230. // filename源文件的文件名;
  231. filename = pThis->m_pArray->ElementAt(i);
  232. // 在导入原片时,该值m_mode=2;
  233. // 在初修导出原片时,该值m_mode=1;
  234. // 选片缓存到梧桐时,m_mode=1;
  235. if (pThis->m_mode == 2)
  236. {
  237. // 得到相片的后缀名ext;
  238. CString ext = filename.Right(filename.GetLength() - filename.ReverseFind('.') - 1);
  239. if (0)//g_serverbak=="localserver")
  240. {
  241. temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
  242. filename2.Format("%s%s", pThis->m_savepath, temp);
  243. }
  244. else
  245. {
  246. // 在导入原片时,m_calnopath其实就是订单文件夹;
  247. // 从订单文件夹里获取最大的相片名编号值+1;
  248. // 这一步过于蛋痛!
  249. fileno = pThis->GetFileNo(pThis->m_calnopath);
  250. // 用最大编号+1重新命名新导入的相片名;
  251. filename2.Format("%s%03d.%s", pThis->m_savepath, fileno, ext);
  252. }
  253. // 新文件名:filename2,原文件名filename;boverwrite==0表示新文件名存在就覆盖;
  254. pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite == 0);
  255. }
  256. else
  257. {
  258. if (pThis->m_bBeautifySkinFrom)//修片导入
  259. {
  260. temp = pThis->m_savepath + filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
  261. pos = temp.ReverseFind('.');
  262. if (pos == -1)continue;
  263. temp = temp.Left(pos);
  264. pos = 0;
  265. filename2.Format("%s.jpg", temp);
  266. pos = 2;
  267. while (::PathFileExists(filename2))
  268. {
  269. filename2.Format("%s-%d.jpg", temp, pos);
  270. pos++;
  271. }
  272. pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite == 0);
  273. }
  274. else
  275. {
  276. if (pThis->m_bOrigin)//原片导出
  277. {
  278. temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
  279. pos = temp.Find(".");
  280. if (pos == -1)continue;
  281. temp = temp.Left(pos);
  282. pThis->MyCopyFile(filename, pThis->m_savepath + filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1), pThis->m_bOverWrite == 0);
  283. }
  284. else
  285. {
  286. if ( -1 != (nIndex = filename.ReverseFind('\\')) )
  287. {
  288. filename2 = pThis->m_savepath + filename.Mid(nIndex+1);
  289. pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite == FALSE);
  290. }
  291. }
  292. }
  293. }
  294. pThis->m_progress.SetPos(i + 1);
  295. }
  296. }
  297. pThis->PostMessage(WM_CLOSE, 0, 0);
  298. return 1;
  299. }
  300. BOOL ImportPhoto::OnInitDialog()
  301. {
  302. CDialog::OnInitDialog();
  303. #if JEFF_TEST_OFF
  304. // Jeff:判断目标路径是否合法;
  305. if ( IsDirectoryLegitimate(m_name) == FALSE)
  306. {
  307. AfxMessageBox("目标路径包含创建目录时的非法目录字符'/ \\ : * ? \" < > |',请修改后重新操作!");
  308. return FALSE;
  309. }
  310. #endif
  311. if (m_bCopyToLocal)
  312. SetDlgItemText(IDC_STATIC1, "客照缓存中, 请稍候...");
  313. else if (m_mode == 1)
  314. SetDlgItemText(IDC_STATIC1, "正在导出客照, 请稍候...");
  315. #if JEFF_TEST_OFF
  316. HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, ImprotOrExportImageThread, (LPVOID)this, 0, NULL);
  317. CloseHandle(hThread);
  318. #endif
  319. if (beginno != -1 && beginno != 0)
  320. {
  321. m_bautono = 0;
  322. }
  323. AfxBeginThread((AFX_THREADPROC)ImportPhotoThread, (LPVOID)this);
  324. return TRUE;
  325. }
  326. void SaveTaskPath(CString pathname)
  327. {
  328. return;
  329. CString path = g_path1 + "\\taskpath.dat";
  330. CStringArray array;
  331. CFile fp;
  332. if (::PathFileExists(path))
  333. {
  334. try
  335. {
  336. int trycount = 5;
  337. while (1)
  338. {
  339. if (fp.Open(path, CFile::modeRead | CFile::shareExclusive))break;
  340. fp.Close();
  341. trycount--;
  342. if (trycount == 0)break;
  343. ::Sleep(1000);
  344. }
  345. if (trycount == 0)
  346. {
  347. if (::PathFileExists(path))return;
  348. }
  349. CArchive ar(&fp, CArchive::load);
  350. array.Serialize(ar);
  351. fp.Close();
  352. }
  353. catch (...)
  354. {
  355. fp.Close();
  356. // AfxMessageBox("读异常");
  357. }
  358. }
  359. array.Add(pathname);
  360. try
  361. {
  362. int trycount = 5;
  363. while (1)
  364. {
  365. if (fp.Open(path, CFile::modeCreate | CFile::modeWrite | CFile::shareExclusive))break;
  366. fp.Close();
  367. trycount--;
  368. if (trycount == 0)break;
  369. ::Sleep(1000);
  370. }
  371. if (trycount == 0)
  372. {
  373. // AfxMessageBox("打开失败2");
  374. return;
  375. }
  376. CArchive ar(&fp, CArchive::store);
  377. array.Serialize(ar);
  378. ar.Close();
  379. fp.Close();
  380. }
  381. catch (...)
  382. {
  383. // AfxMessageBox("写异常");
  384. fp.Close();
  385. }
  386. }
  387. void ImportPhoto::OnClose()
  388. {
  389. #if USE_SHARE_FLORD
  390. // 导入成功后,要写入IncrementalBackup;
  391. // 1.获取相片名,不带后缀;
  392. CString strSQLInsert;
  393. if ( m_nphototype != -1) // 如果是导入相片;
  394. {
  395. int nIndex = 0;
  396. CString AryOfName;
  397. int nSize = 0;
  398. // 上传规则,不应该有dbconfig.dat指向的店铺(假设为分店My) 分店My->分店My;所以这一步应该在界面操作中禁止生成规则;
  399. // 首次插入的必须是dbconfig.dat中指向的数据库地址,不管是否多店汇总或连接分店;
  400. if ( g_bAllBranch ) // 如果是多店汇总;
  401. {
  402. // 保存原值;
  403. BOOL bCurBranchModify = g_bBranchModify;
  404. g_bBranchModify = FALSE;
  405. // 断开之前的连接(有可能之前使用的连接是多店汇总或者连接分店,所以必须断开);
  406. g_pMainWnd->OnDisconnect();
  407. g_branchname = m_branch;
  408. g_branchip = GetIP(m_branch);
  409. // 更新数据到本店数据库中;
  410. g_sendhead.bsql = 1;
  411. g_pMainWnd->ProcessChatMessageRequest2(strSQLInsert); // 有可能发送失败;
  412. if ( !g_bSendOK )
  413. {
  414. //AfxMessageBox(_T("连接服务器失败"));
  415. printf("Jeff:A#多店汇总时连接本店服务器失败\n");
  416. //WriteTextLog(_T("多店汇总时,写增量时连接服务器失败"));
  417. }
  418. g_bBranchModify = bCurBranchModify;
  419. g_branchname = g_branchip = _T("");
  420. }
  421. else if ( g_branchname != _T("") && g_branchip != _T("") ) // 连接分店;
  422. {
  423. // 保存原值;
  424. CString strBranch = g_branchname;
  425. CString strBranchIP = g_branchip;
  426. g_branchname = g_branchip = _T("");
  427. g_bBranchModify = FALSE;
  428. // 断开之前的连接(有可能之前使用的连接是多店汇总或者连接分店,所以必须断开);
  429. g_pMainWnd->OnDisconnect();
  430. // 更新数据到本店数据库中;
  431. g_sendhead.bsql = 1;
  432. g_pMainWnd->ProcessChatMessageRequest2(strSQLInsert); // 有可能发送失败;
  433. if (!g_bSendOK)
  434. {
  435. //AfxMessageBox(_T("连接服务器失败"));
  436. printf("Jeff:B#连接分店时导入相片失败\n");
  437. WriteTextLog(_T("连接分店时,写增量时连接服务器失败"));
  438. }
  439. g_pMainWnd->OnDisconnect();
  440. g_bBranchModify = TRUE;
  441. g_branchname = strBranch;
  442. g_branchip = strBranchIP;
  443. }
  444. else // 连接的是本店;
  445. {
  446. // 更新数据到本店数据库中;
  447. g_sendhead.bsql = 1;
  448. g_pMainWnd->ProcessChatMessageRequest2(strSQLInsert);
  449. if (!g_bSendOK)
  450. {
  451. //AfxMessageBox(_T("连接服务器失败"));
  452. printf("Jeff:C#连接本店时导入相片失败\n");
  453. WriteTextLog(_T("本店连接时,写增量时连接服务器失败"));
  454. }
  455. }
  456. }
  457. #endif
  458. // m_nphototype相片类型:0原片,1初修片,2精修片,3设计片;
  459. if (m_nphototype < 0 || m_nphototype>3)
  460. {
  461. CDialog::OnOK();
  462. return;
  463. }
  464. // m_uploadtaskarray的元素数量不会小于10的;
  465. if (m_uploadtaskarray.GetSize() <= 10)
  466. {
  467. CDialog::OnOK();
  468. return;
  469. }
  470. #ifdef ENTERPRISE_VERSION
  471. // 集团版,是否开启上传功能;
  472. if (m_bSaveUploadTask)
  473. {
  474. // 上传相片的规则,在[version]表中的[uploadrule]字段;
  475. /*
  476. 示例:
  477. "type3@:铁西店->万泰店(总店)%$铁西店->219店%$219店->219店%$金色店->金色店%$万泰店(总店)->万泰店(总店)%$万泰店(总店)->219店%$\
  478. type0@:铁西店->219店%$铁西店->万泰店(总店)%$219店->219店%$金色店->金色店%$万泰店(总店)->万泰店(总店)%$万泰店(总店)->219店%$\
  479. type2@:铁西店->219店%$铁西店->万泰店(总店)%$铁西店->金色店%$219店->219店%$万泰店(总店)->万泰店(总店)%$金色店->金色店%$"
  480. */
  481. CString m_rule = g_cominfoarraylocal.ElementAt(0).ElementAt(116);
  482. CString m_header, m_left, m_right, m_currule;
  483. CStringArray rulearray;
  484. if (m_nphototype == 0)
  485. {
  486. m_header = "type0@:";
  487. }
  488. else if (m_nphototype == 1)
  489. {
  490. m_header = "type1@:";
  491. }
  492. else if (m_nphototype == 2)
  493. {
  494. m_header = "type2@:";
  495. }
  496. else if (m_nphototype == 3)
  497. {
  498. m_header = "type3@:";
  499. }
  500. int pos = m_rule.Find(m_header);
  501. if (pos != -1)
  502. {
  503. m_left = m_rule.Left(pos);
  504. m_rule = m_rule.Right(m_rule.GetLength() - pos);
  505. m_rule.Delete(0, m_header.GetLength());
  506. pos = m_rule.Find("@:");
  507. if (pos != -1)
  508. {
  509. m_right = m_rule.Right(m_rule.GetLength() - pos + 5);
  510. m_rule = m_rule.Left(pos - 5);
  511. }
  512. // m_rule的最终结果如:
  513. // 铁西店->万泰店(总店)%$铁西店->219店%$219店->219店%$金色店->金色店%$万泰店(总店)->万泰店(总店)%$万泰店(总店)->219店%$
  514. m_currule = m_rule;
  515. m_rule.Empty();
  516. m_currule.TrimLeft("%$");
  517. m_currule.TrimRight("%$");
  518. // 铁西店->万泰店(总店)%$铁西店->219店%$219店->219店%$金色店->金色店%$万泰店(总店)->万泰店(总店)%$万泰店(总店)->219店
  519. if (m_currule.Find("%$") != -1)
  520. {
  521. pos = m_currule.Find("%$");
  522. while (pos != -1)
  523. {
  524. if (m_currule.Left(pos) != "")rulearray.Add(m_currule.Left(pos));
  525. m_currule = m_currule.Right(m_currule.GetLength() - pos - 2);
  526. pos = m_currule.Find("%$");
  527. }
  528. }
  529. if (m_currule != "")rulearray.Add(m_currule);
  530. }
  531. for (int i = 0; i < rulearray.GetSize(); i++)
  532. {
  533. m_currule = rulearray.ElementAt(i);
  534. pos = m_currule.Find("->");
  535. if (pos == -1)continue;
  536. m_left = m_currule.Left(pos);
  537. m_right = m_currule.Right(m_currule.GetLength() - pos - 2);
  538. CString curdomain, curdomain2;
  539. // m_branch分店名称,如果"铁西店",表明在使用"多店汇总"菜单;
  540. if (m_branch != "")
  541. {
  542. curdomain = GetDomainFromBranch(m_branch);
  543. curdomain2 = GetDomainFromBranch(g_brancharray.ElementAt(g_brancharray.GetSize() - 1).ElementAt(0));
  544. }
  545. else if (g_branchname != "")// 表示在使用"连接铁西分店"菜单;
  546. {
  547. curdomain = GetDomainFromBranch(g_branchname);
  548. curdomain2 = GetDomainFromBranch(g_brancharray.ElementAt(g_brancharray.GetSize() - 1).ElementAt(0));
  549. }
  550. else// 表示连接的是本店;
  551. {
  552. curdomain = GetDomainFromBranch(g_brancharray.ElementAt(g_brancharray.GetSize() - 1).ElementAt(0));
  553. curdomain2 = curdomain;
  554. }
  555. // 源域名;
  556. CString domainleft = GetDomainFromBranch(m_left);
  557. if (curdomain != domainleft)
  558. {
  559. continue;
  560. }
  561. // 目标域名;
  562. CString domainright = GetDomainFromBranch(m_right);
  563. if (domainleft.Find(".ly.com") == -1 || domainright.Find(".ly.com") == -1)
  564. {
  565. continue;
  566. }
  567. if (curdomain2 == domainright)
  568. {
  569. continue;
  570. }
  571. MyLock lock("uploadtaskaccess");
  572. // m_uploadtaskarray 元素0 = 订单号+顾客名称;
  573. m_uploadtaskarray.SetAt(1, domainright); // 目标域名;
  574. m_uploadtaskarray.SetAt(2, domainleft); // 源域名;
  575. m_uploadtaskarray.SetAt(3, m_sel); // 压缩像素的值;
  576. CFile fp;
  577. CString pathdir = m_savepath + "uploadtask";
  578. //printf("Jeff:pathdir: %s\n", pathdir);
  579. if (m_id != "")
  580. {
  581. int pos = pathdir.Find(m_id);
  582. pos += m_id.GetLength();
  583. int pos2 = pathdir.ReverseFind('\\');
  584. pathdir = pathdir.Left(pos) + pathdir.Right(pathdir.GetLength() - pos2);
  585. }
  586. CString path;
  587. int taskpos = 1;
  588. path.Format("%s%d.dat", pathdir, taskpos);
  589. CString dir = path.Left(path.ReverseFind('\\') + 1);
  590. pathdir = g_path1 + "\\上传任务\\";
  591. //printf("Jeff:pathdir: %s\n", pathdir);
  592. ::CreateDirectory(pathdir, NULL);
  593. path.Format("%s%d.dat", pathdir, taskpos);
  594. while (PathFileExists(path))
  595. {
  596. taskpos++;
  597. path.Format("%s%d.dat", pathdir, taskpos);
  598. printf("Jeff:path: %s\n", path);
  599. }
  600. fp.Open(path, CFile::modeCreate | CFile::modeWrite);
  601. CArchive ar(&fp, CArchive::store);
  602. //printf("Jeff:dir: %s\n", dir);
  603. m_uploadtaskarray.SetAt(4, dir); // 相片所在的路径;
  604. m_uploadtaskarray.Serialize(ar); // 最后将m_uploadtaskarray序列化;
  605. ar.Close();
  606. fp.Close();
  607. // SaveTaskPath(path);
  608. #if USE_SHARE_FLORD
  609. // 2015-07-02 根据上传分店规则,为每个要上传的任务写IncrementalBackup到分店中;
  610. // 分店A,分店B,总店S.
  611. // 在分店A中导入分店B的订单B001,分店A的上传规则:分店A->分店S,分店B->分店B,分店B->总店S.
  612. // 那么本次订单B001同时要上传至分店B和总店S中;
  613. // 1.在这里切换多个分店服务端的连接;2.在FTP客户端中连接多家分店数据库;
  614. // 如果用户不使用FTP来上传相片,那么远程分店是无法按增量来备份的;
  615. //WriteTextLog(_T("写入分店增量:") + strSQLInsert);
  616. if ( g_bAllBranch && m_branch != "" ) // 多店汇总;
  617. {
  618. // 断开之前的连接;
  619. g_pMainWnd->OnDisconnect();
  620. // 更新要连接的服务端;
  621. g_branchname = m_right;
  622. g_branchip = GetIP(m_right);
  623. g_bBranchModify = TRUE;
  624. // 更新数据;
  625. g_sendhead.bsql = 1;
  626. g_pMainWnd->ProcessChatMessageRequest2(strSQLInsert);
  627. if ( !g_bSendOK )
  628. {
  629. //strSQLInsert.Format(_T("连接分店[%s]时失败~"),m_right);
  630. //WriteTextLog(strSQLInsert);
  631. }
  632. // 断开连接;
  633. g_pMainWnd->OnDisconnect();
  634. // 恢复无分店连接状态;
  635. g_bBranchModify = FALSE;
  636. g_branchip = "";
  637. g_branchname = "";
  638. }
  639. else if ( g_branchname != "" ) // 连接分店;
  640. {
  641. if ( !g_branchname.CompareNoCase(m_right) && !g_branchip.CompareNoCase(GetIP(m_right)) )
  642. {
  643. g_sendhead.bsql = 1;
  644. g_pMainWnd->ProcessChatMessageRequest2(strSQLInsert);
  645. }
  646. else
  647. {
  648. CString strCurBranch = g_branchname;
  649. CString strCurBranchIP = g_branchip;
  650. BOOL bCurBranchModify = g_bBranchModify;
  651. // 断开之前的连接;
  652. g_pMainWnd->OnDisconnect();
  653. // 更新要连接的服务端;
  654. g_branchname = m_right;
  655. g_branchip = GetIP(m_right);
  656. g_bBranchModify = TRUE;
  657. // 更新数据;
  658. g_sendhead.bsql = 1;
  659. g_pMainWnd->ProcessChatMessageRequest2(strSQLInsert);
  660. if ( !g_bSendOK )
  661. {
  662. //strSQLInsert.Format(_T("连接分店[%s]时失败~"),m_right);
  663. //WriteTextLog(strSQLInsert);
  664. }
  665. // 断开连接;
  666. g_pMainWnd->OnDisconnect();
  667. // 恢复原分店连接;
  668. g_bBranchModify = bCurBranchModify;
  669. g_branchip = strCurBranchIP;
  670. g_branchname = strCurBranch;
  671. }
  672. }
  673. else // 连接本店;
  674. {
  675. // 断开之前的连接;
  676. g_pMainWnd->OnDisconnect();
  677. // 更新要连接的服务端;
  678. g_branchname = m_right;
  679. g_branchip = GetIP(m_right);
  680. g_bBranchModify = TRUE;
  681. // 更新数据;
  682. g_sendhead.bsql = 1;
  683. g_pMainWnd->ProcessChatMessageRequest2(strSQLInsert);
  684. if ( !g_bSendOK )
  685. {
  686. //strSQLInsert.Format(_T("连接分店[%s]时失败~"),m_right);
  687. //WriteTextLog(strSQLInsert);
  688. }
  689. // 断开连接;
  690. g_pMainWnd->OnDisconnect();
  691. // 恢复本店连接;
  692. g_bBranchModify = FALSE;
  693. g_branchip = "";
  694. g_branchname = "";
  695. }
  696. #endif
  697. }
  698. }
  699. #endif
  700. // CString ss;
  701. //ss.Format ("cc:%d", g_filecount);MessageBox(ss);m_fp.Close ();
  702. CDialog::OnOK();
  703. }
  704. extern void SaveImageToFile(Image *img, CString path);
  705. void ImportPhoto::MyCopyFile(CString file1, CString file2, BOOL bOverWrite)
  706. {
  707. if (::PathFileExists(file1) == 0)
  708. {
  709. return;
  710. }
  711. if (m_bOfmat)
  712. {
  713. CString file1bak = file1;
  714. CString file2bak = file2;
  715. file1bak = file1bak.Left(file1bak.GetLength() - 3);
  716. file2bak = file2bak.Left(file2bak.GetLength() - 3);
  717. file1bak += "jpg";
  718. file2bak += "jpg";
  719. CString src = file1bak;
  720. CString des = file2bak;
  721. src.Replace(".jpg", ".raw");
  722. des.Replace(".jpg", ".raw");
  723. ::CopyFile(src, des, bOverWrite);
  724. src = file1bak;
  725. des = file2bak;
  726. src.Replace(".jpg", ".nef");
  727. des.Replace(".jpg", ".nef");
  728. ::CopyFile(src, des, bOverWrite);
  729. src = file1bak;
  730. des = file2bak;
  731. src.Replace(".jpg", ".cr2");
  732. des.Replace(".jpg", ".cr2");
  733. ::CopyFile(src, des, bOverWrite);
  734. }
  735. if (m_nphototype == 0 || m_nphototype == 1 || m_nphototype == 2 || m_nphototype == 3)
  736. {
  737. CString str = file2;
  738. CString spath = str.Left(str.ReverseFind('\\') + 1);
  739. CString mpath = spath;
  740. spath += "s";
  741. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  742. mpath += "m";
  743. mpath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  744. ::DeleteFile(spath); // 删除s小图;
  745. ::DeleteFile(mpath); // 删除m小图;
  746. }
  747. if (m_nOutputSize)
  748. {
  749. file1.MakeLower();
  750. if (file1.Right(3) == "jpg")
  751. {
  752. Image *img = NULL;
  753. ::LoadImageFromBuf(&img, file1);
  754. if (img == NULL)
  755. {
  756. if (::CopyFile(file1, file2, bOverWrite) == 0)
  757. {
  758. CString str;
  759. str = file1;
  760. int pos = str.ReverseFind('\\');
  761. if (pos != -1)
  762. str = str.Right(str.GetLength() - pos - 1);
  763. AfxMessageBox("拷贝失败" + str + "请重新导入此文件!");
  764. }
  765. }
  766. else if (img->GetWidth() == 0)
  767. {
  768. if (::CopyFile(file1, file2, bOverWrite) == 0)
  769. {
  770. CString str;
  771. str = file1;
  772. int pos = str.ReverseFind('\\');
  773. if (pos != -1)
  774. str = str.Right(str.GetLength() - pos - 1);
  775. AfxMessageBox("拷贝失败" + str + "请重新导入此文件!!");
  776. }
  777. }
  778. else
  779. {
  780. int newsize = m_nOutputSize;
  781. if (img->GetWidth() > newsize || img->GetHeight() > newsize)
  782. {
  783. CRect rc(0, 0, newsize, newsize);
  784. RectFitDes(img->GetWidth(), img->GetHeight(), rc);
  785. Image *simg = img->GetThumbnailImage(rc.Width(), rc.Height(), NULL, NULL);
  786. Graphics graphic(simg);//防止GetThumbnailImage影响质量
  787. graphic.DrawImage(img, 0, 0, simg->GetWidth(), simg->GetHeight());
  788. delete img;
  789. ::SaveImageToFile(simg, file2);
  790. delete simg;
  791. }
  792. else
  793. {
  794. if (::CopyFile(file1, file2, bOverWrite) == 0)
  795. {
  796. CString str;
  797. str = file1;
  798. int pos = str.ReverseFind('\\');
  799. if (pos != -1)
  800. str = str.Right(str.GetLength() - pos - 1);
  801. AfxMessageBox("拷贝失败" + str + "请重新导入此文件!!!");
  802. }
  803. }
  804. }
  805. }
  806. else
  807. {
  808. if (::CopyFile(file1, file2, bOverWrite) == 0)
  809. {
  810. CString str;
  811. str = file1;
  812. int pos = str.ReverseFind('\\');
  813. if (pos != -1)
  814. str = str.Right(str.GetLength() - pos - 1);
  815. AfxMessageBox("拷贝失败" + str + "请重新导入此文件!!!!");
  816. }
  817. }
  818. }
  819. else
  820. {
  821. if (::CopyFile(file1, file2, bOverWrite) == 0)
  822. {
  823. CString str;
  824. str = file1;
  825. int pos = str.ReverseFind('\\');
  826. if (pos != -1)
  827. str = str.Right(str.GetLength() - pos - 1);
  828. AfxMessageBox("拷贝失败" + str + "请重新导入此文件!!!!!");
  829. }
  830. //
  831. if (m_bCopyToLocal)//选片缓存
  832. {
  833. CString path = file2;
  834. CString spath = path.Left(path.ReverseFind('\\') + 1);
  835. spath += "s";
  836. // CString temp=path.Right (path.GetLength ()-path.ReverseFind ('\\')-1);
  837. spath += path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
  838. //if(!PathFileExists (spath))
  839. {
  840. Image *pImg = NULL;
  841. ::LoadImageFromBuf(&pImg, path);
  842. if (pImg == NULL)return;
  843. if (pImg->GetWidth() == 0)return;
  844. CRect rc(0, 0, 100, 90);
  845. RectFitDes(pImg->GetWidth(), pImg->GetHeight(), rc);
  846. Image *simg = pImg->GetThumbnailImage(rc.Width(), rc.Height(), NULL, NULL);
  847. if (simg == NULL)return;
  848. Graphics graphic(simg);//防止GetThumbnailImage影响质量
  849. graphic.Clear(Color(255, 255, 255, 255));
  850. graphic.DrawImage(pImg, 0, 0, simg->GetWidth(), simg->GetHeight());
  851. ///////////////////////////////
  852. UINT totalBufferSize;
  853. UINT numProperties;
  854. pImg->GetPropertySize(&totalBufferSize, &numProperties);
  855. // Allocate the buffer that will receive the property items.
  856. PropertyItem* pAllItems = (PropertyItem*)malloc(totalBufferSize);
  857. // Fill the buffer.
  858. pImg->GetAllPropertyItems(totalBufferSize, numProperties, pAllItems);
  859. // Print the id data member of each property item.
  860. for (UINT j = 0; j < numProperties; ++j)
  861. {
  862. if (PropertyTagOrientation == pAllItems[j].id)
  863. {
  864. short* ptrLong = (short*)(pAllItems[j].value);
  865. int ret = (int)*ptrLong;
  866. // CString str;
  867. // str.Format ("%d", ret);
  868. // AfxMessageBox(str);
  869. if (ret == 8)
  870. {
  871. simg->RotateFlip(Rotate270FlipNone);
  872. }
  873. else if (ret == 6)
  874. {
  875. simg->RotateFlip(Rotate90FlipNone);
  876. }
  877. break;
  878. }
  879. }
  880. free(pAllItems);
  881. ///////////////////////////////
  882. ::SaveImageToFile(simg, spath);
  883. delete simg;
  884. delete pImg;
  885. }
  886. }//选片缓存
  887. }
  888. file2.MakeLower();
  889. if (m_mode != 1 && file2.Right(3) == "jpg")
  890. {
  891. CString path = file2.Left(file2.ReverseFind('\\'));
  892. path.TrimRight("\\"); path += "\\";
  893. path += "modifytime";
  894. CStdioFile fp;
  895. if (::PathFileExists(path))
  896. {
  897. fp.Open(path, CFile::modeWrite);
  898. fp.WriteString(g_date);
  899. fp.Close();
  900. }
  901. else
  902. {
  903. fp.Open(path, CFile::modeCreate | CFile::modeWrite);
  904. fp.WriteString(g_date);
  905. fp.Close();
  906. }
  907. }
  908. #ifdef ENTERPRISE_VERSION
  909. if (m_bSaveUploadTask)
  910. {
  911. if (m_id != "")
  912. {
  913. if (file2.Right(3) == "jpg")
  914. {
  915. int pos = file2.Find(m_id);
  916. pos += m_id.GetLength();
  917. int pos2 = file2.ReverseFind('\\');
  918. // Jeff:获取景点;
  919. CString jd;
  920. if (pos2 > pos)
  921. {
  922. jd = file2.Mid(pos + 1, pos2 - pos - 1);
  923. }
  924. CString task;
  925. if (jd != "")
  926. task = jd + "\\" + file2.Right(file2.GetLength() - pos2 - 1);
  927. else
  928. task = file2.Right(file2.GetLength() - pos2 - 1);
  929. m_uploadtaskarray.Add(task);
  930. m_uploadtaskarray.Add("");
  931. }
  932. }
  933. else
  934. {
  935. if (file2.Right(3) == "jpg")
  936. {
  937. m_uploadtaskarray.Add(file2.Right(file2.GetLength() - m_savepath.GetLength()));
  938. m_uploadtaskarray.Add("");
  939. }
  940. }
  941. }
  942. #endif
  943. }
  944. //*
  945. unsigned int WINAPI ImportPhoto::ImprotOrExportImageThread(LPVOID lp)
  946. {
  947. ImportPhoto *pThis = (ImportPhoto*)lp;
  948. if ( pThis->m_bImportImage )
  949. {
  950. // 初始化工作,并将导入标识写入数据库中;
  951. switch ( pThis->m_ImportOfImageType )
  952. {
  953. case ImageType_Original:
  954. break;
  955. case ImageType_Early:
  956. break;
  957. case ImageType_Further:
  958. break;
  959. case ImageType_Design:
  960. break;
  961. default:
  962. break;
  963. }
  964. // 实参校验;
  965. if ( pThis->m_pArray->GetSize() > 0 && lyfzCreateDirectory(pThis->m_savepath))
  966. lyfzImportImage(pThis->m_savepath, *(pThis->m_pArray));
  967. }
  968. else
  969. {
  970. // 初始化工作;
  971. switch (pThis->m_ExportOfImageType)
  972. {
  973. case ImageType_Original:
  974. break;
  975. case ImageType_Early:
  976. break;
  977. case ImageType_Further:
  978. break;
  979. case ImageType_Design:
  980. default:
  981. break;
  982. }
  983. }
  984. return 0;
  985. }