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

📄 sjkview.cpp

📁 数据库 做的一个管理系统 看看吧,界面简单了点啊
💻 CPP
字号:
// sjkView.cpp : implementation of the CSjkView class
//

#include "stdafx.h"
#include "sjk.h"
#include "AddDialog.h"
#include "sjkSet.h"
#include "sjkDoc.h"
#include "sjkView.h"
#include "DeleteDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSjkView

IMPLEMENT_DYNCREATE(CSjkView, CRecordView)

BEGIN_MESSAGE_MAP(CSjkView, CRecordView)
	//{{AFX_MSG_MAP(CSjkView)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_ALL, OnAll)
	ON_BN_CLICKED(IDC_SORT, OnSort)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_BN_CLICKED(IDC_EDIT, OnEdit)
	ON_BN_CLICKED(IDC_FIND, OnFind)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CSjkView construction/destruction

CSjkView::CSjkView()
	: CRecordView(CSjkView::IDD)
{
	//{{AFX_DATA_INIT(CSjkView)
		// NOTE: the ClassWizard will add member initialization here
	m_pSet = NULL;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CSjkView::~CSjkView()
{
}

void CSjkView::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSjkView)
	DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
	//}}AFX_DATA_MAP
}

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

	return CRecordView::PreCreateWindow(cs);
}

void CSjkView::OnInitialUpdate()
{
	m_pSet = &GetDocument()->m_sjkSet;
	CRecordView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
	//创刷子用来设置界面背景色
    m_Brush=CreateSolidBrush(RGB(30,180,180));
//设表格表题和列的宽度
	m_ListCtrl.SetBkColor(RGB(240,247,220));
	m_ListCtrl.SetTextBkColor(RGB(240,247,220));
    m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
    m_ListCtrl.InsertColumn(0,_T("学号"),LVCFMT_IMAGE|LVCFMT_LEFT);
	m_ListCtrl.InsertColumn(1,_T("姓名"));
	m_ListCtrl.InsertColumn(2,_T("班级"));
	m_ListCtrl.InsertColumn(3,_T("英语"));
	m_ListCtrl.InsertColumn(4,_T("数学"));
	m_ListCtrl.InsertColumn(5,_T("计算机"));
	int j;
    for(j=0;j<6;j++)
	{
	  m_ListCtrl.SetColumnWidth(j ,90);
	}	
//显示所有记录
	this->Show();

}
// CLhwy5323View message handlers
int  CSjkView::Show()
{
	int i=0;
	m_pSet->MoveFirst();
    do
	 {  
		CString s;
        s.Format("%d",m_pSet->m_column1);
        m_ListCtrl.InsertItem(i,s,0);
		m_ListCtrl.SetItemText(i,1,m_pSet->m_column2);
		m_ListCtrl.SetItemText(i,2,m_pSet->m_column3);
        s.Format("%d",m_pSet->m_column4);
        m_ListCtrl.SetItemText(i,3,s);
        s.Format("%d",m_pSet->m_column5);
        m_ListCtrl.SetItemText(i,4,s);
        s.Format("%d",m_pSet->m_column6);
        m_ListCtrl.SetItemText(i,5,s);
		i++;
        m_pSet->MoveNext();
		}  while(!m_pSet->IsEOF());
        m_pSet->MoveFirst();
		return i;
}
/////////////////////////////////////////////////////////////////////////////
// CSjkView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CSjkView diagnostics

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

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

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

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


/////////////////////////////////////////////////////////////////////////////
// CSjkView message handlers

HBRUSH CSjkView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CRecordView::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	
	// TODO: Return a different brush if the default is not desired
	return m_Brush;
}

void CSjkView::OnAdd() 
{
	// TODO: Add your control notification handler code here
	CAddDialog dlg;
	if( dlg.DoModal()==IDOK)
	  {  
		if(dlg.m_Xuehao==0)
		{
		 AfxMessageBox("学号不可为零!");
		}
		else
		{
		 m_pSet->AddNew();
	     m_pSet->m_column1=dlg.m_Xuehao;
         m_pSet->m_column2=dlg.m_strName;
	     m_pSet->m_column3=dlg.m_Maths;
		 m_pSet->m_column4=dlg.m_English;
	     m_pSet->m_column5=dlg.m_Math;
		 m_pSet->m_column6=dlg.m_CPT ;        
		 m_pSet->Update();
	     m_pSet->Requery();
	     m_pSet->MoveLast();

		CString s;
        s.Format("%d",dlg.m_Xuehao);
        m_ListCtrl.InsertItem(0,s,0);
		m_ListCtrl.SetItemText(0,1,dlg.m_strName);
		m_ListCtrl.SetItemText(0,2,dlg.m_Maths);
        s.Format("%d",dlg.m_English);
        m_ListCtrl.SetItemText(0,3,s);
        s.Format("%d",dlg.m_Math);
        m_ListCtrl.SetItemText(0,4,s);
        s.Format("%d",dlg.m_CPT);
        m_ListCtrl.SetItemText(0,5,s);

		}
	}   
        m_pSet->MoveFirst();
	
}

void CSjkView::OnAll() 
{
	// TODO: Add your control notification handler code here
	m_ListCtrl.DeleteAllItems();	
	this->Show();
	
}

void CSjkView::OnSort() 
{
	// TODO: Add your control notification handler code here
	m_ListCtrl.DeleteAllItems();
    m_pSet->m_strSort="[英语]";
	m_pSet->Requery();
	this->Show();	
	
}

void CSjkView::OnDelete() 
{
	// TODO: Add your control notification handler code here
	CDeleteDialog dlg;
	if(dlg.DoModal()==IDOK)
	{
	  if(dlg.m_Password!=1234)
	  AfxMessageBox("你没有权限删除记录!请重输入密码!");
	  else
		{   
		 BOOL b=FALSE;
		 m_pSet->MoveFirst();
		 do
		 {
		  if(dlg.m_Xuehao!=m_pSet->m_column1)
		  m_pSet->MoveNext();
		  else
			{   
			 m_ListCtrl.DeleteAllItems();
			 b=TRUE;
			 m_pSet->Delete();
					
			 m_pSet->Requery();
			 this->Show();
			 m_pSet->MoveFirst();
			 break;
			} 
		}while(!m_pSet->IsEOF());
	          
	if(b==FALSE)
	AfxMessageBox("没有此记录");
	  }
	}
	
}

void CSjkView::OnEdit() 
{
	// TODO: Add your control notification handler code here
	 CEditDialog dlg;
 
  if(dlg.DoModal()==IDOK)
	{
	  if(dlg.m_Password!=1234)
	  AfxMessageBox("你没有权限更改记录!请重输入密码:");
	  else
		  {   
		   BOOL b=FALSE;
		   m_pSet->MoveFirst();
		   do
			{
			 if(dlg.m_Xuehao!=m_pSet->m_column1)
			 m_pSet->MoveNext();
			 else
				{  	
				m_ListCtrl.DeleteAllItems();
				m_pSet->Edit();
				b=TRUE;
			    m_pSet->m_column1=dlg.m_Xuehao;
				m_pSet->m_column2=dlg.m_strName;
				m_pSet->m_column3=dlg.m_Maths;
				m_pSet->m_column4=dlg.m_English;
				m_pSet->Update();	
				m_pSet->Requery();
				this->Show();
				m_pSet->MoveFirst();
				break;
				} 
			}while(!m_pSet->IsEOF());
	          if(b==FALSE)
			  AfxMessageBox("没有此记录");
		}
	}

	
}

void CSjkView::OnFind() 
{
	// TODO: Add your control notification handler code here
	BOOL k=FALSE;
	CFindDialog dlg;
	if(dlg.DoModal()==IDOK)
	{
	  m_pSet->MoveFirst();
	  m_ListCtrl.DeleteAllItems();
	  do{
		if(dlg.m_Xuehao!=m_pSet->m_column1)
		m_pSet->MoveNext();
		else
			{
			 k=TRUE;
		     CString s;
			 s.Format("%d",m_pSet->m_column1);
			 m_ListCtrl.InsertItem(0,s);
			 m_ListCtrl.SetItemText(0,1,m_pSet->m_column2);
			 s.Format("%d",m_pSet->m_column3); 
		     m_ListCtrl.SetItemText(0,2,s);
             s.Format("%d",m_pSet->m_column3);
             m_ListCtrl.SetItemText(0,3,s);  
			 m_pSet->MoveNext();
		} 

	}  while(!m_pSet->IsEOF());
        
	if(k==FALSE)
	AfxMessageBox("没有符和条件的记录");
	}	
	
}

⌨️ 快捷键说明

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