unit uEditorColores;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uDialogBase, ActnList, StdCtrls, ExtCtrls, cxGraphics, cxControls,
  cxLookAndFeels, cxLookAndFeelPainters, cxContainer, cxEdit, cxTextEdit,
  cxDBEdit, DB, uDAInterfaces, uDADataTable, JvExControls, JvEnterTab, ComCtrls;

type
  TfEditorColores = class(TfDialogBase)
    eColor1: TcxDBTextEdit;
    eColor2: TcxDBTextEdit;
    eColor3: TcxDBTextEdit;
    eColor4: TcxDBTextEdit;
    eColor5: TcxDBTextEdit;
    eColor6: TcxDBTextEdit;
    eColor7: TcxDBTextEdit;
    eColor8: TcxDBTextEdit;
    eColor9: TcxDBTextEdit;
    eColor10: TcxDBTextEdit;
    eColor11: TcxDBTextEdit;
    eColor12: TcxDBTextEdit;
    dsDataTable: TDADataSource;
    Label1: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    JvEnterAsTab1: TJvEnterAsTab;
    RichEdit1: TRichEdit;
    procedure actAceptarExecute(Sender: TObject);
    procedure actCancelarExecute(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    FReferencia : String;
    FDescripcion : String;
    function GetTotal: Double;
    procedure SetDescripcion(const Value: String);
    procedure SetReferencia(const Value: String);
    procedure PonerTituloArticulo;
  public
    property Total : Double read GetTotal;
    property Referencia : String read FReferencia write SetReferencia;
    property Descripcion : String read FDescripcion write SetDescripcion;
  end;

implementation

{$R *.dfm}

uses
  uStringsUtils;

{ TfEditorColores }

procedure TfEditorColores.actAceptarExecute(Sender: TObject);
begin
  inherited;
  ModalResult := mrOk;
end;

procedure TfEditorColores.actCancelarExecute(Sender: TObject);
begin
  inherited;
  ModalResult := mrCancel;
end;

procedure TfEditorColores.FormShow(Sender: TObject);
begin
  inherited;
  PonerTituloArticulo;
end;

function TfEditorColores.GetTotal: Double;
var
  ATotal: Double;
begin
  ATotal := 0;
  if not VarIsNull(eColor1.EditValue) then
     ATotal := ATotal + eColor1.EditValue;

  if not VarIsNull(eColor2.EditValue) then
     ATotal := ATotal + eColor2.EditValue;

  if not VarIsNull(eColor3.EditValue) then
     ATotal := ATotal + eColor3.EditValue;

  if not VarIsNull(eColor4.EditValue) then
     ATotal := ATotal + eColor4.EditValue;

  if not VarIsNull(eColor5.EditValue) then
     ATotal := ATotal + eColor5.EditValue;

  if not VarIsNull(eColor6.EditValue) then
     ATotal := ATotal + eColor6.EditValue;

  if not VarIsNull(eColor7.EditValue) then
     ATotal := ATotal + eColor7.EditValue;

  if not VarIsNull(eColor8.EditValue) then
     ATotal := ATotal + eColor8.EditValue;

  if not VarIsNull(eColor9.EditValue) then
     ATotal := ATotal + eColor9.EditValue;

  if not VarIsNull(eColor10.EditValue) then
     ATotal := ATotal + eColor10.EditValue;

  if not VarIsNull(eColor11.EditValue) then
     ATotal := ATotal + eColor11.EditValue;

  if not VarIsNull(eColor12.EditValue) then
     ATotal := ATotal + eColor12.EditValue;

  Result := ATotal;
end;


procedure TfEditorColores.PonerTituloArticulo;
begin
  lblInstruccion.Caption := 'Indique las cantidades por colores para el artículo';
  if not EsCadenaVacia(FReferencia) then
    lblInstruccion.Caption := lblInstruccion.Caption + ' de referencia ' + FReferencia;
    
  RichEdit1.Text := FDescripcion;
end;

procedure TfEditorColores.SetDescripcion(const Value: String);
begin
  FDescripcion := Value;
end;

procedure TfEditorColores.SetReferencia(const Value: String);
begin
  FReferencia := Value;
end;

end.
