FixedAssets.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. // FixedAssets.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "FixedAssets.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. // FixedAssets
  15. IMPLEMENT_DYNCREATE(FixedAssets, MyFormView)
  16. FixedAssets::FixedAssets()
  17. : MyFormView(FixedAssets::IDD)
  18. {
  19. //{{AFX_DATA_INIT(FixedAssets)
  20. m_sex = _T("");
  21. m_pImg = NULL;
  22. m_id = _T("");
  23. m_name = _T("");
  24. m_count = _T("");
  25. m_type = _T("");
  26. m_date = g_date;
  27. m_remark = _T("");
  28. //}}AFX_DATA_INIT
  29. }
  30. FixedAssets::~FixedAssets()
  31. {
  32. if (m_pImg)delete m_pImg;
  33. }
  34. void FixedAssets::DoDataExchange(CDataExchange* pDX)
  35. {
  36. MyFormView::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(FixedAssets)
  38. DDX_Control(pDX, IDC_EDITdate, m_datectrl);
  39. DDX_Control(pDX, IDC_COMBOclerk, m_comboclerk);
  40. DDX_Control(pDX, IDC_LIST2, m_List1);
  41. DDX_Control(pDX, IDC_STATIC1, m_static1);
  42. DDX_Text(pDX, IDC_EDITid, m_id);
  43. DDX_Text(pDX, IDC_EDITname, m_name);
  44. DDX_Text(pDX, IDC_EDITcount, m_count);
  45. DDX_Text(pDX, IDC_EDITtype, m_type);
  46. DDX_Text(pDX, IDC_EDITdate, m_date);
  47. DDX_Text(pDX, IDC_EDITremark, m_remark);
  48. //}}AFX_DATA_MAP
  49. }
  50. BEGIN_MESSAGE_MAP(FixedAssets, MyFormView)
  51. //{{AFX_MSG_MAP(FixedAssets)
  52. ON_BN_CLICKED(IDC_BUTsave, OnBUTsave)
  53. ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
  54. ON_BN_CLICKED(IDC_BUTclose, OnBUTclose)
  55. ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2)
  56. ON_BN_CLICKED(IDC_BUTload, OnBUTload)
  57. ON_BN_CLICKED(IDC_BUTdel2, OnBUTdel2)
  58. ON_WM_PAINT()
  59. ON_WM_LBUTTONDOWN()
  60. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  61. //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63. /////////////////////////////////////////////////////////////////////////////
  64. // FixedAssets diagnostics
  65. #ifdef _DEBUG
  66. void FixedAssets::AssertValid() const
  67. {
  68. MyFormView::AssertValid();
  69. }
  70. void FixedAssets::Dump(CDumpContext& dc) const
  71. {
  72. MyFormView::Dump(dc);
  73. }
  74. #endif //_DEBUG
  75. /////////////////////////////////////////////////////////////////////////////
  76. // FixedAssets message handlers
  77. void FixedAssets::OnInitialUpdate()
  78. {
  79. MyFormView::OnInitialUpdate();
  80. // TODO: Add your specialized code here and/or call the base class
  81. CMyMdi Mdi;
  82. Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this);
  83. // Here we create the outbar control using the splitter as its parent
  84. // and setting its id to the first pane.
  85. CRect rc2;
  86. GetWindowRect(rc2);
  87. ::MoveWindow(m_hWnd, g_rc.left, g_rc.top, g_rc.Width(), g_rc.Height(), TRUE);
  88. EnumChildWindows(m_hWnd, (WNDENUMPROC)EnumChildProc, 0);
  89. m_static1.SetFont(&g_titlefont);
  90. m_List1.SetHeadings("编号, 60;名称, 60;数量, 60;规格, 60;保管员, 60;购买日期, 60;备注,60");
  91. m_List1.LoadColumnInfo(212);
  92. m_comboclerk.RefDroppedWidth();
  93. GetData();
  94. }
  95. void FixedAssets::FillGrid()
  96. {
  97. m_List1.DeleteAllItems2();
  98. int ii = 0;
  99. m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1);
  100. int count = 0;
  101. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  102. {
  103. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  104. }
  105. m_List1.m_arLabels.SetSize(count, 1);
  106. ii = count;
  107. m_List1.m_LabelCount = ii;
  108. m_List1.SetItemCountEx(ii);
  109. }
  110. void FixedAssets::OnBUTclose()
  111. {
  112. // TODO: Add your control notification handler code here
  113. GetParent()->SendMessage(WM_CLOSE);
  114. }
  115. void FixedAssets::ClearCtrl()
  116. {
  117. m_sex = _T("");
  118. m_id = _T("");
  119. m_name = _T("");
  120. m_count = _T("");
  121. m_type = _T("");
  122. m_date = g_date;
  123. m_remark = _T("");
  124. UpdateData(false);
  125. m_comboclerk.SetCurSel(-1);
  126. }
  127. void FixedAssets::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
  128. {
  129. // TODO: Add your control notification handler code here
  130. ListSelChange();
  131. *pResult = 0;
  132. }
  133. void FixedAssets::ListSelChange()//列表项改变,重新读相片;
  134. {
  135. POSITION pos;
  136. pos = m_List1.GetFirstSelectedItemPosition();
  137. if (pos == NULL)
  138. {
  139. OnButton1();
  140. return;
  141. }
  142. int iItem = m_List1.GetNextSelectedItem(pos);
  143. m_oldid = m_List1.GetItemText(iItem, 0);
  144. for (int ii = 0; ii < m_List1array.GetSize(); ii++)
  145. {
  146. if (m_List1array.ElementAt(ii).ElementAt(0) == m_oldid)
  147. {
  148. GetDlgItem(IDC_BUTload)->EnableWindow(1);
  149. GetDlgItem(IDC_BUTdel2)->EnableWindow(1);
  150. CString clerk;
  151. m_id = m_List1array.ElementAt(ii).ElementAt(0);
  152. m_name = m_List1array.ElementAt(ii).ElementAt(1);
  153. m_count = m_List1array.ElementAt(ii).ElementAt(2);
  154. m_type = m_List1array.ElementAt(ii).ElementAt(3);
  155. clerk = m_List1array.ElementAt(ii).ElementAt(4);
  156. m_date = m_List1array.ElementAt(ii).ElementAt(5);
  157. m_remark = m_List1array.ElementAt(ii).ElementAt(6);
  158. UpdateData(false);
  159. if (m_comboclerk.FindString(0, clerk) == -1)
  160. m_comboclerk.AddString(clerk);
  161. int pos = m_comboclerk.FindString(0, clerk);
  162. m_comboclerk.SetCurSel(pos);
  163. char no[100];
  164. memset(no, 0, 100);
  165. #ifdef VC60
  166. strcpy(no, m_id);
  167. #else
  168. _tcscpy_s(no, 100, m_id);
  169. #endif
  170. g_nSendCode = 29;
  171. g_pMainWnd->ProcessChatMessageRequest2((BYTE*)no, 100);
  172. g_nSendCode = 0;
  173. if (g_bSendOK == 0)
  174. {
  175. return;
  176. }
  177. if (m_pImg)delete m_pImg;
  178. m_pImg = NULL;
  179. ::LoadImageFromBuf(&m_pImg, g_pData, g_nLeng);
  180. if (m_pImg == NULL)
  181. {
  182. AfxMessageBox("无效图片文件!"); return;
  183. }
  184. CRect rc;
  185. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  186. ScreenToClient(rc);
  187. InvalidateRect(rc);
  188. return;
  189. }
  190. }
  191. }
  192. void FixedAssets::OnBUTsave()
  193. {
  194. // TODO: Add your control notification handler code here
  195. UpdateData();
  196. if (m_name.IsEmpty() || m_count.IsEmpty())
  197. {
  198. AfxMessageBox("资料不全!", MB_ICONINFORMATION); return;
  199. }
  200. CString sql;
  201. CString clerk;
  202. int pos = m_comboclerk.GetCurSel();
  203. if (pos != -1)
  204. m_comboclerk.GetLBText(pos, clerk);
  205. if (m_oldid.IsEmpty())//新增
  206. {
  207. if (IsExist())
  208. {
  209. AfxMessageBox("已有名称的物品,是否继续?", MB_ICONINFORMATION);
  210. return;
  211. }
  212. sql.Format("insert into fixedassets(name,count,type,clerk,date,remark)values('%s','%s','%s','%s','%s','%s')", m_name, m_count, m_type, clerk, m_date, m_remark);
  213. g_sendhead.bsql = 1;
  214. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  215. GetData();
  216. }
  217. else//修改
  218. {
  219. sql.Format("update fixedassets set name='%s',count='%s',type='%s',clerk='%s',date='%s',remark='%s' where id=%s ", m_name, m_count, m_type, clerk, m_date, m_remark, m_oldid);
  220. g_sendhead.bsql = 1;
  221. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  222. GetData();
  223. }
  224. }
  225. void FixedAssets::OnBUTdel()
  226. {
  227. // TODO: Add your control notification handler code here
  228. POSITION pos;
  229. pos = m_List1.GetFirstSelectedItemPosition();
  230. if (pos == NULL)
  231. {
  232. AfxMessageBox("请先选中您要删除的项目!", MB_ICONINFORMATION); return;
  233. return;
  234. }
  235. if (AfxMessageBox("确认删除吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  236. int iItem = m_List1.GetNextSelectedItem(pos);
  237. CString id = m_List1.GetItemText(iItem, 0);
  238. CString sql;
  239. sql.Format("delete from fixedassets where id=%s ", id);
  240. sql += RENYUAN_REF;
  241. g_sendhead.bsql = 1;
  242. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  243. GetData();
  244. }
  245. void FixedAssets::GetData()
  246. {
  247. g_sendhead.bsql = 0;
  248. g_sendhead.code[0] = 210;
  249. g_sendhead.tabcount = 1;
  250. int g_nYearposTemp = g_nYearpos;
  251. g_nYearpos = -1;
  252. g_pMainWnd->ProcessChatMessageRequest2(1);
  253. g_nYearpos = g_nYearposTemp;
  254. if (g_bSendOK == 0)return;
  255. DataToArray(&m_List1array);
  256. FillGrid();
  257. }
  258. BOOL FixedAssets::IsExist()
  259. {
  260. for (int i = 0; i < m_List1array.GetSize(); i++)
  261. {
  262. if (m_name == m_List1array.ElementAt(i).ElementAt(1))return 1;
  263. }
  264. return 0;
  265. }
  266. BOOL FixedAssets::PreTranslateMessage(MSG* pMsg)
  267. {
  268. // TODO: Add your specialized code here and/or call the base class
  269. try
  270. {
  271. if (pMsg->message == WM_KEYDOWN)
  272. {
  273. switch (pMsg->wParam)
  274. {
  275. case 0x43: // copy
  276. if ((GetKeyState(VK_CONTROL) & 0x80))
  277. {
  278. GetFocus()->SendMessage(WM_COPY);
  279. return TRUE;
  280. }
  281. break;
  282. case 0x56: //Ctrl + V:
  283. if ((GetKeyState(VK_CONTROL) & 0x80))
  284. {
  285. GetFocus()->SendMessage(WM_PASTE);
  286. return TRUE;
  287. }
  288. break;
  289. case 0x58: // cut
  290. if ((GetKeyState(VK_CONTROL) & 0x80))
  291. {
  292. GetFocus()->SendMessage(WM_CUT);
  293. return TRUE;
  294. }
  295. break;
  296. case 0x5A: //undo
  297. case 0x59: //redo
  298. if ((GetKeyState(VK_CONTROL) & 0x80))
  299. {
  300. GetFocus()->SendMessage(WM_UNDO);
  301. return TRUE;
  302. }
  303. break;
  304. }
  305. }
  306. return MyFormView::PreTranslateMessage(pMsg);
  307. }
  308. catch (...)
  309. {
  310. }
  311. return true;
  312. }
  313. void FixedAssets::OnBUTload() //上传照片;
  314. {
  315. // TODO: Add your control notification handler code here
  316. UpdateData();
  317. CFileDialog fdlg(true, NULL, "", OFN_HIDEREADONLY, "jpg files(*jpg)|*.jpg||");
  318. if (fdlg.DoModal() != IDOK)return;
  319. CString path = fdlg.GetPathName();
  320. CFile fp;
  321. if (!fp.Open(path, CFile::modeRead))
  322. {
  323. AfxMessageBox("文件打开失败!");
  324. return;
  325. }
  326. DWORD length = fp.GetLength();
  327. if (length > 1024 * 95)
  328. {
  329. AfxMessageBox("文件太大,请上传小于95K的图片!"); fp.Close();
  330. return;
  331. }
  332. BYTE *m_pData = new BYTE[length + 100];
  333. fp.Read(m_pData, length);
  334. fp.Close();
  335. char no[100];
  336. memset(no, 0, 100);
  337. strcpy(no, m_oldid);
  338. memcpy(m_pData + length, no, 100);
  339. if (m_pImg)delete m_pImg; m_pImg = NULL;
  340. ::LoadImageFromBuf(&m_pImg, path);
  341. if (m_pImg == NULL)
  342. {
  343. AfxMessageBox("无效图片文件!"); return;
  344. }
  345. g_nSendCode = 28;
  346. g_pMainWnd->ProcessChatMessageRequest2(m_pData, length + 100);
  347. g_nSendCode = 0;
  348. delete[]m_pData;
  349. if (g_bSendOK == 0)
  350. {
  351. if (m_pImg)delete m_pImg; m_pImg = NULL;
  352. return;
  353. }
  354. AfxMessageBox("上传成功!");
  355. CRect rc;
  356. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  357. ScreenToClient(rc);
  358. InvalidateRect(rc);
  359. }
  360. void FixedAssets::OnBUTdel2() //删除相片;
  361. {
  362. // TODO: Add your control notification handler code here
  363. if (AfxMessageBox("确认删除吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  364. UpdateData();
  365. char no[100];
  366. memset(no, 0, 100);
  367. strcpy(no, m_oldid);
  368. g_nSendCode = 28;
  369. g_pMainWnd->ProcessChatMessageRequest2((BYTE*)no, 100);
  370. g_nSendCode = 0;
  371. if (g_bSendOK == 0)
  372. {
  373. return;
  374. }
  375. if (m_pImg)delete m_pImg; m_pImg = NULL;
  376. CRect rc;
  377. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  378. ScreenToClient(rc);
  379. InvalidateRect(rc);
  380. }
  381. void FixedAssets::OnPaint()
  382. {
  383. CPaintDC dc(this); // device context for painting
  384. // TODO: Add your message handler code here
  385. if (m_pImg)
  386. {
  387. CRect rc;
  388. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  389. ScreenToClient(rc);
  390. RectFitDes(m_pImg->GetWidth(), m_pImg->GetHeight(), rc);
  391. Graphics dcgraph(dc.GetSafeHdc());
  392. Rect destinationRect(rc.left, rc.top, rc.Width(), rc.Height());
  393. dcgraph.DrawImage(m_pImg, destinationRect, 0, 0, m_pImg->GetWidth(), m_pImg->GetHeight(), UnitPixel);
  394. }
  395. // Do not call MyFormView::OnPaint() for painting messages
  396. }
  397. void FixedAssets::OnLButtonDown(UINT nFlags, CPoint point)
  398. {
  399. // TODO: Add your message handler code here and/or call default
  400. CRect rc;
  401. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  402. ScreenToClient(rc);
  403. if (rc.PtInRect(point) && m_pImg)
  404. {
  405. ShowPhoto dlg;
  406. dlg.m_pImg = m_pImg;
  407. dlg.DoModal();
  408. }
  409. MyFormView::OnLButtonDown(nFlags, point);
  410. }
  411. void FixedAssets::OnButton1()
  412. {
  413. // TODO: Add your control notification handler code here
  414. m_oldid.Empty();
  415. ClearCtrl();
  416. GetDlgItem(IDC_BUTload)->EnableWindow(0);
  417. GetDlgItem(IDC_BUTdel2)->EnableWindow(0);
  418. }