ShangPin.cpp 13 KB

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