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

ActiveX/DCOM/ATL

开发平台:

Visual C++

  1. // ExparameterDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Exparameter.h"
  5. #include "ExparameterDlg.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. // CExparameterDlg dialog
  50. CExparameterDlg::CExparameterDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(CExparameterDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CExparameterDlg)
  54. m_ibsn = _T("");
  55. m_bookname = _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 CExparameterDlg::DoDataExchange(CDataExchange* pDX)
  62. {
  63. CDialog::DoDataExchange(pDX);
  64. //{{AFX_DATA_MAP(CExparameterDlg)
  65. DDX_Text(pDX, IDC_EDIT1, m_ibsn);
  66. DDX_Text(pDX, IDC_EDIT2, m_bookname);
  67. DDX_Text(pDX, IDC_EDIT3, m_author);
  68. //}}AFX_DATA_MAP
  69. }
  70. BEGIN_MESSAGE_MAP(CExparameterDlg, CDialog)
  71. //{{AFX_MSG_MAP(CExparameterDlg)
  72. ON_WM_SYSCOMMAND()
  73. ON_WM_PAINT()
  74. ON_WM_QUERYDRAGICON()
  75. ON_WM_DESTROY()
  76. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  77. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  78. //}}AFX_MSG_MAP
  79. END_MESSAGE_MAP()
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CExparameterDlg message handlers
  82. BOOL CExparameterDlg::OnInitDialog()
  83. {
  84. CDialog::OnInitDialog();
  85. // Add "About..." menu item to system menu.
  86. // IDM_ABOUTBOX must be in the system command range.
  87. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  88. ASSERT(IDM_ABOUTBOX < 0xF000);
  89. CMenu* pSysMenu = GetSystemMenu(FALSE);
  90. if (pSysMenu != NULL)
  91. {
  92. CString strAboutMenu;
  93. strAboutMenu.LoadString(IDS_ABOUTBOX);
  94. if (!strAboutMenu.IsEmpty())
  95. {
  96. pSysMenu->AppendMenu(MF_SEPARATOR);
  97. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  98. }
  99. }
  100. // Set the icon for this dialog.  The framework does this automatically
  101. //  when the application's main window is not a dialog
  102. SetIcon(m_hIcon, TRUE); // Set big icon
  103. SetIcon(m_hIcon, FALSE); // Set small icon
  104. // TODO: Add extra initialization here
  105. ::CoInitialize(NULL);
  106. return TRUE;  // return TRUE  unless you set the focus to a control
  107. }
  108. void CExparameterDlg::OnSysCommand(UINT nID, LPARAM lParam)
  109. {
  110. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  111. {
  112. CAboutDlg dlgAbout;
  113. dlgAbout.DoModal();
  114. }
  115. else
  116. {
  117. CDialog::OnSysCommand(nID, lParam);
  118. }
  119. }
  120. // If you add a minimize button to your dialog, you will need the code below
  121. //  to draw the icon.  For MFC applications using the document/view model,
  122. //  this is automatically done for you by the framework.
  123. void CExparameterDlg::OnPaint() 
  124. {
  125. if (IsIconic())
  126. {
  127. CPaintDC dc(this); // device context for painting
  128. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  129. // Center icon in client rectangle
  130. int cxIcon = GetSystemMetrics(SM_CXICON);
  131. int cyIcon = GetSystemMetrics(SM_CYICON);
  132. CRect rect;
  133. GetClientRect(&rect);
  134. int x = (rect.Width() - cxIcon + 1) / 2;
  135. int y = (rect.Height() - cyIcon + 1) / 2;
  136. // Draw the icon
  137. dc.DrawIcon(x, y, m_hIcon);
  138. }
  139. else
  140. {
  141. CDialog::OnPaint();
  142. }
  143. }
  144. // The system calls this to obtain the cursor to display while the user drags
  145. //  the minimized window.
  146. HCURSOR CExparameterDlg::OnQueryDragIcon()
  147. {
  148. return (HCURSOR) m_hIcon;
  149. }
  150. void CExparameterDlg::OnDestroy() 
  151. {
  152. CDialog::OnDestroy();
  153. // TODO: Add your message handler code here
  154. ::CoUninitialize();
  155. }
  156. void CExparameterDlg::OnButton1() 
  157. {
  158. // TODO: Add your control notification handler code here
  159. _ConnectionPtr myconn=this->GetDataConnection("tarena","scott","tiger");
  160. this->UpdateData(TRUE);
  161. CString sqlFormat="insert into ocybooks(BookIsnb,BookName,BookAuthor) values (%s,'%s','%s')";
  162. CString sql;
  163. sql.Format(sqlFormat,this->m_ibsn,this->m_bookname,this->m_author);
  164. _CommandPtr sqlobj;
  165. sqlobj.CreateInstance(__uuidof(Command));
  166. sqlobj->CommandText=_bstr_t(sql);
  167. sqlobj->CommandType=adCmdText;
  168. sqlobj->ActiveConnection=myconn;
  169. VARIANT vResult;
  170. vResult.vt =VT_I4;
  171. try{
  172. sqlobj->Execute(&vResult,NULL,adCmdText);//执行查询
  173. }
  174. catch(_com_error ex)
  175. {
  176. int i=10;
  177. i=i+1;
  178. }
  179. }
  180. _ConnectionPtr CExparameterDlg::GetDataConnection(
  181. CString datasource, CString uid, CString pwd)
  182. {
  183. CString strFormat="Provider=OraOLEDB.Oracle.1;User Id=%s;Data Source=%s";
  184. CString str;
  185. str.Format(strFormat,uid,datasource);
  186. _ConnectionPtr mytools;
  187. mytools.CreateInstance(__uuidof(Connection));
  188. mytools->Open(_bstr_t(str),"",_bstr_t(pwd),-1);
  189. return mytools;
  190. }
  191. void CExparameterDlg::OnButton2() 
  192. {
  193. // TODO: Add your control notification handler code here
  194. this->UpdateData(TRUE);
  195. _ConnectionPtr myconn=this->GetDataConnection("tarena","scott","tiger");
  196. _bstr_t sql("insert into ocyBooks(BookIsnb,BookName,BookAuthor) values (?,?,?)");
  197. _CommandPtr sqlobj;
  198. sqlobj.CreateInstance(__uuidof(Command));
  199. sqlobj->CommandType=adCmdText;//命令类型
  200. sqlobj->CommandText=sql;//命令文本
  201. _ParameterPtr para1=sqlobj->CreateParameter("id",adInteger,adParamInput,4);
  202. _ParameterPtr para2=sqlobj->CreateParameter("name",adVarChar,adParamInput,20);
  203. _ParameterPtr para3=sqlobj->CreateParameter("author",adVarChar,adParamInput,20);
  204. int id=atoi(this->m_ibsn);//字符转整形
  205.     _variant_t vid((long)id);
  206. para1->Value=vid;
  207.     para2->Value=(_variant_t)(_bstr_t)(this->m_bookname);
  208. para3->Value=(_variant_t)(_bstr_t)(this->m_author);
  209. sqlobj->Parameters->Append(para1);//追加
  210. sqlobj->Parameters->Append(para2);//追加
  211. sqlobj->Parameters->Append(para3);//追加
  212. sqlobj->ActiveConnection=myconn;
  213. VARIANT myvt;
  214. myvt.vt=VT_I4;
  215. sqlobj->Execute(&myvt,NULL,adCmdText);
  216. }