⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bookregdlg.cpp

📁 LibraryManageDM.rar 数据库设计图书馆管理系统
💻 CPP
字号:
// BookRegDlg.cpp : implementation file
//

#include "stdafx.h"
#include "LibraryManage.h"
#include "BookRegDlg.h"
#include "BookTypeSet.h"
#include "BorrowInfoSet.h"
#include "CommonFunc.h"
// CBookRegDlg dialog

IMPLEMENT_DYNAMIC(CBookRegDlg, CDialog)

CBookRegDlg::CBookRegDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBookRegDlg::IDD, pParent)
    , strBookID_(_T(""))
    , strBookName_(_T(""))
    , strBookType_(_T(""))
    , strAuthor_(_T(""))
    , strPressName_(_T(""))
    , dPrice_(0)
    , olePressDT_(CTime::GetCurrentTime())
    , oleInDT_(CTime::GetCurrentTime())
    , nInNumber_(0)
    , nOutNumber_(0)
    , strDescription_(_T(""))
    , bModify_(FALSE) 
    , bSignOff_(FALSE)
	, bAdd_(FALSE)
{

}

CBookRegDlg::~CBookRegDlg()
{
}

void CBookRegDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBookRegDlg)
    DDX_Control(pDX, IDC_EDIT_BOOKNO, ctrlBookID_);
    DDX_Control(pDX, IDC_EDIT_OUTNUM, ctrlOutNum_);
    DDX_Control(pDX, IDC_EDIT_INNUMBER, ctrlInNum_);
    DDX_Control(pDX, IDC_COMBO_BOOKTYPE, ctrlBookType_);
    DDX_Text(pDX, IDC_EDIT_BOOKNO, strBookID_);
	DDV_MaxChars(pDX, strBookID_, 10);
    DDX_Text(pDX, IDC_EDIT_BOOKNAME, strBookName_);
    DDX_CBString(pDX, IDC_COMBO_BOOKTYPE, strBookType_);
	DDV_MaxChars(pDX, strBookType_, 10);
    DDX_Text(pDX, IDC_EDIT_AUTHOR, strAuthor_);
	DDV_MaxChars(pDX, strAuthor_, 20);
    DDX_Text(pDX, IDC_EDIT_PRESS, strPressName_);
    DDX_Text(pDX, IDC_EDIT_PRICE, dPrice_);
    DDX_Text(pDX, IDC_EDIT_INNUMBER, nInNumber_);
    DDX_Text(pDX, IDC_EDIT_OUTNUM, nOutNumber_);
    DDX_Text(pDX, IDC_EDIT_BOOKDES, strDescription_);
    DDX_DateTimeCtrl(pDX, IDC_PRESSDT, olePressDT_);
    DDX_DateTimeCtrl(pDX, IDC_INDATETIME, oleInDT_);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBookRegDlg, CDialog)
	//{{AFX_MSG_MAP(CBookRegDlg)
    ON_BN_CLICKED(IDOK, OnBnClickedOk)
    ON_EN_CHANGE(IDC_EDIT_BOOKNO, OnEnChangeEditBookno)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


// CBookRegDlg message handlers
BOOL CBookRegDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // TODO:  Add extra initialization here
    CBookTypeSet bktRS;
    CString strSQL = _T("SELECT * FROM BookType");
    if (bAdd_)
    {
        if (bktRS.IsOpen())bktRS.Close();
        if (!bktRS.Open(AFX_DB_USE_DEFAULT_TYPE, strSQL))
        {
            AfxMessageBox(IDS_OPENDBFAIL);
            return FALSE;
        }
        while(!bktRS.IsEOF())
        {
            ctrlBookType_.AddString(bktRS.strTypeName_);
            bktRS.MoveNext();
        }
        bktRS.Close();
    }
    if (bModify_)
    {
        ctrlBookID_.SetReadOnly(!strBookID_.IsEmpty());
        ctrlOutNum_.ShowWindow(SW_NORMAL);
        GetDlgItem(IDC_SOUTNUM)->ShowWindow(SW_NORMAL);
        GetDlgItem(IDOK)->SetWindowText(_T("确定(&C)"));
        SetWindowText(_T("修改图书信息"));
        GetData();        
    }
    if (bSignOff_)
    {
        ctrlBookID_.SetReadOnly(!strBookID_.IsEmpty());
        ctrlOutNum_.ShowWindow(SW_NORMAL);
        GetDlgItem(IDC_SOUTNUM)->ShowWindow(SW_NORMAL);
        GetDlgItem(IDOK)->SetWindowText(_T("遗失(&L)"));
        SetWindowText(_T("图书遗失登记"));
        GetData();
    }
    HICON hIcon;
    hIcon = theApp.LoadIcon(IDI_REGICON);
    SetIcon(hIcon, FALSE);
    
    UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
}

