📄 mainsrc.pas
字号:
abort;
end;
repeat
Read(alter_db_name_file,alter_db_name);
Inc(index);
if alter_db_name.UserName=Current_User.UserName then
for itemindex:=0 to 19 do
if alter_db_name.Created_DB[index]=TreeView1.Selected.Text then
begin
alter_db_name.Created_DB[index]:=NewDBName;
Current_User.Created_DB[index]:=NewDBName;
try
Seek(alter_db_name_file,index);
Write(alter_db_name_file,alter_db_name);
except
messagedlg(#13'数据库名已更改,但在写入注册信息时发生错误!',mterror,[mbok],0);
CloseFile(alter_db_name_file);
abort;
end;
end;
until Eof(alter_db_name_file);
CloseFile(alter_db_name_file);
messagedlg(#13'更改数据库名称为 '+NewDBName+' 成功!',mtinformation,[mbok],0);
end;
procedure TMain.ListView1ColumnClick(Sender: TObject; Column: TListColumn);
begin
showmessage('ok');
end;
procedure TMain.ListView1DblClick(Sender: TObject);
var temp,tabcount:integer;
begin
if ListView1.SelCount>0 then
begin
temp:=strtoint(inputbox('题目类型:'+ListView1.Selected.SubItems.Strings[0],'Please enter the number of test(Max:'+
ListView1.Selected.SubItems.Strings[2]+'):',ListView1.Selected.SubItems.Strings[1]));
if temp<=strtoint(ListView1.Selected.SubItems.Strings[2]) then
ListView1.Selected.SubItems.Strings[1]:=inttostr(temp)
else
begin
messagedlg(#13'你输入的数目已超过最大值,可通过调整年限来增大最大值!',mterror,[mbok],0);
abort;
end;
totalscore.Caption:='0';
for TabCount:=0 to ListView1.Items.Count-1 do
totalscore.Caption:=InttoStr(StrtoInt(totalscore.Caption)+
StrtoInt(ListView1.Items.Item[tabcount].SubItems.Strings[1])* StrtoInt(ListView1.Items.Item[tabcount].SubItems.Strings[3]));
ListView1.Selected.SubItems.Strings[3]:=inputbox('题目类型:'+Trim(ListView1.Selected.SubItems.Strings[0]),'Please enter the score of per test:',ListView1.Selected.SubItems.Strings[3]);
totalscore.Caption:='0';
for TabCount:=0 to ListView1.Items.Count-1 do
totalscore.Caption:=InttoStr(StrtoInt(totalscore.Caption)+
StrtoInt(ListView1.Items.Item[tabcount].SubItems.Strings[1])* StrtoInt(ListView1.Items.Item[tabcount].SubItems.Strings[3]));
end;
end;
procedure TMain.BitBtn1Click(Sender: TObject);
var regtest:TIniFile;
listitemcount:integer;
begin
if ListView1.Items.Count>0 then
begin
if FileExists('ini\'+Trim(PapInf_DBName.Text)+'.ini') then
try
DeleteFile('ini\'+Trim(PapInf_DBName.Text)+'.ini');
except
messagedlg(#13'在删除原配置文件 '+Trim(PapInf_DBName.Text)+'.ini 时发生错误!',mterror,[mbok],0);
end;
regtest:=TIniFile.Create('ini\'+Trim(PapInf_DBName.Text)+'.ini');
regtest.WriteInteger('deadline','months',strtoint(MidStr(Trim(limmon.Text),1,2)));
for listitemcount:=0 to ListView1.Items.Count-1 do
begin
regtest.WriteString(ListView1.Items.Item[listitemcount].SubItems.Strings[4],'number',ListView1.Items.Item[listitemcount].SubItems.Strings[1]);
regtest.WriteString(ListView1.Items.Item[listitemcount].SubItems.Strings[4],'score',ListView1.Items.Item[listitemcount].SubItems.Strings[3]);
end;
regtest.Free;
messagedlg(#13'以上配置信息保存成功!',mtinformation,[mbok],0);
end
else
abort;
end;
procedure TMain.TabAmendHide(Sender: TObject);
begin
ADOTableAmend.Close;
ADOConAmend.Close;
end;
procedure TMain.GenPapBeginClick(Sender: TObject);
var TestArray:array of integer;
TempField:array of string;
TestCount,arrayindex,arraycheck,temp,tempfieldindex,index,titleindex,test_num:integer;
isonly:boolean;
TestListItem:TListItem;
dbnow:string;
title :Array[0..19] of string;
begin
title[0]:='一、';title[1]:='二、';title[2]:='三、';title[3]:='四、';title[4]:='五、';title[5]:='六、';
title[6]:='七、';title[7]:='八、';title[8]:='九、';title[9]:='十、';title[10]:='十一、';title[11]:='十二、';
title[12]:='十三、';title[13]:='十四、';title[14]:='十五、';title[15]:='十六、';title[16]:='十七、';
title[17]:='十八、';title[18]:='十九、';title[19]:='二十、';
if strtoint(totalscore.Caption)>0 then
begin
isDisplay:=True;
pagecon.ActivePage:=TabPapPreview;
if ListView2.Items.Count>0 then
repeat
ListView2.Items.Item[0].Delete;
until ListView2.Items.Count=0;
end
else
begin
isDisPlay:=False;
abort;
end;
dbnow:=Trim(PapInf_DbName.Text);
for index:=0 to 19 do
if Current_User.Created_DB[index]=dbnow then break;
try
ADOConGenPap.Close;
ADOConGenPap.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database\'+dbnow+
';Mode=Share Deny None;Persist Security Info=False;Jet OLEDB:Database Password='
+DeCode(Current_User.Authen_DB_Pass[index]);
ADOConGenPap.Open;
except
messagedlg(#13'在连接数据库'+Trim(dbnow)+'时发生错误!',mterror,[mbok],0);
abort;
end;
ADOQueryGenPap.Connection:=ADOConGenPap;
for TestCount:=0 to ListView1.Items.Count-1 do
begin
if testcount=0 then test_num:=0
else if ListView1.Items.Item[testcount].SubItems.Strings[0]=ListView1.Items.Item[testcount-1].SubItems.Strings[0] then
test_num:=test_num+StrToInt(ListView1.Items.Item[testcount-1].SubItems.Strings[1])
else test_num:=0;
if (strtoint(ListView1.Items.Item[testcount].SubItems.Strings[1])>0) and
(strtoint(ListView1.Items.Item[testcount].SubItems.Strings[1])<=strtoint(ListView1.Items.Item[testcount].SubItems.Strings[2])) then
begin
try
if length(ADOQueryGenPap.SQL.GetText)>0 then ADOQueryGenPap.SQL.Clear;
ADOQueryGenPap.SQL.Append('SELECT id FROM '+ListView1.Items.Item[TestCount].SubItems.Strings[4]+' WHERE last_date <='+InttoStr(deadline));
ADOQueryGenPap.Open;
except
messagedlg(#13'在从数据表'+ListView1.Items.Item[TestCount].SubItems.Strings[4]+'抽取'+
ListView1.Items.Item[TestCount].SubItems.Strings[0]+'时发生错误,抽取失败!',mterror,[mbok],0);
continue;
end;
SetLength(tempfield,ADOQueryGenPap.RecordCount);
ADOQueryGenPap.Recordset.MoveFirst;
for tempfieldindex:=0 to ADOQueryGenPap.RecordCount-1 do
begin
tempfield[tempfieldindex]:=ADOQueryGenPap.Recordset.Fields.Item[0].Value;
if not ADOQueryGenPap.Eof then ADOQueryGenPap.Recordset.MoveNext;
end;
ADOQueryGenPap.Close;
SetLength(TestArray,strtoint(ListView1.Items.Item[TestCount].SubItems.Strings[1]));
RandSeed:= HourOf(Time)*1000+MinuteOf(Time)*100+SecondOf(Time)*10;
for arrayindex:=0 to High(TestArray) do
begin
if arrayindex>0 then
begin
repeat
isonly:=True;
Randomize;
temp:=Random(strtoint(ListView1.Items.Item[testcount].SubItems.Strings[2]));
for arraycheck:=0 to arrayindex-1 do
if temp=TestArray[arraycheck] then isonly:=false;
until isonly;
TestArray[arrayindex]:=temp;
TestListItem:=Listview2.Items.Add();
TestListItem.Caption:=InttoStr(test_num+arrayindex+1);
TestListItem.SubItems.Insert(0,tempfield[TestArray[arrayindex]]);
TestListItem.SubItems.Insert(1,ListView1.Items.Item[TestCount].SubItems.Strings[0]);
TestListItem.SubItems.Insert(2,ListView1.Items.Item[TestCount].SubItems.Strings[4]);
TestListItem.SubItems.Insert(3,'');
end
else
begin
Randomize;
TestArray[arrayindex]:=Random(strtoint(ListView1.Items.Item[testcount].SubItems.Strings[2]));
TestListItem:=Listview2.Items.Add();
TestListItem.Caption:=InttoStr(test_num+arrayindex+1);
TestListItem.SubItems.Insert(0,tempfield[TestArray[arrayindex]]);
TestListItem.SubItems.Insert(1,ListView1.Items.Item[TestCount].SubItems.Strings[0]);
TestListItem.SubItems.Insert(2,ListView1.Items.Item[TestCount].SubItems.Strings[4]);
if testcount=0 then
begin
titleindex:=0;
TestListItem.SubItems.Insert(3,title[titleindex]+ListView1.Items.Item[TestCount].SubItems.Strings[0]+
'(每题'+ListView1.Items.Item[TestCount].SubItems.Strings[3]+'分,共'+
ListView1.Items.Item[TestCount].SubItems.Strings[1]+'题)');
end
else if not (ListView1.Items.Item[testcount].SubItems.Strings[0]=ListView1.Items.Item[testcount-1].SubItems.Strings[0]) then
begin
Inc(titleindex);
TestListItem.SubItems.Insert(3,title[titleindex]+ListView1.Items.Item[TestCount].SubItems.Strings[0]+
'(每题'+ListView1.Items.Item[TestCount].SubItems.Strings[3]+'分,共'+
ListView1.Items.Item[TestCount].SubItems.Strings[1]+'题)');
end
else
begin
TestListItem.SubItems.Insert(3,ListView1.Items.Item[TestCount].SubItems.Strings[0]+
'(每题'+ListView1.Items.Item[TestCount].SubItems.Strings[3]+'分,共'+
ListView1.Items.Item[TestCount].SubItems.Strings[1]+'题)');
end;
end;
end;
end;
end;
isDisPlay:=False;
ADOConGenPap.Close;
ListView2.Update;
if checkbox1.Checked then GenPapDocClick(Sender);
end;
procedure TMain.GenPapRepumpAllClick(Sender: TObject);
begin
GenPapBeginClick(Sender);
end;
procedure TMain.ListView2Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
var testindex:integer;
testtype:String;
begin
if not isDisplay then
begin
testtype:=Trim(Item.SubItems.Strings[2]);
if Item.Checked then
begin
for testindex:=0 to ListView2.Items.Count -1 do
begin
if ListView2.Items.Item[testindex].SubItems.Strings[2]=testtype then
ListView2.Items.Item[testindex].Checked:=True
else ListView2.Items.Item[testindex].Checked:=false;
end;
end
else
begin
for testindex:=0 to ListView2.Items.Count -1 do
begin
if ListView2.Items.Item[testindex].SubItems.Strings[2]=testtype then
ListView2.Items.Item[testindex].Checked:=False
end;
end;
end
else abort;
end;
procedure TMain.GenPapRepumpClick(Sender: TObject);
var repumptest:Array of integer;
testindex,arrayindex,temp,startindex,tempindex,maxnumber,arraycheck:integer;
testtype:string;
isonly:boolean;
begin
startindex:=0;
for testindex:=0 to ListView2.Items.Count-1 do
if ListView2.Items.Item[testindex].Checked then
testtype:=ListView2.Items.Item[testindex].SubItems.Strings[2];
if length(testtype)=0 then abort;
for testindex:=0 to ListView1.Items.Count-1 do
if ListView1.Items.Item[testindex].SubItems.Strings[4]=testtype then
begin
SetLength(repumptest,strtoint(ListView1.Items.Item[testindex].SubItems.Strings[1]));
maxnumber:=strtoint(ListView1.Items.Item[testindex].SubItems.Strings[2]);
for tempindex:=0 to testindex-1 do
startindex:=startindex+strtoint(ListView1.Items.Item[tempindex].SubItems.Strings[1]);
end;
RandSeed:= HourOf(Time)*1000+MinuteOf(Time)*100+SecondOf(Time)*10;
for arrayindex:=0 to high(repumptest) do
begin
if arrayindex>0 then
begin
repeat
isonly:=True;
Randomize;
temp:=Random(maxnumber);
for arraycheck:=0 to arrayindex-1 do
if temp=RepumpTest[arraycheck] then isonly:=false;
until isonly;
RepumpTest[arrayindex]:=temp;
ListView2.Items.Item[startindex+arrayindex].SubItems.Strings[0]:=inttostr(RepumpTest[arrayindex]);
end
else
begin
Randomize;
RepumpTest[arrayindex]:=Random(maxnumber);
ListView2.Items.Item[startindex].SubItems.Strings[0]:=inttostr(RepumpTest[arrayindex]);
end;
end;
end;
procedure TMain.PapGenPreviewClick(Sender: TObject);
var TempLate,newTemplate,Visible,DocumentType,munit,count,mext:OleVariant;
test_sum_count,test_count,index,checked_count,checked_now:integer;
ischecked:boolean;
title :Array[0..19] of string;
ms:TMemoryStream;
bmp:TBitMap;
MyFormat : Word;
AData: THandle;
Apalette: HPALETTE;
db:string;
begin
ms:=TMemoryStream.Create;bmp:=TBitMap.Create;
munit:=wdLine;Count:=3;mext:=0;
checked_count:=0;
checked_now:=1;
title[0]:='一';title[1]:='二';title[2]:='三';title[3]:='四';title[4]:='五';title[5]:='六';
title[6]:='七';title[7]:='八';title[8]:='九';title[9]:='十';title[10]:='十一';title[11]:='十二';
title[12]:='十三';title[13]:='十四';title[14]:='十五';title[15]:='十六';title[16]:='十七';
title[17]:='十八';title[18]:='十九';title[19]:='二十';
TempLate:=emptyparam;newTempLate:=False;Visible:=True;DocumentType:=emptyparam;
if ListView2.Items.Count>0 then
begin
ischecked:=False;
PapGenPreview.Enabled:=False;
for test_count:=0 to ListView2.Items.Count-1 do
if ListView2.Items.Item[test_count].Checked then
Inc(Checked_count);
probar.Max:=checked_count;
probar.Position:=0;
panel3.Visible:=True;
now_count.Caption:='正在启动OLE服务器···';
now_count.Update;
if not (Checked_count>0) then
begin
panel3.Visible:=False;
PapGenPreview.Enabled:=True;
abort;
end;
try
WordApp1.Caption:='⊙通用题库管理系统⊙';
WordApp1.Connect;
WordApp1.Visible:=False;
except
messagedlg(#13'无法启动Microsoft Word OLE服务器,请确定你的Office版本!',mterror,[mbok],0);
PapGenPreview.Enabled:=True;
abort;
end;
try
WordDoc1.ConnectTo(WordApp1.Documents.Add(Template, NewTemplate,DocumentType,visible));
except
messagedlg(#13'在创建Word文档时发生错误,无法生成预览!',mterror,[mbok],0);
WordApp1.Quit;
PapGenPreview.Enabled:=True;
abort;
end;
With WordDoc1.Range.PageSetup do {Set paper size}
begin
PageWidth
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -