ImportPhoto.cpp 28 KB

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