void CBookRegDlg::OnBnClickedOk()
{
    // TODO: Add your control notification handler code here
    UpdateData(TRUE);
    if (strBookID_.IsEmpty())
    {
        MessageBox(_T("请输入图书ID!"), theApp.strSystemName);
        ctrlBookID_.SetFocus();
        return ;
    }
    if (strBookName_.IsEmpty())
    {
        MessageBox(_T("请输入书名!"), theApp.strSystemName);
        GetDlgItem(IDC_EDIT_BOOKNAME)->SetFocus();
        return ;
    }
    if (strBookType_.IsEmpty())
    {
        MessageBox(_T("请选择图书类型!"), theApp.strSystemName);
        GetDlgItem(IDC_COMBO_BOOKTYPE)->SetFocus();
        return ;
    }
    if (strAuthor_.IsEmpty())
    {
        MessageBox(_T("请输入图书作者!"), theApp.strSystemName);
        GetDlgItem(IDC_EDIT_AUTHOR)->SetFocus();
        return ;
    }
    if (strPressName_.IsEmpty())
    {
        MessageBox(_T("请输入出版社名!"), theApp.strSystemName);
        GetDlgItem(IDC_EDIT_PRESS)->SetFocus();
        return ;
    }
    if (dPrice_ <= 0)
    {
        MessageBox(_T("请输入图书价格!"), theApp.strSystemName);
        GetDlgItem(IDC_EDIT_PRICE)->SetFocus();
        return ;
    }
    if (nInNumber_ < 0)
    {
        MessageBox(_T("请输入入库数目(正数)!"), theApp.strSystemName);
        GetDlgItem(IDC_EDIT_INNUMBER)->SetFocus();
        return ;
    }
    CString strSQL;
    strSQL.Format(_T("SELECT * FROM BookInfo WHERE BookID = '%s'"), strBookID_);
    if (bkRS.IsOpen()) bkRS.Close();
    if (!bkRS.Open(AFX_DB_USE_DEFAULT_TYPE, strSQL))
    {
        AfxMessageBox(IDS_OPENDBFAIL);
        return;
    }
	//! 添加图书
	if (bAdd_)
    {
        if(bkRS.GetRecordCount() != 0)
        {
            bkRS.Close();
            MessageBox(_T("该图书已经存在,请重新输入!"), 
                theApp.strSystemName, MB_YESNO);
            return;
        }
        //添加图书记录
        bkRS.AddNew();
        SetData();
        if (!bkRS.Update())
        {
            DWORD dwErrrorCode = GetLastError();
            MessageBox(_T("图书登记失败!"), theApp.strSystemName);
            return;
        }
        else
        {
            if(IDYES == MessageBox(_T("图书登记成功!是否登记下一图书?"), 
                theApp.strSystemName,MB_YESNO))
            {
                bkRS.Close();
                strBookID_.Empty();
                UpdateData(FALSE);
                return;
            }
        }
    }
    //! 修改图书信息
	if (bModify_)
    {
        if(bkRS.GetRecordCount() == 0)
        {
            bkRS.Close();
            MessageBox(_T("该图书不存在,请重新输入!"), theApp.strSystemName);
            return;
        }
        // 修改图书信息
        bkRS.Edit();
        SetData();
        if (!bkRS.Update())
        {
            DWORD dwErrrorCode = GetLastError();
            MessageBox(_T("图书更新失败!"), theApp.strSystemName);
            return ;
        }
        else
        {
            bkRS.Close();
            MessageBox(_T("图书更新成功!"), theApp.strSystemName);
            CDialog::OnOK();
        }
    }
	//! 图书遗失登记
	if (bSignOff_)
    {
        CBorrowInfoSet biRS;
        if(bkRS.GetRecordCount() == 0)
        {
            bkRS.Close();
            MessageBox(_T("该图书不存在,请重新输入!"), theApp.strSystemName);
            return;
        }
        if (DeleteRecord(&biRS, _T("BorrowInfo"), _T("BookID"), strBookID_))
        {
            bkRS.Delete();
        }
        else 
            MessageBox(_T("遗失登记失败!"), theApp.strSystemName);
        bkRS.Close();
		CDialog::OnOK();
    }
}

void CBookRegDlg::GetData()
{
    CString strSQL;
    strSQL.Format(_T("SELECT * FROM BookInfo WHERE BookID = '%s'"), strBookID_);
    if (bkRS.IsOpen())bkRS.Close();
    if (bkRS.Open(AFX_DB_USE_DEFAULT_TYPE, strSQL))
    {
        if(bkRS.GetRecordCount() != 0)
        {
            strBookID_      = bkRS.strBookID_;
            strBookName_    = bkRS.strBookName_;
            strBookType_    = bkRS.strBookType_;
			ctrlBookType_.AddString(strBookType_);
			ctrlBookType_.SetCurSel(0);
            strAuthor_      = bkRS.strAuthor_;
            strPressName_   = bkRS.strPress_;
            dPrice_         = bkRS.dPrice_;
            olePressDT_     = bkRS.olePressDT_;
            oleInDT_        = bkRS.oleInDT_;
            nInNumber_      = bkRS.nInNumber_;
            nOutNumber_     = bkRS.nOutNumber_;
            strDescription_ = bkRS.strDescription_;
        }
    }
}

void CBookRegDlg::SetData()
{
    bkRS.strBookID_   = strBookID_;
    bkRS.strBookName_ = strBookName_;
    bkRS.strBookType_ = strBookType_;
    bkRS.strAuthor_   = strAuthor_;
    bkRS.strPress_    = strPressName_;
    bkRS.dPrice_      = dPrice_;
    bkRS.olePressDT_  = olePressDT_;
    bkRS.oleInDT_     = oleInDT_;
    bkRS.nInNumber_   = nInNumber_;
    bkRS.nOutNumber_  = nOutNumber_;
    bkRS.strDescription_= strDescription_;
}
void CBookRegDlg::OnEnChangeEditBookno()
{
    // TODO:  If this is a RICHEDIT control, the control will not
    // send this notification unless you override the CDialog::OnInitDialog()
    // function and call CRichEditCtrl().SetEventMask()
    // with the ENM_CHANGE flag ORed into the mask.

    // TODO:  Add your control notification handler code here
    UpdateData(TRUE);
    GetData();
    UpdateData(FALSE);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -