ShowGoods.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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. {
  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. {
  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. }
  263. void ShowGoods::OnButton1()
  264. {
  265. // TODO: Add your control notification handler code here
  266. UpdateData();
  267. m_filter.TrimLeft ();
  268. m_filter.TrimRight ();
  269. FillGrid();
  270. }
  271. void ShowGoods::OnDblclkList2(NMHDR* pNMHDR, LRESULT* pResult)
  272. {
  273. // TODO: Add your control notification handler code here
  274. /* POSITION pos;
  275. pos=m_List1.GetFirstSelectedItemPosition();
  276. if(pos==NULL)
  277. {
  278. return;
  279. }
  280. int iItem=m_List1.GetNextSelectedItem(pos);
  281. CString memberno=m_List1.GetItemText (iItem, 1);
  282. AddMember dlg;
  283. dlg.m_memberno =memberno;
  284. dlg.m_bAdd=0;
  285. if(dlg.DoModal ()==IDOK)
  286. {
  287. g_sendhead.bsql=0;
  288. g_sendhead.code[0]=68;
  289. g_sendhead.tabcount=1;
  290. g_pMainWnd->ProcessChatMessageRequest2(1);if(g_bSendOK==0)return;
  291. DataToArray(&m_List1array);
  292. OnButton1();
  293. }*/
  294. *pResult = 0;
  295. }
  296. void ShowGoods::OnSelchangeCombo1()
  297. {
  298. // TODO: Add your control notification handler code here
  299. SetTimer(1, 100, NULL);
  300. }
  301. void ShowGoods::GetData()
  302. {
  303. }
  304. void ShowGoods::OnCustomdrawList ( NMHDR* pNMHDR, LRESULT* pResult )
  305. {
  306. NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
  307. // Take the default processing unless we set this to something else below.
  308. *pResult = 0;
  309. // First thing - check the draw stage. If it's the control's prepaint
  310. // stage, then tell Windows we want messages for every item.
  311. if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
  312. {
  313. *pResult = CDRF_NOTIFYITEMDRAW;
  314. }
  315. else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
  316. {
  317. // This is the prepaint stage for an item. Here's where we set the
  318. // item's text color. Our return value will tell Windows to draw the
  319. // item itself, but it will use the new color we set here.
  320. // We'll cycle the colors through red, green, and light blue.
  321. if(atof(m_List1.m_arLabels.ElementAt (pLVCD->nmcd.dwItemSpec).ElementAt (2))<1)
  322. pLVCD->clrText = RGB(220,0,0);
  323. else
  324. pLVCD->clrText = RGB(20,133,20);
  325. if(pLVCD->nmcd.dwItemSpec%2)
  326. pLVCD->clrTextBk = g_gridcol1;
  327. else
  328. pLVCD->clrTextBk = g_gridcol2;
  329. // Store the color back in the NMLVCUSTOMDRAW struct.
  330. // Tell Windows to paint the control itself.
  331. *pResult = CDRF_DODEFAULT;
  332. }
  333. }
  334. void ShowGoods::OnRadio1()
  335. {
  336. // TODO: Add your control notification handler code here
  337. UpdateData();
  338. if(m_radio1==0)
  339. {
  340. GetDlgItem(IDC_LIST2)->ShowWindow(SW_SHOW);
  341. GetDlgItem(IDC_LIST4)->ShowWindow(SW_HIDE);
  342. GetDlgItem(IDC_BUTdel)->ShowWindow(SW_HIDE);
  343. GetDlgItem(IDC_BUTdel2)->ShowWindow(SW_SHOW);
  344. }
  345. else
  346. {
  347. GetDlgItem(IDC_LIST4)->ShowWindow(SW_SHOW);
  348. GetDlgItem(IDC_LIST2)->ShowWindow(SW_HIDE);
  349. GetDlgItem(IDC_BUTdel)->ShowWindow(SW_SHOW);
  350. GetDlgItem(IDC_BUTdel2)->ShowWindow(SW_HIDE);
  351. }
  352. OnButton1();
  353. }
  354. void ShowGoods::OnRadio2()
  355. {
  356. // TODO: Add your control notification handler code here
  357. OnRadio1();
  358. }
  359. void ShowGoods::OnBUTdel()
  360. {
  361. // TODO: Add your control notification handler code here
  362. if(IsHasRights2new(49)==0)return;
  363. POSITION pos;
  364. pos=m_List2.GetFirstSelectedItemPosition();
  365. if(pos==NULL)
  366. {
  367. AfxMessageBox("请先选中您要删除的项目!", MB_ICONINFORMATION);
  368. return;
  369. }
  370. if(AfxMessageBox("删除后将无法恢复, 继续吗?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
  371. int iItem;
  372. CArray<int,int>array;
  373. while (pos)
  374. {
  375. iItem = m_List2.GetNextSelectedItem(pos);
  376. array.Add (iItem);
  377. }
  378. int i = 0;
  379. CString sql;
  380. for( i=0; i<array.GetSize (); i++)
  381. {
  382. iItem=array.ElementAt (i);
  383. CString id=m_List2.GetItemText (iItem, 0);
  384. CString type=m_List2.GetItemText (iItem, 6);
  385. if(type=="入库")
  386. sql+="***delete from storeinfo where id='"+id+"'";
  387. else if(type=="出库")
  388. sql+="***delete from storeinfo2 where id='"+id+"'";
  389. }
  390. sql.TrimLeft ("***");
  391. g_sendhead.bsql=1;
  392. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  393. g_sendhead.bsql=0;
  394. g_sendhead.code[0]=76;
  395. g_sendhead.tabcount=1;
  396. g_pMainWnd->ProcessChatMessageRequest2(1);if(g_bSendOK==0)return;
  397. DataToArray(&g_List1array);
  398. m_List1array.RemoveAll();
  399. m_List2array.RemoveAll();
  400. int size1=0;
  401. int size2=0;
  402. for( i=0; i<g_List1array.GetSize (); i++)
  403. {
  404. if(g_List1array.ElementAt (i).GetSize ()==8)
  405. {
  406. size2++;
  407. m_List2array.SetSize(size2 , 1 );
  408. size2--;
  409. m_List2array.ElementAt (size2).Copy (g_List1array.ElementAt (i));
  410. size2++;
  411. }
  412. else if(g_List1array.ElementAt (i).GetSize ()==3)
  413. {
  414. size1++;
  415. m_List1array.SetSize(size1 , 1 );
  416. size1--;
  417. m_List1array.ElementAt (size1).Copy (g_List1array.ElementAt (i));
  418. size1++;
  419. }
  420. }
  421. FillGrid();
  422. }
  423. void ShowGoods::OnBUTdel6()
  424. {
  425. // TODO: Add your control notification handler code here
  426. UpdateData();
  427. if(m_radio1==0)
  428. ListToXLS(&m_List1, "c:\\库存记录.xls", 0);
  429. else
  430. ListToXLS(&m_List2, "c:\\出入库.xls", 0);
  431. }
  432. void ShowGoods::OnBUTdel2()
  433. {
  434. // TODO: Add your control notification handler code here
  435. POSITION pos;
  436. pos=m_List1.GetFirstSelectedItemPosition();
  437. if(pos==NULL)
  438. {
  439. AfxMessageBox("请先选中您要盘点的项目!", MB_ICONINFORMATION);
  440. return;
  441. }
  442. int iItem=m_List1.GetNextSelectedItem(pos);
  443. CString type=m_List1.GetItemText (iItem, 0);
  444. CString name=m_List1.GetItemText (iItem, 1);
  445. InputName dlg;
  446. dlg.m_mode=1;
  447. if(dlg.DoModal()!=IDOK)return;
  448. if(AfxMessageBox("注意:盘点后将清除全部出入库记录, 继续吗?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
  449. CString sql;
  450. 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);
  451. m_List1array.RemoveAll();
  452. m_List2array.RemoveAll();
  453. g_sendhead.bsql=1;
  454. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  455. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  456. g_sendhead.bsql=0;
  457. g_sendhead.code[0]=76;
  458. g_sendhead.tabcount=1;
  459. g_pMainWnd->ProcessChatMessageRequest2(1);if(g_bSendOK==0)return;
  460. DataToArray(&g_List1array);
  461. int size1=0;
  462. int size2=0;
  463. for(int i=0; i<g_List1array.GetSize (); i++)
  464. {
  465. if(g_List1array.ElementAt (i).GetSize ()==8)
  466. {
  467. size2++;
  468. m_List2array.SetSize(size2 , 1 );
  469. size2--;
  470. m_List2array.ElementAt (size2).Copy (g_List1array.ElementAt (i));
  471. size2++;
  472. }
  473. else if(g_List1array.ElementAt (i).GetSize ()==3)
  474. {
  475. size1++;
  476. m_List1array.SetSize(size1 , 1 );
  477. size1--;
  478. m_List1array.ElementAt (size1).Copy (g_List1array.ElementAt (i));
  479. size1++;
  480. }
  481. }
  482. FillGrid();
  483. }