unit uAltaEdicionTPostOper_AproLin;

{$mode delphi}

interface

uses
  {$IFDEF WINDOWS}
    Windows,
  {$ENDIF}
    Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, xMatDefs, uHistoVarsOps,
    uBaseAltaEdicionPostOpers, uLectorSimRes3Defs, uVerDoc,
    uPostOpers, ExtCtrls, Grids, Types, utilidades;

type

  { TAltaEdicionTPostOper_AproLin }

  TAltaEdicionTPostOper_AproLin = class(TBaseAltaEdicionPostOpers)
    BAgregar: TButton;
    BAyuda: TButton;
    bCancelar: TButton;
    bGuardar: TButton;
    cbParam: TComboBox;
    cbRes: TComboBox;
    cbFuncionAAjustar: TComboBox;
    eLambda: TEdit;
    lCronVar: TLabel;
    lResultado: TLabel;
    lFuncionAAjustar: TLabel;
    ILambda: TLabel;
    Panel1: TPanel;
    sgParams: TStringGrid;

    procedure BAgregarClick(Sender: TObject);
    procedure BAyudaClick(Sender: TObject);
    procedure bCancelarClick(Sender: TObject);
    procedure bGuardarClick(Sender: TObject);
    procedure cbParamChange(Sender: TObject);
    procedure cbFuncionAAjustarChange(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);

    function validarFormulario: boolean; override;

    constructor Create(AOwner: TComponent; lector: TLectorSimRes3Defs;
      postOper: TPostOper; tipoPostOper: TClaseDePostOper); override;
    procedure sgParamsDrawCell(Sender: TObject; aCol, aRow: Integer;
      aRect: TRect; aState: TGridDrawState);
    procedure sgParamsMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure sgParamsMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure sgParamsMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    tiposColsSGParams: TDAOfTTipoColumna;
  end;

var
  AltaEdicionTPostOper_AproLin: TAltaEdicionTPostOper_AproLin;

implementation

uses SimSEEEditMain;

{$R *.lfm}




{ TAltaEdicionTPostOper_AproLin }

procedure TAltaEdicionTPostOper_AproLin.FormCloseQuery(Sender: TObject;
  var CanClose: boolean);
begin
  inherited FormCloseQuery(Sender, CanClose);
end;

function TAltaEdicionTPostOper_AproLin.validarFormulario: boolean;
begin
  result:= validarCBCronVars(cbRes) and
    validarCBCronVars(cbFuncionAAjustar) and
    validarSGCronVar(sgParams,cbParam) and
    validarEditFloat(eLambda, 0, MaxNReal);
end;

procedure TAltaEdicionTPostOper_AproLin.cbParamChange(Sender: TObject);
begin
   inherited cbCronVarChange(Sender, false);
end;

procedure TAltaEdicionTPostOper_AproLin.BAgregarClick(Sender: TObject);
begin
  inherited addSGCronVar_(sgParams, cbParam, BAgregar);
end;

procedure TAltaEdicionTPostOper_AproLin.BAyudaClick(Sender: TObject);
begin
  verdoc( 3829,  TPostOper_AproLin );
end;

procedure TAltaEdicionTPostOper_AproLin.bCancelarClick(Sender: TObject);
begin
  inherited bCancelarClick(Sender);
end;

procedure TAltaEdicionTPostOper_AproLin.bGuardarClick(Sender: TObject);
begin
  if validarFormulario then
  begin
    if postOper = NIL then
    begin
      postOper:= TPostOper_AproLin.Create(valorCBCronVar(cbRes),
        valorSGCronVar(sgParams), valorCBCronVar(cbFuncionAAjustar), strtofloat(eLambda.Text));
    end
    else
    begin
      TPostOper_AproLin(postOper).lambda:= StrToFloat(eLambda.Text);
      TPostOper_AproLin(postOper).res:= valorCBCronVar(cbRes);
      TPostOper_AproLin(postOper).params:= valorSGCronVar(sgParams);
      TPostOper_AproLin(postOper).funcionAAjustar:= valorCBCronVar(cbFuncionAAjustar);
    end;
    ModalResult:= mrOk;
  end;
end;

procedure TAltaEdicionTPostOper_AproLin.cbFuncionAAjustarChange(Sender: TObject);
begin
  inherited cbCronVarChange(Sender, True);
end;

constructor TAltaEdicionTPostOper_AproLin.Create(AOwner: TComponent;
  lector: TLectorSimRes3Defs; postOper: TPostOper;
  tipoPostOper: TClaseDePostOper);
begin
  inherited Create(AOwner, lector, postOper, tipoPostOper);

  inicializarCBCronVars(cbRes, false);
  inicializarSGCronVar(sgParams, tiposColsSGParams, cbParam, BAgregar);
  inicializarCBCronVars(cbFuncionAAjustar, false);

  if postOper <> NIL then
  begin
    setCBCronVar(cbRes, TPostOper_AproLin(postOper).res);

    setCBCronVar(cbFuncionAAjustar, TPostOper_AproLin(postOper).funcionAAjustar);

    setSGCronVar(sgParams,
                 TPostOper_AproLin(postOper).params,
                 cbParam, BAgregar);
    eLambda.Text:= FloatToStr(TPostOper_AproLin(postOper).lambda);

  end;
  utilidades.AutoSizeTypedColsAndTable(sgParams, tiposColsSGParams, FSimSEEEdit.iconos );
end;



procedure TAltaEdicionTPostOper_AproLin.sgParamsDrawCell(Sender: TObject; aCol,
  aRow: Integer; aRect: TRect; aState: TGridDrawState);
begin
  utilidades.ListadoDrawCell(Sender, ACol, ARow, aRect, aState, tiposColsSGParams[Acol], NIL, FSimSEEEdit.iconos);
end;

procedure TAltaEdicionTPostOper_AproLin.sgParamsMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  utilidades.ListadoMouseDown(Sender, Button, Shift, X, Y);
end;

procedure TAltaEdicionTPostOper_AproLin.sgParamsMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
  utilidades.ListadoMouseMove(Sender, Shift, X, Y, tiposColsSGParams);
end;

procedure TAltaEdicionTPostOper_AproLin.sgParamsMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  res: TTipoColumna;
begin
  res:= utilidades.ListadoMouseUp(Sender, Button, Shift, X, Y, tiposColsSGParams);
  case res of
    TC_btEliminar: eliminarSGCronVar(sgParams, utilidades.filaListado, cbParam, BAgregar);
  end;
end;

end.

