AddressAdminDlg.cpp
上传用户:weisheen
上传日期:2022-07-09
资源大小:19390k
文件大小:7k
源码类别:

ActiveX/DCOM/ATL

开发平台:

Visual C++

  1. // AddressAdminDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "AddressAdmin.h"
  5. #include "AddressAdminDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CAboutDlg dialog used for App About
  13. class CAboutDlg : public CDialog
  14. {
  15. public:
  16. CAboutDlg();
  17. // Dialog Data
  18. //{{AFX_DATA(CAboutDlg)
  19. enum { IDD = IDD_ABOUTBOX };
  20. //}}AFX_DATA
  21. // ClassWizard generated virtual function overrides
  22. //{{AFX_VIRTUAL(CAboutDlg)
  23. protected:
  24. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  25. //}}AFX_VIRTUAL
  26. // Implementation
  27. protected:
  28. //{{AFX_MSG(CAboutDlg)
  29. //}}AFX_MSG
  30. DECLARE_MESSAGE_MAP()
  31. };
  32. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  33. {
  34. //{{AFX_DATA_INIT(CAboutDlg)
  35. //}}AFX_DATA_INIT
  36. }
  37. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CAboutDlg)
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  44. //{{AFX_MSG_MAP(CAboutDlg)
  45. // No message handlers
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CAddressAdminDlg dialog
  50. CAddressAdminDlg::CAddressAdminDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(CAddressAdminDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CAddressAdminDlg)
  54. m_name = _T("");
  55. m_age = _T("");
  56. m_sex = _T("");
  57. m_address = _T("");
  58. //}}AFX_DATA_INIT
  59. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  60. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  61. }
  62. void CAddressAdminDlg::DoDataExchange(CDataExchange* pDX)
  63. {
  64. CDialog::DoDataExchange(pDX);
  65. //{{AFX_DATA_MAP(CAddressAdminDlg)
  66. DDX_Text(pDX, IDC_EDIT1, m_name);
  67. DDX_Text(pDX, IDC_EDIT2, m_age);
  68. DDX_Text(pDX, IDC_EDIT3, m_sex);
  69. DDX_Text(pDX, IDC_EDIT4, m_address);
  70. //}}AFX_DATA_MAP
  71. }
  72. BEGIN_MESSAGE_MAP(CAddressAdminDlg, CDialog)
  73. //{{AFX_MSG_MAP(CAddressAdminDlg)
  74. ON_WM_SYSCOMMAND()
  75. ON_WM_PAINT()
  76. ON_WM_QUERYDRAGICON()
  77. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  78. ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
  79. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  80. ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
  81. ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
  82. //}}AFX_MSG_MAP
  83. END_MESSAGE_MAP()
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CAddressAdminDlg message handlers
  86. BOOL CAddressAdminDlg::OnInitDialog()
  87. {
  88. CDialog::OnInitDialog();
  89. // Add "About..." menu item to system menu.
  90. // IDM_ABOUTBOX must be in the system command range.
  91. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  92. ASSERT(IDM_ABOUTBOX < 0xF000);
  93. CMenu* pSysMenu = GetSystemMenu(FALSE);
  94. if (pSysMenu != NULL)
  95. {
  96. CString strAboutMenu;
  97. strAboutMenu.LoadString(IDS_ABOUTBOX);
  98. if (!strAboutMenu.IsEmpty())
  99. {
  100. pSysMenu->AppendMenu(MF_SEPARATOR);
  101. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  102. }
  103. }
  104. // Set the icon for this dialog.  The framework does this automatically
  105. //  when the application's main window is not a dialog
  106. SetIcon(m_hIcon, TRUE); // Set big icon
  107. SetIcon(m_hIcon, FALSE); // Set small icon
  108. ::CoInitialize(NULL);
  109. // TODO: Add extra initialization here
  110. return TRUE;  // return TRUE  unless you set the focus to a control
  111. }
  112. void CAddressAdminDlg::OnSysCommand(UINT nID, LPARAM lParam)
  113. {
  114. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  115. {
  116. CAboutDlg dlgAbout;
  117. dlgAbout.DoModal();
  118. }
  119. else
  120. {
  121. CDialog::OnSysCommand(nID, lParam);
  122. }
  123. }
  124. // If you add a minimize button to your dialog, you will need the code below
  125. //  to draw the icon.  For MFC applications using the document/view model,
  126. //  this is automatically done for you by the framework.
  127. void CAddressAdminDlg::OnPaint() 
  128. {
  129. if (IsIconic())
  130. {
  131. CPaintDC dc(this); // device context for painting
  132. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  133. // Center icon in client rectangle
  134. int cxIcon = GetSystemMetrics(SM_CXICON);
  135. int cyIcon = GetSystemMetrics(SM_CYICON);
  136. CRect rect;
  137. GetClientRect(&rect);
  138. int x = (rect.Width() - cxIcon + 1) / 2;
  139. int y = (rect.Height() - cyIcon + 1) / 2;
  140. // Draw the icon
  141. dc.DrawIcon(x, y, m_hIcon);
  142. }
  143. else
  144. {
  145. CDialog::OnPaint();
  146. }
  147. }
  148. // The system calls this to obtain the cursor to display while the user drags
  149. //  the minimized window.
  150. HCURSOR CAddressAdminDlg::OnQueryDragIcon()
  151. {
  152. return (HCURSOR) m_hIcon;
  153. }
  154. //显示第一条记录
  155. void CAddressAdminDlg::OnButton1() 
  156. {
  157. // TODO: Add your control notification handler code here
  158. _ConnectionPtr conn;
  159. conn.CreateInstance(__uuidof(Connection));
  160. conn->Open(_bstr_t("Provider=OraOLEDB.Oracle.1;User Id=scott;Data Source=tarena"),"",_bstr_t("tiger"),-1);
  161. rs.CreateInstance(__uuidof(Recordset));
  162. _bstr_t sqlobj("select * from ocyadmin");
  163. rs->Open((_variant_t)sqlobj,
  164. conn.GetInterfacePtr(),
  165. adOpenStatic,
  166. adLockBatchOptimistic,
  167. -1);
  168.     //显示第一条记录;
  169. if(!rs->BOF)
  170. {
  171. rs->MoveFirst();
  172. show();
  173. }
  174. else
  175. {
  176. MessageBox("Begin!!!");
  177. }
  178. }
  179. void CAddressAdminDlg::show()
  180. {
  181. if(!rs->adEOF && !rs->BOF)
  182. {
  183. this->m_name=(CString)(LPCTSTR)(_bstr_t)(rs->GetCollect("Name"));
  184. this->m_age=(CString)(LPCTSTR)(_bstr_t)(rs->GetCollect("age"));
  185. this->m_sex=(CString)(LPCTSTR)(_bstr_t)(rs->GetCollect("sex"));
  186. this->m_address=(CString)(LPCTSTR)(_bstr_t)(rs->GetCollect("address"));
  187. this->UpdateData(FALSE);
  188. }
  189. }
  190. //显示最后一条记录
  191. void CAddressAdminDlg::OnButton4() 
  192. {
  193. // TODO: Add your control notification handler code here
  194. if(!rs->EOF)
  195. {
  196. rs->MoveFirst();
  197. show();
  198. }
  199. else
  200. {
  201. MessageBox("Begin!!!");
  202. }
  203. }
  204. //查看前一条数据
  205. void CAddressAdminDlg::OnButton2() 
  206. {
  207. // TODO: Add your control notification handler code here
  208. if(!rs->BOF)
  209. {
  210. rs->MovePrevious();
  211. show();
  212. }
  213. else
  214. {
  215. MessageBox("Begin!!!");
  216. }
  217. }
  218. //查看后一条数据
  219. void CAddressAdminDlg::OnButton3() 
  220. {
  221. // TODO: Add your control notification handler code here
  222. if(!rs->adEOF)
  223. {
  224. rs->MoveNext();
  225. show();
  226. }
  227. else
  228. {
  229. MessageBox("End!!!");
  230. }
  231. }
  232. void CAddressAdminDlg::OnButton5() 
  233. {
  234. // TODO: Add your control notification handler code here
  235. this->m_name="";
  236. this->m_age="";
  237. this->m_sex="";
  238. this->m_address="";
  239. this->UpdateData(FALSE);
  240. this->UpdateData(TRUE);
  241. this->rs->AddNew();
  242. this->rs->GetFields()->GetItem("name")->Value=_variant_t(this->m_name.AllocSysString());
  243. this->rs->GetFields()->GetItem("age")->Value=_variant_t(this->m_age.AllocSysString());
  244. this->rs->GetFields()->GetItem("sex")->Value=_variant_t(this->m_sex.AllocSysString());
  245. this->rs->GetFields()->GetItem("sex")->Value=_variant_t(this->m_address.AllocSysString());
  246. this->rs->Update();
  247. this->rs->UpdateBatch(adAffectAll);
  248. }