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

ActiveX/DCOM/ATL

开发平台:

Visual C++

  1. // OffDemoDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "OffDemo.h"
  5. #include "OffDemoDlg.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. // COffDemoDlg dialog
  50. COffDemoDlg::COffDemoDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(COffDemoDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(COffDemoDlg)
  54. m_isbn = 0;
  55. m_name = _T("");
  56. m_author = _T("");
  57. //}}AFX_DATA_INIT
  58. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  59. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  60. }
  61. void COffDemoDlg::DoDataExchange(CDataExchange* pDX)
  62. {
  63. CDialog::DoDataExchange(pDX);
  64. //{{AFX_DATA_MAP(COffDemoDlg)
  65. DDX_Text(pDX, IDC_EDIT1, m_isbn);
  66. DDX_Text(pDX, IDC_EDIT2, m_name);
  67. DDX_Text(pDX, IDC_EDIT3, m_author);
  68. //}}AFX_DATA_MAP
  69. }
  70. BEGIN_MESSAGE_MAP(COffDemoDlg, CDialog)
  71. //{{AFX_MSG_MAP(COffDemoDlg)
  72. ON_WM_SYSCOMMAND()
  73. ON_WM_PAINT()
  74. ON_WM_QUERYDRAGICON()
  75. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  76. ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
  77. ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
  78. ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
  79. //}}AFX_MSG_MAP
  80. END_MESSAGE_MAP()
  81. /////////////////////////////////////////////////////////////////////////////
  82. // COffDemoDlg message handlers
  83. BOOL COffDemoDlg::OnInitDialog()
  84. {
  85. CDialog::OnInitDialog();
  86. // Add "About..." menu item to system menu.
  87. // IDM_ABOUTBOX must be in the system command range.
  88. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  89. ASSERT(IDM_ABOUTBOX < 0xF000);
  90. CMenu* pSysMenu = GetSystemMenu(FALSE);
  91. if (pSysMenu != NULL)
  92. {
  93. CString strAboutMenu;
  94. strAboutMenu.LoadString(IDS_ABOUTBOX);
  95. if (!strAboutMenu.IsEmpty())
  96. {
  97. pSysMenu->AppendMenu(MF_SEPARATOR);
  98. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  99. }
  100. }
  101. // Set the icon for this dialog.  The framework does this automatically
  102. //  when the application's main window is not a dialog
  103. SetIcon(m_hIcon, TRUE); // Set big icon
  104. SetIcon(m_hIcon, FALSE); // Set small icon
  105. ::CoInitialize(NULL);
  106. // TODO: Add extra initialization here
  107. return TRUE;  // return TRUE  unless you set the focus to a control
  108. }
  109. void COffDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
  110. {
  111. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  112. {
  113. CAboutDlg dlgAbout;
  114. dlgAbout.DoModal();
  115. }
  116. else
  117. {
  118. CDialog::OnSysCommand(nID, lParam);
  119. }
  120. }
  121. // If you add a minimize button to your dialog, you will need the code below
  122. //  to draw the icon.  For MFC applications using the document/view model,
  123. //  this is automatically done for you by the framework.
  124. void COffDemoDlg::OnPaint() 
  125. {
  126. if (IsIconic())
  127. {
  128. CPaintDC dc(this); // device context for painting
  129. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  130. // Center icon in client rectangle
  131. int cxIcon = GetSystemMetrics(SM_CXICON);
  132. int cyIcon = GetSystemMetrics(SM_CYICON);
  133. CRect rect;
  134. GetClientRect(&rect);
  135. int x = (rect.Width() - cxIcon + 1) / 2;
  136. int y = (rect.Height() - cyIcon + 1) / 2;
  137. // Draw the icon
  138. dc.DrawIcon(x, y, m_hIcon);
  139. }
  140. else
  141. {
  142. CDialog::OnPaint();
  143. }
  144. }
  145. // The system calls this to obtain the cursor to display while the user drags
  146. //  the minimized window.
  147. HCURSOR COffDemoDlg::OnQueryDragIcon()
  148. {
  149. return (HCURSOR) m_hIcon;
  150. }
  151. void COffDemoDlg::OnButton1() 
  152. {
  153. // TODO: Add your control notification handler code here
  154. _ConnectionPtr conn;
  155. conn.CreateInstance(__uuidof(Connection));
  156. conn->Open(_bstr_t("Provider=OraOLEDB.Oracle.1;User Id=csd0910;Data Source=lisongtao"),"",_bstr_t("csd0910"),-1);
  157. rs.CreateInstance(__uuidof(Recordset));
  158. _bstr_t sqlobj("select * from mybooks");
  159. rs->Open((_variant_t)sqlobj,conn.GetInterfacePtr(),adOpenStatic,adLockOptimistic,-1);
  160.     //显示第一条记录;
  161. this->show();
  162. }
  163. //显示数据,默认为第一条
  164. void COffDemoDlg::show()
  165. {
  166. if(!rs->adEOF && !rs->BOF)
  167. {
  168. this->m_isbn=(UINT)(long)(rs->GetCollect("BOOKISNB"));
  169. this->m_name=(CString)(LPCTSTR)(_bstr_t)(rs->GetCollect("BOOKNAME"));
  170. this->UpdateData(FALSE);//(更新后)把数据送到文本框
  171. }
  172. }
  173. //查看后一条数据
  174. void COffDemoDlg::OnButton7() 
  175. {
  176. // TODO: Add your control notification handler code here
  177. if(!rs->adEOF)
  178. {
  179. rs->MoveNext();
  180. show();
  181. }
  182. else
  183. {
  184. MessageBox("End!!!");
  185. }
  186. }
  187. //查看前一条数据
  188. void COffDemoDlg::OnButton6() 
  189. {
  190. // TODO: Add your control notification handler code here
  191. if(!rs->BOF)
  192. {
  193. rs->MovePrevious();
  194. show();
  195. }
  196. else
  197. {
  198. MessageBox("Begin!!!");
  199. }
  200. }
  201. //显示第一条数据
  202. void COffDemoDlg::OnButton9() 
  203. {
  204. // TODO: Add your control notification handler code here
  205. if(!rs->BOF)
  206. {
  207. rs->MoveFirst();
  208. show();
  209. }
  210. else
  211. {
  212. MessageBox("Begin!!!");
  213. }
  214. }