?? adddlg.cpp
字號:
#include "stdafx.h"
#include "cc.h"
#include "ccdlg.h"
#include "AddDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CCcApp theApp;
/////////////////////////////////////////////////////////////////////////////
CAddDlg::CAddDlg(CWnd* pParent /*=NULL*/): CDialog(CAddDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAddDlg)
m_strName = _T("");
CString strTimeNow; //得到系統(tǒng)時間
CTime now=CTime::GetCurrentTime();
strTimeNow=now.Format(_T("%Y%m%d"));
m_date1 =strTimeNow;
m_date2 =strTimeNow;
m_bPassed = FALSE;
m_strCollege = _T("");
m_strReason = _T("");
m_strRemark = _T("");
//}}AFX_DATA_INIT
}
void CAddDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAddDlg)
DDX_Text(pDX, IDC_EDIT2, m_strName);
DDX_Text(pDX, IDC_DATETIMEPICKER1, m_date1);
DDX_Text(pDX, IDC_DATETIMEPICKER2, m_date2);
DDX_Check(pDX, IDC_CHECK, m_bPassed);
DDX_Text(pDX, IDC_COLLEGE, m_strCollege);
DDX_Text(pDX, IDC_REASON, m_strReason);
DDX_Text(pDX, IDC_REMARK, m_strRemark);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAddDlg, CDialog)
//{{AFX_MSG_MAP(CAddDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
void CAddDlg::OnOK()
{
UpdateData();
if(m_date2 < m_date1)
{
MessageBox("請輸入正確的起止時間!");
return;
}
try
{
_variant_t RecordsAffected;
if(!m_bAddOrModify) //如果是添加記錄的話就執(zhí)行SQL語句進行添加
{
CTime now=CTime::GetCurrentTime(); CString strNowTime;
strNowTime=now.Format(_T("%Y年%m月%d日%H時%M分%S秒"));
char YorN;
m_bPassed? YorN='Y' : YorN='N';
theApp.m_strSQL="INSERT INTO Records (Name,YorN,College,date1,date2,Reason,Remark,Flag) values('"+m_strName+"','"+YorN+"','"+m_strCollege+"','"+m_date1+"','"+m_date2+"','"+m_strReason+"','"+m_strRemark+"','"+strNowTime+"')";
theApp.m_pConnection->Execute((_bstr_t)theApp.m_strSQL,&RecordsAffected,adCmdText);
//AfxMessageBox("成功插入1條數(shù)據(jù)!");
m_strName="";
m_strCollege="";
m_strReason="";
m_strRemark="";
UpdateData(false);
}
else //如果是修改記錄的話就執(zhí)行SQL語句進行數(shù)據(jù)庫的更新
{
UpdateData();
char YorN;
m_bPassed? YorN='Y' : YorN='N';
theApp.m_strSQL="update Records set Name='"+m_strName+
"',YorN='"+YorN+
"',College='"+m_strCollege+
"',Reason='"+m_strReason+
"',date1='"+m_date1+
"',date2='"+m_date2+
"',Remark='"+m_strRemark+
"' where Flag='"+m_strFlag+"'";
_variant_t RecordsAffected;
theApp.m_pConnection->Execute((_bstr_t)theApp.m_strSQL,&RecordsAffected,adCmdText);
}
((CCcDlg*)AfxGetMainWnd())->List("SELECT * FROM Records");; //更新列表框的顯示
CDialog::OnOK();
}
catch(_com_error e)
{
CATCH_ERROR;
}
}
BOOL CAddDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CString strTimeNow; //得到系統(tǒng)時間
CTime now=CTime::GetCurrentTime();
strTimeNow=now.Format(_T("%Y%m%d"));
theApp.m_strSQL="select * from Records where Name='"
+m_strName+"' and College='"
+m_strCollege+"' and Reason='"
+m_strReason+"' and date1='"
+m_date1+"' and date2='"
+m_date2+"' and Remark='"
+m_strRemark+"'";
_RecordsetPtr m_pRecordset;
switch(this->m_bAddOrModify) //根據(jù)主窗口轉(zhuǎn)來的數(shù)據(jù)判斷是否是添加記錄還是修改。
{
case 0:
SetWindowText("添加請假記錄");
break;
case 1:
SetWindowText("修改記錄");
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)theApp.m_strSQL,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF)
{
m_strFlag=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Flag");
}
m_pRecordset->Close();
}
catch(_com_error e)///捕捉異常
{
CATCH_ERROR;
}
break;
}
return TRUE;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -