unit uViewEmpresa;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewBase, ExtCtrls, StdCtrls, Buttons, DB, uDADataTable,
  DBCtrls, Grids, DBGrids, uBizEmpresas, Mask, ComCtrls, uCustomView,
  JvComponent, JvFormAutoSize, cxControls, cxContainer, cxEdit, cxTextEdit,
  cxDBEdit, dxLayoutControl, dxLayoutLookAndFeels, cxMemo, cxMaskEdit,
  cxSpinEdit, cxImage, JvExControls, JvBitmapButton, ActnList, ImgList,
  PngImageList, TB2Item, TBX, TB2Dock, TB2Toolbar, PngSpeedButton;

type
  IViewEmpresa = interface(IViewBase)
    ['{876DCEBD-9E92-491A-84CE-498B1A84B525}']
    function GetEmpresa: IBizEmpresa;
    procedure SetEmpresa(const Value: IBizEmpresa);
    property Empresa: IBizEmpresa read GetEmpresa write SetEmpresa;
  end;
  
  TfrViewEmpresa = class(TfrViewBase, IViewEmpresa)
    DADataSource: TDADataSource;
    dxLayoutControl1Group_Root: TdxLayoutGroup;
    dxLayoutControl1: TdxLayoutControl;
    dxLayoutControl1Group1: TdxLayoutGroup;
    dxLayoutControl1Group2: TdxLayoutGroup;
    dxLayoutControl1Group3: TdxLayoutGroup;
    dxLayoutControl1Group4: TdxLayoutGroup;
    dxLayoutControl1Group5: TdxLayoutGroup;
    dxLayoutControl1Group6: TdxLayoutGroup;
    dxLayoutControl1Group7: TdxLayoutGroup;
    dxLayoutControl1Item1: TdxLayoutItem;
    eCalle: TcxDBTextEdit;
    dxLayoutControl1Item2: TdxLayoutItem;
    eProvincia: TcxDBTextEdit;
    dxLayoutControl1Item3: TdxLayoutItem;
    ePoblacion: TcxDBTextEdit;
    dxLayoutControl1Item4: TdxLayoutItem;
    eCodigoPostal: TcxDBTextEdit;
    dxLayoutControl1Item5: TdxLayoutItem;
    ePaginaWeb: TcxDBTextEdit;
    dxLayoutControl1Item6: TdxLayoutItem;
    eMailParticular: TcxDBTextEdit;
    dxLayoutControl1Item7: TdxLayoutItem;
    eMailTrabajo: TcxDBTextEdit;
    cxDBMemo1: TcxDBMemo;
    dxLayoutControl1Item8: TdxLayoutItem;
    dxLayoutControl1Item9: TdxLayoutItem;
    eTlfParticular: TcxDBTextEdit;
    dxLayoutControl1Item10: TdxLayoutItem;
    eTlfTrabajo: TcxDBTextEdit;
    dxLayoutControl1Item11: TdxLayoutItem;
    eTlfMovil: TcxDBTextEdit;
    dxLayoutControl1Item12: TdxLayoutItem;
    eFax: TcxDBTextEdit;
    dxLayoutControl1Item13: TdxLayoutItem;
    eNombre: TcxDBTextEdit;
    dxLayoutControl1Item14: TdxLayoutItem;
    eNIFCIF: TcxDBTextEdit;
    dxLayoutControl1Item15: TdxLayoutItem;
    memRegistroMercantil: TcxDBMemo;
    dxLayoutControl1Group10: TdxLayoutGroup;
    dxLayoutControl1Group9: TdxLayoutGroup;
    dxLayoutControl1Group11: TdxLayoutGroup;
    dxLayoutControl1Group8: TdxLayoutGroup;
    cxDBSpinEdit1: TcxDBSpinEdit;
    dxLayoutControl1Item16: TdxLayoutItem;
    ActionList1: TActionList;
    actAnadir: TAction;
    actEliminar: TAction;
    SmallImages: TPngImageList;
    OpenDialog1: TOpenDialog;
    cxDBImage1: TcxDBImage;
    dxLayoutControl1Item17: TdxLayoutItem;
    PngSpeedButton1: TPngSpeedButton;
    dxLayoutControl1Item19: TdxLayoutItem;
    PngSpeedButton2: TPngSpeedButton;
    dxLayoutControl1Item20: TdxLayoutItem;
    dxLayoutControl1Group12: TdxLayoutGroup;
    procedure actAnadirExecute(Sender: TObject);
    procedure actEliminarExecute(Sender: TObject);
    procedure actEliminarUpdate(Sender: TObject);
    procedure actAnadirUpdate(Sender: TObject);
  private
    FEmpresa: IBizEmpresa;
  protected
    function GetEmpresa: IBizEmpresa;
    procedure SetEmpresa(const Value: IBizEmpresa);
  public
    constructor Create(AOwner : TComponent); override;
  end;

implementation
{$R *.dfm}

uses uROClasses, uROTypes;

{ TfrViewEmpresas }

{
******************************* TfrViewEmpresa ********************************
}
procedure TfrViewEmpresa.actAnadirExecute(Sender: TObject);
{var
  StdStream: TMemoryStream;
  StreamRO: IROStream;
}
begin
  inherited;
  cxDBImage1.LoadFromFile;

{if not OpenDialog1.Execute then
  Exit;
  try
    StdStream := TMemoryStream.Create;
    StdStream.LoadFromFile(OpenDialog1.FileName);
    StreamRO := NewROStream(StdStream,False);
    DADataSource.DataTable.Edit;
//    DADataSource.DataTable.FieldByName('LOGOTIPO').Clear;
    DADataSource.DataTable.FieldByName('LOGOTIPO').LoadFromStream(StreamRO);

    DADataSource.DataTable.Post;
  finally
    StdStream.Free;
  end;
}
end;

procedure TfrViewEmpresa.actAnadirUpdate(Sender: TObject);
begin
  inherited;
//  (Sender as TAction).Enabled := cxDBImage1.Picture.Graphic.Empty;
end;

procedure TfrViewEmpresa.actEliminarExecute(Sender: TObject);
begin
  inherited;
  cxDBImage1.Clear;

{  DADataSource.DataTable.Edit;
  DADataSource.DataTable.FieldByName('LOGOTIPO').AsVariant := Null;
  DADataSource.DataTable.Post;
}
end;

procedure TfrViewEmpresa.actEliminarUpdate(Sender: TObject);
begin
  inherited;
//  (Sender as TAction).Enabled := not cxDBImage1.Picture.Graphic.Empty;
end;

constructor TfrViewEmpresa.Create(AOwner : TComponent);
begin
  inherited;
end;

function TfrViewEmpresa.GetEmpresa: IBizEmpresa;
begin
  Result := FEmpresa;
end;

procedure TfrViewEmpresa.SetEmpresa(const Value: IBizEmpresa);
begin
  FEmpresa := Value;
  if Assigned(FEmpresa) then
    DADataSource.DataTable := FEmpresa.DataTable
  else
    DADataSource.DataTable := NIL; 
end;

initialization
  RegisterClass(TfrViewEmpresa);

finalization
  UnRegisterClass(TfrViewEmpresa);

end.

