ShowGoods.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. // ShowGoods.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "ShowGoods.h"
  6. #include "MyMdi.H"
  7. #include "InputName.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // ShowGoods
  15. IMPLEMENT_DYNCREATE(ShowGoods, MyFormView)
  16. ShowGoods::ShowGoods()
  17. : MyFormView(ShowGoods::IDD)
  18. {
  19. //{{AFX_DATA_INIT(ShowGoods)
  20. m_filter = _T("");
  21. m_radio1 = 0;
  22. //}}AFX_DATA_INIT
  23. }
  24. ShowGoods::~ShowGoods()
  25. {
  26. }
  27. void ShowGoods::DoDataExchange(CDataExchange* pDX)
  28. {
  29. MyFormView::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(ShowGoods)
  31. DDX_Control(pDX, IDC_LIST4, m_List2);
  32. DDX_Control(pDX, IDC_COMBO1, m_combo1);
  33. DDX_Control(pDX, IDC_LIST2, m_List1);
  34. DDX_Control(pDX, IDC_STATIC1, m_static1);
  35. DDX_CBString(pDX, IDC_COMBO1, m_filter);
  36. DDX_Radio(pDX, IDC_RADIO1, m_radio1);
  37. //}}AFX_DATA_MAP
  38. }
  39. BEGIN_MESSAGE_MAP(ShowGoods, MyFormView)
  40. //{{AFX_MSG_MAP(ShowGoods)
  41. ON_BN_CLICKED(IDC_BUTclose, OnBUTclose)
  42. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  43. ON_WM_TIMER()
  44. ON_NOTIFY(NM_DBLCLK, IDC_LIST2, OnDblclkList2)
  45. ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
  46. ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
  47. ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
  48. ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
  49. ON_BN_CLICKED(IDC_BUTdel6, OnBUTdel6)
  50. ON_BN_CLICKED(IDC_BUTdel2, OnBUTdel2)
  51. //}}AFX_MSG_MAP
  52. ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST2, OnCustomdrawList)
  53. END_MESSAGE_MAP()
  54. /////////////////////////////////////////////////////////////////////////////
  55. // ShowGoods diagnostics
  56. #ifdef _DEBUG
  57. void ShowGoods::AssertValid() const
  58. {
  59. MyFormView::AssertValid();
  60. }
  61. void ShowGoods::Dump(CDumpContext& dc) const
  62. {
  63. MyFormView::Dump(dc);
  64. }
  65. #endif //_DEBUG
  66. /////////////////////////////////////////////////////////////////////////////
  67. // ShowGoods message handlers
  68. void ShowGoods::OnInitialUpdate()
  69. {
  70. MyFormView::OnInitialUpdate();
  71. GetDlgItem(IDC_BUTdel)->EnableWindow(IsHasRights2new(49));
  72. GetDlgItem(IDC_BUTdel6)->EnableWindow(IsHasRights2new(49));
  73. // TODO: Add your specialized code here and/or call the base class
  74. CMyMdi Mdi;
  75. Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this);
  76. // Here we create the outbar control using the splitter as its parent
  77. // and setting its id to the first pane.
  78. CRect rc2;
  79. GetWindowRect(rc2);
  80. ::MoveWindow(m_hWnd, g_rc.left, g_rc.top, g_rc.Width(), g_rc.Height(), TRUE);
  81. EnumChildWindows(m_hWnd, (WNDENUMPROC)EnumChildProc, 0);
  82. m_static1.SetFont(&g_titlefont);
  83. m_List1.SetHeadings("商品类别,200;商品名称,200;库存,100");
  84. m_List1.LoadColumnInfo(135);
  85. m_List2.SetHeadings("单号,120;商品类别,100;商品名称,120;数量,60;日期,100;经手人,80;类别,60;备注,150");
  86. m_List2.LoadColumnInfo(136);
  87. GetDlgItem(IDC_LIST2)->ShowWindow(SW_SHOW);
  88. GetDlgItem(IDC_LIST4)->ShowWindow(SW_HIDE);
  89. g_sendhead.bsql = 0;
  90. g_sendhead.code[0] = 76;
  91. g_sendhead.tabcount = 1;
  92. g_pMainWnd->ProcessChatMessageRequest2(1); if (g_bSendOK == 0)return;
  93. DataToArray(&g_List1array);
  94. int i = 0;
  95. int size1 = 0;
  96. int size2 = 0;
  97. for ( i = 0; i < g_List1array.GetSize(); i++)
  98. {
  99. if (g_List1array.ElementAt(i).GetSize() == 8)
  100. {// 元素大小 = 8, 表示的是出入库记录;
  101. size2++;
  102. m_List2array.SetSize(size2, 1);
  103. size2--;
  104. m_List2array.ElementAt(size2).Copy(g_List1array.ElementAt(i));
  105. size2++;
  106. }
  107. else if (g_List1array.ElementAt(i).GetSize() == 3)
  108. {// 元素大小 = 3; 表示库存的计算结果;
  109. size1++;
  110. m_List1array.SetSize(size1, 1);
  111. size1--;
  112. m_List1array.ElementAt(size1).Copy(g_List1array.ElementAt(i));
  113. size1++;
  114. }
  115. }
  116. FillGrid();
  117. m_combo1.GetWindowRect(rc2);
  118. ScreenToClient(rc2);
  119. rc2.bottom += 200;
  120. m_combo1.MoveWindow(rc2);
  121. GetDlgItem(IDC_BUTclose)->GetWindowRect(rc2);
  122. SetComboHei(&m_combo1, rc2.Height());
  123. for (i = 0; i < m_List1array.GetSize(); i++)
  124. {
  125. if (m_combo1.FindString(0, m_List1array.ElementAt(i).ElementAt(0)) == -1)
  126. m_combo1.AddString(m_List1array.ElementAt(i).ElementAt(0));
  127. }
  128. }
  129. void ShowGoods::FillGrid()
  130. {
  131. int ii = 0;
  132. if (m_radio1 == 0)
  133. {
  134. m_List1.DeleteAllItems2();
  135. m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1);
  136. int count = 0;
  137. if (m_filter.IsEmpty())
  138. {
  139. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  140. {
  141. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  142. }
  143. }
  144. else
  145. {
  146. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  147. {
  148. if (m_List1array.ElementAt(ii).ElementAt(0).Find(m_filter) != -1 || \
  149. m_List1array.ElementAt(ii).ElementAt(1).Find(m_filter) != -1 || \
  150. m_List1array.ElementAt(ii).ElementAt(2).Find(m_filter) != -1)
  151. {
  152. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  153. }
  154. }
  155. }
  156. m_List1.m_arLabels.SetSize(count, 1);
  157. ii = count;
  158. m_List1.m_LabelCount = ii;
  159. m_List1.SetItemCountEx(ii);
  160. }
  161. else
  162. {
  163. m_List2.DeleteAllItems2();
  164. m_List2.m_arLabels.SetSize(m_List2array.GetSize(), 1);
  165. int count = 0;
  166. if (m_filter.IsEmpty())
  167. {
  168. for (ii = 0; ii < m_List2.m_arLabels.GetSize(); ii++)
  169. {
  170. m_List2.m_arLabels.ElementAt(count++).Copy(m_List2array.ElementAt(ii));
  171. }
  172. }
  173. else
  174. {
  175. for (ii = 0; ii < m_List2.m_arLabels.GetSize(); ii++)
  176. {
  177. if (m_List2array.ElementAt(ii).ElementAt(0).Find(m_filter) != -1 || \
  178. m_List2array.ElementAt(ii).ElementAt(1).Find(m_filter) != -1 || \
  179. m_List2array.ElementAt(ii).ElementAt(2).Find(m_filter) != -1 || \
  180. m_List2array.ElementAt(ii).ElementAt(3).Find(m_filter) != -1 || \
  181. m_List2array.ElementAt(ii).ElementAt(4).Find(m_filter) != -1 || \
  182. m_List2array.ElementAt(ii).ElementAt(5).Find(m_filter) != -1 || \
  183. m_List2array.ElementAt(ii).ElementAt(6).Find(m_filter) != -1 || \
  184. m_List2array.ElementAt(ii).ElementAt(7).Find(m_filter) != -1)
  185. {
  186. m_List2.m_arLabels.ElementAt(count++).Copy(m_List2array.ElementAt(ii));
  187. }
  188. }
  189. }
  190. m_List2.m_arLabels.SetSize(count, 1);
  191. ii = count;
  192. m_List2.m_LabelCount = ii;
  193. m_List2.SetItemCountEx(ii);
  194. }
  195. CString str;
  196. str.Format("项目数:%d", ii);
  197. SetDlgItemText(IDC_STATIC2, str);
  198. CRect rc;
  199. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  200. ScreenToClient(rc);
  201. InvalidateRect(rc);
  202. }
  203. void ShowGoods::OnBUTclose()
  204. {
  205. // TODO: Add your control notification handler code here
  206. GetParent()->SendMessage(WM_CLOSE);
  207. }
  208. void ShowGoods::OnTimer(UINT nIDEvent)
  209. {
  210. // TODO: Add your message handler code here and/or call default
  211. KillTimer(nIDEvent);
  212. OnButton1();
  213. }
  214. BOOL ShowGoods::PreTranslateMessage(MSG* pMsg)
  215. {
  216. // TODO: Add your specialized code here and/or call the base class
  217. try
  218. {
  219. if (pMsg->message == WM_KEYDOWN)
  220. {
  221. switch (pMsg->wParam)
  222. {
  223. case VK_RETURN:
  224. OnButton1();
  225. return 1;
  226. case 0x43: // copy
  227. if ((GetKeyState(VK_CONTROL) & 0x80))
  228. {
  229. GetFocus()->SendMessage(WM_COPY);
  230. return TRUE;
  231. }
  232. break;
  233. case 0x56: //Ctrl + V:
  234. if ((GetKeyState(VK_CONTROL) & 0x80))
  235. {
  236. GetFocus()->SendMessage(WM_PASTE);
  237. return TRUE;
  238. }
  239. break;
  240. case 0x58: // cut
  241. if ((GetKeyState(VK_CONTROL) & 0x80))
  242. {
  243. GetFocus()->SendMessage(WM_CUT);
  244. return TRUE;
  245. }
  246. break;
  247. case 0x5A: //undo
  248. case 0x59: //redo
  249. if ((GetKeyState(VK_CONTROL) & 0x80))
  250. {
  251. GetFocus()->SendMessage(WM_UNDO);
  252. return TRUE;
  253. }
  254. break;
  255. }
  256. }
  257. return MyFormView::PreTranslateMessage(pMsg);
  258. }
  259. catch (...)
  260. {
  261. }
  262. return true;
  263. }
  264. void ShowGoods::OnButton1()
  265. {
  266. // TODO: Add your control notification handler code here
  267. UpdateData();
  268. m_filter.TrimLeft();
  269. m_filter.TrimRight();
  270. FillGrid();
  271. }
  272. void ShowGoods::OnDblclkList2(NMHDR* pNMHDR, LRESULT* pResult)
  273. {
  274. // TODO: Add your control notification handler code here
  275. /* POSITION pos;
  276. pos=m_List1.GetFirstSelectedItemPosition();
  277. if(pos==NULL)
  278. {
  279. return;
  280. }
  281. int iItem=m_List1.GetNextSelectedItem(pos);
  282. CString memberno=m_List1.GetItemText (iItem, 1);
  283. AddMember dlg;
  284. dlg.m_memberno =memberno;
  285. dlg.m_bAdd=0;
  286. if(dlg.DoModal ()==IDOK)
  287. {
  288. g_sendhead.bsql=0;
  289. g_sendhead.code[0]=68;
  290. g_sendhead.tabcount=1;
  291. g_pMainWnd->ProcessChatMessageRequest2(1);if(g_bSendOK==0)return;
  292. DataToArray(&m_List1array);
  293. OnButton1();
  294. }*/
  295. *pResult = 0;
  296. }
  297. void ShowGoods::OnSelchangeCombo1()
  298. {
  299. // TODO: Add your control notification handler code here
  300. SetTimer(1, 100, NULL);
  301. }
  302. void ShowGoods::GetData()
  303. {
  304. }
  305. void ShowGoods::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult)
  306. {
  307. NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
  308. // Take the default processing unless we set this to something else below.
  309. *pResult = 0;
  310. // First thing - check the draw stage. If it's the control's prepaint
  311. // stage, then tell Windows we want messages for every item.
  312. if (CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage)
  313. {
  314. *pResult = CDRF_NOTIFYITEMDRAW;
  315. }
  316. else if (CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage)
  317. {
  318. // This is the prepaint stage for an item. Here's where we set the
  319. // item's text color. Our return value will tell Windows to draw the
  320. // item itself, but it will use the new color we set here.
  321. // We'll cycle the colors through red, green, and light blue.
  322. if (atof(m_List1.m_arLabels.ElementAt(pLVCD->nmcd.dwItemSpec).ElementAt(2)) < 1)
  323. pLVCD->clrText = RGB(220, 0, 0);
  324. else
  325. pLVCD->clrText = RGB(20, 133, 20);
  326. if (pLVCD->nmcd.dwItemSpec % 2)
  327. pLVCD->clrTextBk = g_gridcol1;
  328. else
  329. pLVCD->clrTextBk = g_gridcol2;
  330. // Store the color back in the NMLVCUSTOMDRAW struct.
  331. // Tell Windows to paint the control itself.
  332. *pResult = CDRF_DODEFAULT;
  333. }
  334. }
  335. void ShowGoods::OnRadio1()
  336. {
  337. // TODO: Add your control notification handler code here
  338. UpdateData();
  339. if (m_radio1 == 0)
  340. {
  341. GetDlgItem(IDC_LIST2)->ShowWindow(SW_SHOW);
  342. GetDlgItem(IDC_LIST4)->ShowWindow(SW_HIDE);
  343. GetDlgItem(IDC_BUTdel)->ShowWindow(SW_HIDE);
  344. GetDlgItem(IDC_BUTdel2)->ShowWindow(SW_SHOW);
  345. }
  346. else
  347. {
  348. GetDlgItem(IDC_LIST4)->ShowWindow(SW_SHOW);
  349. GetDlgItem(IDC_LIST2)->ShowWindow(SW_HIDE);
  350. GetDlgItem(IDC_BUTdel)->ShowWindow(SW_SHOW);
  351. GetDlgItem(IDC_BUTdel2)->ShowWindow(SW_HIDE);
  352. }
  353. OnButton1();
  354. }
  355. void ShowGoods::OnRadio2()
  356. {
  357. // TODO: Add your control notification handler code here
  358. OnRadio1();
  359. }
  360. void ShowGoods::OnBUTdel()
  361. {
  362. // TODO: Add your control notification handler code here
  363. if (IsHasRights2new(49) == 0)return;
  364. POSITION pos;
  365. pos = m_List2.GetFirstSelectedItemPosition();
  366. if (pos == NULL)
  367. {
  368. AfxMessageBox("请先选中您要删除的项目!", MB_ICONINFORMATION);
  369. return;
  370. }
  371. if (AfxMessageBox("删除后将无法恢复, 继续吗?", MB_YESNO | MB_ICONSTOP) != IDYES)return;
  372. int iItem;
  373. CArray<int, int>array;
  374. while (pos)
  375. {
  376. iItem = m_List2.GetNextSelectedItem(pos);
  377. array.Add(iItem);
  378. }
  379. int i = 0;
  380. CString sql;
  381. for ( i = 0; i < array.GetSize(); i++)
  382. {
  383. iItem = array.ElementAt(i);
  384. CString id = m_List2.GetItemText(iItem, 0);
  385. CString type = m_List2.GetItemText(iItem, 6);
  386. if (type == "入库")
  387. sql += "***delete from storeinfo where id='" + id + "'";
  388. else if (type == "出库")
  389. sql += "***delete from storeinfo2 where id='" + id + "'";
  390. }
  391. sql.TrimLeft("***");
  392. g_sendhead.bsql = 1;
  393. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  394. g_sendhead.bsql = 0;
  395. g_sendhead.code[0] = 76;
  396. g_sendhead.tabcount = 1;
  397. g_pMainWnd->ProcessChatMessageRequest2(1); if (g_bSendOK == 0)return;
  398. DataToArray(&g_List1array);
  399. m_List1array.RemoveAll();
  400. m_List2array.RemoveAll();
  401. int size1 = 0;
  402. int size2 = 0;
  403. for (i = 0; i < g_List1array.GetSize(); i++)
  404. {
  405. if (g_List1array.ElementAt(i).GetSize() == 8)
  406. {
  407. size2++;
  408. m_List2array.SetSize(size2, 1);
  409. size2--;
  410. m_List2array.ElementAt(size2).Copy(g_List1array.ElementAt(i));
  411. size2++;
  412. }
  413. else if (g_List1array.ElementAt(i).GetSize() == 3)
  414. {
  415. size1++;
  416. m_List1array.SetSize(size1, 1);
  417. size1--;
  418. m_List1array.ElementAt(size1).Copy(g_List1array.ElementAt(i));
  419. size1++;
  420. }
  421. }
  422. FillGrid();
  423. }
  424. void ShowGoods::OnBUTdel6()
  425. {
  426. // TODO: Add your control notification handler code here
  427. UpdateData();
  428. if (m_radio1 == 0)
  429. ListToXLS(&m_List1, "c:\\库存记录.xls", 0);
  430. else
  431. ListToXLS(&m_List2, "c:\\出入库.xls", 0);
  432. }
  433. void ShowGoods::OnBUTdel2()
  434. {
  435. // TODO: Add your control notification handler code here
  436. POSITION pos;
  437. pos = m_List1.GetFirstSelectedItemPosition();
  438. if (pos == NULL)
  439. {
  440. AfxMessageBox("请先选中您要盘点的项目!", MB_ICONINFORMATION);
  441. return;
  442. }
  443. int iItem = m_List1.GetNextSelectedItem(pos);
  444. CString type = m_List1.GetItemText(iItem, 0);
  445. CString name = m_List1.GetItemText(iItem, 1);
  446. InputName dlg;
  447. dlg.m_mode = 1;
  448. if (dlg.DoModal() != IDOK)return;
  449. if (AfxMessageBox("注意:盘点后将清除全部出入库记录, 继续吗?", MB_YESNO | MB_ICONSTOP) != IDYES)return;
  450. CString sql;
  451. sql.Format("delete from [storeinfo] where [type]='%s' and [name]='%s'***delete from [storeinfo2] where [type]='%s' and [name]='%s'***insert into [storeinfo]([id],[type],[name],[count],[date],[remark],[clerk])values('盘点','%s','%s','%d','%s','%s','%s')", type, name, type, name, type, name, atoi(dlg.m_name), g_date, "盘点", g_user.name);
  452. m_List1array.RemoveAll();
  453. m_List2array.RemoveAll();
  454. g_sendhead.bsql = 1;
  455. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  456. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  457. g_sendhead.bsql = 0;
  458. g_sendhead.code[0] = 76;
  459. g_sendhead.tabcount = 1;
  460. g_pMainWnd->ProcessChatMessageRequest2(1); if (g_bSendOK == 0)return;
  461. DataToArray(&g_List1array);
  462. int size1 = 0;
  463. int size2 = 0;
  464. for (int i = 0; i < g_List1array.GetSize(); i++)
  465. {
  466. if (g_List1array.ElementAt(i).GetSize() == 8)
  467. {
  468. size2++;
  469. m_List2array.SetSize(size2, 1);
  470. size2--;
  471. m_List2array.ElementAt(size2).Copy(g_List1array.ElementAt(i));
  472. size2++;
  473. }
  474. else if (g_List1array.ElementAt(i).GetSize() == 3)
  475. {
  476. size1++;
  477. m_List1array.SetSize(size1, 1);
  478. size1--;
  479. m_List1array.ElementAt(size1).Copy(g_List1array.ElementAt(i));
  480. size1++;
  481. }
  482. }
  483. FillGrid();
  484. }