CPhotoFTPSendDlg.cpp 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108
  1. // CPhotoFTPSendDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CPhotoFTPSend.h"
  5. #include "CPhotoFTPSendDlg.h"
  6. //#include "FTPSend.h"
  7. #include "FTPSend2.h"
  8. #include <process.h>
  9. #include "MyLock.h"
  10. #include "Shlwapi.h"
  11. #include "./helper/ffsco.h"
  12. #include "SetDlg.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. int g_port=21;
  19. int g_nFail=0;
  20. CStringArray g_connedip; // 与g_pSend成对;
  21. // g_servrip与g_failcount是成对出现的;同一索引元素位置一一对应;
  22. CStringArray g_serverip;
  23. CArray<int,int>g_failcount;
  24. CCPhotoFTPSendDlg *g_pMainWnd=NULL;
  25. CString g_mainpath;
  26. extern CFont g_listctrlfont;
  27. //#define IPC_CUSTOM_MSG3 _T("{D4F876E2-w78F-22D5-q98A-Y0B0D07B8AAA}")
  28. #define IPC_CUSTOM_MSG3 _T("{E4F876E2-Q78F-22D5-C98A-Y0B0D07B8AAA}")
  29. UINT g_wmClose2 = RegisterWindowMessage(IPC_CUSTOM_MSG3);
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CCPhotoFTPSendDlg
  32. #pragma comment(lib, "Shlwapi.lib")
  33. #define WM_ICON_NOTIFY WM_USER+12
  34. BOOL g_check1=1;
  35. int g_num=5;
  36. void WriteLogin(CString str)
  37. {
  38. MyLock lock("PhotoFTPSendLogfile");
  39. try
  40. {
  41. CStdioFile fp;
  42. CString path=g_mainpath+"\\CPhotoFTPSend.log";
  43. if(::PathFileExists (path))
  44. {
  45. fp.Open (path, CFile::modeWrite);
  46. int length=fp.GetLength ();
  47. if(length>1024*1024)
  48. {
  49. fp.Close ();
  50. ::DeleteFile (path);
  51. return;
  52. }
  53. fp.SeekToEnd ();
  54. }
  55. else
  56. fp.Open (path, CFile::modeCreate|CFile::modeWrite);
  57. fp.WriteString (CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S")+" "+str+"\r\n" );
  58. fp.Close ();
  59. }
  60. catch(...)
  61. {
  62. }
  63. }
  64. int FindArray(CStringArray *pArray, CString Str)
  65. {
  66. for(int i=0; i<pArray->GetSize (); i++)
  67. {
  68. if(pArray->ElementAt (i)==Str)
  69. return i;
  70. }
  71. return -1;
  72. }
  73. void LoadBranchInfo(CArray<CStringArray, CStringArray>*pList1array)
  74. {
  75. MyLock lock("savebranchinfo");
  76. CFile fp;
  77. CString path=g_mainpath+"\\branchinfo.dat";
  78. if(::PathFileExists (path)==0)
  79. {
  80. return;
  81. }
  82. fp.Open (path, CFile::modeRead);
  83. DWORD leng=fp.GetLength ();
  84. if(leng<sizeof(DWORD)*2)
  85. {
  86. fp.Close ();return;
  87. }
  88. DWORD flag;
  89. fp.Seek(-(int)sizeof(DWORD),CFile::end);
  90. fp.Read (&flag, sizeof(DWORD));
  91. //if(flag!=889900)
  92. if(flag!=889900)
  93. {
  94. fp.Close ();return;
  95. }
  96. fp.SeekToBegin ();
  97. DWORD arraysize;
  98. fp.Read (&arraysize, sizeof(DWORD));
  99. BYTE *pData=new BYTE[leng-sizeof(DWORD)];
  100. fp.Read (pData,leng-sizeof(DWORD));
  101. fp.Close ();
  102. CMemFile memfile;
  103. memfile.Attach (pData,leng-sizeof(DWORD));
  104. CArchive ar(&memfile, CArchive::load);
  105. pList1array->RemoveAll ();
  106. pList1array->SetSize(arraysize, 1);
  107. for(int ii=0; ii<pList1array->GetSize (); ii++)
  108. {
  109. pList1array->ElementAt (ii).Serialize (ar);
  110. }
  111. ar.Close();
  112. memfile.Detach ();
  113. delete []pData;
  114. }
  115. void MySleep(int s)
  116. {
  117. int step=2000;
  118. int count=s/step;
  119. for(int i=0; i<count; i++)
  120. {
  121. if(g_pMainWnd->m_bTerminate)break;
  122. if(g_pMainWnd->m_bTerminate2)break;
  123. ::Sleep (step);
  124. }
  125. }
  126. void LoadTaskFromFile(CString path, CStringArray *array)
  127. {
  128. MyLock lock("uploadtaskaccess");
  129. CFile fp;
  130. if(fp.Open (path, CFile::modeRead))
  131. {
  132. DWORD length=fp.GetLength ();
  133. if(!length)return;
  134. CArchive ar(&fp, CArchive::load);
  135. array->Serialize (ar);
  136. fp.Close ();
  137. }
  138. else
  139. WriteLogin("读取任务"+path+"失败!");
  140. }
  141. void SaveUploadFileStaus(CString path, CStringArray *array)
  142. {
  143. MyLock lock("uploadtaskaccess");
  144. CFile fp;
  145. if(fp.Open (path, CFile::modeCreate|CFile::modeWrite))
  146. {
  147. CArchive ar(&fp, CArchive::store);
  148. array->Serialize (ar);
  149. ar.Close();
  150. fp.Close ();
  151. }
  152. else
  153. WriteLogin("保存已发"+path+"失败!");
  154. }
  155. /************************************************************************/
  156. /*
  157. /* 函数:GetIDFromInfo
  158. /* 描述:dat上传任务文件返回的CString对象中获取信息;
  159. /* 参数:
  160. /* info dat文件序列化后返回的CString对象;
  161. /* taskpath dat文件路径;
  162. /* id dat文件对应的订单号;
  163. /* type dat文件要上传的相片类型;
  164. /* 返回:
  165. */
  166. /************************************************************************/
  167. void GetIDFromInfo(CString info , CString taskpath , CString &id, CString &type )
  168. {
  169. CString g_path1;
  170. CString g_path2;
  171. CString g_path3;
  172. CString g_path4;
  173. g_path1="\\客户原片(管理软件)$";
  174. g_path2="\\修好的片(管理软件)$";
  175. g_path3="\\设计好的片(管理软件)$";
  176. g_path4="\\精修好的片(管理软件)$";
  177. if(taskpath.Find(g_path1)!=-1)type= "原片";
  178. if(taskpath.Find(g_path2)!=-1)type= "初修片";
  179. if(taskpath.Find(g_path3)!=-1)type= "设计片";
  180. if(taskpath.Find(g_path4)!=-1)type= "精修片";
  181. int pos=info.Find (";");
  182. if(pos!=-1)id=info.Left (pos);
  183. }
  184. CString g_taskpath[MAX_THREAD]={""};
  185. BOOL g_bActive[MAX_THREAD]={1};
  186. CFTPSend2 *g_pSend[MAX_THREAD]={NULL};
  187. unsigned __stdcall ProcessTask(LPVOID lpParam)
  188. {
  189. int pos=int(lpParam);
  190. CString taskpath=g_taskpath[pos];
  191. if(taskpath.IsEmpty ())
  192. {
  193. goto ll;
  194. }
  195. // 任务文件存在,设置界面为等待中....
  196. if(::PathFileExists (taskpath))
  197. {
  198. CString path=taskpath;
  199. g_pMainWnd->ModifyStaus(path, "等待中...");
  200. CStringArray m_uploadtaskarray;
  201. LoadTaskFromFile(path, &m_uploadtaskarray);
  202. if(m_uploadtaskarray.GetSize()<10)
  203. {
  204. WriteLogin("读取任务"+path+"失败!!");
  205. goto ll;
  206. }
  207. CString dir=path.Left (path.ReverseFind ('\\')+1);
  208. CString clientid,filepath,filename,status,phototype;
  209. CString dirinfile=m_uploadtaskarray.ElementAt (4); // 4 = 相片所在根目录;
  210. if(dirinfile!="")dir=dirinfile;
  211. GetIDFromInfo(m_uploadtaskarray.ElementAt (0), dir, clientid, phototype); // 0 = 订单号;顾客;
  212. CString domain=m_uploadtaskarray.ElementAt (1); // 目录域名;
  213. CString savedomain=m_uploadtaskarray.ElementAt (2); // 源域名;
  214. WriteTextLog("%s,%s,%s,%s,%s,%s,%s,%s",
  215. m_uploadtaskarray.ElementAt(0),
  216. m_uploadtaskarray.ElementAt(1),
  217. m_uploadtaskarray.ElementAt(2),
  218. m_uploadtaskarray.ElementAt(3),
  219. m_uploadtaskarray.ElementAt(4),
  220. m_uploadtaskarray.ElementAt(5),
  221. m_uploadtaskarray.ElementAt(6),
  222. m_uploadtaskarray.ElementAt(7));
  223. if(savedomain==domain)savedomain="";
  224. CString ziptype=m_uploadtaskarray.ElementAt (3); // 压缩像素;
  225. int typepos=ziptype.Find ("x");
  226. if(typepos==-1)
  227. ziptype="";
  228. else
  229. ziptype.Left (typepos);
  230. CString ip,hskip;
  231. // 目标域名不为空时,传域名;
  232. if(domain!="")
  233. ip=g_pMainWnd->GetBranchIP(domain,hskip);
  234. else // 目标域名空时,传任务路径;
  235. ip=g_pMainWnd->GetBranchIP(dir,hskip);
  236. // 记录pos索引所在任务的连接ip;
  237. g_connedip.SetAt (pos, ip);
  238. if(::FindArray (&g_serverip, ip)==-1)
  239. {
  240. g_serverip.Add (ip);
  241. g_failcount.Add (0);
  242. }
  243. if(clientid.IsEmpty () || phototype.IsEmpty ())
  244. goto ll;
  245. // 获取ftp的登陆用户和密码;
  246. CString user,pass;
  247. g_pMainWnd->GetUserPswFromPhotoType(phototype, user, pass);
  248. CFTPSend2 *pftp=NULL;
  249. g_pSend[pos]=pftp;
  250. // 从第10个开始,j+=2的原因是:j=路径,j+1=上传状态;
  251. for(int j=10; j<m_uploadtaskarray.GetSize(); j+=2)
  252. {
  253. if(g_pMainWnd->m_bTerminate)
  254. break;
  255. if(g_pMainWnd->m_bTerminate1[pos])
  256. break;
  257. if(g_pMainWnd->IsStatusPause(path))
  258. break;
  259. g_pMainWnd->ModifyStaus(path, "上传中");
  260. // 获取上传文件路径;
  261. filename=m_uploadtaskarray.ElementAt(j);
  262. filepath=dir+filename;
  263. // 获取上传文件上传状态;
  264. status=m_uploadtaskarray.ElementAt(j+1);
  265. if(status=="OK")
  266. continue;
  267. // 如果上传文件为ok2.dat,表示上传结束;
  268. if(::PathFileExists (filepath) || "ok2.dat"==filename)
  269. {
  270. if(pftp==NULL)
  271. {
  272. g_pMainWnd->ModifyStaus(path, "开始连接");
  273. pftp=new CFTPSend2;
  274. g_pSend[pos]=pftp;
  275. pftp->m_path=path;
  276. pftp->m_pos=pos;
  277. pftp->m_bStop =&(g_pMainWnd->m_bTerminate);
  278. pftp->m_ziptype=ziptype;
  279. if(hskip=="")
  280. {
  281. #if TESTLOCAL
  282. ip = TEST_SERVER;
  283. // user="aaa";
  284. // pass="aaa";
  285. #endif
  286. if(!pftp->LogOnToServer(ip,g_pMainWnd->m_port, user, pass))
  287. {
  288. int pos=::FindArray (&g_serverip, ip);
  289. if(pos!=-1)
  290. {
  291. int count=g_failcount.ElementAt (pos);
  292. g_failcount.SetAt (pos, count+1);
  293. }
  294. g_pMainWnd->ModifyStaus3(path, -1, ip);
  295. delete pftp;pftp=NULL;g_pSend[pos]=pftp;
  296. ::Sleep (2000);
  297. break;
  298. }
  299. }
  300. else
  301. {
  302. BOOL bConned=0;
  303. #if TESTLOCAL
  304. ip = TEST_SERVER;
  305. // user="aaa";
  306. // pass="aaa";
  307. #endif
  308. if(!pftp->LogOnToServer(ip,g_pMainWnd->m_port, user, pass))
  309. bConned=0;
  310. if(bConned==0)
  311. {
  312. int pos=::FindArray (&g_serverip, ip);
  313. if(pos!=-1)
  314. {
  315. int count=g_failcount.ElementAt (pos);
  316. g_failcount.SetAt (pos, count+1);
  317. }
  318. ip=hskip;
  319. g_connedip.SetAt (pos, ip);
  320. if(::FindArray (&g_serverip, ip)==-1)
  321. {
  322. g_serverip.Add (ip);
  323. g_failcount.Add (0);
  324. }
  325. #ifdef TESTLOCAL
  326. ip = TEST_SERVER;
  327. // user="aaa";
  328. // pass="aaa";
  329. #endif
  330. if(!pftp->LogOnToServer(ip,g_pMainWnd->m_port, user, pass))
  331. {
  332. int pos=::FindArray (&g_serverip, ip);
  333. if(pos!=-1)
  334. {
  335. int count=g_failcount.ElementAt (pos);
  336. g_failcount.SetAt (pos, count+1);
  337. }
  338. g_pMainWnd->ModifyStaus3(path, -1, ip);
  339. delete pftp;pftp=NULL;g_pSend[pos]=pftp;
  340. ::Sleep (2000);
  341. break;
  342. }
  343. }
  344. }
  345. g_pMainWnd->ModifyStaus(path, "连接成功");
  346. }
  347. g_pMainWnd->ModifyStaus(path, "上传中..");
  348. int ret;
  349. if(savedomain.IsEmpty ())
  350. ret = pftp->MoveFile(clientid+"\\"+filename,filepath, "ok2.dat"==filename);
  351. else
  352. ret = pftp->MoveFile(savedomain+"\\"+clientid+"\\"+filename,filepath, "ok2.dat"==filename);
  353. // delete pftp;pftp=NULL; //g_pSend[pos]=pftp;
  354. g_pMainWnd->ModifyStaus(path, "上传结束");
  355. if(ret==3)//关闭线程
  356. {
  357. g_pMainWnd->ModifyStaus(path, "等待中");
  358. break;
  359. }
  360. else if(ret!=1 )
  361. {
  362. g_nFail++;
  363. g_pMainWnd->ModifyStaus3(path, ret, filename);
  364. break;
  365. int pos=::FindArray (&g_serverip, ip);
  366. if(pos!=-1)
  367. {
  368. int count=g_failcount.ElementAt (pos);
  369. g_failcount.SetAt (pos, count+1);
  370. }
  371. j-=2;
  372. ::Sleep (2000);
  373. continue;
  374. }
  375. }
  376. m_uploadtaskarray.SetAt (j+1, "OK");
  377. // GetSize() -2 的原因是,最后一个是空字符,而ok2.dat则必须是倒数第2个;
  378. if(m_uploadtaskarray.ElementAt(m_uploadtaskarray.GetSize()-2)!="ok2.dat")
  379. {
  380. m_uploadtaskarray.Add("ok2.dat");
  381. m_uploadtaskarray.Add("");
  382. }
  383. SaveUploadFileStaus(path, &m_uploadtaskarray);
  384. g_pMainWnd->ModifyStaus(path, "保存状态");
  385. g_pMainWnd->CheckTaskOK(path);
  386. g_pMainWnd->ModifyStaus(path, "检查是否传完");
  387. ::Sleep (500);
  388. }
  389. if(pftp)
  390. delete pftp;
  391. pftp=NULL;
  392. g_pSend[pos]=pftp;
  393. ::Sleep (1000);
  394. }
  395. else
  396. {
  397. g_pMainWnd->ModifyStaus2(taskpath);
  398. // AfxMessageBox("m");
  399. }
  400. ll: g_pMainWnd->m_bRunning1[pos]=false;
  401. g_pMainWnd->m_bTerminate1[pos]=false;
  402. _endthreadex( 0 );
  403. return 0;
  404. }
  405. unsigned __stdcall SendMsgThread2(LPVOID lpParam)
  406. {
  407. while(1)
  408. {
  409. if(g_pMainWnd->m_bTerminate2)
  410. break;
  411. // 由于branchinfo.dat中的地址一直在变,所以必须实时去获取branchinfo.dat中的IP信息; // 2015-09-22;
  412. LoadBranchInfo(&(g_pMainWnd->m_branchinfoarray));
  413. g_pMainWnd->LoadTaskFunc();
  414. MySleep(1000*60*2);
  415. }
  416. g_pMainWnd->m_bRunning2=false;
  417. g_pMainWnd->m_bTerminate2=false;
  418. _endthreadex( 0 );
  419. return 0;
  420. }
  421. unsigned __stdcall SendMsgThread(LPVOID lpParam)
  422. {
  423. while(1)
  424. {
  425. int i = 0;
  426. if(g_pMainWnd->m_bTerminate)
  427. break;
  428. int threadpos=-1;
  429. for( i=0; i<g_num; i++)
  430. {
  431. if(g_pMainWnd->m_bRunning1[i])continue;
  432. threadpos=i;break;
  433. }
  434. if(threadpos==-1)//没有空余线程
  435. {
  436. ::MySleep (60000);
  437. continue;
  438. }
  439. CStringArray taskpatharray;
  440. // WriteLogin("检查任务");
  441. g_taskpath[threadpos]="";
  442. {
  443. MyLock lock("accesslist1array");
  444. // WriteLogin("检查任务..");
  445. CArray<CStringArray, CStringArray>*pList1array=&(g_pMainWnd->m_List1array);
  446. int size=pList1array->GetSize ();
  447. while(size)
  448. {
  449. // 索引4 返回任务状态;
  450. if(pList1array->ElementAt (size-1).ElementAt (4)=="暂停")
  451. {
  452. // WriteLogin("暂停");
  453. size--;
  454. continue;
  455. }
  456. if(pList1array->ElementAt (size-1).ElementAt (4)=="上传完毕")
  457. {
  458. // WriteLogin("上传完毕");
  459. size--;
  460. continue;
  461. }
  462. if(pList1array->ElementAt (size-1).ElementAt (4)=="任务文件丢失" && ::PathFileExists (pList1array->ElementAt (size-1).ElementAt(6))==0 )
  463. {
  464. // WriteLogin("文件丢失"+pList1array->ElementAt (size-1).ElementAt(6));
  465. size--;
  466. continue;
  467. }
  468. BOOL bExist=0;
  469. for(int i=0; i<g_num; i++)
  470. {
  471. if(g_pMainWnd->m_bRunning1[i])
  472. {
  473. if(g_taskpath[i]==pList1array->ElementAt (size-1).ElementAt(6)) // 索引6返回*.dat路径
  474. {
  475. // WriteLogin("存在");
  476. bExist=1;break;
  477. }
  478. }
  479. }
  480. if(bExist)
  481. {
  482. size--;
  483. continue;
  484. }
  485. taskpatharray.Add (pList1array->ElementAt (size-1).ElementAt(6));
  486. size--;
  487. // g_taskpath[threadpos]=pList1array->ElementAt (size-1).ElementAt(6);
  488. // break;
  489. }
  490. }
  491. // WriteLogin("检查完毕");
  492. ///////////////计算优先级
  493. if(taskpatharray.GetSize ()==0)
  494. {
  495. ::MySleep (10000);
  496. continue;
  497. }
  498. // 任务数量大于1;
  499. if(taskpatharray.GetSize ()>1 )//&& g_serverip.GetSize ()>1)
  500. {
  501. CString ip;
  502. if(g_serverip.GetSize ())
  503. ip=g_serverip.ElementAt (0);
  504. for( i=1; i<g_serverip.GetSize (); i++)
  505. {
  506. if(g_failcount.ElementAt (i)<g_failcount.ElementAt (i-1))
  507. {
  508. ip=g_serverip.ElementAt (i);
  509. }
  510. }
  511. for( i=0; i<taskpatharray.GetSize (); i++)
  512. {
  513. CString path=taskpatharray.ElementAt (i);
  514. CStringArray m_uploadtaskarray;
  515. LoadTaskFromFile(path, &m_uploadtaskarray);
  516. if(m_uploadtaskarray.GetSize()<10)
  517. {
  518. continue;
  519. }
  520. CString domain=m_uploadtaskarray.ElementAt (1); // 目标域名;
  521. CString savedomain=m_uploadtaskarray.ElementAt (2); // 源域名;
  522. if(savedomain==domain)savedomain="";
  523. CString ip2,hskip;
  524. if(domain!="")
  525. ip2=g_pMainWnd->GetBranchIP(domain,hskip);
  526. else
  527. ip2=g_pMainWnd->GetBranchIP(path,hskip);
  528. if(::FindArray (&g_serverip, ip2)==-1)
  529. {
  530. g_serverip.Add (ip2);
  531. g_failcount.Add (0);
  532. }
  533. if(hskip!="")
  534. {
  535. if(::FindArray (&g_serverip, hskip)==-1)
  536. {
  537. g_serverip.Add (hskip);
  538. g_failcount.Add (0);
  539. }
  540. if(ip==ip2 || ip==hskip)
  541. {
  542. g_taskpath[threadpos]=taskpatharray.ElementAt (i);
  543. break;
  544. }
  545. }
  546. else
  547. {
  548. if(ip==ip2)
  549. {
  550. g_taskpath[threadpos]=taskpatharray.ElementAt (i);
  551. break;
  552. }
  553. }
  554. }
  555. }
  556. if(g_taskpath[threadpos].IsEmpty ())g_taskpath[threadpos]=taskpatharray.ElementAt (0);
  557. g_pMainWnd->m_bTerminate1[threadpos]=false;
  558. g_pMainWnd->m_bRunning1[threadpos]=false;
  559. g_pMainWnd->m_hThread1[threadpos] = NULL;
  560. g_pMainWnd->m_bRunning1[threadpos]=true;
  561. g_pMainWnd->m_hThread1[threadpos] = (HANDLE)_beginthreadex(NULL,0, ProcessTask,(LPVOID)threadpos,0,&(g_pMainWnd->m_dwThreadID1[threadpos]));
  562. ::MySleep (1000);
  563. }
  564. for(int i=0; i<g_num; i++)
  565. {
  566. while(1)
  567. {
  568. if(g_pMainWnd->m_bRunning1[i])
  569. ::Sleep (1000);
  570. else
  571. break;
  572. }
  573. }
  574. g_pMainWnd->m_bRunning=false;
  575. g_pMainWnd->m_bTerminate=false;
  576. _endthreadex( 0 );
  577. return 0;
  578. }
  579. CCPhotoFTPSendDlg::CCPhotoFTPSendDlg(CWnd* pParent /*=NULL*/)
  580. : CDialog(CCPhotoFTPSendDlg::IDD, pParent)
  581. {
  582. //{{AFX_DATA_INIT(CCPhotoFTPSendDlg)
  583. m_host = _T("IT-PC");
  584. // m_host = _T("valuefriend.gicp.net");
  585. m_user = _T("aaa");
  586. m_pass = _T("aaa");
  587. m_port = g_port;
  588. m_fwhost = _T("");
  589. m_fwport = g_port;
  590. m_fwuser = _T("");
  591. m_fwpass = _T("");
  592. m_lfile = _T("");
  593. m_rfile = _T("");
  594. m_pasv = 1;
  595. m_put = 0;
  596. m_logontype = 0;
  597. m_acct = _T("");
  598. //}}AFX_DATA_INIT
  599. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  600. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  601. m_bTerminate=false;
  602. m_bRunning=false;
  603. m_hThread = NULL;
  604. m_bTerminate2=false;
  605. m_bRunning2=false;
  606. m_hThread2 = NULL;
  607. for(int i=0; i<MAX_THREAD; i++)
  608. {
  609. m_bTerminate1[i]=false;
  610. m_bRunning1[i]=false;
  611. m_hThread1[i] = NULL;
  612. g_connedip.Add ("");
  613. }
  614. CString version = _T ("Version 1.0");
  615. g_check1=AfxGetApp()->GetProfileInt (version, "bcontinue", 1);
  616. g_num=min(10, AfxGetApp()->GetProfileInt (version, "nthreadcount", 5));
  617. }
  618. void CCPhotoFTPSendDlg::DoDataExchange(CDataExchange* pDX)
  619. {
  620. CDialog::DoDataExchange(pDX);
  621. //{{AFX_DATA_MAP(CCPhotoFTPSendDlg)
  622. DDX_Control(pDX, IDC_LIST1, m_List1);
  623. DDX_Text(pDX, IDC_EDIT1, m_host);
  624. DDX_Text(pDX, IDC_EDIT2, m_user);
  625. DDX_Text(pDX, IDC_EDIT3, m_pass);
  626. DDX_Text(pDX, IDC_EDIT4, m_port);
  627. DDX_Text(pDX, IDC_EDIT5, m_fwhost);
  628. DDX_Text(pDX, IDC_EDIT6, m_fwport);
  629. DDX_Text(pDX, IDC_EDIT7, m_fwuser);
  630. DDX_Text(pDX, IDC_EDIT8, m_fwpass);
  631. DDX_Text(pDX, IDC_EDIT9, m_lfile);
  632. DDX_Text(pDX, IDC_EDIT10, m_rfile);
  633. DDX_Check(pDX, IDC_CHECK1, m_pasv);
  634. DDX_Radio(pDX, IDC_RADIO1, m_put);
  635. DDX_Radio(pDX, IDC_RADIO3, m_logontype);
  636. DDX_Text(pDX, IDC_EDIT11, m_acct);
  637. //}}AFX_DATA_MAP
  638. }
  639. BEGIN_MESSAGE_MAP(CCPhotoFTPSendDlg, CDialog)
  640. //{{AFX_MSG_MAP(CCPhotoFTPSendDlg)
  641. ON_WM_PAINT()
  642. ON_WM_QUERYDRAGICON()
  643. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  644. ON_WM_DESTROY()
  645. ON_WM_TIMER()
  646. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  647. ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
  648. ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
  649. ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
  650. ON_COMMAND(IDM_OPEN, OnOpen)
  651. ON_COMMAND(IDM_EXIT, OnExit)
  652. ON_WM_CLOSE()
  653. ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
  654. ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
  655. ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
  656. //}}AFX_MSG_MAP
  657. ON_CONTROL_RANGE(BN_CLICKED,IDC_RADIO3,IDC_RADIO11,OnRadio)
  658. ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
  659. ON_REGISTERED_MESSAGE(g_wmClose2, OnAbortClose)
  660. END_MESSAGE_MAP()
  661. LRESULT CCPhotoFTPSendDlg::OnAbortClose(WPARAM wParam, LPARAM lParam)
  662. {
  663. HWND hwnd=::FindWindow (NULL, "数据服务器");
  664. if(hwnd)
  665. {
  666. ::PostMessage (hwnd, g_wmClose2, NULL, NULL);
  667. }
  668. return 1;
  669. }
  670. /////////////////////////////////////////////////////////////////////////////
  671. // CCPhotoFTPSendDlg message handlers
  672. LRESULT CCPhotoFTPSendDlg::OnTrayNotification(WPARAM wParam,LPARAM lParam)
  673. {
  674. return m_TrayIcon.OnTrayNotification(wParam,lParam);
  675. }
  676. void DeleteDirectory(CString strDir)
  677. {
  678. try
  679. {
  680. // 首先删除文件及子文件夹
  681. CFileFind ff;
  682. BOOL bFound = ff.FindFile(strDir+"\\*", 0);
  683. while(bFound)
  684. {
  685. bFound = ff.FindNextFile();
  686. if(ff.GetFileName()=="."||ff.GetFileName()=="..")
  687. continue;
  688. // 去掉文件(夹)只读等属性
  689. SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL);
  690. if(ff.IsDirectory()) { // 递归删除子文件夹
  691. DeleteDirectory(ff.GetFilePath());
  692. RemoveDirectory(ff.GetFilePath());
  693. }
  694. else {
  695. DeleteFile(ff.GetFilePath()); // 删除文件
  696. }
  697. }
  698. ff.Close();
  699. // 然后删除该文件夹
  700. RemoveDirectory(strDir);
  701. }
  702. catch(...)
  703. {
  704. }
  705. // int SHFileOperation( LPSHFILEOPSTRUCT lpFileOp );
  706. }
  707. BOOL CCPhotoFTPSendDlg::OnInitDialog()
  708. {
  709. CDialog::OnInitDialog();
  710. g_pMainWnd=this;
  711. ////////////////////////////
  712. if(0)
  713. {
  714. MessageBox("1");
  715. CString ip="IT-PC";
  716. int pos=0;
  717. CStringArray m_uploadtaskarray;
  718. using namespace helper_coffs;
  719. ffsco o;
  720. o.dirs(0);
  721. o.find(LPCSTR("e:\\ccc"), LPCSTR("*.*"));
  722. ffsco::typeT coo;
  723. ffsco::typeT::iterator it;
  724. coo = o.co_file();
  725. for (it = coo.begin(); coo.end() != it; it ++)
  726. {
  727. CString path=(*it).c_str();
  728. m_uploadtaskarray.Add (path.Right (path.GetLength ()-path.ReverseFind ('\\')-1));
  729. }
  730. CString dir="e:\\ccc\\";
  731. CString ziptype,path;
  732. CFTPSend2 *pftp=NULL;//g_pSend[pos]=pftp;
  733. for(int j=0; j<m_uploadtaskarray.GetSize(); j++)
  734. {
  735. CString filename=m_uploadtaskarray.ElementAt (j);
  736. CString filepath=dir+filename;
  737. if(::PathFileExists (filepath) )
  738. {
  739. if(pftp==NULL)
  740. {
  741. g_pMainWnd->ModifyStaus(path, "开始连接");
  742. pftp=new CFTPSend2;//g_pSend[pos]=pftp;
  743. pftp->m_path=path;
  744. pftp->m_pos=pos;
  745. pftp->m_bStop =&(g_pMainWnd->m_bTerminate);
  746. pftp->m_ziptype=ziptype;
  747. if(!pftp->LogOnToServer(ip,g_pMainWnd->m_port, "aaa", "aaa"))
  748. {
  749. MessageBox("连接失败");
  750. g_pMainWnd->ModifyStaus3(path, -1, ip);
  751. delete pftp;pftp=NULL;//g_pSend[pos]=pftp;
  752. ::Sleep (2000);
  753. break;
  754. }
  755. }
  756. g_pMainWnd->ModifyStaus(path, "开始上传");
  757. int ret;
  758. ret=pftp->MoveFile(filename,filepath, "ok2.dat"==filename);
  759. // delete pftp;pftp=NULL; //g_pSend[pos]=pftp;
  760. g_pMainWnd->ModifyStaus(path, "上传结束");
  761. if(ret!=1 )
  762. { //MessageBox("上传失败");
  763. g_nFail++;
  764. g_pMainWnd->ModifyStaus3(path, ret, filename);
  765. ::Sleep (2000);continue;
  766. }
  767. }
  768. ::Sleep (500);
  769. }
  770. delete pftp;pftp=NULL;
  771. MessageBox("ok");
  772. CDialog::OnOK();
  773. return 0;
  774. }
  775. // Add "About..." menu item to system menu.
  776. // IDM_ABOUTBOX must be in the system command range.
  777. // Set the icon for this dialog. The framework does this automatically
  778. // when the application's main window is not a dialog
  779. SetIcon(m_hIcon, TRUE); // Set big icon
  780. SetIcon(m_hIcon, FALSE); // Set small icon
  781. // TODO: Add extra initialization here
  782. g_listctrlfont.CreatePointFont (110, _T("System"));
  783. // m_List1.SetHeadings("发往,120;客人,250;类型,100;已上传,100;状态,150;任务路径,100" );
  784. // m_List1.LoadColumnInfo (100);
  785. m_List1.InsertColumn(0, "发往", LVCFMT_LEFT, 140);
  786. m_List1.InsertColumn(1, "客人", LVCFMT_LEFT, 250);
  787. m_List1.InsertColumn(2, "类型", LVCFMT_LEFT, 80);
  788. m_List1.InsertColumn(3, "已上传", LVCFMT_LEFT, 100);
  789. m_List1.InsertColumn(4, "状态", LVCFMT_LEFT, 150);
  790. m_List1.InsertColumn(5, "日期", LVCFMT_LEFT, 100);
  791. m_List1.InsertColumn(6, "任务路径", LVCFMT_LEFT, 120);
  792. m_List1.SetFont (&g_listctrlfont);
  793. m_List1.SetExtendedStyle(LVS_EX_FLATSB|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP);
  794. TCHAR szDir[MAX_PATH];
  795. ::GetModuleFileName (NULL, szDir, MAX_PATH);
  796. g_mainpath=szDir;
  797. g_mainpath=g_mainpath.Left (g_mainpath.ReverseFind ('\\'));
  798. CString path=g_mainpath+"\\temp";
  799. DeleteDirectory(path);
  800. m_bFirst=1;
  801. LoadTaskFunc();
  802. m_bFirst=0;
  803. SetTimer(4, 5000, NULL);
  804. SetTimer(1, 200, NULL);
  805. SetTimer(5, 10000, NULL);
  806. return TRUE; // return TRUE unless you set the focus to a control
  807. }
  808. // If you add a minimize button to your dialog, you will need the code below
  809. // to draw the icon. For MFC applications using the document/view model,
  810. // this is automatically done for you by the framework.
  811. void CCPhotoFTPSendDlg::OnPaint()
  812. {
  813. if (IsIconic())
  814. {
  815. CPaintDC dc(this); // device context for painting
  816. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  817. // Center icon in client rectangle
  818. int cxIcon = GetSystemMetrics(SM_CXICON);
  819. int cyIcon = GetSystemMetrics(SM_CYICON);
  820. CRect rect;
  821. GetClientRect(&rect);
  822. int x = (rect.Width() - cxIcon + 1) / 2;
  823. int y = (rect.Height() - cyIcon + 1) / 2;
  824. // Draw the icon
  825. dc.DrawIcon(x, y, m_hIcon);
  826. }
  827. else
  828. {
  829. CDialog::OnPaint();
  830. }
  831. }
  832. // The system calls this to obtain the cursor to display while the user drags
  833. // the minimized window.
  834. HCURSOR CCPhotoFTPSendDlg::OnQueryDragIcon()
  835. {
  836. return (HCURSOR) m_hIcon;
  837. }
  838. // hide/show firewall edit ctrls as appropriate
  839. void CCPhotoFTPSendDlg::OnRadio(UINT nID)
  840. {
  841. UpdateData(TRUE);
  842. for(int i=IDC_EDIT5;i<=IDC_EDIT8;i++)
  843. GetDlgItem(i)->EnableWindow(m_logontype);
  844. }
  845. void CCPhotoFTPSendDlg::GetUserPswFromPhotoType(CString type, CString &user, CString &pass)
  846. {
  847. if(type=="原片")
  848. {
  849. user="photo1account";
  850. pass="lyfzphoto1account";
  851. }
  852. else if(type=="初修片")
  853. {
  854. user="photo2account";
  855. pass="lyfzphoto2account";
  856. }
  857. else if(type=="精修片")
  858. {
  859. user="photo3account";
  860. pass="lyfzphoto3account";
  861. }
  862. else if(type=="设计片")
  863. {
  864. user="photo4account";
  865. pass="lyfzphoto4account";
  866. }
  867. else
  868. {
  869. user="";
  870. pass="";
  871. }
  872. }
  873. int CCPhotoFTPSendDlg::FTPFile(CString path, CString name)
  874. {
  875. return 0;
  876. }
  877. void CCPhotoFTPSendDlg::OnButton1()
  878. {
  879. }
  880. BOOL CCPhotoFTPSendDlg::TerminateThread()
  881. {
  882. try
  883. {
  884. if ( !m_bRunning )
  885. return TRUE;
  886. m_bTerminate=true;
  887. for( ; ; )
  888. {
  889. if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 )
  890. break;
  891. MSG msg;
  892. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  893. {
  894. if (!AfxGetApp()->PumpMessage())
  895. break;
  896. }
  897. }
  898. ::CloseHandle(m_hThread);
  899. m_bRunning=false;
  900. return TRUE;
  901. }
  902. catch(...)
  903. {
  904. }
  905. }
  906. BOOL CCPhotoFTPSendDlg::TerminateThread2()
  907. {
  908. try
  909. {
  910. if ( !m_bRunning2 )
  911. return TRUE;
  912. m_bTerminate2=true;
  913. for( ; ; )
  914. {
  915. if ( ::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0 )
  916. break;
  917. MSG msg;
  918. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  919. {
  920. if (!AfxGetApp()->PumpMessage())
  921. break;
  922. }
  923. }
  924. ::CloseHandle(m_hThread2);
  925. m_bRunning2=false;
  926. return TRUE;
  927. }
  928. catch(...)
  929. {
  930. }
  931. }
  932. void CloseFTP(int pos)
  933. {
  934. try
  935. {
  936. CFTPSend2 *pftp=g_pSend[pos];
  937. if(pftp)
  938. {
  939. delete pftp;
  940. pftp=NULL;
  941. g_pSend[pos]=pftp;
  942. }
  943. }
  944. catch(...)
  945. {
  946. }
  947. }
  948. BOOL CCPhotoFTPSendDlg::TerminateThread1(int pos)
  949. {
  950. try
  951. {
  952. CloseFTP(pos);
  953. if ( ! (m_bRunning1[pos]) )
  954. return TRUE;
  955. m_bTerminate1[pos]=true;
  956. ::TerminateThread (m_hThread1[pos], 0);
  957. ::CloseHandle(m_hThread1[pos]);
  958. m_bRunning1[pos]=false;
  959. return 1;
  960. for( ; ; )
  961. {
  962. if ( ::WaitForSingleObject(m_hThread1[pos], 0) == WAIT_OBJECT_0 )
  963. break;
  964. MSG msg;
  965. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  966. {
  967. if (!AfxGetApp()->PumpMessage())
  968. break;
  969. }
  970. }
  971. ::CloseHandle(m_hThread1[pos]);
  972. m_bRunning1[pos]=false;
  973. return TRUE;
  974. }
  975. catch(...)
  976. {
  977. }
  978. }
  979. BOOL g_bOldSaveType=0;
  980. void CCPhotoFTPSendDlg::LoadTaskFunc()
  981. {
  982. CArray<CStringArray, CStringArray>m_List1temparray;
  983. CString g_path1;
  984. CString g_path2;
  985. CString g_path3;
  986. CString g_path4;
  987. char server[50];
  988. DWORD leng=50;
  989. ::GetComputerName (server, &leng);
  990. g_path1=g_path2=g_path3=g_path4=server;
  991. g_path1="\\\\"+g_path1+"\\客户原片(管理软件)$";
  992. g_path2="\\\\"+g_path2+"\\修好的片(管理软件)$";
  993. g_path3="\\\\"+g_path3+"\\设计好的片(管理软件)$";
  994. g_path4="\\\\"+g_path4+"\\精修好的片(管理软件)$";
  995. // 所有"上传任务"文件夹集合;在 客户原片(管理软件)$ 和该目录下的分店目录中,都有一个"上传任务"文件夹;
  996. CStringArray dirarray;
  997. // 所有"上传任务"文件夹中的全部dat文件路径集合;
  998. CStringArray taskarray;
  999. CString path;
  1000. using namespace helper_coffs;
  1001. CString patharray[4]={g_path2,g_path1,g_path3,g_path4};
  1002. if(m_bFirst==0)
  1003. {
  1004. if(g_bOldSaveType)
  1005. {
  1006. g_bOldSaveType=0;
  1007. }
  1008. else
  1009. {
  1010. WriteLogin("读取任务");
  1011. // 查找出所有"上传文件"目录;
  1012. ffsco o;
  1013. o.dirs(1);
  1014. o.find(LPCSTR(g_path1), LPCSTR("*.*"));WriteLogin(g_path1);
  1015. if(g_pMainWnd->m_bTerminate)return;
  1016. ffsco::typeT coo;
  1017. ffsco::typeT::iterator it;
  1018. coo = o.co_dir();
  1019. it = coo.begin();
  1020. it ++;
  1021. for (;coo.end() != it;it ++)
  1022. {
  1023. if(m_bTerminate)return;
  1024. path=(*it).c_str();
  1025. if(path.Find("上传任务")==-1)continue;
  1026. if(::FindArray (&dirarray, path)==-1)
  1027. dirarray.Add (path);
  1028. }
  1029. // 查找出所有上传dat文件;
  1030. for(int i=0; i<dirarray.GetSize (); i++)
  1031. {
  1032. ffsco o;
  1033. o.dirs(0);
  1034. o.find(LPCSTR(dirarray.ElementAt (i)), LPCSTR("*.dat"));
  1035. ffsco::typeT coo;
  1036. ffsco::typeT::iterator it;
  1037. coo = o.co_file();
  1038. for (it = coo.begin(); coo.end() != it;it ++)
  1039. {
  1040. path=(*it).c_str();
  1041. if( ::FindArray (&taskarray, path)==-1)
  1042. {
  1043. taskarray.Add (path);
  1044. WriteLogin(path);
  1045. }
  1046. }
  1047. }
  1048. }
  1049. }
  1050. if(m_bTerminate)return;
  1051. WriteLogin("从文件读取任务");
  1052. {
  1053. // 读取运行目录下的uploaktask.dat文件内容;
  1054. CFile fp;
  1055. MyLock lock("maintaskmanage");
  1056. if(fp.Open(g_mainpath+"\\uploadtask.dat", CFile::modeRead))
  1057. {
  1058. DWORD leng=fp.GetLength ();
  1059. DWORD arraysize;
  1060. fp.Read (&arraysize, sizeof(DWORD));
  1061. BYTE *pData=new BYTE[leng-sizeof(DWORD)];
  1062. fp.Read (pData,leng-sizeof(DWORD));
  1063. fp.Close ();
  1064. try
  1065. {
  1066. CMemFile memfile;
  1067. memfile.Attach (pData,leng-sizeof(DWORD));
  1068. CArchive ar(&memfile, CArchive::load);
  1069. m_List1temparray.SetSize(arraysize, 1);
  1070. for(int ii=0; ii<m_List1temparray.GetSize (); ii++)
  1071. {
  1072. m_List1temparray.ElementAt (ii).Serialize (ar);
  1073. }
  1074. ar.Close();
  1075. memfile.Detach ();
  1076. delete []pData;
  1077. }
  1078. catch(...)
  1079. {
  1080. ::WriteLogin ("读取任务文件失败");
  1081. ::DeleteFile(g_mainpath+"\\uploadtask.dat");
  1082. if(m_bFirst)
  1083. CDialog::OnCancel ();
  1084. else
  1085. OnExit();
  1086. return;
  1087. }
  1088. for(int ii=0; ii<m_List1temparray.GetSize (); ii++)
  1089. {
  1090. if(m_List1temparray.ElementAt (ii).GetSize ()==10) // 每一个元素大小固定在10个;
  1091. {
  1092. CString modifydate;
  1093. if(::PathFileExists (m_List1temparray.ElementAt (ii).ElementAt (5))) // 索引5:上传完成日期;这里应该搞错了,应该填索引6;
  1094. {
  1095. modifydate=GetModifyDate(m_List1temparray.ElementAt (ii).ElementAt (5));
  1096. }
  1097. m_List1temparray.ElementAt (ii).InsertAt (5, modifydate);
  1098. }
  1099. }
  1100. int aa=0;
  1101. while(m_List1temparray.GetSize ()>500)
  1102. {
  1103. for(int i=m_List1temparray.GetSize ()-1; i>=0; i--)
  1104. {
  1105. if(m_List1temparray.ElementAt (i).ElementAt (4)=="上传完毕")
  1106. {
  1107. m_List1temparray.RemoveAt(i);break;
  1108. }
  1109. }
  1110. aa++;
  1111. if(aa>20)break;
  1112. }
  1113. WriteLogin("读取任务文件成功");
  1114. }
  1115. else
  1116. WriteLogin("打开任务文件失败");
  1117. }
  1118. BOOL bNeedLoad=0;
  1119. {
  1120. int i = 0;
  1121. int oldsize=m_List1temparray.GetSize();
  1122. for( i=0; i<taskarray.GetSize (); i++)
  1123. {
  1124. WriteLogin("读取"+taskarray.ElementAt (i));
  1125. if(TaskExist(taskarray.ElementAt (i), &m_List1temparray))
  1126. {
  1127. // 存在,且未上传完成;
  1128. WriteLogin("失败1");
  1129. continue;
  1130. }
  1131. // 获取每个*.dat中的目标分店域名;
  1132. if(GetBranch(taskarray.ElementAt (i))=="")
  1133. {
  1134. WriteLogin("失败2");
  1135. continue;
  1136. }
  1137. // 相片数量;
  1138. int photocount=0;
  1139. // 顾客昵称;
  1140. CString client=GetClient(taskarray.ElementAt (i), photocount); // 返回顾客名字,以及相片数量;
  1141. if(client=="")
  1142. {
  1143. WriteLogin("失败3");
  1144. continue;
  1145. }
  1146. // size 任务个数;
  1147. int size=m_List1temparray.GetSize();
  1148. m_List1temparray.SetSize(size+1, 1);
  1149. // 添加新的任务到uploadtask.dat中,即m_Listtemparray;
  1150. m_List1temparray.ElementAt (size).Add (GetBranch(taskarray.ElementAt (i)));
  1151. m_List1temparray.ElementAt (size).Add (client);
  1152. m_List1temparray.ElementAt (size).Add (GetPhotoType(taskarray.ElementAt (i)));
  1153. client.Format ("%d/%d", 0, photocount);
  1154. m_List1temparray.ElementAt (size).Add (client);
  1155. m_List1temparray.ElementAt (size).Add ("等待中");
  1156. m_List1temparray.ElementAt (size).Add (GetModifyDate(taskarray.ElementAt (i)));
  1157. m_List1temparray.ElementAt (size).Add (taskarray.ElementAt (i));
  1158. m_List1temparray.ElementAt (size).Add ("");
  1159. m_List1temparray.ElementAt (size).Add ("");
  1160. m_List1temparray.ElementAt (size).Add ("");
  1161. m_List1temparray.ElementAt (size).Add (""); bNeedLoad=1;
  1162. }
  1163. MyLock lock("accesslist1array");
  1164. m_List1array.RemoveAll ();
  1165. m_List1array.SetSize(m_List1temparray.GetSize (), 1);
  1166. int size=m_List1temparray.GetSize ();
  1167. for( i=oldsize; i<size; i++)
  1168. {
  1169. m_List1array.ElementAt (i-oldsize).Copy (m_List1temparray.ElementAt (i));
  1170. }
  1171. for( i=0; i<oldsize; i++)
  1172. {
  1173. m_List1array.ElementAt (size-oldsize+i).Copy (m_List1temparray.ElementAt (i));
  1174. }
  1175. if(size!=oldsize)bNeedLoad=1;
  1176. }
  1177. if(bNeedLoad || m_List1.GetItemCount ()==0 )
  1178. {
  1179. FillGrid();
  1180. SaveTask();
  1181. }
  1182. }
  1183. CString CCPhotoFTPSendDlg::GetBranch(CString path)
  1184. {
  1185. // 1.由本店上传到其他分店;
  1186. int pos=path.Find(".ly.com");
  1187. if(pos==-1)
  1188. {
  1189. //本店传出
  1190. MyLock lock("uploadtaskaccess");
  1191. CFile fp;
  1192. if(fp.Open (path, CFile::modeRead))
  1193. {
  1194. DWORD length=fp.GetLength ();
  1195. if(!length)return "";
  1196. CArchive ar(&fp, CArchive::load);
  1197. CStringArray array;
  1198. array.Serialize (ar);
  1199. fp.Close ();
  1200. if(!array.GetSize ()>2)return "";
  1201. // 读取目标域名;
  1202. if(array.ElementAt (1).Find (".ly.com")==-1)
  1203. return "";
  1204. CString str=GetBranchNameFromDoMain(array.ElementAt (1));
  1205. if(str.IsEmpty ())
  1206. return "";
  1207. return "本店->"+str;
  1208. }
  1209. else
  1210. return "";
  1211. }
  1212. // 2.由分店上传回分店服务器;
  1213. CString pathbak=path;
  1214. path=path.Left(pos+7);
  1215. path=path.Right(path.GetLength()-path.ReverseFind('\\')-1);
  1216. CString from =GetBranchNameFromDoMain(path)+"->";
  1217. CString des;
  1218. MyLock lock("uploadtaskaccess");
  1219. CFile fp;
  1220. if(fp.Open (pathbak, CFile::modeRead))
  1221. {
  1222. DWORD length=fp.GetLength ();
  1223. if(length)
  1224. {
  1225. CArchive ar(&fp, CArchive::load);
  1226. CStringArray array;
  1227. array.Serialize (ar);
  1228. fp.Close ();
  1229. if(array.GetSize ()>=2)
  1230. {
  1231. if(array.ElementAt (1).Find (".ly.com")!=-1)
  1232. des=GetBranchNameFromDoMain(array.ElementAt (1));
  1233. }
  1234. }
  1235. }
  1236. else
  1237. des="";
  1238. return from+des;
  1239. }
  1240. CString CCPhotoFTPSendDlg::GetBranchNameFromDoMain(CString domain)
  1241. {
  1242. BOOL bLoad=0;
  1243. if(1)
  1244. {
  1245. MyLock lock("savebranchinfo");
  1246. if(m_branchinfoarray.GetSize ()==0)
  1247. bLoad=1;
  1248. }
  1249. if(bLoad)LoadBranchInfo(&m_branchinfoarray);
  1250. MyLock lock("savebranchinfo");
  1251. for(int i=0; i<m_branchinfoarray.GetSize (); i++)
  1252. {
  1253. if(domain==m_branchinfoarray.ElementAt (i).ElementAt (0))
  1254. {
  1255. // MessageBox(m_branchinfoarray.ElementAt (i).ElementAt (1));
  1256. return m_branchinfoarray.ElementAt (i).ElementAt (1);
  1257. }
  1258. }
  1259. return "";
  1260. }
  1261. CString CCPhotoFTPSendDlg::GetBranchIP(CString path, CString &hskip)
  1262. {
  1263. if(path.Find ("\\")==-1)
  1264. return GetBranchIPFromDoMain(path, hskip);
  1265. int pos=path.Find(".ly.com");
  1266. if(pos==-1)
  1267. return "";
  1268. path=path.Left(pos+7);
  1269. path=path.Right(path.GetLength()-path.ReverseFind('\\')-1);
  1270. return GetBranchIPFromDoMain(path, hskip);
  1271. }
  1272. CString CCPhotoFTPSendDlg::GetBranchIPFromDoMain(CString domain, CString &hskip)
  1273. {
  1274. BOOL bLoad=0;
  1275. if(1)
  1276. {
  1277. // MyLock lock("savebranchinfo");
  1278. // if(m_branchinfoarray.GetSize ()==0)
  1279. bLoad=1;
  1280. }
  1281. if(bLoad)LoadBranchInfo(&m_branchinfoarray);
  1282. MyLock lock("savebranchinfo");
  1283. for(int i=0; i<m_branchinfoarray.GetSize (); i++)
  1284. {
  1285. if(domain==m_branchinfoarray.ElementAt (i).ElementAt (0))
  1286. {
  1287. if(m_branchinfoarray.ElementAt (i).GetSize ()>6)
  1288. hskip=m_branchinfoarray.ElementAt (i).ElementAt (6);
  1289. return m_branchinfoarray.ElementAt (i).ElementAt (2);
  1290. }
  1291. }
  1292. return "";
  1293. }
  1294. // path:任务文件*.dat;
  1295. // size:相片数量;
  1296. CString CCPhotoFTPSendDlg::GetClient(CString path, int &size)
  1297. {
  1298. MyLock lock("uploadtaskaccess");
  1299. CFile fp;
  1300. if(fp.Open (path, CFile::modeRead))
  1301. {
  1302. DWORD length=fp.GetLength ();
  1303. if(length==0)
  1304. {
  1305. fp.Close ();
  1306. ::DeleteFile (path);
  1307. return "";
  1308. }
  1309. CStringArray m_uploadtaskarray;
  1310. CArchive ar(&fp, CArchive::load);
  1311. m_uploadtaskarray.Serialize (ar);
  1312. fp.Close ();
  1313. if(m_uploadtaskarray.GetSize())
  1314. {
  1315. size=(m_uploadtaskarray.GetSize()-10)/2; // 返回相片数量;
  1316. return m_uploadtaskarray.ElementAt(0);
  1317. }
  1318. }
  1319. return "";
  1320. }
  1321. CString CCPhotoFTPSendDlg::GetPhotoType(CString path)
  1322. {
  1323. WriteLogin("获取类型"+path);
  1324. CString g_path1;
  1325. CString g_path2;
  1326. CString g_path3;
  1327. CString g_path4;
  1328. g_path1="\\客户原片(管理软件)$";
  1329. g_path2="\\修好的片(管理软件)$";
  1330. g_path3="\\设计好的片(管理软件)$";
  1331. g_path4="\\精修好的片(管理软件)$";
  1332. CStringArray m_uploadtaskarray;
  1333. LoadTaskFromFile(path, &m_uploadtaskarray);
  1334. if(m_uploadtaskarray.GetSize()<10)
  1335. {
  1336. WriteLogin("获取类型失败1");
  1337. return "";
  1338. }
  1339. CString dir=path;
  1340. CString dirinfile=m_uploadtaskarray.ElementAt (4);
  1341. if(dirinfile!="")
  1342. {
  1343. WriteLogin("目录"+dir);
  1344. dir=dirinfile;
  1345. }
  1346. if(dir.Find(g_path1)!=-1)return "原片";
  1347. if(dir.Find(g_path2)!=-1)return "初修片";
  1348. if(dir.Find(g_path3)!=-1)return "设计片";
  1349. if(dir.Find(g_path4)!=-1)return "精修片";
  1350. WriteLogin("获取类型失败2");
  1351. return "";
  1352. }
  1353. BOOL CCPhotoFTPSendDlg::SaveTask()
  1354. {
  1355. MyLock lock2("accesslist1array");
  1356. CMemFile memfile;
  1357. CArchive ar(&memfile, CArchive::store);
  1358. for(int ii=0; ii<m_List1array.GetSize (); ii++)
  1359. {
  1360. m_List1array.ElementAt (ii).Serialize (ar);
  1361. }
  1362. ar.Close();
  1363. CFile fp;
  1364. MyLock lock("maintaskmanage");
  1365. if(fp.Open(g_mainpath+"\\uploadtask.dat", CFile::modeCreate|CFile::modeWrite))
  1366. {
  1367. DWORD nBranchDataLeng=memfile.GetLength ();
  1368. BYTE *pBranchData=memfile.Detach();
  1369. DWORD size=m_List1array.GetSize ();
  1370. fp.Write(&size, sizeof(DWORD));
  1371. fp.Write(pBranchData, nBranchDataLeng);
  1372. fp.Close();
  1373. delete []pBranchData;
  1374. return 1;
  1375. }
  1376. else
  1377. WriteLogin("保存上传任务失败!");
  1378. return 0;
  1379. }
  1380. void CCPhotoFTPSendDlg::FillGrid()
  1381. {
  1382. MyLock lock("accesslist1array");
  1383. m_List1.DeleteAllItems ();
  1384. int count=0;
  1385. for(int ii=0; ii<m_List1array.GetSize (); ii++)
  1386. {
  1387. for(int jj=0; jj<7; jj++)
  1388. {
  1389. if(jj==0)
  1390. m_List1.InsertItem (ii, m_List1array.ElementAt (ii).ElementAt (jj));
  1391. else
  1392. m_List1.SetItemText (ii, jj, m_List1array.ElementAt (ii).ElementAt (jj));
  1393. }
  1394. }
  1395. /*m_List1.DeleteAllItems2 ();
  1396. int ii=0;
  1397. m_List1.m_arLabels.SetSize( m_List1array.GetSize (), 1 );
  1398. int count=0;
  1399. for(ii=0; ii<m_List1.m_arLabels.GetSize (); ii++)
  1400. {
  1401. m_List1.m_arLabels.ElementAt (count++).Copy (m_List1array.ElementAt (ii));
  1402. }
  1403. m_List1.m_arLabels.SetSize(count, 1);
  1404. ii=count;
  1405. m_List1.m_LabelCount=ii;
  1406. m_List1.SetItemCountEx (ii);*/
  1407. }
  1408. BOOL CCPhotoFTPSendDlg::TaskExist(CString path, CArray<CStringArray, CStringArray>*pList1array)
  1409. {
  1410. for(int i=0; i<pList1array->GetSize(); i++)
  1411. {
  1412. if(path==pList1array->ElementAt(i).ElementAt(6))
  1413. {
  1414. if(pList1array->ElementAt(i).ElementAt(4)!="上传完毕")
  1415. return 1;
  1416. }
  1417. }
  1418. return 0;
  1419. }
  1420. void CCPhotoFTPSendDlg::ModifyStaus(CString path, CString info)
  1421. {
  1422. MyLock lock("accesslist1array");
  1423. for(int i=0; i<m_List1array.GetSize(); i++)
  1424. {
  1425. if(path==m_List1array.ElementAt(i).ElementAt(6) && "上传完毕"!=m_List1array.ElementAt(i).ElementAt(4))
  1426. {
  1427. m_List1array.ElementAt(i).SetAt(4, info);
  1428. m_List1.SetItemText (i, 4, info);
  1429. //FillGrid();
  1430. break;
  1431. }
  1432. }
  1433. }
  1434. extern CString g_failstr;
  1435. void CCPhotoFTPSendDlg::ModifyStaus3(CString path, int type, CString ip)
  1436. {
  1437. MyLock lock("accesslist1array");
  1438. for(int i=0; i<m_List1array.GetSize(); i++)
  1439. {
  1440. if(path==m_List1array.ElementAt(i).ElementAt(6) && "上传完毕"!=m_List1array.ElementAt(i).ElementAt(4))
  1441. {
  1442. if(type==-1)
  1443. m_List1array.ElementAt(i).SetAt(4, "连接服务器"+ip+"失败");
  1444. else
  1445. m_List1array.ElementAt(i).SetAt(4, "上传文件失败:"+ip+g_failstr);
  1446. // FillGrid();
  1447. m_List1.SetItemText (i, 4, m_List1array.ElementAt (i).ElementAt (4));
  1448. break;
  1449. }
  1450. }
  1451. }
  1452. void CCPhotoFTPSendDlg::ModifyStaus4(CString path, CString str,int pos)
  1453. {
  1454. MyLock lock2("accessrefreshlist");
  1455. MyLock lock("accesslist1array");
  1456. // if(m_bRunning1[pos]==0)return;
  1457. for(int i=0; i<m_List1array.GetSize(); i++)
  1458. {
  1459. if(path==m_List1array.ElementAt(i).ElementAt(6) && m_List1array.ElementAt(i).ElementAt(4)!="上传完毕")
  1460. {
  1461. if(m_List1array.ElementAt(i).ElementAt(4)!="暂停")
  1462. {
  1463. m_List1array.ElementAt(i).SetAt(4, str);
  1464. m_List1.SetItemText (i, 4, str);
  1465. }
  1466. break;
  1467. }
  1468. }
  1469. }
  1470. void CCPhotoFTPSendDlg::ModifyStaus2(CString path)
  1471. {
  1472. {
  1473. MyLock lock("accesslist1array");
  1474. for(int i=0; i<m_List1array.GetSize(); i++)
  1475. {
  1476. if(path==m_List1array.ElementAt(i).ElementAt(6) && m_List1array.ElementAt(i).ElementAt(4)!="上传完毕")
  1477. {
  1478. m_List1array.ElementAt(i).SetAt(4, "任务文件丢失");
  1479. m_List1.SetItemText (i, 4, m_List1array.ElementAt (i).ElementAt (4));
  1480. // FillGrid();
  1481. break;
  1482. }
  1483. }
  1484. }
  1485. SaveTask();
  1486. }
  1487. void CCPhotoFTPSendDlg::OnDestroy()
  1488. {
  1489. CDialog::OnDestroy();
  1490. // TODO: Add your message handler code here
  1491. }
  1492. void CCPhotoFTPSendDlg::OnTimer(UINT nIDEvent)
  1493. {
  1494. // TODO: Add your message handler code here and/or call default
  1495. if(nIDEvent==1)
  1496. {
  1497. KillTimer(1);
  1498. #ifndef _DEBUG
  1499. OnClose();
  1500. #endif
  1501. UpdateData(TRUE);
  1502. m_bTerminate=false;
  1503. m_bRunning=false;
  1504. m_hThread = NULL;
  1505. m_bRunning=true;
  1506. m_hThread = (HANDLE)_beginthreadex(NULL,0, SendMsgThread,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID);
  1507. m_bTerminate2=false;
  1508. m_bRunning2=false;
  1509. m_hThread2 = NULL;
  1510. m_bRunning2=true;
  1511. m_hThread2 = (HANDLE)_beginthreadex(NULL,0, SendMsgThread2,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID2);
  1512. SetTimer(3, 40000, NULL);
  1513. }
  1514. else if(nIDEvent==3)
  1515. {//settimer
  1516. return;
  1517. MyLock lock("g_bActiveaccess");
  1518. for(int i=0; i<g_num; i++)
  1519. {
  1520. if(g_bActive[i]==0 && g_taskpath[i]!="" && m_bRunning1[i])
  1521. {
  1522. g_pMainWnd->ModifyStaus(g_taskpath[i], "连接超时");g_nFail++;
  1523. TerminateThread1(i);
  1524. CString ip=g_connedip.ElementAt (i);
  1525. int pos=::FindArray (&g_serverip, ip);
  1526. if(pos!=-1)
  1527. {
  1528. int count=g_failcount.ElementAt (pos);
  1529. g_failcount.SetAt (pos, count+1);
  1530. }
  1531. }
  1532. g_bActive[i]=0;
  1533. }
  1534. }
  1535. else if(nIDEvent==4)
  1536. {
  1537. static DWORD ticks=::GetTickCount();
  1538. if(g_nFail>30 && (GetTickCount()-ticks>1000*60*5) )
  1539. {
  1540. OnExit();
  1541. }
  1542. }
  1543. else if(nIDEvent==5)
  1544. {
  1545. HWND hwnd=::FindWindow (NULL, "数据服务器");
  1546. if(hwnd)
  1547. {
  1548. ::PostMessage (hwnd, g_wmClose2, NULL, NULL);
  1549. }
  1550. }
  1551. }
  1552. void CCPhotoFTPSendDlg::CheckTaskOK(CString path)
  1553. {
  1554. MyLock lock("uploadtaskaccess");
  1555. CFile fp;
  1556. if(fp.Open (path, CFile::modeRead))
  1557. {
  1558. DWORD length=fp.GetLength ();
  1559. if(!length)return;
  1560. CArchive ar(&fp, CArchive::load);
  1561. CStringArray m_uploadtaskarray;
  1562. m_uploadtaskarray.Serialize (ar);
  1563. fp.Close ();
  1564. BOOL bFind=0;
  1565. int count1=0;
  1566. int count2=0;
  1567. for(int j=10; j<m_uploadtaskarray.GetSize(); j+=2)
  1568. {
  1569. if(m_uploadtaskarray.ElementAt (j+1)!="OK")
  1570. {
  1571. bFind=1;
  1572. }
  1573. else
  1574. count1++;
  1575. count2++;
  1576. }
  1577. if(bFind==0)//全部传完
  1578. {
  1579. BOOL bSave=0;
  1580. {
  1581. MyLock lock("accesslist1array");
  1582. for(int i=0; i<m_List1array.GetSize(); i++)
  1583. {
  1584. if(path==m_List1array.ElementAt(i).ElementAt(6) && m_List1array.ElementAt(i).ElementAt(4)!="上传完毕")
  1585. {
  1586. m_List1array.ElementAt(i).SetAt(4, "上传完毕");
  1587. CString str;
  1588. str.Format ("%d/%d", count1, count2);
  1589. m_List1array.ElementAt(i).SetAt(3, str);
  1590. m_List1.SetItemText (i, 4, m_List1array.ElementAt (i).ElementAt (4));
  1591. m_List1.SetItemText (i, 3, str);
  1592. // FillGrid();
  1593. bSave=1;
  1594. break;
  1595. }
  1596. }
  1597. }
  1598. if(bSave)
  1599. {
  1600. if(SaveTask())
  1601. {
  1602. ::DeleteFile (path);
  1603. }
  1604. }
  1605. }
  1606. else
  1607. {
  1608. BOOL bSave=0;
  1609. {
  1610. MyLock lock("accesslist1array");
  1611. for(int i=0; i<m_List1array.GetSize(); i++)
  1612. {
  1613. if(path==m_List1array.ElementAt(i).ElementAt(6) && m_List1array.ElementAt(i).ElementAt(4)!="上传完毕")
  1614. {
  1615. CString str;
  1616. str.Format ("%d/%d", count1, count2);
  1617. m_List1array.ElementAt(i).SetAt(3, str);
  1618. if(m_List1array.ElementAt(i).ElementAt(4)!="暂停")
  1619. {
  1620. m_List1array.ElementAt(i).SetAt(4, "上传中");
  1621. m_List1.SetItemText (i, 4, m_List1array.ElementAt (i).ElementAt (4));
  1622. }
  1623. m_List1.SetItemText (i, 3, str);
  1624. // FillGrid();
  1625. bSave=1;
  1626. break;
  1627. }
  1628. }
  1629. }
  1630. if(bSave)
  1631. {
  1632. SaveTask();
  1633. }
  1634. }
  1635. }
  1636. else
  1637. WriteLogin("检查任务是否完成"+path+"失败!");
  1638. }
  1639. void CCPhotoFTPSendDlg::OnButton2()
  1640. {
  1641. MyLock lock2("accessrefreshlist");
  1642. // TODO: Add your control notification handler code here
  1643. if(m_pathbak.IsEmpty() )
  1644. {
  1645. AfxMessageBox("请先选中您要取消的任务!", MB_ICONINFORMATION);
  1646. return;
  1647. }
  1648. CString path=m_pathbak;
  1649. if(AfxMessageBox("是否取消"+m_clientinfo+"上传任务?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
  1650. BOOL bSave=0;
  1651. {
  1652. MyLock lock("accesslist1array");
  1653. for(int i=0; i<m_List1array.GetSize (); i++)
  1654. {
  1655. if(path==m_List1array.ElementAt (i).ElementAt (6) && ("上传完毕"!=m_List1array.ElementAt(i).ElementAt(4)||"任务文件丢失"==m_List1array.ElementAt(i).ElementAt(4) ))
  1656. {
  1657. for(int j=0; j<g_num; j++)
  1658. {
  1659. if(g_taskpath[j]==path && m_bRunning1[j])
  1660. {
  1661. TerminateThread1(j);
  1662. }
  1663. }
  1664. if(::DeleteFile (path))
  1665. {
  1666. m_List1array.RemoveAt(i);
  1667. m_List1.DeleteItem (i);
  1668. bSave=1;
  1669. }
  1670. else
  1671. {
  1672. ::Sleep(1000);
  1673. if(::DeleteFile (path))
  1674. {
  1675. m_List1array.RemoveAt(i);
  1676. m_List1.DeleteItem (i);
  1677. bSave=1;
  1678. }
  1679. }
  1680. if("任务文件丢失"==m_List1array.ElementAt(i).ElementAt(4))
  1681. {
  1682. if(bSave==0)
  1683. {
  1684. m_List1array.RemoveAt(i);
  1685. m_List1.DeleteItem (i);
  1686. }
  1687. bSave=1;
  1688. }
  1689. if(bSave==0)
  1690. AfxMessageBox("取消任务失败,请稍候再试!", MB_ICONINFORMATION);
  1691. break;
  1692. }
  1693. }
  1694. }
  1695. if(bSave)
  1696. {
  1697. SaveTask();
  1698. }
  1699. }
  1700. void CCPhotoFTPSendDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
  1701. {
  1702. // TODO: Add your control notification handler code here
  1703. POSITION pos;
  1704. pos=m_List1.GetFirstSelectedItemPosition();
  1705. if(pos==NULL)
  1706. {
  1707. return;
  1708. }
  1709. int iItem=m_List1.GetNextSelectedItem(pos);
  1710. m_pathbak=m_List1.GetItemText (iItem, 6);
  1711. m_clientinfo=m_List1.GetItemText (iItem, 0)+";"+m_List1.GetItemText (iItem, 1)+";"+m_List1.GetItemText (iItem, 2);
  1712. *pResult = 0;
  1713. }
  1714. void CCPhotoFTPSendDlg::OnButton3()
  1715. {
  1716. MyLock lock2("accessrefreshlist");
  1717. // TODO: Add your control notification handler code here
  1718. if(m_pathbak.IsEmpty() )
  1719. {
  1720. AfxMessageBox("请先选中您要暂停的任务!", MB_ICONINFORMATION);
  1721. return;
  1722. }
  1723. CString path=m_pathbak;
  1724. if(AfxMessageBox("是否暂停"+m_clientinfo+"上传任务?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
  1725. BOOL bSave=0;
  1726. {
  1727. MyLock lock("accesslist1array");
  1728. for(int i=0; i<m_List1array.GetSize (); i++)
  1729. {
  1730. if(path==m_List1array.ElementAt (i).ElementAt(6) && "上传完毕"!=m_List1array.ElementAt(i).ElementAt(4))
  1731. {
  1732. for(int j=0; j<g_num; j++)
  1733. {
  1734. if(g_taskpath[j]==path && m_bRunning1[j])
  1735. {
  1736. TerminateThread1(j);
  1737. }
  1738. }
  1739. m_List1array.ElementAt (i).SetAt (4, "暂停");
  1740. m_List1.SetItemText (i, 4, m_List1array.ElementAt (i).ElementAt (4));
  1741. bSave=1;
  1742. break;
  1743. }
  1744. }
  1745. }
  1746. if(bSave) SaveTask();
  1747. }
  1748. BOOL CCPhotoFTPSendDlg::IsStatusPause(CString path)
  1749. {
  1750. MyLock lock("accesslist1array");
  1751. for(int i=0; i<m_List1array.GetSize (); i++)
  1752. {
  1753. if(path==m_List1array.ElementAt (i).ElementAt(6) && "暂停"==m_List1array.ElementAt(i).ElementAt(4))
  1754. {
  1755. return 1;
  1756. }
  1757. }
  1758. return 0;
  1759. }
  1760. void CCPhotoFTPSendDlg::OnButton4()
  1761. {
  1762. MyLock lock2("accessrefreshlist");
  1763. // TODO: Add your control notification handler code here
  1764. if(m_pathbak.IsEmpty() )
  1765. {
  1766. AfxMessageBox("请先选中您要继续上传的任务!", MB_ICONINFORMATION);
  1767. return;
  1768. }
  1769. CString path=m_pathbak;
  1770. if(AfxMessageBox("是否继续"+m_clientinfo+"上传任务?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
  1771. BOOL bSave=0;
  1772. {
  1773. MyLock lock("accesslist1array");
  1774. for(int i=0; i<m_List1array.GetSize (); i++)
  1775. {
  1776. if(path==m_List1array.ElementAt (i).ElementAt(6) && "上传完毕"!=m_List1array.ElementAt(i).ElementAt(4))
  1777. {
  1778. for(int j=0; j<g_num; j++)
  1779. {
  1780. if( m_bRunning1[j])
  1781. {
  1782. TerminateThread1(j);
  1783. }
  1784. }
  1785. // g_pMainWnd->m_bTerminate1[0]=g_pMainWnd->m_bTerminate1[1]=g_pMainWnd->m_bTerminate1[2]=g_pMainWnd->m_bTerminate1[3]=g_pMainWnd->m_bTerminate1[4]=1;
  1786. m_List1array.ElementAt (i).SetAt (4, "等待中");
  1787. m_List1.SetItemText (i, 4, m_List1array.ElementAt (i).ElementAt (4));
  1788. // FillGrid();
  1789. bSave=1;
  1790. break;
  1791. }
  1792. }
  1793. }
  1794. if(bSave)SaveTask();
  1795. }
  1796. //mylock
  1797. void CCPhotoFTPSendDlg::OnCancel()
  1798. {
  1799. // TODO: Add extra cleanup here
  1800. }
  1801. void CCPhotoFTPSendDlg::OnOpen()
  1802. {
  1803. // TODO: Add your command handler code here
  1804. ShowWindow(SW_SHOW);
  1805. }
  1806. void CCPhotoFTPSendDlg::OnExit()
  1807. {
  1808. // TODO: Add your command handler code here
  1809. if(m_bTerminate)return;
  1810. m_TrayIcon.RemoveIcon();
  1811. for(int i=0; i<g_num; i++)
  1812. {
  1813. if(g_taskpath[i]!="" && m_bRunning1[i])
  1814. {
  1815. TerminateThread1(i);
  1816. }
  1817. }
  1818. TerminateThread();TerminateThread2();
  1819. CDialog::OnCancel ();
  1820. }
  1821. void CCPhotoFTPSendDlg::OnClose()
  1822. {
  1823. // TODO: Add your message handler code here and/or call default
  1824. m_TrayIcon.Create(this,WM_ICON_NOTIFY,"客照上传服务器" ,m_hIcon,IDR_MENUtray); //构造
  1825. ShowWindow(SW_HIDE); //隐藏窗口
  1826. }
  1827. //SetSize
  1828. void CCPhotoFTPSendDlg::OnButton5()
  1829. {
  1830. MyLock lock2("accessrefreshlist");
  1831. // TODO: Add your control notification handler code here
  1832. if(m_pathbak.IsEmpty() )
  1833. {
  1834. AfxMessageBox("请先选中您要清除的任务!", MB_ICONINFORMATION);
  1835. return;
  1836. }
  1837. CString path=m_pathbak;
  1838. if(AfxMessageBox("是否清除"+m_clientinfo+"上传任务?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
  1839. BOOL bSave=0;
  1840. {
  1841. MyLock lock("accesslist1array");
  1842. for(int i=0; i<m_List1array.GetSize (); i++)
  1843. {
  1844. if(path==m_List1array.ElementAt (i).ElementAt (6) && "上传完毕"==m_List1array.ElementAt(i).ElementAt(4))
  1845. {
  1846. ::DeleteFile (path);
  1847. m_List1array.RemoveAt(i);
  1848. m_List1.DeleteItem (i);
  1849. bSave=1;
  1850. break;
  1851. }
  1852. }
  1853. }
  1854. if(bSave)
  1855. {
  1856. SaveTask();
  1857. }
  1858. }
  1859. void CCPhotoFTPSendDlg::OnButton6()
  1860. {
  1861. MyLock lock2("accessrefreshlist");
  1862. // TODO: Add your control notification handler code here
  1863. CString path;
  1864. if(AfxMessageBox("是否清除全部已传完的记录?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
  1865. {
  1866. MyLock lock("accesslist1array");
  1867. for(int i=m_List1array.GetSize ()-1; i>=0; i--)
  1868. {
  1869. path=m_List1array.ElementAt(i).ElementAt(6);
  1870. if("上传完毕"==m_List1array.ElementAt(i).ElementAt(4))
  1871. {
  1872. ::DeleteFile (path);
  1873. m_List1array.RemoveAt(i);
  1874. m_List1.DeleteItem (i);
  1875. }
  1876. }
  1877. }
  1878. SaveTask();
  1879. }
  1880. void CCPhotoFTPSendDlg::OnButton7()
  1881. {
  1882. // TODO: Add your control notification handler code here
  1883. SetDlg dlg;
  1884. dlg.DoModal ();
  1885. }
  1886. CString CCPhotoFTPSendDlg::GetModifyDate(CString path)
  1887. {
  1888. HANDLE hFile;
  1889. WIN32_FIND_DATA wfd;
  1890. SYSTEMTIME systime;
  1891. FILETIME localtime;
  1892. CString stime; //输出时间
  1893. memset(&wfd, 0, sizeof(wfd));
  1894. if((hFile=FindFirstFile(path, &wfd))==INVALID_HANDLE_VALUE)
  1895. return "";
  1896. //ok,转换时间
  1897. // FileTimeToLocalFileTime(&wfd.ftLastWriteTime,&localtime);
  1898. FileTimeToLocalFileTime(&wfd.ftCreationTime,&localtime);
  1899. FileTimeToSystemTime(&localtime,&systime);
  1900. stime.Format("%4d-%02d-%02d",systime.wYear,systime.wMonth,systime.wDay);
  1901. return stime;
  1902. }
  1903. //g_wmClose2
  1904. BOOL CCPhotoFTPSendDlg::PreTranslateMessage(MSG* pMsg)
  1905. {
  1906. // TODO: Add your specialized code here and/or call the base class
  1907. if(pMsg->message==WM_KEYDOWN)
  1908. {
  1909. switch (pMsg->wParam)
  1910. {
  1911. case VK_F2:
  1912. if(AfxMessageBox("全盘扫描任务需要较长时间,是否继续?", MB_YESNO|MB_ICONSTOP)!=IDYES)return 1;
  1913. g_bOldSaveType=1;
  1914. return 1;
  1915. }
  1916. }
  1917. return CDialog::PreTranslateMessage(pMsg);
  1918. }
  1919. //连接超时