C++课程设计--实验室设备管理系统设计(MFC)

课设题目

实验室设备管理系统设计

课设要求

  1. 用户管理
  2. 实验室设备信息(实验室名称,设备名称,设备编号,设备状态)的录入、修改,删除和文件导入
  3. 学生信息(专业,姓名,学号)的手工录入,修改、删除和文件导入
  4. 学生登录系统后,同一名称的设备,一个学生最多只能借用-一个
  5. 按设备编号统计并显示该设备的使用情况(借出的数量,可用的数量,维修中的数量)
  6. 根据不同条件查询并显示设备信息
  7. 按实验室统计并显示该实验室所有设备的信息
  8. 统计数据的导出

程序运行界面

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

核心代码

void CadminDevice::OnDeviceAdd() 
{
	// TODO: Add your control notification handler code here
	device_add->ShowWindow(SW_SHOW);
}

void CadminDevice::OnDeviceMod() 
{
	// TODO: Add your control notification handler code here
		dev_mod->ShowWindow(SW_SHOW);
}
LRESULT CadminDevice::DeviceADD(WPARAM wp,LPARAM p)
{
	lab *lab_ = (lab*)wp;
	
	/*查找*/
/*	if(devIsExist(lab_->getDevNum())!= -1){
		MessageBox("该设备编号已经存在","FAIL");
		return -1;
	}*/
	int nRows = 0; 
	int nu = 0;
	nRows = m_list_device.GetItemCount();  
	if (nRows != 0) {
		nu = _ttoi(m_list_device.GetItemText(0, 0));	 
	}
	nu++;
	CString str;
	str.Format("%d", nu);
	m_list_device.InsertItem(0, str);  
	
	m_list_device.SetItemText(0, 1, lab_->getLabName());  
	m_list_device.SetItemText(0, 2, lab_->getDevName());
	m_list_device.SetItemText(0, 3, lab_->getDevNum());
	m_list_device.SetItemText(0, 4, lab_->getDevState());

	ofstream infile("device.txt",ios::out|ios::app);
	infile << lab_->getLabName().GetBuffer(0)  <<"  ";
	infile << lab_->getDevName().GetBuffer(0)  <<"  ";
	infile << lab_->getDevNum().GetBuffer(0)  <<"  ";
	infile << lab_->getDevState().GetBuffer(0)  <<"  "<<endl;
	infile.close();
	/*保存进文件末尾*/
    //设备状态保存
	device_static dev__;
	dev__.add(lab_->getDevNum().GetBuffer(0), _ttoi(lab_->getDevState()));

    //实验室状态保存
	lab_static lab__s;
	lab__s.add(lab_->getLabName().GetBuffer(0), _ttoi(lab_->getDevState()));

	return 0; 

}
int  CadminDevice::devIsExist(CString number)
{
	CString str;
	if (number ==""){
		return -1;
	}
	int nRows = 0;  
	nRows = m_list_device.GetItemCount();  
	//	str.Format("nrouw----%d\n", nRows);
	//	MessageBox(str);
	int nIndex = 0;  
	for(int i = 0; i < nRows; i++)  
	{  
		if(m_list_device.GetItemText(i, 0).Find(number) >= 0)  
		{  
			nIndex = i;  
			return nIndex;
		}  
	}  
	
	return -1;
}
void CadminDevice::OnDeviceDel() 
{
	// TODO: Add your control notification handler code here
	// TODO: Add your control notification handler code here
	CListCtrl *pList=(CListCtrl *)GetDlgItem(IDC_LIST_DEVICE);  //获取一个句柄
	int column=pList->GetSelectionMark();        //选择一行
	if(column==-1)
		MessageBox("请点击要删除的行,再进行删除","尚未选择要删除的行");
	device_static dev__;
	UpdateData();
	dev__.del(m_list_device.GetItemText(column, 3).GetBuffer(0), atoi(m_list_device.GetItemText(column, 4).GetBuffer(0)));
    //实验室状态删除
   lab_static lab__s;
   lab__s.del(m_list_device.GetItemText(column, 1).GetBuffer(0), atoi(m_list_device.GetItemText(column, 4).GetBuffer(0)));


    pList->DeleteItem(column);
	int nRows = 0;
	UpdateData();
	nRows = m_list_device.GetItemCount();  
	//	str.Format("nrouw----%d\n", nRows);
	//	MessageBox(str);
	fstream infile("device.txt",ios::trunc|ios::out);
	int nIndex = 0;  
	for(int i = nRows-1; i >=0 ; i--)  
	{  
		infile << m_list_device.GetItemText(i, 1).GetBuffer(0) <<"  ";
		infile << m_list_device.GetItemText(i, 2).GetBuffer(0)  <<"  ";
		infile << m_list_device.GetItemText(i, 3).GetBuffer(0)  <<"  ";
		infile << m_list_device.GetItemText(i, 4).GetBuffer(0) <<"  "<<endl;
	} 
	infile.close();
	

}

