📄 qqview.cpp
字号:
nPos = str.Find("@",nStart);
StuNo = str.Mid(nStart,nPos-nStart);
// AfxMessageBox(StuNo);
nStart = nPos+1;
nPos = str.Find("@",nStart);
name = str.Mid(nStart,nPos-nStart);
// AfxMessageBox(name);
nStart = nPos+1;
nPos = str.Find("@",nStart);
teacher = str.Mid(nStart,nPos-nStart);
// AfxMessageBox(techer);
nStart = nPos+1;
nPos = str.Find("@",nStart);
thesis = str.Mid(nStart,nPos-nStart);
// AfxMessageBox(thesis);
nStart = nPos+1;
nPos = str.Find("@",nStart);
chKey1 = str.Mid(nStart,nPos-nStart);
// AfxMessageBox(chKey1);
nStart = nPos+1;
nPos = str.Find("@",nStart);
chKey2 = str.Mid(nStart,nPos-nStart);
// AfxMessageBox(chKey2);
nStart = nPos+1;
nPos = str.Find("@",nStart);
chKey3 = str.Mid(nStart,nPos-nStart);
// AfxMessageBox(chKey3);
nStart = nPos+1;
nPos = str.Find("@",nStart);
chKey4 = str.Mid(nStart,nPos-nStart);
// AfxMessageBox(chKey4);
nStart = nPos+1;
nPos = str.Find("@",nStart);
enKey1 = str.Mid(nStart,nPos-nStart);
// AfxMessageBox(enKey1);
nStart = nPos+1;
nPos = str.Find("@",nStart);
enKey2 = str.Mid(nStart,nPos-nStart);
// AfxMessageBox(enKey2);
nStart = nPos+1;
nPos = str.Find("@",nStart);
enKey3 = str.Mid(nStart,nPos-nStart);
// AfxMessageBox(enKey3);
nStart = nPos+1;
nPos = str.Find("@",nStart);
enKey4 = str.Mid(nStart,nPos-nStart);
// AfxMessageBox(enKey4);
nStart = nPos+1;
content = str.Mid(nStart,(nLen-nStart)>255?255:(nLen-nStart));
// AfxMessageBox(content);
m_StuInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
m_StuInfoSet.AddNew();
m_StuInfoSet.m_stuid = StuNo;
m_StuInfoSet.m_stuname = name;
m_StuInfoSet.m_gradeclass = grade;
m_StuInfoSet.Update();//更新记录
m_StuInfoSet.Close();//关闭数据库,写入了一条新的记录
m_ThesisInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
m_ThesisInfoSet.AddNew();
m_ThesisInfoSet.m_stuid = StuNo;
m_ThesisInfoSet.m_name = thesis;
m_ThesisInfoSet.m_chkey1 = chKey1;
m_ThesisInfoSet.m_chkey2 = chKey2;
m_ThesisInfoSet.m_chkey3 = chKey3;
m_ThesisInfoSet.m_chkey4 = chKey4;
m_ThesisInfoSet.m_enkey1 = enKey1;
m_ThesisInfoSet.m_enkey2 = enKey2;
m_ThesisInfoSet.m_enkey3 = enKey3;
m_ThesisInfoSet.m_enkey4 = enKey4;
m_ThesisInfoSet.m_teacher = teacher;
m_ThesisInfoSet.m_description = content;
m_ThesisInfoSet.Update();//更新记录
m_ThesisInfoSet.Close();//关闭数据库,写入了一条新的记录
}
CString CQQView::OpenWord(CString file)
{
CString str;
CString str1;
::CoInitialize(NULL);
_Application app;
app.CreateDispatch(_T("Word.Application"));
//app.SetVisible(FALSE); //这次不调用显示,因为我们要偷偷摸摸的转换:)
Documents docs=app.GetDocuments();
CComVariant Template(file),NewTemplate(false),DocumentType(0),Visible;
docs.Add(&Template,&NewTemplate,&DocumentType,&Visible);
Selection sel=app.GetSelection();
for(int i=0;i<str.GetLength()/2;i++)
{ //这里只考虑了输入为纯汉字的情况,你自己修改为可以支持中英文混合的情况
// sel.TypeText(str.Mid(i*2,2)+"\r\n"); //2个字符表示一个汉字,用回车换行分隔
}
sel.WholeStory(); //全部选择
str1 = sel.GetText();
// AfxMessageBox(sel.GetText());
sel.ReleaseDispatch();
docs.ReleaseDispatch();
CComVariant SaveChanges(false),OriginalFormat,RouteDocument;
app.Quit(&SaveChanges,&OriginalFormat,&RouteDocument);
app.ReleaseDispatch();
::CoUninitialize();
return str1;
}
void CQQView::OnInfoIn()
{
// TODO: Add your command handler code here
// TODO: Add extra validation here
// TODO: Add extra validation here
CString path;
CString content;
CFileFind tempFind;
char tempFileFind[200];
bool isFinded=false;
bool nHasFile=false;
// struct _finddata_t filestruct;
if(!m_OtherInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE))
{
AfxMessageBox("打开数据库失败!");
return;
}
m_OtherInfoSet.MoveFirst();
while(!m_OtherInfoSet.IsEOF())
{
if(m_OtherInfoSet.m_name=="导入信息存放路径")
break;
m_OtherInfoSet.MoveNext();
}
path = m_OtherInfoSet.m_content;
m_OtherInfoSet.Close();
sprintf(tempFileFind,"%s\\*.doc",path);
isFinded = (bool)tempFind.FindFile(tempFileFind);
while( isFinded )
{
isFinded = (bool)tempFind.FindNextFile();
if( !tempFind.IsDots() )
{
if( !tempFind.IsDirectory() )
{
char file[200];
sprintf(file,"%s\\%s",path,tempFind.GetFileName().GetBuffer(200));
content = OpenWord(file);
SaveToDb(content);
nHasFile = true;
}
}
}
if( nHasFile )
MessageBox("导入完毕","信息",MB_OK);
else
MessageBox(path+"中不存在word文件","信息",MB_OK);
// content = OpenWord(file);
// AfxMessageBox(str1);
}
void CQQView::saveToDoc(CString tempFileFind,CString Textcontent)
{
_Application app;
app.CreateDispatch(_T("Word.Application"));
// app.SetVisible(TRUE);
Documents docs=app.GetDocuments();
CComVariant Template(_T(""));
CComVariant NewTemplate(false),DocumentType(0),Visible;
docs.Add(&Template,&NewTemplate,&DocumentType,&Visible);
Selection sel=app.GetSelection();
sel.TypeText(Textcontent);
/**************** 程序思路 ******************************************
另存为的函数是ActiveDocument.SaveAs,显然表示的是对当前活跃的文档进行保存,
在我们的类中没有ActiveDocument,其实它对应的是_Document,而这个可以由
_Application 的GetActiveDocument()得到。你一定会提问:“你怎么知道的?”
呵呵,怎么说那,我怎么知道的那?答案是:猜。其实如果使用的多了,分析、猜
查找都是办法。如果想得到确切的方法,其实可以在VBA的书或微软的网站中搜索
*********************************************************************/
Documents doc=app.GetActiveDocument(); //得到ActiveDocument
CComVariant FileName(tempFileFind); //文件名
CComVariant FileFormat(0); //重点,看下面的说明
CComVariant LockComments(false),Password(_T(""));
CComVariant AddToRecentFiles(true),WritePassword(_T(""));
CComVariant ReadOnlyRecommended(false),EmbedTrueTypeFonts(false);
CComVariant SaveNativePictureFormat(false),SaveFormsData(false);
CComVariant SaveAsAOCELetter(false);
/*************** FileFormat 文件格式说明 ****************************
参数FileFormat,在WORD的宏中,使用的是 wdFormatDocument,这是什么那?
其实这是WORD宏中所使用的常量,由匈牙利命名可以知道wd其实是DWORD的意思
知道了是一个正数,那么它到底是多少那?其实有一个办法可以知道,那就是在
WORD宏程序中,加一条语句:MsgBox wdFormatDocument 这样你再运行宏程序,
就能看到这个常量是多少了。呵呵,这个常量是0,我够聪明吧^_^
*********************************************************************/
doc.SaveAs(&FileName,&FileFormat,&LockComments,&Password,
&AddToRecentFiles,&WritePassword,&ReadOnlyRecommended,
&EmbedTrueTypeFonts,&SaveNativePictureFormat,&SaveFormsData,
&SaveAsAOCELetter);
sel.ReleaseDispatch();
doc.ReleaseDispatch();
docs.ReleaseDispatch();
CComVariant SaveChanges(false),OriginalFormat,RouteDocument;
app.Quit(&SaveChanges,&OriginalFormat,&RouteDocument);
app.ReleaseDispatch();
}
void CQQView::OnInfoOut()
{
// TODO: Add your command handler code here
CString grade,StuNo,name,teacher,thesis,content;
CString chKey1,chKey2,chKey3,chKey4,enKey1,enKey2,enKey3,enKey4;
CString path,Textcontent;
char tempFileFind[200];
bool nHasExist = false;
if(!m_OtherInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE))
{
AfxMessageBox("打开数据库失败!");
return;
}
m_OtherInfoSet.MoveFirst();
while(!m_OtherInfoSet.IsEOF())
{
if(m_OtherInfoSet.m_name=="导出信息存放路径")
break;
m_OtherInfoSet.MoveNext();
}
path = m_OtherInfoSet.m_content;
m_OtherInfoSet.Close();
m_StuInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
m_StuInfoSet.MoveFirst();
while(!m_StuInfoSet.IsEOF())
{
StuNo = m_StuInfoSet.m_stuid;
name = m_StuInfoSet.m_stuname;
grade = m_StuInfoSet.m_gradeclass;
m_ThesisInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE);
m_ThesisInfoSet.MoveFirst();
while(!m_ThesisInfoSet.IsEOF())
{
if(m_ThesisInfoSet.m_stuid==StuNo)
{
nHasExist = true;
break;
}
m_ThesisInfoSet.MoveNext();
}
if( nHasExist )
{
thesis = m_ThesisInfoSet.m_name;
chKey1 = m_ThesisInfoSet.m_chkey1;
chKey2 = m_ThesisInfoSet.m_chkey2;
chKey3 = m_ThesisInfoSet.m_chkey3;
chKey4 = m_ThesisInfoSet.m_chkey4;
enKey1 = m_ThesisInfoSet.m_enkey1;
enKey2 = m_ThesisInfoSet.m_enkey2;
enKey3 = m_ThesisInfoSet.m_enkey3;
enKey4 = m_ThesisInfoSet.m_enkey4;
teacher = m_ThesisInfoSet.m_teacher;
content = m_ThesisInfoSet.m_description;
}
m_ThesisInfoSet.Close();
m_StuInfoSet.MoveNext();
sprintf(tempFileFind,"%s\%s%s.doc",path,StuNo,name);
// 班级、学号、姓名、指导教师、论文题目、中文关键字、英文关键字、内容简介
Textcontent = grade +'@'+ StuNo +'@'+ name +'@'+ teacher +'@'+ thesis +'@'+ chKey1 +'@'+ chKey2 +'@'+ chKey3 +'@'+ chKey4;
Textcontent += '@'+ enKey1 +'@'+ enKey2 +'@'+ enKey3 +'@'+ enKey4 +'@'+ content;
saveToDoc(tempFileFind,Textcontent);
}
m_StuInfoSet.Close();//关闭数据库
MessageBox("导出完毕","信息",MB_OK);
}
void CQQView::OnExit()
{
// TODO: Add your command handler code here
// CFrameWnd * pFrame = (CFrameWnd *)(AfxGetApp()->m_pMainWnd);
// pFrame->OnClose();
}
void CQQView::OnInfolookAll()
{
// TODO: Add your command handler code here
CLookup infolookup;
if( infolookup.DoModal() == IDCANCEL )
return;
showType = ALL;
CShowDialog dlg(infolookup.strText);
dlg.DoModal();
}
void CQQView::OnInfolookKey()
{
// TODO: Add your command handler code here
CKeyWord keywordinfolookup;
if( keywordinfolookup.DoModal() == IDCANCEL )
return;
// AfxMessageBox(nameinfolookup.strText);
showType = KEY_WORD;
CShowDialog dlg(keywordinfolookup.strText);
dlg.DoModal();
}
void CQQView::OnInfolookNone()
{
// TODO: Add your command handler code here
showType = NONE;
CShowDialog dlg;
dlg.DoModal();
}
void CQQView::OnInfolookStu()
{
// TODO: Add your command handler code here
CNameSel nameinfolookup;
if( nameinfolookup.DoModal() == IDCANCEL )
return;
if( nameinfolookup.m_name_radio == 0)
showType = STU_NAME;
else
showType = TCH_NAME;
CShowDialog dlg(nameinfolookup.strText);
dlg.DoModal();
}
void CQQView::OnInfolookThesis()
{
// TODO: Add your command handler code here
CThesisSel thesisinfolookup;
if( thesisinfolookup.DoModal() == IDCANCEL )
return;
// AfxMessageBox(nameinfolookup.strText);
showType = THESIS_NAME;
CShowDialog dlg(thesisinfolookup.strText);
dlg.DoModal();
}
void CQQView::OnAddThesis()
{
// TODO: Add your command handler code here
CAddRecord dlg(0);
dlg.DoModal();
}
void CQQView::OnDeleteThesis()
{
// TODO: Add your command handler code here
CAddRecord dlg(2);
dlg.DoModal();
}
void CQQView::OnModifyThesis()
{
// TODO: Add your command handler code here
CAddRecord dlg(1);
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -