TXDlg.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. // TXDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "LYFZIPManage.h"
  5. #include "TXDlg.h"
  6. #include "MyMdi.H"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // TXDlg
  14. IMPLEMENT_DYNCREATE(TXDlg, CFormView)
  15. TXDlg::TXDlg()
  16. : CFormView(TXDlg::IDD)
  17. {
  18. //{{AFX_DATA_INIT(TXDlg)
  19. m_taoxiid = _T("");
  20. m_taoxijiage = _T("");
  21. m_taoxiname = _T("");
  22. m_zs = _T("");
  23. //}}AFX_DATA_INIT
  24. }
  25. TXDlg::~TXDlg()
  26. {
  27. }
  28. void TXDlg::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CFormView::DoDataExchange(pDX);
  31. //{{AFX_DATA_MAP(TXDlg)
  32. DDX_Control(pDX, IDC_EDITtaoxijiage, m_editctrl1);
  33. DDX_Control(pDX, IDC_STATIC1, m_static1);
  34. DDX_Control(pDX, IDC_LIST2, m_List1);
  35. DDX_Text(pDX, IDC_EDITtaoxiid, m_taoxiid);
  36. DDX_Text(pDX, IDC_EDITtaoxijiage, m_taoxijiage);
  37. DDX_Text(pDX, IDC_EDITtaoxiname, m_taoxiname);
  38. DDX_Text(pDX, IDC_EDITzs, m_zs);
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(TXDlg, CFormView)
  42. //{{AFX_MSG_MAP(TXDlg)
  43. ON_BN_CLICKED(IDC_BUTsave, OnBUTsave)
  44. ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
  45. ON_BN_CLICKED(IDC_BUTclose, OnBUTclose)
  46. ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2)
  47. ON_BN_CLICKED(IDC_BUTadd, OnBUTadd)
  48. //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50. /////////////////////////////////////////////////////////////////////////////
  51. // TXDlg diagnostics
  52. #ifdef _DEBUG
  53. void TXDlg::AssertValid() const
  54. {
  55. CFormView::AssertValid();
  56. }
  57. void TXDlg::Dump(CDumpContext& dc) const
  58. {
  59. CFormView::Dump(dc);
  60. }
  61. #endif //_DEBUG
  62. /////////////////////////////////////////////////////////////////////////////
  63. // TXDlg message handlers
  64. void TXDlg::OnInitialUpdate()
  65. {
  66. CFormView::OnInitialUpdate();
  67. // TODO: Add your specialized code here and/or call the base class
  68. CMyMdi Mdi;
  69. Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this);
  70. // Here we create the outbar control using the splitter as its parent
  71. // and setting its id to the first pane.
  72. CRect rc2;
  73. GetWindowRect(rc2);
  74. ::MoveWindow(m_hWnd,g_rc.left,g_rc.top,g_rc.Width(),g_rc.Height(),TRUE);
  75. EnumChildWindows(m_hWnd,(WNDENUMPROC)EnumChildProc,0);
  76. m_static1.SetFont (&g_titlefont);
  77. m_List1.SetHeadings( "套系编号, 100;套系名称, 100;套系价格, 100;赠送张数, 100" );
  78. m_List1.LoadColumnInfo (102);
  79. GetData();
  80. }
  81. void TXDlg::FillGrid()
  82. {
  83. m_List1.DeleteAllItems2 ();
  84. int ii=0;
  85. m_List1.m_arLabels.SetSize( m_List1array.GetSize (), 1 );
  86. int count=0;
  87. for(ii=0; ii<m_List1.m_arLabels.GetSize (); ii++)
  88. {
  89. m_List1.m_arLabels.ElementAt (count++).Copy (m_List1array.ElementAt (ii));
  90. }
  91. m_List1.m_arLabels.SetSize(count, 1);
  92. ii=count;
  93. m_List1.m_LabelCount=ii;
  94. m_List1.SetItemCountEx (ii);
  95. OnBUTadd();
  96. }
  97. void TXDlg::OnBUTclose()
  98. {
  99. // TODO: Add your control notification handler code here
  100. GetParent()->SendMessage(WM_CLOSE);
  101. }
  102. void TXDlg::ClearCtrl()
  103. {
  104. m_taoxiid = _T("");
  105. m_taoxijiage = _T("");
  106. m_taoxiname = _T("");
  107. m_zs = _T("");
  108. UpdateData(false);
  109. }
  110. void TXDlg::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
  111. {
  112. // TODO: Add your control notification handler code here
  113. ListSelChange();
  114. *pResult = 0;
  115. }
  116. void TXDlg::ListSelChange()
  117. {
  118. POSITION pos;
  119. pos=m_List1.GetFirstSelectedItemPosition();
  120. if(pos==NULL)
  121. {
  122. OnBUTadd() ;
  123. return;
  124. }
  125. int iItem=m_List1.GetNextSelectedItem(pos);
  126. m_oldtaoxiid=m_List1.GetItemText (iItem, 0);
  127. m_oldtaoxiname=m_List1.GetItemText (iItem, 1);
  128. for(int ii=0; ii<m_List1array.GetSize (); ii++)
  129. {
  130. if(m_List1array.ElementAt (ii).ElementAt (0)==m_oldtaoxiid)
  131. {
  132. m_taoxiid = m_List1array.ElementAt (ii).ElementAt (0);
  133. m_taoxiname = m_List1array.ElementAt (ii).ElementAt (1);
  134. m_taoxijiage = m_List1array.ElementAt (ii).ElementAt (2);
  135. m_zs = m_List1array.ElementAt (ii).ElementAt (3);
  136. UpdateData(false);
  137. return;
  138. }
  139. }
  140. }
  141. void TXDlg::OnBUTadd()
  142. {
  143. // TODO: Add your control notification handler code here
  144. m_oldtaoxiid.Empty ();
  145. m_oldtaoxiname.Empty ();
  146. ClearCtrl();
  147. }
  148. void TXDlg::OnBUTsave()
  149. {
  150. // TODO: Add your control notification handler code here
  151. UpdateData();
  152. if(m_taoxiid.IsEmpty () || m_taoxiname.IsEmpty () || m_taoxijiage.IsEmpty ())
  153. {
  154. AfxMessageBox("资料不全!", MB_ICONINFORMATION);return;
  155. }
  156. CString sql;
  157. if(m_oldtaoxiid.IsEmpty ())//新增
  158. {
  159. if(IsExist())
  160. {
  161. AfxMessageBox("已有此编号或名称的套系,请重新输入!", MB_ICONINFORMATION);
  162. return;
  163. }
  164. sql.Format ("insert into taoxi(taoxiid,taoxiname,taoxijiage,zs)\
  165. values('%s','%s','%s','%s')", m_taoxiid,m_taoxiname,m_taoxijiage,m_zs);
  166. sql+=TAOXI_REF;
  167. g_sendhead.bsql=1;
  168. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  169. GetData();
  170. }
  171. else//修改
  172. {
  173. if(m_oldtaoxiid!=m_taoxiid)
  174. {
  175. if(IsExistID())
  176. {
  177. AfxMessageBox("已有此编号的套系,请重新输入!", MB_ICONINFORMATION);
  178. return;
  179. }
  180. }
  181. if(m_oldtaoxiname!=m_taoxiname)
  182. {
  183. if(IsExistName())
  184. {
  185. AfxMessageBox("已有此名称的套系,请重新输入!", MB_ICONINFORMATION);
  186. return;
  187. }
  188. }
  189. sql.Format ("update taoxi set taoxiid='%s',taoxiname='%s',taoxijiage='%s',zs='%s' where taoxiid='%s' ", m_taoxiid,m_taoxiname,m_taoxijiage,m_zs, m_oldtaoxiid);
  190. sql+=TAOXI_REF;
  191. g_sendhead.bsql=1;
  192. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  193. GetData();
  194. }
  195. }
  196. void TXDlg::OnBUTdel()
  197. {
  198. // TODO: Add your control notification handler code here
  199. POSITION pos;
  200. pos=m_List1.GetFirstSelectedItemPosition();
  201. if(pos==NULL)
  202. {
  203. return;
  204. }
  205. if(AfxMessageBox("确认删除吗?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return;
  206. int iItem=m_List1.GetNextSelectedItem(pos);
  207. CString id=m_List1.GetItemText (iItem, 0);
  208. CString sql;
  209. sql.Format ("delete from taoxi where taoxiid='%s' ", id);
  210. sql+=TAOXI_REF;
  211. g_sendhead.bsql=1;
  212. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  213. GetData();
  214. }
  215. void TXDlg::GetData()
  216. {
  217. g_sendhead.bsql=0;
  218. g_sendhead.code[0]=6;
  219. g_sendhead.tabcount=1;
  220. g_pMainWnd->ProcessChatMessageRequest2(6);if(g_bSendOK==0)return;
  221. DataToArray(&m_List1array);
  222. FillGrid();
  223. }
  224. BOOL TXDlg::IsExist()
  225. {
  226. for(int i=0; i<m_List1array.GetSize (); i++)
  227. {
  228. if(m_taoxiid==m_List1array.ElementAt (i).ElementAt (0))return 1;
  229. if(m_taoxiname==m_List1array.ElementAt (i).ElementAt (1))return 1;
  230. }
  231. return 0;
  232. }
  233. BOOL TXDlg::IsExistID()
  234. {
  235. for(int i=0; i<m_List1array.GetSize (); i++)
  236. {
  237. if(m_taoxiid==m_List1array.ElementAt (i).ElementAt (0))return 1;
  238. }
  239. return 0;
  240. }
  241. BOOL TXDlg::IsExistName()
  242. {
  243. for(int i=0; i<m_List1array.GetSize (); i++)
  244. {
  245. if(m_taoxiname==m_List1array.ElementAt (i).ElementAt (1))return 1;
  246. }
  247. return 0;
  248. }
  249. BOOL TXDlg::PreTranslateMessage(MSG* pMsg)
  250. {
  251. // TODO: Add your specialized code here and/or call the base class
  252. if(pMsg->message==WM_KEYDOWN)
  253. {
  254. switch (pMsg->wParam)
  255. {
  256. case VK_RETURN:
  257. OnBUTsave();
  258. return 1;
  259. case 0x43: // copy
  260. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  261. {
  262. GetFocus()->SendMessage(WM_COPY);
  263. return TRUE;
  264. }
  265. break;
  266. case 0x56: //Ctrl + V:
  267. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  268. {
  269. GetFocus()->SendMessage(WM_PASTE);
  270. return TRUE;
  271. }
  272. break;
  273. case 0x58: // cut
  274. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  275. {
  276. GetFocus()->SendMessage(WM_CUT);
  277. return TRUE;
  278. }
  279. break;
  280. case 0x5A: //undo
  281. case 0x59: //redo
  282. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  283. {
  284. GetFocus()->SendMessage(WM_UNDO);
  285. return TRUE;
  286. }
  287. break;
  288. }
  289. }
  290. return CFormView::PreTranslateMessage(pMsg);
  291. }