ShowGoods.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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 size1=0;
  95. int size2=0;
  96. for(int i=0; i<g_List1array.GetSize (); i++)
  97. {
  98. if(g_List1array.ElementAt (i).GetSize ()==8)
  99. {
  100. size2++;
  101. m_List2array.SetSize(size2 , 1 );
  102. size2--;
  103. m_List2array.ElementAt (size2).Copy (g_List1array.ElementAt (i));
  104. size2++;
  105. }
  106. else if(g_List1array.ElementAt (i).GetSize ()==3)
  107. {
  108. size1++;
  109. m_List1array.SetSize(size1 , 1 );
  110. size1--;
  111. m_List1array.ElementAt (size1).Copy (g_List1array.ElementAt (i));
  112. size1++;
  113. }
  114. }
  115. FillGrid();
  116. m_combo1.GetWindowRect (rc2);
  117. ScreenToClient(rc2);
  118. rc2.bottom +=200;
  119. m_combo1.MoveWindow (rc2);
  120. GetDlgItem(IDC_BUTclose)->GetWindowRect(rc2);
  121. SetComboHei(&m_combo1, rc2.Height ());
  122. for( i=0; i<m_List1array.GetSize (); i++)
  123. {
  124. if(m_combo1.FindString (0, m_List1array.ElementAt (i).ElementAt (0))==-1)
  125. m_combo1.AddString (m_List1array.ElementAt (i).ElementAt (0));
  126. }
  127. }
  128. void ShowGoods::FillGrid()
  129. {
  130. int ii=0;
  131. if(m_radio1==0)
  132. {
  133. m_List1.DeleteAllItems2 ();
  134. m_List1.m_arLabels.SetSize( m_List1array.GetSize (), 1 );
  135. int count=0;
  136. if(m_filter.IsEmpty ())
  137. {
  138. for(ii=0; ii<m_List1.m_arLabels.GetSize (); ii++)
  139. {
  140. m_List1.m_arLabels.ElementAt (count++).Copy (m_List1array.ElementAt (ii));
  141. }
  142. }
  143. else
  144. {
  145. for(ii=0; ii<m_List1.m_arLabels.GetSize (); ii++)
  146. {
  147. if(m_List1array.ElementAt (ii).ElementAt (0).Find (m_filter)!=-1 ||\
  148. m_List1array.ElementAt (ii).ElementAt (1).Find (m_filter)!=-1 || \
  149. m_List1array.ElementAt (ii).ElementAt (2).Find (m_filter)!=-1 )
  150. {
  151. m_List1.m_arLabels.ElementAt (count++).Copy (m_List1array.ElementAt (ii));
  152. }
  153. }
  154. }
  155. m_List1.m_arLabels.SetSize(count, 1);
  156. ii=count;
  157. m_List1.m_LabelCount=ii;
  158. m_List1.SetItemCountEx (ii);
  159. }
  160. else
  161. {
  162. m_List2.DeleteAllItems2 ();
  163. m_List2.m_arLabels.SetSize( m_List2array.GetSize (), 1 );
  164. int count=0;
  165. if(m_filter.IsEmpty ())
  166. {
  167. for(ii=0; ii<m_List2.m_arLabels.GetSize (); ii++)
  168. {
  169. m_List2.m_arLabels.ElementAt (count++).Copy (m_List2array.ElementAt (ii));
  170. }
  171. }
  172. else
  173. {
  174. for(ii=0; ii<m_List2.m_arLabels.GetSize (); ii++)
  175. {
  176. if(m_List2array.ElementAt (ii).ElementAt (0).Find (m_filter)!=-1 ||\
  177. m_List2array.ElementAt (ii).ElementAt (1).Find (m_filter)!=-1 || \
  178. m_List2array.ElementAt (ii).ElementAt (2).Find (m_filter)!=-1 || \
  179. m_List2array.ElementAt (ii).ElementAt (3).Find (m_filter)!=-1 || \
  180. m_List2array.ElementAt (ii).ElementAt (4).Find (m_filter)!=-1 || \
  181. m_List2array.ElementAt (ii).ElementAt (5).Find (m_filter)!=-1 || \
  182. m_List2array.ElementAt (ii).ElementAt (6).Find (m_filter)!=-1 || \
  183. m_List2array.ElementAt (ii).ElementAt (7).Find (m_filter)!=-1 )
  184. {
  185. m_List2.m_arLabels.ElementAt (count++).Copy (m_List2array.ElementAt (ii));
  186. }
  187. }
  188. }
  189. m_List2.m_arLabels.SetSize(count, 1);
  190. ii=count;
  191. m_List2.m_LabelCount=ii;
  192. m_List2.SetItemCountEx (ii);
  193. }
  194. CString str;
  195. str.Format ("项目数:%d", ii);
  196. SetDlgItemText(IDC_STATIC2, str);
  197. CRect rc;
  198. GetDlgItem(IDC_STATIC2)->GetWindowRect (rc);
  199. ScreenToClient(rc);
  200. InvalidateRect(rc);
  201. }
  202. void ShowGoods::OnBUTclose()
  203. {
  204. // TODO: Add your control notification handler code here
  205. GetParent()->SendMessage(WM_CLOSE);
  206. }
  207. void ShowGoods::OnTimer(UINT nIDEvent)
  208. {
  209. // TODO: Add your message handler code here and/or call default
  210. KillTimer(nIDEvent);
  211. OnButton1();
  212. }
  213. BOOL ShowGoods::PreTranslateMessage(MSG* pMsg)
  214. {
  215. // TODO: Add your specialized code here and/or call the base class
  216. try
  217. {
  218. if(pMsg->message==WM_KEYDOWN)
  219. {
  220. switch (pMsg->wParam)
  221. {
  222. case VK_RETURN:
  223. OnButton1();
  224. return 1;
  225. case 0x43: // copy
  226. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  227. {
  228. GetFocus()->SendMessage(WM_COPY);
  229. return TRUE;
  230. }
  231. break;
  232. case 0x56: //Ctrl + V:
  233. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  234. {
  235. GetFocus()->SendMessage(WM_PASTE);
  236. return TRUE;
  237. }
  238. break;
  239. case 0x58: // cut
  240. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  241. {
  242. GetFocus()->SendMessage(WM_CUT);
  243. return TRUE;
  244. }
  245. break;
  246. case 0x5A: //undo
  247. case 0x59: //redo
  248. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  249. {
  250. GetFocus()->SendMessage(WM_UNDO);
  251. return TRUE;
  252. }
  253. break;
  254. }
  255. }
  256. return MyFormView::PreTranslateMessage(pMsg);
  257. }
  258. catch(...)
  259. {
  260. }
  261. }
  262. void ShowGoods::OnButton1()
  263. {
  264. // TODO: Add your control notification handler code here
  265. UpdateData();
  266. m_filter.TrimLeft ();
  267. m_filter.TrimRight ();
  268. FillGrid();
  269. }
  270. void ShowGoods::OnDblclkList2(NMHDR* pNMHDR, LRESULT* pResult)
  271. {
  272. // TODO: Add your control notification handler code here
  273. /* POSITION pos;
  274. pos=m_List1.GetFirstSelectedItemPosition();
  275. if(pos==NULL)
  276. {
  277. return;
  278. }
  279. int iItem=m_List1.GetNextSelectedItem(pos);
  280. CString memberno=m_List1.GetItemText (iItem, 1);
  281. AddMember dlg;
  282. dlg.m_memberno =memberno;
  283. dlg.m_bAdd=0;
  284. if(dlg.DoModal ()==IDOK)
  285. {
  286. g_sendhead.bsql=0;
  287. g_sendhead.code[0]=68;
  288. g_sendhead.tabcount=1;
  289. g_pMainWnd->ProcessChatMessageRequest2(1);if(g_bSendOK==0)return;
  290. DataToArray(&m_List1array);
  291. OnButton1();
  292. }*/
  293. *pResult = 0;
  294. }
  295. void ShowGoods::OnSelchangeCombo1()
  296. {
  297. // TODO: Add your control notification handler code here
  298. SetTimer(1, 100, NULL);
  299. }
  300. void ShowGoods::GetData()
  301. {
  302. }
  303. void ShowGoods::OnCustomdrawList ( NMHDR* pNMHDR, LRESULT* pResult )
  304. {
  305. NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
  306. // Take the default processing unless we set this to something else below.
  307. *pResult = 0;
  308. // First thing - check the draw stage. If it's the control's prepaint
  309. // stage, then tell Windows we want messages for every item.
  310. if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
  311. {
  312. *pResult = CDRF_NOTIFYITEMDRAW;
  313. }
  314. else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
  315. {
  316. // This is the prepaint stage for an item. Here's where we set the
  317. // item's text color. Our return value will tell Windows to draw the
  318. // item itself, but it will use the new color we set here.
  319. // We'll cycle the colors through red, green, and light blue.
  320. if(atof(m_List1.m_arLabels.ElementAt (pLVCD->nmcd.dwItemSpec).ElementAt (2))<1)
  321. pLVCD->clrText = RGB(220,0,0);
  322. else
  323. pLVCD->clrText = RGB(20,133,20);
  324. if(pLVCD->nmcd.dwItemSpec%2)
  325. pLVCD->clrTextBk = g_gridcol1;
  326. else
  327. pLVCD->clrTextBk = g_gridcol2;
  328. // Store the color back in the NMLVCUSTOMDRAW struct.
  329. // Tell Windows to paint the control itself.
  330. *pResult = CDRF_DODEFAULT;
  331. }
  332. }
  333. void ShowGoods::OnRadio1()
  334. {
  335. // TODO: Add your control notification handler code here
  336. UpdateData();
  337. if(m_radio1==0)
  338. {
  339. GetDlgItem(IDC_LIST2)->ShowWindow(SW_SHOW);
  340. GetDlgItem(IDC_LIST4)->ShowWindow(SW_HIDE);
  341. GetDlgItem(IDC_BUTdel)->ShowWindow(SW_HIDE);
  342. GetDlgItem(IDC_BUTdel2)->ShowWindow(SW_SHOW);
  343. }
  344. else
  345. {
  346. GetDlgItem(IDC_LIST4)->ShowWindow(SW_SHOW);
  347. GetDlgItem(IDC_LIST2)->ShowWindow(SW_HIDE);
  348. GetDlgItem(IDC_BUTdel)->ShowWindow(SW_SHOW);
  349. GetDlgItem(IDC_BUTdel2)->ShowWindow(SW_HIDE);
  350. }
  351. OnButton1();
  352. }
  353. void ShowGoods::OnRadio2()
  354. {
  355. // TODO: Add your control notification handler code here
  356. OnRadio1();
  357. }
  358. void ShowGoods::OnBUTdel()
  359. {
  360. // TODO: Add your control notification handler code here
  361. if(IsHasRights2new(49)==0)return;
  362. POSITION pos;
  363. pos=m_List2.GetFirstSelectedItemPosition();
  364. if(pos==NULL)
  365. {
  366. AfxMessageBox("请先选中您要删除的项目!", MB_ICONINFORMATION);
  367. return;
  368. }
  369. if(AfxMessageBox("删除后将无法恢复, 继续吗?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
  370. int iItem;
  371. CArray<int,int>array;
  372. while (pos)
  373. {
  374. iItem = m_List2.GetNextSelectedItem(pos);
  375. array.Add (iItem);
  376. }
  377. CString sql;
  378. for(int i=0; i<array.GetSize (); i++)
  379. {
  380. iItem=array.ElementAt (i);
  381. CString id=m_List2.GetItemText (iItem, 0);
  382. CString type=m_List2.GetItemText (iItem, 6);
  383. if(type=="入库")
  384. sql+="***delete from storeinfo where id='"+id+"'";
  385. else if(type=="出库")
  386. sql+="***delete from storeinfo2 where id='"+id+"'";
  387. }
  388. sql.TrimLeft ("***");
  389. g_sendhead.bsql=1;
  390. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  391. g_sendhead.bsql=0;
  392. g_sendhead.code[0]=76;
  393. g_sendhead.tabcount=1;
  394. g_pMainWnd->ProcessChatMessageRequest2(1);if(g_bSendOK==0)return;
  395. DataToArray(&g_List1array);
  396. m_List1array.RemoveAll();
  397. m_List2array.RemoveAll();
  398. int size1=0;
  399. int size2=0;
  400. for( i=0; i<g_List1array.GetSize (); i++)
  401. {
  402. if(g_List1array.ElementAt (i).GetSize ()==8)
  403. {
  404. size2++;
  405. m_List2array.SetSize(size2 , 1 );
  406. size2--;
  407. m_List2array.ElementAt (size2).Copy (g_List1array.ElementAt (i));
  408. size2++;
  409. }
  410. else if(g_List1array.ElementAt (i).GetSize ()==3)
  411. {
  412. size1++;
  413. m_List1array.SetSize(size1 , 1 );
  414. size1--;
  415. m_List1array.ElementAt (size1).Copy (g_List1array.ElementAt (i));
  416. size1++;
  417. }
  418. }
  419. FillGrid();
  420. }
  421. void ShowGoods::OnBUTdel6()
  422. {
  423. // TODO: Add your control notification handler code here
  424. UpdateData();
  425. if(m_radio1==0)
  426. ListToXLS(&m_List1, "c:\\库存记录.xls", 0);
  427. else
  428. ListToXLS(&m_List2, "c:\\出入库.xls", 0);
  429. }
  430. void ShowGoods::OnBUTdel2()
  431. {
  432. // TODO: Add your control notification handler code here
  433. POSITION pos;
  434. pos=m_List1.GetFirstSelectedItemPosition();
  435. if(pos==NULL)
  436. {
  437. AfxMessageBox("请先选中您要盘点的项目!", MB_ICONINFORMATION);
  438. return;
  439. }
  440. int iItem=m_List1.GetNextSelectedItem(pos);
  441. CString type=m_List1.GetItemText (iItem, 0);
  442. CString name=m_List1.GetItemText (iItem, 1);
  443. InputName dlg;
  444. dlg.m_mode=1;
  445. if(dlg.DoModal()!=IDOK)return;
  446. if(AfxMessageBox("注意:盘点后将清除全部出入库记录, 继续吗?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
  447. CString sql;
  448. 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);
  449. m_List1array.RemoveAll();
  450. m_List2array.RemoveAll();
  451. g_sendhead.bsql=1;
  452. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  453. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  454. g_sendhead.bsql=0;
  455. g_sendhead.code[0]=76;
  456. g_sendhead.tabcount=1;
  457. g_pMainWnd->ProcessChatMessageRequest2(1);if(g_bSendOK==0)return;
  458. DataToArray(&g_List1array);
  459. int size1=0;
  460. int size2=0;
  461. for(int i=0; i<g_List1array.GetSize (); i++)
  462. {
  463. if(g_List1array.ElementAt (i).GetSize ()==8)
  464. {
  465. size2++;
  466. m_List2array.SetSize(size2 , 1 );
  467. size2--;
  468. m_List2array.ElementAt (size2).Copy (g_List1array.ElementAt (i));
  469. size2++;
  470. }
  471. else if(g_List1array.ElementAt (i).GetSize ()==3)
  472. {
  473. size1++;
  474. m_List1array.SetSize(size1 , 1 );
  475. size1--;
  476. m_List1array.ElementAt (size1).Copy (g_List1array.ElementAt (i));
  477. size1++;
  478. }
  479. }
  480. FillGrid();
  481. }