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

📄 returndlg.cpp

📁 小图书馆管理系统
💻 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);//
	  }
///////检验此人是否借此书//////////////
     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()
{
    //将数据保存到数据库
	//设置借书期限是一个月
	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();

	//保存数据到user表
	m_UserSet.Edit();
	m_UserSet.m_borrownum--;
	m_UserSet.Update();

	//保存数据到book表
	if (returnStyle=="0")
	{
	 m_BookSet.Edit();
	 m_BookSet.m_remain++;
	 m_BookSet.Update();
	}
     //更新对话框的数据
	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();//使价格只保留两位小数
	     price=price.Left(strLength-2);
         price=" 您应赔偿"+price+"*"+returnStyle;
     m_BorrowSet.Close();
     m_UserSet.Close();
	 m_BookSet.Close();
     UpdateData(false);
          if (returnStyle=="1") 
			BookRepair();
          if (returnStyle=="2") 
		    BookDel();
	//关闭数据集
     
}
void CReturnDlg::BookRepair()
{
     m_BorrowSet.Open();
     m_UserSet.Open();
    //保存数据到borrow表
	m_BorrowSet.AddNew();
	m_BorrowSet.m_userid="10000";
	m_BorrowSet.m_bookid=m_Bookid;
	m_BorrowSet.m_remaindate=15;//假定修书期限为十五天
	m_BorrowSet.Update();

	//保存数据到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();
    //保存数据到borrow表
	m_BorrowSet.AddNew();
	m_BorrowSet.m_userid="10001";
	m_BorrowSet.m_bookid=m_Bookid;
	m_BorrowSet.m_remaindate=1000;//假定修书期限为十五天
	m_BorrowSet.Update();

	//保存数据到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();


}

⌨️ 快捷键说明

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