SPBox.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. // SPBox.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "SPBox.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // SPBox dialog
  13. SPBox::SPBox(CWnd* pParent /*=NULL*/)
  14. : CDialog(SPBox::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(SPBox)
  17. m_filter = _T("");
  18. //}}AFX_DATA_INIT
  19. m_mode = 0;
  20. m_badmin = 0;
  21. }
  22. void SPBox::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(SPBox)
  26. DDX_Control(pDX, IDC_LIST1, m_listbox1);
  27. DDX_Control(pDX, IDC_LIST2, m_List1);
  28. DDX_Control(pDX, IDC_COMBOsplb, m_combosplb);
  29. DDX_Text(pDX, IDC_EDIT1, m_filter);
  30. //}}AFX_DATA_MAP
  31. }
  32. BEGIN_MESSAGE_MAP(SPBox, CDialog)
  33. //{{AFX_MSG_MAP(SPBox)
  34. ON_CBN_SELCHANGE(IDC_COMBOsplb, OnSelchangeCOMBOsplb)
  35. ON_NOTIFY(NM_DBLCLK, IDC_LIST2, OnDblclkList2)
  36. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  37. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  38. ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // SPBox message handlers
  43. BOOL SPBox::OnInitDialog()
  44. {
  45. CDialog::OnInitDialog();
  46. // TODO: Add extra initialization here
  47. // m_badmin=IsHasRights2new(49);
  48. if (m_badmin)
  49. m_List1.SetHeadings("编号,50;商品名称,150;成本价,80;销售价,80");
  50. else
  51. m_List1.SetHeadings("编号,50;商品名称,150;销售价,80");
  52. m_List1.LoadColumnInfo(103);
  53. CString filter = "hide<>'下架' or hide is null;";
  54. g_sendhead.bsql = 0;
  55. g_sendhead.code[0] = 8;
  56. g_sendhead.code[1] = 2;
  57. g_sendhead.tabcount = 2;
  58. g_pMainWnd->ProcessChatMessageRequest2(filter); if (g_bSendOK == 0)return 1;
  59. DataToArray(&m_List1array, &m_List2array);
  60. CString strRes1;
  61. if (m_badmin == 0)
  62. {
  63. for (int i = 0; i < m_List1array.GetSize(); i++)
  64. {
  65. m_List1array.ElementAt(i).RemoveAt(2);
  66. ChinesePinYin::GetFirstLetter(m_List1array.ElementAt(i).ElementAt(1), strRes1);
  67. m_List1array.ElementAt(i).InsertAt(3, strRes1);
  68. }
  69. }
  70. else
  71. {
  72. for (int i = 0; i < m_List1array.GetSize(); i++)
  73. {
  74. ChinesePinYin::GetFirstLetter(m_List1array.ElementAt(i).ElementAt(1), strRes1);
  75. m_List1array.ElementAt(i).InsertAt(4, strRes1);
  76. }
  77. }
  78. if (m_mode)
  79. {
  80. m_combosplb.AddString("婚庆服务");
  81. }
  82. else
  83. {
  84. for (int i = 0; i < m_List2array.GetSize(); i++)
  85. m_combosplb.AddString(m_List2array.ElementAt(i).ElementAt(0));
  86. }
  87. if (m_combosplb.GetCount())
  88. m_combosplb.SetCurSel(0);
  89. OnSelchangeCOMBOsplb();
  90. this->CenterWindow(g_pMainWnd);
  91. m_combosplb.SetFocus();
  92. return false; // return TRUE unless you set the focus to a control
  93. // EXCEPTION: OCX Property Pages should return FALSE
  94. }
  95. void SPBox::OnCancel()
  96. {
  97. // TODO: Add extra cleanup here
  98. CDialog::OnCancel();
  99. }
  100. void SPBox::OnOK()
  101. {
  102. // TODO: Add extra validation here
  103. /* int pos=m_combosplb.GetCurSel ();
  104. if(pos==-1)return;
  105. m_combosplb.GetLBText (pos, m_lb);*/
  106. //if(m_mode==0)
  107. {
  108. POSITION pos;
  109. pos = m_List1.GetFirstSelectedItemPosition();
  110. if (pos == NULL)
  111. {
  112. AfxMessageBox("请先选中一个商品!");
  113. return;
  114. }
  115. int iItem = m_List1.GetNextSelectedItem(pos);
  116. m_spid = m_List1.GetItemText(iItem, 0);
  117. m_spname = m_List1.GetItemText(iItem, 1);
  118. }
  119. CDialog::OnOK();
  120. }
  121. void SPBox::OnSelchangeCOMBOsplb()
  122. {
  123. // TODO: Add your control notification handler code here
  124. int pos = m_combosplb.GetCurSel();
  125. if (pos == -1)return;
  126. CString str;
  127. m_combosplb.GetLBText(pos, str);
  128. FillGrid(str);
  129. }
  130. void SPBox::FillGrid(CString str)
  131. {
  132. UpdateData();
  133. m_filter.MakeUpper();
  134. if (m_filter != "")m_combosplb.SetCurSel(-1);
  135. m_List1.DeleteAllItems2();
  136. int ii = 0;
  137. m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1);
  138. int count = 0;
  139. if (m_badmin)
  140. {
  141. if (m_filter == "")
  142. {
  143. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  144. {
  145. if (m_List1array.ElementAt(ii).ElementAt(5) == str)
  146. {
  147. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  148. }
  149. }
  150. }
  151. else
  152. {
  153. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  154. {
  155. if (m_List1array.ElementAt(ii).ElementAt(1).Find(m_filter) != -1 || \
  156. m_List1array.ElementAt(ii).ElementAt(2).Find(m_filter) != -1 || \
  157. m_List1array.ElementAt(ii).ElementAt(3).Find(m_filter) != -1 || \
  158. m_List1array.ElementAt(ii).ElementAt(4).Find(m_filter) != -1 || \
  159. m_List1array.ElementAt(ii).ElementAt(5).Find(m_filter) != -1)
  160. {
  161. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  162. }
  163. }
  164. }
  165. }
  166. else
  167. {
  168. if (m_filter == "")
  169. {
  170. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  171. {
  172. if (m_List1array.ElementAt(ii).ElementAt(4) == str)
  173. {
  174. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  175. }
  176. }
  177. }
  178. else
  179. {
  180. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  181. {
  182. if (m_List1array.ElementAt(ii).ElementAt(1).Find(m_filter) != -1 || \
  183. m_List1array.ElementAt(ii).ElementAt(2).Find(m_filter) != -1 || \
  184. m_List1array.ElementAt(ii).ElementAt(3).Find(m_filter) != -1 || \
  185. m_List1array.ElementAt(ii).ElementAt(4).Find(m_filter) != -1)
  186. {
  187. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  188. }
  189. }
  190. }
  191. }
  192. m_List1.m_arLabels.SetSize(count, 1);
  193. ii = count;
  194. m_List1.m_LabelCount = ii;
  195. m_List1.SetItemCountEx(ii);
  196. }
  197. void SPBox::OnDblclkList2(NMHDR* pNMHDR, LRESULT* pResult)
  198. {
  199. // TODO: Add your control notification handler code here
  200. OnButton1();
  201. *pResult = 0;
  202. }
  203. void SPBox::OnButton1()
  204. {
  205. // TODO: Add your control notification handler code here
  206. /* {
  207. int pos=m_combosplb.GetCurSel ();
  208. if(pos==-1)return;
  209. m_combosplb.GetLBText (pos, m_lb);
  210. }*/
  211. POSITION pos;
  212. pos = m_List1.GetFirstSelectedItemPosition();
  213. if (pos == NULL)
  214. {
  215. return;
  216. }
  217. int iItem = m_List1.GetNextSelectedItem(pos);
  218. m_spid = m_List1.GetItemText(iItem, 0);
  219. for (int i = 0; i < m_List1array.GetSize(); i++)
  220. {
  221. if (m_spid == m_List1array.ElementAt(i).ElementAt(0))
  222. {
  223. m_lb = m_List1array.ElementAt(i).ElementAt(4); break;
  224. }
  225. }
  226. m_spname = m_List1.GetItemText(iItem, 1);
  227. m_spidarray.Add(m_spid);
  228. m_spnamearray.Add(m_spname);
  229. m_lbarray.Add(m_lb);
  230. m_listbox1.AddString(m_spname);
  231. }
  232. void SPBox::OnButton2()
  233. {
  234. // TODO: Add your control notification handler code here
  235. int pos = m_listbox1.GetCurSel();
  236. if (pos == -1)return;
  237. m_spidarray.RemoveAt(pos);
  238. m_spnamearray.RemoveAt(pos);
  239. m_lbarray.RemoveAt(pos);
  240. m_listbox1.DeleteString(pos);
  241. if (pos == m_listbox1.GetCount() && pos)
  242. m_listbox1.SetCurSel(0);
  243. else if (m_listbox1.GetCount())
  244. m_listbox1.SetCurSel(pos);
  245. }
  246. void SPBox::OnButton3()
  247. {
  248. // TODO: Add your control notification handler code here
  249. UpdateData();
  250. m_filter.TrimLeft();
  251. m_filter.TrimRight();
  252. if (m_filter == "")
  253. {
  254. OnSelchangeCOMBOsplb();
  255. return;
  256. }
  257. FillGrid("");
  258. }