TXSPDlg.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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. for (int i = 0; i < m_List2array.GetSize(); i++)
  110. {
  111. if (m_List2array.ElementAt(i).ElementAt(0) != m_taoxiid)continue;
  112. m_List1.InsertItem(pos, m_List2array.ElementAt(i).ElementAt(1));
  113. m_List1.SetItemText(pos, 1, GetSPNameFromId(m_List2array.ElementAt(i).ElementAt(1)));
  114. m_List1.SetItemText(pos, 2, m_List2array.ElementAt(i).ElementAt(2));
  115. pos++;
  116. }
  117. //#ifndef MODERN_VERSION
  118. #if 0
  119. for( i=0; i<m_List3array.GetSize (); i++)
  120. {
  121. if(m_List3array.ElementAt (i).ElementAt (0)!=m_taoxiid)continue;
  122. m_List1.InsertItem(pos, m_List3array.ElementAt (i).ElementAt (1));
  123. m_List1.SetItemText(pos,1, GetSPNameFromId(m_List3array.ElementAt (i).ElementAt (1)));
  124. m_List1.SetItemText(pos,2, m_List3array.ElementAt (i).ElementAt (2));
  125. pos++;
  126. }
  127. #else
  128. m_List2.DeleteAllItems();
  129. pos = 0;
  130. for (i = 0; i < m_List3array.GetSize(); i++)
  131. {
  132. if (m_List3array.ElementAt(i).ElementAt(0) != m_taoxiid)continue;
  133. m_List2.InsertItem(pos, m_List3array.ElementAt(i).ElementAt(1));
  134. m_List2.SetItemText(pos, 1, GetSPNameFromId(m_List3array.ElementAt(i).ElementAt(1)));
  135. m_List2.SetItemText(pos, 2, m_List3array.ElementAt(i).ElementAt(2));
  136. pos++;
  137. }
  138. #endif
  139. }
  140. CString TXSPDlg::GetSPNameFromId(CString id)
  141. {
  142. for (int i = 0; i < m_sparray.GetSize(); i++)
  143. {
  144. if (id == m_sparray.ElementAt(i).ElementAt(0))
  145. return m_sparray.ElementAt(i).ElementAt(1);
  146. }
  147. id.TrimLeft("0");
  148. for (i = 0; i < m_sparray.GetSize(); i++)
  149. {
  150. if (id == m_sparray.ElementAt(i).ElementAt(0))
  151. return m_sparray.ElementAt(i).ElementAt(1);
  152. }
  153. return "";
  154. }
  155. BOOL TXSPDlg::PreTranslateMessage(MSG* pMsg)
  156. {
  157. if (pMsg->message == WM_KEYDOWN)
  158. {
  159. switch (pMsg->wParam)
  160. {
  161. case 0x43: // copy
  162. if ((GetKeyState(VK_CONTROL) & 0x80))
  163. {
  164. GetFocus()->SendMessage(WM_COPY);
  165. return TRUE;
  166. }
  167. break;
  168. case 0x56: //Ctrl + V:
  169. if ((GetKeyState(VK_CONTROL) & 0x80))
  170. {
  171. GetFocus()->SendMessage(WM_PASTE);
  172. return TRUE;
  173. }
  174. break;
  175. case 0x58: // cut
  176. if ((GetKeyState(VK_CONTROL) & 0x80))
  177. {
  178. GetFocus()->SendMessage(WM_CUT);
  179. return TRUE;
  180. }
  181. break;
  182. case 0x5A: //undo
  183. case 0x59: //redo
  184. if ((GetKeyState(VK_CONTROL) & 0x80))
  185. {
  186. GetFocus()->SendMessage(WM_UNDO);
  187. return TRUE;
  188. }
  189. break;
  190. }
  191. }
  192. else if (pMsg->message == WM_LBUTTONDBLCLK)
  193. {
  194. if (0)
  195. {//list1
  196. CPoint pt;
  197. CRect rc, rc2;
  198. ::GetCursorPos(&pt);
  199. m_List1.GetWindowRect(rc2);
  200. if (rc2.PtInRect(pt) == 0) return MyFormView::PreTranslateMessage(pMsg);
  201. pt.x -= rc2.left;
  202. pt.y -= rc2.top;
  203. POSITION pos;
  204. pos = m_List1.GetFirstSelectedItemPosition();
  205. if (pos == NULL)return 1;
  206. int iItem = m_List1.GetNextSelectedItem(pos);
  207. m_List1.GetSubItemRect(iItem, 2, LVIR_BOUNDS, rc);
  208. if (rc.PtInRect(pt))
  209. return MyFormView::PreTranslateMessage(pMsg);
  210. else
  211. return 1;
  212. }
  213. }
  214. return MyFormView::PreTranslateMessage(pMsg);
  215. }
  216. void TXSPDlg::SetSPName1()
  217. {
  218. for (int i = 0; i < m_List1.GetItemCount(); i++)
  219. {
  220. m_List1.SetItemText(i, 1, GetSPNameFromId(m_List1.GetItemText(i, 0)));
  221. }
  222. }
  223. void TXSPDlg::SetSPName2()
  224. {
  225. for (int i = 0; i < m_List2.GetItemCount(); i++)
  226. {
  227. m_List2.SetItemText(i, 1, GetSPNameFromId(m_List2.GetItemText(i, 0)));
  228. }
  229. }
  230. void TXSPDlg::OnTimer(UINT nIDEvent)
  231. {
  232. if (nIDEvent == 1)
  233. {
  234. KillTimer(nIDEvent);
  235. SetSPName1();
  236. }
  237. else if (nIDEvent == 2)
  238. {
  239. KillTimer(nIDEvent);
  240. SetSPName2();
  241. }
  242. }
  243. void TXSPDlg::OnBUTsave()
  244. {
  245. int pos = m_combotaoxiname.GetCurSel();
  246. if (pos == -1)return;
  247. CArray<CStringArray, CStringArray>sparray;
  248. sparray.SetSize(m_List1.GetItemCount());
  249. int realcount = 0;
  250. for (int i = 0; i < m_List1.GetItemCount(); i++)
  251. {
  252. if (m_List1.GetItemText(i, 0).IsEmpty())continue;
  253. sparray.ElementAt(realcount).Add(m_List1array.ElementAt(pos).ElementAt(0));
  254. sparray.ElementAt(realcount).Add(m_List1.GetItemText(i, 0));
  255. sparray.ElementAt(realcount).Add(m_List1.GetItemText(i, 2));
  256. realcount++;
  257. }
  258. sparray.SetSize(realcount);
  259. if (realcount == 0)
  260. {
  261. sparray.SetSize(1);
  262. sparray.ElementAt(0).Add(m_List1array.ElementAt(pos).ElementAt(0));
  263. }
  264. CMemFile memfile;
  265. CArchive ar(&memfile, CArchive::store);
  266. for (int ii = 0; ii < sparray.GetSize(); ii++)
  267. {
  268. sparray.ElementAt(ii).Serialize(ar);
  269. }
  270. ar.Close();
  271. int length = memfile.GetLength();
  272. BYTE *pData = memfile.Detach();
  273. int size = sparray.GetSize();
  274. BYTE *pData2 = new BYTE[length + sizeof(int)];
  275. memcpy(pData2, pData, length);
  276. memcpy(pData2 + length, &size, sizeof(int));
  277. delete[]pData;
  278. length += sizeof(int);
  279. g_nSendCode = 1;
  280. g_pMainWnd->ProcessChatMessageRequest2(pData2, length);
  281. g_nSendCode = 0;
  282. delete[]pData2;
  283. if (g_bSendOK == 0)return;
  284. g_sendhead.bsql = 0;
  285. g_sendhead.code[0] = 7;
  286. g_sendhead.code[1] = 10;
  287. g_sendhead.tabcount = 2;
  288. g_pMainWnd->ProcessChatMessageRequest2(7); if (g_bSendOK == 0)return;
  289. DataToArray(&m_List2array, &m_List3array);
  290. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  291. }
  292. void TXSPDlg::OnBUTdel()
  293. {
  294. POSITION pos;
  295. pos = m_List1.GetFirstSelectedItemPosition();
  296. if (pos == NULL)
  297. {
  298. AfxMessageBox("请先选中您要删除的项目!", MB_ICONINFORMATION);
  299. return;
  300. }
  301. int iItem = m_List1.GetNextSelectedItem(pos);
  302. m_List1.DeleteItem(iItem);
  303. int count = m_List1.GetItemCount();
  304. if (count == 0)return;
  305. if (iItem == count)
  306. iItem = 0;
  307. m_List1.SetItemState(iItem, LVIS_SELECTED, LVIS_SELECTED);
  308. }
  309. void TXSPDlg::OnBUTspbox()
  310. {
  311. SPBox dlg;
  312. if (dlg.DoModal() != IDOK)return;
  313. for (int a = 0; a < dlg.m_spidarray.GetSize(); a++)
  314. {
  315. dlg.m_spid = dlg.m_spidarray.ElementAt(a);
  316. dlg.m_spname = dlg.m_spnamearray.ElementAt(a);
  317. dlg.m_lb = dlg.m_lbarray.ElementAt(a);
  318. int pos = m_List1.GetItemCount();
  319. if (pos)
  320. {
  321. if (m_List1.GetItemText(pos - 1, 0).IsEmpty() && m_List1.GetItemText(pos - 1, 1).IsEmpty() && m_List1.GetItemText(pos - 1, 2).IsEmpty())
  322. {
  323. pos--;
  324. m_List1.SetItemText(pos, 0, dlg.m_spid);
  325. m_List1.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
  326. }
  327. else
  328. {
  329. m_List1.InsertItem(pos, dlg.m_spid);
  330. m_List1.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
  331. m_List1.SetItemText(pos, 2, "1");
  332. }
  333. }
  334. else
  335. {
  336. m_List1.InsertItem(pos, dlg.m_spid);
  337. m_List1.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
  338. m_List1.SetItemText(pos, 2, "1");
  339. }
  340. }
  341. }
  342. void TXSPDlg::OnBUTclose()
  343. {
  344. GetParent()->SendMessage(WM_CLOSE);
  345. }
  346. void TXSPDlg::OnBUTsave2()
  347. {
  348. int pos = m_combotaoxiname.GetCurSel();
  349. if (pos == -1)return;
  350. CArray<CStringArray, CStringArray>sparray;
  351. sparray.SetSize(m_List2.GetItemCount());
  352. int realcount = 0;
  353. for (int i = 0; i < m_List2.GetItemCount(); i++)
  354. {
  355. if (m_List2.GetItemText(i, 0).IsEmpty())continue;
  356. sparray.ElementAt(realcount).Add(m_List1array.ElementAt(pos).ElementAt(0));
  357. sparray.ElementAt(realcount).Add(m_List2.GetItemText(i, 0));
  358. sparray.ElementAt(realcount).Add(m_List2.GetItemText(i, 2));
  359. realcount++;
  360. }
  361. sparray.SetSize(realcount);
  362. if (realcount == 0)
  363. {
  364. sparray.SetSize(1);
  365. sparray.ElementAt(0).Add(m_List1array.ElementAt(pos).ElementAt(0));
  366. }
  367. CMemFile memfile;
  368. CArchive ar(&memfile, CArchive::store);
  369. for (int ii = 0; ii < sparray.GetSize(); ii++)
  370. {
  371. sparray.ElementAt(ii).Serialize(ar);
  372. }
  373. ar.Close();
  374. int length = memfile.GetLength();
  375. BYTE *pData = memfile.Detach();
  376. int size = sparray.GetSize();
  377. BYTE *pData2 = new BYTE[length + sizeof(int)];
  378. memcpy(pData2, pData, length);
  379. memcpy(pData2 + length, &size, sizeof(int));
  380. delete[]pData;
  381. length += sizeof(int);
  382. g_nSendCode = 2;
  383. g_pMainWnd->ProcessChatMessageRequest2(pData2, length);
  384. g_nSendCode = 0;
  385. delete[]pData2;
  386. if (g_bSendOK == 0)return;
  387. g_sendhead.bsql = 0;
  388. g_sendhead.code[0] = 7;
  389. g_sendhead.code[1] = 10;
  390. g_sendhead.tabcount = 2;
  391. g_pMainWnd->ProcessChatMessageRequest2(7); if (g_bSendOK == 0)return;
  392. DataToArray(&m_List2array, &m_List3array);
  393. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  394. }
  395. void TXSPDlg::OnBUTdel2()
  396. {
  397. POSITION pos;
  398. pos = m_List2.GetFirstSelectedItemPosition();
  399. if (pos == NULL)
  400. {
  401. AfxMessageBox("请先选中您要删除的项目!", MB_ICONINFORMATION);
  402. return;
  403. }
  404. int iItem = m_List2.GetNextSelectedItem(pos);
  405. m_List2.DeleteItem(iItem);
  406. int count = m_List2.GetItemCount();
  407. if (count == 0)return;
  408. if (iItem == count)
  409. iItem = 0;
  410. m_List2.SetItemState(iItem, LVIS_SELECTED, LVIS_SELECTED);
  411. }
  412. void TXSPDlg::OnBUTspbox2()
  413. {
  414. SPBox dlg;
  415. dlg.m_mode = 1;
  416. if (dlg.DoModal() != IDOK)return;
  417. for (int a = 0; a < dlg.m_spidarray.GetSize(); a++)
  418. {
  419. dlg.m_spid = dlg.m_spidarray.ElementAt(a);
  420. dlg.m_spname = dlg.m_spnamearray.ElementAt(a);
  421. dlg.m_lb = dlg.m_lbarray.ElementAt(a);
  422. int pos = m_List2.GetItemCount();
  423. if (pos)
  424. {
  425. if (m_List2.GetItemText(pos - 1, 0).IsEmpty() && m_List2.GetItemText(pos - 1, 1).IsEmpty() && m_List2.GetItemText(pos - 1, 2).IsEmpty())
  426. {
  427. pos--;
  428. m_List2.SetItemText(pos, 0, dlg.m_spid);
  429. m_List2.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
  430. m_List2.SetItemText(pos, 2, "1");
  431. }
  432. else
  433. {
  434. m_List2.InsertItem(pos, dlg.m_spid);
  435. m_List2.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
  436. m_List2.SetItemText(pos, 2, "1");
  437. }
  438. }
  439. else
  440. {
  441. m_List2.InsertItem(pos, dlg.m_spid);
  442. m_List2.SetItemText(pos, 1, GetSPNameFromId(dlg.m_spid));
  443. m_List2.SetItemText(pos, 2, "1");
  444. }
  445. }
  446. }
  447. void TXSPDlg::OnBUTclose2()
  448. {
  449. GetParent()->SendMessage(WM_CLOSE);
  450. }
  451. void TXSPDlg::OnCbnSelchangeKinds()
  452. {
  453. }
  454. BOOL CALLBACK TXSPDlg::EnumChildProc1(HWND hwnd, LPARAM lParam)
  455. {
  456. CSize sz = (CSize)lParam;
  457. CRect rtCtrl, rtWnd; // 子窗口,父窗口;
  458. if (hwnd)
  459. {
  460. ::GetWindowRect(hwnd, &rtCtrl); // 获取控件大小;
  461. ::GetWindowRect(::GetParent(hwnd), &rtWnd); // 获取父窗口大小;
  462. ((CWnd*)hwnd)->ScreenToClient(rtCtrl);
  463. rtCtrl.left += g_rc.left;
  464. rtCtrl.top += g_rc.top;
  465. rtCtrl.right += sz.cx;
  466. rtCtrl.bottom += sz.cy;
  467. ::MoveWindow(hwnd, rtCtrl.left, rtCtrl.top, rtCtrl.Width(), rtCtrl.Height(), TRUE);
  468. return TRUE;
  469. }
  470. else
  471. {
  472. return FALSE;
  473. }
  474. }
  475. // 从OnSize中可以获取两个坐标:1.原始的, 2.最后的;
  476. // 1.原始的:第一次的Get cx,cy;
  477. // 2.最后的:最后一次Get cx,cy;
  478. void TXSPDlg::OnSize(UINT nType, int cx, int cy)
  479. {
  480. MyFormView::OnSize(nType, cx, cy);
  481. static BOOL bDeal = FALSE;
  482. static CRect FirstRect(g_rc.left, g_rc.top, g_rc.left + cx, g_rc.top + cy); // 移动到g_rc后的原始屏幕坐标;
  483. static CRect LastWindowRect( g_rc.left, g_rc.top, g_rc.right, g_rc.bottom );
  484. if ( bDeal == FALSE)
  485. {
  486. m_rcOld = FirstRect;
  487. bDeal = TRUE;
  488. }
  489. }