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

📄 putongdialog.cpp

📁 一个小型的图书管理系统,用到了access数据库,其中有三种权限的用户登陆这个系统,每种用户将拥有不同的权限,用户密码和帐户打开程序中的access便可知道.
💻 CPP
字号:
// PuTongDialog.cpp : implementation file
//

#include "stdafx.h"
#include "Book.h"
#include "PuTongDialog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPuTongDialog dialog


CPuTongDialog::CPuTongDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CPuTongDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPuTongDialog)
	m_pubookclass = _T("");
	m_pustuclass = _T("");
	m_pubookno = 0;
	m_pubookname = _T("");
	m_pustuno = 0;
	m_pustuname = _T("");
	//}}AFX_DATA_INIT
}


void CPuTongDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPuTongDialog)
	DDX_Control(pDX, IDC_BUTTONSEESTUNO, m_seestuno);
	DDX_Control(pDX, IDC_BUTTONSEESTUNM, m_seestunm);
	DDX_Control(pDX, IDC_BUTTONPUSEEBOOKNO, m_puseebookno);
	DDX_Control(pDX, IDC_BUTTONPUSEEBOOKNM, m_puseebooknm);
	DDX_Control(pDX, IDC_LISTPTSTUSHOW, m_ptstushow);
	DDX_Control(pDX, IDC_LISTPTBOOKSHOW, m_ptbookshow);
	DDX_Control(pDX, IDC_BUTTONSEEBK, m_seebook);
	DDX_Control(pDX, IDC_BUTTONSEEB, m_seeborrow);
	DDX_CBString(pDX, IDC_COMBOPUBOOKCLASS, m_pubookclass);
	DDX_CBString(pDX, IDC_COMBOPUSTUCLASS, m_pustuclass);
	DDX_Text(pDX, IDC_EDITPUBOOKNO, m_pubookno);
	DDX_Text(pDX, IDC_EDITPUBOOKNAME, m_pubookname);
	DDX_Text(pDX, IDC_EDITPUSTUNO, m_pustuno);
	DDX_Text(pDX, IDC_EDITSTUNAME, m_pustuname);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPuTongDialog, CDialog)
	//{{AFX_MSG_MAP(CPuTongDialog)
	ON_BN_CLICKED(IDC_BUTTONSEEB, OnButtonseeb)
	ON_BN_CLICKED(IDC_BUTTONSEEBK, OnButtonseebk)
	ON_BN_CLICKED(IDC_BUTTONPUSEEBOOKNO, OnButtonpuseebookno)
	ON_BN_CLICKED(IDC_BUTTONPUSEEBOOKNM, OnButtonpuseebooknm)
	ON_BN_CLICKED(IDC_BUTTONSEESTUNO, OnButtonseestuno)
	ON_BN_CLICKED(IDC_BUTTONSEESTUNM, OnButtonseestunm)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPuTongDialog message handlers

BOOL CPuTongDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	ptbooksource=new CBookDataSouce(&theApp.m_DB);
	ptstudentsource=new CStdDataSource(&theApp.m_DB);
	unsigned i;
	CODBCFieldInfo info;
	m_ptbookshow.SetBkColor(RGB(200,250,230));//设置列表框的背景颜色
	m_ptbookshow.SetTextBkColor(RGB(200,250,230));//设置列表框中文字的背景颜色
	m_ptbookshow.SetTextColor(RGB(0,0,255));
	
	m_ptstushow.SetBkColor(RGB(200,250,230));//设置列表框的背景颜色
	m_ptstushow.SetTextBkColor(RGB(200,250,230));//设置列表框中文字的背景颜色
	m_ptstushow.SetTextColor(RGB(0,0,255));
	ptbooksource->Open();
	m_ptbookshow.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	for(i=0;i<ptbooksource->m_nFields;i++)
	{
		ptbooksource->GetODBCFieldInfo(i,info);
		m_ptbookshow.InsertColumn(i,info.m_strName,LVCFMT_LEFT,85);
	}
	ptbooksource->Close();

	ptstudentsource->Open();
	m_ptstushow.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	for(i=0;i<ptstudentsource->m_nFields;i++)
	{
		ptstudentsource->GetODBCFieldInfo(i,info);
		m_ptstushow.InsertColumn(i,info.m_strName,LVCFMT_LEFT,85);
	}
	ptstudentsource->Close();
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPuTongDialog::OnButtonseeb()//专业查看借书情况
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(m_pustuclass=="")
	{
		AfxMessageBox("专业不能为空!");
		return;
	}
	if(!ShowMessage(2,"专业"))
		AfxMessageBox("没有该用户!");
	UpdateData(FALSE);
}

void CPuTongDialog::OnButtonseebk()//类别查看图书情况
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(m_pubookclass=="")
	{
		AfxMessageBox("类别不能为空!");
		return;
	}
	if(!ShowMessage(1,"类别"))
		AfxMessageBox("没有这本书!");
	UpdateData(FALSE);	
}

void CPuTongDialog::OnButtonpuseebookno()//书号查看图书情况 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(!ShowMessage(1,"书号"))
		AfxMessageBox("没有这本书!");
	UpdateData(FALSE);	
}

void CPuTongDialog::OnButtonpuseebooknm()//书名查看图书情况 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(m_pubookname=="")
	{
		AfxMessageBox("书名不能为空!");
		return;
	}
	if(!ShowMessage(1,"书名"))
		AfxMessageBox("没有这本书!");
	UpdateData(FALSE);	
}

