Userdlg.cpp
上传用户:hahaxixi
上传日期:2022-04-15
资源大小:1939k
文件大小:5k
源码类别:

手机短信编程

开发平台:

Visual C++

  1. // Userdlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "NoteManage.h"
  5. #include "Userdlg.h"
  6. #include "ADOConn.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CUserdlg dialog
  14. CUserdlg::CUserdlg(CWnd* pParent /*=NULL*/)
  15. : CDialog(CUserdlg::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CUserdlg)
  18. m_Name = _T("");
  19. m_PassWord = _T("");
  20. //}}AFX_DATA_INIT
  21. }
  22. void CUserdlg::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CUserdlg)
  26. DDX_Control(pDX, IDC_CANCEL, m_Cancel);
  27. DDX_Control(pDX, IDC_BUTTONMOD, m_ButMod);
  28. DDX_Control(pDX, IDC_BUTTONDEL, m_ButDel);
  29. DDX_Control(pDX, IDC_BUTTONADD, m_ButAdd);
  30. DDX_Control(pDX, IDC_LIST1, m_List);
  31. DDX_Text(pDX, IDC_EDIT1, m_Name);
  32. DDX_Text(pDX, IDC_EDIT2, m_PassWord);
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(CUserdlg, CDialog)
  36. //{{AFX_MSG_MAP(CUserdlg)
  37. ON_BN_CLICKED(IDC_BUTTONADD, OnButtonadd)
  38. ON_BN_CLICKED(IDC_BUTTONMOD, OnButtonmod)
  39. ON_BN_CLICKED(IDC_BUTTONDEL, OnButtondel)
  40. ON_BN_CLICKED(IDC_CANCEL, OnCancel)
  41. ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CUserdlg message handlers
  46. void CUserdlg::OnButtonadd() 
  47. {
  48. // TODO: Add your control notification handler code here
  49. UpdateData(TRUE);
  50. if(m_Name.IsEmpty() || m_PassWord.IsEmpty())
  51. {
  52. MessageBox("用户名或密码不能为空");
  53. return;
  54. }
  55. ADOConn m_AdoConn;
  56. m_AdoConn.OnInitADOConn();
  57. CString sql;
  58. sql.Format("insert into tb_user (用户名,密码) values ('%s','%s')",
  59. m_Name,m_PassWord);
  60. m_AdoConn.ExecuteSQL((_bstr_t)sql);
  61. m_AdoConn.ExitConnect();
  62. m_List.DeleteAllItems();
  63. AddToList();
  64. }
  65. void CUserdlg::OnButtonmod() 
  66. {
  67. // TODO: Add your control notification handler code here
  68. UpdateData(TRUE);
  69. if(m_Name.IsEmpty() || m_PassWord.IsEmpty())
  70. {
  71. MessageBox("用户名或密码不能为空");
  72. return;
  73. }
  74. ADOConn m_AdoConn;
  75. m_AdoConn.OnInitADOConn();
  76. CString sql;
  77. sql.Format("update tb_user set 用户名='%s',密码='%s' where 用户名='%s' ",
  78. m_Name,m_PassWord,m_oName);
  79. m_AdoConn.ExecuteSQL((_bstr_t)sql);
  80. m_AdoConn.ExitConnect();
  81. m_List.DeleteAllItems();
  82. AddToList();
  83. }
  84. void CUserdlg::OnButtondel() 
  85. {
  86. // TODO: Add your control notification handler code here
  87. UpdateData(TRUE);
  88. if(m_Name.IsEmpty())
  89. {
  90. MessageBox("用户名不能为空");
  91. return;
  92. }
  93. ADOConn m_AdoConn;
  94. m_AdoConn.OnInitADOConn();
  95. CString sql;
  96. sql.Format("delete * from tb_user where 用户名='%s' ",m_Name);
  97. m_AdoConn.ExecuteSQL((_bstr_t)sql);
  98. m_AdoConn.ExitConnect();
  99. m_List.DeleteAllItems();
  100. AddToList();
  101. }
  102. BOOL CUserdlg::OnInitDialog() 
  103. {
  104. CDialog::OnInitDialog();
  105. // TODO: Add extra initialization here
  106. m_ImageList.Create(32,32,ILC_COLOR24|ILC_MASK,1,0); //创建列表视图窗口
  107. //向图像列表中添加图标
  108. m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
  109. m_List.SetImageList(&m_ImageList,LVSIL_NORMAL);
  110. AddToList();
  111. m_ButAdd.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
  112. MAKEINTRESOURCE(IDB_BUTADD1))); //设置位图
  113. m_ButAdd.SetHBitmap(LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTADD2)),
  114. LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTADD1)));
  115. m_ButMod.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
  116. MAKEINTRESOURCE(IDB_BUTMOD1))); //设置位图
  117. m_ButMod.SetHBitmap(LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTMOD2)),
  118. LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTMOD1)));
  119. m_ButDel.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
  120. MAKEINTRESOURCE(IDB_BUTDEL1))); //设置位图
  121. m_ButDel.SetHBitmap(LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTDEL2)),
  122. LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTDEL1)));
  123. m_Cancel.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
  124. MAKEINTRESOURCE(IDB_CANCEL1))); //设置位图
  125. m_Cancel.SetHBitmap(LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_CANCEL2)),
  126. LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_CANCEL1)));
  127. return TRUE;  // return TRUE unless you set the focus to a control
  128.               // EXCEPTION: OCX Property Pages should return FALSE
  129. }
  130. void CUserdlg::AddToList()
  131. {
  132. ADOConn m_AdoConn;
  133. m_AdoConn.OnInitADOConn();
  134. CString sql;
  135. sql.Format("select 用户名 from tb_user ",m_Name,m_PassWord);
  136. m_AdoConn.m_pRecordset = m_AdoConn.GetRecordSet((_bstr_t)sql);
  137. int i = 0;
  138. while(!m_AdoConn.m_pRecordset->adoEOF)
  139. {
  140. m_List.InsertItem(i,(char*)(_bstr_t)m_AdoConn.m_pRecordset->GetCollect("用户名"),0);
  141. m_AdoConn.m_pRecordset->MoveNext();
  142. i++;
  143. }
  144. m_AdoConn.ExitConnect();
  145. }
  146. void CUserdlg::OnCancel() 
  147. {
  148. // TODO: Add your control notification handler code here
  149. CDialog::OnCancel();
  150. }
  151. void CUserdlg::OnOK()
  152. {
  153. }
  154. void CUserdlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
  155. {
  156. // TODO: Add your control notification handler code here
  157. int pos = m_List.GetSelectionMark();
  158. m_Name = m_oName = m_List.GetItemText(pos,0);
  159. UpdateData(FALSE);
  160. *pResult = 0;
  161. }