ImportPhoto.cpp 28 KB

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