Hola compañeros.Necesito de su ayuda.tengo un formulario en el cual hago una consulta a medida por medio de un quickreport con los datos de docentes de una base de datos.esta consulta esta desarrollada utilizando
combobox, para el filtrado de los datos:
consulta:
- por sexo (todos/femenino/masculino)
- por estado (todos/habilitados/deshabilitados)
- por localidad (los datos se toman de otra tabla llamada localidades)
- por tipo de documento (TODOS/D.N.I./L.C./L.E./D.N.I.F./M/PASS/C.I.)
- por edad (todas/Igual a/Mayor a/Menor a/Desde utilizando tambien 2 edit's para establecer el numero)
- por orden (Apellido Ascendente/Apellido Descendente)
Esto por una parte.luego existen otros 4
combobox, los cuales deberian funcionar en forma de cascada, es decir, selecciono el primero y de acuerdo a ello se va filtrando la informacion de los demas
combobox.Ellos son:
- por area (Todas las Areas/Cs. Económicas/Cs. Exactas/Cs. Humanas/Cs. Sociales)
- por carrera
- por plan de estudio
- por materia
Estos 3 ultimos tambien utilizan datos de una tabla. Al ejecutar el programa, cuando quiero ver la consulta, sin cambiar algo en los
combobox,me aparecen todos los datos bien, ahora cuando cambio alguno de los
combobox, no aparece ningun dato.Este es el codigo que tenemos para hacer la consulta:
Código Delphi
[-]procedure TForm_docente.BitBtn_VistaPreviaClick(Sender: TObject);
var
consulta: string;
puse_where: Boolean;
begin
inherited;
cont:=cont+1;
puse_where:=false;
consulta:='select * from docente';
case ComboBox_tipodoc.ItemIndex of
0: begin
end;
else
begin
if(puse_where)then
consulta:=consulta + ' and tip_doc=:tipo'
else
consulta:=consulta + ' where tip_doc=:tipo';
puse_where:=true;
end;
end;
case ComboBox_materia.ItemIndex of
0:
begin
end;
else
begin
dm.IBDataSet_materia.Locate('nombre',ComboBox_materia.Text,[]);
dm.IBDataSet_profesor.Locate('id_docente',dm.IBDataSet_materiaID_DOCENTE.Value,[]);
if (puse_where)then
consulta:=consulta +' and id_docente=:mat'
else
begin
consulta:= consulta + ' where id_docente=:mat';
puse_where:=true;
end;
end;
end;
case ComboBox_localidad.ItemIndex of
0:
begin
end;
else
begin
DM.IBDataSet_Localidad.Locate('nombre',ComboBox_localidad.Text,[]);
if(puse_where)then
consulta:= consulta + ' and id_localidad=:loc'
else
begin
consulta:= consulta + ' where id_localidad=:loc';
puse_where:=true;
end;
end;
end;
case ComboBox_sexo.ItemIndex of
0: begin
end;
else
if(puse_where)then
consulta:= consulta + ' and SEXO=:sex'
else
begin
consulta:= consulta + ' where SEXO=:sex';
puse_where:=true;
end;
end;
case ComboBox_estado.ItemIndex of
0: begin
end;
1:
begin
if(puse_where)then
consulta:= consulta + ' and ESTADO=1'
else
begin
consulta:= consulta + ' where ESTADO=1';
puse_where:=true;
end;
end;
2:
begin
if(puse_where)then
consulta:= consulta + ' and ESTADO=0'
else
begin
consulta:= consulta + ' where ESTADO=0';
puse_where:=true;
end;
end;
end;
case ComboBox_Con_Edad.ItemIndex of
0: begin
end;
1: begin
if(puse_where)then
consulta:= consulta + ' and EDAD=:eda'
else
begin
consulta:= consulta + ' where EDAD=:eda';
puse_where:=true;
end;
end;
2: begin
if(puse_where)then
consulta:= consulta + ' and EDAD>:eda'
else
begin
consulta:= consulta + ' where EDAD>:eda';
puse_where:=true;
end;
end;
3: begin
if(puse_where)then
consulta:= consulta + ' and EDAD<:eda'
else
begin
consulta:= consulta + ' where EDAD<:eda';
puse_where:=true;
end;
end;
4: begin
if(puse_where)then
consulta:= consulta + ' and ((EDAD>=:eda)and (EDAD<=:eda2))'
else
begin
consulta:= consulta + ' where ((EDAD>=:eda)and (EDAD<=:eda2))';
puse_where:=true;
end;
end;
end;
case ComboBox_Con_Orden.ItemIndex of
0: begin
consulta:=consulta +' order by nombre_apellido asc';
end;
1: begin
consulta:=consulta +' order by nombre_apellido DESC';
end;
end;
with(DM.IBQuery_profesor)do
begin
SQL.Clear;
SQL.Add(consulta);
if(ComboBox_tipodoc.ItemIndex<>0)then
ParamByName('tipo').AsString:=ComboBox_tipodoc.Text;
if(ComboBox_localidad.ItemIndex<>0)then
ParamByName('loc').AsInteger:=DM.IBDataSet_LocalidadID_LOCALIDAD.Value;
if(ComboBox_materia.ItemIndex<>0)then
ParamByName('mat').AsInteger:=DM.IBDataSet_materiaID_DOCENTE.Value;
if(ComboBox_sexo.ItemIndex<>0)then
ParamByName('sex').AsString:=ComboBox_sexo.Text;
if(ComboBox_Con_Edad.ItemIndex=1)then
ParamByName('eda').AsString:=Edit_Con_n1.Text;
if(ComboBox_Con_Edad.ItemIndex=2)then
ParamByName('eda').AsString:=Edit_Con_n1.Text;
if(ComboBox_Con_Edad.ItemIndex=3)then
ParamByName('eda').AsString:=Edit_Con_n1.Text;
if(ComboBox_Con_Edad.ItemIndex=4)then
ParamByName('eda').AsString:=Edit_Con_n1.Text;
if(ComboBox_Con_Edad.ItemIndex=4)then
ParamByName('eda2').AsString:=Edit_Con_n2.Text;
Open;
QuickReport_Docentes.PreviewModal;
if(cont<>0)then
begin
Form_docente.ComboBox_area.Text:='Todas las Areas';
Form_docente.ComboBox_carrera.Clear;
Form_docente.ComboBox_carrera.Text:='Todas las Carreras';
Form_docente.ComboBox_plan.Clear;
Form_docente.ComboBox_plan.Text:='Todas los Planes de Estudios';
Form_docente.ComboBox_materia.Clear;
Form_docente.ComboBox_materia.Text:='Todas las Materias';
end;
end;
end;
procedure TForm_docente.ComboBox_areaChange(Sender: TObject);
begin
inherited;
if(ComboBox_area.ItemIndex<>0)then
begin
with (DM.IBQuery_carrera)do
begin
ComboBox_carrera.Clear;
SQL.Clear;
SQL.Add('select * from carrera where area starting with :name AND ESTADO = 1 order by nombre');
ParamByName('name').AsString:=ComboBox_area.Text;
Open;
first;
while not eof do
begin
ComboBox_carrera.Items.Add(dm.IBQuery_carreraNOMBRE.Value);
Next;
end;
ComboBox_carrera.ItemIndex:=0;
with (DM.IBQuery_plan_estudio)do
BEGIN
dm.IBQuery_carrera.Locate('nombre',ComboBox_carrera.Text,[]);
ComboBox_plan.Items.Clear;
SQL.Clear;
SQL.Add('select * from pe where PE.CARRERA=:CARRERA AND ESTADO = 1 order by nombre');
ParamByName('CARRERA').AsInteger:=DM.IBQuery_carreraID_CARRERA.Value;
dm.IBQuery_plan_estudio.Open;
if not dm.IBQuery_plan_estudio.IsEmpty then
dm.IBQuery_plan_estudio.first;
while(dm.IBQuery_plan_estudio.Eof=false)do
BEGIN
ComboBox_plan.Items.Add(DM.IBQuery_plan_estudioNOMBRE.Value);
dm.IBQuery_plan_estudio.Next;
END;
with (DM.IBQuery_materia)do
BEGIN
dm.IBQuery_plan_estudio.Locate('nombre',ComboBox_plan.Text,[]);
ComboBox_materia.Items.Clear;
SQL.Clear;
SQL.Add('select * from materia where materia.plan_estudio=:plan AND ESTADO = 1 order by N_CUATRI');
ParamByName('plan').AsInteger:=DM.IBQuery_plan_estudioID_PE.Value;
DM.IBQuery_materia.Open;
if not dm.IBQuery_materia.IsEmpty then
DM.IBQuery_materia.First;
while(dm.IBQuery_materia.Eof=false)do
BEGIN
ComboBox_materia.Items.Add(DM.IBQuery_materiaNOMBRE.Value);
DM.IBQuery_materia.Next;
END;
end
end;
end;
end;
end;
procedure TForm_docente.ComboBox_carreraEnter(Sender: TObject);
begin
inherited;
if(ComboBox_area.ItemIndex<>0)then
begin
with (DM.IBQuery_carrera)do
BEGIN
SQL.Clear;
SQL.Add('select * from carrera where carrera.AREA starting with :name AND ESTADO = 1 order by nombre');
ParamByName('name').AsString:=ComboBox_area.Text;
Open;
first;
while(dm.IBQuery_carrera.Eof=false)do
BEGIN
ComboBox_carrera.Items.Add(DM.IBQuery_carreraNOMBRE.Value);
NEXT;
END;
END
end
else
begin
poner_carreras;
end;
end;
procedure TForm_docente.ComboBox_planEnter(Sender: TObject);
begin
inherited;
if(ComboBox_carrera.ItemIndex<>0)then
begin
with (DM.IBQuery_plan_estudio)do
BEGIN
SQL.Clear;
SQL.Add('select * from pe where PE.CARRERA starting with :CARRERA AND ESTADO = 1 order by nombre');
ParamByName('CARRERA').AsInteger:=DM.IBQuery_carreraID_CARRERA.Value;
Open;
First;
while(dm.IBQuery_plan_estudio.Eof=false)do
BEGIN
ComboBox_plan.Items.Add(DM.IBQuery_plan_estudioNOMBRE.Value);
NEXT;
END;
END
end
else
begin
poner_pe;
end;
end;
procedure TForm_docente.ComboBox_materiaEnter(Sender: TObject);
begin
inherited;
if(ComboBox_plan.ItemIndex<>0)then
begin
with (DM.IBQuery_materia)do
BEGIN
SQL.Clear;
SQL.Add('select * from materia where materia.plan_estudio starting with :plan AND ESTADO = 1 order by nombre');
ParamByName('plan').AsInteger:=DM.IBQuery_plan_estudioID_PE.Value;
Open;
first;
while(dm.IBQuery_materia.Eof=false)do
BEGIN
ComboBox_materia.Items.Add(DM.IBQuery_materiaNOMBRE.Value);
NEXT;
END;
END
end
else
begin
poner_materia;
end;
end;
procedure TForm_docente.ComboBox_planChange(Sender: TObject);
begin
inherited;
ComboBox_materia.Clear;
with (DM.IBQuery_materia)do
BEGIN
dm.IBQuery_plan_estudio.Locate('nombre',ComboBox_plan.Text,[]);
ComboBox_materia.Items.Clear;
SQL.Clear;
SQL.Add('select * from materia where materia.plan_estudio=:plan AND ESTADO = 1 order by N_CUATRI');
ParamByName('plan').AsInteger:=DM.IBQuery_plan_estudioID_PE.Value;
DM.IBQuery_materia.Open;
if not dm.IBQuery_materia.IsEmpty then
DM.IBQuery_materia.First;
while(dm.IBQuery_materia.Eof=false)do
BEGIN
ComboBox_materia.Items.Add(DM.IBQuery_materiaNOMBRE.Value);
DM.IBQuery_materia.Next;
END;
end
end;
procedure TForm_docente.ComboBox_carreraChange(Sender: TObject);
begin
inherited;
ComboBox_plan.Clear;
with (DM.IBQuery_plan_estudio)do
BEGIN
dm.IBQuery_carrera.Locate('nombre',ComboBox_carrera.Text,[]);
ComboBox_plan.Items.Clear;
SQL.Clear;
SQL.Add('select * from pe where PE.CARRERA=:CARRERA AND ESTADO = 1 order by nombre');
ParamByName('CARRERA').AsInteger:=DM.IBQuery_carreraID_CARRERA.Value;
dm.IBQuery_plan_estudio.Open;
if not dm.IBQuery_plan_estudio.IsEmpty then
dm.IBQuery_plan_estudio.first;
while(dm.IBQuery_plan_estudio.Eof=false)do
BEGIN
ComboBox_plan.Items.Add(DM.IBQuery_plan_estudioNOMBRE.Value);
dm.IBQuery_plan_estudio.Next;
END;
END
end;
espero puedan ayudarme y desde ya muchas gracias por sus respuestas.