ShangPin.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. // ShangPin.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "ShangPin.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. /////////////////////////////////////////////////////////////////////////////
  13. // ShangPin IDC_COMBOsplb
  14. IMPLEMENT_DYNCREATE(ShangPin, MyFormView)
  15. ShangPin::ShangPin()
  16. : MyFormView(ShangPin::IDD)
  17. {
  18. //{{AFX_DATA_INIT(ShangPin)
  19. m_spbz = _T("");
  20. m_spdanwei = _T("");
  21. m_spid = _T("");
  22. m_spjiaga1 = _T("");
  23. m_spjiage2 = _T("");
  24. m_spname = _T("");
  25. m_spjiage3 = _T("");
  26. m_autoid=0;
  27. m_radio1 = 0;
  28. //}}AFX_DATA_INIT
  29. }
  30. ShangPin::~ShangPin()
  31. {
  32. }
  33. void ShangPin::DoDataExchange(CDataExchange* pDX)
  34. {
  35. MyFormView::DoDataExchange(pDX);
  36. //{{AFX_DATA_MAP(ShangPin)
  37. DDX_Control(pDX, IDC_COMBOstatus, m_combostatus);
  38. DDX_Control(pDX, IDC_EDITspjiage3, m_editctrl3);
  39. DDX_Control(pDX, IDC_EDITspjiage2, m_editctrl2);
  40. DDX_Control(pDX, IDC_EDITspjiaga1, m_editctrl1);
  41. DDX_Control(pDX, IDC_COMBOsplb, m_combosplb);
  42. DDX_Control(pDX, IDC_LIST2, m_List1);
  43. DDX_Control(pDX, IDC_STATIC1, m_static1);
  44. DDX_Text(pDX, IDC_EDITspbz, m_spbz);
  45. DDV_MaxChars(pDX, m_spbz, 1000);
  46. DDX_Text(pDX, IDC_EDITspdanwei, m_spdanwei);
  47. DDX_Text(pDX, IDC_EDITspid, m_spid);
  48. DDX_Text(pDX, IDC_EDITspjiaga1, m_spjiaga1);
  49. DDX_Text(pDX, IDC_EDITspjiage2, m_spjiage2);
  50. DDX_Text(pDX, IDC_EDITspname, m_spname);
  51. DDX_Text(pDX, IDC_EDITspjiage3, m_spjiage3);
  52. DDX_Radio(pDX, IDC_RADIO1, m_radio1);
  53. //}}AFX_DATA_MAP
  54. }
  55. BEGIN_MESSAGE_MAP(ShangPin, MyFormView)
  56. //{{AFX_MSG_MAP(ShangPin)
  57. ON_BN_CLICKED(IDC_BUTsave, OnBUTsave)
  58. ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
  59. ON_BN_CLICKED(IDC_BUTclose, OnBUTclose)
  60. ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2)
  61. ON_BN_CLICKED(IDC_BUTadd, OnBUTadd)
  62. ON_CBN_SELCHANGE(IDC_COMBOsplb, OnSelchangeCOMBOsplb)
  63. ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
  64. ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
  65. ON_BN_CLICKED(IDC_RADIO9, OnRadio9)
  66. //}}AFX_MSG_MAP
  67. END_MESSAGE_MAP()
  68. /////////////////////////////////////////////////////////////////////////////
  69. // ShangPin diagnostics
  70. #ifdef _DEBUG
  71. void ShangPin::AssertValid() const
  72. {
  73. MyFormView::AssertValid();
  74. }
  75. void ShangPin::Dump(CDumpContext& dc) const
  76. {
  77. MyFormView::Dump(dc);
  78. }
  79. #endif //_DEBUG
  80. /////////////////////////////////////////////////////////////////////////////
  81. // ShangPin message handlers
  82. void ShangPin::OnInitialUpdate()
  83. {
  84. MyFormView::OnInitialUpdate();
  85. // TODO: Add your specialized code here and/or call the base class
  86. if(IsHasRights2new(29)==0)
  87. {
  88. GetDlgItem(IDC_BUTsave)->EnableWindow(0);
  89. }
  90. CMyMdi Mdi;
  91. Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this);
  92. // Here we create the outbar control using the splitter as its parent
  93. // and setting its id to the first pane.
  94. CRect rc2;
  95. GetWindowRect(rc2);
  96. ::MoveWindow(m_hWnd,g_rc.left,g_rc.top,g_rc.Width(),g_rc.Height(),TRUE);
  97. EnumChildWindows(m_hWnd,(WNDENUMPROC)EnumChildProc,0);
  98. m_combosplb.GetWindowRect (rc2);
  99. ScreenToClient(rc2);
  100. rc2.bottom +=200;
  101. m_combosplb.MoveWindow (rc2);
  102. m_combostatus.GetWindowRect (rc2);
  103. ScreenToClient(rc2);
  104. rc2.bottom +=200;
  105. m_combostatus.MoveWindow (rc2);
  106. m_combostatus.AddString("上架");
  107. m_combostatus.AddString("下架");
  108. m_static1.SetFont (&g_titlefont);
  109. m_List1.SetHeadings( "编号, 50;商品名称, 100;单位, 50;进价, 50;卖价, 50;制作费用,80;商品分类, 100;状态,100" );
  110. m_List1.LoadColumnInfo (100);
  111. g_sendhead.bsql=0;
  112. g_sendhead.code[0]=2;
  113. g_sendhead.code[1]=4;
  114. g_sendhead.tabcount=2;
  115. g_pMainWnd->ProcessChatMessageRequest2(2);if(g_bSendOK==0)return;
  116. DataToArray(&g_List1array, &m_List1array);
  117. if(IsHasRights2new(29)==0)
  118. {
  119. for(int i=0; i<m_List1array.GetSize (); i++)
  120. {
  121. m_List1array.ElementAt (i).SetAt (3, "***");
  122. m_List1array.ElementAt (i).SetAt (4, "***");
  123. m_List1array.ElementAt (i).SetAt (5, "***");
  124. }
  125. }
  126. for(int i=0; i<g_List1array.GetSize (); i++)
  127. m_combosplb.AddString (g_List1array.ElementAt (i).ElementAt (0));
  128. }
  129. void ShangPin::OnSelchangeCOMBOsplb()
  130. {
  131. // TODO: Add your control notification handler code here
  132. int pos=m_combosplb.GetCurSel ();
  133. if(pos==-1)return;
  134. CString str;
  135. m_combosplb.GetLBText (pos, str);
  136. FillGrid(str);
  137. }
  138. void ShangPin::FillGrid(CString str)
  139. {
  140. UpdateData();
  141. m_List1.DeleteAllItems2 ();
  142. int ii=0;
  143. m_List1.m_arLabels.SetSize( m_List1array.GetSize (), 1 );
  144. int count=0;
  145. if(m_radio1==2)
  146. {
  147. for(ii=0; ii<m_List1.m_arLabels.GetSize (); ii++)
  148. {
  149. if(m_List1array.ElementAt (ii).ElementAt (6)==str)
  150. {
  151. m_List1.m_arLabels.ElementAt (count++).Copy (m_List1array.ElementAt (ii));
  152. }
  153. }
  154. }
  155. else if(m_radio1==0)
  156. {
  157. for(ii=0; ii<m_List1.m_arLabels.GetSize (); ii++)
  158. {
  159. if(m_List1array.ElementAt (ii).ElementAt (6)==str && m_List1array.ElementAt (ii).ElementAt (7)!="下架")
  160. {
  161. m_List1.m_arLabels.ElementAt (count++).Copy (m_List1array.ElementAt (ii));
  162. }
  163. }
  164. }
  165. else
  166. {
  167. for(ii=0; ii<m_List1.m_arLabels.GetSize (); ii++)
  168. {
  169. if(m_List1array.ElementAt (ii).ElementAt (6)==str && m_List1array.ElementAt (ii).ElementAt (7)=="下架")
  170. {
  171. m_List1.m_arLabels.ElementAt (count++).Copy (m_List1array.ElementAt (ii));
  172. }
  173. }
  174. }
  175. m_List1.m_arLabels.SetSize(count, 1);
  176. ii=count;
  177. m_List1.m_LabelCount=ii;
  178. m_List1.SetItemCountEx (ii);
  179. OnBUTadd() ;
  180. }
  181. void ShangPin::OnBUTclose()
  182. {
  183. // TODO: Add your control notification handler code here
  184. GetParent()->SendMessage(WM_CLOSE);
  185. }
  186. void ShangPin::ClearCtrl()
  187. {
  188. m_spbz = _T("");
  189. m_spdanwei = _T("");
  190. m_spjiaga1 = _T("");
  191. m_spjiage2 = _T("");
  192. m_spjiage3 = _T("");
  193. m_spname = _T("");
  194. UpdateData(false);
  195. AutoId();
  196. }
  197. void ShangPin::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
  198. {
  199. // TODO: Add your control notification handler code here
  200. ListSelChange();
  201. *pResult = 0;
  202. }
  203. void ShangPin::ListSelChange()
  204. {
  205. POSITION pos;
  206. pos=m_List1.GetFirstSelectedItemPosition();
  207. if(pos==NULL)
  208. {OnBUTadd();
  209. return;
  210. }
  211. int iItem=m_List1.GetNextSelectedItem(pos);
  212. m_oldspid=m_List1.GetItemText (iItem, 0);
  213. for(int ii=0; ii<m_List1array.GetSize (); ii++)
  214. {
  215. if(m_List1array.ElementAt (ii).ElementAt (0)==m_oldspid)
  216. {
  217. m_spid = m_List1array.ElementAt (ii).ElementAt (0);
  218. m_spname = m_List1array.ElementAt (ii).ElementAt (1);
  219. m_spdanwei = m_List1array.ElementAt (ii).ElementAt (2);
  220. m_spjiaga1 = m_List1array.ElementAt (ii).ElementAt (3);
  221. m_spjiage2 = m_List1array.ElementAt (ii).ElementAt (4);
  222. m_spjiage3 = m_List1array.ElementAt (ii).ElementAt (5);
  223. m_spbz = m_List1array.ElementAt (ii).ElementAt (8);
  224. CString status = m_List1array.ElementAt (ii).ElementAt (7);
  225. m_combostatus.SetCurSel(m_combostatus.FindString(0, status));
  226. UpdateData(false);
  227. return;
  228. }
  229. }
  230. }
  231. void ShangPin::OnBUTadd()
  232. {
  233. // TODO: Add your control notification handler code here
  234. m_oldspid.Empty ();
  235. ClearCtrl();
  236. }
  237. void ShangPin::OnBUTsave()
  238. {
  239. // TODO: Add your control notification handler code here
  240. UpdateData();
  241. m_spname.TrimRight();
  242. if(m_spid.IsEmpty () || m_spname.IsEmpty () || m_spjiaga1.IsEmpty () || m_spjiage2.IsEmpty ())
  243. {
  244. AfxMessageBox("资料不全!", MB_ICONINFORMATION);return;
  245. }
  246. if(m_spname.Find("/")!=-1)
  247. {
  248. AfxMessageBox("产品名称中请不要包含以下字符 /\\:*?\"<>|", MB_ICONINFORMATION);return;
  249. }
  250. if(m_spname.Find("\\")!=-1)
  251. {
  252. AfxMessageBox("产品名称中请不要包含以下字符 /\\:*?\"<>|", MB_ICONINFORMATION);return;
  253. }
  254. if(m_spname.Find(":")!=-1)
  255. {
  256. AfxMessageBox("产品名称中请不要包含以下字符 /\\:*?\"<>|", MB_ICONINFORMATION);return;
  257. }
  258. if(m_spname.Find("*")!=-1)
  259. {
  260. AfxMessageBox("产品名称中请不要包含以下字符 /\\:*?\"<>|", MB_ICONINFORMATION);return;
  261. }
  262. if(m_spname.Find("?")!=-1)
  263. {
  264. AfxMessageBox("产品名称中请不要包含以下字符 /\\:*?\"<>|", MB_ICONINFORMATION);return;
  265. }
  266. if(m_spname.Find("\"")!=-1)
  267. {
  268. AfxMessageBox("产品名称中请不要包含以下字符 /\\:*?\"<>|", MB_ICONINFORMATION);return;
  269. }
  270. if(m_spname.Find("<")!=-1)
  271. {
  272. AfxMessageBox("产品名称中请不要包含以下字符 /\\:*?\"<>|", MB_ICONINFORMATION);return;
  273. }
  274. if(m_spname.Find(">")!=-1)
  275. {
  276. AfxMessageBox("产品名称中请不要包含以下字符 /\\:*?\"<>|", MB_ICONINFORMATION);return;
  277. }
  278. if(m_spname.Find("|")!=-1)
  279. {
  280. AfxMessageBox("产品名称中请不要包含以下字符 /\\:*?\"<>|", MB_ICONINFORMATION);return;
  281. }
  282. CString sql;
  283. CString splb;
  284. int pos=m_combosplb.GetCurSel ();
  285. if(pos==-1)return;
  286. m_combosplb.GetLBText (pos, splb);
  287. CString status;
  288. pos=m_combostatus.GetCurSel ();
  289. if(pos==-1)
  290. {AfxMessageBox("资料不全!", MB_ICONINFORMATION);
  291. return;
  292. }
  293. m_combostatus.GetLBText (pos, status);
  294. if(m_oldspid.IsEmpty ())//新增
  295. {
  296. if(IsExist())
  297. {
  298. AfxMessageBox("已有此商品记录,请重新输入!", MB_ICONINFORMATION);
  299. return;
  300. }
  301. sql.Format ("insert into shangpin(spid,spname,spdanwei,spjiaga1,spjiage2,spjiage3,splb,spbz,hide)values('%s','%s','%s','%s','%s','%s','%s','%s','%s')",
  302. m_spid,m_spname,m_spdanwei,m_spjiaga1,m_spjiage2,m_spjiage3,splb,m_spbz,status);
  303. g_sendhead.bsql=1;
  304. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  305. GetData();
  306. OnSelchangeCOMBOsplb();
  307. m_autoid++;
  308. }
  309. else//修改
  310. {
  311. if(m_oldspid!=m_spid)
  312. {
  313. if(IsExist())
  314. {
  315. AfxMessageBox("已有此商品记录,请重新输入!", MB_ICONINFORMATION);
  316. return;
  317. }
  318. }
  319. sql.Format ("update shangpin set spid='%s',spname='%s',spdanwei='%s',spjiaga1='%s',spjiage2='%s',spjiage3='%s',splb='%s',spbz='%s',hide='%s' where spid='%s' ", m_spid,m_spname,m_spdanwei,m_spjiaga1,m_spjiage2,m_spjiage3,splb,m_spbz,status, (m_oldspid));
  320. g_sendhead.bsql=1;
  321. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  322. GetData();
  323. OnSelchangeCOMBOsplb();
  324. }
  325. OnBUTadd();
  326. }
  327. void ShangPin::OnBUTdel()
  328. {
  329. // TODO: Add your control notification handler code here
  330. POSITION pos;
  331. pos=m_List1.GetFirstSelectedItemPosition();
  332. if(pos==NULL)
  333. {
  334. return;
  335. }
  336. if(AfxMessageBox("确认删除该产品吗?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return;
  337. int iItem=m_List1.GetNextSelectedItem(pos);
  338. CString id=m_List1.GetItemText (iItem, 0);
  339. CString sql;
  340. sql.Format ("delete from shangpin where spid='%s' ",id);
  341. g_sendhead.bsql=1;
  342. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  343. GetData();
  344. OnSelchangeCOMBOsplb();
  345. }
  346. void ShangPin::GetData()
  347. {
  348. g_sendhead.bsql=0;
  349. g_sendhead.code[0]=4;
  350. g_sendhead.tabcount=1;
  351. g_pMainWnd->ProcessChatMessageRequest2(4);if(g_bSendOK==0)return;
  352. DataToArray(&m_List1array);
  353. }
  354. BOOL ShangPin::IsExist()
  355. {
  356. for(int i=0; i<m_List1array.GetSize (); i++)
  357. {
  358. if(m_spname==m_List1array.ElementAt (i).ElementAt (1))
  359. {
  360. CString str;
  361. str.Format("此产品已存在于类别:%s中", m_List1array.ElementAt (i).ElementAt (6));
  362. AfxMessageBox(str, MB_ICONINFORMATION);
  363. return 1;
  364. }
  365. }
  366. return 0;
  367. }
  368. BOOL ShangPin::PreTranslateMessage(MSG* pMsg)
  369. {
  370. // TODO: Add your specialized code here and/or call the base class
  371. try
  372. {
  373. if(pMsg->message==WM_KEYDOWN)
  374. {
  375. switch (pMsg->wParam)
  376. {
  377. case 0x43: // copy
  378. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  379. {
  380. GetFocus()->SendMessage(WM_COPY);
  381. return TRUE;
  382. }
  383. break;
  384. case 0x56: //Ctrl + V:
  385. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  386. {
  387. GetFocus()->SendMessage(WM_PASTE);
  388. return TRUE;
  389. }
  390. break;
  391. case 0x58: // cut
  392. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  393. {
  394. GetFocus()->SendMessage(WM_CUT);
  395. return TRUE;
  396. }
  397. break;
  398. case 0x5A: //undo
  399. case 0x59: //redo
  400. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  401. {
  402. GetFocus()->SendMessage(WM_UNDO);
  403. return TRUE;
  404. }
  405. break;
  406. }
  407. }
  408. return MyFormView::PreTranslateMessage(pMsg);
  409. }
  410. catch(...)
  411. {
  412. }
  413. }
  414. void ShangPin::AutoId()
  415. {
  416. UpdateData();
  417. int pos=m_combosplb.GetCurSel ();
  418. if(pos==-1)return;
  419. CString type;
  420. m_combosplb.GetLBText (pos, type);
  421. CString strRes1;
  422. GetFirstLetter(type, strRes1);
  423. int begin=1;
  424. BOOL bFind=1;
  425. while(bFind)
  426. {
  427. m_spid.Format ("%s%03d", strRes1, begin++);
  428. for(int i=0; i< m_List1array.GetSize (); i++)
  429. {
  430. if(m_spid==m_List1array.ElementAt (i).ElementAt (0))
  431. {
  432. break;
  433. }
  434. }
  435. if(i==m_List1array.GetSize ())bFind=0;
  436. }
  437. UpdateData(false);
  438. }
  439. void ShangPin::OnRadio1()
  440. {
  441. // TODO: Add your control notification handler code here
  442. OnSelchangeCOMBOsplb();
  443. }
  444. void ShangPin::OnRadio2()
  445. {
  446. // TODO: Add your control notification handler code here
  447. OnSelchangeCOMBOsplb();
  448. }
  449. void ShangPin::OnRadio9()
  450. {
  451. // TODO: Add your control notification handler code here
  452. OnSelchangeCOMBOsplb();
  453. }