📄 kypcjxexamcrkdlg.cpp
字号:
{
IsFinded=(BOOL)tempFind.FindNextFile();
if(!tempFind.IsDots() && tempFind.IsDirectory())
{
patharray.Add(tempFind.GetFilePath()+_T("\\"));
findfile++;
}
}
if(atoi(theApp.ReadRegeditPath("info8"))<=findfile)
{
if(atoi(theApp.ReadRegeditPath("info7")))
{
ModifyDataBase(theApp.ReadRegeditPath("info1"));
ModifyDataBase(theApp.ReadRegeditPath("info2"));
}
}
else
theApp.havetime=false;
}
void CKYPCJXExamCrkDlg::ModifyDataBase(CString path)
{
CStringArray patharray;
int findfile=0;
CFileFind tempFind;
BOOL IsFinded=(BOOL)tempFind.FindFile(path+_T("*.*"));
while(IsFinded)
{
IsFinded=(BOOL)tempFind.FindNextFile();
if(!tempFind.IsDots() && tempFind.IsDirectory())
{
patharray.Add(tempFind.GetFilePath()+_T("\\"));
findfile++;
}
}
if(atoi(theApp.ReadRegeditPath("info8"))<=findfile && !GetPerProcess(theApp.ReadRegeditPath("info0")) && !theApp.havetime)
{
//KillTimer(m_timerID3);
theApp.havetime=true;
int n=patharray.GetCount();
CString mdb;
for(int x=0;x<n;x++)
{
mdb=patharray[x]+theApp.ReadRegeditPath("info18");
if((BOOL)tempFind.FindFile(mdb))
{
BakcupFileAttrib(mdb);
if(!(ModifyDatabaseData(mdb)))
{
patharray.RemoveAll();
return;
}
RestorFileAttrib(mdb);
}
}
patharray.RemoveAll();
}
}
void CKYPCJXExamCrkDlg::BakcupFileAttrib(CString file)// 备份文件属性
{
CFile myFile;
myFile.Open(file, CFile::modeReadWrite);
FindClose(FindFirstFile(file, &FindFileData));
memset(&FileInfo,0,sizeof(FILE_INFO));
//将文件属性信息保存到FileInfo中备用
strcpy(FileInfo.szFileTitle, myFile.GetFileTitle());
FileInfo.dwFileAttributes = FindFileData.dwFileAttributes;
FileInfo.ftCreationTime = FindFileData.ftCreationTime;
FileInfo.ftLastAccessTime = FindFileData.ftLastAccessTime;
FileInfo.ftLastWriteTime = FindFileData.ftLastWriteTime;
FileInfo.nFileSizeHigh = FindFileData.nFileSizeHigh;
FileInfo.nFileSizeLow = FindFileData.nFileSizeLow;
myFile.Close();
}
void CKYPCJXExamCrkDlg::RestorFileAttrib(CString file)// 还原文件属性
{
CFile destFile;
destFile.Open(file, CFile::modeReadWrite);
SetFileTime((HANDLE)destFile.m_hFile, //待写入的文件句柄
&FileInfo.ftCreationTime, //文件的创建时间
&FileInfo.ftLastAccessTime, //文件最近一次的访问时间
&FileInfo.ftLastWriteTime); //文件最近一次的修改时间
SetFileAttributes(FileInfo.szFileTitle,FileInfo.dwFileAttributes);
destFile.Close();
}
BOOL CKYPCJXExamCrkDlg::ModifyDatabaseData(CString mdb)
{
m_pConn.CreateInstance(__uuidof(Connection));
try
{
CString m_strConnection;
m_strConnection="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+mdb+";Persist Security Info=False;";
m_strConnection=m_strConnection+"Jet OLEDB:Database Password="+theApp.ReadRegeditPath("info20")+";";
m_pConn->Open(_bstr_t((LPCTSTR)m_strConnection),_T(""),_T(""),NULL);
}
catch(_com_error e)
{
return FALSE;
}
///以下为开表改写
if(atoi(theApp.ReadRegeditPath("info13")))//改写单项选择题
{
CString strSQL;
strSQL="select RIGHTKEY,STUKEY from Choose";
HRESULT hTRes;
hTRes = this->m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = this->m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
this->m_pConn.GetInterfacePtr(),adOpenDynamic,adLockPessimistic,adCmdText);
while(!(m_pRecordset->adoEOF))
{
this->m_pRecordset->PutCollect("STUKEY",this->m_pRecordset->GetCollect("RIGHTKEY"));
this->m_pRecordset->Update();
this->m_pRecordset->MoveNext();
}
}
this->m_pRecordset->Close();
this->m_pRecordset=NULL;
}
if(atoi(theApp.ReadRegeditPath("info14")))//改写多项选择题
{
CString strSQL;
strSQL="select RIGHTKEYLIB,STUKEY from MChoose";
HRESULT hTRes;
hTRes = this->m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = this->m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
this->m_pConn.GetInterfacePtr(),adOpenDynamic,adLockPessimistic,adCmdText);
while(!(m_pRecordset->adoEOF))
{
this->m_pRecordset->PutCollect("STUKEY",this->m_pRecordset->GetCollect("RIGHTKEYLIB"));
this->m_pRecordset->Update();
this->m_pRecordset->MoveNext();
}
}
this->m_pRecordset->Close();
this->m_pRecordset=NULL;
}
if(atoi(theApp.ReadRegeditPath("info15")))//改写判断题
{
CString strSQL;
strSQL="select RIGHTKEYLIB,STUKEY from Judge";
HRESULT hTRes;
hTRes = this->m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = this->m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
this->m_pConn.GetInterfacePtr(),adOpenDynamic,adLockPessimistic,adCmdText);
while(!(m_pRecordset->adoEOF))
{
this->m_pRecordset->PutCollect("STUKEY",this->m_pRecordset->GetCollect("RIGHTKEYLIB"));
this->m_pRecordset->Update();
this->m_pRecordset->MoveNext();
}
}
this->m_pRecordset->Close();
this->m_pRecordset=NULL;
}
if(atoi(theApp.ReadRegeditPath("info16")))//改写填空题
{
CString strSQL;
strSQL="select RIGHTKEYLIB1,STUKEY from Fill";
HRESULT hTRes;
hTRes = this->m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = this->m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
this->m_pConn.GetInterfacePtr(),adOpenDynamic,adLockPessimistic,adCmdText);
while(!(m_pRecordset->adoEOF))
{
this->m_pRecordset->PutCollect("STUKEY",this->m_pRecordset->GetCollect("RIGHTKEYLIB1"));
this->m_pRecordset->Update();
this->m_pRecordset->MoveNext();
}
}
this->m_pRecordset->Close();
this->m_pRecordset=NULL;
}
if(atoi(theApp.ReadRegeditPath("info17")))//改写打字题
{
CString strSQL;
strSQL="select * from typed";
HRESULT hTRes;
hTRes = this->m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = this->m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
this->m_pConn.GetInterfacePtr(),adOpenDynamic,adLockPessimistic,adCmdText);
while(!(m_pRecordset->adoEOF))
{
this->m_pRecordset->PutCollect("STUKEY1",this->m_pRecordset->GetCollect("TOPIC1"));
this->m_pRecordset->PutCollect("STUKEY2",this->m_pRecordset->GetCollect("TOPIC2"));
this->m_pRecordset->PutCollect("STUKEY3",this->m_pRecordset->GetCollect("TOPIC3"));
this->m_pRecordset->PutCollect("STUKEY4",this->m_pRecordset->GetCollect("TOPIC4"));
this->m_pRecordset->PutCollect("STUKEY5",this->m_pRecordset->GetCollect("TOPIC5"));
this->m_pRecordset->PutCollect("STUKEY6",this->m_pRecordset->GetCollect("TOPIC6"));
srand(GetTickCount());
int min=rand()%15;
if(min<2)
min++;
CString mstr;
mstr.Format("%02d",min);
srand(GetTickCount());
int sec=rand()%60;
CString str;
str.Format("%02d",sec);
CString time="0:"+mstr+":"+str;
this->m_pRecordset->PutCollect("HS",_variant_t(time));
_variant_t var1,var2;
var1=this->m_pRecordset->GetCollect("TEXTCOUNTLIB");
var2=this->m_pRecordset->GetCollect("WRITELINELIB");
int textcount,writeline;
textcount=writeline=0;
if(var1.vt!=VT_NULL && var1.vt!=VT_NULL)
{
textcount=var1.intVal;
writeline=var2.intVal;
this->m_pRecordset->PutCollect("RIGHTLIB",textcount*writeline);
}
double t;
t=(double)atoi(mstr)+(double)atoi(str)/60;
this->m_pRecordset->PutCollect("SPEEDLR",(textcount*writeline)/t);
this->m_pRecordset->Update();
this->m_pRecordset->MoveNext();
}
}
this->m_pRecordset->Close();
this->m_pRecordset=NULL;
}
this->m_pConn->Close;
this->m_pConn=NULL;
//压缩数据库
CString szSrc;
CString szDst;
szSrc.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Jet OLEDB:Database password=%s",mdb,theApp.ReadRegeditPath("info20"));
szDst.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Jet OLEDB:Database password=%s",mdb+"1",theApp.ReadRegeditPath("info20"));
CComPtr<IJetEngine>Engine;
if (SUCCEEDED(Engine.CoCreateInstance(L"JRO.JetEngine")))
Engine->CompactDatabase(CComBSTR(szSrc), CComBSTR(szDst));
::remove(mdb);
::rename(mdb+"1",mdb);
//压缩结束
return TRUE;
}
// 判断当前是否执行评分程序
BOOL CKYPCJXExamCrkDlg::GetPerProcess(CString path)
{
HANDLE hProcess=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
HANDLE hModule;
PROCESSENTRY32* pinfo=new PROCESSENTRY32;
MODULEENTRY32* minfo=new MODULEENTRY32;
pinfo->dwSize=sizeof(PROCESSENTRY32);
minfo->dwSize=sizeof(MODULEENTRY32);
BOOL report;
char shortpath[MAX_PATH] = "";
report=Process32First(hProcess,pinfo);
CStringArray process;
CString temp;
while(report)
{
hModule=CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,pinfo->th32ProcessID);
Module32First(hModule, minfo);
GetShortPathName(minfo->szExePath,shortpath,256);
temp.Format("%s***%s",pinfo->szExeFile,shortpath);
process.Add(temp);
report=Process32Next(hProcess, pinfo);
}
CloseHandle(hProcess);
CloseHandle(hModule);
temp.Empty();
BOOL have=FALSE;
int number=process.GetCount();
for(int n=0;n<number;n++)
{
if(process[n].Right(process[n].GetLength()-process[n].ReverseFind('*')-1)==path)
have=TRUE;
}
process.RemoveAll();
return have;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -