6 Star 3 Fork 0

阿甘 / CTestAutoJudge

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
frmsettestcase.~cpp 4.88 KB
一键复制 编辑 原始数据 按行查看 历史
阿甘 提交于 2020-07-13 20:06 . (1)版本更新到2.1.X.X
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "frmsettestcase.h"
#include "tfilename.h"
//---------------------------------------------------------------------------
#include"myprogfun.h"
#include "testcase.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
const AnsiString TITLE1="测试用例管理,";
TFrmTestCase *FrmTestCase;
using namespace imagan;
//---------------------------------------------------------------------------
__fastcall TFrmTestCase::TFrmTestCase(TComponent* Owner,int paperId,int quesId)
: TForm(Owner)
{
this->paperId=paperId;
this->quesId=quesId;
this->UpdateTitle();
this->UpdateTestFileList();
}
//---------------------------------------------------------------------------
void __fastcall TFrmTestCase::LstBxInputClick(TObject *Sender)
{
int index= LstBxInput->ItemIndex;
LstBxOutput->ItemIndex=index;
if(index!=-1)
{
LstBxInput->Hint=LstBxInput->Items->Strings[index];
LstBxOutput->Hint=LstBxOutput->Items->Strings[index];
TestFile testfile(LstBxInput->Hint,LstBxOutput->Hint);
TestCase* tcase=testfile.Read();
this->MemInput->Clear();
this->MemInput->Lines->AddStrings(tcase->Input);
this->MemOutput->Clear();
this->MemOutput->Lines->AddStrings(tcase->Output);
}
}
//---------------------------------------------------------------------------
void __fastcall TFrmTestCase::BtnSaveClick(TObject *Sender)
{
int k=this->LstBxInput->ItemIndex;
if(k==-1)
{
ShowMessage("没有选定测试文件");
return;
}
try
{
TestCase*testcase=new TestCase();
testcase->Input->AddStrings(this->MemInput->Lines);
testcase->Output->AddStrings(this->MemOutput->Lines);
TestFile*testfile=new TestFile(this->LstBxInput->Items->Strings[k],
this->LstBxOutput->Items->Strings[k]);
testfile->Save(testcase);
ShowMessage("保存成功!");
this->BtnSave->Enabled=false;
}
catch(Exception & Exp)
{
ShowMessage(Exp.Message);
}
}
//---------------------------------------------------------------------------
void TFrmTestCase::UpdateTestFileList()
{
TStringList*inputfiles=new TStringList;
TStringList*outputfiles=new TStringList;
GetAllTestFile(inputfiles,
outputfiles,(short)paperId,(short)quesId);
this->LstBxInput->Items->Clear();
this->LstBxOutput->Items->Clear();
this->LstBxInput->Items->AddStrings(inputfiles);
this->LstBxOutput->Items->AddStrings(outputfiles);
delete inputfiles;
delete outputfiles;
}
void TFrmTestCase::UpdateTitle()
{
AnsiString paperAB=(paperId==0?"不分AB卷":(paperId==1?"A卷":"B卷"));
AnsiString quesIdStr=AnsiString("第")+IntToStr(quesId+1)+"题";
this->Caption=TITLE1+paperAB+","+quesIdStr;
}
void __fastcall TFrmTestCase::Button1Click(TObject *Sender)
{
if(MessageBox(this->WindowHandle,"确实要添加测试文件否?","添加确认",
MB_OKCANCEL)==IDCANCEL )
return;
TFileSpec fs(Application->ExeName);
AnsiString fpath=fs.FilePath+"test_example\\";
int ind=LstBxInput->Items->Count-1;
int nextOrder=1;
if(ind!=-1)
nextOrder=this->GetNextOrderStr(LstBxInput->Items->Strings[ind]);
TestFile* tf=TestFile::CreateTestFile(fpath,this->paperId,this->quesId,
nextOrder);
LstBxInput->Items->Add(tf->InputFile);
LstBxOutput->Items->Add(tf->OutputFile);
LstBxInput->ItemIndex=LstBxInput->Count-1;
LstBxOutput->ItemIndex=LstBxOutput->Count-1;
TestCase*testcase=tf->Read();
MemInput->Lines->Clear();
MemInput->Lines->AddStrings(testcase->Input);
MemOutput->Lines->Clear();
MemOutput->Lines->AddStrings(testcase->Output);
delete tf;
}
//---------------------------------------------------------------------------
int TFrmTestCase::GetNextOrderStr(AnsiString fname)
{
int pos0=fname.LastDelimiter("_");
int pos1=fname.LastDelimiter(".");
AnsiString orders=fname.SubString(pos0+1,pos1-pos0-1);
return orders.ToInt()+1;
}
void __fastcall TFrmTestCase::btnDelClick(TObject *Sender)
{
if (MessageDlg("确实要删除最后一个测试用例文件吗?", mtConfirmation,
TMsgDlgButtons() << mbOK << mbCancel, 0) == mrCancel) {
return;
}
int ind=LstBxInput->Count-1;
if(ind<0)
return;
AnsiString fpath0=LstBxInput->Items->Strings[ind];
AnsiString fpath1=LstBxOutput->Items->Strings[ind];
if(!DeleteFileA(fpath0)||!DeleteFileA(fpath1))
{
MessageDlg("删除失败!", mtInformation, TMsgDlgButtons() << mbOK, 0);
return;
}
LstBxInput->Items->Delete(ind);
LstBxOutput->Items->Delete(ind);
}
//---------------------------------------------------------------------------
void __fastcall TFrmTestCase::MemInputChange(TObject *Sender)
{
if(LstBxInput->ItemIndex==-1)
return;
this->BtnSave->Enabled=true;
}
//---------------------------------------------------------------------------
C++
1
https://gitee.com/gancaijun/CTestAutoJudge.git
git@gitee.com:gancaijun/CTestAutoJudge.git
gancaijun
CTestAutoJudge
CTestAutoJudge
develop

搜索帮助