📄 workdlg.cpp
字号:
// WorkDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Work.h"
#include "WorkDlg.h"
#include "LogDialog.h"
#include "CommonData.h"
#include "CJianSuo.h"
#include "Personal.h"
#include "ChangeP.h"
#include "YuYueHistory.h"
#include "JHistory1.h"
#include "JHistory2.h"
#include "WeiZhang.h"
#include "JieShu.h"
#include "HuanShu.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWorkDlg dialog
CWorkDlg::CWorkDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWorkDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWorkDlg)
m_UserName = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CWorkDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWorkDlg)
DDX_Control(pDX, IDC_HUANSHU_BTN, m_HuanShu_Btn);
DDX_Control(pDX, IDC_JIESHU_BTN, m_JieShu_Btn);
DDX_Control(pDX, IDC_WEIZHANG_BTN, m_WeiZhang_Btn);
DDX_Control(pDX, IDC_CHANGEP_BTN, m_ChangeP_Btn);
DDX_Control(pDX, IDC_PERSONAL_BTN, m_Personal_Btn);
DDX_Control(pDX, IDC_BYUYUE_BTN, m_BYuYue_Btn);
DDX_Control(pDX, IDC_JHistory_Btn2, m_JHistory_Btn2);
DDX_Control(pDX, IDC_JHistory_Btn1, m_JHistory_Btn1);
DDX_Control(pDX, IDC_JianSuo_Btn, m_JianSuo_Btn);
DDX_Control(pDX, IDC_LOGOUT_BTN, m_Logout_Btn);
DDX_Control(pDX, IDC_LOGIN_BTN, m_Login_Btn);
DDX_Text(pDX, IDC_UserName_STATIC, m_UserName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWorkDlg, CDialog)
//{{AFX_MSG_MAP(CWorkDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_LOGIN_BTN, OnLoginBtn)
ON_BN_CLICKED(IDC_LOGOUT_BTN, OnLogoutBtn)
ON_BN_CLICKED(IDC_JianSuo_Btn, OnJianSuoBtn)
ON_BN_CLICKED(IDC_PERSONAL_BTN, OnPersonalBtn)
ON_BN_CLICKED(IDC_CHANGEP_BTN, OnChangepBtn)
ON_BN_CLICKED(IDC_BYUYUE_BTN, OnByuyueBtn)
ON_BN_CLICKED(IDC_JHistory_Btn1, OnJHistoryBtn1)
ON_BN_CLICKED(IDC_JHistory_Btn2, OnJHistoryBtn2)
ON_BN_CLICKED(IDC_WEIZHANG_BTN, OnWeizhangBtn)
ON_BN_CLICKED(IDC_JIESHU_BTN, OnJieshuBtn)
ON_BN_CLICKED(IDC_HUANSHU_BTN, OnHuanshuBtn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWorkDlg message handlers
BOOL CWorkDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CWorkDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CWorkDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CWorkDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CWorkDlg::OnLoginBtn()
{
// TODO: Add your control notification handler code here
CLogDialog newUser;
if(newUser.DoModal()==IDOK)
{
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance("ADODB.Recordset");
try
{
m_pRecordset->Open("SELECT * FROM Stu_Infor",_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
}
catch(_com_error& e)
{
MessageBox(e.Description());
}
CString Number,Password;
Number=CCommonData::userNumber;
Password=CCommonData::UserPassword;
bool search=false;
while(!m_pRecordset->adoEOF)
{
CString RealNumber,RealPassword;
RealNumber=(LPCTSTR)_bstr_t(m_pRecordset->GetCollect("SNumber"));
RealPassword=(LPCTSTR)_bstr_t(m_pRecordset->GetCollect("SPassword"));
if(RealNumber==Number&&RealPassword==Password)
{
CCommonData::UserName=(LPCTSTR)_bstr_t(m_pRecordset->GetCollect("SName"));
m_UserName=CCommonData.UserName;
m_Login_Btn.ShowWindow(0);
m_Logout_Btn.ShowWindow(1);
UpdateData(FALSE);
search=true;
break;
}
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
if(search==false)
{
MessageBox("登录信息错误……");
CCommonData::UserName="";
CCommonData::userNumber="";
CCommonData::UserPassword="";
return;
}
//是否是管理员
if(CCommonData::userNumber=="00000001")
{
m_JieShu_Btn.ShowWindow(1);
m_HuanShu_Btn.ShowWindow(1);
m_Personal_Btn.ShowWindow(1);
m_ChangeP_Btn.ShowWindow(1);
m_JianSuo_Btn.ShowWindow(1);
m_WeiZhang_Btn.ShowWindow(0);
m_BYuYue_Btn.ShowWindow(0);
m_JHistory_Btn1.ShowWindow(0);
m_JHistory_Btn2.ShowWindow(0);
UpdateData(FALSE);
//对数据库进行相应的检查
CString QueryString="SELECT * FROM Book_Borrow_Infor";
CString BPreDate,BBorrowDate,BReturnDate,BIsReturned,BNTiaoMa;
int year,month,day;
m_pRecordset->Open((_bstr_t)QueryString,_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(!m_pRecordset->BOF)
{
bool ShouldMove=true;
m_pRecordset->MoveFirst();
while(!m_pRecordset->adoEOF)
{
BIsReturned=(LPCTSTR)_bstr_t(m_pRecordset->GetCollect("BIsReturned"));
if(BIsReturned=="0") //未还的书或预约的书籍
{
BPreDate=(LPCTSTR)_bstr_t(m_pRecordset->GetCollect("BPreDate"));
BNTiaoMa=(LPCTSTR)_bstr_t(m_pRecordset->GetCollect("BNTiaoMa"));
if(BPreDate=="3000-1-1") //非预约书籍
{
BReturnDate=(LPCTSTR)_bstr_t(m_pRecordset->GetCollect("BReturnDate"));
sscanf(BReturnDate,"%d-%d-%d",&year,&month,&day);
CTime qdate(year,month,day);
CTime now=CTime::GetCurrentTime();
if(qdate<now)//逾期,插入违章记录
{
_RecordsetPtr m_pRecordset1;
m_pRecordset1.CreateInstance("ADODB.Recordset");
CString QueryString1="SELECT * FROM WeiZhang_Infor";
m_pRecordset1->Open((_bstr_t)QueryString1,_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
bool can=true;
if(!m_pRecordset1->BOF) //是否已有此记录
{
m_pRecordset1->MoveFirst();
while(!m_pRecordset1->adoEOF)
{
CString IsOK,tiaoma;
IsOK=(LPCTSTR)_bstr_t(m_pRecordset1->GetCollect("IsOK"));
tiaoma=(LPCTSTR)_bstr_t(m_pRecordset1->GetCollect("BNTiaoMa"));
if(IsOK=="0"&&tiaoma==BNTiaoMa)
{
can=false;
break;
}
m_pRecordset1->MoveNext();
}
}
if(can==true)
{
m_pRecordset1->AddNew();
m_pRecordset1->PutCollect("BSNumber",(_variant_t)Number);
m_pRecordset1->PutCollect("BTime",(_variant_t)BReturnDate);
m_pRecordset1->PutCollect("BNTiaoMa",(_variant_t)BNTiaoMa);
m_pRecordset1->PutCollect("IsOK","0");
m_pRecordset1->Update();
m_pRecordset1->Close();
}
}
}
else //预约书籍
{
sscanf(BPreDate,"%d-%d-%d",&year,&month,&day);
CTime ydate(year,month,day),now;
CTimeSpan t(3,0,0,0);
now=CTime::GetCurrentTime();
if(now>(ydate+t)) //预约已到期
{
m_pRecordset->Delete(adAffectCurrent); // 参数adAffectCurrent为删除当前记录
m_pRecordset->Update();
ShouldMove=false;
//修改Book_Infor中的CanBorrowDate为当前日期
BNTiaoMa=(LPCTSTR)_bstr_t(m_pRecordset->GetCollect("BNTiaoMa"));
_RecordsetPtr m_pRecordset1;
m_pRecordset1.CreateInstance("ADODB.Recordset");
CString QueryString1="SELECT * FROM Book_Infor WHERE BNTiaoMa='"+BNTiaoMa+"'";
m_pRecordset1->Open((_bstr_t)QueryString1,_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
m_pRecordset1->MoveFirst();
m_pRecordset1->PutCollect("BCanBorrowDate","2000-1-1");
m_pRecordset1->Close();
}
}
}
if(ShouldMove==true)
{
m_pRecordset->MoveNext();
}
else
{
ShouldMove=false;
}
}
}
m_pRecordset->Close();
return;
}
//运行到此说明登录成功且非管理员,现验证是否有违章记录
CString isWeiZhang="SELECT * FROM WeiZhang_Infor where BSNumber='"+CCommonData::userNumber+"' AND IsOK=0";
m_pRecordset->Open((_bstr_t)isWeiZhang,_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(!m_pRecordset->BOF)
{
m_Personal_Btn.ShowWindow(1);
m_ChangeP_Btn.ShowWindow(1);
m_WeiZhang_Btn.ShowWindow(1);
m_JianSuo_Btn.ShowWindow(0);
m_JieShu_Btn.ShowWindow(0);
m_HuanShu_Btn.ShowWindow(0);
m_BYuYue_Btn.ShowWindow(0);
m_JHistory_Btn1.ShowWindow(0);
m_JHistory_Btn2.ShowWindow(0);
UpdateData(FALSE);
MessageBox("您欠款啦……");
return;
}
//正常用户
m_Personal_Btn.ShowWindow(1);
m_ChangeP_Btn.ShowWindow(1);
m_WeiZhang_Btn.ShowWindow(1);
m_JianSuo_Btn.ShowWindow(1);
m_JieShu_Btn.ShowWindow(0);
m_HuanShu_Btn.ShowWindow(0);
m_BYuYue_Btn.ShowWindow(1);
m_JHistory_Btn1.ShowWindow(1);
m_JHistory_Btn2.ShowWindow(1);
UpdateData(FALSE);
}
}
void CWorkDlg::OnLogoutBtn()
{
// TODO: Add your control notification handler code here
int yes=MessageBox("确定登出?","登出",MB_YESNO);
if(yes==IDYES)
{
CCommonData::UserName="";
CCommonData::userNumber="";
CCommonData::UserPassword="";
m_UserName="";
m_Login_Btn.ShowWindow(1);
m_Logout_Btn.ShowWindow(0);
m_JianSuo_Btn.ShowWindow(1);
m_Personal_Btn.ShowWindow(0);
m_ChangeP_Btn.ShowWindow(0);
m_WeiZhang_Btn.ShowWindow(0);
m_JieShu_Btn.ShowWindow(0);
m_HuanShu_Btn.ShowWindow(0);
m_BYuYue_Btn.ShowWindow(0);
m_JHistory_Btn1.ShowWindow(0);
m_JHistory_Btn2.ShowWindow(0);
UpdateData(FALSE);
}
}
void CWorkDlg::OnCancel()
{
// TODO: Add extra cleanup here
m_pConnection->Close();
CDialog::OnCancel();
}
void CWorkDlg::OnJianSuoBtn()
{
// TODO: Add your control notification handler code here
CCJianSuo newJianSuo;
newJianSuo.DoModal();
}
void CWorkDlg::OnPersonalBtn()
{
// TODO: Add your control notification handler code here
CPersonal newP;
newP.DoModal();
}
void CWorkDlg::OnChangepBtn()
{
// TODO: Add your control notification handler code here
CChangeP newCh;
newCh.DoModal();
}
void CWorkDlg::OnByuyueBtn()
{
// TODO: Add your control notification handler code here
CYuYueHistory newHistory;
newHistory.DoModal();
}
void CWorkDlg::OnJHistoryBtn1() //察看当前正在借阅的书籍
{
// TODO: Add your control notification handler code here
CJHistory1 newJHistory1;
newJHistory1.DoModal();
}
void CWorkDlg::OnJHistoryBtn2()
{
// TODO: Add your control notification handler code here
CJHistory2 newJHistory2;
newJHistory2.DoModal();
}
void CWorkDlg::OnWeizhangBtn()
{
// TODO: Add your control notification handler code here
CWeiZhang newWeiZhang;
newWeiZhang.DoModal();
}
void CWorkDlg::OnJieshuBtn()
{
// TODO: Add your control notification handler code here
CJieShu newJieShu;
newJieShu.DoModal();
}
void CWorkDlg::OnHuanshuBtn()
{
// TODO: Add your control notification handler code here
CHuanShu newHuanShu;
newHuanShu.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -