📄 u_sjzdsc.pas
字号:
ARecord^.gwzlxh:=PMyRec(treenode1.Data)^.gwzlxh;
ARecord^.khdxxh:=PMyRec(treenode1.Data)^.khdxxh;
ARecord^.khdxmc:=treenode1.Text;
MyList.Add(ARecord);
end;
end;
treenode1:=treenode1.getNextSibling;
end;
end
else
if PMyRec(treeview1.Selections[i].Data)^.flag then
begin
New(ARecord);
ARecord^.zyxh := PMyRec(treeview1.Selections[i].Data)^.zyxh;
ARecord^.gwlbxh := PMyRec(treeview1.Selections[i].Data)^.gwlbxh;
ARecord^.gwzlxh:=PMyRec(treeview1.Selections[i].Data)^.gwzlxh;
ARecord^.khdxxh:=PMyRec(treeview1.Selections[i].Data)^.khdxxh;
ARecord^.khdxmc:=treeview1.Selections[i].Text;
MyList.Add(ARecord);
end;
end;
if not Assigned(WordObject) then
begin
WordObject := TWordObject.Create;
with WordObject do begin
Visible := false;
OnQuit := WordQuit;
end;
end;
v1:=WdDoNotSaveChanges;
v2:=Unassigned;
v3:=Unassigned;
if WordObject.Application.Documents.Count>0 then
begin
WordObject.Application.Documents.Close(v1,v2,v3);
WordObject.Visible:=false;
end;
Save_Cursor:=screen.Cursor;
screen.Cursor:=crHourGlass;
txxhhz[1]:='一';
txxhhz[2]:='二';
txxhhz[3]:='三';
txxhhz[4]:='四';
txxhhz[5]:='五';
txxhhz[6]:='六';
txxhhz[7]:='七';
txxhhz[8]:='八';
txxhhz[9]:='九';
txxhhz[10]:='十';
tbl_sjscfanr.Filter:='faname='+QuotedStr(trim(combobox1.Text));
tbl_sjscfa.Locate('faname',trim(combobox1.Text),[loCaseInsensitive]);
progressfrm.ProgressBar1.Min:=0;
progressfrm.ProgressBar1.Max:=UpDown1.Position*tbl_sjscfanr.RecordCount;
progressfrm.Caption:='正在生成试卷,请稍候...';
progressfrm.Show;
//初始随机数产生器
Randomize;
for i:=0 to MyList.Count-1 do
begin
for j:=0 to UpDown1.Position-1 do //试卷套数循环
begin
tbl_tmp_stlb.Close;
tbl_tmp_stlb.EmptyTable;
tbl_tmp_stlb.Open;
//根据配卷方案,计算出重点题的数量(nzdtksl)
//得出重点题的数量(nzdtsl)
ntotal:=tbl_sjscfanr.RecordCount;
nzdtsl:=round(ntotal*tbl_sjscfa.fieldbyname('zdtbl').AsInteger/100.0);
setLength(zycdarray,ntotal);
//首次产生试题重要程度随机数组
for m:=0 to ntotal-1 do
begin
zycdarray[m]:=false;
end;
ncount:=0;
for m:=0 to ntotal-1 do
begin
n:=RandomRange(1,100);
if (n<=tbl_sjscfa.fieldbyname('zdtbl').AsInteger) and (ncount<nzdtsl) then
begin
zycdarray[m]:=true;
ncount:=ncount+1;
end;
end;
//调整不足
n:=nzdtsl-ncount;
if n<>0 then
begin
for m:=1 to n do
begin
for k:=0 to ntotal-1 do
begin
if not zycdarray[k] then
begin
zycdarray[k]:=true;
break;
end;
end;
end;
end;
stcount:=0;
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('select distinct txxh from sjscfanr where faname='''+combobox1.Text+'''');
Query1.Open;
while not Query1.Eof do //试题题型循环
begin
//试题数量k
Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Add('select txxh from sjscfanr where faname='''+combobox1.Text+''' and txxh='+Query1.fieldbyname('txxh').AsString);
Query2.Open;
k:=Query2.RecordCount;
//循环抽取k道试题
for r:=1 to k do
begin
//选取满足条件的所有试题
//选取满足考核对象的试题
Query2.Close;
Query2.SQL.Clear;
qrystring0:='select stxh from stkdb where zyxh='
+inttostr(PMyList(MyList.Items[i])^.zyxh)
+' and gwlbxh='
+inttostr(PMyList(MyList.Items[i])^.gwlbxh)
+' and gwzlxh='
+inttostr(PMyList(MyList.Items[i])^.gwzlxh)
+' and khdxxh='
+inttostr(PMyList(MyList.Items[i])^.khdxxh)
+' and txxh='
+inttostr(Query1.fieldbyname('txxh').AsInteger);
Query2.SQL.Add(qrystring0);
Query2.Open;
if Query2.RecordCount=0 then//一个也没有
begin
tbl_sttx.Locate('txxh',Query1.fieldbyname('txxh').AsInteger,[]);
MessageBox(Handle,PAnsiChar('试题库中没有'
+PMyList(MyList.Items[i])^.khdxmc
+'的'+tbl_sttx.FieldByName('txmc').AsString+'!'),'试卷生成',MB_OK+MB_ICONEXCLAMATION);
progressfrm.SetFocus;
break;
end
else
if Query2.RecordCount<k then //题量是否够
begin
tbl_sttx.Locate('txxh',Query1.fieldbyname('txxh').AsInteger,[]);
MessageBox(Handle,PAnsiChar('试题库中'
+PMyList(MyList.Items[i])^.khdxmc
+'的'+tbl_sttx.FieldByName('txmc').AsString+'数量不够!'),'试卷生成',MB_OK+MB_ICONEXCLAMATION);
progressfrm.SetFocus;
break;
end;
//判断满足所有条件(考核对象、课目和重要程度)的试题个数是否够
//抽取满足所有条件(考核对象、课目和重要程度)的试题
qrystring:=qrystring0+' and zwcd=';
//确定抽取试题的重要程度。
ifzdt:=zycdarray[stcount];
if ifzdt then
zwcdstr:='true'
else
zwcdstr:='false';
qrystring:=qrystring+zwcdstr;
Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Add(qrystring);
Query2.Open;
if Query2.RecordCount<k then//没有或不够则更改重要程度
begin
qrystring:=qrystring0+' and zwcd=';
if ifzdt then
zwcdstr:='false'
else
zwcdstr:='true';
qrystring:=qrystring+zwcdstr;
Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Add(qrystring);
Query2.Open;
if Query2.RecordCount<k then//不够则更改重要程度
begin
qrystring:=qrystring0;
qrystring:=qrystring+zwcdstr;
Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Add(qrystring);
Query2.Open;
end;
end;
//根据试题个数,产生一个随机数,以确定抽取哪一个试题
ntemp:=1;
repeat //避免重题
nrecordno:=Random(Query2.RecordCount+1);
Query2.First;
Query2.MoveBy(nrecordno);
if not tbl_tmp_stlb.Locate('txxh;stxh',VarArrayOf([
Query1.fieldbyname('txxh').AsInteger,
Query2.fieldbyname('stxh').AsInteger]),
[]) then
break;
until ntemp=2;
//增加试题
tbl_tmp_stlb.Append;
tbl_tmp_stlb.FieldByName('txxh').AsInteger:=Query1.fieldbyname('txxh').AsInteger;
tbl_tmp_stlb.FieldByName('stxh').AsInteger:=Query2.fieldbyname('stxh').AsInteger;
tbl_tmp_stlb.Post;
stcount:=stcount+1;
Query2.Close;
end;//循环抽取k道试题结束
Query1.Next;
end;//试题题型循环结束
//生成试卷,若缺题则不生成试卷
if tbl_tmp_stlb.RecordCount=ntotal then
begin
//生成考试卷和答案卷
strfrom:= Pb_runpath+'\template\装备训练考核试卷.doc'+#0;
strto1:=Pb_runpath+'\temp\考试卷'+inttostr(j+1)+'.doc'+#0;
CopyDirectory(Handle,strfrom,strto1);
strfrom:= Pb_runpath+'\template\装备训练考核答案卷.doc'+#0;
strto2:=Pb_runpath+'\temp\答案卷'+inttostr(j+1)+'.doc'+#0;
CopyDirectory(Handle,strfrom,strto2);
try
wDoc1:=WordObject.OpenDoc(strto1);
except
if Assigned(WordObject) then
begin
WordObject.Free;
WordObject := nil;
end;
exit;
end;
try
wDoc2:=WordObject.OpenDoc(strto2);
except
if Assigned(WordObject) then
begin
WordObject.Free;
WordObject := nil;
end;
exit;
end;
//写考核对象名称
wDoc1.Activate;
wDoc1.Application.Selection.GoTo(-1,0,0,'khdxmc');
tbl_zy.Locate('zyxh',PMyList(MyList.Items[i])^.zyxh,[]);
wDoc1.Application.Selection.TypeText(tbl_zy.FieldByName('zymc').AsString
+#13
+PMyList(MyList.Items[i])^.khdxmc
+'考核试卷');
wDoc2.Activate;
wDoc2.Application.Selection.GoTo(-1,0,0,'khdxmc');
wDoc2.Application.Selection.TypeText(tbl_zy.FieldByName('zymc').AsString
+#13
+PMyList(MyList.Items[i])^.khdxmc
+'考核答案卷');
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('select distinct txxh from tmp_sjsc_stlb');
m:=1;
Query1.Open;
while not Query1.Eof do
begin
//写题型导语
Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Add('select sum(jf) as totalfs from sjscfanr where txxh='
+inttostr(Query1.fieldbyname('txxh').AsInteger)
+' and faname='''
+trim(ComboBox1.Text)+'''');
Query2.Open;
tbl_sttx.Locate('txxh',Query1.fieldbyname('txxh').AsInteger,[]);
wDoc1.Activate;
wDoc1.Application.Selection.EndKey(wdStory);
wDoc1.Application.Selection.Font.Bold := True;
wDoc1.Application.Selection.Font.Name := '宋体';
wDoc1.Application.Selection.Font.Size := 14;
tbl_sjscfanr.Locate('txxh',Query1.fieldbyname('txxh').AsInteger,[]);
if tbl_sjscfanr.fieldbyname('jf').AsInteger<>Query2.fieldbyname('totalfs').AsInteger then
begin
if Copy(tbl_sttx.FieldByName('txmc').AsString,1,4)='填空' then
wDoc1.Application.Selection.TypeText(txxhhz[m]+'、'+tbl_sttx.FieldByName('txmc').AsString+'(每题'
+inttostr(tbl_sjscfanr.fieldbyname('jf').AsInteger)+'分,共'
+inttostr(Query2.fieldbyname('totalfs').AsInteger)+'分)')
else
wDoc1.Application.Selection.TypeText(txxhhz[m]+'、'+tbl_sttx.FieldByName('txmc').AsString+'(每题'
+inttostr(tbl_sjscfanr.fieldbyname('jf').AsInteger)+'分,共'
+inttostr(Query2.fieldbyname('totalfs').AsInteger)+'分)');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -