ScholarshipDlg.cpp
资源名称:school.rar [点击查看]
上传用户:rs600066
上传日期:2017-10-16
资源大小:4788k
文件大小:8k
源码类别:
数据库系统
开发平台:
Visual C++
- // ScholarshipDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "school.h"
- #include "ScholarshipDlg.h"
- #include "scholarshipinfodlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CScholarshipDlg dialog
- CScholarshipDlg::CScholarshipDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CScholarshipDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CScholarshipDlg)
- m_nCondition = -1;
- m_strContent = _T("");
- //}}AFX_DATA_INIT
- }
- void CScholarshipDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CScholarshipDlg)
- DDX_Control(pDX, IDC_LIST1, m_ctrList);
- DDX_CBIndex(pDX, IDC_COMBO_CONDITION, m_nCondition);
- DDX_CBString(pDX, IDC_COMBO_CONTENT, m_strContent);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CScholarshipDlg, CDialog)
- //{{AFX_MSG_MAP(CScholarshipDlg)
- ON_BN_CLICKED(IDC_BUTTON_NEW, OnButtonNew)
- ON_BN_CLICKED(IDC_BUTTON_SEARCH, OnButtonSearch)
- ON_BN_CLICKED(IDC_BUTTON_MODIFY, OnButtonModify)
- ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
- ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CScholarshipDlg message handlers
- BOOL CScholarshipDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- m_ctrList.InsertColumn(0,"序号");
- m_ctrList.InsertColumn(1,"奖学金名称");
- m_ctrList.InsertColumn(2,"奖学金类型");
- m_ctrList.InsertColumn(3,"奖学金等级");
- m_ctrList.InsertColumn(4,"获奖人");
- m_ctrList.InsertColumn(5,"说明");
- m_ctrList.InsertColumn(6,"获奖日期");
- m_ctrList.SetColumnWidth(0,60);
- m_ctrList.SetColumnWidth(1,100);
- m_ctrList.SetColumnWidth(2,100);
- m_ctrList.SetColumnWidth(3,100);
- m_ctrList.SetColumnWidth(4,100);
- m_ctrList.SetColumnWidth(5,100);
- m_ctrList.SetColumnWidth(6,100);
- m_ctrList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
- RefreshData("select * from scholarship");
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CScholarshipDlg::RefreshData(CString strSQL)
- {
- m_ctrList.DeleteAllItems();
- m_ctrList.SetRedraw(FALSE);
- UpdateData(TRUE);
- // strSQL="select * from dept";
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- int i=0;
- CString strTime;
- char buffer[20];
- while(!m_recordset.IsEOF())
- {
- _ltoa(m_recordset.m_ID,buffer,10);
- m_ctrList.InsertItem(i,buffer);
- m_ctrList.SetItemText(i,1,m_recordset.m_name);
- m_ctrList.SetItemText(i,2,m_recordset.m_type);
- m_ctrList.SetItemText(i,3,m_recordset.m_level);
- m_ctrList.SetItemText(i,4,m_recordset.m_person);
- m_ctrList.SetItemText(i,5,m_recordset.m_brief);
- strTime.Format("%d-%d-%d",m_recordset.m_date.GetYear(),m_recordset.m_date.GetMonth(),m_recordset.m_date.GetDay());
- m_ctrList.SetItemText(i,6,strTime);
- i++;
- m_recordset.MoveNext();
- }
- m_recordset.Close();
- m_ctrList.SetRedraw(TRUE);
- }
- void CScholarshipDlg::OnButtonNew()
- {
- // TODO: Add your control notification handler code here
- CScholarshipInfoDlg Dlg;
- if(IDOK==Dlg.DoModal())
- {
- //添加新记录
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE))
- {
- AfxMessageBox("打开数据库失败!");
- return ;
- }
- m_recordset.AddNew();
- m_recordset.m_name = Dlg.m_strName ;
- m_recordset.m_brief = Dlg.m_strBrief ;
- m_recordset.m_date = Dlg.m_tmDate ;
- m_recordset.m_level = Dlg.m_strLevel ;
- m_recordset.m_person = Dlg.m_strPerson ;
- m_recordset.m_type = Dlg.m_strType ;
- m_recordset.Update();
- m_recordset.Close();
- CString strSQL = "select * from scholarship ";
- RefreshData(strSQL);
- }
- }
- void CScholarshipDlg::OnButtonSearch()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- CString strSQL;
- if(0==m_nCondition)
- {//奖学金名称
- strSQL.Format("select * from scholarship where name = '%s'",m_strContent);
- }else if(1==m_nCondition)
- {//奖学金类型
- strSQL.Format("select * from scholarship where type = '%s'",m_strContent);
- }else if(2==m_nCondition)
- {//奖学金等级
- strSQL.Format("select * from scholarship where level = '%s'",m_strContent);
- }else if(3==m_nCondition)
- {//获奖人
- strSQL.Format("select * from scholarship where person = '%s'",m_strContent);
- }else if(4==m_nCondition)
- {//全部
- strSQL.Format("select * from scholarship");
- }else
- {
- strSQL.Format("select * from scholarship ");
- }
- RefreshData(strSQL);
- }
- void CScholarshipDlg::OnButtonModify()
- {
- // TODO: Add your control notification handler code here
- CScholarshipInfoDlg Dlg;
- UpdateData();
- int i = m_ctrList.GetSelectionMark();
- if(0>i)
- {
- AfxMessageBox("请选择一条记录进行修改!");
- return;
- }
- CString strSQL;
- strSQL.Format("select * from scholarship where ID = %s",m_ctrList.GetItemText(i,0));
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- return ;
- }
- Dlg.m_strName = m_recordset.m_name ;
- Dlg.m_strBrief = m_recordset.m_brief ;
- Dlg.m_tmDate = m_recordset.m_date ;
- Dlg.m_strLevel = m_recordset.m_level ;
- Dlg.m_strPerson = m_recordset.m_person ;
- Dlg.m_strType = m_recordset.m_type ;
- m_recordset.Close();
- if(IDOK==Dlg.DoModal())
- {//修改记录
- strSQL.Format("select * from scholarship where ID = %s",m_ctrList.GetItemText(i,0));
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- return ;
- }
- m_recordset.Edit();
- m_recordset.m_name = Dlg.m_strName ;
- m_recordset.m_brief = Dlg.m_strBrief ;
- m_recordset.m_date = Dlg.m_tmDate ;
- m_recordset.m_level = Dlg.m_strLevel ;
- m_recordset.m_person = Dlg.m_strPerson ;
- m_recordset.m_type = Dlg.m_strType ;
- m_recordset.Update();
- m_recordset.Close();
- strSQL = "select * from scholarship ";
- RefreshData(strSQL);
- }
- }
- void CScholarshipDlg::OnButtonDelete()
- {
- // TODO: Add your control notification handler code here
- int i = m_ctrList.GetSelectionMark();
- if(0>i)
- {
- AfxMessageBox("请选择一条记录进行查看!");
- return;
- }
- CString strSQL;
- strSQL.Format("select * from scholarship where ID = %s ",m_ctrList.GetItemText(i,0));
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- return ;
- }
- m_recordset.Delete();
- m_recordset.Close();
- strSQL = "select * from scholarship";
- RefreshData(strSQL);
- }
- void CScholarshipDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- CScholarshipInfoDlg Dlg;
- UpdateData();
- int i = m_ctrList.GetSelectionMark();
- if(0>i)
- {
- AfxMessageBox("请选择一条记录进行修改!");
- return;
- }
- CString strSQL;
- strSQL.Format("select * from scholarship where ID = %s",m_ctrList.GetItemText(i,0));
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- return ;
- }
- Dlg.m_strName = m_recordset.m_name ;
- Dlg.m_strBrief = m_recordset.m_brief ;
- Dlg.m_tmDate = m_recordset.m_date ;
- Dlg.m_strLevel = m_recordset.m_level ;
- Dlg.m_strPerson = m_recordset.m_person ;
- Dlg.m_strType = m_recordset.m_type ;
- m_recordset.Close();
- if(IDOK==Dlg.DoModal())
- {//修改记录
- strSQL.Format("select * from scholarship where ID = %s",m_ctrList.GetItemText(i,0));
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- return ;
- }
- m_recordset.Edit();
- m_recordset.m_name = Dlg.m_strName ;
- m_recordset.m_brief = Dlg.m_strBrief ;
- m_recordset.m_date = Dlg.m_tmDate ;
- m_recordset.m_level = Dlg.m_strLevel ;
- m_recordset.m_person = Dlg.m_strPerson ;
- m_recordset.m_type = Dlg.m_strType ;
- m_recordset.Update();
- m_recordset.Close();
- strSQL = "select * from scholarship ";
- RefreshData(strSQL);
- }
- *pResult = 0;
- }