PageRenderTime 16ms CodeModel.GetById 12ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

/Gedemin/Messaging/msg_dlgOpenAttachment.pas

http://gedemin.googlecode.com/
Pascal | 108 lines | 90 code | 16 blank | 2 comment | 4 complexity | 3453228e6cfec205baac0e4399405b06 MD5 | raw file
  1unit msg_dlgOpenAttachment;
  2
  3interface
  4
  5uses
  6  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7  StdCtrls, ExtCtrls, Db, IBCustomDataSet, gdcBase, gdcMessage, gd_createable_form;
  8
  9type
 10  Tfrm_msgOpenAttachment = class(TCreateableForm)
 11    Bevel1: TBevel;
 12    Image1: TImage;
 13    lblOpen: TLabel;
 14    lblFileName: TLabel;
 15    btnOk: TButton;
 16    btnCancel: TButton;
 17    rbOpen: TRadioButton;
 18    rbSave: TRadioButton;
 19    lblQuetion: TLabel;
 20    lblAttention1: TLabel;
 21    lblAttencion2: TLabel;
 22    Label1: TLabel;
 23    lblAttention3: TLabel;
 24    gdcAttachmentOpen: TgdcAttachment;
 25    msgOpenDataSource: TDataSource;
 26    SaveDialogAttachment: TSaveDialog;
 27    procedure rbSaveClick(Sender: TObject);
 28    procedure rbOpenClick(Sender: TObject);
 29    procedure btnCancelClick(Sender: TObject);
 30    procedure btnOkClick(Sender: TObject);
 31    procedure FormCreate(Sender: TObject);
 32  private
 33    FFileName: String;
 34    { Private declarations }
 35  public
 36    constructor CreateDialog(AOwner: TComponent; AFileName: String);
 37  end;
 38
 39var
 40  frm_msgOpenAttachment: Tfrm_msgOpenAttachment;
 41
 42implementation
 43
 44uses
 45  msg_frmmain,                  msg_attachment;
 46
 47{$R *.DFM}
 48
 49procedure Tfrm_msgOpenAttachment.rbSaveClick(Sender: TObject);
 50begin
 51  rbOpen.Checked := not rbSave.Checked;
 52end;
 53
 54procedure Tfrm_msgOpenAttachment.rbOpenClick(Sender: TObject);
 55begin
 56  rbSave.Checked := not rbOpen.Checked;
 57end;
 58
 59procedure Tfrm_msgOpenAttachment.btnCancelClick(Sender: TObject);
 60begin
 61  ModalResult := mrCancel;
 62  Close;
 63end;
 64
 65procedure Tfrm_msgOpenAttachment.btnOkClick(Sender: TObject);
 66begin
 67  if rbOpen.Checked then
 68    gdcAttachmentOpen.OpenAttachment
 69  else
 70    begin
 71      SaveDialogAttachment.FileName :=  GetCurrentDir;
 72      if copy(SaveDialogAttachment.FileName, Length(SaveDialogAttachment.FileName), 1) = '\' then
 73        SaveDialogAttachment.FileName := SaveDialogAttachment.FileName + FFileName
 74      else
 75        SaveDialogAttachment.FileName := SaveDialogAttachment.FileName +
 76          '\' + FFileName;
 77      if SaveDialogAttachment.Execute then
 78        attSaveToFile(SaveDialogAttachment.FileName,
 79        gdcAttachmentOpen.FieldByName('bdata').AsString);
 80    end;
 81  ModalResult := mrOk;
 82  Close;
 83end;
 84
 85procedure Tfrm_msgOpenAttachment.FormCreate(Sender: TObject);
 86begin
 87  with msg_mainform do
 88    begin
 89      gdcAttachmentOpen.Transaction := IBTransaction;
 90      msgOpenDataSource.DataSet := ibqMessage;
 91      gdcAttachmentOpen.Open;
 92      gdcAttachmentOpen.Locate('FileName', FFileName, [loCaseInsensitive]);
 93    end;
 94  lblFileName.Caption := FFileName; 
 95end;
 96
 97constructor Tfrm_msgOpenAttachment.CreateDialog(AOwner: TComponent;
 98  AFileName: String);
 99begin
100  inherited Create(AOwner);
101
102  FFileName := AFileName;
103  if Pos('&', FFileName) > 0 then
104      Delete(FFileName, Pos('&', FFileName), 1);
105
106end;
107
108end.