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

📄 borrowmanagedlg.cpp

📁 LibraryManageDM.rar 数据库设计图书馆管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    if (biRS_.IsOpen())biRS_.Close();
    if (!biRS_.Open(AFX_DB_USE_DEFAULT_TYPE, strSQL_))
    {
		AfxMessageBox(IDS_OPENDBFAIL);
		return FALSE;
    }
    if (dPunish_ >= punishlimit)
    {
        MessageBox(_T("您有罚款未缴纳,\n\n请先还书并缴纳罚款!"), theApp.strSystemName);
        return FALSE;
    }
    biRS_.Edit();
    biRS_.oleDeadLineDT_ += nOutDayLimit_ * 24 * 3600;
    biRS_.bRenewed_ = TRUE;
    biRS_.Update();
    biRS_.Close();
    return TRUE;
}
BOOL CBorrowManageDlg::ReturnBook()
{
    CString strSQL[2];
    BOOL ret = FALSE;
    strSQL[0].Format(_T("SELECT * FROM BookInfo WHERE BookID = '%s'"), strBookID_);
    strSQL[1].Format(_T("SELECT * FROM BorrowInfo WHERE ReaderID = '%s' AND BookID = '%s'"),
        strReaderID_, strBookID_);
    double punish = 0.0;
    //! 查询图书信息和借阅信息
    if (bkRS_.IsOpen())bkRS_.Close();
    if (biRS_.IsOpen())biRS_.Close();
    if (!bkRS_.Open(AFX_DB_USE_DEFAULT_TYPE, strSQL[0]) || 
        !biRS_.Open(AFX_DB_USE_DEFAULT_TYPE, strSQL[1]))
    {
		AfxMessageBox(IDS_OPENDBFAIL);
		return FALSE;
    }
    if(bkRS_.GetRecordCount()==0)
    {
        bkRS_.Close();
        biRS_.Close();
        return FALSE;
    }
    //! 修改图书信息
    bkRS_.Edit();
    --bkRS_.nOutNumber_;
    ++bkRS_.nInNumber_;

    //判断是否借出
    if(biRS_.GetRecordCount() != 0)
    {
        biRS_.Edit();
        biRS_.bReturned_ = TRUE;
        biRS_.bRenewed_ = TRUE;
        biRS_.oleReturnDT_ = CTime::GetCurrentTime();
        if (nDamReate_ > 0)
        {
			QueryPunishSetting(_T("损坏赔偿"), punish);
            punish *= dPrice_ * nDamReate_;
        }
        UpdatePunishInfo(strReaderID_, dPunish_ + punish);
        ret = biRS_.Update();
        biRS_.Close();
    }
    if (ret)
        bkRS_.Update();
    bkRS_.Close();
    return TRUE;
}
BOOL CBorrowManageDlg::UpdateReader()
{
    if (!QueryReader())return FALSE;
    if (!QueryReaderType())return FALSE;
    if (!QueryBorrowInfo(strReaderID_))return FALSE;
    if (!QueryPunishInfo(strReaderID_, dPunish_))return FALSE;
    return TRUE;
}
BOOL CBorrowManageDlg::UpdateBook()
{
    if (!QueryBook())return FALSE;
    if (!QueryBookType())return FALSE;
    if (!QueryBorrowInfo(strReaderID_, strBookID_))return FALSE;
    return TRUE;
}
// CBorrowManageDlg message handlers
BOOL CBorrowManageDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // TODO:  Add extra initialization here
    if (eType_ != BORROW)
    {
        ctrlReaderID_.SetReadOnly(FALSE);
        ctrlBookID_.ShowWindow(SW_HIDE);
        ctrlComBorrowed_.ShowWindow(SW_NORMAL);
    }
    switch (eType_)
    {
    case BORROW:
        SetWindowText(_T("借书"));
        GetDlgItem(IDOK)->SetWindowText(_T("借出"));
        GetDlgItem(IDC_DATETIME_DEADLINE)->EnableWindow(FALSE);
        ctrlBookID_.SetReadOnly(FALSE);
		break;
    case RENEW:
        GetDlgItem(IDC_CHECK_RENEW)->ShowWindow(SW_NORMAL);
        SetWindowText(_T("续借图书"));
        GetDlgItem(IDOK)->SetWindowText(_T("续借"));
        if (!strReaderID_.IsEmpty())
        {
            ctrlReaderID_.SetReadOnly(UpdateReader());
            if (!strBookID_.IsEmpty())
            {
                ctrlComBorrowed_.SetWindowText(strBookID_);
                ctrlComBorrowed_.EnableWindow(FALSE);
                UpdateBook();
            }
        }
        if (!bRenewed_)
            ctrlBookID_.SetReadOnly(TRUE);
        break;
    case RETURN:
        ctrlPunish_.SetReadOnly(TRUE);
        SetWindowText(_T("还书"));
        GetDlgItem(IDOK)->SetWindowText(_T("归还"));
        if (!strReaderID_.IsEmpty())
        {
            ctrlReaderID_.SetReadOnly(UpdateReader());
            if (!strBookID_.IsEmpty())
            {
                ctrlComBorrowed_.SetWindowText(strBookID_);
                ctrlComBorrowed_.EnableWindow(FALSE);
                UpdateBook();
            }
            double punish = 0.0;
            int nOverDays = (int)(CTime::GetCurrentTime()- biRS_.oleDeadLineDT_).GetDays();
            if (nOverDays > 0)
            {
                QueryPunishSetting(_T("逾期罚款"), punish);
            }
            dPunish_ = punish * nOverDays;
        }
        GetDlgItem(IDC_DATETIME_DEADLINE)->EnableWindow(FALSE);
        GetDlgItem(IDC_BSPUNISH)->SetWindowText(_T("逾期罚款"));
        GetDlgItem(IDC_BSPUNISH2)->ShowWindow(SW_NORMAL);
        GetDlgItem(IDC_EDIT_RATE)->ShowWindow(SW_NORMAL);
        GetDlgItem(IDC_SRANGE)->ShowWindow(SW_NORMAL);
        break;
    }
    HICON hIcon;
    hIcon = theApp.LoadIcon(IDI_BWMICON);
    SetIcon(hIcon, FALSE);
    ctrlReaderID_.SetFocus();
    strOperatorName_ = theApp.GetOperator();
    UpdateData(FALSE);
    return TRUE;  // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
}

