TXDlg.cpp 9.5 KB

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