unit UBuscarBim;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Data.Win.ADODB, Vcl.Grids,
  Vcl.DBGrids, Vcl.StdCtrls, Vcl.Buttons;

type
  TFBuscarBim = class(TForm)
    DBGrid1: TDBGrid;
    DSBimestres: TDataSource;
    QBimestres: TADOQuery;
    Label1: TLabel;
    CBAnio: TComboBox;
    Label2: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    CBMes: TComboBox;
    QBimestresIdBimestre: TAutoIncField;
    QBimestresAnio: TSmallintField;
    QBimestresFecha_elab: TDateTimeField;
    QBimestresObservaciones: TWideStringField;
    QBimestresMes: TWordField;
    QBimestresNomMes: TStringField;
    procedure CBAnioChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure QBimestresCalcFields(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FBuscarBim: TFBuscarBim;

implementation

{$R *.dfm}

uses Udm;
procedure buscar(anio : string; mes:string; elquery:TAdoQuery);
var
  txtBus : string;
  begin
    begin
       elquery.Active:= false;
       txtbus:= 'Select * from Bimestres where Anio = ' + anio + ' and mes = ' + mes;
       elquery.SQL.Clear;
       elquery.SQL.Add(txtbus);
       elquery.Active:= true;
    end;
  end;



procedure TFBuscarBim.CBAnioChange(Sender: TObject);
 var
   val : integer;
begin
val :=  CBMes.ItemIndex + 1;
if val = 0 then
   inc(val);
  buscar(CBAnio.Text, inttostr(val), QBimestres);
  //showmessage(inttostr(val));
end;

procedure TFBuscarBim.FormCreate(Sender: TObject);
begin
 CBAnio.Text:= CBAnio.Items[0];
 CBMes.Text:= CBMes.Items[0]
end;

procedure TFBuscarBim.QBimestresCalcFields(DataSet: TDataSet);

  var
  bimes: array[1..6] of string = ('1er Bimestre', '2do. Bimestre', '3er. Bimestre', '4to. Bimestre','5to. Bimestre','6to. Bimestre');
begin
  //QBimestres.FieldByName('NomMes').AsString:= FormatSettings.LongMonthNames[QBimestres.FieldByName('Bimest').AsInteger];
  QBimestres.fieldByName('NomBimestre').AsString:= bimes[QBimestres.FieldByName('Bimestre').AsInteger];
end;

end.
