Ir para conteúdo
Fórum Script Brasil
  • 0

(Resolvido) Como Calcular Número De Aulas Excedidas E Atribuir A


robinhocne

Pergunta

Estou com um projeto que faço marcação de aulas para auto escola e gostaria de acrescentar algumas utilidades para o usuário sendo um também: Informações:

Delphi 07

Firebird 2.0.3

A tabela que eu marco aulas praticas é feita em tempo de execução:

Coloquei dois tipos de edits um para aulas de carro e outro moto

TxtCarro

TxtMoto

E mais dois para aulas extras

TxtExtCarro

TXTExtMoto

É assim: Todos os alunos tem direito a 15 aulas de carro e 15 de moto então após ser marcado as 15 aulas ai contasse como aulas extras e registrasse no outro edit.

Acho que isso é tudo.

Se alguém poder me ajudar nesse tópico agradeço desde já.

Editado por Micheus
Alterado título para melhor expressão da dúvida
Link para o comentário
Compartilhar em outros sites

13 respostass a esta questão

Posts Recomendados

  • 0

Achei que pelo tópico era pra contar os clicks do mouse...

É assim: Todos os alunos tem direito a 15 aulas de carro e 15 de moto então após ser marcado as 15 aulas ai contasse como aulas extras e registrasse no outro edit.

Neste caso use um if para verificar se as aulas já passou de 15... se passou faz o registro em TxtExtCarro ou TXTExtMoto ... para melhor precisão na resposta é melhor postar o seu codigo.

Link para o comentário
Compartilhar em outros sites

  • 0
Posta a parte do codigo em que voce marca aulas praticas ... ai tento te dar uma força.

Esse é o do FormCreate.

procedure Tfrmpraticas.FormCreate(Sender: TObject);// Procedure para criar a Tabela
var labels : TpsvBorderLabel;  edits  : TEdit;
    a, top_edit, top_label, left_edit : Integer;
    HoraAtual, HoraFinal : TTime;
begin
   dataInicial := Date();
   PosicionaSemana;
   top_edit    := 3;
   top_label   := 3;
   left_edit   := 98; // left da primeira fileira dos edits
   HoraFinal   := StrToTime( '22:10:00' );
   HoraAtual   := StrToTime( '08:00:00' );

   while ( ( HoraAtual + StrToTime( '00:50' ) ) < HoraFinal ) do
      begin
         // cria a label do horario
         Labels := TpsvBorderLabel.Create( Self );
         with Labels do
            begin
               Height  := 18; // Tamanho do Labels
               Border  := psvBorderLabel.bsRaised; // bordas do labels
               Parent  := sbxPra;
               Top     := top_label;
               Left    := 16;
               Caption := FormatDateTime( 'hh:nn', HoraAtual );
               Name    := 'lbl_' + FormatDateTime( 'hhnn', HoraAtual );
                  with Font do
                     begin
                        Name       := 'Courier New';
                        Size       := 10;
                        Style      := [fsBold];
                        FocusColor := ClBlack;
                        Width      := 75;
                        Layout     := tlCenter;
                        Alignment  := TaCenter;
                     end;
            end;
         for a := 1 to 7 do
            begin
               // cria o edit do codigo do aluno
               edits := TEdit.Create( Self );
               with edits do
                  begin
                     Cursor     := crCross;
                     Parent     := sbxPra;
                     Top        := top_edit;
                     Left       := left_edit;
                     Name       := 'ed_' + IntToStr( a ) + FormatDateTime( 'hhnn', HoraAtual );
                     Width      := 65;
                     //Enabled   := False;
                     ReadOnly   := True;
                     Text       := '';
                     OnDblClick := PreencheEdit;
                     OnKeyDown  := BloqueioDesbloqueio;
                        with Font do
                           Begin
                              Height  := 15;
                              Name    := 'Courier New';
                              Size    := 10;
                           //   Style   := [fsBold];
                           end;
                  end;

               // cria o edit da categoria
               left_edit := left_edit + 67; // espaço entre o edit codigo e edit categoria
               edits := TEdit.Create( Self );
               with edits do
                  begin
                     Cursor  := crCross;
                     Parent  := sbxPra;
                     Top     := top_edit;
                     Left    := left_edit;
                     Name    := 'ed_cat_' + IntToStr( a ) + FormatDateTime( 'hhnn', HoraAtual );
                     Width   := 20;
                     //Enabled   := False;
                     ReadOnly  := True;
                     Text      := '';
                        with Font do
                           Begin
                              Height  := 15;
                              Name    := 'Courier New';
                              Size    := 10;
                             // Style   := [fsBold];
                           end;
                  end;
               left_edit := left_edit + 23; // Espaço entre o edit da categoria para o codigo da outra fileira.
            end;
         top_label := top_label + 28; // top dos edits
         top_edit  := top_edit + 28; // top dos labels
         left_edit := 98; // left das demais fileiras dos edits

         if ( HoraAtual < StrToTime( '17:00:00' ) ) then
            HoraAtual := HoraAtual + StrToTime( '01:00' )
         else
            HoraAtual := HoraAtual + StrToTime( '00:50' );
      end;
   Application.OnMessage := AppEventsMessage; // Para a movimentação do mouse
   linha                 := 1;
end;

Link para o comentário
Compartilhar em outros sites

  • 0

robinho ... acho que voce esta gastando codigo de graça, a criação de labels e edits voce esta fazendo do jeito mais dificil .... (voce esta criando 7 edits em tempo de execução e definindo suas propriedades) ... porque voce não utiliza os componentes da paleta do delphi e atribui as propriedades diretamente no componente ? A parte do codigo onde voce atribui as aulas não esta neste codigo ... É isto mesmo que voce está querendo ?

Editado por Jhonas
Link para o comentário
Compartilhar em outros sites

  • 0
robinho ... acho que voce esta gastando codigo de graça, a criação de labels e edits voce esta fazendo do jeito mais dificil .... (voce esta criando 7 edits em tempo de execução e definindo suas propriedades) ... porque voce não utiliza os componentes da paleta do delphi e atribui as propriedades diretamente no componente ? A parte do codigo onde voce atribui as aulas não esta neste codigo ... É isto mesmo que voce está querendo ?

É isso que eu quero sim, desculpe passei os codigos errados>

procedure Tfrmpraticas.PreencheEdit( Sender : TObject );
begin 
   if ( Length( Trim( txtCod.Text ) ) = 0 ) then Exit;
   if ( Length( Trim( ( Sender as TEdit ).Text ) ) = 0 ) then

      begin
         if ( ConsultaRegistros( 'Praticas', 'Aluno',
                                 'Aluno=' + txtCod.Text + ' AND ' +
                                 'Data=' + #39 + FormatDateTime( 'mm/dd/yyyy', RetornaData( ( Sender as TEdit ).Name ) ) + #39 + ' AND ' +
                                 'Horario=' + #39 + FormatDateTime( 'hh:nn', RetornaHora( ( Sender as TEdit ).Name ) ) + #39 + ' AND ' +
                                 'Status=1' ) ) then
            begin
               ShowMessage( 'Aluno já tem aula marcada neste Horário!' );
               Exit;
            end;
         ( Sender as TEdit ).Text := StrZero( StrToFloat( txtCod.Text ), 6 );
         TEdit( FindComponent( 'ed_cat_' + Copy( ( Sender as TEdit ).Name, 4, 5 ) ) ).Text := txtCat.Text;
         // salva a aula na tabela
         with vCpo do
            begin
               Clear;
               Add( 'Aluno' );
               Add( 'Instrutor' );
               Add( 'Categoria' );
               Add( 'Data' );
               Add( 'Horario' );
               Add( 'Status' );
            end;
         with vVlr do
            begin
               Clear;
               Add( txtCod.Text );
               Add( txtCodIns.Text );
               Add( #39 + txtCat.Text + #39 );
               Add( #39 + FormatDateTime( 'mm/dd/yyyy', RetornaData( ( Sender as TEdit ).Name ) ) + #39 );
               Add( #39 + FormatDateTime( 'hh:nn', RetornaHora( ( Sender as TEdit ).Name ) ) + #39 );
               Add( '1' );
            end;
         IncluirRegistro( 'Praticas', vCpo, vVlr );
      end
   else
      begin
         if ( ( Sender as TEdit ).Text <> txtCod.Text ) then
         begin
            ShowMessage( 'Código do Aluno não confere com o Nome do mesmo selecionado!' );
            Exit;
         end;
         ExcluirRegistro( 'Praticas',
                          'Aluno=' + ( Sender as TEdit ).Text + ' AND ' +
                          'Instrutor=' + txtCodIns.Text + ' AND ' +
                          'Categoria=' + #39 + TEdit( FindComponent( 'ed_cat_' + Copy( ( Sender as TEdit ).Name, 4, 5 ) ) ).Text + #39 + ' AND ' +
                          'Data=' + #39 + FormatDateTime( 'mm/dd/yyyy', RetornaData( ( Sender as TEdit ).Name ) ) + #39 + ' AND ' +
                          'Horario=' + #39 + FormatDateTime( 'hh:nn', RetornaHora( ( Sender as TEdit ).Name ) ) + #39 );
         ( Sender as TEdit ).Text := '';
         TEdit( FindComponent( 'ed_cat_' + Copy( ( Sender as TEdit ).Name, 4, 5 ) ) ).Text := '';
      end;
    ConsultaAula;
end;

Link para o comentário
Compartilhar em outros sites

  • 0
voce atribui o numero de aulas do aluno no txtCod.Text ? onde esta a procedure ConsultaAula ? onde esta o registro das aulas que o aluno já fez ? voce pode me explicar a sua lógica no programa ?

Jhonas é o seguinte:

> O txtcod.text é onde atribui o codigo do aluno.

Vou passar os dados da tabela de praticas para você entender melhor!

unit Praticas;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, psvBasiclbl, psvBorderLabel, Buttons, WinSkinData,
  Grids, DBGrids, ExtCtrls, DateUtils, DB, DBTables, IBCustomDataSet,
  IBQuery;

type
  Tfrmpraticas = class(TForm)
    txtcod: TEdit;
    txtaluno: TEdit;
    txtcodins: TEdit;
    txtnomins: TEdit;
    txtcodcat: TEdit;
    txtcat: TEdit;
    spbaluloc: TSpeedButton;
    psvBorderLabel1: TpsvBorderLabel;
    psvBorderLabel2: TpsvBorderLabel;
    psvBorderLabel3: TpsvBorderLabel;
    SbpInst: TSpeedButton;
    SpbCat: TSpeedButton;
    Panel1: TPanel;
    spbpro: TSpeedButton;
    spbant: TSpeedButton;
    sbxPra: TScrollBox;
    Panel2: TPanel;
    panHor: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    Panel5: TPanel;
    Panel6: TPanel;
    panDom: TPanel;
    panTer: TPanel;
    panQua: TPanel;
    panQui: TPanel;
    panSex: TPanel;
    panSab: TPanel;
    Panel14: TPanel;
    Panel15: TPanel;
    Panel16: TPanel;
    Panel17: TPanel;
    Panel18: TPanel;
    Panel19: TPanel;
    Panel20: TPanel;
    Panel21: TPanel;
    panSeg: TPanel;
    Panel7: TPanel;
    DbgRel: TDBGrid;
    txtvei: TEdit;
    SpbImp: TSpeedButton;
    spbfec: TSpeedButton;
    DtsPra: TDataSource;
    QryPra: TIBQuery;
    psvBorderLabel4: TpsvBorderLabel;
    psvBorderLabel5: TpsvBorderLabel;
    TxtMoto: TEdit;
    TxtCarro: TEdit;
    psvBorderLabel6: TpsvBorderLabel;
    psvBorderLabel7: TpsvBorderLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure spbfecClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure spbantClick(Sender: TObject);
    procedure spbproClick(Sender: TObject);
    procedure PosicionaSemana;
    procedure ConsultaAgendamento;
    procedure PreencheEdit( Sender : TObject );
    procedure BloqueioDesbloqueio( Sender: TObject; var Key: Word; Shift: TShiftState );
    procedure SalvaBloqueio( Sender : TObject );
    procedure RemoveBloqueio( Sender : TObject );
    function  RetornaData( edit : String ) : TDate;
    function  RetornaHora( edit : String ) : TTime;
    procedure txtcodinsExit(Sender: TObject);
    procedure spbalulocClick(Sender: TObject);
    procedure LeRegistro ();
    procedure SbpInstClick(Sender: TObject);
    procedure SpbCatClick(Sender: TObject);
    Procedure ConsultaAula;
    procedure DbgRelDrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);

  private
   linha : integer;
   dataInicial, InicioSemana, FinalSemana : TDate;
   procedure AppEventsMessage(var Msg: TMsg; var Handled: Boolean);
  public
    { Public declarations }
  end;

var
  frmpraticas: Tfrmpraticas;


implementation

{$R *.dfm}

uses funcoes, fprincipal, fdtmiza, Fpesquisa, finstrutores, fcategoria, falunos;

Var
  cont : extended;

procedure Tfrmpraticas.spbfecClick(Sender: TObject);
begin
   close;
end;


procedure Tfrmpraticas.FormCreate(Sender: TObject);// Procedure para criar a Tabela
var labels : TpsvBorderLabel;  edits  : TEdit;
    a, top_edit, top_label, left_edit : Integer;
    HoraAtual, HoraFinal : TTime;
begin
   dataInicial := Date();
   PosicionaSemana;
   top_edit    := 3;
   top_label   := 3;
   left_edit   := 98; // left da primeira fileira dos edits
   HoraFinal   := StrToTime( '22:10:00' );
   HoraAtual   := StrToTime( '08:00:00' );

   while ( ( HoraAtual + StrToTime( '00:50' ) ) < HoraFinal ) do
      begin
         // cria a label do horario
         Labels := TpsvBorderLabel.Create( Self );
         with Labels do
            begin
               Height  := 18; // Tamanho do Labels
               Border  := psvBorderLabel.bsRaised; // bordas do labels
               Parent  := sbxPra;
               Top     := top_label;
               Left    := 16;
               Caption := FormatDateTime( 'hh:nn', HoraAtual );
               Name    := 'lbl_' + FormatDateTime( 'hhnn', HoraAtual );
                  with Font do
                     begin
                        Name       := 'Courier New';
                        Size       := 10;
                        Style      := [fsBold];
                        FocusColor := ClBlack;
                        Width      := 75;
                        Layout     := tlCenter;
                        Alignment  := TaCenter;
                     end;
            end;
         for a := 1 to 7 do
            begin
               // cria o edit do codigo do aluno
               edits := TEdit.Create( Self );
               with edits do
                  begin
                     Cursor     := crCross;
                     Parent     := sbxPra;
                     Top        := top_edit;
                     Left       := left_edit;
                     Name       := 'ed_' + IntToStr( a ) + FormatDateTime( 'hhnn', HoraAtual );
                     Width      := 65;
                     //Enabled   := False;
                     ReadOnly   := True;
                     Text       := '';
                     OnDblClick := PreencheEdit;
                     OnKeyDown  := BloqueioDesbloqueio;
                        with Font do
                           Begin
                              Height  := 15;
                              Name    := 'Courier New';
                              Size    := 10;
                           //   Style   := [fsBold];
                           end;
                  end;

               // cria o edit da categoria
               left_edit := left_edit + 67; // espaço entre o edit codigo e edit categoria
               edits := TEdit.Create( Self );
               with edits do
                  begin
                     Cursor  := crCross;
                     Parent  := sbxPra;
                     Top     := top_edit;
                     Left    := left_edit;
                     Name    := 'ed_cat_' + IntToStr( a ) + FormatDateTime( 'hhnn', HoraAtual );
                     Width   := 20;
                     //Enabled   := False;
                     ReadOnly  := True;
                     Text      := '';
                        with Font do
                           Begin
                              Height  := 15;
                              Name    := 'Courier New';
                              Size    := 10;
                             // Style   := [fsBold];
                           end;
                  end;
               left_edit := left_edit + 23; // Espaço entre o edit da categoria para o codigo da outra fileira.
            end;
         top_label := top_label + 28; // top dos edits
         top_edit  := top_edit + 28; // top dos labels
         left_edit := 98; // left das demais fileiras dos edits

         if ( HoraAtual < StrToTime( '17:00:00' ) ) then
            HoraAtual := HoraAtual + StrToTime( '01:00' )
         else
            HoraAtual := HoraAtual + StrToTime( '00:50' );
      end;
   Application.OnMessage := AppEventsMessage; // Para a movimentação do mouse
   linha                 := 1;
end;

procedure Tfrmpraticas.PosicionaSemana;   // Procedure para mostrar as datas
var hoje : Integer;
begin
   hoje := DayOfTheWeek( dataInicial );  // 1->segunda;2->terca;...;7->domingo

   case hoje of
      1 :
         begin
            InicioSemana   := dataInicial-1;
            FinalSemana    := dataInicial+5;
            panDom.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-1 );
            panSeg.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial   );
            panTer.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+1 );
            panQua.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+2 );
            panQui.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+3 );
            panSex.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+4 );
            panSab.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+5 );
         end;
      2 :
         begin
            InicioSemana   := dataInicial-2;
            FinalSemana    := dataInicial+4;
            panDom.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-2 );
            panSeg.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-1 );
            panTer.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial   );
            panQua.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+1 );
            panQui.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+2 );
            panSex.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+3 );
            panSab.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+4 );
         end;
      3 :
         begin
            InicioSemana   := dataInicial-3;
            FinalSemana    := dataInicial+3;
            panDom.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-3 );
            panSeg.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-2 );
            panTer.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-1 );
            panQua.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial   );
            panQui.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+1 );
            panSex.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+2 );
            panSab.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+3 );
         end;
      4 :
         begin
            InicioSemana   := dataInicial-4;
            FinalSemana    := dataInicial+2;
            panDom.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-4 );
            panSeg.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-3 );
            panTer.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-2 );
            panQua.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-1 );
            panQui.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial   );
            panSex.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+1 );
            panSab.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+2 );
         end;
      5 :
         begin
            InicioSemana   := dataInicial-5;
            FinalSemana    := dataInicial+1;
            panDom.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-5 );
            panSeg.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-4 );
            panTer.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-3 );
            panQua.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-2 );
            panQui.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-1 );
            panSex.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial   );
            panSab.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+1 );
         end;
      6 :
         begin
            InicioSemana   := dataInicial-6;
            FinalSemana    := dataInicial;
            panDom.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-6 );
            panSeg.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-5 );
            panTer.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-4 );
            panQua.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-3 );
            panQui.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-2 );
            panSex.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial-1 );
            panSab.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial   );
         end;
      7 :
         begin
            InicioSemana   := dataInicial;
            FinalSemana    := dataInicial+6;
            panDom.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial );
            panSeg.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+1 );
            panTer.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+2 );
            panQua.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+3 );
            panQui.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+4 );
            panSex.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+5 );
            panSab.Caption := FormatDateTime( 'dd/mm/yyyy', dataInicial+6 );
         end;
   end;
end;

procedure Tfrmpraticas.spbantClick(Sender: TObject);// Procedure para mostrar a semana anterior
begin
   dataInicial := ( dataInicial - 7 );
   PosicionaSemana;
   ConsultaAgendamento;
end;

procedure Tfrmpraticas.spbproClick(Sender: TObject);// Procedure para mostrar a proxima semana
begin
   dataInicial := ( dataInicial + 7 );
   PosicionaSemana;
   ConsultaAgendamento;
end;

procedure Tfrmpraticas.ConsultaAgendamento;// Procedure para consultar os agendamentos dos Edits
var a, nDia : Integer;
begin
   for a := 0 to ComponentCount-1 do
      begin
         if ( Components[a] is TEdit ) then
            begin
               if ( Copy( ( Components[a] as TEdit ).Name, 01, 03 ) = 'ed_' ) then ( Components[a] as TEdit ).Text := '';
            end;
      end;
   ConsultaRegistros( 'Praticas',
                      'Aluno, Instrutor, Categoria, Data, Horario, Status',
                      'Instrutor=' + txtCodIns.Text +
                      ' AND Data BETWEEN ' +
                      #39 + FormatDateTime( 'mm/dd/yyyy', InicioSemana ) + #39 +
                      ' AND ' +
                      #39 + FormatDateTime( 'mm/dd/yyyy', FinalSemana ) + #39 +
                      ' ORDER BY Data, Horario' );

   while ( not dtmIza.qryiza.EOF ) do
      begin
         nDia := DayOfTheWeek( LeDados( 'Data' ) );
         if ( nDia <> 7 ) then nDia := nDia+1 else nDia := 1;

         if ( LeDados( 'Status' ) = 0 ) then
            begin
               TEdit( FindComponent( 'ed_' + IntToStr( nDia ) + FormatDateTime( 'hhnn', LeDados( 'Horario' ) ) ) ).Text := '**********';
            end
         else
            begin
               TEdit( FindComponent( 'ed_' + IntToStr( nDia ) + FormatDateTime( 'hhnn', LeDados( 'Horario' ) ) ) ).Text := StrZero( LeDados( 'Aluno' ), 6 );
               TEdit( FindComponent( 'ed_cat_' + IntToStr( nDia ) + FormatDateTime( 'hhnn', LeDados( 'Horario' ) ) ) ).Text := LeDados( 'Categoria' );
            end;
         dtmIza.qryiza.Next;
      end;
