Worker.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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. #ifdef VC60
  166. GetParent()->SendMessage(WM_CLOSE);
  167. #else
  168. GetParent()->PostMessage(WM_CLOSE);
  169. #endif
  170. }
  171. void Worker::ClearCtrl()
  172. {
  173. m_bz = _T("");
  174. m_sex = _T("");
  175. m_id = _T("");
  176. m_phone = _T("");
  177. m_address = _T("");
  178. m_name = _T("");
  179. m_address2 = _T("");
  180. m_idno = _T("");
  181. m_loginno1 = _T("");
  182. m_loginno2 = _T("");
  183. m_combolevel.SetCurSel(0);
  184. UpdateData(false);
  185. if (m_pImg)delete m_pImg; m_pImg = NULL;
  186. CRect rc;
  187. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  188. ScreenToClient(rc);
  189. InvalidateRect(rc);
  190. }
  191. void Worker::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
  192. {
  193. // TODO: Add your control notification handler code here
  194. ListSelChange();
  195. *pResult = 0;
  196. }
  197. void Worker::ListSelChange()
  198. {
  199. POSITION pos;
  200. pos = m_List1.GetFirstSelectedItemPosition();
  201. if (pos == NULL)
  202. {
  203. OnBUTadd();
  204. return;
  205. }
  206. int iItem = m_List1.GetNextSelectedItem(pos);
  207. m_oldid = m_List1.GetItemText(iItem, 0);
  208. m_oldname = m_List1.GetItemText(iItem, 1);
  209. CString level;
  210. for (int ii = 0; ii < m_List1arrayBak.GetSize(); ii++)
  211. {
  212. if (m_List1arrayBak.ElementAt(ii).ElementAt(0) == m_oldid)
  213. {
  214. GetDlgItem(IDC_BUTload)->EnableWindow(1);
  215. GetDlgItem(IDC_BUTdel2)->EnableWindow(1);
  216. CString bm, marry, dimission;
  217. m_id = m_List1arrayBak.ElementAt(ii).ElementAt(0);
  218. m_name = m_List1arrayBak.ElementAt(ii).ElementAt(1);
  219. bm = m_List1arrayBak.ElementAt(ii).ElementAt(2);
  220. m_sex = m_List1arrayBak.ElementAt(ii).ElementAt(3);
  221. m_phone = m_List1arrayBak.ElementAt(ii).ElementAt(4);
  222. m_address = m_List1arrayBak.ElementAt(ii).ElementAt(5);
  223. m_bz = m_List1arrayBak.ElementAt(ii).ElementAt(6);
  224. m_address2 = m_List1arrayBak.ElementAt(ii).ElementAt(7);
  225. m_idno = m_List1arrayBak.ElementAt(ii).ElementAt(8);
  226. marry = m_List1arrayBak.ElementAt(ii).ElementAt(9);
  227. dimission = m_List1arrayBak.ElementAt(ii).ElementAt(10);
  228. m_loginno1 = m_List1arrayBak.ElementAt(ii).ElementAt(11);
  229. m_loginno2 = m_List1arrayBak.ElementAt(ii).ElementAt(12);
  230. level = m_List1arrayBak.ElementAt(ii).ElementAt(13);
  231. UpdateData(false);
  232. int pos = m_combobm.FindString(0, bm);
  233. m_combobm.SetCurSel(pos);
  234. pos = m_combosex.FindString(0, m_sex);
  235. m_combosex.SetCurSel(pos);
  236. pos = m_combomarry.FindString(0, marry);
  237. m_combomarry.SetCurSel(pos);
  238. pos = m_combodimission.FindString(0, dimission);
  239. m_combodimission.SetCurSel(pos);
  240. pos = m_combolevel.FindString(0, level);
  241. m_combolevel.SetCurSel(pos);
  242. char no[100];
  243. memset(no, 0, 100);
  244. #ifdef VC60
  245. strcpy(no, m_id);
  246. #else
  247. strcpy_s(no, 100, m_id);
  248. #endif
  249. g_nSendCode = 27;
  250. g_pMainWnd->ProcessChatMessageRequest2((BYTE*)no, 100);
  251. g_nSendCode = 0;
  252. if (g_bSendOK == 0)
  253. {
  254. return;
  255. }
  256. // g_pData, g_nLeng
  257. if (m_pImg)delete m_pImg; m_pImg = NULL;
  258. ::LoadImageFromBuf(&m_pImg, g_pData, g_nLeng);
  259. if (m_pImg == NULL)
  260. {
  261. AfxMessageBox("无效图片文件!"); return;
  262. }
  263. CRect rc;
  264. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  265. ScreenToClient(rc);
  266. InvalidateRect(rc);
  267. return;
  268. }
  269. }
  270. }
  271. void Worker::OnBUTadd()
  272. {
  273. // TODO: Add your control notification handler code here
  274. m_oldid.Empty();
  275. m_oldname.Empty();
  276. ClearCtrl(); OnBUTAutoGet();
  277. GetDlgItem(IDC_BUTload)->EnableWindow(0);
  278. GetDlgItem(IDC_BUTdel2)->EnableWindow(0);
  279. }
  280. void Worker::OnBUTsave() // Jeff:保存按钮;
  281. {
  282. // TODO: Add your control notification handler code here
  283. UpdateData();
  284. if (m_id.IsEmpty() || m_name.IsEmpty() || m_phone.IsEmpty() || m_address.IsEmpty() || m_address2.IsEmpty() || m_idno.IsEmpty())
  285. {
  286. AfxMessageBox("资料不全!", MB_ICONINFORMATION);
  287. return;
  288. }
  289. m_loginno1.TrimLeft();
  290. m_loginno1.TrimRight();
  291. m_loginno1.TrimLeft("0");
  292. m_loginno2.TrimLeft();
  293. m_loginno2.TrimRight();
  294. m_loginno2.TrimLeft("0");
  295. CString sql;
  296. CString bm, dimission, marry, level;
  297. int pos = m_combobm.GetCurSel();
  298. if (pos == -1)
  299. {
  300. AfxMessageBox("资料不全!", MB_ICONINFORMATION); return;
  301. }
  302. m_combobm.GetLBText(pos, bm);
  303. pos = m_combosex.GetCurSel();
  304. if (pos == -1)
  305. {
  306. AfxMessageBox("资料不全!", MB_ICONINFORMATION); return;
  307. }
  308. m_combosex.GetLBText(pos, m_sex);
  309. pos = m_combomarry.GetCurSel();
  310. if (pos == -1)
  311. {
  312. AfxMessageBox("资料不全!", MB_ICONINFORMATION); return;
  313. }
  314. m_combomarry.GetLBText(pos, marry);
  315. pos = m_combodimission.GetCurSel();
  316. if (pos == -1)
  317. {
  318. AfxMessageBox("资料不全!", MB_ICONINFORMATION); return;
  319. }
  320. m_combodimission.GetLBText(pos, dimission);
  321. #if 0 // Jeff Modify
  322. pos=m_combolevel.GetCurSel();
  323. if(pos==-1)
  324. {
  325. AfxMessageBox("资料不全!", MB_ICONINFORMATION);return;
  326. }
  327. m_combolevel.GetLBText(pos, level);
  328. #else
  329. level = "1";
  330. #endif
  331. if (m_oldid.IsEmpty())//新增
  332. {
  333. if (IsExist())
  334. {
  335. AfxMessageBox("已有此编号或姓名或指纹的员工,请重新输入!", MB_ICONINFORMATION);
  336. return;
  337. }
  338. 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);
  339. g_sendhead.bsql = 1;
  340. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  341. GetData();
  342. }
  343. else//修改
  344. {
  345. if (m_oldid != m_id)
  346. {
  347. if (IsExistID())
  348. {
  349. AfxMessageBox("已有此编号的员工,请重新输入!", MB_ICONINFORMATION);
  350. return;
  351. }
  352. }
  353. if (m_oldname != m_name)
  354. {
  355. if (IsExistName())
  356. {
  357. AfxMessageBox("已有此姓名的员工,请重新输入!", MB_ICONINFORMATION);
  358. return;
  359. }
  360. }
  361. 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);
  362. if (m_oldname != m_name)
  363. {
  364. sql += "***update [user] set [name]='" + m_name + "' where [name]='" + m_oldname + "'";
  365. }
  366. g_sendhead.bsql = 1;
  367. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  368. GetData();
  369. }
  370. }
  371. void Worker::OnBUTdel()
  372. {
  373. // TODO: Add your control notification handler code here
  374. POSITION pos;
  375. pos = m_List1.GetFirstSelectedItemPosition();
  376. if (pos == NULL)
  377. {
  378. return;
  379. }
  380. if (AfxMessageBox("确认删除吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  381. int iItem = m_List1.GetNextSelectedItem(pos);
  382. CString id = m_List1.GetItemText(iItem, 0);
  383. CString sql;
  384. sql.Format("delete from renyuan where id='%s' ", id);
  385. sql += RENYUAN_REF;
  386. g_sendhead.bsql = 1;
  387. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  388. GetData();
  389. }
  390. void Worker::GetData()
  391. {
  392. g_sendhead.bsql = 0;
  393. g_sendhead.code[0] = 5;
  394. g_sendhead.tabcount = 1;
  395. int g_nYearposTemp = g_nYearpos;
  396. g_nYearpos = -1;
  397. g_pMainWnd->ProcessChatMessageRequest2(1);
  398. g_nYearpos = g_nYearposTemp;
  399. if (g_bSendOK == 0)return;
  400. DataToArray(&m_List1array);
  401. m_List1arrayBak.SetSize(m_List1array.GetSize());
  402. for (int i = 0; i < m_List1array.GetSize(); i++)
  403. {
  404. m_List1arrayBak.ElementAt(i).Copy(m_List1array.ElementAt(i));
  405. m_List1array.ElementAt(i).RemoveAt(6, 5);
  406. }
  407. FillGrid();
  408. g_userarray.SetSize(m_List1arrayBak.GetSize(), 1);
  409. int count = 0;
  410. for (int ii = 0; ii < m_List1arrayBak.GetSize(); ii++)
  411. {
  412. if (m_List1arrayBak.ElementAt(ii).ElementAt(10) == "在职")
  413. g_userarray.ElementAt(count++).Copy(m_List1arrayBak.ElementAt(ii));
  414. }
  415. g_userarray.SetSize(count, 1);
  416. }
  417. BOOL Worker::IsExist()
  418. {
  419. CString str1, str2;
  420. for (int i = 0; i < m_List1arrayBak.GetSize(); i++)
  421. {
  422. if (m_id == m_List1arrayBak.ElementAt(i).ElementAt(0))return 1;
  423. if (m_name == m_List1arrayBak.ElementAt(i).ElementAt(1))return 1;
  424. str1 = m_loginno1;
  425. str2 = m_List1arrayBak.ElementAt(i).ElementAt(11);
  426. str1.TrimLeft("0");
  427. str2.TrimLeft("0");
  428. if (str1 == str2 && str1 != "")return 1;
  429. str1 = m_loginno2;
  430. str2 = m_List1arrayBak.ElementAt(i).ElementAt(12);
  431. str1.TrimLeft("0");
  432. str2.TrimLeft("0");
  433. if (str1 == str2 && str1 != "")return 1;
  434. }
  435. return 0;
  436. }
  437. BOOL Worker::IsExistID()
  438. {
  439. for (int i = 0; i < m_List1arrayBak.GetSize(); i++)
  440. {
  441. if (m_id == m_List1arrayBak.ElementAt(i).ElementAt(0))return 1;
  442. }
  443. return 0;
  444. }
  445. BOOL Worker::IsExistName()
  446. {
  447. for (int i = 0; i < m_List1arrayBak.GetSize(); i++)
  448. {
  449. if (m_name == m_List1arrayBak.ElementAt(i).ElementAt(1))return 1;
  450. }
  451. return 0;
  452. }
  453. BOOL Worker::PreTranslateMessage(MSG* pMsg)
  454. {
  455. // TODO: Add your specialized code here and/or call the base class
  456. try
  457. {
  458. if (pMsg->message == WM_KEYDOWN)
  459. {
  460. switch (pMsg->wParam)
  461. {
  462. case 0x43: // copy
  463. if ((GetKeyState(VK_CONTROL) & 0x80))
  464. {
  465. GetFocus()->SendMessage(WM_COPY);
  466. return TRUE;
  467. }
  468. break;
  469. case 0x56: //Ctrl + V:
  470. if ((GetKeyState(VK_CONTROL) & 0x80))
  471. {
  472. GetFocus()->SendMessage(WM_PASTE);
  473. return TRUE;
  474. }
  475. break;
  476. case 0x58: // cut
  477. if ((GetKeyState(VK_CONTROL) & 0x80))
  478. {
  479. GetFocus()->SendMessage(WM_CUT);
  480. return TRUE;
  481. }
  482. break;
  483. case 0x5A: //undo
  484. case 0x59: //redo
  485. if ((GetKeyState(VK_CONTROL) & 0x80))
  486. {
  487. GetFocus()->SendMessage(WM_UNDO);
  488. return TRUE;
  489. }
  490. break;
  491. }
  492. }
  493. return MyFormView::PreTranslateMessage(pMsg);
  494. }
  495. catch (...)
  496. {
  497. }
  498. return TRUE;
  499. }
  500. void Worker::OnBUTAutoGet()
  501. {
  502. // TODO: Add your control notification handler code here
  503. UpdateData();
  504. int begin = 1;
  505. BOOL bFind = 1;
  506. while (bFind)
  507. {
  508. m_id.Format("%03d", begin++);
  509. int i = 0;
  510. for ( i = 0; i < m_List1arrayBak.GetSize(); i++)
  511. {
  512. if (m_id == m_List1arrayBak.ElementAt(i).ElementAt(0))
  513. {
  514. break;
  515. }
  516. }
  517. if (i == m_List1arrayBak.GetSize())bFind = 0;
  518. }
  519. UpdateData(false);
  520. }
  521. void Worker::OnBUTload()
  522. {
  523. // TODO: Add your control notification handler code here
  524. UpdateData();
  525. CFileDialog fdlg(true, NULL, "", OFN_HIDEREADONLY, "jpg files(*jpg)|*.jpg||");
  526. if (fdlg.DoModal() != IDOK)return;
  527. CString path = fdlg.GetPathName();
  528. CFile fp;
  529. if (!fp.Open(path, CFile::modeRead))
  530. {
  531. AfxMessageBox("文件打开失败!");
  532. return;
  533. }
  534. DWORD length = fp.GetLength();
  535. if (length > 1024 * 200)
  536. {
  537. AfxMessageBox("文件太大,请上传小于200K的图片!");
  538. fp.Close();
  539. return;
  540. }
  541. BYTE *m_pData = new BYTE[length + 100];
  542. fp.Read(m_pData, length);
  543. fp.Close();
  544. char no[100];
  545. memset(no, 0, 100);
  546. #ifdef VC60
  547. strcpy(no, m_id);
  548. #else
  549. strcpy_s(no, 100, m_id);
  550. #endif
  551. memcpy(m_pData + length, no, 100);
  552. if (m_pImg)delete m_pImg; m_pImg = NULL;
  553. ::LoadImageFromBuf(&m_pImg, path);
  554. if (m_pImg == NULL)
  555. {
  556. AfxMessageBox("无效图片文件!"); return;
  557. }
  558. g_nSendCode = 26;
  559. g_pMainWnd->ProcessChatMessageRequest2(m_pData, length + 100);
  560. g_nSendCode = 0;
  561. delete[]m_pData;
  562. if (g_bSendOK == 0)
  563. {
  564. if (m_pImg)delete m_pImg; m_pImg = NULL;
  565. return;
  566. }
  567. AfxMessageBox("上传成功!");
  568. CRect rc;
  569. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  570. ScreenToClient(rc);
  571. InvalidateRect(rc);
  572. }
  573. void Worker::OnBUTdel2()
  574. {
  575. // TODO: Add your control notification handler code here
  576. if (AfxMessageBox("确认删除吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  577. UpdateData();
  578. char no[100];
  579. memset(no, 0, 100);
  580. #ifdef VC60
  581. strcpy(no, m_id);
  582. #else
  583. strcpy_s(no, 100, m_id);
  584. #endif
  585. g_nSendCode = 26;
  586. g_pMainWnd->ProcessChatMessageRequest2((BYTE*)no, 100);
  587. g_nSendCode = 0;
  588. if (g_bSendOK == 0)
  589. {
  590. return;
  591. }
  592. if (m_pImg)delete m_pImg; m_pImg = NULL;
  593. CRect rc;
  594. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  595. ScreenToClient(rc);
  596. InvalidateRect(rc);
  597. }
  598. void Worker::OnPaint()
  599. {
  600. CPaintDC dc(this); // device context for painting
  601. // TODO: Add your message handler code here
  602. if (m_pImg)
  603. {
  604. CRect rc;
  605. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  606. ScreenToClient(rc);
  607. RectFitDes(m_pImg->GetWidth(), m_pImg->GetHeight(), rc);
  608. Graphics dcgraph(dc.GetSafeHdc());
  609. Rect destinationRect(rc.left, rc.top, rc.Width(), rc.Height());
  610. dcgraph.DrawImage(m_pImg, destinationRect, 0, 0, m_pImg->GetWidth(), m_pImg->GetHeight(), UnitPixel);
  611. }
  612. // Do not call MyFormView::OnPaint() for painting messages
  613. }
  614. void Worker::OnLButtonDown(UINT nFlags, CPoint point)
  615. {
  616. // TODO: Add your message handler code here and/or call default
  617. CRect rc;
  618. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  619. ScreenToClient(rc);
  620. if (rc.PtInRect(point) && m_pImg)
  621. {
  622. ShowPhoto dlg;
  623. dlg.m_pImg = m_pImg;
  624. dlg.DoModal();
  625. }
  626. MyFormView::OnLButtonDown(nFlags, point);
  627. }