ShangPin.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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. {
  209. OnBUTadd();
  210. return;
  211. }
  212. int iItem = m_List1.GetNextSelectedItem(pos);
  213. m_oldspid = m_List1.GetItemText(iItem, 0);
  214. for (int ii = 0; ii < m_List1array.GetSize(); ii++)
  215. {
  216. if (m_List1array.ElementAt(ii).ElementAt(0) == m_oldspid)
  217. {
  218. m_spid = m_List1array.ElementAt(ii).ElementAt(0);
  219. m_spname = m_List1array.ElementAt(ii).ElementAt(1);
  220. m_spdanwei = m_List1array.ElementAt(ii).ElementAt(2);
  221. m_spjiaga1 = m_List1array.ElementAt(ii).ElementAt(3);
  222. m_spjiage2 = m_List1array.ElementAt(ii).ElementAt(4);
  223. m_spjiage3 = m_List1array.ElementAt(ii).ElementAt(5);
  224. m_spbz = m_List1array.ElementAt(ii).ElementAt(8);
  225. CString status = m_List1array.ElementAt(ii).ElementAt(7);
  226. m_combostatus.SetCurSel(m_combostatus.FindString(0, status));
  227. UpdateData(false);
  228. return;
  229. }
  230. }
  231. }
  232. void ShangPin::OnBUTadd()
  233. {
  234. // TODO: Add your control notification handler code here
  235. m_oldspid.Empty();
  236. ClearCtrl();
  237. }
  238. void ShangPin::OnBUTsave() // 保存按钮;
  239. {
  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. {
  291. AfxMessageBox("资料不全!", MB_ICONINFORMATION);
  292. return;
  293. }
  294. m_combostatus.GetLBText(pos, status);
  295. if (m_oldspid.IsEmpty())//新增
  296. {
  297. if (IsExist())
  298. {
  299. AfxMessageBox("已有此商品记录,请重新输入!", MB_ICONINFORMATION);
  300. return;
  301. }
  302. sql.Format("insert into shangpin(spid,spname,spdanwei,spjiaga1,spjiage2,spjiage3,splb,spbz,hide)values('%s','%s','%s','%s','%s','%s','%s','%s','%s')",
  303. m_spid, m_spname, m_spdanwei, m_spjiaga1, m_spjiage2, m_spjiage3, splb, m_spbz, status);
  304. g_sendhead.bsql = 1;
  305. g_pMainWnd->ProcessChatMessageRequest2(sql);
  306. if (g_bSendOK == 0)return;
  307. GetData();
  308. OnSelchangeCOMBOsplb();
  309. m_autoid++;
  310. }
  311. else//修改
  312. {
  313. if (m_oldspid != m_spid)
  314. {
  315. if (IsExist())
  316. {
  317. AfxMessageBox("已有此商品记录,请重新输入!", MB_ICONINFORMATION);
  318. return;
  319. }
  320. }
  321. 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));
  322. g_sendhead.bsql = 1;
  323. g_pMainWnd->ProcessChatMessageRequest2(sql);
  324. if (g_bSendOK == 0)return;
  325. GetData();
  326. OnSelchangeCOMBOsplb();
  327. }
  328. OnBUTadd();
  329. }
  330. void ShangPin::OnBUTdel()
  331. {
  332. POSITION pos;
  333. pos = m_List1.GetFirstSelectedItemPosition();
  334. if (pos == NULL)
  335. {
  336. return;
  337. }
  338. if (AfxMessageBox("确认删除该产品吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  339. int iItem = m_List1.GetNextSelectedItem(pos);
  340. CString id = m_List1.GetItemText(iItem, 0);
  341. CString sql;
  342. sql.Format("delete from shangpin where spid='%s' ", id);
  343. g_sendhead.bsql = 1;
  344. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  345. GetData();
  346. OnSelchangeCOMBOsplb();
  347. }
  348. void ShangPin::GetData()
  349. {
  350. g_sendhead.bsql = 0;
  351. g_sendhead.code[0] = 4;
  352. g_sendhead.tabcount = 1;
  353. g_pMainWnd->ProcessChatMessageRequest2(4); if (g_bSendOK == 0)return;
  354. DataToArray(&m_List1array);
  355. }
  356. BOOL ShangPin::IsExist()
  357. {
  358. for (int i = 0; i < m_List1array.GetSize(); i++)
  359. {
  360. if (m_spname == m_List1array.ElementAt(i).ElementAt(1))
  361. {
  362. CString str;
  363. str.Format("此产品已存在于类别:%s中", m_List1array.ElementAt(i).ElementAt(6));
  364. AfxMessageBox(str, MB_ICONINFORMATION);
  365. return 1;
  366. }
  367. }
  368. return 0;
  369. }
  370. BOOL ShangPin::PreTranslateMessage(MSG* pMsg)
  371. {
  372. // TODO: Add your specialized code here and/or call the base class
  373. try
  374. {
  375. if (pMsg->message == WM_KEYDOWN)
  376. {
  377. switch (pMsg->wParam)
  378. {
  379. case 0x43: // copy
  380. if ((GetKeyState(VK_CONTROL) & 0x80))
  381. {
  382. GetFocus()->SendMessage(WM_COPY);
  383. return TRUE;
  384. }
  385. break;
  386. case 0x56: //Ctrl + V:
  387. if ((GetKeyState(VK_CONTROL) & 0x80))
  388. {
  389. GetFocus()->SendMessage(WM_PASTE);
  390. return TRUE;
  391. }
  392. break;
  393. case 0x58: // cut
  394. if ((GetKeyState(VK_CONTROL) & 0x80))
  395. {
  396. GetFocus()->SendMessage(WM_CUT);
  397. return TRUE;
  398. }
  399. break;
  400. case 0x5A: //undo
  401. case 0x59: //redo
  402. if ((GetKeyState(VK_CONTROL) & 0x80))
  403. {
  404. GetFocus()->SendMessage(WM_UNDO);
  405. return TRUE;
  406. }
  407. break;
  408. }
  409. }
  410. return MyFormView::PreTranslateMessage(pMsg);
  411. }
  412. catch (...)
  413. {
  414. }
  415. }
  416. void ShangPin::AutoId()
  417. {
  418. UpdateData();
  419. int pos = m_combosplb.GetCurSel();
  420. if (pos == -1)return;
  421. CString type;
  422. m_combosplb.GetLBText(pos, type);
  423. CString strRes1;
  424. GetFirstLetter(type, strRes1);
  425. int begin = 1;
  426. BOOL bFind = 1;
  427. while (bFind)
  428. {
  429. m_spid.Format("%s%03d", strRes1, begin++);
  430. for (int i = 0; i < m_List1array.GetSize(); i++)
  431. {
  432. if (m_spid == m_List1array.ElementAt(i).ElementAt(0))
  433. {
  434. break;
  435. }
  436. }
  437. if (i == m_List1array.GetSize())bFind = 0;
  438. }
  439. UpdateData(false);
  440. }
  441. void ShangPin::OnRadio1()
  442. {
  443. // TODO: Add your control notification handler code here
  444. OnSelchangeCOMBOsplb();
  445. }
  446. void ShangPin::OnRadio2()
  447. {
  448. // TODO: Add your control notification handler code here
  449. OnSelchangeCOMBOsplb();
  450. }
  451. void ShangPin::OnRadio9()
  452. {
  453. // TODO: Add your control notification handler code here
  454. OnSelchangeCOMBOsplb();
  455. }