unit OperateUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
InitialUnit, ComCtrls;
type
TFormType = (Initial,Query,AddNewUser,RemoveOldUser,SetPassword);
TOperateType = (lzSort,lzSearch,lzFindAndSave,lzDelete);
TFileOptions = Record
flName,flAttribution,flPath:String;
flSize,flFileNO:Integer;
End;
TOperateForm = class(TForm)
InitialFrame: TInitialFrame;
procedure InitialFrameOKClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
FormType: TFormType;
end;
TFindFile =class(TObject)
Private
FFileNO,FCDNO:Integer;
FSaveTime,FCDName:String;
FileOptions:TFileOptions;
Procedure FindFile;
Procedure WriteTable;
Public
Constructor Create(FindPath,CDName:String);
End;
TOperate = class(TObject)
Private
FindFile:TFindFile;
Public
Constructor Create(OperateType:TOperateType;FileName,FindPath:String);
End;
var
OperateForm: TOperateForm;
implementation
uses DataModule;
{$R *.DFM}
{FindFile}
{Create}
constructor TFindFile.Create(FindPath,CDName: String);
var
DateTime:TSystemTime;
begin
Inherited Create;
GetSystemTime(DateTime);
FSaveTime:=IntToStr(DateTime.wYear)+'-'+IntToStr(DateTime.wMonth)+'-'+IntToStr(DateTime.wDay);
//运行到上面一句就出错,不知为什么?
if FileDataModule.CDNOTable.RecordCount=0 then
begin
FileDataModule.CDTable.Last;
FCDNO:=FileDataModule.CDTable.FieldByName('光盘编号').AsInteger+1;
end
else
begin
FileDataModule.CDNOTable.First;
FCDNO:=FileDataModule.CDNOTable.FieldByName('光盘编号').AsInteger;
FileDataModule.CDNOTable.Delete;
end;
FCDName:=CDName;
With FileDataModule.CDTable Do
Begin
Append;
FieldByName('光盘编号').AsInteger:=FCDNO;
FieldByName('光盘名称').AsString:=FCDName;
FieldByName('光盘简介').AsString:=OperateForm.InitialFrame.IntorductionMemo.Text;
FieldByName('保存时间').AsDateTime:=StrToDateTime(FSaveTime);
End;
FileDataModule.FileTable.Last;
FFileNO:=FileDataModule.FileTable.FieldByName('文件编号').Asinteger+1;
FileOptions.flPath:=FindPath;
ChDir(FileOptions.flPath);
FindFile;
end;
procedure TFindFile.FindFile;
var
SearchRec: TSearchRec;
err:integer;
begin
try
err:=FindFirst('*.*',faAnyFile, SearchRec);
while err = 0 do
begin
Application.ProcessMessages;
if SearchRec.Name[1]<>'.' then
begin
if SearchRec.Attr = fadirectory then
begin
FileOptions.flPath:=LowerCase(ExtractFileName(SearchRec.Name));
FileOptions.flName:=LowerCase(SearchRec.Name);
FileOptions.flFileNO:=FFileNO;
FileOptions.flSize:=0;//SearchRec.Size;
FileOptions.flAttribution:='文件夹';
WriteTable;
FFileNO:=FFileNO+1;
try
ChDir(SearchRec.Name);
FindFile;
ChDir('..')
except
exit;
end;
End
else
begin
FileOptions.flPath:=LowerCase(ExpandFileName(SearchRec.Name));
FileOptions.flName:=LowerCase(SearchRec.Name);
FileOptions.flFileNO:=FFileNO;
FileOptions.flSize:=SearchRec.Size;
FileOptions.flAttribution:=LowerCase(ExtractFileExt(SearchRec.Name));
WriteTable;
FFileNO:=FFileNO+1;
end;
end;
err:= FindNext(SearchRec);
end;
finally
FindClose(SearchRec);
end;
end;
{
//GetPath
function TFindFile.GetPath(Path: String): String;
Var
Size,j:Integer;
NewPath:String;
begin
for Size:=Length(Path) DownTo 1 do
Begin
if Path[Size]='/' then
Begin
Setlength(NewPath,Size);
for j:=1 to Size do NewPath[j]:=Path[j];
Result:=NewPath;
Exit;
End;
End;
end;
}
{WriteTable}
procedure TFindFile.WriteTable;
begin
FileDataModule.FileTable.Append;
FileDataModule.FileTable.FieldByName('文件编号').AsInteger:=FileOptions.flFileNO;
FileDataModule.FileTable.FieldByName('文件名称').AsString:=FileOptions.flName;
FileDataModule.FileTable.FieldByName('光盘编号').AsInteger:=FCDNO;
// FileDataModule.FileTable.FieldByName('存入时间').AsDateTime:=StrToDateTime(FSaveTime);
FileDataModule.FileTable.FieldByName('文件类型').AsString:=FileOptions.flAttribution;
FileDataModule.FileTable.FieldByName('文件大小').AsInteger:=FileOptions.flSize;
// FileDataModule.FileTable.FieldByName('光盘名称').AsString:=lowercase(Form3.Edit1.Text);
FileDataModule.FileTable.FieldByName('所属文件夹').AsString:=FileOptions.flPath;
FileDataModule.FileTable.Post;
end;
{ TOperate }
{Create}
constructor TOperate.Create(OperateType: TOperateType
FileName,
FindPath: String);
begin
Inherited Create;
Case OperateType Of
lzSort:Begin
End;
lzSearch:Begin
End;
lzFindAndSave: FindFile.Create(FindPath,FileName);
lzDelete:Begin
End;
End;
end;
end.
我将原码贴上来了,还请各位打下多多帮忙。
(再加100分)