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

📄 studentdlg.cpp

📁 以前的课程设计,觉得功能不错,界面设计的也不错
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// StudentDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Student.h"
#include "StudentDlg.h"
#include "BaseInfo.h"
#include "Grade.h"
#include "ChoiceDlg.h"
#include "FindDlg.h"
#include "ChangeDlg.h"
#include "GetPicFromBase.h"
#include "Out.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

extern CStudentApp theApp;


class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStudentDlg dialog

CStudentDlg::CStudentDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CStudentDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStudentDlg)
	m_adress = _T("安徽滁州市");
	m_id = _T("040330519");
	m_name = _T("陆良虎");
	m_sex = _T("男");
	m_tel = _T("0550-3940717");
	m_born = _T("1986.02.28");

	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CStudentDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStudentDlg)
	DDX_Control(pDX, IDC_STATIC_PICTUER, m_showpic);
	DDX_Control(pDX, IDC_STATIC_SHOW, m_staticshow);
	DDX_Control(pDX, IDC_LIST, m_list);
	DDX_Text(pDX, IDC_STUDENTADRESS, m_adress);
	DDX_Text(pDX, IDC_STUDENTID, m_id);
	DDX_Text(pDX, IDC_STUDENTNAME, m_name);
	DDX_Text(pDX, IDC_STUDENTSEX, m_sex);
	DDX_Text(pDX, IDC_STUDENTTEL, m_tel);
	DDX_Text(pDX, IDC_STUDENTBORN, m_born);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CStudentDlg, CDialog)
	//{{AFX_MSG_MAP(CStudentDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_GRADE, OnGrade)
	ON_BN_CLICKED(IDC_CHOICE, OnChoice)
	ON_BN_CLICKED(IDC_NAME, OnName)
	ON_BN_CLICKED(IDC_ID, OnId)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
	ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
	ON_COMMAND(IDC_ABOUT_FILE, OnAboutFile)
	ON_COMMAND(IDC_EXIT_FILE, OnExitFile)
	ON_COMMAND(IDC_RESET_FILE, OnResetFile)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_RESET, OnReset)
	ON_COMMAND(ID_INPUT, OnInput)
	ON_COMMAND(ID_OUT, OnOut)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStudentDlg message handlers

BOOL CStudentDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
   m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
//	m_list.SetBkColor(RGB(255,255,255));
//	m_list.SetTextBkColor(RGB(0,0,0));
	m_list.InsertColumn(1,"学号",LVCFMT_CENTER,130,1);
	m_list.InsertColumn(2,"姓名",LVCFMT_CENTER,150,1);
	m_list.InsertColumn(3,"性别",LVCFMT_CENTER,100,1);
	m_list.InsertColumn(4,"住址",LVCFMT_CENTER,150,1);
	m_list.InsertColumn(5,"电话",LVCFMT_CENTER,130,1);
    m_list.InsertColumn(6,"出生",LVCFMT_CENTER,130,1);
    MoveWindow(0,0,1024,760);
    Updatelist();

   m_staticshow.MoveWindow(50,660,1020,680); //这里的数据不要乱改
   CString show="  Hello to use this system about student, it was made by lulianghu !!!!  station: NUAA  Email:lulianghu@163.com";
   SetDlgItemText(IDC_STATIC_SHOW,show);
    
   //下面代码用来打开图象

	try
	{
		m_pset.CreateInstance("ADODB.Recordset");
		m_pset->Open("SELECT * FROM Base ORDER BY ID",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
	}

	catch(_com_error e)///捕捉异常
	{
		AfxMessageBox("读取数据库失败!");///显示错误信息
	}

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CStudentDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CStudentDlg::OnPaint() 
{
	
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting
        

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	    
	}
	else
	{
		
		CDialog::OnPaint();
       

	}

}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CStudentDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CStudentDlg::OnGrade() 
{
	// TODO: Add your control notification handler code here
	CGrade m_dlg;  

	if(m_dlg.DoModal()==IDOK)
	{
     
      

	}
	m_dlg.DestroyWindow();
}

void CStudentDlg::OnChoice() 
{
	// TODO: Add your control notification handler code here
	CChoiceDlg m_choicedlg;
	if(m_choicedlg.DoModal()==IDOK)
	{

	}
    m_choicedlg.DestroyWindow();
}

void CStudentDlg::OnName() 
{
	// TODO: Add your control notification handler code here
	CFindDlg m_fingdlg;
	if(m_fingdlg.DoModal()==IDOK)
	{

	}
	m_fingdlg.DestroyWindow();

}

