📄 inputlocationsdlg.cpp
字号:
// InputLocationsDlg.cpp : implementation file
//
#include <string.h>
#include <iomanip.h>
#include "stdafx.h"
#include "HRDB.h"
#include "InputLocationsDlg.h"
#include "desexec.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//引入全局SQL环境变量
extern SQLHENV henv;
extern SQLHDBC hdbc;
extern SQLHSTMT hstmt;
extern SQLRETURN retcode;
/////////////////////////////////////////////////////////////////////////////
// CInputLocationsDlg dialog
CInputLocationsDlg::CInputLocationsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CInputLocationsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CInputLocationsDlg)
m_strLCountryID = _T("");
m_strPostalCode = _T("");
m_intLocationID = 0;
m_strStateProvince = _T("");
m_strStreetAddress = _T("");
m_strCity = _T("");
//}}AFX_DATA_INIT
}
void CInputLocationsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CInputLocationsDlg)
DDX_Control(pDX, IDC_INPUT_CITY, m_editCity);
DDX_Control(pDX, IDC_INPUT_STREET_ADDRESS, m_editStreetAddress);
DDX_Control(pDX, IDC_INPUT_STATE_PROVINCE, m_editStateProvince);
DDX_Control(pDX, IDC_INPUT_LOCATION_ID, m_editLocationID);
DDX_Control(pDX, IDC_INPUT_POSTAL_CODE, m_editPostalCode);
DDX_Control(pDX, IDC_INPUT_L_COUNTRY_ID, m_editLCountryID);
DDX_Text(pDX, IDC_INPUT_L_COUNTRY_ID, m_strLCountryID);
DDX_Text(pDX, IDC_INPUT_POSTAL_CODE, m_strPostalCode);
DDX_Text(pDX, IDC_INPUT_LOCATION_ID, m_intLocationID);
DDX_Text(pDX, IDC_INPUT_STATE_PROVINCE, m_strStateProvince);
DDX_Text(pDX, IDC_INPUT_STREET_ADDRESS, m_strStreetAddress);
DDX_Text(pDX, IDC_INPUT_CITY, m_strCity);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CInputLocationsDlg, CDialog)
//{{AFX_MSG_MAP(CInputLocationsDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInputLocationsDlg message handlers
BOOL CInputLocationsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CInputLocationsDlg::OnCancel()
{
CDialog::OnCancel();
}
void CInputLocationsDlg::OnOK()
{
// 使用参数绑定的方法向表中插入数据
SQLUINTEGER location_id;
SQLVARCHAR street_address[40];
SQLVARCHAR postal_code[12];
SQLVARCHAR city[30];
SQLVARCHAR state_province[25];
SQLCHAR country_id[2];
SQLINTEGER location_idInd = 0, street_addressLenOrInd = 0, postal_codeLenOrInd = 0;
SQLINTEGER cityLenOrInd = 0, state_provinceLenOrInd = 0, country_idLenOrInd = 0;
// 准备包含参数标志符的SQL语句
TODBCs( hstmt, SQLPrepare( hstmt,
(unsigned char *)"insert into locations (location_id, street_address, postal_code, \
city, state_province, country_id) Values (?, ?, ?, ?, ?, ?)", SQL_NTS ) );
// 为每一个参数都调用函数SQLBindParameter, 绑定相应的参数
TODBCs( hstmt, SQLBindParameter( hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER,
4, 0, &location_id, 0, &location_idInd ) );
TODBCs( hstmt, SQLBindParameter( hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
40, 0, street_address, sizeof(street_address), &street_addressLenOrInd ) );
TODBCs( hstmt, SQLBindParameter( hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
12, 0, postal_code, sizeof(postal_code), &postal_codeLenOrInd ) );
TODBCs( hstmt, SQLBindParameter( hstmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
30, 0, city, sizeof(city), &cityLenOrInd ) );
TODBCs( hstmt, SQLBindParameter( hstmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
25, 0, state_province, sizeof(state_province), &state_provinceLenOrInd ) );
TODBCs( hstmt, SQLBindParameter( hstmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
2, 0, country_id, sizeof(country_id), &country_idLenOrInd ) );
// 先给参数变量赋值,然后执行SQL语句,向表中插入新记录
UpdateData(TRUE); //更新控件关联变量
location_id = m_intLocationID;
strcpy( (char *)street_address, m_strStreetAddress);
strcpy( (char *)postal_code, m_strPostalCode);
strcpy( (char *)city, m_strCity);
strcpy( (char *)state_province, m_strStateProvince);
strcpy( (char *)country_id, m_strLCountryID);
street_addressLenOrInd = SQL_NTS;
postal_codeLenOrInd = SQL_NTS;
cityLenOrInd = SQL_NTS;
state_provinceLenOrInd = SQL_NTS;
country_idLenOrInd = SQL_NTS;
retcode = TODBCs( hstmt, SQLExecute(hstmt) );
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
{
//捕获异常
AfxMessageBox("无权添加,或添加失败!");
}
// 释放绑定的参数
TODBCs( hstmt, SQLFreeStmt( hstmt, SQL_RESET_PARAMS ) );
// 释放绑定的参数
TODBCs( hstmt, SQLFreeStmt( hstmt, SQL_UNBIND ) );
m_editLocationID.SetWindowText("");
m_editStreetAddress.SetWindowText("");
m_editPostalCode.SetWindowText("");
m_editCity.SetWindowText("");
m_editStateProvince.SetWindowText("");
m_editLCountryID.SetWindowText("");
//CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -