Como fazer uma pesquisa que mostre no mês que tem movimento?
Olá pessoal, estou precisando de uma idéia qual o componente usar aqui
Quero fazer um filtro por ano (Isso eu sei fazer) e mostrar o resultado em algum componente, mais gostaria que o form ja tivesse uns labels assim
JANEIRO
FEVEREIRO
MARÇO
...
...
DEZEMBRO
E vamos supor que eu pesquise algum cliente que tem movimento em alguns períodos tipo em Janeiro e Março, mostrar assim
JANEIRO............500,00
FEVEREIRO........Sem movimento n/mes
MARÇO..............250,50
...
...
DEZEMBRO.......Sem movimento n/mes
E os outros meses que ja vão ficar fixos no form ficar mostrando [b:bbd79d906c]Sem movimento n/mes[/b:bbd79d906c], tem como? Não to com ideia como fazer isso, pois com um dbgrid não funciona como eu quero.
E a tabela esteja gravado assim
data------------valor-------id_cli
01/2007--------500,00------1
03/2007--------250,50------1
//***********************************
Se a tabela estivesse preenchida tipo assim
01/2007--------0.00
02/2007--------500.00
03/2007--------0.00
04/2007--------150.00
Ai eu poderia fazer assim
Mais não vou gravar desta forma na tabela, por isso a dificuldade em fazer algo assim.
Estou usando Firebird 2.0
Grato Adriano
Quero fazer um filtro por ano (Isso eu sei fazer) e mostrar o resultado em algum componente, mais gostaria que o form ja tivesse uns labels assim
JANEIRO
FEVEREIRO
MARÇO
...
...
DEZEMBRO
E vamos supor que eu pesquise algum cliente que tem movimento em alguns períodos tipo em Janeiro e Março, mostrar assim
JANEIRO............500,00
FEVEREIRO........Sem movimento n/mes
MARÇO..............250,50
...
...
DEZEMBRO.......Sem movimento n/mes
E os outros meses que ja vão ficar fixos no form ficar mostrando [b:bbd79d906c]Sem movimento n/mes[/b:bbd79d906c], tem como? Não to com ideia como fazer isso, pois com um dbgrid não funciona como eu quero.
E a tabela esteja gravado assim
data------------valor-------id_cli
01/2007--------500,00------1
03/2007--------250,50------1
//***********************************
Se a tabela estivesse preenchida tipo assim
01/2007--------0.00
02/2007--------500.00
03/2007--------0.00
04/2007--------150.00
Ai eu poderia fazer assim
select case when REFERENTEMESANO=´01/2007´ and valorpg <> 0 then valorpg || ´-´ || REFERENTEMESANO when REFERENTEMESANO=´01/2007´ and valorpg = 0 then ´Sem movimento neste mes´ when REFERENTEMESANO=´02/2007´ and valorpg <> 0 then valorpg || ´-´ || REFERENTEMESANO when REFERENTEMESANO=´02/2007´ and valorpg = 0 then ´Sem movimento neste mes´ ... ...
Mais não vou gravar desta forma na tabela, por isso a dificuldade em fazer algo assim.
Estou usando Firebird 2.0
Grato Adriano
Adriano_servitec
Curtidas 0
Respostas
Adriano_servitec
31/08/2007
Inclusive se funcionasse poderia até usar o comando Iif do firebird 2.0
select Iif(valorpg <> 0, valorpg || ´-´ || REFERENTEMESANO , ´Sem Movimento n/mes´) as Status from corrente;
GOSTEI 0
Adriano_servitec
31/08/2007
Resolvido
a unica maneira foi fazer uma tabela em tempo de execução com o CDS.
Fiz algumas gambiarras no código aqui, não ficou 100¬, mais ficou + ou - do jeito que eu queria.
Bom pessoal, acho que vai ficar assim mesmo.
a unica maneira foi fazer uma tabela em tempo de execução com o CDS.
Fiz algumas gambiarras no código aqui, não ficou 100¬, mais ficou + ou - do jeito que eu queria.
procedure TFMensal_Ano.btnGravarClick(Sender: TObject); var i, n: SmallInt; begin //--primeiro carrego os edits que estão invisiveis //--passo o comando para preencher os edits dm.zqMensal2.Open; dm.zqMensal2.DisableControls; //desativa os controles dm.zqMensal2.First; while not dm.zqMensal2.Eof do begin if dm.zqmensal2referentemesano.value = ´01/´+edtAno.Text then begin edtjaneiro.Text:=CurrToStr(dm.zqmensal2valorpg.value); end; if dm.zqmensal2referentemesano.value = ´02/´+edtAno.Text then begin edtfevereiro.Text:=CurrToStr(dm.zqmensal2valorpg.value); end; if dm.zqmensal2referentemesano.value = ´03/´+edtAno.Text then begin edtmarco.Text:=CurrToStr(dm.zqmensal2valorpg.value); end; if dm.zqmensal2referentemesano.value = ´04/´+edtAno.Text then begin edtAbril.Text:=CurrToStr(dm.zqmensal2valorpg.value); end; if dm.zqmensal2referentemesano.value = ´05/´+edtAno.Text then begin edtMaio.Text:=CurrToStr(dm.zqmensal2valorpg.value); end; if dm.zqmensal2referentemesano.value = ´06/´+edtAno.Text then begin edtJunho.Text:=CurrToStr(dm.zqmensal2valorpg.value); end; if dm.zqmensal2referentemesano.value = ´07/´+edtAno.Text then begin edtJulho.Text:=CurrToStr(dm.zqmensal2valorpg.value); end; if dm.zqmensal2referentemesano.value = ´08/´+edtAno.Text then begin edtAgosto.Text:=CurrToStr(dm.zqmensal2valorpg.value); end; if dm.zqmensal2referentemesano.value = ´09/´+edtAno.Text then begin edtsetembro.Text:=CurrToStr(dm.zqmensal2valorpg.value); end; if dm.zqmensal2referentemesano.value = ´10/´+edtAno.Text then begin edtoutubro.Text:=CurrToStr(dm.zqmensal2valorpg.value); end; if dm.zqmensal2referentemesano.value = ´11/´+edtAno.Text then begin edtnovembro.Text:=CurrToStr(dm.zqmensal2valorpg.value); end; if dm.zqmensal2referentemesano.value = ´12/´+edtAno.Text then begin edtdezembro.Text:=CurrToStr(dm.zqmensal2valorpg.value); end; dm.zqMensal2.Next; end; dm.zqMensal2.EnableControls; //ativa os controles //--depois jogo para a tabela em tempo de execução N := ComponentCount; for I := 0 to N-1 do begin if (Components[I] is TEdit) then if (Components[I] as TEdit).Tag > 0 then begin cdsDados.Append; cdsDadosAno.Value := edtAno.Text; cdsDadosMes.Value := (Components[I] as TEdit).Tag; if (cdsDadosMes.Value = 1) and (edtJaneiro.Text = ´´) then begin e1.Text:=´Sem movimento neste mês´; cdsDadosHistorico.Value :=e1.Text; end else if (cdsDadosMes.Value = 1) and (edtJaneiro.Text <> ´´) then begin e1.Text:=´Pago mensalidade n/mês´; cdsDadosHistorico.Value :=e1.Text; end; if (cdsDadosMes.Value = 2) and (edtFevereiro.Text = ´´) then begin e1.Text:=´Sem movimento neste mês´; cdsDadosHistorico.Value :=e1.Text; end else if (cdsDadosMes.Value = 2) and (edtFevereiro.Text <> ´´) then begin e1.Text:=´Pago mensalidade n/mês´; cdsDadosHistorico.Value :=e1.Text; end; if (cdsDadosMes.Value = 3) and (edtMarco.Text = ´´) then begin e1.Text:=´Sem movimento neste mês´; cdsDadosHistorico.Value :=e1.Text; end else if (cdsDadosMes.Value = 3) and (edtMarco.Text <> ´´) then begin e1.Text:=´Pago mensalidade n/mês´; cdsDadosHistorico.Value :=e1.Text; end; if (cdsDadosMes.Value = 4) and (edtAbril.Text = ´´) then begin e1.Text:=´Sem movimento neste mês´; cdsDadosHistorico.Value :=e1.Text; end else if (cdsDadosMes.Value = 4) and (edtAbril.Text <> ´´) then begin e1.Text:=´Pago mensalidade n/mês´; cdsDadosHistorico.Value :=e1.Text; end; if (cdsDadosMes.Value = 5) and (edtMaio.Text = ´´) then begin e1.Text:=´Sem movimento neste mês´; cdsDadosHistorico.Value :=e1.Text; end else if (cdsDadosMes.Value = 5) and (edtMaio.Text <> ´´) then begin e1.Text:=´Pago mensalidade n/mês´; cdsDadosHistorico.Value :=e1.Text; end; if (cdsDadosMes.Value = 6) and (edtJunho.Text <> ´´) then begin e1.Text:=´Pago mensalidade n/mês´; cdsDadosHistorico.Value :=e1.Text; end else if (cdsDadosMes.Value = 6) and (edtJunho.Text = ´´) then begin e1.Text:=´Sem movimento neste mês´; cdsDadosHistorico.Value :=e1.Text; end; if (cdsDadosMes.Value = 7) and (edtJulho.Text <> ´´) then begin e1.Text:=´Pago mensalidade n/mês´; cdsDadosHistorico.Value :=e1.Text; end else if (cdsDadosMes.Value = 7) and (edtJulho.Text = ´´) then begin e1.Text:=´Sem movimento neste mês´; cdsDadosHistorico.Value :=e1.Text; end; if (cdsDadosMes.Value = 8) and (edtAgosto.Text <> ´´) then begin e1.Text:=´Pago mensalidade n/mês´; cdsDadosHistorico.Value :=e1.Text; end else if (cdsDadosMes.Value = 8) and (edtAgosto.Text = ´´) then begin e1.Text:=´Sem movimento neste mês´; cdsDadosHistorico.Value :=e1.Text; end; if (cdsDadosMes.Value = 9) and (edtSetembro.Text <> ´´) then begin e1.Text:=´Pago mensalidade n/mês´; cdsDadosHistorico.Value :=e1.Text; end else if (cdsDadosMes.Value = 9) and (edtSetembro.Text = ´´) then begin e1.Text:=´Sem movimento neste mês´; cdsDadosHistorico.Value :=e1.Text; end; if (cdsDadosMes.Value = 10) and (edtOutubro.Text <> ´´) then begin e1.Text:=´Pago mensalidade n/mês´; cdsDadosHistorico.Value :=e1.Text; end else if (cdsDadosMes.Value = 10) and (edtOutubro.Text = ´´) then begin e1.Text:=´Sem movimento neste mês´; cdsDadosHistorico.Value :=e1.Text; end; if (cdsDadosMes.Value = 11) and (edtNovembro.Text <> ´´) then begin e1.Text:=´Pago mensalidade n/mês´; cdsDadosHistorico.Value :=e1.Text; end else if (cdsDadosMes.Value = 11) and (edtNovembro.Text = ´´) then begin e1.Text:=´Sem movimento neste mês´; cdsDadosHistorico.Value :=e1.Text; end; if (cdsDadosMes.Value = 12) and (edtDezembro.Text <> ´´) then begin e1.Text:=´Pago mensalidade n/mês´; cdsDadosHistorico.Value :=e1.Text; end else if (cdsDadosMes.Value = 12) and (edtDezembro.Text = ´´) then begin e1.Text:=´Sem movimento neste mês´; cdsDadosHistorico.Value :=e1.Text; end; Case (Components[I] as TEdit).Tag of 1: cdsDadosValor.Value := StrToCurrDef((Components[I] as TEdit).Text, 0); 2: cdsDadosValor.Value := StrToCurrDef((Components[I] as TEdit).Text, 0); 3: cdsDadosValor.Value := StrToCurrDef((Components[I] as TEdit).Text, 0); 4: cdsDadosValor.Value := StrToCurrDef((Components[I] as TEdit).Text, 0); 5: cdsDadosValor.Value := StrToCurrDef((Components[I] as TEdit).Text, 0); 6: cdsDadosValor.Value := StrToCurrDef((Components[I] as TEdit).Text, 0); 7: cdsDadosValor.Value := StrToCurrDef((Components[I] as TEdit).Text, 0); 8: cdsDadosValor.Value := StrToCurrDef((Components[I] as TEdit).Text, 0); 9: cdsDadosValor.Value := StrToCurrDef((Components[I] as TEdit).Text, 0); 10: cdsDadosValor.Value := StrToCurrDef((Components[I] as TEdit).Text, 0); 11: cdsDadosValor.Value := StrToCurrDef((Components[I] as TEdit).Text, 0); 12: cdsDadosValor.Value := StrToCurrDef((Components[I] as TEdit).Text, 0); end; cdsDados.Post; end; end; //--depois limpo os edit com a procedure // ClearEdits; end;
Bom pessoal, acho que vai ficar assim mesmo.
GOSTEI 0
Emerson Nascimento
31/08/2007
rapaz... eu não entendi o por que daquele case. todas as linhas são idênticas! o case somente seria necessário se a ações a serem tomadas fossem diferentes em cada caso.
veja seu código com uma pequena alteração:
veja seu código com uma pequena alteração:
procedure TFMensal_Ano.btnGravarClick(Sender: TObject); var i, n: SmallInt; SemMovimento: boolean; iTag: integer; begin //--primeiro carrego os edits que estão invisiveis //--passo o comando para preencher os edits dm.zqMensal2.Open; dm.zqMensal2.DisableControls; //desativa os controles dm.zqMensal2.First; while not dm.zqMensal2.Eof do begin if dm.zqmensal2referentemesano.value = ´01/´+edtAno.Text then edtjaneiro.Text:=CurrToStr(dm.zqmensal2valorpg.value) else if dm.zqmensal2referentemesano.value = ´02/´+edtAno.Text then edtfevereiro.Text:=CurrToStr(dm.zqmensal2valorpg.value) else if dm.zqmensal2referentemesano.value = ´03/´+edtAno.Text then edtmarco.Text:=CurrToStr(dm.zqmensal2valorpg.value) else if dm.zqmensal2referentemesano.value = ´04/´+edtAno.Text then edtAbril.Text:=CurrToStr(dm.zqmensal2valorpg.value) else if dm.zqmensal2referentemesano.value = ´05/´+edtAno.Text then edtMaio.Text:=CurrToStr(dm.zqmensal2valorpg.value) else if dm.zqmensal2referentemesano.value = ´06/´+edtAno.Text then edtJunho.Text:=CurrToStr(dm.zqmensal2valorpg.value) else if dm.zqmensal2referentemesano.value = ´07/´+edtAno.Text then edtJulho.Text:=CurrToStr(dm.zqmensal2valorpg.value) else if dm.zqmensal2referentemesano.value = ´08/´+edtAno.Text then edtAgosto.Text:=CurrToStr(dm.zqmensal2valorpg.value) else if dm.zqmensal2referentemesano.value = ´09/´+edtAno.Text then edtsetembro.Text:=CurrToStr(dm.zqmensal2valorpg.value) else if dm.zqmensal2referentemesano.value = ´10/´+edtAno.Text then edtoutubro.Text:=CurrToStr(dm.zqmensal2valorpg.value) else if dm.zqmensal2referentemesano.value = ´11/´+edtAno.Text then edtnovembro.Text:=CurrToStr(dm.zqmensal2valorpg.value) else if dm.zqmensal2referentemesano.value = ´12/´+edtAno.Text then edtdezembro.Text:=CurrToStr(dm.zqmensal2valorpg.value); dm.zqMensal2.Next; end; dm.zqMensal2.EnableControls; //ativa os controles //--depois jogo para a tabela em tempo de execução N := ComponentCount - 1; for I := 0 to N do begin iTag := Components[I].Tag if (Components[I] is TEdit) and (iTag in [1..12]) then begin cdsDados.Append; cdsDadosAno.Value := edtAno.Text; cdsDadosMes.Value := iTag; case iTag of 1: SemMovimento := (edtJaneiro.Text = ´´); 2: SemMovimento := (edtFevereiro.Text = ´´); 3: SemMovimento := (edtMarco.Text = ´´); 4: SemMovimento := (edtAbril.Text = ´´); 5: SemMovimento := (edtMaio.Text = ´´); 6: SemMovimento := (edtJunho.Text = ´´); 7: SemMovimento := (edtJulho.Text = ´´); 8: SemMovimento := (edtAgosto.Text = ´´); 9: SemMovimento := (edtSetembro.Text = ´´); 10: SemMovimento := (edtOutubro.Text = ´´); 11: SemMovimento := (edtNovembro.Text = ´´); 12: SemMovimento := (edtDezembro.Text = ´´); end; if iTag in [1..12] then begin if SemMovimento then e1.Text:=´Sem movimento neste mês´ else e1.Text:=´Pago mensalidade n/mês´; cdsDadosHistorico.Value := e1.Text; cdsDadosValor.Value := StrToCurrDef((Components[I] as TEdit).Text, 0); end; cdsDados.Post; end; end; //--depois limpo os edit com a procedure // ClearEdits; end
GOSTEI 0
Adriano_servitec
31/08/2007
Tem razão amigo, o código ficou mais enxuto assim
Obrigado por arruma-lo pra mim.
Valeu.
Obrigado por arruma-lo pra mim.
Valeu.
GOSTEI 0