?? student2view.cpp
字號:
// student2View.cpp : implementation of the CStudent2View class
//
#include "stdafx.h"
#include "student2.h"
#include "student2Set.h"
#include "student2Doc.h"
#include "student2View.h"
#include "Student.h"
#include "Dept.h"
#include "Banji.h"
#include "College.h"
#include "ScoreDlg.h"
#include "Paiming.h"
#include "MainFrm.h"
#include "Entry.h"
#include "XiugaiDlag.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStudent2View
IMPLEMENT_DYNCREATE(CStudent2View, CRecordView)
BEGIN_MESSAGE_MAP(CStudent2View, CRecordView)
//{{AFX_MSG_MAP(CStudent2View)
ON_BN_CLICKED(IDC_BUTTON_View, OnBUTTONView)
ON_BN_CLICKED(IDC_REC_ADD, OnRecAdd)
ON_BN_CLICKED(IDC_REC_EDIT, OnRecEdit)
ON_BN_CLICKED(IDC_REC_DEL, OnRecDel)
ON_BN_CLICKED(IDC_BUTTONFind, OnBUTTONFind)
ON_BN_CLICKED(IDC_BUTTONFinddel, OnBUTTONFinddel)
ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE, OnSelchangedTree)
ON_BN_CLICKED(IDC_BUTTON_SORT, OnButtonSort)
ON_BN_CLICKED(IDC_BUTTON_ENTRY, OnButtonEntry)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStudent2View construction/destruction
CStudent2View::CStudent2View()
: CRecordView(CStudent2View::IDD)
{
//{{AFX_DATA_INIT(CStudent2View)
m_pSet = NULL;
m_StrQuery = _T("");
m_score = _T("");
m_scorno = _T("");
m_xueyuan1 = _T("");
m_deptname1 = _T("");
m_stuname = _T("");
m_stuno = _T("");
m_zzmm = _T("");
m_dhhm = _T("");
m_jtzz = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
m_strSQL=_T("");
m_stuid=_T("");
m_name=_T("");
m_sex=_T("");
m_chengji=0;
m_xuefen=0;
m_xueyuan=_T("");
m_deptname=_T("");
m_class=_T("");
m_political=_T("");
m_address=_T("");
m_tel=_T("");
m_birthday=_T("");
m_banjino=0;
}
CStudent2View::~CStudent2View()
{
}
void CStudent2View::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStudent2View)
DDX_Control(pDX, IDC_EDIT_SHOW, m_show);
DDX_Control(pDX, IDC_TREE1, m_tcTest);
DDX_Text(pDX, IDC_EDIT7, m_StrQuery);
DDX_Text(pDX, IDC_EDIT3, m_score);
DDX_Text(pDX, IDC_EDIT4, m_scorno);
DDX_Text(pDX, IDC_EDIT5, m_xueyuan1);
DDX_Text(pDX, IDC_EDIT6, m_deptname1);
DDX_Text(pDX, IDC_EDIT2, m_stuname);
DDX_Text(pDX, IDC_EDIT1, m_stuno);
DDX_Text(pDX, IDC_ZZMM, m_zzmm);
DDX_Text(pDX, IDC_DHHM, m_dhhm);
DDX_Text(pDX, IDC_JTZZ, m_jtzz);
//}}AFX_DATA_MAP
DDX_Control(pDX,IDC_DATAGRID,m_DataGrid);
}
BOOL CStudent2View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CStudent2View::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_student2Set;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
//CEntry dlg;
m_show.SetWindowText(STR_EDIT_SHOW);
InitTreeList(); //初始化TreeList控件
// m_pSet->m_stuno="";
// UpdateData(FALSE);
UpdateData(TRUE); //連接數據庫
try
{
m_Connection.CreateInstance(__uuidof(Connection));
m_Recordset.CreateInstance(__uuidof(Recordset));
m_Connection->Open("DSN=studentsn","","",-1);
}
catch(_com_error &e)
{
MessageBox(e.Description());
}
catch(...){}
UpdateData(FALSE);
}
/////////////////////////////////////////////////////////////////////////////
// CStudent2View printing
BOOL CStudent2View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CStudent2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CStudent2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CStudent2View diagnostics
#ifdef _DEBUG
void CStudent2View::AssertValid() const
{
CRecordView::AssertValid();
}
void CStudent2View::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CStudent2Doc* CStudent2View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CStudent2Doc)));
return (CStudent2Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CStudent2View database support
CRecordset* CStudent2View::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CStudent2View message handlers
void CStudent2View::InitTreeList() //初始化TreeList控件
{
// 清空原有項目
m_tcTest.DeleteAllItems();
HTREEITEM root=m_tcTest.InsertItem("西安工程大學",0,0);
// 學院查詢
CString strCollageQuery;
strCollageQuery = "SELECT * FROM college ORDER BY collegeno ASC";
CDatabase db1;
CCollege xy(&db1);
xy.Open(AFX_DB_USE_DEFAULT_TYPE, strCollageQuery);
// 插入學院名
while(!xy.IsEOF())
{
HTREEITEM subroot = m_tcTest.InsertItem(xy.m_collegename,1,1,root);
//設置學院ID
m_tcTest.SetItemData(subroot,xy.m_collegeno);
// 查詢學院下專業
//CString strCollageQuery;
strCollageQuery.Format("SELECT * FROM dept WHERE collegeno = %d",xy.m_collegeno);
CDatabase db2;
CDept zy(&db2);
zy.Open(AFX_DB_USE_DEFAULT_TYPE,strCollageQuery);
HTREEITEM zhuanye;
//插入專業
while(!zy.IsEOF())
{
// 插入專業
zhuanye = m_tcTest.InsertItem(zy.m_deptname,1,1,subroot);
// 設置專業ID
m_tcTest.SetItemData(zhuanye, zy.m_deptno);
CString strClassQuery;
strClassQuery.Format("SELECT * FROM class WHERE deptno = %d",
zy.m_deptno);
CDatabase db3;
CBanji bj(&db3);
bj.Open(AFX_DB_USE_DEFAULT_TYPE, strClassQuery);
//插入班級
while(!bj.IsEOF())
{
HTREEITEM banji = m_tcTest.InsertItem(bj.m_classname,zhuanye);
// 設置班級ID
m_tcTest.SetItemData(banji, bj.m_classno);
bj.MoveNext();
}
db3.Close();
zy.MoveNext();
}
db2.Close();
xy.MoveNext();
}
db1.Close();
}
void CStudent2View::OnBUTTONView() //瀏覽所有記錄按鈕命令消息處理函數
{
// TODO: Add your control notification handler code here
if(m_flag==1)
{
switch(m_tcTest.GetItemData(hItem))
{
case 101:
m_strSQL.Format("select * from student WHERE classno = %d",101);
break;
case 102:
m_strSQL.Format("select * from student WHERE classno = %d",102);
break;
case 103:
m_strSQL.Format("select * from student WHERE classno = %d",103);
break;
case 104:
m_strSQL.Format("select * from student WHERE classno = %d",104);
break;
case 105:
m_strSQL.Format("select * from student WHERE classno = %d",105);
break;
case 106:
m_strSQL.Format("select * from student WHERE classno = %d",106);
break;
default:
m_strSQL.Format("select * from student WHERE classno = %d",5664);
break;
}
try
{
m_Recordset.CreateInstance(__uuidof(Recordset));
UpdateData(TRUE);
m_Connection->CursorLocation=adUseClient;
m_Recordset->Open(m_strSQL.GetBuffer(0),
m_Connection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,adCmdText);
}
catch(_com_error &e)
{
MessageBox(e.Description());
}
catch(...){}
m_DataGrid.SetRefDataSource((LPUNKNOWN)m_Recordset);
m_DataGrid.Refresh();
UpdateData(FALSE);
}
else
AfxMessageBox("請選擇你的班級!");
}
void CStudent2View::OnRecAdd() //添加按鈕命令消息處理函數
{
// TODO: Add your control notification handler code here
CScoreDlg dlg;
CString strsex,strdata;
if(dlg.DoModal()!=IDOK)return;
m_stuid=dlg.m_xuehao;
m_name=dlg.m_xingming;
m_chengji=dlg.m_chengji;
m_sex=dlg.m_xingbie;
m_xueyuan=dlg.m_xystr;
m_deptname=dlg.m_deptname;
m_xuefen=dlg.m_xuefen;
m_class=dlg.m_banji;
if(dlg.m_banji=="計算機1班")m_banjino=101;
else if(dlg.m_banji=="計算機2班")m_banjino=102;
else if (dlg.m_banji=="計算機3班")m_banjino=103;
else if (dlg.m_banji=="計算機4班")m_banjino=104;
else if (dlg.m_banji=="計算機5班")m_banjino=105;
else if(dlg.m_banji=="計算機6班")m_banjino=106;
else if(dlg.m_banji=="教育1班")m_banjino=201;
else if(dlg.m_banji=="教育2班")m_banjino=202;
else if(dlg.m_banji=="信科1班")m_banjino=301;
else if(dlg.m_banji=="信科2班")m_banjino=302;
else if(dlg.m_banji=="工業設計1班")m_banjino=401;
else if(dlg.m_banji=="工業設計2班")m_banjino=402;
else if(dlg.m_banji=="機械及自動化1班")m_banjino=501;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -