394 lines
9.5 KiB
ObjectPascal
394 lines
9.5 KiB
ObjectPascal
unit U_FjList;
|
||
|
||
interface
|
||
|
||
uses
|
||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||
Dialogs, ExtCtrls, ComCtrls, Menus, cxLookAndFeelPainters, StdCtrls,
|
||
cxButtons, DB, ADODB, ImgList,shellapi, IdBaseComponent, IdComponent,
|
||
IdTCPConnection, IdTCPClient, IdFTP,strutils;
|
||
|
||
type
|
||
TfrmFjList = class(TForm)
|
||
ListView1: TListView;
|
||
Panel1: TPanel;
|
||
FileName: TcxButton;
|
||
cxButton1: TcxButton;
|
||
cxButton2: TcxButton;
|
||
cxButton3: TcxButton;
|
||
ADOQueryTmp: TADOQuery;
|
||
ADOQueryCmd: TADOQuery;
|
||
ImageList1: TImageList;
|
||
Panel2: TPanel;
|
||
IdFTP1: TIdFTP;
|
||
ADOConnection1: TADOConnection;
|
||
procedure cxButton3Click(Sender: TObject);
|
||
procedure FormDestroy(Sender: TObject);
|
||
procedure FileNameClick(Sender: TObject);
|
||
procedure FormCreate(Sender: TObject);
|
||
procedure FormShow(Sender: TObject);
|
||
procedure ListView1DblClick(Sender: TObject);
|
||
procedure cxButton1Click(Sender: TObject);
|
||
procedure cxButton2Click(Sender: TObject);
|
||
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
||
procedure Panel2DblClick(Sender: TObject);
|
||
private
|
||
procedure InitData();
|
||
{ Private declarations }
|
||
public
|
||
fkeyNO:string;
|
||
fType:string;
|
||
fId:integer;
|
||
|
||
fstatus:integer;
|
||
|
||
{ Public declarations }
|
||
end;
|
||
|
||
var
|
||
frmFjList: TfrmFjList;
|
||
|
||
implementation
|
||
uses
|
||
U_DataLink,U_Fun10;
|
||
{$R *.dfm}
|
||
procedure TfrmFjList.InitData();
|
||
var
|
||
ListItem: TListItem;
|
||
Flag: Cardinal;
|
||
info: SHFILEINFOA;
|
||
Icon: TIcon;
|
||
begin
|
||
ListView1.Items.Clear;
|
||
try
|
||
|
||
with adoqueryTmp do
|
||
begin
|
||
close;
|
||
sql.Clear;
|
||
sql.Add('select fileName from TP_File ');
|
||
sql.Add('where WBID='+quotedstr(trim(fkeyNO)));
|
||
sql.Add('and TFType='+quotedstr(trim(fType)));
|
||
open;
|
||
if not IsEmpty then
|
||
begin
|
||
while not eof do
|
||
begin
|
||
with ListView1 do
|
||
begin
|
||
LargeImages := ImageList1;
|
||
Icon := TIcon.Create;
|
||
ListItem := Items.Add;
|
||
Listitem.Caption := trim(fieldbyname('fileName').AsString);
|
||
// Listitem.SubItems.Add(OpenDiaLog.FileName);
|
||
Flag := (SHGFI_SMALLICON or SHGFI_ICON or SHGFI_USEFILEATTRIBUTES);
|
||
SHGetFileInfo(Pchar(trim(fieldbyname('fileName').AsString)), 0, info, Sizeof(info), Flag);
|
||
Icon.Handle := info.hIcon;
|
||
ImageList1.AddIcon(Icon);
|
||
ListItem.ImageIndex := ImageList1.Count - 1;
|
||
end;
|
||
next;
|
||
end;
|
||
end;
|
||
end;
|
||
except
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmFjList.cxButton3Click(Sender: TObject);
|
||
begin
|
||
ADOQueryTmp.Close;
|
||
ADOQuerycmd.Close;
|
||
ListView1.Items.Free;
|
||
ModalResult:=-1;
|
||
end;
|
||
|
||
procedure TfrmFjList.FormDestroy(Sender: TObject);
|
||
begin
|
||
frmFjList:=nil;
|
||
end;
|
||
|
||
procedure TfrmFjList.FileNameClick(Sender: TObject);
|
||
var
|
||
OpenDiaLog: TOpenDialog;
|
||
fFileName:string;
|
||
fFilePath:string;
|
||
maxNo:string;
|
||
// myStream: TADOBlobStream;
|
||
// FJStream : TMemoryStream;
|
||
begin
|
||
|
||
try
|
||
OpenDiaLog := TOpenDialog.Create(Self);
|
||
if OpenDiaLog.Execute then
|
||
begin
|
||
fFilePath:=OpenDiaLog.FileName;
|
||
fFileName:=ExtractFileName(OpenDiaLog.FileName);
|
||
|
||
|
||
with adoqueryCmd do
|
||
begin
|
||
close;
|
||
sql.Clear;
|
||
sql.Add('select TFId from TP_File ');
|
||
sql.Add('where WBID<>'+quotedstr(trim(fkeyNO)));
|
||
sql.Add('and TFType='+quotedstr(trim(fType)));
|
||
sql.Add('and FileName='+quotedstr(trim(fFileName)));
|
||
open;
|
||
IF not adoqueryCmd.IsEmpty then
|
||
begin
|
||
application.MessageBox('<27>˸<EFBFBD><CBB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><D1B4>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><DEB8>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD>','<27><>ʾ<EFBFBD><CABE>Ϣ',MB_ICONERROR);
|
||
exit;
|
||
end;
|
||
end;
|
||
|
||
Panel2.Caption:='<27><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD>Ե<EFBFBD>...';
|
||
Panel2.Visible:=true;
|
||
application.ProcessMessages;
|
||
|
||
if GetLSNo(ADOQueryCmd,maxNo,'FJ','TP_File',4,1)=False then
|
||
begin
|
||
Application.MessageBox('ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>','<27><>ʾ',0);
|
||
Exit;
|
||
end;
|
||
|
||
adoqueryCmd.Connection.BeginTrans;
|
||
|
||
|
||
with adoqueryCmd do
|
||
begin
|
||
close;
|
||
sql.Clear;
|
||
sql.Add('delete from TP_File ');
|
||
sql.Add('where WBID='+quotedstr(trim(fkeyNO)));
|
||
sql.Add('and TFType='+quotedstr(trim(fType)));
|
||
sql.Add('and FileName='+quotedstr(trim(fFileName)));
|
||
execsql;
|
||
end;
|
||
|
||
try
|
||
with adoqueryCmd do
|
||
begin
|
||
close;
|
||
sql.Clear;
|
||
sql.Add('select * from TP_File ');
|
||
sql.Add('where WBID='+quotedstr(trim(fkeyNO)));
|
||
sql.Add('and TFType='+quotedstr(trim(fType)));
|
||
sql.Add('and FileName='+quotedstr(trim(fFileName)));
|
||
open;
|
||
append;
|
||
fieldbyname('TFID').Value:=trim(maxNO);
|
||
fieldbyname('WBID').Value:=trim(fkeyNO);
|
||
fieldbyname('TFType').Value:=trim(fType);
|
||
fieldbyname('FileName').Value:=trim(fFileName);
|
||
// tblobfield(FieldByName('Filesother')).LoadFromFile(fFilePath);
|
||
post;
|
||
end;
|
||
|
||
if fFilePath <> '' then
|
||
begin
|
||
try
|
||
IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI','SERVER','FTP<54><50>ַ','127.0.0.1');
|
||
IdFTP1.Username := 'three';
|
||
IdFTP1.Password := '641010';
|
||
IdFTP1.Connect();
|
||
IdFTP1.Put(fFilePath, 'FJ\' + Trim(fFileName));
|
||
IdFTP1.Quit;
|
||
except
|
||
IdFTP1.Quit;
|
||
Application.MessageBox('<27>ϴ<EFBFBD><CFB4>ͻ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ', MB_ICONWARNING);
|
||
end;
|
||
end;
|
||
IdFTP1.Quit;
|
||
|
||
Panel2.Visible:=false;
|
||
initdata();
|
||
finally
|
||
// FJStream.Free;
|
||
end;
|
||
|
||
end;
|
||
adoqueryCmd.Connection.CommitTrans;
|
||
except
|
||
adoqueryCmd.Connection.RollbackTrans;
|
||
application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>','<27><>ʾ<EFBFBD><CABE>Ϣ',0);
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmFjList.FormCreate(Sender: TObject);
|
||
begin
|
||
with ADOConnection1 do
|
||
begin
|
||
Connected:=false;
|
||
ConnectionString:=DConString;
|
||
//ConnectionString:='';
|
||
Connected:=true;
|
||
end;
|
||
ListView1.Align:=alclient;
|
||
fstatus:=0;
|
||
end;
|
||
|
||
procedure TfrmFjList.FormShow(Sender: TObject);
|
||
begin
|
||
IF fstatus=0 then Panel1.Visible:=true
|
||
else Panel1.Visible:=false;
|
||
initdata();
|
||
end;
|
||
|
||
procedure TfrmFjList.ListView1DblClick(Sender: TObject);
|
||
var
|
||
sFieldName:string;
|
||
fileName:string;
|
||
begin
|
||
if ListView1.Items.Count<1 THEN EXIT;
|
||
|
||
if listView1.SelCount<1 then exit;
|
||
sFieldName:=leftbstr(ExtractFilePath(Application.ExeName),1)+':\ͼƬ<CDBC>鿴';
|
||
|
||
if not DirectoryExists(pchar(sFieldName)) then
|
||
CreateDirectory(pchar(sFieldName),nil);
|
||
|
||
fileName:=ListView1.Selected.Caption;
|
||
|
||
sFieldName:=sFieldName+'\'+trim(fileName);
|
||
|
||
try
|
||
IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI','SERVER','FTP<54><50>ַ','127.0.0.1');
|
||
IdFTP1.Username := 'three';
|
||
IdFTP1.Password := '641010';
|
||
IdFTP1.Connect();
|
||
except
|
||
;
|
||
end;
|
||
|
||
if IdFTP1.Connected then
|
||
begin
|
||
|
||
Panel2.Caption:='<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD>Ե<EFBFBD>...';
|
||
Panel2.Visible:=true;
|
||
application.ProcessMessages;
|
||
try
|
||
IdFTP1.Get('FJ\'+ Trim(fileName), sFieldName,true, false);
|
||
except
|
||
Panel2.Visible:=false;
|
||
Application.MessageBox('<27>ͻ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ', MB_ICONWARNING);
|
||
IdFTP1.Quit;
|
||
Exit;
|
||
end;
|
||
end
|
||
else
|
||
begin
|
||
Panel2.Visible:=false;
|
||
Application.MessageBox('<27><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ', MB_ICONWARNING);
|
||
IdFTP1.Quit;
|
||
Exit;
|
||
end;
|
||
Panel2.Visible:=false;
|
||
if IdFTP1.Connected then IdFTP1.Quit;
|
||
ShellExecute(Handle, 'open',PChar(sFieldName),'', '', SW_SHOWNORMAL);
|
||
|
||
end;
|
||
|
||
procedure TfrmFjList.cxButton1Click(Sender: TObject);
|
||
var
|
||
fFileName:string;
|
||
fFilePath:string;
|
||
begin
|
||
if listView1.SelCount<1 then exit;
|
||
|
||
try
|
||
fFileName:=ListView1.Selected.Caption;
|
||
// ADOQueryTmp.Locate('fileName',fFileName,[]);
|
||
|
||
with ADOQueryCmd do
|
||
begin
|
||
close;
|
||
sql.Clear;
|
||
sql.Add('delete from TP_File ');
|
||
sql.Add('where WBID='+quotedstr(trim(fkeyNO)));
|
||
sql.Add('and TFType='+quotedstr(trim(fType)));
|
||
sql.Add('and FileName='+quotedstr(trim(fFileName)));
|
||
execsql;
|
||
end;
|
||
|
||
initData();
|
||
|
||
except
|
||
end;
|
||
|
||
end;
|
||
|
||
procedure TfrmFjList.cxButton2Click(Sender: TObject);
|
||
var
|
||
SaveDialog: TSaveDialog;
|
||
fFileName:string;
|
||
fFilePath:string;
|
||
begin
|
||
if listView1.SelCount<1 then exit;
|
||
|
||
try
|
||
|
||
fFileName:=ListView1.Selected.Caption;
|
||
|
||
SaveDialog := TSaveDialog.Create(Self);
|
||
|
||
SaveDialog.FileName:=fFileName;
|
||
if SaveDialog.Execute then
|
||
begin
|
||
Panel2.Caption:='<27><><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD>Ե<EFBFBD>...';
|
||
Panel2.Visible:=true;
|
||
application.ProcessMessages;
|
||
fFilePath:=SaveDialog.FileName;
|
||
try
|
||
IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI','SERVER','FTP<54><50>ַ','127.0.0.1');;
|
||
IdFTP1.Username := 'three';
|
||
IdFTP1.Password := '641010';
|
||
IdFTP1.Connect();
|
||
except
|
||
;
|
||
end;
|
||
|
||
if IdFTP1.Connected then
|
||
begin
|
||
|
||
Panel2.Caption:='<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD>Ե<EFBFBD>...';
|
||
Panel2.Visible:=true;
|
||
application.ProcessMessages;
|
||
try
|
||
IdFTP1.Get('FJ\'+ Trim(fFileName), fFilePath,false, true);
|
||
except
|
||
Panel2.Visible:=false;
|
||
Application.MessageBox('<27>ͻ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ', MB_ICONWARNING);
|
||
IdFTP1.Quit;
|
||
Exit;
|
||
end;
|
||
end
|
||
else
|
||
begin
|
||
Panel2.Visible:=false;
|
||
Application.MessageBox('<27><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ', MB_ICONWARNING);
|
||
IdFTP1.Quit;
|
||
Exit;
|
||
end;
|
||
Panel2.Visible:=false;
|
||
if IdFTP1.Connected then IdFTP1.Quit;
|
||
end;
|
||
except
|
||
Panel2.Visible:=false;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmFjList.FormClose(Sender: TObject; var Action: TCloseAction);
|
||
begin
|
||
if fId=10 then Action:=cafree
|
||
else
|
||
Action:=cahide;
|
||
end;
|
||
|
||
procedure TfrmFjList.Panel2DblClick(Sender: TObject);
|
||
begin
|
||
Panel2.Visible:=false;
|
||
end;
|
||
|
||
end.
|