end;

procedure Tfrmpraticas.PreencheEdit( Sender : TObject );
begin 
   if ( Length( Trim( txtCod.Text ) ) = 0 ) then Exit;
   if ( Length( Trim( ( Sender as TEdit ).Text ) ) = 0 ) then

      begin
         if ( ConsultaRegistros( 'Praticas', 'Aluno',
                                 'Aluno=' + txtCod.Text + ' AND ' +
                                 'Data=' + #39 + FormatDateTime( 'mm/dd/yyyy', RetornaData( ( Sender as TEdit ).Name ) ) + #39 + ' AND ' +
                                 'Horario=' + #39 + FormatDateTime( 'hh:nn', RetornaHora( ( Sender as TEdit ).Name ) ) + #39 + ' AND ' +
                                 'Status=1' ) ) then
            begin
               ShowMessage( 'Aluno já tem aula marcada neste Horário!' );
               Exit;
            end;
         ( Sender as TEdit ).Text := StrZero( StrToFloat( txtCod.Text ), 6 );
         TEdit( FindComponent( 'ed_cat_' + Copy( ( Sender as TEdit ).Name, 4, 5 ) ) ).Text := txtCat.Text;
         // salva a aula na tabela
         with vCpo do
            begin
               Clear;
               Add( 'Aluno' );
               Add( 'Instrutor' );
               Add( 'Categoria' );
               Add( 'Data' );
               Add( 'Horario' );
               Add( 'Status' );
            end;
         with vVlr do
            begin
               Clear;
               Add( txtCod.Text );
               Add( txtCodIns.Text );
               Add( #39 + txtCat.Text + #39 );
               Add( #39 + FormatDateTime( 'mm/dd/yyyy', RetornaData( ( Sender as TEdit ).Name ) ) + #39 );
               Add( #39 + FormatDateTime( 'hh:nn', RetornaHora( ( Sender as TEdit ).Name ) ) + #39 );
               Add( '1' );
            end;
         IncluirRegistro( 'Praticas', vCpo, vVlr );
      end
   else
      begin
         if ( ( Sender as TEdit ).Text <> txtCod.Text ) then
         begin
            ShowMessage( 'Código do Aluno não confere com o Nome do mesmo selecionado!' );
            Exit;
         end;
         ExcluirRegistro( 'Praticas',
                          'Aluno=' + ( Sender as TEdit ).Text + ' AND ' +
                          'Instrutor=' + txtCodIns.Text + ' AND ' +
                          'Categoria=' + #39 + TEdit( FindComponent( 'ed_cat_' + Copy( ( Sender as TEdit ).Name, 4, 5 ) ) ).Text + #39 + ' AND ' +
                          'Data=' + #39 + FormatDateTime( 'mm/dd/yyyy', RetornaData( ( Sender as TEdit ).Name ) ) + #39 + ' AND ' +
                          'Horario=' + #39 + FormatDateTime( 'hh:nn', RetornaHora( ( Sender as TEdit ).Name ) ) + #39 );
         ( Sender as TEdit ).Text := '';
         TEdit( FindComponent( 'ed_cat_' + Copy( ( Sender as TEdit ).Name, 4, 5 ) ) ).Text := '';
      end;
    ConsultaAula;
end;

function Tfrmpraticas.RetornaData(edit: String) : TDate;// Função para Retornar as datas
var nDia : Integer;
begin
   nDia := StrToInt( Copy( edit, 4, 1 ) );

   case nDia of
      1 : Result := StrToDate( panDom.Caption );
      2 : Result := StrToDate( panSeg.Caption );
      3 : Result := StrToDate( panTer.Caption );
      4 : Result := StrToDate( panQua.Caption );
      5 : Result := StrToDate( panQui.Caption );
      6 : Result := StrToDate( panSex.Caption );
      7 : Result := StrToDate( panSab.Caption );
   end;
end;

function Tfrmpraticas.RetornaHora(edit: String): TTime;// Função para retornar as horas
begin
   Result := StrToTime( Copy( edit, 5, 2 ) + ':' + Copy( edit, 7, 2 ) );
end;

procedure Tfrmpraticas.txtcodinsExit(Sender: TObject);
begin
   ConsultaAgendamento;
end;

procedure Tfrmpraticas.BloqueioDesbloqueio(Sender: TObject; var Key: Word;// Procedure para bloquear os Horarios
  Shift: TShiftState);
begin
   if ( Length( Trim( txtCodIns.Text ) ) = 0 ) then Exit;

   if ( Key = Ord( 'B' ) ) then  // Tecla para desbloqueio 'B'
      begin
         ( Sender as TEdit ).Text := '**********';
         SalvaBloqueio( Sender );
      end;
   if ( Key = Ord( 'D' ) ) then // Tecla para desbloqueio 'D'
      begin
         RemoveBloqueio( Sender );
         ( Sender as TEdit ).Text := '';
      end;
end;

procedure Tfrmpraticas.RemoveBloqueio( Sender : TObject );// Procedure para excluir os Bloqueio
begin
   ExcluirRegistro( 'Praticas',
                    'Instrutor=' + txtCodIns.Text + ' AND ' +
                    'Categoria=' + #39 + 'A' + #39 + ' AND ' +
                    'Data=' + #39 + FormatDateTime( 'mm/dd/yyyy', RetornaData( ( Sender as TEdit ).Name ) ) + #39 + ' AND ' +
                    'Horario=' + #39 + FormatDateTime( 'hh:nn', RetornaHora( ( Sender as TEdit ).Name ) ) + #39 + ' AND ' +
                    'Status=0' );
end;

procedure Tfrmpraticas.SalvaBloqueio( Sender : TObject );// Procedure para salvar os Bloqueio
begin
   with vCpo do
      begin
         Clear;
         Add ( 'Aluno' );
         Add ( 'Instrutor' );
         Add ( 'Categoria' );
         Add ( 'Data' );
         Add ( 'Horario' );
         Add ( 'Status' );
      end;
   with vVlr do
      begin
         Clear;
         Add ( #39 + TxtCod.Text + #39 );
         Add ( #39 + TxtCodIns.Text + #39 );
         Add ( #39 + TxtCat.Text + #39 );
         Add ( #39 + FormatDateTime( 'mm/dd/yyyy', RetornaData( ( Sender as TEdit ).Name ) ) + #39 );
         Add ( #39 + FormatDateTime( 'hh:nn', RetornaHora( ( Sender as TEdit ).Name ) ) + #39 );
         Add ( '0' );
      end;
   IncluirRegistro( 'Praticas', vCpo, vVlr );
end;

procedure Tfrmpraticas.spbalulocClick(Sender: TObject);
begin
   with vcpo do
      begin
         clear;
         add ('Codigo');
         add ('Nome');
         add ('Cpf');
         add ('Processo');
      end;
   with vvlr do
      begin
         clear;
         add ('Codigo');
         add ('Nome');
         add ('Cpf');
         add ('Processo');
      end;

   with tfrmpesquisa.create (application) do
      begin
         try
            tabela := 'Alunos';
            camporetorno := 'Codigo';
            showmodal;
         finally
            free;
      end;
   end;
   if ( Retorno <> '' ) then
      begin
         inherited;
         ConsultaRegistros( 'Alunos', 'Codigo, Nome', 'Codigo=' + Retorno );
         LeRegistro();
      end;
   TxtCod.Text := StrZero (StrToFloat(TxtCod.Text), 6);
   SbpInst.Enabled := True;
   TxtCod.Enabled := False;
end;

procedure Tfrmpraticas.LeRegistro;
begin
   txtCod.Text   := LeDados ( 'Codigo' );
   txtAluno.Text := LeDados ( 'Nome'   );
   ConsultaAula;
end;

procedure Tfrmpraticas.SbpInstClick(Sender: TObject);
begin
 with vcpo do
      begin
         clear;
         add ('Codigo');
         add ('Nome');
      end;
   with vvlr do
      begin
         clear;
         add ('Codigo');
         add ('Nome');
      end;

   with tfrmpesquisa.create (application) do
      begin
         try
            tabela       := 'Instrutores';
            camporetorno := 'codigo';
            showmodal;
         finally
            free;
      end;
   end;
   if (retorno<> '') then
      begin
         ConsultaRegistros( 'Instrutores', 'Nome', 'Codigo=' + Retorno );
         txtCodIns.Text  := Retorno;
         txtNomIns.Text  := LeDados ( 'Nome' );
       end;
   ConsultaAgendamento;
   TxtCodIns.Text := StrZero( StrToFloat( txtCodIns.Text ), 2 );
   SpbCat.Enabled := True;
   TxtCodIns.Enabled := False;
end;

procedure Tfrmpraticas.SpbCatClick(Sender: TObject);
begin
 with vcpo do
      begin
         clear;
         add ( 'Codigo' );
         add ( 'Nome' );
         add ( 'Categoria' );
      end;
   with vvlr do
      begin
         clear;
         add ( 'Codigo' );
         add ( 'Nome' );
         add ( 'Categoria' );
      end;
   with tfrmpesquisa.create (application) do
      begin
         try
            tabela       := 'Veiculos';
            camporetorno := 'codigo';
            showmodal;
         finally
            free;
        end;
   end;
   if (retorno<> '') then
      begin
         ConsultaRegistros( 'Veiculos', 'Codigo, Categoria, Nome', 'Codigo=' + Retorno );
         txtCodCat.Text := Retorno;
         txtCat.Text    := LeDados ('Categoria');
         TxtVei.Text    := LeDados ('Nome'     );
      end;
   TxtCodCat.Text := StrZero( StrToFloat( txtCodCat.Text ), 3 );
   SpbAnt.Enabled := True;
   SpbPro.Enabled := True;
   SpbImp.Enabled := True;
   TxtCodCat.Enabled := False;
end;

procedure Tfrmpraticas.ConsultaAula;
Begin
  With QryPra do
      Begin
         Close;
         Sql.Clear;
         Sql.Add ('Select P.Aluno, P.Instrutor, P.Data, P.Horario, P.Categoria, P.Aluno From Praticas P,'
                  +'Instrutores I Where P.Aluno=' + txtcod.Text +
                   'AND P.Status=1 AND I.Codigo=P.Instrutor ORDER BY P.Data, P.Horario');
         Open;
      end;
end;


procedure Tfrmpraticas.AppEventsMessage(var Msg: TMsg; var Handled: Boolean);  // para a a bolinha do mouse rolar
var
  Sentido: SmallInt;
  WndClass :array[0..128] of char;
begin
  if Msg.message = WM_MOUSEWHEEL then
    begin
       GetClassName(Msg.hwnd, WndClass, SizeOf(WndClass)-1);
       if StrComp(WndClass, 'TDBGrid') = 0 then
          begin
             Msg.message := WM_KEYDOWN;
             Msg.lParam := 0;
             Sentido := HiWord(Msg.wParam);
             if Sentido > 0 then
             Msg.wParam := VK_UP
         else
             Msg.wParam := VK_DOWN;
         end;
    End;
end;

procedure Tfrmpraticas.DbgRelDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
Begin
   If odd(linha) then   //  coloque aqui a sua query ou table
      begin
         DbgRel.Canvas.Font.Color:= clBlack;
         DbgRel.Canvas.Brush.Color:= cl3DLight;
      end
   else
      begin
         DbgRel.Canvas.Font.Color:= clBlack;
         DbgRel.Canvas.Brush.Color:= clMoneyGreen;
      end;
   DbgRel.Canvas.FillRect(Rect);
   DbgRel.DefaultDrawColumnCell(Rect, DataCol, Column, State);

   if ( DataCol = 4 ) then inc( linha );
end;


end.

Link para o comentário
Compartilhar em outros sites

  • 0
A tabela que eu marco aulas praticas é feita em tempo de execução:

Coloquei dois tipos de edits um para aulas de carro e outro moto

TxtCarro

TxtMoto

E mais dois para aulas extras

TxtExtCarro

TXTExtMoto

É assim: Todos os alunos tem direito a 15 aulas de carro e 15 de moto então após ser marcado as 15 aulas ai contasse

como aulas extras e registrasse no outro edit.

a) Pelo que entendi do seu codigo voce esta contabilizando as aulas como sendo data e hora, ou seja, uma data e uma hora

conta como sendo 1 aula.

B) voce definiu TxtMoto: TEdit; TxtCarro: TEdit; mas não achei a definição de TxtExtCarro e TXTExtMoto

c) como voce procura pelo componente usando " TEdit( FindComponent( 'ed_'..." não achei onde voce trabalha com o TxtMoto

e o TxtCarro.

d) entretanto nesta parte do codigo, acho que voce pode fazer o que está querendo ( após ser marcado as 15 aulas ai contasse

como aulas extras e registrasse no outro edit.)

procedure Tfrmpraticas.ConsultaAula;
Begin
  With QryPra do
      Begin
         Close;
         Sql.Clear;
         Sql.Add ('Select P.Aluno, P.Instrutor, P.Data, P.Horario, P.Categoria, P.Aluno From Praticas P,'
                  +'Instrutores I Where P.Aluno=' + txtcod.Text +
                   'AND P.Status=1 AND I.Codigo=P.Instrutor ORDER BY P.Data, P.Horario');
         Open;
      end;

  if QryPra.recordcount <= 15 then
     begin
        // quantidade de aulas menor ou igual a 15


     end
  else
     begin
        // quantidade de aulas maior que 15



     end;
end;

Nesta rotina voce pode implementar o resto do codigo para fazer o que esta querendo, é mais ou menos isto ?

Link para o comentário
Compartilhar em outros sites

  • 0

Ok, Jhonas consegui resolver com ajuda do meu professor e conclui nesse resultado.

Fiz um procedimento no banco de dados e atribui no delphi também.

No banco de dados:

CREATE PROCEDURE STPCSLAUL (
    palu numeric(6,0))
returns (
    pord numeric(3,0),
    pins numeric(2,0),
    pdat date,
    phor time,
    pcat char(2))
as
BEGIN
   pOrd = 0;
   FOR Select P.Instrutor, P.Data, P.Horario, P.Categoria
       From Praticas P, Instrutores I
       Where P.Aluno=:pAlu AND P.Status=1 AND
       I.Codigo=P.Instrutor ORDER BY P.Data, P.Horario
       INTO :pIns, :pDat, :pHor, :pCat
   DO
   BEGIN
      pOrd = :pOrd + 1;
      SUSPEND;
   END
END^

SET TERM; ^

GRANT SELECT ON PRATICAS TO PROCEDURE STPCSLAUL;

GRANT SELECT ON INSTRUTORES TO PROCEDURE STPCSLAUL;

GRANT EXECUTE ON PROCEDURE STPCSLAUL TO SYSDBA;
procedure Tfrmpraticas.ConsultaAula;
var aulasCarro, aulasMoto : integer;
Begin
   With QryPra do
     Begin
        Close;
        Sql.Clear;
        Sql.Add ( 'SELECT * FROM stpCslAul( ' + txtcod.Text + ' );' );
        Open;
     end;

   aulasCarro := 0;
   aulasMoto  := 0;

   while ( not qryPra.Eof ) do
   begin
      if ( Trim( qryPra.FieldByName( 'pCat' ).AsString ) = 'A' ) then
      begin
         Inc( aulasMoto );
      end
      else
      begin
         Inc( aulasCarro );
      end;

      if ( aulasMoto <= 15 ) then
      begin
         txtMoto.Text := IntToStr( aulasMoto );
         Edit1.Text   := '0';
      end
      else
      begin
         txtMoto.Text := '15';
         Edit1.Text   := IntToStr( aulasMoto - 15 );
      end;

      if ( aulasCarro <= 15 ) then
      begin
         txtCarro.Text := IntToStr( aulasCarro );
         Edit2.Text   := '0';
      end
      else
      begin
         txtCarro.Text := '15';
         Edit2.Text   := IntToStr( aulasCarro - 15 );
      end;
      qryPra.Next;
   end;

end;

Com isso resolvi o meu problema, mas também gostaria de saber algo em cima desse tema, no grid que eu mostro os dados cadastrados, queria colocar o seguinte que acima dos quinze ele mostrasse de outra cor.

Link para o comentário
Compartilhar em outros sites

  • 0

Ok, Obrigado Jhonas consegui resolver, mas como são 15 aulas de carro e moto no agendamento, então eu tive que fazer assim:Resolvido

procedure Tfrmpraticas.DbgRelDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
Begin

   If odd( qryPra.FieldByName( 'pOrd' ).AsInteger ) then   //  coloque aqui a sua query ou table
      begin
         DbgRel.Canvas.Font.Color:= clBlack;
         DbgRel.Canvas.Brush.Color:= cl3DLight;
      end
   else
      begin
         DbgRel.Canvas.Font.Color:= clBlack;
         DbgRel.Canvas.Brush.Color:= clMoneyGreen;
      end;
            if qryPra.FieldByName('pOrd').value >= 31 then
            begin
               DbgRel.Canvas.Font.Color:= clRed;
               DbgRel.Canvas.FillRect(Rect);
            end;
   DbgRel.Canvas.FillRect(Rect);
   DbgRel.DefaultDrawColumnCell(Rect, DataCol, Column, State);

      end;

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152k
    • Posts
      651,8k
×
×
  • Criar Novo...