Welcome.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. // Welcome.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "Welcome.h"
  6. //extern void WriteClientLog(CString str); // Jeff写客户端日志;
  7. /////////////////////////////////////////////////////////////////////////////
  8. // Welcome dialog
  9. Welcome::Welcome(CWnd* pParent /*=NULL*/)
  10. : CDialog(Welcome::IDD, pParent)
  11. {
  12. //{{AFX_DATA_INIT(Welcome)
  13. // NOTE: the ClassWizard will add member initialization here
  14. //}}AFX_DATA_INIT
  15. m_pBk=NULL;
  16. g_bNoConnDlg=1;
  17. m_bFirst=1;
  18. }
  19. void Welcome::DoDataExchange(CDataExchange* pDX)
  20. {
  21. CDialog::DoDataExchange(pDX);
  22. //{{AFX_DATA_MAP(Welcome)
  23. // NOTE: the ClassWizard will add DDX and DDV calls here
  24. //}}AFX_DATA_MAP
  25. }
  26. BEGIN_MESSAGE_MAP(Welcome, CDialog)
  27. //{{AFX_MSG_MAP(Welcome)
  28. ON_WM_PAINT()
  29. ON_WM_DESTROY()
  30. ON_WM_ERASEBKGND()
  31. ON_WM_TIMER()
  32. //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34. /////////////////////////////////////////////////////////////////////////////
  35. // Welcome message handlers
  36. BOOL Welcome::OnEraseBkgnd(CDC* pDC)
  37. {
  38. // TODO: Add your message handler code here and/or call default
  39. if(m_pBk)
  40. {
  41. Graphics graph(pDC->GetSafeHdc ());
  42. CRect rc;
  43. GetClientRect (rc);
  44. Rect destinationRect(0,0,rc.Width (), rc.Height ());
  45. graph.DrawImage(m_pBk, destinationRect, rc.left , rc.top ,rc.Width (), rc.Height (),UnitPixel);
  46. }
  47. if(m_bFirst)
  48. {
  49. m_bFirst=0;
  50. m_nticks=::GetTickCount ();
  51. SetTimer(1, 10, NULL);
  52. }
  53. return 1;
  54. }
  55. void Welcome::OnCancel()
  56. {
  57. // TODO: Add extra cleanup here
  58. }
  59. void Welcome::OnOK()
  60. {
  61. // TODO: Add extra validation here
  62. }
  63. void Welcome::OnPaint()
  64. {
  65. CPaintDC dc(this); // device context for painting
  66. // TODO: Add your message handler code here
  67. if(m_pBk)
  68. {
  69. Graphics graph(dc.GetSafeHdc ());
  70. CRect rc;
  71. GetClientRect (rc);
  72. Rect destinationRect(0,0,rc.Width (), rc.Height ());
  73. graph.DrawImage(m_pBk, destinationRect, rc.left , rc.top ,rc.Width (), rc.Height (),UnitPixel);
  74. }
  75. if(m_bFirst)
  76. {
  77. m_bFirst=0;
  78. m_nticks=::GetTickCount ();
  79. SetTimer(1, 10, NULL);
  80. }
  81. // Do not call CDialog::OnPaint() for painting messages
  82. }
  83. void Welcome::OnDestroy()
  84. {
  85. // TODO: Add your message handler code here
  86. if(m_pBk)delete m_pBk;g_bNoConnDlg=0;
  87. CDialog::OnDestroy();
  88. }
  89. BOOL Welcome::OnInitDialog()
  90. {
  91. CDialog::OnInitDialog();
  92. // TODO: Add extra initialization here
  93. CString picdir=g_mainpath+"\\图片\\";
  94. if(g_bRedSkin)
  95. picdir=g_mainpath+"\\图片-红色风格\\";
  96. //MessageBox(picdir+"欢迎.jpg");
  97. // .Jeff加载欢迎图片,作为欢迎界面;
  98. if(::PathFileExists(picdir+"欢迎.jpg")==0)
  99. {
  100. if(0)//::PathFileExists (g_mainpath+"\\zx.dll"))
  101. {
  102. HINSTANCE hinst=::LoadLibrary (g_mainpath+"\\zx.dll");
  103. if(hinst==NULL)
  104. {
  105. ::LoadImageFromRes (&m_pBk, MAKEINTRESOURCE(IDR_JPG4), "JPG");
  106. }
  107. else
  108. {
  109. AfxSetResourceHandle(hinst);
  110. ::LoadImageFromRes (&m_pBk, MAKEINTRESOURCE(2009), "ZX");
  111. AfxSetResourceHandle(AfxGetInstanceHandle());
  112. FreeLibrary(hinst);
  113. }
  114. }
  115. else if(::PathFileExists (g_mainpath+"\\zwj.dll"))
  116. {
  117. HINSTANCE hinst=::LoadLibrary (g_mainpath+"\\zwj.dll");
  118. if(hinst==NULL)
  119. {
  120. ::LoadImageFromRes (&m_pBk, MAKEINTRESOURCE(IDR_JPG4), "JPG");
  121. }
  122. else
  123. {
  124. AfxSetResourceHandle(hinst);
  125. ::LoadImageFromRes (&m_pBk, MAKEINTRESOURCE(2009), "ZWJ");
  126. AfxSetResourceHandle(AfxGetInstanceHandle());
  127. FreeLibrary(hinst);
  128. }
  129. }
  130. else
  131. ::LoadImageFromRes (&m_pBk, MAKEINTRESOURCE(IDR_JPG4), "JPG");
  132. }
  133. else
  134. ::LoadImageFromBuf (&m_pBk, picdir+"欢迎.jpg");
  135. if(m_pBk)
  136. {
  137. // MessageBox("draw");
  138. CRect rc;
  139. GetWindowRect(rc);
  140. rc.right =rc.left +m_pBk->GetWidth();
  141. rc.bottom =rc.top +m_pBk->GetHeight();
  142. MoveWindow(rc);
  143. CenterWindow();
  144. CString str;
  145. int version=625;
  146. //str.Format ("00%d", version);
  147. str.Format("%d%d%d%d", g_arrFileVersion[0], g_arrFileVersion[1], g_arrFileVersion[2], g_arrFileVersion[3]);
  148. Graphics graph(m_pBk);
  149. if(0)// !g_bRedSkin)
  150. {
  151. Rect destinationRect(325,161, 59,15);
  152. SolidBrush *Brush2=new SolidBrush(Color(255,37,85,147));
  153. graph.FillRectangle (Brush2, destinationRect);
  154. delete Brush2;
  155. }
  156. StringFormat format;
  157. format.SetAlignment(StringAlignmentNear );
  158. RectF layoutRect(325,161, 59,15);
  159. SolidBrush *Brush=new SolidBrush(Color(255,255,255,255));
  160. int leng=str.GetLength ();
  161. BSTR bstr= str.AllocSysString();
  162. Font *g_TimerFont;
  163. g_TimerFont=new Font(L"黑体", 16);
  164. graph.SetTextRenderingHint(TextRenderingHintAntiAlias);
  165. //PointF pointF(325,161);
  166. ///graph.DrawString(L"Hello", -1, g_TimerFont, pointF, Brush);
  167. graph.DrawString(
  168. bstr,
  169. leng,
  170. g_TimerFont,
  171. layoutRect,
  172. &format,
  173. Brush);
  174. delete Brush;
  175. delete g_TimerFont;
  176. SysFreeString(bstr);
  177. }
  178. AnimateWindow(GetSafeHwnd(), 300, AW_BLEND);
  179. return TRUE; // return TRUE unless you set the focus to a control
  180. // EXCEPTION: OCX Property Pages should return FALSE
  181. }
  182. CString GetFileSize(CString path)
  183. {
  184. CString str="0";
  185. try
  186. {
  187. CFile fp;
  188. if( fp.Open(path, CFile::modeRead) )
  189. {
  190. str.Format("%d", fp.GetLength());
  191. fp.Close();
  192. }
  193. }
  194. catch(...)
  195. {
  196. }
  197. return str;
  198. }
  199. void Welcome::OnTimer(UINT nIDEvent)
  200. {
  201. if(nIDEvent==1)
  202. {
  203. KillTimer(1);
  204. if(g_bGenBranchData)
  205. {
  206. WriteClientLog("启动分店操作");
  207. // 1.Jeff.获取存储在本地服务器目录下的branchinfo.dat文件内容;
  208. CArray<CStringArray, CStringArray>brancharray;
  209. g_sendhead.bsql=0;
  210. g_sendhead.code[0]=152; // Jeff.152获取DBServer.exe所在目录的branchinfo.dat里保存的分店内容;
  211. g_sendhead.tabcount=1;
  212. g_pMainWnd->ProcessChatMessageRequest2(1);
  213. if(g_bSendOK==0)//Jeff.通信失败;
  214. {
  215. exit(0);
  216. return;
  217. }
  218. DataToArray(&brancharray);
  219. // 2.Jeff.若branchinfo.dat里有多家分店信息,则遍历全部分店信息;
  220. CString branch,domain;
  221. CArray<CStringArray, CStringArray>tagList1array; // Jeff.不规范的变量名称!!!
  222. for(int i=-1; i<brancharray.GetSize ()-1; i++)
  223. {
  224. //printf("Jeff:branchinfo.dat分店数量=%d,i=%d\n\n",brancharray.GetSize(),i);
  225. if(i!=-1)
  226. {
  227. WriteClientLog("只有单店,无分店");
  228. domain=brancharray.ElementAt (i).ElementAt (2); // Jeff.本店的*.ly.com信息;
  229. branch=brancharray.ElementAt (i).ElementAt (0); // Jeff.本店做为分店的名称;
  230. g_branchip=brancharray.ElementAt (i).ElementAt (1); // Jeff.本店外网IP地址;
  231. g_pMainWnd->OnDisconnect();
  232. g_branchname=branch;
  233. g_bBranchModify=1;
  234. }
  235. else
  236. {
  237. domain=brancharray.ElementAt (brancharray.GetSize ()-1).ElementAt (2);
  238. branch=brancharray.ElementAt (brancharray.GetSize ()-1).ElementAt (0);
  239. }
  240. // 2.1.获取本机数据库的dindan表信息:订单号、取件时间, 发送到本店服务器中;
  241. // 本店服务器会将这些信息存储在服务目录下branchdindan.dat文件中;
  242. //
  243. CString filter="status3='OK' and time5 is not null and time5<>''";
  244. g_sendhead.bsql=0;
  245. g_sendhead.code[0]=231; // Jeff.case 231->获取db数据库以及所有历史数据库中已完成取件的定单;
  246. g_sendhead.tabcount=1;
  247. g_pMainWnd->ProcessChatMessageRequest2(filter);if(g_bSendOK==0)continue;
  248. CArray<CStringArray, CStringArray>List1array;
  249. DataToArray(&List1array);
  250. int size=tagList1array.GetSize ();
  251. for(int j=0; j<List1array.GetSize (); j++)
  252. {
  253. size++;
  254. tagList1array.SetSize(size , 1 );
  255. size--;
  256. tagList1array.ElementAt (size).Copy (List1array.ElementAt (j));
  257. tagList1array.ElementAt (size).InsertAt (0, domain); // Jeff.*.ly.com
  258. size++;
  259. }
  260. }
  261. g_pMainWnd->OnDisconnect();
  262. g_bBranchModify=0;
  263. g_branchip=g_branchname="";
  264. // 3.将domain、订单号、取件时间 存储在tagList1array;
  265. // 存储在内存中,发送到本机服务器中,由服务器生成branchdindan.dat文件中,待用;
  266. CMemFile memfile;
  267. CArchive ar(&memfile, CArchive::store);
  268. for(int ii=0; ii<tagList1array.GetSize (); ii++)
  269. {
  270. tagList1array.ElementAt (ii).Serialize (ar);
  271. }
  272. ar.Close();
  273. int length=memfile.GetLength ();
  274. BYTE *pData = memfile.Detach();
  275. int size=tagList1array.GetSize ();
  276. BYTE *pData2=new BYTE[length+sizeof(int)];
  277. memcpy(pData2, pData, length);
  278. memcpy(pData2+length, &size, sizeof(int));
  279. delete []pData;
  280. length+=sizeof(int);
  281. g_nSendCode=41; // dwToUserID==41 处理 branchdindan.dat 文件;
  282. g_pMainWnd->ProcessChatMessageRequest2(pData2, length);
  283. g_nSendCode=0;
  284. delete []pData2;
  285. exit(0);
  286. return;
  287. }
  288. BOOL bSuccess=1;
  289. CStringArray filesarray;
  290. filesarray.Add ("AutoUpdate.exe");
  291. filesarray.Add ("skin\\1.lia");
  292. filesarray.Add ("skin\\2.lia");
  293. filesarray.Add ("skin\\3.lia");
  294. filesarray.Add ("skin\\4.lia");
  295. filesarray.Add ("skin\\5.lia");
  296. filesarray.Add ("skin\\10.lia");
  297. filesarray.Add ("skin\\5-red.lia");
  298. filesarray.Add ("skin\\10-red.lia");
  299. filesarray.Add ("图片\\logo.jpg"); // .10.
  300. filesarray.Add ("图片\\标题-选片.jpg");
  301. filesarray.Add ("图片\\标题-看设计.jpg");
  302. filesarray.Add ("图片\\选片.jpg");
  303. filesarray.Add ("图片\\看设计.jpg");
  304. filesarray.Add ("图片\\欢迎.jpg");
  305. filesarray.Add ("图片\\连接.jpg");
  306. filesarray.Add ("图片\\标题.jpg");
  307. filesarray.Add ("图片\\背景.jpg");
  308. filesarray.Add ("图片-红色风格\\欢迎.jpg");
  309. filesarray.Add ("图片-红色风格\\连接.jpg"); // .20.
  310. filesarray.Add ("图片-红色风格\\标题.jpg");
  311. filesarray.Add ("图片-红色风格\\背景.jpg");
  312. filesarray.Add ("skin\\6.lia");
  313. filesarray.Add ("图片\\掌中宝.jpg");
  314. filesarray.Add ("regsvr32.exe"); // .25.
  315. ::CreateDirectory (g_mainpath+"\\skin", NULL);
  316. ::CreateDirectory (g_mainpath+"\\图片", NULL);
  317. ::CreateDirectory (g_mainpath+"\\图片-红色风格", NULL);
  318. // 1.Jeff.array分上下两部分,前半部分保存着文件路径名,后半部分保存着上半部分文件的大小;
  319. CStringArray array;
  320. array.Copy(filesarray);
  321. for(int i=0; i<filesarray.GetSize(); i++)
  322. {
  323. // array.Add (GetModifyTime (g_mainpath+"\\"+filesarray.ElementAt (i)));
  324. array.Add (GetFileSize(g_mainpath+"\\"+filesarray.ElementAt(i)));
  325. // if(filesarray.ElementAt (i).Find("5.lia")!=-1)
  326. // AfxMessageBox(GetFileSize (g_mainpath+"\\"+filesarray.ElementAt (i)));
  327. }
  328. // 2.将array用内存文件处理,作为二进制数据与服务端通信;
  329. {
  330. CMemFile memfile;
  331. CArchive ar(&memfile, CArchive::store);
  332. array.Serialize(ar);
  333. ar.Close();
  334. DWORD length=memfile.GetLength ();
  335. BYTE *pData = memfile.Detach();
  336. #if 0 // Jeff.原
  337. ll: g_nSendCode=211;//Jeff.已经没用到这个goto了;
  338. #else
  339. g_nSendCode = 211;//g_nSendCode=211: 更新 \服务端\skin\ 文件夹下的大小变更的文件到客户端去;
  340. #endif
  341. g_pMainWnd->ProcessChatMessageRequest2(pData, length);
  342. if(g_bSendOK==0)
  343. { //AfxMessageBox("2");
  344. exit(0);
  345. return;
  346. }
  347. g_nSendCode=0;
  348. delete []pData;
  349. if(g_bSendOK==0) // Jeff.前面都exit和return了,后面还有用么????
  350. {
  351. bSuccess=0;
  352. CDialog::OnCancel();
  353. g_pMainWnd->m_pMainFrimDlg2=new MainFrimDlg2;
  354. g_pMainWnd->m_pMainFrimDlg2->SetLiaPath("10.lia");
  355. // Jeff.remak.2014.06.26
  356. // MainFrimDlg2::Create调用了MyDlg::OnInitDialog(),接着调用LoadLia()
  357. // LoadLia()再调用GetPos(),GetPost()调用了ProcessChatMessageRequest2:code[0]=105
  358. g_pMainWnd->m_pMainFrimDlg2->Create(IDD_DLGmydlg, g_pMainWnd);
  359. return;
  360. }
  361. }
  362. // Jeff.g_pData2里保存的是更新的数据;
  363. BYTE *pData[40]={NULL};
  364. DWORD nDataLeng[40]={0};
  365. BYTE *pSumData=g_pData2;
  366. DWORD sumleng=g_nLeng2;
  367. CStringArray filedatearray;
  368. DWORD nArrayLength;
  369. memcpy(&nArrayLength, pSumData, sizeof(DWORD));
  370. CMemFile memfile;
  371. memfile.Attach (pSumData+sizeof(DWORD), nArrayLength);
  372. CArchive ar(&memfile, CArchive::load);
  373. filedatearray.Serialize (ar);
  374. ar.Close();
  375. memfile.Detach ();
  376. // Jeff.
  377. DWORD bytesread=0;
  378. DWORD a;
  379. int pos=0;
  380. CString stime;
  381. for( i=0; i<40; i++)
  382. {
  383. memcpy(&a, pSumData+sizeof(DWORD)*i+nArrayLength+sizeof(DWORD), sizeof(DWORD));
  384. nDataLeng[i]=a;
  385. if(a)
  386. {
  387. CFile fp;
  388. if(fp.Open (g_mainpath+"\\"+filesarray.ElementAt(i), CFile::modeCreate|CFile::modeWrite))
  389. {
  390. fp.Write (pSumData+sizeof(DWORD)*40+bytesread+nArrayLength+sizeof(DWORD), a);
  391. bytesread+=a;
  392. fp.Close ();
  393. stime=filedatearray.ElementAt (pos);
  394. pos++;
  395. /* if(stime.GetLength ()==32)
  396. {
  397. FILETIME localtime;
  398. FILETIME localtime2;
  399. localtime.dwHighDateTime =atol(stime.Left (16));
  400. localtime.dwLowDateTime =atol(stime.Right (16));
  401. HANDLE hFile = CreateFile(g_mainpath+"\\"+filesarray.ElementAt (i), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_DELETE,NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
  402. LocalFileTimeToFileTime(&localtime, &localtime2);
  403. SetFileTime(hFile, NULL, NULL,&localtime2);
  404. CloseHandle(hFile);
  405. }*/
  406. }
  407. else
  408. {
  409. bSuccess=0;
  410. break;
  411. }
  412. }
  413. }
  414. //if( g_server.Find ("192.168.10.")!=-1 )::Sleep(3000);
  415. if(g_pData2)
  416. delete []g_pData2;
  417. g_pData2=NULL;
  418. g_pMainWnd->m_pMainFrimDlg2=new MainFrimDlg2;
  419. g_pMainWnd->m_pMainFrimDlg2->SetLiaPath ("10.lia");
  420. // Jeff.remak.2014.06.26
  421. // MainFrimDlg2::Create调用了MyDlg::OnInitDialog(),接着调用LoadLia()
  422. // LoadLia()再调用GetPos(),GetPost()调用了ProcessChatMessageRequest2:code[0]=105
  423. // case 105:界面;
  424. // case 218:client表;
  425. g_pMainWnd->m_pMainFrimDlg2->Create(IDD_DLGmydlg, g_pMainWnd);
  426. g_sendhead.bsql=0;
  427. // AfxMessageBox("6");
  428. g_sendhead.code[0]=218;
  429. g_sendhead.tabcount=1;
  430. // if( g_server.Find ("192.168.10.")!=-1 )::Sleep(3000);
  431. g_pMainWnd->ProcessChatMessageRequest2(1);
  432. if(g_bSendOK==0)
  433. { //AfxMessageBox("7");
  434. exit(0);
  435. return;
  436. }
  437. //AfxMessageBox("8");
  438. DataToArray(&g_oldclientarray);
  439. if(::GetTickCount ()-m_nticks<2000)
  440. ::Sleep (2000-(::GetTickCount ()-m_nticks));
  441. CDialog::OnCancel ();
  442. }
  443. else if (nIDEvent == 0)
  444. {
  445. CRect dlgRect;
  446. CRect DesktopRect;
  447. GetWindowRect(dlgRect);
  448. GetDesktopWindow()->GetWindowRect(DesktopRect);
  449. if (dlgRect.Width() >= (dlgWidth - dlgDx) ) dlgDx = dlgWidth - dlgRect.Width();
  450. if (dlgRect.Height() >= (dlgHeight - dlgDy) ) dlgDy = dlgHeight - dlgRect.Height();
  451. MoveWindow
  452. (
  453. ( -dlgDx+DesktopRect.Width() - dlgRect.Width() )/2,
  454. ( -dlgDy+DesktopRect.Height() - dlgRect.Height() )/2,
  455. +dlgDx+dlgRect.Width(),
  456. +dlgDy+dlgRect.Height()
  457. );
  458. if ( ( dlgRect.Width() >= (dlgWidth - dlgDx) ) && ( dlgRect.Height() >= (dlgHeight - dlgDy) ) )
  459. ::KillTimer(this->m_hWnd, 0);
  460. }
  461. }