unit frmPromosEsp;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, FIBDataSet, pFIBDataSet, FIBDatabase, pFIBDatabase, StdCtrls,
  Grids, Wwdbigrd, Wwdbgrid, ExtCtrls;

type
  TfmPromosEsp = class(TForm)
    Panel1: TPanel;
    GroupBox1: TGroupBox;
    dbgArticulos: TwwDBGrid;
    Panel2: TPanel;
    Button2: TButton;
    trTrans: TpFIBTransaction;
    dsPromosEsp: TpFIBDataSet;
    dsoPromosEsp: TDataSource;
    dsPromosEspID_PROMO_ESPECIAL: TFIBIntegerField;
    dsPromosEspSKU: TFIBStringField;
    dsPromosEspPRESENTACION: TFIBStringField;
    dsPromosEspPROMOCION: TFIBStringField;
    dsPromosEspFECHA_FIN_PROMO: TFIBDateTimeField;
    dsPromosEspTIPO_PROMO: TFIBStringField;
    dsPromosEspPOLITICAS: TFIBStringField;
    dsPromosEspPROCESO_ID: TFIBIntegerField;
    IBQuery1: TpFIBDataSet;
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    FProcesoId:Integer;
    procedure Inicio();
  end;

var
  fmPromosEsp: TfmPromosEsp;

implementation
uses Unit1;

{$R *.dfm}

procedure TfmPromosEsp.Inicio();
begin
try
begin
  if trTrans.InTransaction then
    trTrans.Rollback;

  trTrans.StartTransaction;

  dsPromosEsp.Close;
  dsPromosEsp.ParamByName('PROCESO_ID').AsInteger:=FProcesoId;
  dsPromosEsp.Open;

end;
except on e:exception do
begin
  if trTrans.InTransaction then trTrans.Rollback;
    trTrans.StartTransaction;
end;
end;
end;

procedure TfmPromosEsp.Button2Click(Sender: TObject);
begin
  Close;
end;

procedure TfmPromosEsp.FormClose(Sender: TObject; var Action: TCloseAction);
var I:Integer;
begin
  IBQuery1.Close;
  IBQuery1.SelectSQL.Clear;
  IBQuery1.SelectSQL.Add('DELETE FROM MGNADRO_PROMOCIONES_ESPECIALES A WHERE A.PROCESO_ID = :PROCESO_ID');
  IBQuery1.ParamByName('PROCESO_ID').AsInteger := FProcesoId;
  IBQuery1.Open;

  if trTrans.InTransaction then
    trTrans.Commit;


  for I := 0 to trTrans.FIBDataSetsCount - 1 do
    trTrans.FIBDataSets[I].Close;
  trTrans.CloseAllQueryHandles;
  trTrans.Active := False;
end;

procedure TfmPromosEsp.FormShow(Sender: TObject);
begin
  Inicio();
end;

end.
