www.pudn.com > Desktop-Manager.rar > Unit8.pas, change:2004-07-30,size:4161b


unit Unit8; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, ExtCtrls, StdCtrls, FileCtrl,JPEG, ComCtrls; 
 
type 
  TSaveManyPicDlg = class(TForm) 
    Panel1: TPanel; 
    Panel2: TPanel; 
    Panel3: TPanel; 
    Panel4: TPanel; 
    Panel5: TPanel; 
    DriveComboBox1: TDriveComboBox; 
    DirectoryListBox1: TDirectoryListBox; 
    Label1: TLabel; 
    Button1: TButton; 
    Button2: TButton; 
    Button3: TButton; 
    RadioGroup1: TRadioGroup; 
    RadioButton1: TRadioButton; 
    RadioButton2: TRadioButton; 
    Edit1: TEdit; 
    ProgressBar1: TProgressBar; 
    procedure Button3Click(Sender: TObject); 
    procedure Button2Click(Sender: TObject); 
    procedure RadioButton2Click(Sender: TObject); 
    procedure RadioButton1Click(Sender: TObject); 
    procedure Button1Click(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 
 
var 
  SaveManyPicDlg: TSaveManyPicDlg; 
 
implementation 
Uses Unit1,unit9; 
{$R *.dfm} 
 
procedure TSaveManyPicDlg.Button3Click(Sender: TObject); 
begin 
  close; 
end; 
 
procedure TSaveManyPicDlg.Button2Click(Sender: TObject); 
var 
  JPEG:TJPEGImage; 
  I :integer; 
  SaveFileName:string; 
begin 
  //考虑加入进度条 
  if Form1.DataSource1.DataSet.FieldByName('picture').IsNull=false then 
  begin 
    JPEG:=TJPEGImage.Create; 
    try 
      Form1.ADOQuery1.First; //移动到第一条记录 
      if Radiobutton1.Checked=true then //当选择用数据库中的文件名保存时执行 
      begin 
      //-------------------------------------------------------------- 
      //--设置进度条参数 
        ProgressBar1.Min:=1; 
        ProgressBar1.Max:=Form1.DataSource1.DataSet.RecordCount; 
        ProgressBar1.Step:=1; 
      //-------------------------------------------------------------- 
 
        for I:=1 to  Form1.DataSource1.DataSet.RecordCount do 
        begin 
          ProgressBar1.StepIt;//进度条动画 
 
          //判断若保存的文件名已经被使用,则换一个文件名 
          SaveFileName:=DirectoryListBox1.Directory+'\'+Form1.DBText1.Caption+'.jpg'; 
          if FileExists(SaveFileName) then 
            SaveFileName:=DirectoryListBox1.Directory+'\'+Form1.DBText1.Caption+IntToStr(I)+'.jpg'; 
 
          JPEG.Assign(Form1.DataSource1.DataSet.FieldByName('picture')); 
          JPEG.SaveToFile(SaveFileName); 
          Form1.DataSource1.DataSet.Next; 
        end; 
        ProgressBar1.Visible:=false;//导出完毕后隐藏进度条 
        ShowMessage('导出完毕!'); 
        close; 
      end; 
      if Radiobutton2.Checked=true then //当选择统一命名保存时执行 
      begin 
      //-------------------------------------------------------------- 
      //--设置进度条参数 
        ProgressBar1.Min:=1; 
        ProgressBar1.Max:=Form1.DataSource1.DataSet.RecordCount; 
        ProgressBar1.Step:=1; 
      //-------------------------------------------------------------- 
 
        for I:=1 to  Form1.DataSource1.DataSet.RecordCount do 
        begin 
          ProgressBar1.StepIt;//进度条动画 
 
          JPEG.Assign(Form1.DataSource1.DataSet.FieldByName('picture')); 
                                                          //在公用名后加上数字做为文件名 
          JPEG.SaveToFile(DirectoryListBox1.Directory+'\'+Edit1.Text+IntToStr(I)+'.jpg'); 
          Form1.DataSource1.DataSet.Next; 
        end; 
        ProgressBar1.Visible:=false;//导出完毕后隐藏进度条 
        ShowMessage('导出完毕!'); 
        close;         
      end; 
    finally 
      JPEG.Free; 
    end; 
   end; 
  close; 
 
end; 
 
procedure TSaveManyPicDlg.RadioButton2Click(Sender: TObject); 
begin 
  Edit1.Enabled:=true; 
  Edit1.Color:=clWindow; 
  Edit1.SetFocus; 
end; 
 
procedure TSaveManyPicDlg.RadioButton1Click(Sender: TObject); 
begin 
  Edit1.Enabled:=false; 
  Edit1.Color:=cl3DLight; 
end; 
 
procedure TSaveManyPicDlg.Button1Click(Sender: TObject); 
begin 
  InputDirDlg:=TInputDirDlg.Create(nil); 
  InputDirDlg.Top:=SaveManyPicDlg.Top+SaveManyPicDlg.Height-130; 
  InputDirDlg.Left:=SaveManyPicDlg.Left; 
  InputDirDlg.ShowModal; 
  InputDirDlg.Free; 
end; 
 
end. 
 
//进度:准备创建新建文件夹