TXDlg.cpp 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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. m_combo1.GetWindowRect(rc2);
  70. ScreenToClient(rc2);
  71. rc2.bottom += 200;
  72. m_combo1.MoveWindow(rc2);
  73. m_combo2.GetWindowRect(rc2);
  74. ScreenToClient(rc2);
  75. rc2.bottom += 200;
  76. m_combo2.MoveWindow(rc2);
  77. m_combo2.AddString("显示");
  78. m_combo2.AddString("隐藏");
  79. m_static1.SetFont(&g_titlefont);
  80. m_List1.SetHeadings("套系编号, 100;套系名称, 100;套系价格, 100;入底\\入册, 100;套系大类,100;是否显示,100");
  81. m_List1.LoadColumnInfo(102);
  82. GetData();
  83. }
  84. void TXDlg::FillGrid()
  85. {
  86. m_List1.DeleteAllItems2();
  87. int ii = 0;
  88. m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1);
  89. int count = 0;
  90. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  91. {
  92. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  93. }
  94. m_List1.m_arLabels.SetSize(count, 1);
  95. ii = count;
  96. m_List1.m_LabelCount = ii;
  97. m_List1.SetItemCountEx(ii);
  98. OnBUTadd();
  99. }
  100. void TXDlg::OnBUTclose()
  101. {
  102. GetParent()->SendMessage(WM_CLOSE);
  103. }
  104. void TXDlg::ClearCtrl()
  105. {
  106. m_taoxiid = _T("");
  107. m_taoxijiage = _T("");
  108. m_taoxiname = _T("");
  109. m_zs = _T("");
  110. m_zs2 = _T("");
  111. UpdateData(false);
  112. }
  113. void TXDlg::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
  114. {
  115. ListSelChange();
  116. *pResult = 0;
  117. }
  118. void TXDlg::ListSelChange()
  119. {
  120. POSITION pos;
  121. pos = m_List1.GetFirstSelectedItemPosition();
  122. if (pos == NULL)
  123. {
  124. OnBUTadd();
  125. return;
  126. }
  127. int iItem = m_List1.GetNextSelectedItem(pos);
  128. m_oldtaoxiid = m_List1.GetItemText(iItem, 0);
  129. m_oldtaoxiname = m_List1.GetItemText(iItem, 1);
  130. for (int ii = 0; ii < m_List1array.GetSize(); ii++)
  131. {
  132. if (m_List1array.ElementAt(ii).ElementAt(0) == m_oldtaoxiid)
  133. {
  134. m_taoxiid = m_List1array.ElementAt(ii).ElementAt(0);
  135. m_taoxiname = m_List1array.ElementAt(ii).ElementAt(1);
  136. m_taoxijiage = m_List1array.ElementAt(ii).ElementAt(2);
  137. CString zs = m_List1array.ElementAt(ii).ElementAt(3);
  138. int pos = zs.Find("\\");
  139. if (pos != -1)
  140. {
  141. m_zs = zs.Left(pos);
  142. m_zs2 = zs.Right(zs.GetLength() - pos - 1);
  143. }
  144. else
  145. {
  146. m_zs = zs;
  147. m_zs2 = "";
  148. }
  149. CString txlb = m_List1array.ElementAt(ii).ElementAt(4);
  150. CString isshow = m_List1array.ElementAt(ii).ElementAt(5);
  151. if (m_combo1.FindString(0, txlb) == -1)
  152. m_combo1.AddString(txlb);
  153. m_combo1.SetCurSel(m_combo1.FindString(0, txlb));
  154. if (isshow == "")
  155. m_combo2.SetCurSel(0);
  156. else
  157. m_combo2.SetCurSel(m_combo2.FindString(0, isshow));
  158. UpdateData(false);
  159. return;
  160. }
  161. }
  162. }
  163. void TXDlg::OnBUTadd()
  164. {
  165. m_oldtaoxiid.Empty();
  166. m_oldtaoxiname.Empty();
  167. ClearCtrl();
  168. }
  169. void TXDlg::OnBUTsave()
  170. {
  171. UpdateData();
  172. if (m_taoxiid.IsEmpty() || m_taoxiname.IsEmpty() || m_taoxijiage.IsEmpty())
  173. {
  174. AfxMessageBox("资料不全!", MB_ICONINFORMATION); return;
  175. }
  176. CString txlb, isshow;
  177. int pos = m_combo1.GetCurSel();
  178. if (pos != -1)
  179. {
  180. m_combo1.GetLBText(pos, txlb);
  181. }
  182. pos = m_combo2.GetCurSel();
  183. if (pos != -1)
  184. {
  185. m_combo2.GetLBText(pos, isshow);
  186. }
  187. if (isshow == "")isshow = "显示";
  188. CString sql;
  189. CString zs = m_zs + "\\" + m_zs2;
  190. if (m_oldtaoxiid.IsEmpty())//新增
  191. {
  192. if (IsExist())
  193. {
  194. AfxMessageBox("已有此编号或名称的套系,请重新输入!", MB_ICONINFORMATION);
  195. return;
  196. }
  197. 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);
  198. sql += TAOXI_REF;
  199. g_sendhead.bsql = 1;
  200. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  201. GetData();
  202. }
  203. else//修改
  204. {
  205. if (m_oldtaoxiid != m_taoxiid)
  206. {
  207. if (IsExistID())
  208. {
  209. AfxMessageBox("已有此编号的套系,请重新输入!", MB_ICONINFORMATION);
  210. return;
  211. }
  212. }
  213. if (m_oldtaoxiname != m_taoxiname)
  214. {
  215. if (IsExistName())
  216. {
  217. AfxMessageBox("已有此名称的套系,请重新输入!", MB_ICONINFORMATION);
  218. return;
  219. }
  220. }
  221. 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);
  222. sql += TAOXI_REF;
  223. g_sendhead.bsql = 1;
  224. // MessageBox(sql);
  225. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  226. GetData();
  227. }
  228. }
  229. void TXDlg::OnBUTdel()
  230. {
  231. POSITION pos;
  232. pos = m_List1.GetFirstSelectedItemPosition();
  233. if (pos == NULL)
  234. {
  235. return;
  236. }
  237. if (AfxMessageBox("确认删除吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  238. int iItem = m_List1.GetNextSelectedItem(pos);
  239. CString id = m_List1.GetItemText(iItem, 0);
  240. CString sql;
  241. sql.Format("delete from taoxi where taoxiid='%s' ", id);
  242. sql += TAOXI_REF;
  243. g_sendhead.bsql = 1;
  244. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  245. GetData();
  246. }
  247. void TXDlg::GetData()
  248. {
  249. if (m_combo1.GetCount() == 0)
  250. {
  251. g_sendhead.bsql = 0;
  252. g_sendhead.code[0] = 6;
  253. g_sendhead.code[1] = 194;
  254. g_sendhead.tabcount = 2;
  255. g_pMainWnd->ProcessChatMessageRequest2(6);
  256. if (g_bSendOK == 0)return;
  257. CArray<CStringArray, CStringArray>expendtypearray;
  258. DataToArray(&m_List1array, &expendtypearray);
  259. m_combo1.ResetContent();
  260. for (int i = 0; i < expendtypearray.GetSize(); i++)
  261. m_combo1.AddString(expendtypearray.ElementAt(i).ElementAt(0));
  262. m_cbKinds.ResetContent();
  263. m_cbKinds.AddString(_T("全部"));
  264. for (int j = 0; j < expendtypearray.GetSize(); j++)
  265. {
  266. m_cbKinds.AddString(expendtypearray.ElementAt(j).ElementAt(0));
  267. }
  268. FillGrid();
  269. return;
  270. }
  271. g_sendhead.bsql = 0;
  272. g_sendhead.code[0] = 6;
  273. g_sendhead.tabcount = 1;
  274. g_pMainWnd->ProcessChatMessageRequest2(6);
  275. if (g_bSendOK == 0)return;
  276. DataToArray(&m_List1array);
  277. FillGrid();
  278. }
  279. BOOL TXDlg::IsExist()
  280. {
  281. for (int i = 0; i < m_List1array.GetSize(); i++)
  282. {
  283. if (m_taoxiid == m_List1array.ElementAt(i).ElementAt(0))return 1;
  284. if (m_taoxiname == m_List1array.ElementAt(i).ElementAt(1))return 1;
  285. }
  286. return 0;
  287. }
  288. BOOL TXDlg::IsExistID()
  289. {
  290. for (int i = 0; i < m_List1array.GetSize(); i++)
  291. {
  292. if (m_taoxiid == m_List1array.ElementAt(i).ElementAt(0))return 1;
  293. }
  294. return 0;
  295. }
  296. BOOL TXDlg::IsExistName()
  297. {
  298. for (int i = 0; i < m_List1array.GetSize(); i++)
  299. {
  300. if (m_taoxiname == m_List1array.ElementAt(i).ElementAt(1))return 1;
  301. }
  302. return 0;
  303. }
  304. BOOL TXDlg::PreTranslateMessage(MSG* pMsg)
  305. {
  306. if (pMsg->message == WM_KEYDOWN)
  307. {
  308. switch (pMsg->wParam)
  309. {
  310. case VK_RETURN:
  311. OnBUTsave();
  312. return 1;
  313. case 0x43: // copy
  314. if ((GetKeyState(VK_CONTROL) & 0x80))
  315. {
  316. GetFocus()->SendMessage(WM_COPY);
  317. return TRUE;
  318. }
  319. break;
  320. case 0x56: //Ctrl + V:
  321. if ((GetKeyState(VK_CONTROL) & 0x80))
  322. {
  323. GetFocus()->SendMessage(WM_PASTE);
  324. return TRUE;
  325. }
  326. break;
  327. case 0x58: // cut
  328. if ((GetKeyState(VK_CONTROL) & 0x80))
  329. {
  330. GetFocus()->SendMessage(WM_CUT);
  331. return TRUE;
  332. }
  333. break;
  334. case 0x5A: //undo
  335. case 0x59: //redo
  336. if ((GetKeyState(VK_CONTROL) & 0x80))
  337. {
  338. GetFocus()->SendMessage(WM_UNDO);
  339. return TRUE;
  340. }
  341. break;
  342. }
  343. }
  344. return MyFormView::PreTranslateMessage(pMsg);
  345. }
  346. void TXDlg::OnButton1()
  347. {
  348. SPLBDlg dlg;
  349. dlg.m_mode = 12;
  350. dlg.DoModal();
  351. g_sendhead.bsql = 0;
  352. g_sendhead.code[0] = 194;
  353. g_sendhead.tabcount = 1;
  354. g_pMainWnd->ProcessChatMessageRequest2(1);
  355. if (g_bSendOK == 0)return;
  356. CArray<CStringArray, CStringArray>expendtypearray;
  357. DataToArray(&expendtypearray);
  358. m_combo1.ResetContent();
  359. for (int i = 0; i < expendtypearray.GetSize(); i++)
  360. {
  361. m_combo1.AddString(expendtypearray.ElementAt(i).ElementAt(0));
  362. }
  363. m_cbKinds.ResetContent();
  364. m_cbKinds.AddString(_T("全部"));
  365. for (int j = 0; j < expendtypearray.GetSize(); j++)
  366. {
  367. m_cbKinds.AddString(expendtypearray.ElementAt(j).ElementAt(0));
  368. }
  369. }
  370. void TXDlg::OnCbnSelchangeKinds()
  371. {
  372. // 处理套系显示下拉框时的列表显示;
  373. // 1.获取选中文本内容;
  374. CString strCurSelText;
  375. m_cbKinds.GetLBText(m_cbKinds.GetCurSel(), strCurSelText);
  376. // 2.筛选内容;
  377. m_List1.DeleteAllItems2();
  378. m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1);
  379. int count = 0;
  380. int nIndex = 0;
  381. if (strCurSelText == _T("全部"))
  382. {
  383. for (nIndex = 0; nIndex < m_List1.m_arLabels.GetSize(); nIndex++)
  384. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(nIndex));
  385. }
  386. else
  387. {
  388. for (nIndex = 0; nIndex < m_List1.m_arLabels.GetSize(); nIndex++)
  389. if (strCurSelText == m_List1array.ElementAt(nIndex).ElementAt(4))
  390. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(nIndex));
  391. }
  392. m_List1.m_arLabels.SetSize(count, 1);
  393. nIndex = count;
  394. m_List1.m_LabelCount = nIndex;
  395. m_List1.SetItemCountEx(nIndex);
  396. }