📄 statereport.cpp
字号:
// StateReport.cpp : implementation file
//
#include "stdafx.h"
#include "SoftDocSystem.h"
#include "StateReport.h"
#include "LogMngr.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStateReport dialog
extern CString PublicUserName;
CStateReport::CStateReport(CWnd* pParent /*=NULL*/)
: CDialog(CStateReport::IDD, pParent)
{
//{{AFX_DATA_INIT(CStateReport)
m_NowState = -1;
m_howtoget = -1;
m_SName = _T("");
m_SAuthor = _T("");
m_SZhuang = _T("");
m_RName = _T("");
m_RAddr = _T("");
m_SDay = _T("");
m_RAuthor = _T("");
m_Xinghao = _T("");
m_suoqu = _T("");
//}}AFX_DATA_INIT
}
void CStateReport::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStateReport)
DDX_Control(pDX, IDC_COMBO4, m_suoquCtrl);
DDX_Control(pDX, IDC_COMBO2, m_XinghaoCtrl);
DDX_Control(pDX, IDC_UNAME, m_UserName);
DDX_Radio(pDX, IDC_RADIO1, m_NowState);
DDX_Radio(pDX, IDC_RADIO3, m_howtoget);
DDX_Text(pDX, IDC_EDIT2, m_SName);
DDX_Text(pDX, IDC_EDIT3, m_SAuthor);
DDX_Text(pDX, IDC_EDIT4, m_SZhuang);
DDX_Text(pDX, IDC_EDIT6, m_RName);
DDX_Text(pDX, IDC_EDIT7, m_RAddr);
DDX_Text(pDX, IDC_EDIT9, m_SDay);
DDX_Text(pDX, IDC_EDIT8, m_RAuthor);
DDX_CBString(pDX, IDC_COMBO2, m_Xinghao);
DDX_CBString(pDX, IDC_COMBO4, m_suoqu);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStateReport, CDialog)
//{{AFX_MSG_MAP(CStateReport)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDOK, OnApply)
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStateReport message handlers
void CStateReport::OnRadio1()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_EDIT2)->EnableWindow(true);
GetDlgItem(IDC_EDIT3)->EnableWindow(true);
GetDlgItem(IDC_EDIT9)->EnableWindow(true);
GetDlgItem(IDC_EDIT4)->EnableWindow(true);
GetDlgItem(IDC_COMBO2)->EnableWindow(true);
GetDlgItem(IDC_EDIT8)->EnableWindow(false);
GetDlgItem(IDC_EDIT6)->EnableWindow(false);
GetDlgItem(IDC_EDIT7)->EnableWindow(false);
GetDlgItem(IDC_CHECK2)->EnableWindow(false);
GetDlgItem(IDC_CHECK3)->EnableWindow(false);
GetDlgItem(IDC_CHECK4)->EnableWindow(false);
GetDlgItem(IDC_COMBO4)->EnableWindow(false);
GetDlgItem(IDC_RADIO3)->EnableWindow(false);
GetDlgItem(IDC_RADIO4)->EnableWindow(false);
NowState="1";
}
void CStateReport::OnRadio2()
{
// TODO: Add your control notification handler code here
Initiate();
}
BOOL CStateReport::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
((CButton*)GetDlgItem(IDC_RADIO2))->SetCheck(true);
//改变字体
LOGFONT LogFont;
(CFont*)CWnd::GetFont()->GetLogFont(&LogFont);
LogFont.lfItalic=true;
strcpy(LogFont.lfFaceName,"楷体_GB2312");
LogFont.lfHeight=LogFont.lfHeight*1.5;
LogFont.lfWidth=LogFont.lfWidth*1.5;
m_font.CreateFontIndirect(&LogFont);
GetDlgItem(IDC_UNAME)->SetFont(&m_font,true);
//Databaxe Initialled
_bstr_t source("Provider=sqloledb;Data Source=;Integrated Security='SSPI';Initial Catalog=SoftDocument;User Id=;Password=;");
_bstr_t user("");
_bstr_t pwd("");
HRESULT hr;
try{
hr = m_DBCnt.CreateInstance(_uuidof(Connection));
if(SUCCEEDED(hr))
hr = m_DBCnt->Open(source, user, pwd, 16);
if(SUCCEEDED(hr))
{m_fConnected = TRUE;
}
else
m_fConnected = FALSE;
}
catch (_com_error &e){
MessageBox(e.ErrorMessage());
m_fConnected = FALSE;
}
if(!m_fConnected)
{MessageBox("ADO数据源初始化失败!");
return false;}
Initiate();
if(PublicUserName=="")PublicUserName="一般用户";
GetDlgItem(IDC_UNAME)->SetWindowText(PublicUserName);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CStateReport::Initiate()
{
GetDlgItem(IDC_EDIT2)->EnableWindow(false);
GetDlgItem(IDC_EDIT3)->EnableWindow(false);
GetDlgItem(IDC_EDIT9)->EnableWindow(false);
GetDlgItem(IDC_EDIT4)->EnableWindow(false);
GetDlgItem(IDC_COMBO2)->EnableWindow(false);
GetDlgItem(IDC_EDIT8)->EnableWindow(true);
GetDlgItem(IDC_EDIT6)->EnableWindow(true);
GetDlgItem(IDC_EDIT7)->EnableWindow(true);
GetDlgItem(IDC_CHECK2)->EnableWindow(true);
GetDlgItem(IDC_CHECK3)->EnableWindow(true);
GetDlgItem(IDC_CHECK4)->EnableWindow(true);
GetDlgItem(IDC_COMBO4)->EnableWindow(false);
GetDlgItem(IDC_RADIO3)->EnableWindow(true);
GetDlgItem(IDC_RADIO4)->EnableWindow(true);
((CButton*)GetDlgItem(IDC_RADIO4))->SetCheck(true);
}
void CStateReport::OnApply()
{
// TODO: Add your control notification handler code here
UpdateData();
CString StateNumber;
CTime tm=CTime::GetCurrentTime ();
StateNumber.Format("SR%d%02d%02d%02d%02d%02d",tm.GetYear (),tm.GetMonth (),tm.GetDay(),tm.GetHour(),tm.GetMinute(),tm.GetSecond ());
if(m_NowState==0){
//判断输入正确性
if(m_SName==""){AfxMessageBox("请输入软件名称!");return;}
if(m_SAuthor==""){AfxMessageBox("请输入软件作者");return;}
if(m_SDay==""){AfxMessageBox("请输入需要天数!");return;}
if(m_Xinghao==""){AfxMessageBox("请输入型号名称!");return;}
if(m_SZhuang==""){AfxMessageBox("请输入状态描述!");return;}
//输入数据库
CString str1;
str1.Format ("%d-%d-%d",tm.GetYear (),tm.GetMonth(),tm.GetDay ());
CString sql_;
sql_.Format ("INSERT INTO StateReport (状态编号,用户名,状态,软件名称,软件作者,剩余时间,用于型号,状态描述,汇报时间) VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s')",StateNumber,PublicUserName,NowState,m_SName,m_SAuthor,m_SDay,m_Xinghao,m_SZhuang,str1);
_bstr_t sql=sql_;
try{
m_DBCnt->Execute (sql,NULL,adCmdText);}
catch (_com_error &e){
AfxMessageBox(e.ErrorMessage()); return;}
CString str2;
str2.Format ("Dear %s,你的信息已成功成功输入!",PublicUserName);
AfxMessageBox(str2);
}
else
{
//判断输入正确性
CString XingShi,SuoAddr;
XingShi.Empty();
if(((CButton*)GetDlgItem(IDC_CHECK2))->GetCheck())XingShi="光盘、磁盘";
if(((CButton*)GetDlgItem(IDC_CHECK3))->GetCheck())XingShi+="、文本";
if(((CButton*)GetDlgItem(IDC_CHECK4))->GetCheck())XingShi+="、其他";
if(XingShi.IsEmpty()){AfxMessageBox("请输入文档形式!");return;}
if(m_RName==""){AfxMessageBox("请输入软件名称!");return;}
if(m_RAuthor==""){AfxMessageBox("请输入软件作者");return;}
//回复
CString strTime;
m_suoquCtrl.GetWindowText(strTime);
if(m_howtoget==0){if(strTime==""){AfxMessageBox("请输入索取地址!");return;}
else
SuoAddr=strTime;
}
else
{if(m_RAddr==""){AfxMessageBox("请输入交给管理员的时间!");return;}
else
SuoAddr=m_RAddr;}
//输入数据库
CString str1,str3;
str1.Format ("%d-%d-%d",tm.GetYear (),tm.GetMonth(),tm.GetDay ());
CString sql_;
sql_.Format ("INSERT INTO StateReport (状态编号,用户名,状态,软件名称,软件作者,文档形式,索取地址,汇报时间) VALUES('%s','%s','%s','%s','%s','%s','%s','%s')",StateNumber,PublicUserName,NowState,m_RName,m_RAuthor,XingShi,SuoAddr,str1);
_bstr_t sql=sql_;
try{
m_DBCnt->Execute (sql,NULL,adCmdText);}
catch (_com_error &e){
AfxMessageBox(e.ErrorMessage()); return;}
CString str2;
str2.Format ("Dear %s,你的信息已成功输入!",PublicUserName);
AfxMessageBox(str2);
}
}
void CStateReport::OnRadio3()
{
// TODO: Add your control notification handler code here
NowState="2";
GetDlgItem(IDC_COMBO4)->EnableWindow(true);
GetDlgItem(IDC_EDIT7)->EnableWindow(false);
}
void CStateReport::OnRadio4()
{
// TODO: Add your control notification handler code here
NowState="3";
GetDlgItem(IDC_COMBO4)->EnableWindow(false);
GetDlgItem(IDC_EDIT7)->EnableWindow(true);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -