Worker.cpp 17 KB

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