Instantly share code, notes, and snippets.

anonymous /buscar
Created May 2, 2015

Embed
What would you like to do?
búsqueda
unit UBuscarUnidad;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, StdCtrls, DBCtrls, ExtCtrls, Buttons, DB,
IBCustomDataSet, IBQuery;
type
TFBuscarUnidad = class(TForm)
DataSource1: TDataSource;
Panel4: TPanel;
Panel1: TPanel;
Panel3: TPanel;
DBNavigator1: TDBNavigator;
DBImage1: TDBImage;
Memo1: TMemo;
DBGrid1: TDBGrid;
Panel2: TPanel;
SBSalir: TSpeedButton;
sbbuscar: TSpeedButton;
sblimpiar: TSpeedButton;
RGBus: TRadioGroup;
Panel5: TPanel;
Label1: TLabel;
Edit1: TEdit;
DBGrid2: TDBGrid;
DBGrid3: TDBGrid;
Panel6: TPanel;
Panel7: TPanel;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
DataSource2: TDataSource;
DataSource3: TDataSource;
IBQUnidades: TIBQuery;
SBCancelar: TSpeedButton;
procedure Image1Click(Sender: TObject);
procedure Image3Click(Sender: TObject);
procedure Image4Click(Sender: TObject);
procedure Image2Click(Sender: TObject);
procedure sblimpiarClick(Sender: TObject);
procedure sbbuscarClick(Sender: TObject);
procedure SBSalirClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure RGBusClick(Sender: TObject);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure DataSource1DataChange(Sender: TObject; Field: TField);
procedure comprobar;
procedure SBCancelarClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FBuscarUnidad: TFBuscarUnidad;
implementation
{$R *.dfm}
uses UDM, Funciones;
procedure TFBuscarUnidad.comprobar;
//------------------------------------------------------------------------------
//************************************************************[ comprobar ]*****
//------------------------------------------------------------------------------
begin
if FBuscarUnidad.Active then
begin
if not (DataSource1.DataSet.State in [dsEdit,dsInsert]) then
begin
if not ((DM.IBDUnidades.IsEmpty) or (IBQUnidades.Active=false )) then
begin
if DataSource1.DataSet.FieldByName('NOTAS').Value<>'' then Memo1.Lines.Text:=DataSource1.DataSet.FieldByName('NOTAS').AsString
else Memo1.Lines.Clear;
end;
end;
end;
end;
procedure TFBuscarUnidad.DataSource1DataChange(Sender: TObject; Field: TField);
//------------------------------------------------------------------------------
//******************************************************[ Cambia de datos ]*****
//------------------------------------------------------------------------------
begin
comprobar;
end;
procedure TFBuscarUnidad.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
//------------------------------------------------------------------------------
//********************************[ Color según estado en nuestra rejilla ]*****
//------------------------------------------------------------------------------
var varbdispo:Boolean;
begin
if ((DataSource1.DataSet.FieldByName('DISPONIBLE').Value='S') and
(DataSource1.DataSet.FieldByName('VENDIDA').Value='N') and
(DataSource1.DataSet.FieldByName('PERDIDA').Value='N')) then dbgrid1.Canvas.Brush.Color:=StringToColor(DM.IBDConfiguracionCOLOR_DISPONIBLE.value)
else begin
varbdispo:=True;
if (DataSource1.DataSet.FieldByName('VENDIDA').Value='S') then
begin
dbgrid1.Canvas.Brush.Color:=StringToColor(DM.IBDConfiguracionCOLOR_BLOQUEADA.value);
varbdispo:=False;
end;
if (DataSource1.DataSet.FieldByName('PERDIDA').Value='S') then
begin
dbgrid1.Canvas.Brush.Color:=StringToColor(DM.IBDConfiguracionCOLOR_BLOQUEADA.value);
varbdispo:=False;
end;
if varbdispo then dbgrid1.Canvas.Brush.Color:=StringToColor(DM.IBDConfiguracionCOLOR_NO_DISPONIBLE.value);
end;
dbgrid1.Canvas.FillRect(Rect);
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
procedure TFBuscarUnidad.FormActivate(Sender: TObject);
//------------------------------------------------------------------------------
//**********************************************************[ On Activate ]*****
//------------------------------------------------------------------------------
begin
comprobar;
case RGBus.ItemIndex of
0:Label1.Caption:='Título';
1:Label1.Caption:='Código';
2:Label1.Caption:='Código de barras';
end;
end;
procedure TFBuscarUnidad.Image1Click(Sender: TObject);
//------------------------------------------------------------------------------
//************************************************************[ Subir uno ]*****
//------------------------------------------------------------------------------
begin
DataSource2.DataSet.Prior;
end;
procedure TFBuscarUnidad.Image2Click(Sender: TObject);
//------------------------------------------------------------------------------
//************************************************************[ Bajar uno ]*****
//------------------------------------------------------------------------------
begin
DataSource3.DataSet.next;
end;
procedure TFBuscarUnidad.Image3Click(Sender: TObject);
//------------------------------------------------------------------------------
//************************************************************[ Subir uno ]*****
//------------------------------------------------------------------------------
begin
DataSource3.DataSet.Prior;
end;
procedure TFBuscarUnidad.Image4Click(Sender: TObject);
//------------------------------------------------------------------------------
//************************************************************[ Bajar uno ]*****
//------------------------------------------------------------------------------
begin
DataSource2.DataSet.next;
end;
procedure TFBuscarUnidad.RGBusClick(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************************[ OnClick ]*****
// Si cambiamos el modo de búsqueda
//------------------------------------------------------------------------------
begin
case RGBus.ItemIndex of
0:Label1.Caption:='Título';
1:Label1.Caption:='Código';
2:Label1.Caption:='Código de barras';
end;
end;
procedure TFBuscarUnidad.sbbuscarClick(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************************[ buscar por ]*****
//------------------------------------------------------------------------------
begin
case RGBus.ItemIndex of
0:ActQuery(IBQUnidades,'select * from UNIDADES WHERE UNIDADES.TITULO LIKE '+QuotedStr('%'+Edit1.Text+'%'));
1:ActQuery(IBQUnidades,'select * from UNIDADES WHERE UNIDADES.CODIGO LIKE '+QuotedStr('%'+Edit1.Text+'%'));
2:ActQuery(IBQUnidades,'select * from UNIDADES WHERE UNIDADES.CODIGO_BARRAS LIKE '+QuotedStr('%'+Edit1.Text+'%'));
end;
end;
procedure TFBuscarUnidad.SBCancelarClick(Sender: TObject);
begin
varSBusqueda:='Cancelado';
Close;
end;
procedure TFBuscarUnidad.sblimpiarClick(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************************[ Limpiar ]*****
//------------------------------------------------------------------------------
begin
Edit1.Text:='';
sbbuscarClick(Sender);
end;
procedure TFBuscarUnidad.SBSalirClick(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************************[ SBSalir ]*****
//------------------------------------------------------------------------------
begin
varSBusqueda:=IntToStr(DataSource1.DataSet.FieldByName('ID').Value);
IBQUnidades.Active:=False;
sblimpiarClick(Sender);
Close;
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment