TXDlg.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. // TXDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "TXDlg.h"
  6. #include "MyMdi.H"
  7. #include "SPLBDlg.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // TXDlg
  15. IMPLEMENT_DYNCREATE(TXDlg, MyFormView)TXDlg::TXDlg(): MyFormView(TXDlg::IDD)
  16. {
  17. m_taoxiid = _T("");
  18. m_taoxijiage = _T("");
  19. m_taoxiname = _T("");
  20. m_zs = _T("");
  21. m_zs2 = _T("");
  22. }
  23. TXDlg::~TXDlg()
  24. {
  25. }
  26. void TXDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28. MyFormView::DoDataExchange(pDX);
  29. DDX_Control(pDX, IDC_COMBO2, m_combo2);
  30. DDX_Control(pDX, IDC_COMBO1, m_combo1);
  31. DDX_Control(pDX, IDC_EDITtaoxijiage, m_editctrl1);
  32. DDX_Control(pDX, IDC_STATIC1, m_static1);
  33. DDX_Control(pDX, IDC_LIST2, m_List1);
  34. DDX_Text(pDX, IDC_EDITtaoxiid, m_taoxiid);
  35. DDX_Text(pDX, IDC_EDITtaoxijiage, m_taoxijiage);
  36. DDX_Text(pDX, IDC_EDITtaoxiname, m_taoxiname);
  37. DDX_Text(pDX, IDC_EDITzs, m_zs);
  38. DDX_Text(pDX, IDC_EDITzs4, m_zs2);
  39. DDX_Control(pDX, CB_KINDS, m_cbKinds);
  40. }
  41. BEGIN_MESSAGE_MAP(TXDlg, MyFormView)
  42. ON_BN_CLICKED(IDC_BUTsave, OnBUTsave)
  43. ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
  44. ON_BN_CLICKED(IDC_BUTclose, OnBUTclose)
  45. ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2)
  46. ON_BN_CLICKED(IDC_BUTadd, OnBUTadd)
  47. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  48. ON_CBN_SELCHANGE(CB_KINDS, OnCbnSelchangeKinds)
  49. END_MESSAGE_MAP()
  50. #ifdef _DEBUG
  51. void TXDlg::AssertValid() const
  52. {
  53. MyFormView::AssertValid();
  54. }
  55. void TXDlg::Dump(CDumpContext& dc) const
  56. {
  57. MyFormView::Dump(dc);
  58. }
  59. #endif
  60. void TXDlg::OnInitialUpdate()
  61. {
  62. MyFormView::OnInitialUpdate();
  63. CMyMdi Mdi;
  64. Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this);
  65. CRect rc2;
  66. GetWindowRect(rc2);
  67. ::MoveWindow(m_hWnd, g_rc.left, g_rc.top, g_rc.Width(), g_rc.Height(), TRUE);
  68. EnumChildWindows(m_hWnd, (WNDENUMPROC)EnumChildProc, 0);
  69. #if defined(VC70) || defined(VC80)
  70. m_combo1.GetWindowRect(rc2);
  71. ScreenToClient(rc2);
  72. rc2.bottom += 200;
  73. m_combo1.MoveWindow(rc2);
  74. m_combo2.GetWindowRect(rc2);
  75. ScreenToClient(rc2);
  76. rc2.bottom += 200;
  77. m_combo2.MoveWindow(rc2);
  78. m_cbKinds.GetWindowRect(rc2);
  79. ScreenToClient(rc2);
  80. rc2.bottom += 500;
  81. m_cbKinds.MoveWindow(rc2);
  82. #endif
  83. m_combo2.AddString("显示");
  84. m_combo2.AddString("隐藏");
  85. m_static1.SetFont(&g_titlefont);
  86. m_List1.SetHeadings("套系编号, 100;套系名称, 100;套系价格, 100;入底\\入册, 100;套系大类,100;是否显示,100");
  87. m_List1.LoadColumnInfo(102);
  88. GetData();
  89. }
  90. void TXDlg::FillGrid()
  91. {
  92. m_List1.DeleteAllItems2();
  93. int ii = 0;
  94. m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1);
  95. int count = 0;
  96. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  97. {
  98. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  99. }
  100. m_List1.m_arLabels.SetSize(count, 1);
  101. ii = count;
  102. m_List1.m_LabelCount = ii;
  103. m_List1.SetItemCountEx(ii);
  104. OnBUTadd();
  105. }
  106. void TXDlg::OnBUTclose()
  107. {
  108. GetParent()->SendMessage(WM_CLOSE);
  109. }
  110. void TXDlg::ClearCtrl()
  111. {
  112. m_taoxiid = _T("");
  113. m_taoxijiage = _T("");
  114. m_taoxiname = _T("");
  115. m_zs = _T("");
  116. m_zs2 = _T("");
  117. UpdateData(false);
  118. }
  119. void TXDlg::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
  120. {
  121. ListSelChange();
  122. *pResult = 0;
  123. }
  124. void TXDlg::ListSelChange()
  125. {
  126. POSITION pos;
  127. pos = m_List1.GetFirstSelectedItemPosition();
  128. if (pos == NULL)
  129. {
  130. OnBUTadd();
  131. return;
  132. }
  133. int iItem = m_List1.GetNextSelectedItem(pos);
  134. m_oldtaoxiid = m_List1.GetItemText(iItem, 0);
  135. m_oldtaoxiname = m_List1.GetItemText(iItem, 1);
  136. for (int ii = 0; ii < m_List1array.GetSize(); ii++)
  137. {
  138. if (m_List1array.ElementAt(ii).ElementAt(0) == m_oldtaoxiid)
  139. {
  140. m_taoxiid = m_List1array.ElementAt(ii).ElementAt(0);
  141. m_taoxiname = m_List1array.ElementAt(ii).ElementAt(1);
  142. m_taoxijiage = m_List1array.ElementAt(ii).ElementAt(2);
  143. CString zs = m_List1array.ElementAt(ii).ElementAt(3);
  144. int pos = zs.Find("\\");
  145. if (pos != -1)
  146. {
  147. m_zs = zs.Left(pos);
  148. m_zs2 = zs.Right(zs.GetLength() - pos - 1);
  149. }
  150. else
  151. {
  152. m_zs = zs;
  153. m_zs2 = "";
  154. }
  155. CString txlb = m_List1array.ElementAt(ii).ElementAt(4);
  156. CString isshow = m_List1array.ElementAt(ii).ElementAt(5);
  157. if (m_combo1.FindString(0, txlb) == -1)
  158. m_combo1.AddString(txlb);
  159. m_combo1.SetCurSel(m_combo1.FindString(0, txlb));
  160. if (isshow == "")
  161. m_combo2.SetCurSel(0);
  162. else
  163. m_combo2.SetCurSel(m_combo2.FindString(0, isshow));
  164. UpdateData(false);
  165. return;
  166. }
  167. }
  168. }
  169. void TXDlg::OnBUTadd()
  170. {
  171. m_oldtaoxiid.Empty();
  172. m_oldtaoxiname.Empty();
  173. ClearCtrl();
  174. }
  175. void TXDlg::OnBUTsave()
  176. {
  177. UpdateData();
  178. if (m_taoxiid.IsEmpty() || m_taoxiname.IsEmpty() || m_taoxijiage.IsEmpty())
  179. {
  180. AfxMessageBox("资料不全!", MB_ICONINFORMATION); return;
  181. }
  182. CString txlb, isshow;
  183. int pos = m_combo1.GetCurSel();
  184. if (pos != -1)
  185. {
  186. m_combo1.GetLBText(pos, txlb);
  187. }
  188. pos = m_combo2.GetCurSel();
  189. if (pos != -1)
  190. {
  191. m_combo2.GetLBText(pos, isshow);
  192. }
  193. if (isshow == "")isshow = "显示";
  194. CString sql;
  195. CString zs = m_zs + "\\" + m_zs2;
  196. if (m_oldtaoxiid.IsEmpty())//新增
  197. {
  198. if (IsExist())
  199. {
  200. AfxMessageBox("已有此编号或名称的套系,请重新输入!", MB_ICONINFORMATION);
  201. return;
  202. }
  203. sql.Format("insert into taoxi(taoxiid,taoxiname,taoxijiage,zs,type,show)values('%s','%s','%s','%s','%s','%s')", m_taoxiid, m_taoxiname, m_taoxijiage, zs, txlb, isshow);
  204. sql += TAOXI_REF;
  205. g_sendhead.bsql = 1;
  206. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  207. GetData();
  208. }
  209. else//修改
  210. {
  211. if (m_oldtaoxiid != m_taoxiid)
  212. {
  213. if (IsExistID())
  214. {
  215. AfxMessageBox("已有此编号的套系,请重新输入!", MB_ICONINFORMATION);
  216. return;
  217. }
  218. }
  219. if (m_oldtaoxiname != m_taoxiname)
  220. {
  221. if (IsExistName())
  222. {
  223. AfxMessageBox("已有此名称的套系,请重新输入!", MB_ICONINFORMATION);
  224. return;
  225. }
  226. }
  227. sql.Format("update taoxi set taoxiid='%s',taoxiname='%s',taoxijiage='%s',zs='%s',type='%s',show='%s' where taoxiid='%s' ", m_taoxiid, m_taoxiname, m_taoxijiage, zs, txlb, isshow, m_oldtaoxiid);
  228. sql += TAOXI_REF;
  229. g_sendhead.bsql = 1;
  230. // MessageBox(sql);
  231. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  232. GetData();
  233. }
  234. }
  235. void TXDlg::OnBUTdel()
  236. {
  237. POSITION pos;
  238. pos = m_List1.GetFirstSelectedItemPosition();
  239. if (pos == NULL)
  240. {
  241. return;
  242. }
  243. if (AfxMessageBox("确认删除吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  244. int iItem = m_List1.GetNextSelectedItem(pos);
  245. CString id = m_List1.GetItemText(iItem, 0);
  246. CString sql;
  247. sql.Format("delete from taoxi where taoxiid='%s' ", id);
  248. sql += TAOXI_REF;
  249. g_sendhead.bsql = 1;
  250. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  251. GetData();
  252. }
  253. void TXDlg::GetData()
  254. {
  255. if (m_combo1.GetCount() == 0)
  256. {
  257. g_sendhead.bsql = 0;
  258. g_sendhead.code[0] = 6;
  259. g_sendhead.code[1] = 194;
  260. g_sendhead.tabcount = 2;
  261. g_pMainWnd->ProcessChatMessageRequest2(6);
  262. if (g_bSendOK == 0)return;
  263. CArray<CStringArray, CStringArray>expendtypearray;
  264. DataToArray(&m_List1array, &expendtypearray);
  265. m_combo1.ResetContent();
  266. for (int i = 0; i < expendtypearray.GetSize(); i++)
  267. m_combo1.AddString(expendtypearray.ElementAt(i).ElementAt(0));
  268. m_cbKinds.ResetContent();
  269. m_cbKinds.AddString(_T("全部"));
  270. for (int j = 0; j < expendtypearray.GetSize(); j++)
  271. {
  272. m_cbKinds.AddString(expendtypearray.ElementAt(j).ElementAt(0));
  273. }
  274. FillGrid();
  275. return;
  276. }
  277. g_sendhead.bsql = 0;
  278. g_sendhead.code[0] = 6;
  279. g_sendhead.tabcount = 1;
  280. g_pMainWnd->ProcessChatMessageRequest2(6);
  281. if (g_bSendOK == 0)return;
  282. DataToArray(&m_List1array);
  283. FillGrid();
  284. }
  285. BOOL TXDlg::IsExist()
  286. {
  287. for (int i = 0; i < m_List1array.GetSize(); i++)
  288. {
  289. if (m_taoxiid == m_List1array.ElementAt(i).ElementAt(0))return 1;
  290. if (m_taoxiname == m_List1array.ElementAt(i).ElementAt(1))return 1;
  291. }
  292. return 0;
  293. }
  294. BOOL TXDlg::IsExistID()
  295. {
  296. for (int i = 0; i < m_List1array.GetSize(); i++)
  297. {
  298. if (m_taoxiid == m_List1array.ElementAt(i).ElementAt(0))return 1;
  299. }
  300. return 0;
  301. }
  302. BOOL TXDlg::IsExistName()
  303. {
  304. for (int i = 0; i < m_List1array.GetSize(); i++)
  305. {
  306. if (m_taoxiname == m_List1array.ElementAt(i).ElementAt(1))return 1;
  307. }
  308. return 0;
  309. }
  310. BOOL TXDlg::PreTranslateMessage(MSG* pMsg)
  311. {
  312. if (pMsg->message == WM_KEYDOWN)
  313. {
  314. switch (pMsg->wParam)
  315. {
  316. case VK_RETURN:
  317. OnBUTsave();
  318. return 1;
  319. case 0x43: // copy
  320. if ((GetKeyState(VK_CONTROL) & 0x80))
  321. {
  322. GetFocus()->SendMessage(WM_COPY);
  323. return TRUE;
  324. }
  325. break;
  326. case 0x56: //Ctrl + V:
  327. if ((GetKeyState(VK_CONTROL) & 0x80))
  328. {
  329. GetFocus()->SendMessage(WM_PASTE);
  330. return TRUE;
  331. }
  332. break;
  333. case 0x58: // cut
  334. if ((GetKeyState(VK_CONTROL) & 0x80))
  335. {
  336. GetFocus()->SendMessage(WM_CUT);
  337. return TRUE;
  338. }
  339. break;
  340. case 0x5A: //undo
  341. case 0x59: //redo
  342. if ((GetKeyState(VK_CONTROL) & 0x80))
  343. {
  344. GetFocus()->SendMessage(WM_UNDO);
  345. return TRUE;
  346. }
  347. break;
  348. }
  349. }
  350. return MyFormView::PreTranslateMessage(pMsg);
  351. }
  352. void TXDlg::OnButton1()
  353. {
  354. SPLBDlg dlg;
  355. dlg.m_mode = 12;
  356. dlg.DoModal();
  357. g_sendhead.bsql = 0;
  358. g_sendhead.code[0] = 194;
  359. g_sendhead.tabcount = 1;
  360. g_pMainWnd->ProcessChatMessageRequest2(1);
  361. if (g_bSendOK == 0)return;
  362. CArray<CStringArray, CStringArray>expendtypearray;
  363. DataToArray(&expendtypearray);
  364. m_combo1.ResetContent();
  365. for (int i = 0; i < expendtypearray.GetSize(); i++)
  366. {
  367. m_combo1.AddString(expendtypearray.ElementAt(i).ElementAt(0));
  368. }
  369. m_cbKinds.ResetContent();
  370. m_cbKinds.AddString(_T("全部"));
  371. for (int j = 0; j < expendtypearray.GetSize(); j++)
  372. {
  373. m_cbKinds.AddString(expendtypearray.ElementAt(j).ElementAt(0));
  374. }
  375. }
  376. void TXDlg::OnCbnSelchangeKinds()
  377. {
  378. // 处理套系显示下拉框时的列表显示;
  379. // 1.获取选中文本内容;
  380. CString strCurSelText;
  381. m_cbKinds.GetLBText(m_cbKinds.GetCurSel(), strCurSelText);
  382. // 2.筛选内容;
  383. m_List1.DeleteAllItems2();
  384. m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1);
  385. int count = 0;
  386. int nIndex = 0;
  387. if (strCurSelText == _T("全部"))
  388. {
  389. for (nIndex = 0; nIndex < m_List1.m_arLabels.GetSize(); nIndex++)
  390. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(nIndex));
  391. }
  392. else
  393. {
  394. for (nIndex = 0; nIndex < m_List1.m_arLabels.GetSize(); nIndex++)
  395. if (strCurSelText == m_List1array.ElementAt(nIndex).ElementAt(4))
  396. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(nIndex));
  397. }
  398. m_List1.m_arLabels.SetSize(count, 1);
  399. nIndex = count;
  400. m_List1.m_LabelCount = nIndex;
  401. m_List1.SetItemCountEx(nIndex);
  402. }