Skip to content

Instantly share code, notes, and snippets.

/gist:5812974
Created Jun 19, 2013

Embed
What would you like to do?
Módulo de búsqueda del programa de Gestión desde 0
unit UbusquedaFP;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls, Grids, DBGrids, DB, ComCtrls, ExtCtrls, DBCtrls,
SPBBC, IBCustomDataSet, IBQuery;
type
TFbusquedaFP = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
StatusBar1: TStatusBar;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Edbusqueda: TEdit;
Button2: TButton;
Button3: TButton;
Label1: TLabel;
SB_Salir: TSpeedButtonBC;
comboCampos: TComboBox;
Label2: TLabel;
DBNavigator1: TDBNavigator;
IBQBusqueda: TIBQuery;
CheckBox1: TCheckBox;
DataSource2: TDataSource;
procedure FormActivate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure EdbusquedaChange(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure SB_SalirClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure CarGarGrid(Column:Integer;MyField:WideString;Width:Integer;Titlecolumn:string);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FbusquedaFP: TFbusquedaFP;
VarSTabla:string;
implementation
{$R *.dfm}
uses UDM, Fun, FUN_DBGRID, UMENU, UProveedor;
procedure TFbusquedaFP.Button2Click(Sender: TObject);
//------------------------------------------------------------------------------
//****************************************************[ Hace la búsqueda ]******
//------------------------------------------------------------------------------
begin
// Usamos por defecto locate pero lo podemos cambiar por un Query y sus cláusulas
if comboCampos.Text<>'' then
begin
if CheckBox1.Checked then ActQuery(IBQBusqueda,'Select * From '+VarSTabla+' WHERE UPPER('+comboCampos.text+') LIKE UPPER('+QuotedStr('%'+Edbusqueda.Text+'%')+')')
else ActQuery(IBQBusqueda,'Select * From '+VarSTabla+' WHERE UPPER('+comboCampos.text+') WHERE UPPER('+QuotedStr(Edbusqueda.Text)+')');
end else ShowMessage('Debe seleccionar el campo por el que buscar');
end;
procedure TFbusquedaFP.Button3Click(Sender: TObject);
//------------------------------------------------------------------------------
//***************************************************[ Limpiamos el edit ]******
//------------------------------------------------------------------------------
begin
Edbusqueda.Text:='';
Edbusqueda.SetFocus;
end;
procedure TFbusquedaFP.CarGarGrid(Column:Integer;MyField:WideString;Width:Integer;Titlecolumn:string);
//------------------------------------------------------------------------------
//*************************************************************[ CargarGrid ]****
//------------------------------------------------------------------------------
begin
DBGrid1.Columns.Add;
with DBGrid1.Columns[Column] do
begin
FieldName:=MyField;
Title.Caption:=Titlecolumn;
Width:=Width;
end;
end;
procedure TFbusquedaFP.EdbusquedaChange(Sender: TObject);
//------------------------------------------------------------------------------
//*************************************************[ Mientras escribimos ]******
// Mientras escribimos hacemos la busqueda
//------------------------------------------------------------------------------
begin
Button2Click(sender);
end;
procedure TFbusquedaFP.FormActivate(Sender: TObject);
//------------------------------------------------------------------------------
//********************[ Cargamos los Campos de la tabla en el ComboBox ]******
//------------------------------------------------------------------------------
begin
//Comprobamos si el combo esta vacio cargamos los datos
if VarSTabla='FPAGOS' then if Edbusqueda.Text='' then ActQuery(IBQBusqueda,'Select * From '+VarSTabla);
if IBQBusqueda.IsEmpty then
begin
ShowMessage('No hay datos para buscar o mostrar');
SB_SalirClick(Sender);
end else
begin
if comboCampos.Items.Count=0 then DataSource1.DataSet.GetFieldNames(comboCampos.items);
CarGarGrid(0,'ID',50,'ID');
CarGarGrid(1,'CODIGO',130,'Código');
CarGarGrid(2,'FORMAPAGO',260,'Forma de pago');
CarGarGrid(3,'DIASPRESENTACION',130,'Días de presentación');
CarGarGrid(4,'DIASCOBRO',130,'Días de cobro');
CarGarGrid(5,'NUMERODEPAGOS',130,'Número de pagos');
end;
end;
procedure TFbusquedaFP.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if (VarSNomMod='PROVEEDORES') and (FProveedor.DsPrincipal.DataSet.State in [dsEdit,dsInsert]) then
begin
FProveedor.DBNCodigoFormaPago.Field.Value:=IBQBusqueda.FieldByName('FORMAPAGO').AsString; //Pnemos la forma de pago elegida
FProveedor.DBNCodigoFormaPago.SetFocus; //Damos el focno nuevamente al campo
end;
Button3Click(Sender);
QuerryOC(IBQBusqueda);
comboCampos.Items.Clear;
end;
procedure TFbusquedaFP.FormCreate(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************************[ OnCreate ]****
//------------------------------------------------------------------------------
begin
comboCampos.Items.Clear;
end;
procedure TFbusquedaFP.FormShow(Sender: TObject);
//------------------------------------------------------------------------------
//****************************************************************[ OnShow ]****
// Adaptamos el título del form a la tabla que usamos
//------------------------------------------------------------------------------
begin
if VarSTabla='FPAGOS' then Caption:='Búsquedas en Fromas de pago'; //Caption del Form
end;
procedure TFbusquedaFP.SB_SalirClick(Sender: TObject);
//------------------------------------------------------------------------------
//******************************************************[ Salir del Form ]******
//------------------------------------------------------------------------------
begin
FbusquedaFP.Close;
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.