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. ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
  80. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  81. //}}AFX_MSG_MAP
  82. END_MESSAGE_MAP()
  83. /////////////////////////////////////////////////////////////////////////////
  84. // COffDemoDlg message handlers
  85. BOOL COffDemoDlg::OnInitDialog()
  86. {
  87. CDialog::OnInitDialog();
  88. // Add "About..." menu item to system menu.
  89. // IDM_ABOUTBOX must be in the system command range.
  90. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  91. ASSERT(IDM_ABOUTBOX < 0xF000);
  92. CMenu* pSysMenu = GetSystemMenu(FALSE);
  93. if (pSysMenu != NULL)
  94. {
  95. CString strAboutMenu;
  96. strAboutMenu.LoadString(IDS_ABOUTBOX);
  97. if (!strAboutMenu.IsEmpty())
  98. {
  99. pSysMenu->AppendMenu(MF_SEPARATOR);
  100. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  101. }
  102. }
  103. // Set the icon for this dialog.  The framework does this automatically
  104. //  when the application's main window is not a dialog
  105. SetIcon(m_hIcon, TRUE); // Set big icon
  106. SetIcon(m_hIcon, FALSE); // Set small icon
  107. ::CoInitialize(NULL);
  108. // TODO: Add extra initialization here
  109. return TRUE;  // return TRUE  unless you set the focus to a control
  110. }
  111. void COffDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
  112. {
  113. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  114. {
  115. CAboutDlg dlgAbout;
  116. dlgAbout.DoModal();
  117. }
  118. else
  119. {
  120. CDialog::OnSysCommand(nID, lParam);
  121. }
  122. }
  123. // If you add a minimize button to your dialog, you will need the code below
  124. //  to draw the icon.  For MFC applications using the document/view model,
  125. //  this is automatically done for you by the framework.
  126. void COffDemoDlg::OnPaint() 
  127. {
  128. if (IsIconic())
  129. {
  130. CPaintDC dc(this); // device context for painting
  131. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  132. // Center icon in client rectangle
  133. int cxIcon = GetSystemMetrics(SM_CXICON);
  134. int cyIcon = GetSystemMetrics(SM_CYICON);
  135. CRect rect;
  136. GetClientRect(&rect);
  137. int x = (rect.Width() - cxIcon + 1) / 2;
  138. int y = (rect.Height() - cyIcon + 1) / 2;
  139. // Draw the icon
  140. dc.DrawIcon(x, y, m_hIcon);
  141. }
  142. else
  143. {
  144. CDialog::OnPaint();
  145. }
  146. }
  147. // The system calls this to obtain the cursor to display while the user drags
  148. //  the minimized window.
  149. HCURSOR COffDemoDlg::OnQueryDragIcon()
  150. {
  151. return (HCURSOR) m_hIcon;
  152. }
  153. void COffDemoDlg::OnButton1() 
  154. {
  155. // TODO: Add your control notification handler code here
  156. _ConnectionPtr conn;
  157. conn.CreateInstance(__uuidof(Connection));
  158. conn->Open(_bstr_t("Provider=OraOLEDB.Oracle.1;User Id=csd0910;Data Source=lisongtao"),"",_bstr_t("csd0910"),-1);
  159. rs.CreateInstance(__uuidof(Recordset));
  160. _bstr_t sqlobj("select * from mybooks");
  161. rs->Open((_variant_t)sqlobj,conn.GetInterfacePtr(),adOpenStatic,adLockOptimistic,-1);
  162.     //显示第一条记录;
  163. this->show();
  164. }
  165. //显示数据,默认为第一条
  166. void COffDemoDlg::show()
  167. {
  168. if(!rs->adEOF && !rs->BOF)
  169. {
  170. this->m_isbn=(UINT)(long)(rs->GetCollect("BOOKISNB"));
  171. this->m_name=(CString)(LPCTSTR)(_bstr_t)(rs->GetCollect("BOOKNAME"));
  172. this->UpdateData(FALSE);
  173. }
  174. }
  175. //查看后一条数据
  176. void COffDemoDlg::OnButton7() 
  177. {
  178. // TODO: Add your control notification handler code here
  179. if(!rs->adEOF)
  180. {
  181. rs->MoveNext();
  182. show();
  183. }
  184. else
  185. {
  186. MessageBox("End!!!");
  187. }
  188. }
  189. //查看前一条数据
  190. void COffDemoDlg::OnButton6() 
  191. {
  192. // TODO: Add your control notification handler code here
  193. if(!rs->BOF)
  194. {
  195. rs->MovePrevious();
  196. show();
  197. }
  198. else
  199. {
  200. MessageBox("Begin!!!");
  201. }
  202. }
  203. //显示第一条数据
  204. void COffDemoDlg::OnButton9() 
  205. {
  206. // TODO: Add your control notification handler code here
  207. if(!rs->BOF)
  208. {
  209. rs->MoveFirst();
  210. show();
  211. }
  212. else
  213. {
  214. MessageBox("Begin!!!");
  215. }
  216. }
  217. //新增记录时先清空文本框
  218. void COffDemoDlg::OnButton3() 
  219. {
  220. // TODO: Add your control notification handler code here
  221. this->m_isbn=0;
  222. this->m_name="";
  223. this->m_author="";
  224. this->UpdateData(FALSE);//(更新后)把数据送到文本框
  225. }
  226. void COffDemoDlg::OnButton2() 
  227. {
  228. // TODO: Add your control notification handler code here
  229. this->UpdateData(TRUE);
  230. this->rs->AddNew();
  231. this->rs["BOOKISNB"]=_variant_t((long)(this->m_isbn));
  232. this->rs["BOOKName"]=(_variant_t)_bstr_t(this->m_name);
  233. this->rs["BOOKAuthor"]=(_variant_t)_bstr_t(this->m_author);
  234. _variant_t vt;
  235. vt->vt=VT_I4;
  236. this->rs->Update(NULL,&vt);
  237. }