void CPuTongDialog::OnButtonseestuno()//学号查看图书情况
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(!ShowMessage(2,"学号"))
		AfxMessageBox("没有该用户!");
	UpdateData(FALSE);
}

void CPuTongDialog::OnButtonseestunm()//姓名查看图书情况
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(m_pustuname=="")
	{
		AfxMessageBox("姓名不能为空!");
		return;
	}
	if(!ShowMessage(2,"姓名"))
		AfxMessageBox("没有该用户!");
	UpdateData(FALSE);
	
}

BOOL CPuTongDialog::ShowMessage(int cs, CString kd)
{
	BOOL flag=true;
	if(cs==1)
	{
		m_ptbookshow.DeleteAllItems();
		int j=0;
		ptbooksource->Open();
		while(!ptbooksource->IsEOF())
		{
			if(kd=="书号")
			{
				if(ptbooksource->m_column1==m_pubookno)
				{
					ShowList(j,1);
					j++;
					flag=false;
				}
			}
			else if(kd=="书名")
			{
				if(ptbooksource->m_column2==m_pubookname)
				{
					ShowList(j,1);
					j++;
					flag=false;
				}
					
			}
			else if(kd=="类别")
			{
				if(ptbooksource->m_column3==m_pubookclass)
				{
					ShowList(j,1);
					j++;
					flag=false;
				}
			}
			else
			{
				AfxMessageBox("没有此种图书查询方式!");
				ptbooksource->Close();
				return true;
			}
			ptbooksource->MoveNext();
		}
		ptbooksource->Close();
	}
	else if(cs==2) 
	{
		m_ptstushow.DeleteAllItems();
		int j=0;
		ptstudentsource->Open();
		while(!ptstudentsource->IsEOF())
		{
			if(kd=="学号")
			{
				if(ptstudentsource->m_column1==m_pustuno)
				{
					BookIsLate(ptstudentsource->m_column1);
					ShowList(j,2);
					j++;
					flag=false;
				}
			}
			else if(kd=="姓名")
			{
				if(ptstudentsource->m_column2==m_pustuname)
				{
					BookIsLate(ptstudentsource->m_column1);
					ShowList(j,2);
					j++;
					flag=false;
				}		
			}
			else if(kd=="专业")
			{
				if(ptstudentsource->m_column3==m_pustuclass)
				{
					BookIsLate(ptstudentsource->m_column1);
					ShowList(j,2);
					j++;
					flag=false;
				}
			}
			else
			{
				AfxMessageBox("没有此种借书查询方式!");
				ptstudentsource->Close();
				return true;
			}
			ptstudentsource->MoveNext();
		}

		ptstudentsource->Close();
	}
	else
	{
		AfxMessageBox("参数传递有误!");
		return true;
	}
	if(flag)
		return false;
	return true;
}

void CPuTongDialog::ShowList(int no,int listno)
{
	int j=no;
	CString str;
	if(listno==1)
	{
		str.Format("%d",ptbooksource->m_column1);
		m_ptbookshow.InsertItem(j,str,0);
			
		m_ptbookshow.SetItemText(j,1,ptbooksource->m_column2);
		m_ptbookshow.SetItemText(j,2,ptbooksource->m_column3);
		m_ptbookshow.SetItemText(j,3,ptbooksource->m_column4);
		m_ptbookshow.SetItemText(j,4,ptbooksource->m_column5);
		m_ptbookshow.SetItemText(j,5,ptbooksource->m_column6.Format("%Y-%m-%d"));
			
		str.Format("%6.2f",ptbooksource->m_column7);
		m_ptbookshow.SetItemText(j,8,str);
		str.Format("%d",ptbooksource->m_column8);
		m_ptbookshow.SetItemText(j,6,str);
		str.Format("%d",ptbooksource->m_column9);
		m_ptbookshow.SetItemText(j,7,str);
	}
	else if(listno==2)
	{
		str.Format("%d",ptstudentsource->m_column1);
		m_ptstushow.InsertItem(j,str,0);
			
		m_ptstushow.SetItemText(j,1,ptstudentsource->m_column2);
		m_ptstushow.SetItemText(j,2,ptstudentsource->m_column3);

		str.Format("%d",ptstudentsource->m_column4);
		m_ptstushow.SetItemText(j,3,str);

		m_ptstushow.SetItemText(j,4,ptstudentsource->m_column5);
		m_ptstushow.SetItemText(j,5,ptstudentsource->m_column6.Format("%Y-%m-%d"));
			
		str.Format("%d",ptstudentsource->m_column7);
		m_ptstushow.SetItemText(j,6,str);
	}
}

void CPuTongDialog::BookIsLate(int stuno)
{
	long lateday;//借书的天数
	CTimeSpan latetime;//
	if(ptstudentsource->m_column4==0)//没有借书,不存在过期的情况
	{
		return ;
	}
	if(ptstudentsource->m_column1==stuno)
	{
		latetime=CTime::GetCurrentTime()-ptstudentsource->m_column6;
		lateday=latetime.GetTotalHours()/24;
		if(lateday>60)
		{
			ptstudentsource->Edit();
			ptstudentsource->m_column7=lateday-60;
			ptstudentsource->Update();
		}
	}
}

⌨️ 快捷键说明

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