📄 gshi.cpp
字号:
// Gshi.cpp : implementation file
//
#include "stdafx.h"
#include "jeah_data.h"
#include "Gshi.h"
#include "sqltypes.h"
#include "sql.h"
#include "sqlext.h"
#include "MsgeBox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern HDBC hdbc;
extern HENV henv;
/////////////////////////////////////////////////////////////////////////////
// Gshi dialog
Gshi::Gshi(CWnd* pParent /*=NULL*/)
: CDialog(Gshi::IDD, pParent)
{
//{{AFX_DATA_INIT(Gshi)
m_kanum = _T("");
m_mima = _T("");
m_name = _T("");
//}}AFX_DATA_INIT
}
void Gshi::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Gshi)
DDX_Control(pDX, IDC_GNAM, m_gshname);
DDX_Control(pDX, IDOK2, m_ok2);
DDX_Control(pDX, IDOK, m_ok);
DDX_Text(pDX, IDC_GKNUM, m_kanum);
DDX_Text(pDX, IDC_GMIMA, m_mima);
DDX_Text(pDX, IDC_GNAME, m_name);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Gshi, CDialog)
//{{AFX_MSG_MAP(Gshi)
ON_BN_CLICKED(IDOK2, OnOk2)
ON_BN_CLICKED(IDC_GNAM, OnGnam)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Gshi message handlers
void Gshi::OnOK()
{
// TODO: Add extra validation here
int i=0;
HSTMT FAR* phstmt;
phstmt=(HSTMT FAR *)malloc(sizeof(HSTMT FAR));
UpdateData(true);
char * b;
char *rgbValue;
RETCODE rc;
SDWORD FAR *pcbValue;
CString sql;
CString sqlset;
rgbValue=(char*)malloc(200);
pcbValue=(SDWORD FAR*)malloc(sizeof(SDWORD FAR));
b=(char*)malloc(200);
sql="select 姓名,密码,注销 from 读者表 where 卡号="+m_kanum;
// AfxMessageBox(sql);
strcpy(b,sql.GetBuffer(sql.GetLength()));
// AfxMessageBox(b);
SQLAllocStmt(hdbc,phstmt);
rc=SQLExecDirect(*phstmt,(UCHAR FAR *)b,SQL_NTS);
if(rc==SQL_SUCCESS)
{
SQLFetch(*phstmt);
rc=SQLGetData(*phstmt,1,SQL_C_CHAR,rgbValue,100,pcbValue);
if(m_name==rgbValue)
{
// AfxMessageBox("haha");
rc=SQLGetData(*phstmt,2,SQL_C_CHAR,rgbValue,100,pcbValue);
if(m_mima!=rgbValue)
{
// AfxMessageBox("密码不正确,请重新输入!!");
MsgeBox mb;
mb.m_msge=_T("密码不正确\n请重新输入!");
UpdateData(false);
mb.DoModal();
i=1;
}
else
{
rc=SQLGetData(*phstmt,3,SQL_C_CHAR,rgbValue,100,pcbValue);
if(strcmp(rgbValue,"3")==0)
{
// AfxMessageBox("你的卡已被删除!!");
MsgeBox mb;
mb.m_msge=_T("\n你的卡已被删除!");
UpdateData(false);
mb.DoModal();
}
else
{
if(strcmp(rgbValue,"1")==0)
{
sqlset="select 书名 from 借书表 where 卡号=";
sqlset+=m_kanum;
strcpy(b,sqlset.GetBuffer(sqlset.GetLength()));
SQLAllocStmt(hdbc,phstmt);
rc=SQLExecDirect(*phstmt,(UCHAR FAR *)b,SQL_NTS);
SQLFetch(*phstmt);
rc=SQLGetData(*phstmt,1,SQL_C_CHAR,rgbValue,100,pcbValue);
sqlset="请你先把书:\n";
sqlset+=rgbValue;
sqlset+=" \n 先还了!";
MsgeBox mb;
mb.m_msge=_T(sqlset);
UpdateData(false);
mb.DoModal();
// AfxMessageBox(sqlset);
}
else
{
sqlset="update 读者表 set 注销=2 where 卡号=";
sqlset+=m_kanum;
strcpy(b,sqlset.GetBuffer(sqlset.GetLength()));
SQLAllocStmt(hdbc,phstmt);
rc=SQLExecDirect(*phstmt,(UCHAR FAR *)b,SQL_NTS);
if(rc==SQL_SUCCESS)
{
//AfxMessageBox("系统已登记!");
MsgeBox mb;
mb.m_msge=_T("\n系统已登记!");
UpdateData(false);
mb.DoModal();
m_kanum=_T("");
m_name=_T("");
m_mima=_T("");
UpdateData(false);
}
}
}
}
}
else
{
// AfxMessageBox("卡号与姓名不匹配!");
MsgeBox mb;
mb.m_msge=_T("\n卡号与姓名不匹配!");
UpdateData(false);
mb.DoModal();
i=1;
}
}
else
{
// AfxMessageBox("请正确输入!!");
MsgeBox mb;
mb.m_msge=_T("\n请正确输入!");
UpdateData(false);
mb.DoModal();
i=1;
}
sql.ReleaseBuffer(sql.GetLength());
free(b);
free(rgbValue);
free(pcbValue);
if(i=1)
{
char sourcename[30],username[10],password[10];
strcpy(sourcename,"jeah_data_1");
strcpy(username,"sa");
strcpy(password,"jeah");
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(hdbc);
SQLAllocEnv(&henv);
SQLAllocConnect(henv,&hdbc);
SQLConnect(hdbc,(UCHAR*)sourcename,SQL_NTS,(UCHAR*)username,
SQL_NTS,(UCHAR*)password,SQL_NTS);
}
}
void Gshi::OnOk2()
{
// TODO: Add your control notification handler code here
CDialog::OnOK();
}
void Gshi::OnGnam()
{
// TODO: Add your control notification handler code here
HSTMT FAR* phstmt;
phstmt=(HSTMT FAR *)malloc(sizeof(HSTMT FAR));
UpdateData(true);
char * b;
char *rgbValue;
RETCODE rc;
SDWORD FAR *pcbValue;
rgbValue=(char*)malloc(200);
pcbValue=(SDWORD FAR*)malloc(sizeof(SDWORD FAR));
b=(char*)malloc(200);
CString sql;
sql="select 姓名 from 读者表 where 卡号="+m_kanum;
strcpy(b,sql.GetBuffer(sql.GetLength()));
SQLAllocStmt(hdbc,phstmt);
rc=SQLExecDirect(*phstmt,(UCHAR FAR *)b,SQL_NTS);
if(rc==SQL_SUCCESS)
{
SQLFetch(*phstmt);
rc=SQLGetData(*phstmt,1,SQL_C_CHAR,rgbValue,100,pcbValue);
if(rc==SQL_SUCCESS)
{
m_name=rgbValue;
UpdateData(false);
GetDlgItem(IDC_GMIMA)->SetFocus();
}
else
{
// AfxMessageBox("找不到与此卡号对应的姓名!");
MsgeBox mb;
mb.m_msge=_T("\n找不到与此卡号对应的姓名!");
UpdateData(false);
mb.DoModal();
}
}
else
{
// AfxMessageBox("请正确输入!!");
MsgeBox mb;
mb.m_msge=_T("\n请正确输入!");
UpdateData(false);
mb.DoModal();
}
sql.ReleaseBuffer(sql.GetLength());
free(b);
free(rgbValue);
free(pcbValue);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -