for l:=1 to cycle do //这里出错,如果cycle是3,当l:=4时
begin
setlength(tempstr,cycle*num);
j:=0;
ssql:='insert into sc_route_shift values(:tename,:grname,:shname';
si:=0;
while j<n do
begin
if si<cycle*num then
begin
ynum:=0;
nnum:=0;
ypos:=0;
npos:=0;
if shift_array[j]=l then
begin
sc.comp_ADOQuery1.Active:=false;
sc.comp_ADOQuery1.SQL.Clear;
sc.comp_ADOQuery1.SQL.Add('select route_train1,route_train2,start_time1,arrive_time1,');
sc.comp_ADOQuery1.SQL.Add('start_time2,arrive_time2 from sc_little_route');
sc.comp_ADOQuery1.SQL.Add('where route_id=:routeid');
sc.comp_ADOQuery1.Parameters.ParamByName('routeid').value:=route_array[j];
sc.comp_ADOQuery1.Active:=true;
for k:=0 to 5 do
string_array[k]:=sc.comp_ADOQuery1.Fields.Fields[k].Text;
for k:=2 to 5 do
begin
ypos:=pos('Y',string_array[k]);
npos:=pos('N',string_array[k]);
if ypos<>0 then
ynum:=ynum+1;
if npos<>0 then
nnum:=nnum+1;
end;
if ynum=2 then
begin
si:=day[j]-1;
tempstr[si]:=copy(string_array[0],0,4);
tempstr[si+1]:=copy(string_array[1],0,4);
j:=j+3;
end
else if ynum=1 then
begin
si:=day[j]-1;
tempstr[si]:=copy(string_array[0],0,4)+'/'+copy(string_array[1],0,4);
j:=j+1;
end
else if nnum=1 then
begin
si:=day[j]-1;
tempstr[si]:=copy(string_array[0],0,4)+'/'+copy(string_array[1],0,4);
if si=cycle*num-1 then
tempstr[0]:='到'
else
tempstr[si+1]:='到';
j:=j+2;
end
else
begin
si:=day[j];
tempstr[si]:=copy(string_array[0],0,4)+'/'+copy(string_array[1],0,4);
j:=j+1;
end;
end
else
j:=j+1;
end
else
break;
end;
for j:=0 to cycle*num-1 do
begin
if tempstr[j]='' then
tempstr[j]:='休息';
end;
for j:=0 to 15 do
begin
if j<cycle*num then
ssql:=ssql+','+''''+tempstr[j]+''''
else
ssql:=ssql+','+'''''';
end;
ssql:=ssql+')';
sc.comp_ADOQuery1.Active:=false;
sc.comp_ADOQuery1.SQL.Clear;
sc.comp_ADOQuery1.SQL.Add(ssql);
sc.comp_ADOQuery1.Parameters.ParamByName('tename').value:=teamname;
sc.comp_ADOQuery1.Parameters.ParamByName('grname').value:=groupname;
sc.comp_ADOQuery1.Parameters.ParamByName('shname').value:=inttostr(l);
sc.comp_ADOQuery1.ExecSQL;
ssql:='';
setlength(tempstr,0);
end;