TXSPDlg.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. // TXSPDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "TXSPDlg.h"
  6. #include "MyMdi.H"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. IMPLEMENT_DYNCREATE(TXSPDlg, MyFormView)
  13. TXSPDlg::TXSPDlg(): MyFormView(TXSPDlg::IDD)
  14. {
  15. m_taoxiid = _T("");
  16. m_taoxijiage = _T("");
  17. m_zs = _T("");
  18. }
  19. TXSPDlg::~TXSPDlg()
  20. {
  21. }
  22. void TXSPDlg::DoDataExchange(CDataExchange* pDX)
  23. {
  24. MyFormView::DoDataExchange(pDX);
  25. DDX_Control(pDX, IDC_LIST2, m_List2);
  26. DDX_Control(pDX, IDC_LIST1, m_List1);
  27. DDX_Control(pDX, IDC_STATIC1, m_static1);
  28. DDX_Control(pDX, IDC_COMBOtaoxiname, m_combotaoxiname);
  29. DDX_Text(pDX, IDC_EDITtaoxiid, m_taoxiid);
  30. DDX_Text(pDX, IDC_EDITtaoxijiage, m_taoxijiage);
  31. DDX_Text(pDX, IDC_EDITzs, m_zs);
  32. DDX_Control(pDX, CB_KINDS, m_cbKinds);
  33. }
  34. BEGIN_MESSAGE_MAP(TXSPDlg, MyFormView)
  35. ON_BN_CLICKED(IDC_BUTsave, OnBUTsave)
  36. ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
  37. ON_BN_CLICKED(IDC_BUTclose, OnBUTclose)
  38. ON_CBN_SELCHANGE(IDC_COMBOtaoxiname, OnSelchangeCOMBOtaoxiname)
  39. ON_BN_CLICKED(IDC_BUTspbox, OnBUTspbox)
  40. ON_WM_TIMER()
  41. ON_BN_CLICKED(IDC_BUTsave2, OnBUTsave2)
  42. ON_BN_CLICKED(IDC_BUTdel2, OnBUTdel2)
  43. ON_BN_CLICKED(IDC_BUTspbox2, OnBUTspbox2)
  44. ON_BN_CLICKED(IDC_BUTclose2, OnBUTclose2)
  45. ON_CBN_SELCHANGE(CB_KINDS, OnCbnSelchangeKinds)
  46. ON_WM_SIZE()
  47. END_MESSAGE_MAP()
  48. #ifdef _DEBUG
  49. void TXSPDlg::AssertValid() const
  50. {
  51. MyFormView::AssertValid();
  52. }
  53. void TXSPDlg::Dump(CDumpContext& dc) const
  54. {
  55. MyFormView::Dump(dc);
  56. }
  57. #endif
  58. void TXSPDlg::OnInitialUpdate()
  59. {
  60. MyFormView::OnInitialUpdate();
  61. CMyMdi Mdi;
  62. Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this);
  63. CRect rc1, rc2;
  64. GetWindowRect(rc1);
  65. rc2 = rc1;
  66. rc1 = g_rc;
  67. ScreenToClient(&rc1);
  68. ::MoveWindow(m_hWnd, g_rc.left, g_rc.top, g_rc.Width(), g_rc.Height(), TRUE);
  69. EnumChildWindows(m_hWnd, (WNDENUMPROC)EnumChildProc, 0);
  70. m_combotaoxiname.GetWindowRect(rc2);
  71. ScreenToClient(rc2);
  72. rc2.bottom += 200;
  73. m_combotaoxiname.MoveWindow(rc2);
  74. m_static1.SetFont(&g_titlefont);
  75. g_sendhead.bsql = 0;
  76. g_sendhead.code[0] = 6;
  77. g_sendhead.code[1] = 7;
  78. g_sendhead.code[2] = 10;
  79. g_sendhead.code[3] = 4;
  80. g_sendhead.tabcount = 4;
  81. g_pMainWnd->ProcessChatMessageRequest2(6);
  82. if (g_bSendOK == 0)return;
  83. DataToArray(&m_List1array, &m_List2array, &m_List3array, &m_sparray);
  84. for (int i = 0; i < m_List1array.GetSize(); i++)
  85. m_combotaoxiname.AddString(m_List1array.ElementAt(i).ElementAt(1));
  86. m_List1.InitStyle();
  87. m_List1.InsertColumn(0, _T("编号"), LVCFMT_LEFT, 80);
  88. m_List1.InsertColumn(1, _T("商品名称"), LVCFMT_LEFT, 200);
  89. m_List1.InsertColumn(2, _T("数量"), LVCFMT_LEFT, 60);
  90. m_List2.InitStyle();
  91. m_List2.InsertColumn(0, _T("编号"), LVCFMT_LEFT, 80);
  92. m_List2.InsertColumn(1, _T("商品名称"), LVCFMT_LEFT, 200);
  93. m_List2.InsertColumn(2, _T("数量"), LVCFMT_LEFT, 60);
  94. }
  95. void TXSPDlg::OnSelchangeCOMBOtaoxiname()
  96. {
  97. int pos = m_combotaoxiname.GetCurSel();
  98. if (pos == -1)return;
  99. m_taoxiid = m_List1array.ElementAt(pos).ElementAt(0);
  100. m_taoxijiage = m_List1array.ElementAt(pos).ElementAt(2);
  101. m_zs = m_List1array.ElementAt(pos).ElementAt(3);
  102. UpdateData(false);
  103. FillGrid();
  104. }
  105. void TXSPDlg::FillGrid()
  106. {
  107. m_List1.DeleteAllItems();
  108. int pos = 0;
  109. int i = 0;
  110. for ( i = 0; i < m_List2array.GetSize(); i++)
  111. {
  112. if (m_List2array.ElementAt(i).ElementAt(0) != m_taoxiid)continue;
  113. m_List1.InsertItem(pos, m_List2array.ElementAt(i).ElementAt(1));
  114. m_List1.SetItemText(pos, 1, GetSPNameFromId(m_List2array.ElementAt(i).ElementAt(1)));
  115. m_List1.SetItemText(pos, 2, m_List2array.ElementAt(i).ElementAt(2));
  116. pos++;
  117. }
  118. //#ifndef MODERN_VERSION
  119. #if 0
  120. for( i=0; i<m_List3array.GetSize (); i++)
  121. {
  122. if(m_List3array.ElementAt (i).ElementAt (0)!=m_taoxiid)continue;
  123. m_List1.InsertItem(pos, m_List3array.ElementAt (i).ElementAt (1));
  124. m_List1.SetItemText(pos,1, GetSPNameFromId(m_List3array.ElementAt (i).ElementAt (1)));
  125. m_List1.SetItemText(pos,2, m_List3array.ElementAt (i).ElementAt (2));
  126. pos++;
  127. }
  128. #else
  129. m_List2.DeleteAllItems();
  130. pos = 0;
  131. for (i = 0; i < m_List3array.GetSize(); i++)
  132. {
  133. if (m_List3array.ElementAt(i).ElementAt(0) != m_taoxiid)continue;
  134. m_List2.InsertItem(pos, m_List3array.ElementAt(i).ElementAt(1));
  135. m_List2.SetItemText(pos, 1, GetSPNameFromId(m_List3array.ElementAt(i).ElementAt(1)));
  136. m_List2.SetItemText(pos, 2, m_List3array.ElementAt(i).ElementAt(2));
  137. pos++;
  138. }
  139. #endif
  140. }
  141. CString TXSPDlg::GetSPNameFromId(CString id)
  142. {
  143. int i = 0;
  144. for ( i = 0; i < m_sparray.GetSize(); i++)
  145. {
  146. if (id == m_sparray.ElementAt(i).ElementAt(0))
  147. return m_sparray.ElementAt(i).ElementAt(1);
  148. }
  149. id.TrimLeft("0");
  150. for (i = 0; i < m_sparray.GetSize(); i++)
  151. {
  152. if (id == m_sparray.ElementAt(i).ElementAt(0))
  153. return m_sparray.ElementAt(i).ElementAt(1);
  154. }
  155. return "";
  156. }
  157. BOOL TXSPDlg::PreTranslateMessage(MSG* pMsg)
  158. {
  159. if (pMsg->message == WM_KEYDOWN)
  160. {
  161. switch (pMsg->wParam)
  162. {
  163. case 0x43: // copy
  164. if ((GetKeyState(VK_CONTROL) & 0x80))
  165. {
  166. GetFocus()->SendMessage(WM_COPY);
  167. return TRUE;
  168. }
  169. break;
  170. case 0x56: //Ctrl + V:
  171. if ((GetKeyState(VK_CONTROL) & 0x80))
  172. {
  173. GetFocus()->SendMessage(WM_PASTE);
  174. return TRUE;
  175. }
  176. break;
  177. case 0x58: // cut
  178. if ((GetKeyState(VK_CONTROL) & 0x80))
  179. {
  180. GetFocus()->SendMessage(WM_CUT);
  181. return TRUE;
  182. }
  183. break;
  184. case 0x5A: //undo
  185. case 0x59: //redo
  186. if ((GetKeyState(VK_CONTROL) & 0x80))
  187. {
  188. GetFocus()->SendMessage(WM_UNDO);
  189. return TRUE;
  190. }
  191. break;
  192. }
  193. }
  194. else if (pMsg->message == WM_LBUTTONDBLCLK)
  195. {
  196. if (0)
  197. {//list1
  198. CPoint pt;
  199. CRect rc, rc2;
  200. ::GetCursorPos(&pt);
  201. m_List1.GetWindowRect(rc2);
  202. if (rc2.PtInRect(pt) == 0) return MyFormView::PreTranslateMessage(pMsg);
  203. pt.x -= rc2.left;
  204. pt.y -= rc2.top;
  205. POSITION pos;
  206. pos = m_List1.GetFirstSelectedItemPosition();
  207. if (pos == NULL)return 1;
  208. int iItem = m_List1.GetNextSelectedItem(pos);
  209. m_List1.GetSubItemRect(iItem, 2, LVIR_BOUNDS, rc);
  210. if (rc.PtInRect(pt))
  211. return MyFormView::PreTranslateMessage(pMsg);
  212. else
  213. return 1;
  214. }
  215. }
  216. return MyFormView::PreTranslateMessage(pMsg);
  217. }
  218. void TXSPDlg::SetSPName1()
  219. {
  220. for (int i = 0; i < m_List1.GetItemCount(); i++)
  221. {
  222. m_List1.SetItemText(i, 1, GetSPNameFromId(m_List1.GetItemText(i, 0)));
  223. }
  224. }
  225. void TXSPDlg::SetSPName2()
  226. {
  227. for (int i = 0; i < m_List2.GetItemCount(); i++)
  228. {
  229. m_List2.SetItemText(i, 1, GetSPNameFromId(m_List2.GetItemText(i, 0)));
  230. }
  231. }
  232. void TXSPDlg::OnTimer(UINT nIDEvent)
  233. {
  234. if (nIDEvent == 1)
  235. {
  236. KillTimer(nIDEvent);
  237. SetSPName1();
  238. }
  239. else if (nIDEvent == 2)
  240. {
  241. KillTimer(nIDEvent);
  242. SetSPName2();
  243. }
  244. }
  245. void TXSPDlg::OnBUTsave()
  246. {
  247. int pos = m_combotaoxiname.GetCurSel();
  248. if (pos == -1)return;
  249. CArray<CStringArray, CStringArray>sparray;
  250. sparray.SetSize(m_List1.GetItemCount());
  251. int realcount = 0;
  252. for (int i = 0; i < m_List1.GetItemCount(); i++)
  253. {
  254. if (m_List1.GetItemText(i, 0).IsEmpty())continue;
  255. sparray.ElementAt(realcount).Add(m_List1array.ElementAt(pos).ElementAt(0));
  256. sparray.ElementAt(realcount).Add(m_List1.GetItemText(i, 0));
  257. sparray.ElementAt(realcount).Add(m_List1.GetItemText(i, 2));
  258. realcount++;
  259. }
  260. sparray.SetSize(realcount);
  261. if (realcount == 0)
  262. {
  263. sparray.SetSize(1);
  264. sparray.ElementAt(0).Add(m_List1array.ElementAt(pos).ElementAt(0));
  265. }
  266. CMemFile memfile;
  267. CArchive ar(&memfile, CArchive::store);
  268. for (int ii = 0; ii < sparray.GetSize(); ii++)
  269. {
  270. sparray.ElementAt(ii).Serialize(ar);
  271. }
  272. ar.Close();
  273. int length = memfile.GetLength();
  274. BYTE *pData = memfile.Detach();
  275. int size = sparray.GetSize();
  276. BYTE *pData2 = new BYTE[length + sizeof(int)];
  277. memcpy(pData2, pData, length);
  278. memcpy(pData2 + length, &size, sizeof(int));
  279. delete[]pData;
  280. length += sizeof(int);
  281. g_nSendCode = 1;
  282. g_pMainWnd->ProcessChatMessageRequest2(pData2, length);
  283. g_nSendCode = 0;
  284. delete[]pData2;
  285. if (g_bSendOK == 0)return;
  286. g_sendhead.bsql = 0;
  287. g_sendhead.code[0] = 7;
  288. g_sendhead.code[1] = 10;
  289. g_sendhead.tabcount = 2;
  290. g_pMainWnd->ProcessChatMessageRequest2(7); if (g_bSendOK == 0)return;
  291. DataToArray(&m_List2array, &m_List3array);
  292. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  293. }
  294. void TXSPDlg::OnBUTdel()
  295. {
  296. POSITION pos;
  297. pos = m_List1.GetFirstSelectedItemPosition();
  298. if (pos == NULL)
  299. {
  300. AfxMessageBox("请先选中您要删除的项目!", MB_ICONINFORMATION);
  301. return;
  302. }
  303. int iItem = m_List1.GetNextSelectedItem(pos);
  304. m_List1.DeleteItem(iItem);
  305. int count = m_List1.GetItemCount();
  306. if (count == 0)return;
  307. if (iItem == count)
  308. iItem = 0;
  309. m_List1.SetItemState(iItem, LVIS_SELECTED, LVIS_SELECTED);
  310. }
  311. void TXSPDlg::OnBUTspbox()
  312. {
  313. SPBox dlg;
  314. if (dlg.DoModal() != IDOK)return;
  315. for (int a = 0; a < dlg.m_spidarray.GetSize(); a++)
  316. {
  317. dlg.m_spid = dlg.m_spidarray.ElementAt(a);
  318. dlg.m_spname = dlg.m_spnamearray.ElementAt(a);
  319. dlg.m_lb = dlg.m_lbarray.ElementAt(a);
  320. int pos = m_List1.GetItemCount();
  321. if (pos)
  322. {
  323. if (m_List1.GetItemText(pos - 1, 0).IsEmpty() && m_List1.GetItemText(pos - 1, 1).IsEmpty() && m_List1.GetItemText(pos - 1, 2).IsEmpty())
  324. {
  325. pos--;
  326. m_List1.SetItemText(pos, 0, dlg.m_spid);
  327. m_List1.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
  328. }
  329. else
  330. {
  331. m_List1.InsertItem(pos, dlg.m_spid);
  332. m_List1.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
  333. m_List1.SetItemText(pos, 2, "1");
  334. }
  335. }
  336. else
  337. {
  338. m_List1.InsertItem(pos, dlg.m_spid);
  339. m_List1.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
  340. m_List1.SetItemText(pos, 2, "1");
  341. }
  342. }
  343. }
  344. void TXSPDlg::OnBUTclose()
  345. {
  346. GetParent()->SendMessage(WM_CLOSE);
  347. }
  348. void TXSPDlg::OnBUTsave2()
  349. {
  350. int pos = m_combotaoxiname.GetCurSel();
  351. if (pos == -1)return;
  352. CArray<CStringArray, CStringArray>sparray;
  353. sparray.SetSize(m_List2.GetItemCount());
  354. int realcount = 0;
  355. for (int i = 0; i < m_List2.GetItemCount(); i++)
  356. {
  357. if (m_List2.GetItemText(i, 0).IsEmpty())continue;
  358. sparray.ElementAt(realcount).Add(m_List1array.ElementAt(pos).ElementAt(0));
  359. sparray.ElementAt(realcount).Add(m_List2.GetItemText(i, 0));
  360. sparray.ElementAt(realcount).Add(m_List2.GetItemText(i, 2));
  361. realcount++;
  362. }
  363. sparray.SetSize(realcount);
  364. if (realcount == 0)
  365. {
  366. sparray.SetSize(1);
  367. sparray.ElementAt(0).Add(m_List1array.ElementAt(pos).ElementAt(0));
  368. }
  369. CMemFile memfile;
  370. CArchive ar(&memfile, CArchive::store);
  371. for (int ii = 0; ii < sparray.GetSize(); ii++)
  372. {
  373. sparray.ElementAt(ii).Serialize(ar);
  374. }
  375. ar.Close();
  376. int length = memfile.GetLength();
  377. BYTE *pData = memfile.Detach();
  378. int size = sparray.GetSize();
  379. BYTE *pData2 = new BYTE[length + sizeof(int)];
  380. memcpy(pData2, pData, length);
  381. memcpy(pData2 + length, &size, sizeof(int));
  382. delete[]pData;
  383. length += sizeof(int);
  384. g_nSendCode = 2;
  385. g_pMainWnd->ProcessChatMessageRequest2(pData2, length);
  386. g_nSendCode = 0;
  387. delete[]pData2;
  388. if (g_bSendOK == 0)return;
  389. g_sendhead.bsql = 0;
  390. g_sendhead.code[0] = 7;
  391. g_sendhead.code[1] = 10;
  392. g_sendhead.tabcount = 2;
  393. g_pMainWnd->ProcessChatMessageRequest2(7); if (g_bSendOK == 0)return;
  394. DataToArray(&m_List2array, &m_List3array);
  395. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  396. }
  397. void TXSPDlg::OnBUTdel2()
  398. {
  399. POSITION pos;
  400. pos = m_List2.GetFirstSelectedItemPosition();
  401. if (pos == NULL)
  402. {
  403. AfxMessageBox("请先选中您要删除的项目!", MB_ICONINFORMATION);
  404. return;
  405. }
  406. int iItem = m_List2.GetNextSelectedItem(pos);
  407. m_List2.DeleteItem(iItem);
  408. int count = m_List2.GetItemCount();
  409. if (count == 0)return;
  410. if (iItem == count)
  411. iItem = 0;
  412. m_List2.SetItemState(iItem, LVIS_SELECTED, LVIS_SELECTED);
  413. }
  414. void TXSPDlg::OnBUTspbox2()
  415. {
  416. SPBox dlg;
  417. dlg.m_mode = 1;
  418. if (dlg.DoModal() != IDOK)return;
  419. for (int a = 0; a < dlg.m_spidarray.GetSize(); a++)
  420. {
  421. dlg.m_spid = dlg.m_spidarray.ElementAt(a);
  422. dlg.m_spname = dlg.m_spnamearray.ElementAt(a);
  423. dlg.m_lb = dlg.m_lbarray.ElementAt(a);
  424. int pos = m_List2.GetItemCount();
  425. if (pos)
  426. {
  427. if (m_List2.GetItemText(pos - 1, 0).IsEmpty() && m_List2.GetItemText(pos - 1, 1).IsEmpty() && m_List2.GetItemText(pos - 1, 2).IsEmpty())
  428. {
  429. pos--;
  430. m_List2.SetItemText(pos, 0, dlg.m_spid);
  431. m_List2.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
  432. m_List2.SetItemText(pos, 2, "1");
  433. }
  434. else
  435. {
  436. m_List2.InsertItem(pos, dlg.m_spid);
  437. m_List2.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
  438. m_List2.SetItemText(pos, 2, "1");
  439. }
  440. }
  441. else
  442. {
  443. m_List2.InsertItem(pos, dlg.m_spid);
  444. m_List2.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
  445. m_List2.SetItemText(pos, 2, "1");
  446. }
  447. }
  448. }
  449. void TXSPDlg::OnBUTclose2()
  450. {
  451. GetParent()->SendMessage(WM_CLOSE);
  452. }
  453. void TXSPDlg::OnCbnSelchangeKinds()
  454. {
  455. }
  456. BOOL CALLBACK TXSPDlg::EnumChildProc1(HWND hwnd, LPARAM lParam)
  457. {
  458. CSize sz = (CSize)lParam;
  459. CRect rtCtrl, rtWnd; // 子窗口,父窗口;
  460. if (hwnd)
  461. {
  462. ::GetWindowRect(hwnd, &rtCtrl); // 获取控件大小;
  463. ::GetWindowRect(::GetParent(hwnd), &rtWnd); // 获取父窗口大小;
  464. ((CWnd*)hwnd)->ScreenToClient(rtCtrl);
  465. rtCtrl.left += g_rc.left;
  466. rtCtrl.top += g_rc.top;
  467. rtCtrl.right += sz.cx;
  468. rtCtrl.bottom += sz.cy;
  469. ::MoveWindow(hwnd, rtCtrl.left, rtCtrl.top, rtCtrl.Width(), rtCtrl.Height(), TRUE);
  470. return TRUE;
  471. }
  472. else
  473. {
  474. return FALSE;
  475. }
  476. }
  477. // 从OnSize中可以获取两个坐标:1.原始的, 2.最后的;
  478. // 1.原始的:第一次的Get cx,cy;
  479. // 2.最后的:最后一次Get cx,cy;
  480. void TXSPDlg::OnSize(UINT nType, int cx, int cy)
  481. {
  482. MyFormView::OnSize(nType, cx, cy);
  483. static BOOL bDeal = FALSE;
  484. static CRect FirstRect(g_rc.left, g_rc.top, g_rc.left + cx, g_rc.top + cy); // 移动到g_rc后的原始屏幕坐标;
  485. static CRect LastWindowRect( g_rc.left, g_rc.top, g_rc.right, g_rc.bottom );
  486. if ( bDeal == FALSE)
  487. {
  488. m_rcOld = FirstRect;
  489. bDeal = TRUE;
  490. }
  491. }