5,388
社区成员
发帖
与我相关
我的任务
分享
procedure TForm1.downListAndUpload();
var
i: Integer;
j: Integer;
begin
ListView1.Clear();
Panel2.Visible := false;
//下载FTP上的文件列表
if not FileExists(ExtractFilePath(Paramstr(0)) + userName + '.txt') then
begin
FtpLibrary1.localpath := ExtractFilePath(Paramstr(0)) + userName + '.txt';
FtpLibrary1.remotepath := userName + '.txt';
if FtpLibrary1.ExistFile(userName + '.txt') then
begin
if FtpLibrary1.Download() then
FtpLibrary1.DeleteFile(userName + '.txt');
end
else
begin
if CheckBox3.Checked = true then
//自动关机
ShutDown();
end;
end;
//列表存在 解析文件列表 加入listview
if FileExists(ExtractFilePath(Paramstr(0)) + userName + '.txt') then
begin
mystring := TStringlist.Create;
mystring.LoadFromFile(ExtractFilePath(Paramstr(0)) + userName + '.txt');
list := TStringlist.Create;
ExtractStrings(['|'], [], Pchar(mystring.text), list);
mystring.Free;
//增加
for i := 0 to list.Count - 1 do
begin
sub := TStringlist.Create;
ExtractStrings(['$'], [], Pchar(list[i]), sub);
ListItem := ListView1.Items.Add;
ListItem.Caption := StringReplace(sub[0], ' ', '', [rfReplaceAll]); //添加标题
ListItem.SubItems.Add(inttostr(i));
sub.Free;
end;
FtpLibrary1.Encoding := 'UTF8';
FtpLibrary1.ReplaceSetting := 2;
isUpdating := true;
//上传到服务器
for i := 0 to list.Count - 1 do
begin
sub := TStringlist.Create;
ExtractStrings(['$'], [], Pchar(list[i]), sub);
FtpLibrary1.localpath := sub[0];
tempWide := sub[0];
tempWide := ExtractFileName(tempWide);
FtpLibrary1.remotepath := string(tempWide);
if FtpLibrary1.Upload() then
begin
url := baseUrl+'/clientlogin!updateOrdersByFileName?orderCode='
+ sub[1];
Idhttp1.HandleRedirects := true; //必须支持重定向否则可能出错
Idhttp1.ReadTimeout := 5000; //超过这个时间则不再访问
try
s := Idhttp1.Get(url);
except
url := baseUrl1+'/clientlogin!updateOrdersByFileName?orderCode='
+ sub[1];
try
s := Idhttp1.Get(url);
except
s := 'fail';
end;
end;
for j := 0 to listview1.Items.Count - 1 do
begin
if SameText(ListView1.Items[j].Caption,sub[0]) then
begin
ListView1.Items.Delete(j);
Break;
end;
end
end
else
begin
for j := 0 to listview1.Items.Count - 1 do
begin
if SameText(ListView1.Items[j].Caption,sub[0]) then
ListView1.Items.Delete(j);
Break;
end;
end;
end;
list.Free;
sub.Free;
isUpdating := false;
Panel2.Visible := true;
//上传完删除文件列表
sleep(1000);
DeleteFile(ExtractFilePath(Paramstr(0)) + userName + '.txt');
end;
Timer1.Enabled := true;
end;
for j := listview1.Items.Count - 1 downto 0
for j := 0 to listview1.Items.Count - 1 do//应改为for j := listview1.Items.Count - 1 to 0
begin
if SameText(ListView1.Items[j].Caption,sub[0]) then
ListView1.Items.Delete(j);
Break;
end;