⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cyjview.cpp

📁 学生成绩管理系统
💻 CPP
字号:
// cyjView.cpp : implementation of the CCyjView class
//

#include "stdafx.h"
#include "cyj.h"
#include "ADDDLG.h"
#include "cyjSet.h"
#include "cyjDoc.h"
#include "cyjView.h"
#include "FINDDLG.h"
#include "SCDLG.h"
#include "SYSTEMDLG.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCyjView

IMPLEMENT_DYNCREATE(CCyjView, CRecordView)

BEGIN_MESSAGE_MAP(CCyjView, CRecordView)
	//{{AFX_MSG_MAP(CCyjView)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_BN_CLICKED(IDC_FIND, OnFind)
	ON_BN_CLICKED(IDC_SORT, OnSort)
	ON_BN_CLICKED(IDC_SHUAXIN, OnShuaxin)
	ON_BN_CLICKED(IDC_MODIFY, OnModify)
	ON_BN_CLICKED(IDC_SYSTEM, OnSystem)
	ON_BN_CLICKED(IDC_PRINT, OnPrint)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CCyjView construction/destruction

CCyjView::CCyjView()
	: CRecordView(CCyjView::IDD)
{
	//{{AFX_DATA_INIT(CCyjView)
	m_pSet = NULL;
	//}}AFX_DATA_INIT
	// TODO: add construction code here
m_pSet1=new SCSET;
}

CCyjView::~CCyjView()
{
}

void CCyjView::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCyjView)
	DDX_Control(pDX, IDC_CHECK1, m_check);
	DDX_FieldText(pDX, IDC_SAGE, m_pSet->m_sage, m_pSet);
	DDX_FieldText(pDX, IDC_SDEPT, m_pSet->m_sdept, m_pSet);
	DDX_FieldText(pDX, IDC_SNAME, m_pSet->m_sname, m_pSet);
	DDX_FieldText(pDX, IDC_SSEX, m_pSet->m_ssex, m_pSet);
	DDX_FieldText(pDX, IDC_SNO, m_pSet->m_sno, m_pSet);
	//}}AFX_DATA_MAP
}

BOOL CCyjView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CRecordView::PreCreateWindow(cs);
}

void CCyjView::OnInitialUpdate()
{CString str;
	CCyjApp *p=(CCyjApp *)AfxGetApp();
	str.Format("用户:%s权限:%s",p->str1,p->str2);
    CMainFrame *s=(CMainFrame *)AfxGetApp()->m_pMainWnd;
    s->m_wndStatusBar.SetPaneText(1,str,true);
    p->str2.TrimRight();
	if( p->str2=="录入员")
	{GetDlgItem(IDC_ADD)->EnableWindow(false);
	 GetDlgItem(IDC_DELETE)->EnableWindow(false);}
	
	
	
	
	pdb=new CDatabase;
        pdb->Open("ODBC;DSN=cyj");
	m_pSet = &GetDocument()->m_cyjSet;
	CRecordView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

}

/////////////////////////////////////////////////////////////////////////////
// CCyjView printing

BOOL CCyjView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CCyjView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CCyjView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CCyjView diagnostics

#ifdef _DEBUG
void CCyjView::AssertValid() const
{
	CRecordView::AssertValid();
}

void CCyjView::Dump(CDumpContext& dc) const
{
	CRecordView::Dump(dc);
}

CCyjDoc* CCyjView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCyjDoc)));
	return (CCyjDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CCyjView database support
CRecordset* CCyjView::OnGetRecordset()
{
	return m_pSet;
}


/////////////////////////////////////////////////////////////////////////////
// CCyjView message handlers

void CCyjView::OnAdd() 
{
	// TODO: Add your control notification handler code here
	ADDDLG mydlg;
	long id;
	id=m_pSet->m_id;


	if(mydlg.DoModal()==IDOK)
	{CString str;
	try {
			str.Format("insert into student values('%s','%s','%s',%d,'%s',%d)",mydlg.m_sno,mydlg.m_name,mydlg.m_sex,mydlg.m_age,mydlg.m_dept,id);
			
	pdb->ExecuteSQL(str);
		}
	
		catch(...)
		{
			AfxMessageBox("该学号已经有了!");
			return ; 
		}
		AfxMessageBox("添加成功!");
		m_pSet->Requery();
		m_pSet->MoveLast();
		UpdateData(FALSE);
}
}

void CCyjView::OnDelete() 
{
CString str;
str.Format("delete from student where sno='%s'",m_pSet->m_sno);
MessageBox(str);
pdb->ExecuteSQL(str);
AfxMessageBox("删除成功!");
m_pSet->Requery();
 m_pSet->MoveLast();
 UpdateData(FALSE);	
}

void CCyjView::OnFind() 
{FINDDLG mydlg;
mydlg.DoModal();
}

void CCyjView::OnSort() 
{
		FINDDLG mydlg;
	mydlg.sertflag=true;
	mydlg.DoModal();

}

void CCyjView::OnShuaxin() 
{
	// TODO: Add your control notification handler code here
	m_pSet->m_strFilter="";
	m_pSet->Requery();
	UpdateData(FALSE);
}

void CCyjView::OnModify() 
{SCDLG mydlg;

	if(m_check.GetCheck())
		mydlg.showallflag=false;	
	else 
	    mydlg.m_sno=m_pSet->m_sno;
	mydlg.DoModal();
	
}

void CCyjView::OnSystem() 
{
SYSTEMDLG mydlg;
mydlg.DoModal();	
}

void CCyjView::OnPrint() 
{ CString filename;
      CFile infile;
	  
	  CFileDialog filedlg(false,"txt",NULL,
		  OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"文本文件(*.txt)|*.txt|");
	  
	  if(filedlg.DoModal()==IDOK)
		  filename=filedlg.GetPathName();
	  else
		  return;
	  if(filename=="")
	  {
		  AfxMessageBox("你还没有输入文件名");
		  return;
	  }
	  
	  infile.Open(filename,CFile::modeCreate);
	  infile.Close();
	  infile.Open(filename,CFile::modeWrite);
	  infile.SeekToEnd();
	  { 
		  //////////////////////////////////////////////
		  CString str;
		  str="学号      课程号      成绩\r\n";
		  m_pSet1->Open();
		  while(!m_pSet1->IsEOF())
		  {
			  str+=m_pSet1->m_sno;
			  str+=m_pSet1->m_cno;
			  CString str1;
			  str1.Format("%d",m_pSet1->m_grade);
			  str+=str1+"\r\n";
			  m_pSet1->MoveNext();
		  }
          m_pSet1->Close();
		  infile.Write(str,str.GetLength()); 
	  }
	  infile.Close();
	  AfxMessageBox("导出成功!");
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -