📄 changesuspanddlg.cpp
字号:
// ChangeSuspandDlg.cpp : implementation file
//
#include "stdafx.h"
#include "school.h"
#include "ChangeSuspandDlg.h"
#include "ChangeSuspandInfoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChangeSuspandDlg dialog
CChangeSuspandDlg::CChangeSuspandDlg(CWnd* pParent /*=NULL*/)
: CDialog(CChangeSuspandDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CChangeSuspandDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CChangeSuspandDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChangeSuspandDlg)
DDX_Control(pDX, IDC_LIST1, m_ctrList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChangeSuspandDlg, CDialog)
//{{AFX_MSG_MAP(CChangeSuspandDlg)
ON_BN_CLICKED(IDC_BUTTON_NEW, OnButtonNew)
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()
/////////////////////////////////////////////////////////////////////////////
// CChangeSuspandDlg message handlers
BOOL CChangeSuspandDlg::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.SetColumnWidth(0,80);
m_ctrList.SetColumnWidth(1,80);
m_ctrList.SetColumnWidth(2,80);
m_ctrList.SetColumnWidth(3,80);
m_ctrList.SetColumnWidth(4,80);
m_ctrList.SetColumnWidth(5,120);
m_ctrList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
RefreshData();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CChangeSuspandDlg::RefreshData()
{
m_ctrList.DeleteAllItems();
m_ctrList.SetRedraw(FALSE);
UpdateData(TRUE);
CString strSQL;
strSQL="select * from suspand";
if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
MessageBox("打开数据库失败!","数据库错误",MB_OK);
return ;
}
int i=0;
while(!m_recordset.IsEOF())
{
m_ctrList.InsertItem(i,m_recordset.m_code);
m_ctrList.SetItemText(i,1,m_recordset.m_name);
m_ctrList.SetItemText(i,2,m_recordset.m_class);
m_ctrList.SetItemText(i,3,m_recordset.m_date);
m_ctrList.SetItemText(i,4,m_recordset.m_time);
m_ctrList.SetItemText(i,5,m_recordset.m_reason);
i++;
m_recordset.MoveNext();
}
m_recordset.Close();
m_ctrList.SetRedraw(TRUE);
}
void CChangeSuspandDlg::OnButtonNew()
{
// TODO: Add your control notification handler code here
CString strSQL;
CChangeSuspandInfoDlg Dlg;
while(1)
{
if(IDOK==Dlg.DoModal())
{
strSQL.Format("select * from suspand where code = '%s'",Dlg.m_strCode);
if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
AfxMessageBox("打开数据库失败!");
return ;
}
if(m_recordset.GetRecordCount()!=0)
{
AfxMessageBox("该编号已经存在!请重新输入!");
m_recordset.Close();
continue;
}
m_recordset.AddNew();
m_recordset.m_name = Dlg.m_strName ;
m_recordset.m_reason = Dlg.m_strBrief ;
m_recordset.m_date = Dlg.m_strDate ;
m_recordset.m_class = Dlg.m_strClass ;
m_recordset.m_code = Dlg.m_strCode ;
m_recordset.m_time = Dlg.m_strLong ;
m_recordset.Update();
m_recordset.Close();
RefreshData();
}
break;
}
}
void CChangeSuspandDlg::OnButtonModify()
{
// TODO: Add your control notification handler code here
CChangeSuspandInfoDlg Dlg;
UpdateData();
int i = m_ctrList.GetSelectionMark();
if(0>i)
{
AfxMessageBox("请选择一条记录进行修改!");
return;
}
Dlg.m_strName = m_ctrList.GetItemText(i,1);
Dlg.m_strBrief = m_ctrList.GetItemText(i,5);
Dlg.m_strDate = m_ctrList.GetItemText(i,3);
Dlg.m_strClass = m_ctrList.GetItemText(i,2);
Dlg.m_strCode = m_ctrList.GetItemText(i,0);
Dlg.m_strLong = m_ctrList.GetItemText(i,4);
if(IDOK==Dlg.DoModal())
{//修改记录
CString strSQL;
strSQL.Format("select * from suspand where code = '%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_reason = Dlg.m_strBrief ;
m_recordset.m_date = Dlg.m_strDate ;
m_recordset.m_class = Dlg.m_strClass ;
m_recordset.m_code = Dlg.m_strCode ;
m_recordset.m_time = Dlg.m_strLong ;
m_recordset.Update();
m_recordset.Close();
RefreshData();
}
}
void CChangeSuspandDlg::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 suspand where code = '%s' ",m_ctrList.GetItemText(i,0));
if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
AfxMessageBox("打开数据库失败!");
return ;
}
m_recordset.Delete();
m_recordset.Close();
RefreshData();
}
void CChangeSuspandDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CChangeSuspandInfoDlg Dlg;
UpdateData();
int i = m_ctrList.GetSelectionMark();
if(0>i)
{
AfxMessageBox("请选择一条记录进行修改!");
return;
}
Dlg.m_strName = m_ctrList.GetItemText(i,1);
Dlg.m_strBrief = m_ctrList.GetItemText(i,5);
Dlg.m_strDate = m_ctrList.GetItemText(i,3);
Dlg.m_strClass = m_ctrList.GetItemText(i,2);
Dlg.m_strCode = m_ctrList.GetItemText(i,0);
Dlg.m_strLong = m_ctrList.GetItemText(i,4);
if(IDOK==Dlg.DoModal())
{//修改记录
CString strSQL;
strSQL.Format("select * from suspand where code = '%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_reason = Dlg.m_strBrief ;
m_recordset.m_date = Dlg.m_strDate ;
m_recordset.m_class = Dlg.m_strClass ;
m_recordset.m_code = Dlg.m_strCode ;
m_recordset.m_time = Dlg.m_strLong ;
m_recordset.Update();
m_recordset.Close();
RefreshData();
}
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -