ShangPin.cpp 12 KB

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