void CBorrowManageDlg::OnEnChangeEditBreaderid()
{
    // 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);
    if (!UpdateReader())return ;
    ctrlBookID_.SetReadOnly(FALSE);
    UpdateData(FALSE);
}

void CBorrowManageDlg::OnEnChangeEditBbookid()
{
    // 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);
    if (!UpdateBook())return ;
    
    if (eType_ == BORROW)
        oleDeadLineDT_ = CTime::GetCurrentTime() + nOutDayLimit_ * 24 * 3600;
    else
    {
        //! 根据读者ID和图书ID查询借阅信息
        if (!QueryBorrowInfo(strReaderID_, strBookID_))return ;
        if (eType_ == RETURN)
        {
            double punish = 0.0;
            int nOverDays = (int)(CTime::GetCurrentTime()- biRS_.oleDeadLineDT_).GetDays();
            if (nOverDays > 0)
            {
                QueryPunishSetting(_T("逾期罚款"), punish);
            }
            dPunish_ = punish * nOverDays;
        }
    }
    UpdateData(FALSE);
}

void CBorrowManageDlg::OnBnClickedOk()
{
    // TODO: Add your control notification handler code here
    UpdateData(TRUE);
    if (strReaderID_.IsEmpty())
    {
        MessageBox(_T("请输入借阅者ID!"), theApp.strSystemName);
        return;
    }
    if (strBookID_.IsEmpty())
    {
        MessageBox(_T("请输入图书ID!"), theApp.strSystemName);
        return;
    }
    if (eType_ == RETURN && (nDamReate_ <0 || nDamReate_ > 100))
    {
        MessageBox(_T("请输入合法的损坏比例!"), theApp.strSystemName);
        return;
    }
    switch (eType_)
    {
    case BORROW:
        if (BorrowBook())
        {
            MessageBox(_T("图书借阅成功!"), theApp.strSystemName);
            ClearDatas();
        }
        break;
    case RENEW:
        if (RenewBook())
        {
            MessageBox(_T("图书续借成功!"), theApp.strSystemName);
            ClearDatas();
        }
        if (bOff_)CDialog::OnOK();
        break;
    case RETURN:
        if (ReturnBook())
        {
            MessageBox(_T("图书归还成功!"), theApp.strSystemName);
            ClearDatas();
        }
        if (bOff_)CDialog::OnOK();
        break;
    }
    if (!UpdateReader())return ;
    strBookID_ = _T("");
    if (!UpdateBook())return ;
}

void CBorrowManageDlg::OnCbnSelchangeComboBorrowed()
{
    // TODO: Add your control notification handler code here
    UpdateData(TRUE);
    strBookID_ = szBookID_;
    if (!strBookID_.IsEmpty())
    {
        UpdateBook();
        UpdateData(FALSE);
    }
}

void CBorrowManageDlg::ClearDatas()
{
    strReaderID_.Empty();
    strBookID_.Empty();
    szBookID_.Empty();
    strReaderName_.Empty();
    strBookName_.Empty();
    strReaderType_.Empty();
    strBookType_.Empty();
    nOutNumLimit_ = 0;
    nOutDayLimit_ = 0;
    nAlOutNum_ = 0;
    dPunish_ = 0.0;
    oleDeadLineDT_ = CTime::GetCurrentTime();
    oleBorrwDT_ = CTime::GetCurrentTime();
    strSQL_.Empty();
    nDamReate_ = 0;
    nBorOutNumLimit_  = 0;
    bRenewed_ = TRUE;
    UpdateData(FALSE);
}

⌨️ 快捷键说明

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