|

楼主 |
发表于 2008-10-23 16:16:50
|
显示全部楼层
procedure TTaskCenterInfo.TaskUpdate(const TaskGUID: array of string);
var
S: string;
I: Integer;
Q: TSQLDataSet;
SaveReadOnly, SaveFiltered: Boolean;
begin
if not DataSetTaskIndex.Active then
Exit;
S := System.String.Join(''', ''', TaskGUID);
Q := TSQLDataSet.Create(Self);
try
Q.Database.URL := DataSetTaskIndex.Database.URL;
Q.SQL.Text := 'select * from TTASK where FGUID in (''' + S + ''')';
Q.SQLFilter := DataSetTaskIndex.SQLFilter;
Q.SQLFiltered := DataSetTaskIndex.SQLFiltered;
Q.UserFilter := DataSetTaskIndex.UserFilter;
Q.Open;
Q.Order := 'FGUID';
DataSetTaskIndex.DisableControls;
SaveReadOnly := DataSetTaskIndex.ReadOnly;
SaveFiltered := DataSetTaskIndex.Filtered;
try
DataSetTaskIndex.ReadOnly := False;
DataSetTaskIndex.Filtered := False;
DataSetTaskIndex.First;
for I := Low(TaskGUID) to High(TaskGUID) do
begin
S := TaskGUID[I];
if (FTask <> nil) and (FTask.GUID = S) then
FTask := nil;
if DataSetTaskIndex.Locate('FGUID', [S], []) then
if Q.FindKey([S]) then
begin
DataSetTaskIndex.Edit;
try
CopyFields(Q, DataSetTaskIndex);
DataSetTaskIndex.Post;
except
DataSetTaskIndex.Cancel;
raise;
end;
end
else
DataSetTaskIndex.Delete
else
if Q.FindKey([S]) then
begin
DataSetTaskIndex.Append;
try
CopyFields(Q, DataSetTaskIndex);
DataSetTaskIndex.Post;
except
DataSetTaskIndex.Cancel;
raise;
end;
end;
end;
finally
DataSetTaskIndex.Filtered := SaveFiltered;
DataSetTaskIndex.ReadOnly := SaveReadOnly;
DataSetTaskIndex.EnableControls;
end;
finally
Q.Free;
end;
end;
请解释一下这段话是啥意思,DataSetTaskIndex与Q的数据不是一样吗?为什么要再Copy一次,然后再Post呢?这个有更新到数据库里吗?如果有,我想改成用Sql来写,可以吗? |
|