📄 experiencedlg.cpp
字号:
// ExperienceDlg.cpp : implementation file
//
#include "stdafx.h"
#include "StuManage.h"
#include "ExperienceDlg.h"
#include "Columns.h"
#include "Column.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExperienceDlg dialog
extern CStuManageApp theApp;
CExperienceDlg::CExperienceDlg(CWnd* pParent /*=NULL*/)
: CDialog(CExperienceDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CExperienceDlg)
m_strEleSchool = _T("");
m_strId = _T("");
m_strName = _T("");
m_strJunSchool = _T("");
m_strSenSchool = _T("");
m_timeEleEnd = 0;
m_timeJunEnd = 0;
m_timeSenEnd = 0;
m_timeEleStart = 0;
m_timeJunStart = 0;
m_timeSenStart = 0;
//}}AFX_DATA_INIT
}
void CExperienceDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExperienceDlg)
DDX_Control(pDX, IDC_EDIT_EXP_ID, m_ID);
DDX_Control(pDX, IDC_DATETIMEPICKER_START_SENH, m_timectrlSenStart);
DDX_Control(pDX, IDC_DATETIMEPICKER_START_JUNH, m_timectrlJunStart);
DDX_Control(pDX, IDC_DATETIMEPICKER_START_ELE, m_timectrlEleStart);
DDX_Control(pDX, IDC_DATETIMEPICKER_END_JUNH, m_timectrlJunEnd);
DDX_Control(pDX, IDC_DATETIMEPICKER_END_ELE, m_timectrlEleEnd);
DDX_Control(pDX, IDC_DATETIMEPICKER_END_SENH, m_timectrlSenEnd);
DDX_Control(pDX, IDC_DATAGRID_EXPERIENCE, m_dgExperience);
DDX_Text(pDX, IDC_EDIT_ELEMENTARY_SCHOOL, m_strEleSchool);
DDX_Text(pDX, IDC_EDIT_EXP_ID, m_strId);
DDX_Text(pDX, IDC_EDIT_EXP_NAME, m_strName);
DDX_Text(pDX, IDC_EDIT_JUNIOR_HIGH_SCHOOL, m_strJunSchool);
DDX_Text(pDX, IDC_EDIT_SENIOR_HIGH_SCHOOL, m_strSenSchool);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_END_ELE, m_timeEleEnd);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_END_JUNH, m_timeJunEnd);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_END_SENH, m_timeSenEnd);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_START_ELE, m_timeEleStart);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_START_JUNH, m_timeJunStart);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_START_SENH, m_timeSenStart);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CExperienceDlg, CDialog)
//{{AFX_MSG_MAP(CExperienceDlg)
ON_BN_CLICKED(IDC_ADD_EXPERIENCE_BTN, OnAddExperienceBtn)
ON_BN_CLICKED(IDC_DELETE_EXPERIENCE_BTN, OnDeleteExperienceBtn)
ON_BN_CLICKED(IDC_MODIFY_EXPERIENCE_BTN, OnModifyExperienceBtn)
ON_BN_CLICKED(IDC_SAVE_EXPERIENCE_BTN, OnSaveExperienceBtn)
ON_BN_CLICKED(IDC_LOOKFOR_EXPERIENCE_BTN, OnLookforExperienceBtn)
ON_EN_KILLFOCUS(IDC_EDIT_EXP_ID, OnKillfocusEditExpId)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExperienceDlg message handlers
BOOL CExperienceDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString str;
SelectType=0;
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open("select * from StudentExperience",_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
m_dgExperience.SetRefDataSource(NULL);
m_dgExperience.SetRefDataSource((LPUNKNOWN)m_pRecordset);
m_dgExperience.SetColumnHeaders(2) ;
_variant_t var;
var = long(0);
m_dgExperience.GetColumns().GetItem(var).SetCaption("学号");
m_dgExperience.GetColumns().GetItem(var).SetWidth(60);
var = long(1);
m_dgExperience.GetColumns().GetItem(var).SetCaption("姓名");
m_dgExperience.GetColumns().GetItem(var).SetWidth(40);
var = long(2);
m_dgExperience.GetColumns().GetItem(var).SetCaption("小学入学时间");
m_dgExperience.GetColumns().GetItem(var).SetWidth(65);
var = long(3);
m_dgExperience.GetColumns().GetItem(var).SetCaption("小学毕业时间");
m_dgExperience.GetColumns().GetItem(var).SetWidth(65);
var = long(4);
m_dgExperience.GetColumns().GetItem(var).SetCaption("小学毕业学校");
m_dgExperience.GetColumns().GetItem(var).SetWidth(65);
var = long(5);
m_dgExperience.GetColumns().GetItem(var).SetCaption("初中入学时间");
m_dgExperience.GetColumns().GetItem(var).SetWidth(65);
var = long(6);
m_dgExperience.GetColumns().GetItem(var).SetCaption("初中毕业时间");
m_dgExperience.GetColumns().GetItem(var).SetWidth(65);
var = long(7);
m_dgExperience.GetColumns().GetItem(var).SetCaption("初中毕业学校");
m_dgExperience.GetColumns().GetItem(var).SetWidth(65);
var = long(8);
m_dgExperience.GetColumns().GetItem(var).SetCaption("高中入学时间");
m_dgExperience.GetColumns().GetItem(var).SetWidth(65);
var = long(9);
m_dgExperience.GetColumns().GetItem(var).SetCaption("高中毕业时间");
m_dgExperience.GetColumns().GetItem(var).SetWidth(65);
var = long(10);
m_dgExperience.GetColumns().GetItem(var).SetCaption("高中毕业学校");
m_dgExperience.GetColumns().GetItem(var).SetWidth(65);
m_dgExperience.Refresh();
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CExperienceDlg::OnAddExperienceBtn()
{
// TODO: Add your control notification handler code here
if(theApp.m_Level != 2)
{
AfxMessageBox("您无权添加记录");
return;
}
m_strEleSchool = "";
m_strId = "";
m_strName = "";
m_strJunSchool = "";
m_strSenSchool = "";
AfxMessageBox("请输入新的记录");
action = 1;
UpdateData(FALSE);
}
void CExperienceDlg::OnDeleteExperienceBtn()
{
// TODO: Add your control notification handler code here
if(theApp.m_Level != 2)
{
AfxMessageBox("您无权删除记录");
return;
}
if(AfxMessageBox("确定删除此记录吗?",MB_YESNO)==IDYES)
action = 3;
}
void CExperienceDlg::OnModifyExperienceBtn()
{
// TODO: Add your control notification handler code here
if(theApp.m_Level != 2)
{
AfxMessageBox("您无权修改记录");
return;
}
if(AfxMessageBox("确定修改此记录吗?",MB_YESNO)==IDYES)
action = 2;
}
void CExperienceDlg::OnSaveExperienceBtn()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString sql,str,id;
sql = "select * from StudentExperience ";
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
switch(action)
{
case 1:
if (m_strEleSchool=="")
{
MessageBox("请输入小学就读学校名称","错误提示",MB_OK);
return;
}
if (m_strJunSchool=="")
{
MessageBox("请输入初中就读学校名称","错误提示",MB_OK);
return;
}
if (m_strSenSchool=="")
{
MessageBox("请输入高中就读学校名称","错误提示",MB_OK);
return;
}
m_pRecordset->AddNew();
//学号
m_pRecordset->PutCollect("ID",(_variant_t)m_strId);
//姓名
m_pRecordset->PutCollect("Name",(_variant_t)m_strName);
//小学开始时间
str.Format("%d-%d-%d",m_timeEleStart.GetYear(),m_timeEleStart.GetMonth(),m_timeEleStart.GetDay());
m_pRecordset->PutCollect("ElementaryStart",(_variant_t)str);
//小学结束时间
str.Format("%d-%d-%d",m_timeEleEnd.GetYear(),m_timeEleEnd.GetMonth(),m_timeEleEnd.GetDay());
m_pRecordset->PutCollect("ElementaryEnd",(_variant_t)str);
//初中开始时间
str.Format("%d-%d-%d",m_timeJunStart.GetYear(),m_timeJunStart.GetMonth(),m_timeJunStart.GetDay());
m_pRecordset->PutCollect("JuniorStart",(_variant_t)str);
//初中结束时间
str.Format("%d-%d-%d",m_timeJunEnd.GetYear(),m_timeJunEnd.GetMonth(),m_timeJunEnd.GetDay());
m_pRecordset->PutCollect("JuniorEnd",(_variant_t)str);
//高中开始时间
str.Format("%d-%d-%d",m_timeSenStart.GetYear(),m_timeSenStart.GetMonth(),m_timeSenStart.GetDay());
m_pRecordset->PutCollect("SeniorStart",(_variant_t)str);
//高中结束时间
str.Format("%d-%d-%d",m_timeSenEnd.GetYear(),m_timeSenEnd.GetMonth(),m_timeSenEnd.GetDay());
m_pRecordset->PutCollect("SeniorEnd",(_variant_t)str);
//小学学校名称
m_pRecordset->PutCollect("ElementarySchool",(_variant_t)m_strEleSchool);
//初中学校名称
m_pRecordset->PutCollect("JuniorSchool",(_variant_t)m_strJunSchool);
//高中学校名称
m_pRecordset->PutCollect("SeniorSchool",(_variant_t)m_strSenSchool);
m_pRecordset->Update();
break;
case 2:
if(m_pRecordset->GetRecordCount()!=0)
{
m_pRecordset->MoveFirst();
while(!m_pRecordset->adoEOF)
{
id=m_pRecordset->GetCollect("ID").bstrVal;
if(id.CompareNoCase(m_strId) == 0)
{
//小学开始时间
str.Format("%d-%d-%d",m_timeEleStart.GetYear(),m_timeEleStart.GetMonth(),m_timeEleStart.GetDay());
m_pRecordset->PutCollect("ElementaryStart",(_variant_t)str);
//小学结束时间
str.Format("%d-%d-%d",m_timeEleEnd.GetYear(),m_timeEleEnd.GetMonth(),m_timeEleEnd.GetDay());
m_pRecordset->PutCollect("ElementaryEnd",(_variant_t)str);
//初中开始时间
str.Format("%d-%d-%d",m_timeJunStart.GetYear(),m_timeJunStart.GetMonth(),m_timeJunStart.GetDay());
m_pRecordset->PutCollect("JuniorStart",(_variant_t)str);
//初中结束时间
str.Format("%d-%d-%d",m_timeJunEnd.GetYear(),m_timeJunEnd.GetMonth(),m_timeJunEnd.GetDay());
m_pRecordset->PutCollect("JuniorEnd",(_variant_t)str);
//高中开始时间
str.Format("%d-%d-%d",m_timeSenStart.GetYear(),m_timeSenStart.GetMonth(),m_timeSenStart.GetDay());
m_pRecordset->PutCollect("SeniorStart",(_variant_t)str);
//高中结束时间
str.Format("%d-%d-%d",m_timeSenEnd.GetYear(),m_timeSenEnd.GetMonth(),m_timeSenEnd.GetDay());
m_pRecordset->PutCollect("SeniorEnd",(_variant_t)str);
//小学学校名称
m_pRecordset->PutCollect("ElementarySchool",(_variant_t)m_strEleSchool);
//初中学校名称
m_pRecordset->PutCollect("JuniorSchool",(_variant_t)m_strJunSchool);
//高中学校名称
m_pRecordset->PutCollect("SeniorSchool",(_variant_t)m_strSenSchool);
}
m_pRecordset->MoveNext();
}
}
break;
case 3:
if(m_pRecordset->GetRecordCount()!=0)
{
m_pRecordset->MoveFirst();
while(!m_pRecordset->adoEOF)
{
id=m_pRecordset->GetCollect("ID").bstrVal;
if(id.CompareNoCase(m_strId) == 0)
m_pRecordset->Delete(adAffectCurrent);
m_pRecordset->MoveNext();
}
}
break;
default:
break;
}
m_pRecordset->Close();
UpdateData(FALSE);
action = 0;
OnInitDialog();
}
void CExperienceDlg::OnLookforExperienceBtn()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
MessageBox("请在学号输入框中输入您要查询的学生学号","教育经历");
SelectType=1;
m_strEleSchool = "";
m_strId = "";
m_strName = "";
m_strJunSchool = "";
m_strSenSchool = "";
m_ID.SetFocus();
UpdateData(FALSE);
}
void CExperienceDlg::OnKillfocusEditExpId()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString sql,str;
sql = "select * from StudentExperience where ID = '"+m_strId+"'";
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)
{
m_strName = m_pRecordset->GetCollect("Name").bstrVal;
m_strEleSchool = m_pRecordset->GetCollect("ElementarySchool").bstrVal;
m_strJunSchool = m_pRecordset->GetCollect("JuniorSchool").bstrVal;
m_strSenSchool = m_pRecordset->GetCollect("SeniorSchool").bstrVal;
str = m_pRecordset->GetCollect("ElementaryStart").bstrVal;
m_timectrlEleStart.SetFormat(str);
str = m_pRecordset->GetCollect("ElementaryEnd").bstrVal;
m_timectrlEleEnd.SetFormat(str);
str = m_pRecordset->GetCollect("JuniorStart").bstrVal;
m_timectrlJunStart.SetFormat(str);
str = m_pRecordset->GetCollect("JuniorEnd").bstrVal;
m_timectrlJunEnd.SetFormat(str);
str = m_pRecordset->GetCollect("SeniorStart").bstrVal;
m_timectrlSenStart.SetFormat(str);
str = m_pRecordset->GetCollect("SeniorEnd").bstrVal;
m_timectrlSenEnd.SetFormat(str);
}
else
{
if (SelectType==1)
{
MessageBox("该学号的学生记录不存在","教育经历");
}
m_strEleSchool = "";
m_strId = "";
m_strName = "";
m_strJunSchool = "";
m_strSenSchool = "";
}
SelectType=0;
UpdateData(FALSE);
m_pRecordset->Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -