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

📄 showdialog.cpp

📁 VC++编写的论文管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:

	m_ThesisInfoSet.MoveFirst();
	do 
	{
		keyWord = m_ThesisInfoSet.m_chkey1 +','+ m_ThesisInfoSet.m_chkey2 +','+m_ThesisInfoSet.m_chkey3 +','+ m_ThesisInfoSet.m_chkey4;
		keyWord += m_ThesisInfoSet.m_enkey1 +','+ m_ThesisInfoSet.m_enkey2 +','+m_ThesisInfoSet.m_enkey3 +','+ m_ThesisInfoSet.m_enkey4;
		if( checkText(m_ThesisInfoSet.m_stuid, stuid,stuidFlag) && checkText(m_ThesisInfoSet.m_name,thesis,thesisFlag) && 
			checkText(keyWord,key,keyFlag) && checkText(m_ThesisInfoSet.m_teacher,tch,tchFlag) )
		{
			m_StuInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
			m_StuInfoSet.MoveFirst();
			do 
			{
				if((m_StuInfoSet.m_stuid == m_ThesisInfoSet.m_stuid) && checkText(m_StuInfoSet.m_stuname,stu,stuFlag))
				{
					nHasExist = true;
					break;
				}
				m_StuInfoSet.MoveNext();
			}while(!m_StuInfoSet.IsEOF());
			if( nHasExist )
			{
				show(k);
				k++;
			}
			m_StuInfoSet.Close();
		}
		m_ThesisInfoSet.MoveNext();

	}while(!m_ThesisInfoSet.IsEOF());
		}
	m_ThesisInfoSet.Close();//关闭数据库
	if( k == 0 )
	{
		MessageBox("没有找到相匹配的记录!","警告",MB_OK);
		CDialog::OnOK();
	}
}
void CShowDialog::showAll()
{
	int k=0;
	bool nHasExist=false;

	m_StuInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
				if( !m_StuInfoSet.IsEOF() )
	{
			
				//	MessageBox("没有记录!","警告",MB_OK);
				//	m_StuInfoSet.Close();//关闭数据库
//	CDialog::OnOK();
				//	return;
		
//	}		
	m_StuInfoSet.MoveFirst();

	do 
	{
		m_ThesisInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
		m_ThesisInfoSet.MoveFirst();
		do 
		{
			if(m_ThesisInfoSet.m_stuid==m_StuInfoSet.m_stuid)
			{
				nHasExist = true;
				break;
			}
			m_ThesisInfoSet.MoveNext();
		}while(!m_ThesisInfoSet.IsEOF());
		if( nHasExist )
		{
			show(k);
			k++;
		}
		m_ThesisInfoSet.Close();
		m_StuInfoSet.MoveNext();

	}while(!m_StuInfoSet.IsEOF());
	m_StuInfoSet.Close();//关闭数据库
				}
	if( k == 0 )
	{
		MessageBox("没有记录!","警告",MB_OK);
		CDialog::OnOK();
	}
}
BOOL CShowDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();

	
	// TODO: Add extra initialization here

	DWORD dwStyle = m_show_list.GetExtendedStyle();
	dwStyle |= LVS_EX_FULLROWSELECT;
	m_show_list.SetExtendedStyle(dwStyle);
	m_show_list.ModifyStyle(0, LVS_REPORT);
	CRect rect;
	m_show_list.GetClientRect(&rect);
	int nColInterval = rect.Width();//设置单位宽度
			//	班级、学号、姓名、指导教师、论文题目、中文关键字、英文关键字、内容简介 
	m_show_list.InsertColumn(0,_T(" 班   级"),LVCFMT_LEFT,nColInterval/6-50);
	m_show_list.InsertColumn(1,_T(" 学   号"),LVCFMT_LEFT,nColInterval/6-30);
	m_show_list.InsertColumn(2,_T(" 姓   名"),LVCFMT_LEFT,nColInterval/6-30);
	m_show_list.InsertColumn(3,_T(" 指导教师"),LVCFMT_LEFT,nColInterval/6-30);
	m_show_list.InsertColumn(4,_T(" 论文题目"),LVCFMT_LEFT,nColInterval/6+10);
	m_show_list.InsertColumn(5,_T(" 论文类型"),LVCFMT_LEFT,nColInterval/6+10);
	m_show_list.InsertColumn(6,_T(" 论文成绩"),LVCFMT_LEFT,nColInterval/6+10);
	m_show_list.InsertColumn(7,_T(" 中文关键字"),LVCFMT_LEFT,nColInterval/6+40);
	m_show_list.InsertColumn(8,_T(" 英文关键字"),LVCFMT_LEFT,nColInterval/6+40);

	switch( showType )
	{
	case NONE:
		showAll();
		break;
	case STU_NAME:
		showSName(strText);
		break;
	case TCH_NAME:
		showTName(strText);
		break;
	case KEY_WORD:
		showKey(strText);
		break;
	case THESIS_NAME:
		showThesis(strText);
		break;
	case ALL:
		showUp(strText);
		break;
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CShowDialog::OnClickShowList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	//	AfxMessageBox("导出完毕");
	bool nHasExist = false;
	CString stuNo;
	int l=m_show_list.GetSelectedCount();
	if(l<=0) 
	{
		//MessageBox("您还没选中记录!");
		GetDlgItem(IDC_DES_STATIC)->SetWindowText("         ");
		return;
	}
    
	POSITION pos=m_show_list.GetFirstSelectedItemPosition();
	int nSel=m_show_list.GetNextSelectedItem(pos);
//MessageBox(m_show_list.GetItemText(nSel,1));
	m_ThesisInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
	m_ThesisInfoSet.MoveFirst();
	do 
	{
		if(m_ThesisInfoSet.m_stuid==m_show_list.GetItemText(nSel,1) )
		{
			nHasExist = true;
			break;
		}
		m_ThesisInfoSet.MoveNext();
	}while(!m_ThesisInfoSet.IsEOF());
	if( nHasExist )
	{
		CString des = m_ThesisInfoSet.m_description;

		GetDlgItem(IDC_DES_STATIC)->SetWindowText("         "+des);
	}
	m_ThesisInfoSet.Close();
	*pResult = 0;
	UpdateData(false);
}

void CShowDialog::OnDblclkShowList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
//	AfxMessageBox("导出完各个感毕");
	CString strGrade,strTeacher,strStuname,strThesisname,strType,strScore,score;
	CString enKey,chKey;
	int l=m_show_list.GetSelectedCount();
	if(l<=0) 
	{
		MessageBox("您还没选中记录!","出错",MB_OK);
		return;
	}
    
	POSITION pos=m_show_list.GetFirstSelectedItemPosition();
	int nSel=m_show_list.GetNextSelectedItem(pos);
	
	CChangeAndDel dlg(m_show_list.GetItemText(nSel,1));
	switch( dlg.DoModal() )
	{
	case IDOK:
		m_show_list.SetItemText(nSel,0,dlg.m_edit2);
		m_show_list.SetItemText(nSel,3,dlg.m_edit4);
		m_show_list.SetItemText(nSel,2,dlg.m_edit3);
		m_show_list.SetItemText(nSel,4,dlg.m_edit5);
		m_show_list.SetItemText(nSel,5,dlg.m_edit10);
		score.Format("%.2f",dlg.m_edit6);
		m_show_list.SetItemText(nSel,6,score);
		chKey = dlg.m_edit7;
		chKey.Replace(",","  ");
		m_show_list.SetItemText(nSel,7,chKey);
	    enKey = dlg.m_edit8;//m_ThesisInfoSet.m_enkey1+" "+m_ThesisInfoSet.m_enkey2+" "+m_ThesisInfoSet.m_enkey3+" "+m_ThesisInfoSet.m_enkey4;
		enKey.Replace(",","  ");
		m_show_list.SetItemText(nSel,8,enKey);
		break;
	case IDCANCEL:
		break;
	}
	if( dlg.m_flag == 1 )
		m_show_list.DeleteItem(nSel);

/*	m_show_list.DeleteItem(nSel);
//	m_show_list.DeleteAllItems();
//UpdateData(true);
	switch( showType )
	{
	case NONE:
		showAll();
		//	m_show_list.DeleteAllItems();
		//		showAll();
		break;
	case STU_NAME:
		showSName(strText);
		break;
	case TCH_NAME:
		showTName(strText);
		break;
	case KEY_WORD:
		showKey(strText);
		break;
	case THESIS_NAME:
		showThesis(strText);
		break;
	case ALL:
		showUp(strText);
		break;
	}*/
	//	UpdateData(false);
	*pResult = 0;
}

void CShowDialog::OnColumnclickShowList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
//	AfxMessageBox("导出完各个感毕");
	*pResult = 0;
}
int CShowDialog::checkFile(CString wordfile)
{
	CFile file;
	CFileException fileException;
	if( !file.Open(wordfile,CFile::modeRead,&fileException) )
	{
			return 1;
	}
	return 0;
}
#include "msword9.h"
#include <AtlBase.h>

void CShowDialog::openWord(CString path,CString file)
{
	CLSID clsid;
	HRESULT hr;
	hr=::CLSIDFromProgID(L"Word.Application",&clsid);	//通过ProgID取得CLSID
	if(FAILED(hr))
	{
		AfxMessageBox(_T("不会吧,竟然没有安装OFFICE"));
		return;
	}
	IUnknown *pUnknown=NULL;
	IDispatch *pDispatch=NULL;
	_Application app;
	CString wordfile=path+"\\"+file;

	if( checkFile(wordfile) )
	{
		MessageBox(path+_T("下不存在文件: ")+file,"出错",MB_OK);
		return;
	}	
	app.CreateDispatch(_T("Word.Application"));
	app.SetVisible(TRUE);
	Documents docs=app.GetDocuments();
	CComVariant Template(wordfile);	//为了简单,没有使用WORD的文档模板
	CComVariant NewTemplate(false),DocumentType(0),Visible;
	docs.Add(&Template,&NewTemplate,&DocumentType,&Visible);



	app.SetCaption(file);
	hr=::GetActiveObject(clsid,NULL,&pUnknown);	//查找是否有WORD程序在运行
	if(FAILED(hr))
	{
		AfxMessageBox(_T("没有正在运行中的WORD应用程序"));
		return;
	}

	try
	{
		hr=pUnknown->QueryInterface(IID_IDispatch,(LPVOID *)&app);
		if(FAILED(hr))	throw(_T("没有取得IDispatchPtr"));
		pUnknown->Release();	pUnknown=NULL;
	
	}
	catch(LPCTSTR lpErr)
	{
		AfxMessageBox(lpErr);
	}
	if(pUnknown)	pUnknown->Release();
}

void CShowDialog::OnButton1() 
{
	// TODO: Add your control notification handler code here
	CString path,file;
	POSITION pos=m_show_list.GetFirstSelectedItemPosition();
	int nSel=m_show_list.GetNextSelectedItem(pos);

	int l=m_show_list.GetSelectedCount();
	if(l<=0) 
	{
		MessageBox("您还没选中记录!","出错",MB_OK);
		return;
	}
	if(!m_OtherInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE))
	{
       	AfxMessageBox("打开数据库失败!");
       	return;
	}
	m_OtherInfoSet.MoveFirst();
	do
	{
		 if(m_OtherInfoSet.m_name== "论文存放路径")
			 break;
		 m_OtherInfoSet.MoveNext();
	}while(!m_OtherInfoSet.IsEOF());
	path = m_OtherInfoSet.m_content;
    m_OtherInfoSet.Close();
	file = m_show_list.GetItemText(nSel,1)+m_show_list.GetItemText(nSel,2)+".doc";
	openWord(path,file);


	
}

void CShowDialog::OnButton2() 
{
	// TODO: Add your control notification handler code here
		CString path,file;
	POSITION pos=m_show_list.GetFirstSelectedItemPosition();
	int nSel=m_show_list.GetNextSelectedItem(pos);

	int l=m_show_list.GetSelectedCount();
	if(l<=0) 
	{
		MessageBox("您还没选中记录!","出错",MB_OK);
		return;
	}
	if(!m_OtherInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE))
	{
       	AfxMessageBox("打开数据库失败!");
       	return;
	}
	m_OtherInfoSet.MoveFirst();
	do
	{
		 if(m_OtherInfoSet.m_name== "摘要存放路径")
			 break;
		 m_OtherInfoSet.MoveNext();
	}while(!m_OtherInfoSet.IsEOF());
	path = m_OtherInfoSet.m_content;
    m_OtherInfoSet.Close();
	file = m_show_list.GetItemText(nSel,1)+m_show_list.GetItemText(nSel,2)+".doc";
	openWord(path,file);

	
}

BOOL CShowDialog::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CDialog::Create(IDD, pParentWnd);
}

⌨️ 快捷键说明

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