?? returndlg.cpp
字號:
// ReturnDlg.cpp : implementation file
//
#include "stdafx.h"
#include "lib.h"
#include "ReturnDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CReturnDlg dialog
CReturnDlg::CReturnDlg(CWnd* pParent /*=NULL*/)
: CDialog(CReturnDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CReturnDlg)
m_Bookid = _T("");
m_Userid = _T("");
m_Bookname = _T("");
m_Booknum = _T("");
m_Borrownum = _T("");
m_Username = _T("");
//}}AFX_DATA_INIT
returnStyle=1;
}
void CReturnDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CReturnDlg)
DDX_Text(pDX, IDC_EDIT_BOOKID, m_Bookid);
DDX_Text(pDX, IDC_EDIT_USERID, m_Userid);
DDX_Text(pDX, IDC_STATIC_BOOKNAME, m_Bookname);
DDX_Text(pDX, IDC_STATIC_BOOKNUM, m_Booknum);
DDX_Text(pDX, IDC_STATIC_BORROWNUM, m_Borrownum);
DDX_Text(pDX, IDC_STATIC_USERNAME, m_Username);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CReturnDlg, CDialog)
//{{AFX_MSG_MAP(CReturnDlg)
ON_BN_CLICKED(IDC_BUTTON1, OnReturn)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CReturnDlg message handlers
void CReturnDlg::OnReturn()
{
// TODO: Add your control notification handler code here
// TODO: Add your control notification handler code here
UpdateData();
if(CheckValid())
{
CString pp;
UpdateData(false);
SaveData();
pp="歸還成功";
if (returnStyle!="0") pp=pp+price;
AfxMessageBox(pp);
}
}
void CReturnDlg::OnRadio1()
{
// TODO: Add your control notification handler code here
returnStyle="0";
}
void CReturnDlg::OnRadio2()
{
// TODO: Add your control notification handler code here
returnStyle="1";
}
void CReturnDlg::OnRadio3()
{
// TODO: Add your control notification handler code here
returnStyle="2";
}
BOOL CReturnDlg::CheckValid()
{
//檢查輸入的合法性
char buffer[20];//
if(m_Userid.IsEmpty() || m_Bookid.IsEmpty())
{
AfxMessageBox("請輸入借書證號和書號!");
return false;
}
m_UserSet.Open();
m_UserSet.m_strFilter="userid='"+m_Userid+"'";
m_UserSet.Requery();
if(m_UserSet.GetRecordCount()==0)
{
AfxMessageBox("您的借書證號輸入有誤,請重新輸入!");
GetDlgItem(IDC_EDIT_USERID)->SetFocus();
m_UserSet.Close();
return false;
}
else
{
m_Username=m_UserSet.m_username;//
ltoa(m_UserSet.m_borrownum,buffer,10);
m_Borrownum=buffer;//
UpdateData(false);//
};
m_BookSet.Open();
m_BookSet.m_strFilter="bookid='"+m_Bookid+"'";
m_BookSet.Requery();
if(m_BookSet.GetRecordCount()==0)
{
AfxMessageBox("您的書號輸入有誤,請重新輸入!");
GetDlgItem(IDC_EDIT_BOOKID)->SetFocus();
m_UserSet.Close();
m_BookSet.Close();
return false;
}
else
{
m_Bookname=m_BookSet.m_bookname;//
ltoa(m_BookSet.m_remain,buffer,10);
m_Booknum=buffer;//
UpdateData(false);//
}
///////檢驗(yàn)此人是否借此書//////////////
m_BorrowSet.Open();
CString ppstr;
ppstr="userid='"+m_Userid+"'"+"and bookid='"+m_Bookid+"'"+"and remaindate<=30";
// ppstr="PP='"+m_pp+"'"+"and "+"&&LX='"+m_gn+"'";
m_BorrowSet.m_strFilter=ppstr;
m_BorrowSet.Requery();
//m_BorrowSet.m_remaindata==999
if(m_BorrowSet.GetRecordCount()==0)
{
AfxMessageBox("你未借此書,請重新輸入!");
GetDlgItem(IDC_EDIT_BOOKID)->SetFocus();
m_UserSet.Close();
m_BookSet.Close();
m_BorrowSet.Close();
return false;
}
return true;
}
void CReturnDlg::SaveData()
{
//將數(shù)據(jù)保存到數(shù)據(jù)庫
//設(shè)置借書期限是一個月
char buffer[20];
//CTimeSpan m_BorrowSpan(30,0,0,0);
//m_BorrowTime=CTime::GetCurrentTime();
//m_ReturnTime=m_BorrowTime+m_BorrowSpan;
//注銷borrow表中的借期
m_BorrowSet.Edit();
m_BorrowSet.m_remaindate=999;
m_BorrowSet.Update();
//保存數(shù)據(jù)到user表
m_UserSet.Edit();
m_UserSet.m_borrownum--;
m_UserSet.Update();
//保存數(shù)據(jù)到book表
if (returnStyle=="0")
{
m_BookSet.Edit();
m_BookSet.m_remain++;
m_BookSet.Update();
}
//更新對話框的數(shù)據(jù)
ltoa(m_BookSet.m_remain,buffer,10);
m_Booknum=buffer;//
ltoa(m_UserSet.m_borrownum,buffer,10);
m_Borrownum=buffer;
//
//計算罰金 處理損毀書
price=m_BookSet.m_price;
int strLength=price.GetLength();//使價格只保留兩位小數(shù)
price=price.Left(strLength-2);
price=" 您應(yīng)賠償"+price+"*"+returnStyle;
m_BorrowSet.Close();
m_UserSet.Close();
m_BookSet.Close();
UpdateData(false);
if (returnStyle=="1")
BookRepair();
if (returnStyle=="2")
BookDel();
//關(guān)閉數(shù)據(jù)集
}
void CReturnDlg::BookRepair()
{
m_BorrowSet.Open();
m_UserSet.Open();
//保存數(shù)據(jù)到borrow表
m_BorrowSet.AddNew();
m_BorrowSet.m_userid="10000";
m_BorrowSet.m_bookid=m_Bookid;
m_BorrowSet.m_remaindate=15;//假定修書期限為十五天
m_BorrowSet.Update();
//保存數(shù)據(jù)到user表
m_UserSet.m_strFilter="userid='10000'";
m_UserSet.Requery();
m_UserSet.Edit();
m_UserSet.m_borrownum+=1;
m_UserSet.Update();
m_BorrowSet.Close();
m_UserSet.Close();
}
void CReturnDlg::BookDel()
{
m_BorrowSet.Open();
m_UserSet.Open();
//保存數(shù)據(jù)到borrow表
m_BorrowSet.AddNew();
m_BorrowSet.m_userid="10001";
m_BorrowSet.m_bookid=m_Bookid;
m_BorrowSet.m_remaindate=1000;//假定修書期限為十五天
m_BorrowSet.Update();
//保存數(shù)據(jù)到user表
m_UserSet.m_strFilter="userid='10001'";
m_UserSet.Requery();
m_UserSet.Edit();
m_UserSet.m_borrownum+=1;
m_UserSet.Update();
m_BorrowSet.Close();
m_UserSet.Close();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -