📄 databaseview.cpp
字号:
// DATABASEView.cpp : implementation of the CDATABASEView class
//
#include "stdafx.h"
#include "DATABASE.h"
#include "DATABASESet.h"
#include "DATABASEDoc.h"
#include "DATABASEView.h"
#include "MainFrm.h"
#include "StuDlg.h"
#include "MakeSure.h"
#include "Xueji.h"
#include "XuejiDlg.h"
#include "CodeSet.h"
#include "XxSet.h"
#include "XxDlg.h"
#include "Add.h"
#include "CjDlg.h"
#include "CjSet.h"
#include "KmSet.h"
#include "Search1.h"
#include "Input.h"
#include "Input0.h"
#include "PSWset.h"
#include "SEARCH2.h"
#include "Sd.h"
#include "HSearch.h"
#include "Ifo.h"
#include "IfoSet.h"
#include "KmSet2.h"
#include "AllSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDATABASEView
extern CString CurrentUser;
IMPLEMENT_DYNCREATE(CDATABASEView, CRecordView)
BEGIN_MESSAGE_MAP(CDATABASEView, CRecordView)
//{{AFX_MSG_MAP(CDATABASEView)
ON_BN_CLICKED(IDC_REC_ADD, OnRecAdd)
ON_BN_CLICKED(IDC_REC_DEL, OnRecDel)
ON_BN_CLICKED(IDC_REC_EDIT, OnRecEdit)
ON_BN_CLICKED(IDC_SORT, OnSort)
ON_BN_CLICKED(IDC_XUEJI, OnXueji)
ON_BN_CLICKED(IDC_XUANXIU, OnXuanxiu)
ON_BN_CLICKED(IDC_SCORE, OnScore)
ON_BN_CLICKED(IDC_SAERCH1, OnSaerch1)
ON_BN_CLICKED(IDC_SQL, OnSql)
ON_BN_CLICKED(IDC_SEARCH2, OnSearch2)
ON_BN_CLICKED(IDC_SHOUDONG, OnShoudong)
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_IFO, OnIfo)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CDATABASEView construction/destruction
CDATABASEView::CDATABASEView()
: CRecordView(CDATABASEView::IDD)
{
//{{AFX_DATA_INIT(CDATABASEView)
m_pSet = NULL;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CDATABASEView::~CDATABASEView()
{
}
static int i=0;
void CDATABASEView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDATABASEView)
DDX_Control(pDX, IDC_SHOUDONG, m_shoudong);
DDX_Control(pDX, IDC_REC_EDIT, m_edit);
DDX_Control(pDX, IDC_REC_ADD, m_add);
DDX_Control(pDX, IDC_REC_DEL, m_del);
DDX_Control(pDX, IDC_MSFLEXGRID, m_MSFGrid);
DDX_FieldText(pDX, IDC_PROF_CODE, m_pSet->m_profcode, m_pSet);
DDX_FieldText(pDX, IDC_STU_ID, m_pSet->m_stuid, m_pSet);
DDX_FieldText(pDX, IDC_STU_NAME, m_pSet->m_name, m_pSet);
DDX_FieldText(pDX, IDC_STU_SEX, m_pSet->m_sex, m_pSet);
DDX_FieldText(pDX, IDC_ADDR, m_pSet->m_address, m_pSet);
//}}AFX_DATA_MAP
}
BOOL CDATABASEView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CDATABASEView::OnInitialUpdate()
{
if(!i++)CheckRadioButton(IDC_SORT_ID,IDC_SORT_NAME,IDC_SORT_ID);
m_pSet = &GetDocument()->m_dATABASESet;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
//m_Brush=CreateSolidBrush(RGB(200,250,160));
//m_MSFGrid.SetBackColor(RGB(200,250,160));
//SetCheckedButton(IDC_SORT_ID);
//ResizeParentToFit();
//////---//////
if(CurrentUser=="anonymous")
{
m_del.EnableWindow(false);
m_edit.EnableWindow(false);
m_add.EnableWindow(false);
m_shoudong.EnableWindow(false);
}
while(!m_pSet->IsEOF())
{
m_pSet->MoveNext();
m_pSet->GetRecordCount();
}
m_pSet->MoveFirst();
m_MSFGrid.SetCols(m_pSet->m_nFields+1);
m_MSFGrid.SetRows(m_pSet->GetRecordCount()+1);
m_MSFGrid.SetColWidth(1,1200);
m_MSFGrid.SetColWidth(2,1200);
m_MSFGrid.SetColWidth(3,800);
m_MSFGrid.SetColWidth(4,1200);
m_MSFGrid.SetColWidth(5,3200);
m_MSFGrid.SetRow(0);
m_MSFGrid.SetCol(1);
m_MSFGrid.SetText("学号");
m_MSFGrid.SetRow(0);
m_MSFGrid.SetCol(2);
m_MSFGrid.SetText("姓名");
m_MSFGrid.SetRow(0);
m_MSFGrid.SetCol(3);
m_MSFGrid.SetText("性别");
m_MSFGrid.SetRow(0);
m_MSFGrid.SetCol(4);
m_MSFGrid.SetText("专业代号");
m_MSFGrid.SetRow(0);
m_MSFGrid.SetCol(5);
m_MSFGrid.SetText("联系方式");
int iRow=1;
while(!m_pSet->IsEOF())
{
CString str;
str.Format("记录%d",iRow);
m_MSFGrid.SetRow(iRow);m_MSFGrid.SetCol(0);
m_MSFGrid.SetText(str);
m_MSFGrid.SetRow(iRow);m_MSFGrid.SetCol(1);
m_MSFGrid.SetText(m_pSet->m_stuid);
m_MSFGrid.SetRow(iRow);m_MSFGrid.SetCol(2);
m_MSFGrid.SetText(m_pSet->m_name);
m_MSFGrid.SetRow(iRow);m_MSFGrid.SetCol(3);
m_MSFGrid.SetText(m_pSet->m_sex);
m_MSFGrid.SetRow(iRow);m_MSFGrid.SetCol(4);
m_MSFGrid.SetText(m_pSet->m_profcode);
m_MSFGrid.SetRow(iRow);m_MSFGrid.SetCol(5);
m_MSFGrid.SetText(m_pSet->m_address);
iRow++;
m_pSet->MoveNext();
}
m_MSFGrid.SetRow(1);
m_MSFGrid.SetCol(1);
m_pSet->MoveFirst();
//////---//////
}
/////////////////////////////////////////////////////////////////////////////
// CDATABASEView printing
BOOL CDATABASEView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDATABASEView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDATABASEView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDATABASEView diagnostics
#ifdef _DEBUG
void CDATABASEView::AssertValid() const
{
CRecordView::AssertValid();
}
void CDATABASEView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CDATABASEDoc* CDATABASEView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDATABASEDoc)));
return (CDATABASEDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDATABASEView database support
CRecordset* CDATABASEView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CDATABASEView message handlers
BOOL CDATABASEView::OnCommand(WPARAM wParam, LPARAM lParam)
{
//////---//////
CString str;
CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;//获得主框架窗口的指针
CStatusBar* pStatus=&pFrame->m_wndStatusBar;
if(pStatus)
{
CRecordsetStatus rStatus;
m_pSet->GetStatus(rStatus);
str.Format("当前记录:%d总记录:%d",1+rStatus.m_lCurrentRecord,m_pSet->GetRecordCount());
pStatus->SetPaneText(1,str);
}
//////---//////
return CRecordView::OnCommand(wParam, lParam);
}
void CDATABASEView::OnRecAdd()
{
CStuDlg dlg;
if(dlg.DoModal()==IDOK){
m_pSet->AddNew();
m_pSet->m_stuid=dlg.m_StuID;
m_pSet->m_sex=dlg.m_sex;
m_pSet->m_name=dlg.m_StuName;
m_pSet->m_profcode=dlg.m_ProfCode;
m_pSet->m_address=dlg.m_address;
m_pSet->Update();
m_pSet->Requery();
AfxMessageBox("记录添加成功!");
OnInitialUpdate();
}
}
void CDATABASEView::OnRecDel()
{
CMakeSure dlg;
CXxSet xxSet;
CCjSet cjSet;
CXueji xjSet;
CIfoSet IfoSet;
if(dlg.DoModal()==IDOK)
{
CRecordsetStatus status;
xxSet.Open();
xxSet.m_strFilter.Format("stuid='%s'",m_pSet->m_stuid);
xxSet.Requery();
if(!xxSet.IsEOF()){
xxSet.GetStatus(status);
xxSet.Delete();
if(status.m_lCurrentRecord==0)
xxSet.MoveNext();
else
xxSet.MoveFirst();
xxSet.Requery();
UpdateData(FALSE);
}
xxSet.Close();
cjSet.Open();
cjSet.m_strFilter.Format("stuid='%s'",m_pSet->m_stuid);
cjSet.Requery();
if(!cjSet.IsEOF()){
cjSet.GetStatus(status);
cjSet.Delete();
if(status.m_lCurrentRecord==0)
cjSet.MoveNext();
else
cjSet.MoveFirst();
cjSet.Requery();
UpdateData(FALSE);
}
cjSet.Close();
xjSet.Open();
xjSet.m_strFilter.Format("stuid='%s'",m_pSet->m_stuid);
xjSet.Requery();
if(!xjSet.IsEOF()){
xjSet.GetStatus(status);
xjSet.Delete();
if(status.m_lCurrentRecord==0)
xjSet.MoveNext();
else
xjSet.MoveFirst();
xjSet.Requery();
UpdateData(FALSE);
}
xjSet.Close();
IfoSet.Open();
IfoSet.m_strFilter.Format("stuid='%s'",m_pSet->m_stuid);
IfoSet.Requery();
if(!IfoSet.IsEOF()){
IfoSet.GetStatus(status);
IfoSet.Delete();
if(status.m_lCurrentRecord==0)
IfoSet.MoveNext();
else
IfoSet.MoveFirst();
IfoSet.Requery();
UpdateData(FALSE);
}
IfoSet.Close();
m_pSet->GetStatus(status);
m_pSet->Delete();
if(status.m_lCurrentRecord==0)
m_pSet->MoveFirst();
else
m_pSet->MoveLast();
m_pSet->Requery();
UpdateData(FALSE);
AfxMessageBox("记录已删除!");
}
OnInitialUpdate();
}
void CDATABASEView::OnRecEdit()
{
CStuDlg dlg;
dlg.m_StuID=m_pSet->m_stuid;
dlg.m_sex=m_pSet->m_sex;
dlg.m_StuName=m_pSet->m_name;
dlg.m_ProfCode=m_pSet->m_profcode;
dlg.m_address=m_pSet->m_address;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -