FixedAssets.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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. strcpy(no, m_id);
  166. g_nSendCode = 29;
  167. g_pMainWnd->ProcessChatMessageRequest2((BYTE*)no, 100);
  168. g_nSendCode = 0;
  169. if (g_bSendOK == 0)
  170. {
  171. return;
  172. }
  173. if (m_pImg)delete m_pImg;
  174. m_pImg = NULL;
  175. ::LoadImageFromBuf(&m_pImg, g_pData, g_nLeng);
  176. if (m_pImg == NULL)
  177. {
  178. AfxMessageBox("无效图片文件!"); return;
  179. }
  180. CRect rc;
  181. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  182. ScreenToClient(rc);
  183. InvalidateRect(rc);
  184. return;
  185. }
  186. }
  187. }
  188. void FixedAssets::OnBUTsave()
  189. {
  190. // TODO: Add your control notification handler code here
  191. UpdateData();
  192. if (m_name.IsEmpty() || m_count.IsEmpty())
  193. {
  194. AfxMessageBox("资料不全!", MB_ICONINFORMATION); return;
  195. }
  196. CString sql;
  197. CString clerk;
  198. int pos = m_comboclerk.GetCurSel();
  199. if (pos != -1)
  200. m_comboclerk.GetLBText(pos, clerk);
  201. if (m_oldid.IsEmpty())//新增
  202. {
  203. if (IsExist())
  204. {
  205. AfxMessageBox("已有名称的物品,是否继续?", MB_ICONINFORMATION);
  206. return;
  207. }
  208. 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);
  209. g_sendhead.bsql = 1;
  210. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  211. GetData();
  212. }
  213. else//修改
  214. {
  215. 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);
  216. g_sendhead.bsql = 1;
  217. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  218. GetData();
  219. }
  220. }
  221. void FixedAssets::OnBUTdel()
  222. {
  223. // TODO: Add your control notification handler code here
  224. POSITION pos;
  225. pos = m_List1.GetFirstSelectedItemPosition();
  226. if (pos == NULL)
  227. {
  228. AfxMessageBox("请先选中您要删除的项目!", MB_ICONINFORMATION); return;
  229. return;
  230. }
  231. if (AfxMessageBox("确认删除吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  232. int iItem = m_List1.GetNextSelectedItem(pos);
  233. CString id = m_List1.GetItemText(iItem, 0);
  234. CString sql;
  235. sql.Format("delete from fixedassets where id=%s ", id);
  236. sql += RENYUAN_REF;
  237. g_sendhead.bsql = 1;
  238. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  239. GetData();
  240. }
  241. void FixedAssets::GetData()
  242. {
  243. g_sendhead.bsql = 0;
  244. g_sendhead.code[0] = 210;
  245. g_sendhead.tabcount = 1;
  246. int g_nYearposTemp = g_nYearpos;
  247. g_nYearpos = -1;
  248. g_pMainWnd->ProcessChatMessageRequest2(1);
  249. g_nYearpos = g_nYearposTemp;
  250. if (g_bSendOK == 0)return;
  251. DataToArray(&m_List1array);
  252. FillGrid();
  253. }
  254. BOOL FixedAssets::IsExist()
  255. {
  256. for (int i = 0; i < m_List1array.GetSize(); i++)
  257. {
  258. if (m_name == m_List1array.ElementAt(i).ElementAt(1))return 1;
  259. }
  260. return 0;
  261. }
  262. BOOL FixedAssets::PreTranslateMessage(MSG* pMsg)
  263. {
  264. // TODO: Add your specialized code here and/or call the base class
  265. try
  266. {
  267. if (pMsg->message == WM_KEYDOWN)
  268. {
  269. switch (pMsg->wParam)
  270. {
  271. case 0x43: // copy
  272. if ((GetKeyState(VK_CONTROL) & 0x80))
  273. {
  274. GetFocus()->SendMessage(WM_COPY);
  275. return TRUE;
  276. }
  277. break;
  278. case 0x56: //Ctrl + V:
  279. if ((GetKeyState(VK_CONTROL) & 0x80))
  280. {
  281. GetFocus()->SendMessage(WM_PASTE);
  282. return TRUE;
  283. }
  284. break;
  285. case 0x58: // cut
  286. if ((GetKeyState(VK_CONTROL) & 0x80))
  287. {
  288. GetFocus()->SendMessage(WM_CUT);
  289. return TRUE;
  290. }
  291. break;
  292. case 0x5A: //undo
  293. case 0x59: //redo
  294. if ((GetKeyState(VK_CONTROL) & 0x80))
  295. {
  296. GetFocus()->SendMessage(WM_UNDO);
  297. return TRUE;
  298. }
  299. break;
  300. }
  301. }
  302. return MyFormView::PreTranslateMessage(pMsg);
  303. }
  304. catch (...)
  305. {
  306. }
  307. }
  308. void FixedAssets::OnBUTload() //上传照片;
  309. {
  310. // TODO: Add your control notification handler code here
  311. UpdateData();
  312. CFileDialog fdlg(true, NULL, "", OFN_HIDEREADONLY, "jpg files(*jpg)|*.jpg||");
  313. if (fdlg.DoModal() != IDOK)return;
  314. CString path = fdlg.GetPathName();
  315. CFile fp;
  316. if (!fp.Open(path, CFile::modeRead))
  317. {
  318. AfxMessageBox("文件打开失败!");
  319. return;
  320. }
  321. DWORD length = fp.GetLength();
  322. if (length > 1024 * 95)
  323. {
  324. AfxMessageBox("文件太大,请上传小于95K的图片!"); fp.Close();
  325. return;
  326. }
  327. BYTE *m_pData = new BYTE[length + 100];
  328. fp.Read(m_pData, length);
  329. fp.Close();
  330. char no[100];
  331. memset(no, 0, 100);
  332. strcpy(no, m_oldid);
  333. memcpy(m_pData + length, no, 100);
  334. if (m_pImg)delete m_pImg; m_pImg = NULL;
  335. ::LoadImageFromBuf(&m_pImg, path);
  336. if (m_pImg == NULL)
  337. {
  338. AfxMessageBox("无效图片文件!"); return;
  339. }
  340. g_nSendCode = 28;
  341. g_pMainWnd->ProcessChatMessageRequest2(m_pData, length + 100);
  342. g_nSendCode = 0;
  343. delete[]m_pData;
  344. if (g_bSendOK == 0)
  345. {
  346. if (m_pImg)delete m_pImg; m_pImg = NULL;
  347. return;
  348. }
  349. AfxMessageBox("上传成功!");
  350. CRect rc;
  351. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  352. ScreenToClient(rc);
  353. InvalidateRect(rc);
  354. }
  355. void FixedAssets::OnBUTdel2() //删除相片;
  356. {
  357. // TODO: Add your control notification handler code here
  358. if (AfxMessageBox("确认删除吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  359. UpdateData();
  360. char no[100];
  361. memset(no, 0, 100);
  362. strcpy(no, m_oldid);
  363. g_nSendCode = 28;
  364. g_pMainWnd->ProcessChatMessageRequest2((BYTE*)no, 100);
  365. g_nSendCode = 0;
  366. if (g_bSendOK == 0)
  367. {
  368. return;
  369. }
  370. if (m_pImg)delete m_pImg; m_pImg = NULL;
  371. CRect rc;
  372. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  373. ScreenToClient(rc);
  374. InvalidateRect(rc);
  375. }
  376. void FixedAssets::OnPaint()
  377. {
  378. CPaintDC dc(this); // device context for painting
  379. // TODO: Add your message handler code here
  380. if (m_pImg)
  381. {
  382. CRect rc;
  383. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  384. ScreenToClient(rc);
  385. RectFitDes(m_pImg->GetWidth(), m_pImg->GetHeight(), rc);
  386. Graphics dcgraph(dc.GetSafeHdc());
  387. Rect destinationRect(rc.left, rc.top, rc.Width(), rc.Height());
  388. dcgraph.DrawImage(m_pImg, destinationRect, 0, 0, m_pImg->GetWidth(), m_pImg->GetHeight(), UnitPixel);
  389. }
  390. // Do not call MyFormView::OnPaint() for painting messages
  391. }
  392. void FixedAssets::OnLButtonDown(UINT nFlags, CPoint point)
  393. {
  394. // TODO: Add your message handler code here and/or call default
  395. CRect rc;
  396. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  397. ScreenToClient(rc);
  398. if (rc.PtInRect(point) && m_pImg)
  399. {
  400. ShowPhoto dlg;
  401. dlg.m_pImg = m_pImg;
  402. dlg.DoModal();
  403. }
  404. MyFormView::OnLButtonDown(nFlags, point);
  405. }
  406. void FixedAssets::OnButton1()
  407. {
  408. // TODO: Add your control notification handler code here
  409. m_oldid.Empty();
  410. ClearCtrl();
  411. GetDlgItem(IDC_BUTload)->EnableWindow(0);
  412. GetDlgItem(IDC_BUTdel2)->EnableWindow(0);
  413. }