📄 student.cpp
字号:
// student.cpp : implementation file
//
#include "stdafx.h"
#include "mark.h"
#include "student.h"
#include "MainFrm.h"
#include "adodc.h"
#include "_recordset.h"
#include "fields.h"
#include "field.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Cstudent
IMPLEMENT_DYNCREATE(Cstudent, CFormView)
Cstudent::Cstudent()
: CFormView(Cstudent::IDD)
{
//{{AFX_DATA_INIT(Cstudent)
m_yuanxi = _T("");
m_banji = _T("");
m_xuehao = _T("");
m_xingming = _T("");
m_xingbie = _T("");
//}}AFX_DATA_INIT
}
Cstudent::~Cstudent()
{
}
void Cstudent::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Cstudent)
DDX_Control(pDX, IDC_ADODC1, m_ado);
DDX_Text(pDX, IDC_EDIT1, m_yuanxi);
DDX_Text(pDX, IDC_EDIT2, m_banji);
DDX_Text(pDX, IDC_EDIT3, m_xuehao);
DDX_Text(pDX, IDC_EDIT4, m_xingming);
DDX_Text(pDX, IDC_EDIT5, m_xingbie);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Cstudent, CFormView)
//{{AFX_MSG_MAP(Cstudent)
ON_WM_CREATE()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Cstudent diagnostics
#ifdef _DEBUG
void Cstudent::AssertValid() const
{
CFormView::AssertValid();
}
void Cstudent::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// Cstudent message handlers
int Cstudent::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFormView::OnCreate(lpCreateStruct) == -1)
return -1;
//CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
//CAdodc *ado=(CAdodc *)GetDlgItem(IDC_ADODC1);
//CString cnstr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=hello;Pwd=panpan;Initial Catalog=student;Data Source="+pframe->connectip;
//ado->SetConnectionString(cnstr);
//ado->Refresh();
return 0;
}
void Cstudent::OnButton1()
{
CString yx,bj,xh,xm,xb;
CEdit *yuanxi=(CEdit *)GetDlgItem(IDC_EDIT1);
CEdit *banji=(CEdit *)GetDlgItem(IDC_EDIT2);
CEdit *xuehao=(CEdit *)GetDlgItem(IDC_EDIT3);
CEdit *xingming=(CEdit *)GetDlgItem(IDC_EDIT4);
CEdit *xingbie=(CEdit *)GetDlgItem(IDC_EDIT5);
yuanxi->GetWindowText(yx);
banji->GetWindowText(bj);
xuehao->GetWindowText(xh);
xingming->GetWindowText(xm);
xingbie->GetWindowText(xb);
CAdodc *adodc1=(CAdodc *)GetDlgItem(IDC_ADODC1);
adodc1->GetRecordset().AddNew(COleVariant("学号"),COleVariant(xh));
adodc1->GetRecordset().GetFields().GetItem(COleVariant("姓名")).SetValue(COleVariant(xm));
adodc1->GetRecordset().GetFields().GetItem(COleVariant("院系")).SetValue(COleVariant(yx));
adodc1->GetRecordset().GetFields().GetItem(COleVariant("班级")).SetValue(COleVariant(bj));
adodc1->GetRecordset().GetFields().GetItem(COleVariant("性别")).SetValue(COleVariant(xb));
adodc1->GetRecordset().GetFields().GetItem(COleVariant("是否注册")).SetValue(COleVariant("否"));
xuehao->SetWindowText("");
xingming->SetWindowText("");
xingbie->SetWindowText("");
xuehao->SetFocus();
CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
pframe->Agenttalk("你增加了一位名叫 "+xm+" 的学生。");
}
void Cstudent::OnButton2()
{
bool isfind=false;
CEdit *find=(CEdit *)GetDlgItem(IDC_EDIT6);
CString findstr;
find->GetWindowText(findstr);
if(findstr==""){
CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
pframe->Agenttalk("查找的学号不能为空!");
return;
}
CAdodc *adodc2=(CAdodc *)GetDlgItem(IDC_ADODC1);
long i=adodc2->GetRecordset().GetAbsolutePosition();
adodc2->GetRecordset().MoveFirst();
while(!adodc2->GetRecordset().GetEof()){
COleVariant temp=adodc2->GetRecordset().GetFields().GetItem(COleVariant("学号")).GetValue();
if(COleVariant(findstr)==temp){
isfind=true;
break;
}
adodc2->GetRecordset().MoveNext();
}
if(!isfind){
adodc2->GetRecordset().SetAbsolutePosition(i);
CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
pframe->Agenttalk("没有找到学号为 "+findstr+" 的学生。");
find->SetWindowText("");
find->SetFocus();
}
}
void Cstudent::OnButton3()
{
bool isfound=false;
CEdit *found=(CEdit *)GetDlgItem(IDC_EDIT7);
CString foundstr;
found->GetWindowText(foundstr);
if(foundstr==""){
CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
pframe->Agenttalk("查找的姓名不能为空!");
return;
}
CAdodc *adodc3=(CAdodc *)GetDlgItem(IDC_ADODC1);
long i=adodc3->GetRecordset().GetAbsolutePosition();
adodc3->GetRecordset().MoveFirst();
while(!adodc3->GetRecordset().GetEof()){
COleVariant temp=adodc3->GetRecordset().GetFields().GetItem(COleVariant("姓名")).GetValue();
if(COleVariant(foundstr)==temp){
isfound=true;
break;
}
adodc3->GetRecordset().MoveNext();
}
if(!isfound){
adodc3->GetRecordset().SetAbsolutePosition(i);
CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
pframe->Agenttalk("没有找到名叫 "+foundstr+" 的学生。");
found->SetWindowText("");
found->SetFocus();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -