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

📄 encpundlg.cpp

📁 student manager system
💻 CPP
字号:
// EncPunDlg.cpp : implementation file
//

#include "stdafx.h"
#include "StuManage.h"
#include "EncPunDlg.h"
#include "Columns.h"
#include "Column.h"

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

/////////////////////////////////////////////////////////////////////////////
// CEncPunDlg dialog

extern CStuManageApp theApp;

CEncPunDlg::CEncPunDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CEncPunDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CEncPunDlg)
	m_timeEncFun = CTime::GetCurrentTime();
	m_strEncFunMark = _T("");
	m_strStudentName = _T("");
	m_strEncFun = _T("");
	m_strStudentId = _T("");
	m_looktype = 0;
	//}}AFX_DATA_INIT
}


void CEncPunDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEncPunDlg)
	DDX_Control(pDX, IDC_DATETIMEPICKER_ENCFUN, m_timectrl);
	DDX_Control(pDX, IDC_COMBO_ENCFUN_NAME, m_cbEncFun);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_ENCFUN, m_timeEncFun);
	DDX_Text(pDX, IDC_EDIT_ENCFUN_REMARK, m_strEncFunMark);
	DDX_Text(pDX, IDC_EDIT_STUDNETNAME, m_strStudentName);
	DDX_CBString(pDX, IDC_COMBO_ENCFUN_NAME, m_strEncFun);
	DDX_Text(pDX, IDC_EDIT_ENCFUN_ID, m_strStudentId);
	DDX_Radio(pDX, IDC_RADIO_STUDENT_ID, m_looktype);
	DDX_Control(pDX, IDC_DATAGRID_ENCPUN, m_dgResult);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CEncPunDlg, CDialog)
	//{{AFX_MSG_MAP(CEncPunDlg)
	ON_BN_CLICKED(IDC_VIEW_ENCFUN_BTN, OnViewEncfunBtn)
	ON_BN_CLICKED(IDC_ADD_ENCFUN_BTN, OnAddEncfunBtn)
	ON_BN_CLICKED(IDC_ENCFUN_SAVE_BTN, OnEncfunSaveBtn)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEncPunDlg message handlers

BOOL CEncPunDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_add = FALSE;
	m_cbEncFun.AddString("特等奖");
	m_cbEncFun.AddString("进步奖");
	m_cbEncFun.AddString("社会工作奖");
	m_cbEncFun.AddString("留校查看");

	m_pRecordset.CreateInstance("ADODB.Recordset");
	m_pRecordset->Open("SELECT * FROM Encourage_Punishment",_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);       	

	if(m_pRecordset->GetRecordCount()!=0)
	{
		m_pRecordset->MoveFirst();
		m_strStudentId = m_pRecordset->GetCollect("ID").bstrVal;
		m_strStudentName = m_pRecordset->GetCollect("Name").bstrVal;	
		CString str;	
		m_strEncFun = m_pRecordset->GetCollect("Enc_PunName").bstrVal;

		str = m_pRecordset->GetCollect("Enc_PunTime").bstrVal;	//str to time
		m_timectrl.SetFormat(str);
		
		m_strEncFunMark = m_pRecordset->GetCollect("Remark").bstrVal;
	}
	
	m_pRecordset->Close();
	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CEncPunDlg::OnViewEncfunBtn() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CString sql,str;
	if(m_looktype == 0)
	{
		if(m_strStudentId.CompareNoCase("") == 0)
		{
			AfxMessageBox("请输入您要查找的学号");
			return;
		}
		sql = "select * from Encourage_Punishment where ID = '"+m_strStudentId+"' ";
	}
	else if(m_looktype == 1)
	{
		if(m_strEncFun.CompareNoCase("") == 0)
		{
			AfxMessageBox("请输入您要查找的奖惩项");
			return;
		}
		sql = "select * from Encourage_Punishment where Enc_PunName = '"+m_strEncFun+"' ";
	}
	else if(m_looktype == 2)
		sql = "select * from Encourage_Punishment";
	
	m_pRecordset.CreateInstance("ADODB.Recordset");
	m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);       	
	
	if(m_pRecordset->GetRecordCount()==0)
	{
		AfxMessageBox("没有找到您需要的记录");
		return;
	}
	
	m_dgResult.SetRefDataSource(NULL);
	m_dgResult.SetRefDataSource((LPUNKNOWN)m_pRecordset);
	m_dgResult.SetColumnHeaders(2) ;
	
	_variant_t var;
	var = long(0);
	m_dgResult.GetColumns().GetItem(var).SetCaption("学号");
	m_dgResult.GetColumns().GetItem(var).SetWidth(50);
	var = long(1);
	m_dgResult.GetColumns().GetItem(var).SetCaption("姓名");
	m_dgResult.GetColumns().GetItem(var).SetWidth(50);
	var = long(2);
	m_dgResult.GetColumns().GetItem(var).SetCaption("奖惩项");
	m_dgResult.GetColumns().GetItem(var).SetWidth(60);
	var = long(3);
	m_dgResult.GetColumns().GetItem(var).SetCaption("时间");
	m_dgResult.GetColumns().GetItem(var).SetWidth(70);
	var = long(4);
	m_dgResult.GetColumns().GetItem(var).SetCaption("备注");
	m_dgResult.GetColumns().GetItem(var).SetWidth(100);

	m_dgResult.Refresh();
	
	UpdateData(FALSE);

}

void CEncPunDlg::OnAddEncfunBtn() 
{
	// TODO: Add your control notification handler code here
	if(theApp.m_Level != 2)
	{
		AfxMessageBox("您无权进行奖惩设置");
		return;
	}
	m_timeEncFun = CTime::GetCurrentTime();
	m_strStudentId = "";
	m_strEncFunMark = "";
	m_strStudentName = "";
	m_strEncFun = "";
	AfxMessageBox("请输入新的奖惩记录后保存");
	m_add = TRUE;
	
	UpdateData(FALSE);
}

void CEncPunDlg::OnEncfunSaveBtn() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	if(m_add == TRUE)
	{
		CString sql,str;
		sql = "select * from Encourage_Punishment ";
		m_pRecordset.CreateInstance("ADODB.Recordset");
		m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);       	
		
		m_pRecordset->AddNew();
		m_pRecordset->PutCollect("ID",(_variant_t)m_strStudentId);
		m_pRecordset->PutCollect("Name",(_variant_t)m_strStudentName);
		
		int i=m_cbEncFun.GetCurSel();
		m_cbEncFun.GetLBText(i,m_strEncFun);
		m_pRecordset->PutCollect("Enc_PunName",(_variant_t)m_strEncFun);
		
		m_timeEncFun = CTime::GetCurrentTime();
		str.Format("%d-%d-%d",m_timeEncFun.GetYear(),m_timeEncFun.GetMonth(),m_timeEncFun.GetDay());
		m_pRecordset->PutCollect("Enc_PunTime",(_variant_t)str);
		
		m_pRecordset->PutCollect("Remark",(_variant_t)m_strEncFunMark);
		
		m_pRecordset->Update();
		m_pRecordset->Close();
	}
	m_add = FALSE;
}

⌨️ 快捷键说明

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