void CStudentDlg::OnId() 
{
	// TODO: Add your control notification handler code here

 CChangeDlg m_changedlg;
 if(m_changedlg.DoModal()==IDOK)
 {


 }
 m_changedlg.DestroyWindow();

}
void CStudentDlg::Updatelist()
{
  int nIndex;
  int i=0;
  m_baseset.Open();
  m_baseset.MoveFirst();
  m_list.DeleteAllItems();           //删除原由的东西
  while(!m_baseset.IsEOF())
  {
   nIndex= m_list.InsertItem(i,m_baseset.m_id);
   m_list.SetItemText(nIndex,1,m_baseset.m_name);
   m_list.SetItemText(nIndex,2,m_baseset.m_sex);
   m_list.SetItemText(nIndex,3,m_baseset.m_adress);
   m_list.SetItemText(nIndex,4,m_baseset.m_tel);
   m_list.SetItemText(nIndex,5,m_baseset.m_born);
   i++;

   m_baseset.MoveNext();
 
  }
  
  m_baseset.Close();
}

void CStudentDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
 CBaseInfo dlg;
 int i=0;
 /*获取要修改的数据*/
 	int nItem = m_list.GetNextItem( -1, LVNI_ALL | LVNI_SELECTED);
	m_id=m_list.GetItemText(nItem,0);
	m_name= m_list.GetItemText(nItem,1);
	m_sex=m_list.GetItemText(nItem,2);
	m_adress=m_list.GetItemText(nItem,3);
    m_tel=m_list.GetItemText(nItem,4);
    m_born=m_list.GetItemText(nItem,5);	
/*获取要修改的数据*/

/*让修改对话框中有数值,避免要输入很多的值*/
dlg.m_adress=m_adress;                 
dlg.m_bore=m_born;
dlg.m_id=m_id;
dlg.m_name=m_name;
dlg.m_sex=m_sex;
dlg.m_tel=m_tel;
/*让修改对话框中有数值,避免要输入很多的值*/ 

  if(dlg.DoModal()==IDOK)
  {
   m_id=dlg.m_id;
   m_name=dlg.m_name;
   m_sex=dlg.m_sex;
   m_adress=dlg.m_adress;
   m_tel=dlg.m_tel;
   m_born=dlg.m_bore;
  
 /* the code below is used to reset the data of the listctrl*/
//   m_list.SetItemText(nItem,0,m_id);      //不容许修改学生的的学好,除非拥有超级权限
   m_list.SetItemText(nItem,1,m_name);
   m_list.SetItemText(nItem,2,m_sex);
   m_list.SetItemText(nItem,3,m_adress);
   m_list.SetItemText(nItem,4,m_tel);
   m_list.SetItemText(nItem,5,m_born);
   m_list.Update(nItem);                  //updatedate the item of the listctrl
   UpdateData(0);
/* the code below is used to reset the data of the listctrl*/

   m_baseset.Open();

   m_baseset.MoveFirst();
   m_pset->MoveFirst();
   while(i<nItem)
   {
	   m_baseset.MoveNext();

       m_pset->MoveNext(); 
       i++;
   }
      m_baseset.Edit();
      m_baseset.m_adress=m_adress;
      m_baseset.m_born=m_born;
//      m_baseset.m_id=m_id;    //不容许修改学生的的学好,除非拥有超级权限
      m_baseset.m_name=m_name;
      m_baseset.m_sex=m_sex;
      m_baseset.m_tel=m_tel;
      m_baseset.Update();
	  MessageBox("       恭喜你!!\n已经成功的更新数据库了",NULL,MB_OK|MB_ICONINFORMATION);
      m_baseset.Close();
	  dlg.DestroyWindow();
  }
   GetDataFromBase();       //显示图象
}

void CStudentDlg::OnClickList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	int nItem = m_list.GetNextItem( -1, LVNI_ALL | LVNI_SELECTED);
	m_id=m_list.GetItemText(nItem,0);
	m_name= m_list.GetItemText(nItem,1);
	m_sex=m_list.GetItemText(nItem,2);
	m_adress=m_list.GetItemText(nItem,3);
    m_tel=m_list.GetItemText(nItem,4);
    m_born=m_list.GetItemText(nItem,5);

    UpdateData(0);	
	*pResult = 0;
   m_baseset.Open();

   m_baseset.MoveFirst();
   m_pset->MoveFirst();
   int i=0;
   while(i<nItem)
   {
	   m_baseset.MoveNext();
       m_pset->MoveNext(); 
       i++;
   }
	GetDataFromBase();
	m_baseset.Close();
}

void CStudentDlg::OnAboutFile() 
{
	// TODO: Add your command handler code here
	CAboutDlg dlg;
	dlg.DoModal();
}

void CStudentDlg::OnExitFile() 
{
	// TODO: Add your command handler code here
	CDialog::DestroyWindow();
}

void CStudentDlg::OnResetFile() 
{
	// TODO: Add your command handler code here
	Updatelist();
}

void CStudentDlg::OnAdd() 
{
	// TODO: Add your control notification handler code here



	  CFile f;
	  CString  FilePathName;
	  CFileException e;

⌨️ 快捷键说明

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