Worker.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. // Worker.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "Worker.h"
  6. #include "MyMdi.H"
  7. #include "ShowPhoto.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // Worker
  15. IMPLEMENT_DYNCREATE(Worker, MyFormView)
  16. Worker::Worker()
  17. : MyFormView(Worker::IDD)
  18. {
  19. //{{AFX_DATA_INIT(Worker)
  20. m_bz = _T("");
  21. m_sex = _T("");
  22. m_id = _T("");
  23. m_phone = _T("");
  24. m_address = _T("");
  25. m_name = _T("");
  26. m_address2 = _T("");
  27. m_idno = _T("");
  28. m_loginno1 = _T("");
  29. m_loginno2 = _T("");
  30. m_pImg = NULL;
  31. //}}AFX_DATA_INIT
  32. }
  33. Worker::~Worker()
  34. {
  35. if (m_pImg)delete m_pImg;
  36. }
  37. void Worker::DoDataExchange(CDataExchange* pDX)
  38. {
  39. MyFormView::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(Worker)
  41. DDX_Control(pDX, IDC_COMBOlevel, m_combolevel);
  42. DDX_Control(pDX, IDC_COMBOdimission, m_combodimission);
  43. DDX_Control(pDX, IDC_COMBOmarry, m_combomarry);
  44. DDX_Control(pDX, IDC_COMBOsex, m_combosex);
  45. DDX_Control(pDX, IDC_COMBObm, m_combobm);
  46. DDX_Control(pDX, IDC_LIST2, m_List1);
  47. DDX_Control(pDX, IDC_STATIC1, m_static1);
  48. DDX_Text(pDX, IDC_EDITbz, m_bz);
  49. DDV_MaxChars(pDX, m_bz, 1000);
  50. DDX_Text(pDX, IDC_EDITid, m_id);
  51. DDX_Text(pDX, IDC_EDITphone, m_phone);
  52. DDX_Text(pDX, IDC_EDITaddress, m_address);
  53. DDX_Text(pDX, IDC_EDITname, m_name);
  54. DDX_Text(pDX, IDC_EDITaddress2, m_address2);
  55. DDX_Text(pDX, IDC_EDITidno, m_idno);
  56. DDX_Text(pDX, IDC_EDITloginno1, m_loginno1);
  57. DDX_Text(pDX, IDC_EDITloginno2, m_loginno2);
  58. //}}AFX_DATA_MAP
  59. }
  60. BEGIN_MESSAGE_MAP(Worker, MyFormView)
  61. //{{AFX_MSG_MAP(Worker)
  62. ON_BN_CLICKED(IDC_BUTsave, OnBUTsave)
  63. ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
  64. ON_BN_CLICKED(IDC_BUTclose, OnBUTclose)
  65. ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2)
  66. ON_BN_CLICKED(IDC_BUTadd, OnBUTadd)
  67. ON_BN_CLICKED(IDC_BUTAutoGet, OnBUTAutoGet)
  68. ON_BN_CLICKED(IDC_BUTload, OnBUTload)
  69. ON_BN_CLICKED(IDC_BUTdel2, OnBUTdel2)
  70. ON_WM_PAINT()
  71. ON_WM_LBUTTONDOWN()
  72. //}}AFX_MSG_MAP
  73. END_MESSAGE_MAP()
  74. /////////////////////////////////////////////////////////////////////////////
  75. // Worker diagnostics
  76. #ifdef _DEBUG
  77. void Worker::AssertValid() const
  78. {
  79. MyFormView::AssertValid();
  80. }
  81. void Worker::Dump(CDumpContext& dc) const
  82. {
  83. MyFormView::Dump(dc);
  84. }
  85. #endif //_DEBUG
  86. /////////////////////////////////////////////////////////////////////////////
  87. // Worker message handlers
  88. void Worker::OnInitialUpdate()
  89. {
  90. MyFormView::OnInitialUpdate();
  91. // TODO: Add your specialized code here and/or call the base class
  92. CMyMdi Mdi;
  93. Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this);
  94. // Here we create the outbar control using the splitter as its parent
  95. // and setting its id to the first pane.
  96. CRect rc2;
  97. GetWindowRect(rc2);
  98. ::MoveWindow(m_hWnd, g_rc.left, g_rc.top, g_rc.Width(), g_rc.Height(), TRUE);
  99. EnumChildWindows(m_hWnd, (WNDENUMPROC)EnumChildProc, 0);
  100. m_combobm.GetWindowRect(rc2);
  101. ScreenToClient(rc2);
  102. rc2.bottom += 200;
  103. m_combobm.MoveWindow(rc2);
  104. m_combosex.GetWindowRect(rc2);
  105. ScreenToClient(rc2);
  106. rc2.bottom += 200;
  107. m_combosex.MoveWindow(rc2);
  108. m_combomarry.GetWindowRect(rc2);
  109. ScreenToClient(rc2);
  110. rc2.bottom += 200;
  111. m_combomarry.MoveWindow(rc2);
  112. m_combodimission.GetWindowRect(rc2);
  113. ScreenToClient(rc2);
  114. rc2.bottom += 200;
  115. m_combodimission.MoveWindow(rc2);
  116. m_combolevel.GetWindowRect(rc2);
  117. ScreenToClient(rc2);
  118. rc2.bottom += 200;
  119. m_combolevel.MoveWindow(rc2);
  120. GetDlgItem(IDC_BUTsave)->EnableWindow(IsHasRights2new(27));
  121. GetDlgItem(IDC_BUTdel)->EnableWindow(IsHasRights2new(27));
  122. m_static1.SetFont(&g_titlefont);
  123. m_List1.SetHeadings("编号, 60;姓名, 60;部门, 60;性别, 60;电话, 60;地址, 60;指纹1,60;指纹2,60;文件权限,60");
  124. m_List1.LoadColumnInfo(101);
  125. g_sendhead.bsql = 0;
  126. g_sendhead.code[0] = 3;
  127. g_sendhead.tabcount = 1;
  128. g_pMainWnd->ProcessChatMessageRequest2(3); if (g_bSendOK == 0)return;
  129. DataToArray(&g_List1array);
  130. for (int i = 0; i < g_List1array.GetSize(); i++)
  131. m_combobm.AddString(g_List1array.ElementAt(i).ElementAt(0));
  132. m_combosex.AddString("女");
  133. m_combosex.AddString("男");
  134. m_combomarry.AddString("未婚");
  135. m_combomarry.AddString("已婚");
  136. m_combodimission.AddString("在职");
  137. m_combodimission.AddString("离职");
  138. m_combolevel.AddString("1级");
  139. m_combolevel.AddString("2级");
  140. m_combolevel.AddString("3级");
  141. m_combolevel.AddString("4级");
  142. m_combolevel.AddString("5级");
  143. m_combolevel.SetCurSel(0);
  144. GetData();
  145. }
  146. void Worker::FillGrid()
  147. {
  148. m_List1.DeleteAllItems2();
  149. int ii = 0;
  150. m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1);
  151. int count = 0;
  152. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  153. {
  154. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  155. }
  156. m_List1.m_arLabels.SetSize(count, 1);
  157. ii = count;
  158. m_List1.m_LabelCount = ii;
  159. m_List1.SetItemCountEx(ii);
  160. OnBUTadd();
  161. }
  162. void Worker::OnBUTclose()
  163. {
  164. // TODO: Add your control notification handler code here
  165. GetParent()->SendMessage(WM_CLOSE);
  166. }
  167. void Worker::ClearCtrl()
  168. {
  169. m_bz = _T("");
  170. m_sex = _T("");
  171. m_id = _T("");
  172. m_phone = _T("");
  173. m_address = _T("");
  174. m_name = _T("");
  175. m_address2 = _T("");
  176. m_idno = _T("");
  177. m_loginno1 = _T("");
  178. m_loginno2 = _T("");
  179. m_combolevel.SetCurSel(0);
  180. UpdateData(false);
  181. if (m_pImg)delete m_pImg; m_pImg = NULL;
  182. CRect rc;
  183. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  184. ScreenToClient(rc);
  185. InvalidateRect(rc);
  186. }
  187. void Worker::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
  188. {
  189. // TODO: Add your control notification handler code here
  190. ListSelChange();
  191. *pResult = 0;
  192. }
  193. void Worker::ListSelChange()
  194. {
  195. POSITION pos;
  196. pos = m_List1.GetFirstSelectedItemPosition();
  197. if (pos == NULL)
  198. {
  199. OnBUTadd();
  200. return;
  201. }
  202. int iItem = m_List1.GetNextSelectedItem(pos);
  203. m_oldid = m_List1.GetItemText(iItem, 0);
  204. m_oldname = m_List1.GetItemText(iItem, 1);
  205. CString level;
  206. for (int ii = 0; ii < m_List1arrayBak.GetSize(); ii++)
  207. {
  208. if (m_List1arrayBak.ElementAt(ii).ElementAt(0) == m_oldid)
  209. {
  210. GetDlgItem(IDC_BUTload)->EnableWindow(1);
  211. GetDlgItem(IDC_BUTdel2)->EnableWindow(1);
  212. CString bm, marry, dimission;
  213. m_id = m_List1arrayBak.ElementAt(ii).ElementAt(0);
  214. m_name = m_List1arrayBak.ElementAt(ii).ElementAt(1);
  215. bm = m_List1arrayBak.ElementAt(ii).ElementAt(2);
  216. m_sex = m_List1arrayBak.ElementAt(ii).ElementAt(3);
  217. m_phone = m_List1arrayBak.ElementAt(ii).ElementAt(4);
  218. m_address = m_List1arrayBak.ElementAt(ii).ElementAt(5);
  219. m_bz = m_List1arrayBak.ElementAt(ii).ElementAt(6);
  220. m_address2 = m_List1arrayBak.ElementAt(ii).ElementAt(7);
  221. m_idno = m_List1arrayBak.ElementAt(ii).ElementAt(8);
  222. marry = m_List1arrayBak.ElementAt(ii).ElementAt(9);
  223. dimission = m_List1arrayBak.ElementAt(ii).ElementAt(10);
  224. m_loginno1 = m_List1arrayBak.ElementAt(ii).ElementAt(11);
  225. m_loginno2 = m_List1arrayBak.ElementAt(ii).ElementAt(12);
  226. level = m_List1arrayBak.ElementAt(ii).ElementAt(13);
  227. UpdateData(false);
  228. int pos = m_combobm.FindString(0, bm);
  229. m_combobm.SetCurSel(pos);
  230. pos = m_combosex.FindString(0, m_sex);
  231. m_combosex.SetCurSel(pos);
  232. pos = m_combomarry.FindString(0, marry);
  233. m_combomarry.SetCurSel(pos);
  234. pos = m_combodimission.FindString(0, dimission);
  235. m_combodimission.SetCurSel(pos);
  236. pos = m_combolevel.FindString(0, level);
  237. m_combolevel.SetCurSel(pos);
  238. char no[100];
  239. memset(no, 0, 100);
  240. strcpy(no, m_id);
  241. g_nSendCode = 27;
  242. g_pMainWnd->ProcessChatMessageRequest2((BYTE*)no, 100);
  243. g_nSendCode = 0;
  244. if (g_bSendOK == 0)
  245. {
  246. return;
  247. }
  248. // g_pData, g_nLeng
  249. if (m_pImg)delete m_pImg; m_pImg = NULL;
  250. ::LoadImageFromBuf(&m_pImg, g_pData, g_nLeng);
  251. if (m_pImg == NULL)
  252. {
  253. AfxMessageBox("无效图片文件!"); return;
  254. }
  255. CRect rc;
  256. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  257. ScreenToClient(rc);
  258. InvalidateRect(rc);
  259. return;
  260. }
  261. }
  262. }
  263. void Worker::OnBUTadd()
  264. {
  265. // TODO: Add your control notification handler code here
  266. m_oldid.Empty();
  267. m_oldname.Empty();
  268. ClearCtrl(); OnBUTAutoGet();
  269. GetDlgItem(IDC_BUTload)->EnableWindow(0);
  270. GetDlgItem(IDC_BUTdel2)->EnableWindow(0);
  271. }
  272. void Worker::OnBUTsave() // Jeff:保存按钮;
  273. {
  274. // TODO: Add your control notification handler code here
  275. UpdateData();
  276. if (m_id.IsEmpty() || m_name.IsEmpty() || m_phone.IsEmpty() || m_address.IsEmpty() || m_address2.IsEmpty() || m_idno.IsEmpty())
  277. {
  278. AfxMessageBox("资料不全!", MB_ICONINFORMATION);
  279. return;
  280. }
  281. m_loginno1.TrimLeft();
  282. m_loginno1.TrimRight();
  283. m_loginno1.TrimLeft("0");
  284. m_loginno2.TrimLeft();
  285. m_loginno2.TrimRight();
  286. m_loginno2.TrimLeft("0");
  287. CString sql;
  288. CString bm, dimission, marry, level;
  289. int pos = m_combobm.GetCurSel();
  290. if (pos == -1)
  291. {
  292. AfxMessageBox("资料不全!", MB_ICONINFORMATION); return;
  293. }
  294. m_combobm.GetLBText(pos, bm);
  295. pos = m_combosex.GetCurSel();
  296. if (pos == -1)
  297. {
  298. AfxMessageBox("资料不全!", MB_ICONINFORMATION); return;
  299. }
  300. m_combosex.GetLBText(pos, m_sex);
  301. pos = m_combomarry.GetCurSel();
  302. if (pos == -1)
  303. {
  304. AfxMessageBox("资料不全!", MB_ICONINFORMATION); return;
  305. }
  306. m_combomarry.GetLBText(pos, marry);
  307. pos = m_combodimission.GetCurSel();
  308. if (pos == -1)
  309. {
  310. AfxMessageBox("资料不全!", MB_ICONINFORMATION); return;
  311. }
  312. m_combodimission.GetLBText(pos, dimission);
  313. #if 0 // Jeff Modify
  314. pos=m_combolevel.GetCurSel();
  315. if(pos==-1)
  316. {
  317. AfxMessageBox("资料不全!", MB_ICONINFORMATION);return;
  318. }
  319. m_combolevel.GetLBText(pos, level);
  320. #else
  321. level = "1";
  322. #endif
  323. if (m_oldid.IsEmpty())//新增
  324. {
  325. if (IsExist())
  326. {
  327. AfxMessageBox("已有此编号或姓名或指纹的员工,请重新输入!", MB_ICONINFORMATION);
  328. return;
  329. }
  330. sql.Format("insert into renyuan(bm,id,name,sex,phone,address,bz,address2,idno,marry,dimission,loginno1,loginno2,level) values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')", bm, m_id, m_name, m_sex, m_phone, m_address, m_bz, m_address2, m_idno, marry, dimission, m_loginno1, m_loginno2, level);
  331. g_sendhead.bsql = 1;
  332. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  333. GetData();
  334. }
  335. else//修改
  336. {
  337. if (m_oldid != m_id)
  338. {
  339. if (IsExistID())
  340. {
  341. AfxMessageBox("已有此编号的员工,请重新输入!", MB_ICONINFORMATION);
  342. return;
  343. }
  344. }
  345. if (m_oldname != m_name)
  346. {
  347. if (IsExistName())
  348. {
  349. AfxMessageBox("已有此姓名的员工,请重新输入!", MB_ICONINFORMATION);
  350. return;
  351. }
  352. }
  353. sql.Format("update renyuan set bm='%s',id='%s',name='%s',sex='%s',phone='%s',address='%s',bz='%s',address2='%s',idno='%s',marry='%s',dimission='%s',loginno1='%s',loginno2='%s',level='%s' where id='%s'", bm, m_id, m_name, m_sex, m_phone, m_address, m_bz, m_address2, m_idno, marry, dimission, m_loginno1, m_loginno2, level, m_oldid);
  354. if (m_oldname != m_name)
  355. {
  356. sql += "***update [user] set [name]='" + m_name + "' where [name]='" + m_oldname + "'";
  357. }
  358. g_sendhead.bsql = 1;
  359. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  360. GetData();
  361. }
  362. }
  363. void Worker::OnBUTdel()
  364. {
  365. // TODO: Add your control notification handler code here
  366. POSITION pos;
  367. pos = m_List1.GetFirstSelectedItemPosition();
  368. if (pos == NULL)
  369. {
  370. return;
  371. }
  372. if (AfxMessageBox("确认删除吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  373. int iItem = m_List1.GetNextSelectedItem(pos);
  374. CString id = m_List1.GetItemText(iItem, 0);
  375. CString sql;
  376. sql.Format("delete from renyuan where id='%s' ", id);
  377. sql += RENYUAN_REF;
  378. g_sendhead.bsql = 1;
  379. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  380. GetData();
  381. }
  382. void Worker::GetData()
  383. {
  384. g_sendhead.bsql = 0;
  385. g_sendhead.code[0] = 5;
  386. g_sendhead.tabcount = 1;
  387. int g_nYearposTemp = g_nYearpos;
  388. g_nYearpos = -1;
  389. g_pMainWnd->ProcessChatMessageRequest2(1);
  390. g_nYearpos = g_nYearposTemp;
  391. if (g_bSendOK == 0)return;
  392. DataToArray(&m_List1array);
  393. m_List1arrayBak.SetSize(m_List1array.GetSize());
  394. for (int i = 0; i < m_List1array.GetSize(); i++)
  395. {
  396. m_List1arrayBak.ElementAt(i).Copy(m_List1array.ElementAt(i));
  397. m_List1array.ElementAt(i).RemoveAt(6, 5);
  398. }
  399. FillGrid();
  400. g_userarray.SetSize(m_List1arrayBak.GetSize(), 1);
  401. int count = 0;
  402. for (int ii = 0; ii < m_List1arrayBak.GetSize(); ii++)
  403. {
  404. if (m_List1arrayBak.ElementAt(ii).ElementAt(10) == "在职")
  405. g_userarray.ElementAt(count++).Copy(m_List1arrayBak.ElementAt(ii));
  406. }
  407. g_userarray.SetSize(count, 1);
  408. }
  409. BOOL Worker::IsExist()
  410. {
  411. CString str1, str2;
  412. for (int i = 0; i < m_List1arrayBak.GetSize(); i++)
  413. {
  414. if (m_id == m_List1arrayBak.ElementAt(i).ElementAt(0))return 1;
  415. if (m_name == m_List1arrayBak.ElementAt(i).ElementAt(1))return 1;
  416. str1 = m_loginno1;
  417. str2 = m_List1arrayBak.ElementAt(i).ElementAt(11);
  418. str1.TrimLeft("0");
  419. str2.TrimLeft("0");
  420. if (str1 == str2 && str1 != "")return 1;
  421. str1 = m_loginno2;
  422. str2 = m_List1arrayBak.ElementAt(i).ElementAt(12);
  423. str1.TrimLeft("0");
  424. str2.TrimLeft("0");
  425. if (str1 == str2 && str1 != "")return 1;
  426. }
  427. return 0;
  428. }
  429. BOOL Worker::IsExistID()
  430. {
  431. for (int i = 0; i < m_List1arrayBak.GetSize(); i++)
  432. {
  433. if (m_id == m_List1arrayBak.ElementAt(i).ElementAt(0))return 1;
  434. }
  435. return 0;
  436. }
  437. BOOL Worker::IsExistName()
  438. {
  439. for (int i = 0; i < m_List1arrayBak.GetSize(); i++)
  440. {
  441. if (m_name == m_List1arrayBak.ElementAt(i).ElementAt(1))return 1;
  442. }
  443. return 0;
  444. }
  445. BOOL Worker::PreTranslateMessage(MSG* pMsg)
  446. {
  447. // TODO: Add your specialized code here and/or call the base class
  448. try
  449. {
  450. if (pMsg->message == WM_KEYDOWN)
  451. {
  452. switch (pMsg->wParam)
  453. {
  454. case 0x43: // copy
  455. if ((GetKeyState(VK_CONTROL) & 0x80))
  456. {
  457. GetFocus()->SendMessage(WM_COPY);
  458. return TRUE;
  459. }
  460. break;
  461. case 0x56: //Ctrl + V:
  462. if ((GetKeyState(VK_CONTROL) & 0x80))
  463. {
  464. GetFocus()->SendMessage(WM_PASTE);
  465. return TRUE;
  466. }
  467. break;
  468. case 0x58: // cut
  469. if ((GetKeyState(VK_CONTROL) & 0x80))
  470. {
  471. GetFocus()->SendMessage(WM_CUT);
  472. return TRUE;
  473. }
  474. break;
  475. case 0x5A: //undo
  476. case 0x59: //redo
  477. if ((GetKeyState(VK_CONTROL) & 0x80))
  478. {
  479. GetFocus()->SendMessage(WM_UNDO);
  480. return TRUE;
  481. }
  482. break;
  483. }
  484. }
  485. return MyFormView::PreTranslateMessage(pMsg);
  486. }
  487. catch (...)
  488. {
  489. }
  490. }
  491. void Worker::OnBUTAutoGet()
  492. {
  493. // TODO: Add your control notification handler code here
  494. UpdateData();
  495. int begin = 1;
  496. BOOL bFind = 1;
  497. while (bFind)
  498. {
  499. m_id.Format("%03d", begin++);
  500. for (int i = 0; i < m_List1arrayBak.GetSize(); i++)
  501. {
  502. if (m_id == m_List1arrayBak.ElementAt(i).ElementAt(0))
  503. {
  504. break;
  505. }
  506. }
  507. if (i == m_List1arrayBak.GetSize())bFind = 0;
  508. }
  509. UpdateData(false);
  510. }
  511. void Worker::OnBUTload()
  512. {
  513. // TODO: Add your control notification handler code here
  514. UpdateData();
  515. CFileDialog fdlg(true, NULL, "", OFN_HIDEREADONLY, "jpg files(*jpg)|*.jpg||");
  516. if (fdlg.DoModal() != IDOK)return;
  517. CString path = fdlg.GetPathName();
  518. CFile fp;
  519. if (!fp.Open(path, CFile::modeRead))
  520. {
  521. AfxMessageBox("文件打开失败!");
  522. return;
  523. }
  524. DWORD length = fp.GetLength();
  525. if (length > 1024 * 200)
  526. {
  527. AfxMessageBox("文件太大,请上传小于200K的图片!");
  528. fp.Close();
  529. return;
  530. }
  531. BYTE *m_pData = new BYTE[length + 100];
  532. fp.Read(m_pData, length);
  533. fp.Close();
  534. char no[100];
  535. memset(no, 0, 100);
  536. strcpy(no, m_id);
  537. memcpy(m_pData + length, no, 100);
  538. if (m_pImg)delete m_pImg; m_pImg = NULL;
  539. ::LoadImageFromBuf(&m_pImg, path);
  540. if (m_pImg == NULL)
  541. {
  542. AfxMessageBox("无效图片文件!"); return;
  543. }
  544. g_nSendCode = 26;
  545. g_pMainWnd->ProcessChatMessageRequest2(m_pData, length + 100);
  546. g_nSendCode = 0;
  547. delete[]m_pData;
  548. if (g_bSendOK == 0)
  549. {
  550. if (m_pImg)delete m_pImg; m_pImg = NULL;
  551. return;
  552. }
  553. AfxMessageBox("上传成功!");
  554. CRect rc;
  555. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  556. ScreenToClient(rc);
  557. InvalidateRect(rc);
  558. }
  559. void Worker::OnBUTdel2()
  560. {
  561. // TODO: Add your control notification handler code here
  562. if (AfxMessageBox("确认删除吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  563. UpdateData();
  564. char no[100];
  565. memset(no, 0, 100);
  566. strcpy(no, m_id);
  567. g_nSendCode = 26;
  568. g_pMainWnd->ProcessChatMessageRequest2((BYTE*)no, 100);
  569. g_nSendCode = 0;
  570. if (g_bSendOK == 0)
  571. {
  572. return;
  573. }
  574. if (m_pImg)delete m_pImg; m_pImg = NULL;
  575. CRect rc;
  576. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  577. ScreenToClient(rc);
  578. InvalidateRect(rc);
  579. }
  580. void Worker::OnPaint()
  581. {
  582. CPaintDC dc(this); // device context for painting
  583. // TODO: Add your message handler code here
  584. if (m_pImg)
  585. {
  586. CRect rc;
  587. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  588. ScreenToClient(rc);
  589. RectFitDes(m_pImg->GetWidth(), m_pImg->GetHeight(), rc);
  590. Graphics dcgraph(dc.GetSafeHdc());
  591. Rect destinationRect(rc.left, rc.top, rc.Width(), rc.Height());
  592. dcgraph.DrawImage(m_pImg, destinationRect, 0, 0, m_pImg->GetWidth(), m_pImg->GetHeight(), UnitPixel);
  593. }
  594. // Do not call MyFormView::OnPaint() for painting messages
  595. }
  596. void Worker::OnLButtonDown(UINT nFlags, CPoint point)
  597. {
  598. // TODO: Add your message handler code here and/or call default
  599. CRect rc;
  600. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  601. ScreenToClient(rc);
  602. if (rc.PtInRect(point) && m_pImg)
  603. {
  604. ShowPhoto dlg;
  605. dlg.m_pImg = m_pImg;
  606. dlg.DoModal();
  607. }
  608. MyFormView::OnLButtonDown(nFlags, point);
  609. }