BOOL CadminDevice::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	// TODO: Add extra initialization here
	DWORD dwStyle = m_list_device.GetExtendedStyle();
	dwStyle |= LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES; /*带有虚线*/
	m_list_device.SetExtendedStyle(dwStyle);
	m_list_device.InsertColumn(0,"编号",LVCFMT_LEFT,50);             
    m_list_device.InsertColumn(1,"实验室",LVCFMT_LEFT,80);
    m_list_device.InsertColumn(2,"设备名",LVCFMT_LEFT,80);
    m_list_device.InsertColumn(3,"设备编号",LVCFMT_LEFT,90);
	m_list_device.InsertColumn(4,"状态",LVCFMT_LEFT,50);
	
    device_add = new Cdevice();
	device_add->Create(IDD_DEV_ADD,this); 
	device_add->setGetHwnd(this->m_hWnd);
	//读取数据
	dev_mod = new CDeviceMod();
	dev_mod->Create(IDD_DEV_MOD,this); 
	dev_mod->setGetHwnd(this->m_hWnd);

	fstream infile("device.txt",ios::in);
	int N=count("device.txt");
	int i =0;
	string lab_name;
	string dev_name;
	string dev_num;
	string dev_state;
	CString clab_name;
	CString cdev_name;
	CString cdev_num;
	CString cdev_state;

	UpdateData();
	for(i=0;i<N;i++)
	{	
		infile>>lab_name;
		infile>>dev_name;
		infile>>dev_num;
		infile>>dev_state;

		CString strnum;
		strnum.Format("%d", i+1);
		clab_name.Format("%s", lab_name.c_str());
		cdev_name.Format("%s", dev_name.c_str());
		cdev_num.Format("%s", dev_num.c_str());
		cdev_state.Format("%s", dev_state.c_str());

		m_list_device.InsertItem(0, strnum);
		m_list_device.SetItemText(0, 1, clab_name);
		m_list_device.SetItemText(0, 2, cdev_name);
		m_list_device.SetItemText(0, 3, cdev_num);
		m_list_device.SetItemText(0, 4, cdev_state);
	}
	infile.close();
	UpdateData(FALSE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
LRESULT CadminDevice::DeviceMOD(WPARAM wp,LPARAM lp)
{

	lab *lab_ = (lab*)wp;
	int index;
	fstream infile("device.txt",ios::trunc|ios::out);
	/*查找*/
	index = devIsExist(lab_->getNum());
	if(index == -1){
		MessageBox("改编号设备不存在","FAIL");
		return -1;
	}
	device_static dev__;
	dev__.del(m_list_device.GetItemText(index, 3).GetBuffer(0), atoi(m_list_device.GetItemText(index, 4).GetBuffer(0)));

    lab_static lab__s;
    lab__s.del(m_list_device.GetItemText(index, 1).GetBuffer(0), atoi(m_list_device.GetItemText(index, 4).GetBuffer(0)));

    m_list_device.SetItemText(index, 1, lab_->getLabName());  
	m_list_device.SetItemText(index, 2, lab_->getDevName());
	m_list_device.SetItemText(index, 3, lab_->getDevNum());
	m_list_device.SetItemText(index, 4, lab_->getDevState());
	UpdateData(FALSE);
	//显示高亮
	m_list_device.SetFocus();//设置焦点  
	m_list_device.SetItemState(index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);//设置状态  
	m_list_device.EnsureVisible(index, FALSE);//设置当前视图可见  
	UpdateData();
	int nRows = 0;
	nRows = m_list_device.GetItemCount();  
	
	//	str.Format("nrouw----%d\n", nRows);
	//	MessageBox(str);
	int nIndex = 0;  
	for(int i = nRows-1; i >=0 ; i--)  
	{  
		infile << m_list_device.GetItemText(i, 1).GetBuffer(0) <<"  ";
		infile << m_list_device.GetItemText(i, 2).GetBuffer(0)  <<"  ";
		infile << m_list_device.GetItemText(i, 3).GetBuffer(0)  <<"  ";
		infile << m_list_device.GetItemText(i, 4).GetBuffer(0) <<"  "<<endl;
	} 
	infile.close();
	dev__.add(m_list_device.GetItemText(index, 3).GetBuffer(0), atoi(m_list_device.GetItemText(index, 4).GetBuffer(0)));
	
    lab__s.add(m_list_device.GetItemText(index, 1).GetBuffer(0), atoi(m_list_device.GetItemText(index, 4).GetBuffer(0)));
	return 0; 
}

项目源码

需要源码的小伙伴请前往
微信公众号:海轰Pro
回复: 海轰
O(∩_∩)O哈哈~

发布了155 篇原创文章 · 获赞 110 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/weixin_44225182/article/details/103956761