?? 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 + -