Ir para conteúdo
Fórum Script Brasil

Alessandro

Membros
  • Total de itens

    160
  • Registro em

  • Última visita

Posts postados por Alessandro

  1. Quero somar duas variaveis que são do tipo TIME (uso mysql).

    $tempo1: 00:20:50 (hh/mm/ss)

    $tempo2: 00:20:15 (hh/mm/ss)

    Gostaria de somar essas duas variáveis obtendo o seguinte resultado:

    $result: 00:41:05 (hh/mm/ss)

    Será que você pode me ajudar ??

    Obrigado.

  2. CONSEGUIMOS biggrin.gif

    É corposemalma...você está certo...eu não me conformei com o fato de ter tudo rolando no dbGrid e no Relatório dar errado....

    O problema foi o seguinte :

    O objeto que recebia os códigos era um QRExpression, ele que não deixava aparecer os selecionados....

    Eu mudei de componente, coloquei um QRDBText para testar, apontei o Form que gerar o Relatório e funcionou que foi uma beleza.....

    Foram 90 posts, dei muito trabalho para você o principalmente o s3c...obrigado ao Arlon também....

    Olha o resultado

    O sistema está pronto, só faltava isso...gerar os selecionados......agora eu vou fazer os ajustes galera......muito obrigado mesmo...

    Senão fosse aqui eu estaria perdido.....

    PS.Visita o meu blog e dá uma olhada no agradecimento que fiz a vocês :

    Meu blog

    biggrin.gifbiggrin.gifbiggrin.gif

  3. Nada....não deixei nada no DataSource do dbGrid e mesmo assim o relatório saiu na mesma.... wink.gif , eu estou achando que o QuickReport está com alguma propriedade que não deixa isso acontecer...pois quando a gente usar somente o QuickRep1.Preview, aparecem todos, se o código funciona redondinho no dbGrid, só não funcionaria no Relatório por este motivo.....

    Ps..qualquer besteira que eu falei aqui, desconsidere... biggrin.gif

  4. Lá no final eu chamo assim :

    fmRelAt := tfmRelAt.Create(application);

    fmRelAt.QuickRep1.Preview;

    fmRelAt.Release

    procedure TfmGerarRelAt.SpeedButton1Click(Sender: TObject);
    var i:Integer; sWhe:String;
    begin
      Query1.Close;
    
      sWhe := 'Select CodPart,NomeFant,Quantidade From dbCadAt.db ';
    
      for i := 0 to Lista2.Items.Count-1 do
      begin
        if Lista2.Items.Count > 10 then
        begin
          MessageDLG('Você ultrapassou a capacidade de itens selecionados!',mtWarning,[mbok],0);
          abort;
        end
        else begin
          if i = 0 then
            begin
              sWhe := sWhe + 'Where (CodPart = :P' + IntToStr(i) +')'
            end
           else begin
            sWhe := sWhe + ' or (CodPart = :P' + IntToStr(i) + ')';
           end;
        end;
      end;
      Query1.SQL.Text := sWhe;
    
      ShowMessage(sWhe);
    
      for i := 0 to Lista2.Items.Count-1 do
       begin
        Query1.ParamByName('P'+IntToStr(i)).asString := Lista2.Items[i];
       end;
    
        Query1.Open;
    
        fmRelAt := tfmRelAt.Create(application);
        fmRelAt.QuickRep1.Preview;
        fmRelAt.Release 

  5. Bom...vamos ver se entendi....

    No QuickRep1, a propriedade DataSet está apontando para :

    fmGerarRelAt.Query1

    Era isso que você queria saber ?! wink.gif

    Ahh, consegui o View as Text do Relatório....ajuda ?!?!

    object fmRelAt: TfmRelAt
      Left = 210
      Top = 163
      Width = 681
      Height = 493
      Caption = 'Relatório de Ligações'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      Scaled = False
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 13
      object QuickRep1: TQuickRep
        Left = 0
        Top = 0
        Width = 794
        Height = 1123
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        DataSet = fmGerarRelAt.Query1
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -13
        Font.Name = 'Verdana'
        Font.Style = []
        Functions.Strings = (
          'PAGENUMBER'
          'COLUMNNUMBER'
          'REPORTTITLE')
        Functions.DATA = (
          '0'
          '0'
          '''''')
        Options = [FirstPageHeader, LastPageFooter]
        Page.Columns = 1
        Page.Orientation = poPortrait
        Page.PaperSize = A4
        Page.Values = (
          100
          2970
          100
          2100
          100
          100
          0)
        PrinterSettings.Copies = 1
        PrinterSettings.Duplex = False
        PrinterSettings.FirstPage = 0
        PrinterSettings.LastPage = 0
        PrinterSettings.OutputBin = Auto
        PrintIfEmpty = True
        SnapToGrid = True
        Units = MM
        Zoom = 100
        object PageFooterBand1: TQRBand
          Left = 38
          Top = 122
          Width = 718
          Height = 22
          Frame.Color = clBlack
          Frame.DrawTop = False
          Frame.DrawBottom = False
          Frame.DrawLeft = False
          Frame.DrawRight = False
          AlignToBottom = False
          Color = clWhite
          ForceNewColumn = False
          ForceNewPage = False
          Size.Values = (
            58.2083333333333
            1899.70833333333)
          BandType = rbPageFooter
          object QRExpr1: TQRExpr
            Left = 574
            Top = 0
            Width = 144
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              1518.70833333333
              0
              381)
            Alignment = taRightJustify
            AlignToBand = True
            AutoSize = True
            AutoStretch = False
            Color = clWhite
            ResetAfterPrint = False
            Transparent = False
            WordWrap = True
            Expression = '''Page '' + PageNumber'
            FontSize = 10
          end
        end
        object ColumnHeaderBand1: TQRBand
          Left = 38
          Top = 78
          Width = 718
          Height = 22
          Frame.Color = clBlack
          Frame.DrawTop = False
          Frame.DrawBottom = False
          Frame.DrawLeft = False
          Frame.DrawRight = False
          AlignToBottom = False
          Color = clWhite
          ForceNewColumn = False
          ForceNewPage = False
          Size.Values = (
            58.2083333333333
            1899.70833333333)
          BandType = rbColumnHeader
          object QRLabel1: TQRLabel
            Left = 41
            Top = 0
            Width = 112
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = True
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              108.479166666667
              0
              296.333333333333)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = False
            AutoStretch = False
            Caption = 'Código Partner'
            Color = clWhite
            Font.Charset = DEFAULT_CHARSET
            Font.Color = clWindowText
            Font.Height = -13
            Font.Name = 'Verdana'
            Font.Style = [fsBold]
            ParentFont = False
            Transparent = False
            WordWrap = True
            FontSize = 10
          end
          object QRLabel2: TQRLabel
            Left = 182
            Top = 0
            Width = 107
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = True
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              481.541666666667
              0
              283.104166666667)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = False
            AutoStretch = False
            Caption = 'Nome Fantasia'
            Color = clWhite
            Font.Charset = DEFAULT_CHARSET
            Font.Color = clWindowText
            Font.Height = -13
            Font.Name = 'Verdana'
            Font.Style = [fsBold]
            ParentFont = False
            Transparent = False
            WordWrap = True
            FontSize = 10
          end
          object QRLabel3: TQRLabel
            Left = 443
            Top = 0
            Width = 86
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = True
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              1172.10416666667
              0
              227.541666666667)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = False
            AutoStretch = False
            Caption = 'Ligações'
            Color = clWhite
            Font.Charset = DEFAULT_CHARSET
            Font.Color = clWindowText
            Font.Height = -13
            Font.Name = 'Verdana'
            Font.Style = [fsBold]
            ParentFont = False
            Transparent = False
            WordWrap = True
            FontSize = 10
          end
          object QRLabel5: TQRLabel
            Left = 640
            Top = 0
            Width = 61
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              1693.33333333333
              0
              161.395833333333)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = True
            AutoStretch = False
            Caption = 'QRLabel5'
            Color = clWhite
            Transparent = False
            WordWrap = True
            FontSize = 10
          end
          object QRLabel6: TQRLabel
            Left = 587
            Top = 0
            Width = 46
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = True
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              1553.10416666667
              0
              121.708333333333)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = False
            AutoStretch = False
            Caption = 'Total'
            Color = clWhite
            Font.Charset = DEFAULT_CHARSET
            Font.Color = clWindowText
            Font.Height = -13
            Font.Name = 'Verdana'
            Font.Style = [fsBold]
            ParentFont = False
            Transparent = False
            WordWrap = True
            FontSize = 10
          end
        end
        object DetailBand1: TQRBand
          Left = 38
          Top = 100
          Width = 718
          Height = 22
          Frame.Color = clBlack
          Frame.DrawTop = False
          Frame.DrawBottom = False
          Frame.DrawLeft = False
          Frame.DrawRight = False
          AlignToBottom = False
          Color = clWhite
          ForceNewColumn = False
          ForceNewPage = False
          Size.Values = (
            58.2083333333333
            1899.70833333333)
          BandType = rbDetail
          object QRExpr2: TQRExpr
            Left = 41
            Top = 0
            Width = 64
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              108.479166666667
              0
              169.333333333333)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = False
            AutoStretch = False
            Color = clWhite
            ResetAfterPrint = False
            Transparent = False
            WordWrap = True
            Expression = '[CodPart]'
            FontSize = 10
          end
          object QRExpr3: TQRExpr
            Left = 182
            Top = 0
            Width = 259
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              481.541666666667
              0
              685.270833333333)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = False
            AutoStretch = False
            Color = clWhite
            ResetAfterPrint = False
            Transparent = False
            WordWrap = True
            Expression = '[NomeFant]'
            FontSize = 10
          end
          object QRExpr4: TQRExpr
            Left = 443
            Top = 0
            Width = 86
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              1172.10416666667
              0
              227.541666666667)
            Alignment = taRightJustify
            AlignToBand = False
            AutoSize = False
            AutoStretch = False
            Color = clWhite
            ResetAfterPrint = False
            Transparent = False
            WordWrap = True
            Expression = '[Quantidade]'
            FontSize = 10
          end
          object QRExpr5: TQRExpr
            Left = 0
            Top = 0
            Width = 47
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              0
              0
              124.354166666667)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = True
            AutoStretch = False
            Color = clWhite
            ResetAfterPrint = False
            Transparent = False
            WordWrap = True
            Expression = 'COUNT'
            FontSize = 10
          end
        end
        object TitleBand1: TQRBand
          Left = 38
          Top = 38
          Width = 718
          Height = 40
          Frame.Color = clBlack
          Frame.DrawTop = False
          Frame.DrawBottom = False
          Frame.DrawLeft = False
          Frame.DrawRight = False
          AlignToBottom = False
          Color = clWhite
          ForceNewColumn = False
          ForceNewPage = False
          Size.Values = (
            105.833333333333
            1899.70833333333)
          BandType = rbTitle
          object QRLabel4: TQRLabel
            Left = 112
            Top = 8
            Width = 506
            Height = 26
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              68.7916666666667
              296.333333333333
              21.1666666666667
              1338.79166666667)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = True
            AutoStretch = False
            Caption = 'Relatório de Ligações das Assistências Técnicas'
            Color = clWhite
            Font.Charset = DEFAULT_CHARSET
            Font.Color = clWindowText
            Font.Height = -21
            Font.Name = 'Verdana'
            Font.Style = []
            ParentFont = False
            Transparent = False
            WordWrap = True
            FontSize = 16
          end
        end
      end
      object Table1: TTable
        Active = True
        DatabaseName = 'Projeto'
        TableName = 'dbCadAt.DB'
        Left = 7
        Top = 8
      end
      object Query1: TQuery
        DatabaseName = 'Projeto'
        Left = 48
        Top = 8
      end
      object DataSource1: TDataSource
        DataSet = Query1
        Left = 88
        Top = 8
      end
    end

  6. Unit Principal

    unit U_Principal;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Menus, ComCtrls, ExtCtrls, Buttons, StdCtrls, DBCtrls;
    
    type
      TfmPrincipal = class(TForm)
        MainMenu1: TMainMenu;
        Cadastro1: TMenuItem;
        CadastrodeAT1: TMenuItem;
        CadastrodeUsurio1: TMenuItem;
        Atendimento1: TMenuItem;
        Script1: TMenuItem;
        Relatrios1: TMenuItem;
        Usurios1: TMenuItem;
        Assistm1: TMenuItem;
        Listas1: TMenuItem;
        OSCancelada1: TMenuItem;
        InsumosSolicitados1: TMenuItem;
        Ajuda1: TMenuItem;
        Sair1: TMenuItem;
        StatusBar1: TStatusBar;
        Timer1: TTimer;
        SpeedButton1: TSpeedButton;
        SpeedButton2: TSpeedButton;
        SpeedButton3: TSpeedButton;
        SpeedButton4: TSpeedButton;
        SpeedButton5: TSpeedButton;
        SpeedButton6: TSpeedButton;
        procedure FormCreate(Sender: TObject);
        procedure Sair1Click(Sender: TObject);
        procedure CadastrodeAT1Click(Sender: TObject);
        procedure CadastrodeUsurio1Click(Sender: TObject);
        procedure Usurios1Click(Sender: TObject);
        procedure Assistm1Click(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        procedure Script1Click(Sender: TObject);
        procedure OSCancelada1Click(Sender: TObject);
        procedure SpeedButton1Click(Sender: TObject);
        procedure SpeedButton3Click(Sender: TObject);
        procedure SpeedButton2Click(Sender: TObject);
        procedure SpeedButton4Click(Sender: TObject);
        procedure InsumosSolicitados1Click(Sender: TObject);
        procedure SpeedButton5Click(Sender: TObject);
        procedure SpeedButton6Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      fmPrincipal: TfmPrincipal;
    
    implementation
    
    uses U_CadUsu, U_CadAt, U_RelAt, U_RelUsu, U_CadOsCancel, U_Suporte,
      U_GerarRelAt;
    
    {$R *.dfm}
    
    procedure TfmPrincipal.FormCreate(Sender: TObject);
    var Data: TDateTime;
    begin
      Data := Now;
      StatusBar1.Panels[1].Text := FormatDateTime('dddd," "dd" de "mmmm" de "yyyy',Data);
      WindowState := wsMaximized;
      SetWindowLong(Application.Handle,GWL_EXSTYLE,
      GetWindowLong(Application.Handle, GWL_EXSTYLE)
      or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);
    end;
    
    procedure TfmPrincipal.Sair1Click(Sender: TObject);
    begin
     if MessageDlg('Deseja sair do Sistema ?',mtConfirmation,[mbyes,mbno],0) = mrYes then
       begin
         Application.Terminate;
       end
    end;
    
    procedure TfmPrincipal.CadastrodeAT1Click(Sender: TObject);
    begin
      fmCadAt := tfmCadAt.create(application);
      fmCadAt.showmodal; // abre o formulário no modo moldal para não perder o foco
      fmCadAt.Release;  //apaga form da memória quando o mesmo for fechado
    end;
    
    procedure TfmPrincipal.CadastrodeUsurio1Click(Sender: TObject);
    begin
    fmCadUsu := tfmCadUsu.create(application);
      fmCadUsu.showmodal; // abre o formulário no modo moldal para não perder o foco
      fmCadUsu.Release;  //apaga form da memória quando o mesmo for fechado
    end;
    
    procedure TfmPrincipal.Usurios1Click(Sender: TObject);
    begin
        fmGerarRelAt := tfmGerarRelAt.Create(application);
        fmGerarRelAt.ShowModal;
        fmGerarRelAt.Release;
    end;
    
    procedure TfmPrincipal.Assistm1Click(Sender: TObject);
    begin
      fmRelUsu := tfmRelUsu.create(application);
      fmRelUsu.QuickRep1.Preview; 
      fmRelUsu.Release;  //apaga form da memória quando o mesmo for fechado
    end;
    
    procedure TfmPrincipal.Timer1Timer(Sender: TObject);
    begin
    StatusBar1.Panels[2].Text := timetostr(time);
    end;
    
    procedure TfmPrincipal.Script1Click(Sender: TObject);
    begin
    WinExec('c:\Projeto\Script.exe', sw_normal);
    WindowState :=  wsMinimized;
    end;
    
    procedure TfmPrincipal.OSCancelada1Click(Sender: TObject);
    begin
      fmCadOsCancel := tfmCadOsCancel.create(application);
      fmCadOsCancel.showmodal; // abre o formulário no modo moldal para não perder o foco
      fmCadOsCancel.Release;  //apaga form da memória quando o mesmo for fechado
    end;
    
    procedure TfmPrincipal.SpeedButton1Click(Sender: TObject);
    begin
      fmCadAt := tfmCadAt.create(application);
      fmCadAt.showmodal; // abre o formulário no modo moldal para não perder o foco
      fmCadAt.Release;  //apaga form da memória quando o mesmo for fechado
    end;
    
    procedure TfmPrincipal.SpeedButton3Click(Sender: TObject);
    begin
      fmCadOsCancel := tfmCadOsCancel.create(application);
      fmCadOsCancel.showmodal; // abre o formulário no modo moldal para não perder o foco
      fmCadOsCancel.Release;  //apaga form da memória quando o mesmo for fechado
    end;
    
    procedure TfmPrincipal.SpeedButton2Click(Sender: TObject);
    begin
    fmCadUsu := tfmCadUsu.create(application);
      fmCadUsu.showmodal; // abre o formulário no modo moldal para não perder o foco
      fmCadUsu.Release;  //apaga form da memória quando o mesmo for fechado
    end;
    
    procedure TfmPrincipal.SpeedButton4Click(Sender: TObject);
    begin
      fmGerarRelAt := tfmGerarRelAt.create(application);
      fmGerarRelAt.showModal;
      fmGerarRelAt.Release;  //apaga form da memória quando o mesmo for fechado
    end;
    
    procedure TfmPrincipal.InsumosSolicitados1Click(Sender: TObject);
    begin
    fmSuporte := tfmSuporte.create(application);
    fmSuporte.showmodal;
    fmSuporte.Release;
    end;
    
    procedure TfmPrincipal.SpeedButton5Click(Sender: TObject);
    begin
    fmSuporte := tfmSuporte.create(application);
    fmSuporte.showmodal;
    fmSuporte.Release;
    end;
    
    procedure TfmPrincipal.SpeedButton6Click(Sender: TObject);
    begin
     if MessageDlg('Deseja sair do Sistema ?',mtConfirmation,[mbyes,mbno],0) = mrYes then
       begin
         Application.Terminate;
       end
    end;
    
    end.
    Unit do GerarRelAt
    unit U_GerarRelAt;
    
    interface
    
    uses 
      Windows, Messages, SysUtils, Classes, Graphics, Forms, Dialogs, Controls, StdCtrls, 
      Buttons, DB, DBTables, Grids, DBGrids;
    
    type
      TfmGerarRelAt = class(TForm)
        Lista1: TListBox;
        Lista2: TListBox;
        SrcLabel: TLabel;
        DstLabel: TLabel;
        IncludeBtn: TSpeedButton;
        IncAllBtn: TSpeedButton;
        ExcludeBtn: TSpeedButton;
        ExAllBtn: TSpeedButton;
        SpeedButton1: TSpeedButton;
        SpeedButton2: TSpeedButton;
        Label1: TLabel;
        DBGrid1: TDBGrid;
        DataSource1: TDataSource;
        Query1: TQuery;
        procedure IncludeBtnClick(Sender: TObject);
        procedure ExcludeBtnClick(Sender: TObject);
        procedure IncAllBtnClick(Sender: TObject);
        procedure ExcAllBtnClick(Sender: TObject);
        procedure btnCancelClick(Sender: TObject);
        procedure btnGerarClick(Sender: TObject);
        procedure SpeedButton1Click(Sender: TObject);
        procedure SpeedButton2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure MoveSelected(List: TCustomListBox; Items: TStrings);
        procedure SetItem(List: TListBox; Index: Integer);
        function GetFirstSelection(List: TCustomListBox): Integer;
        procedure SetButtons;
      end;
    
    var
      fmGerarRelAt: TfmGerarRelAt;
    
    implementation
    
    uses U_RelAt, dataProjeto, U_CadAt;
    
    {$R *.dfm}
    
    procedure TfmGerarRelAt.IncludeBtnClick(Sender: TObject);
    var
      Index: Integer;
    begin
      Index := GetFirstSelection(Lista1);
      MoveSelected(Lista1, Lista2.Items);
      SetItem(Lista1, Index);
    end;
    
    procedure TfmGerarRelAt.ExcludeBtnClick(Sender: TObject);
    var
      Index: Integer;
    begin
      Index := GetFirstSelection(Lista2);
      MoveSelected(Lista2, Lista1.Items);
      SetItem(Lista2, Index);
    end;
    
    procedure TfmGerarRelAt.IncAllBtnClick(Sender: TObject);
    var
      I: Integer;
    begin
      for I := 0 to Lista1.Items.Count - 1 do
        Lista2.Items.AddObject(Lista1.Items[I],
          Lista1.Items.Objects[I]);
      Lista1.Items.Clear;
      SetItem(Lista1, 0);
    end;
    
    procedure TfmGerarRelAt.ExcAllBtnClick(Sender: TObject);
    var
      I: Integer;
    begin
      for I := 0 to Lista2.Items.Count - 1 do
        Lista1.Items.AddObject(Lista2.Items[I], Lista2.Items.Objects[I]);
      Lista2.Items.Clear;
      SetItem(Lista2, 0);
    end;
    
    procedure TfmGerarRelAt.MoveSelected(List: TCustomListBox; Items: TStrings);
    var
      I: Integer;
    begin
      for I := List.Items.Count - 1 downto 0 do
        if List.Selected[I] then
        begin
          Items.AddObject(List.Items[I], List.Items.Objects[I]);
          List.Items.Delete(I);
        end;
    end;
    
    procedure TfmGerarRelAt.SetButtons;
    var
      SrcEmpty, DstEmpty: Boolean;
    begin
      SrcEmpty := Lista1.Items.Count = 0;
      DstEmpty := Lista2.Items.Count = 0;
      IncludeBtn.Enabled := not SrcEmpty;
      IncAllBtn.Enabled := not SrcEmpty;
      ExcludeBtn.Enabled := not DstEmpty;
      ExAllBtn.Enabled := not DstEmpty;
    end;
    
    function TfmGerarRelAt.GetFirstSelection(List: TCustomListBox): Integer;
    begin
      for Result := 0 to List.Items.Count - 1 do
        if List.Selected[Result] then Exit;
      Result := LB_ERR;
    end;
    
    procedure TfmGerarRelAt.SetItem(List: TListBox; Index: Integer);
    var
      MaxIndex: Integer;
    begin
      with List do
      begin
        SetFocus;
        MaxIndex := List.Items.Count - 1;
        if Index = LB_ERR then Index := 0
        else if Index > MaxIndex then Index := MaxIndex;
        Selected[Index] := True;
      end;
      SetButtons;
    end;
    
    procedure TfmGerarRelAt.btnCancelClick(Sender: TObject);
    begin
    fmGerarRelAt.Close;
    end;
    
    procedure TfmGerarRelAt.btnGerarClick(Sender: TObject);
    var i:Integer; sWhe:String;
    begin
      Query1.Close;
    
      sWhe := 'Select * From dbCadAt.db ';
    
      for i := 0 to Lista2.Items.Count-1 do
      begin
        if Lista2.Items.Count > 10 then
        begin
          MessageDLG('Você ultrapassou a capacidade de itens selecionados!',mtWarning,[mbok],0);
          abort;
        end
        else begin
          if i = 0 then
            begin
              sWhe := sWhe + 'Where (CodPart = :P' + IntToStr(i) +')'
            end
           else begin
            sWhe := sWhe + ' or (CodPart = :P' + IntToStr(i) + ')';
           end;
        end;
      end;
      Query1.SQL.Text := sWhe;
    
      ShowMessage(sWhe); //<- vamu ver agora...
      modProjeto.tbCadAt.First;
    
      for i := 0 to Lista2.Items.Count-1 do
       begin
        Query1.ParamByName('P'+IntToStr(i)).asString := Lista2.Items[i];
       end;
        Query1.Open;
        fmRelAt := tfmRelAt.Create(application);
        fmRelAt.QuickRep1.Preview;
        fmRelAt.Release;
    end;
    
    
    
    procedure TfmGerarRelAt.SpeedButton1Click(Sender: TObject);
    var i:Integer; sWhe:String;
    begin
      Query1.Close;
    
      sWhe := 'Select CodPart,NomeFant,Quantidade From dbCadAt.db ';
    
      for i := 0 to Lista2.Items.Count-1 do
      begin
        if Lista2.Items.Count > 10 then
        begin
          MessageDLG('Você ultrapassou a capacidade de itens selecionados!',mtWarning,[mbok],0);
          abort;
        end
        else begin
          if i = 0 then
            begin
              sWhe := sWhe + 'Where (CodPart = :P' + IntToStr(i) +')'
            end
           else begin
            sWhe := sWhe + ' or (CodPart = :P' + IntToStr(i) + ')';
           end;
        end;
      end;
      Query1.SQL.Text := sWhe;
    
      ShowMessage(sWhe); //<- vamu ver agora...
    
      for i := 0 to Lista2.Items.Count-1 do
       begin
        Query1.ParamByName('P'+IntToStr(i)).asString := Lista2.Items[i];
       end;
    
        Query1.Open;
        fmRelAt := tfmRelAt.Create(application);
        fmRelAt.QuickRep1.Preview;
        fmRelAt.Release;
    
    end;
    
    procedure TfmGerarRelAt.SpeedButton2Click(Sender: TObject);
    begin
    fmGerarRelAt.Close;
    end;
    
    end.
    Unit do Relatório
    unit U_RelAt;
    
    interface
    
    uses
      SysUtils, Windows, Messages, Classes, Graphics, Controls,
      StdCtrls, ExtCtrls, Forms, QuickRpt, QRCtrls, DB, DBTables, Buttons;
    
    type
      TfmRelAt = class(TForm)
        QuickRep1: TQuickRep;
        PageFooterBand1: TQRBand;
        QRExpr1: TQRExpr;
        ColumnHeaderBand1: TQRBand;
        DetailBand1: TQRBand;
        QRLabel1: TQRLabel;
        QRExpr2: TQRExpr;
        QRLabel2: TQRLabel;
        QRExpr3: TQRExpr;
        QRLabel3: TQRLabel;
        QRExpr4: TQRExpr;
        Table1: TTable;
        TitleBand1: TQRBand;
        QRLabel4: TQRLabel;
        QRLabel5: TQRLabel;
        QRLabel6: TQRLabel;
        QRExpr5: TQRExpr;
        Query1: TQuery;
        DataSource1: TDataSource;
        procedure SpeedButton1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
      end;
    
    var
      fmRelAt: TfmRelAt;
    
    implementation
    
    uses dataProjeto, U_GerarRelAt, U_CadAt;
    
    {$R *.DFM}
    
    procedure TfmRelAt.SpeedButton1Click(Sender: TObject);
    begin
    modProjeto.tbCadUsu.First;
    
    QrLabel5.Caption := 'Teste'
    end;
    
    procedure TfmRelAt.FormCreate(Sender: TObject);
    var i,Total:Integer;
    begin
      Total := 0;
      Query1.Close;
      Query1.SQL.Text := 'Select Quantidade From dbCadAt.db Where CodPart = :cod';
       for i := 0 to fmGerarRelAt.Lista2.Items.Count-1 do
         begin
          Query1.ParamByName('cod').asString := fmGerarRelAt.Lista2.Items[i];
          Query1.Open;
          Total := Total + Query1.FieldByName('Quantidade').asInteger;
          Query1.Close;
        end;
       qrLabel5.Caption := IntToStr(Total);
    end;
    
    end.

    Valeu... smile.gif

  7. Sim.. esse datasource esta ligado na Query?

    Sim, está....

    E os campos no relatorios estao apontando para esse DataSource?

    Não sei qual a propriedade...seria a do QuickRep1 ?

    Vê aí

    Seria a propriedade DataSet do QuickRep1 ?

    Olha qtos eu selecionei

    Se for vê como sai o relatório :

    Relatório

    Ele está aparecendo o número de vezes referente ao nº de códigos que eu selecionei, porém todos iguais ao primeiro....

  8. Então ficou assim, com a ajuda da galera eu tenho o form que irá gerar um relatórório Clique aqui para ver o form

    no evento onclick do botão gerar tem o seguinte código :

    procedure TfmGerarRelAt.SpeedButton1Click(Sender: TObject);
    var i:Integer; sWhe:String;
    begin
    Query1.Close;
    
    sWhe := 'Select * From dbCadAt.db ';
    
    for i := 0 to Lista2.Items.Count-1 do
    begin
    if i = 0 then
    sWhe := sWhe + 'Where (CodPart = :P' + IntToStr(i) +')'
    else
    sWhe := sWhe + ' or (CodPart = :P' + IntToStr(i) + ')';
    end;
    
    Query1.SQL.Text := sWhe;
    
    ShowMessage(sWhe); //<- vamu ver agora...
    
    for i := 0 to Lista2.Items.Count-1 do
    begin
    Query1.ParamByName('P'+IntToStr(i)).asString := Lista2.Items[i];
    end;
    Query1.Open;
    fmRelAt := tfmRelAt.Create(application);
    fmRelAt.QuickRep1.Preview;
    fmRelAt.Release;
    end;
    end;
    Selecionando os código e passando para a Lista2 eles estão temporariamente aparecendo em um dbGrid. No evento oncreate do form do Relatório : Clique aqui para ver o relatório Tem o seguinte código :
    procedure TfmRelAt.FormCreate(Sender: TObject);
    var i,Total:Integer;
    begin
      Total := 0;
      Query1.Close;
      Query1.SQL.Text := 'Select Quantidade From dbCadAt.db Where CodPart = :cod';
       for i := 0 to fmGerarRelAt.Lista2.Items.Count-1 do
         begin
          Query1.ParamByName('cod').asString := fmGerarRelAt.Lista2.Items[i];
          Query1.Open;
          Total := Total + Query1.FieldByName('Quantidade').asInteger;
          Query1.Close;
        end;
       qrLabel5.Caption := IntToStr(Total);
    end;

    Por fim ficou assim...

    1º Eu seleciono códigos e clico em gerar chamando o form do relatório

    2º no Total aparece o total dos códigos selecionados mas na relação aparecem todos os código, os selecionados e os não-selecionados.

    Portanto o código que o s3c passou e está no oncreate está fiel, pois conta o total somente dos que eu seleciono...

    A única coisa agora é fazer com que o relatório imprima de acordo com o que é solicitado. biggrin.gif

  9. Essa query é um objeto TQuery?

    Se for, verifique a propriedade RequestLive e deixe-a false.

    É sim !!! só que estava false, mas mudando para TRUE funcionou..... biggrin.gif

    SUCESSO s3c...

    Agora o que eu seleciono na lista 2 está aparecendo no dbGrid...(somente os selecionados)...

    Bom, o código ficou assim :

    var i:Integer; sWhe:String;
    begin
    Query1.Close;
    
    sWhe := 'Select * From dbCadAt.db ';
    
    for i := 0 to Lista2.Items.Count-1 do
    begin
    if i = 0 then
    sWhe := sWhe + 'Where (CodPart = :P' + IntToStr(i) +')'
    else
    sWhe := sWhe + ' or (CodPart = :P' + IntToStr(i) + ')';
    end;
    
    
    Query1.SQL.Text := sWhe;
    
    ShowMessage(sWhe); //<- vamu ver agora...
    
    for i := 0 to Lista2.Items.Count-1 do
    begin
    Query1.ParamByName('P'+IntToStr(i)).asString := Lista2.Items[i];
    end;
    Query1.Open;
    fmRelAt := tfmRelAt.Create(application);
    fmRelAt.QuickRep1.Preview;
    fmRelAt.Release;
    end;

    Fiz um teste para ver o Relatório mas ainda está chamando tudo, porém o código está redondinho no dbGrid...

    Lembra do código que você me passou para mostrar somente o total dos selecionados, pois é....está mostrando somente o total.....ou seja....agora só falta fazer aparecer os benditos da Lista2 no relatório......Será que é possível....senão estou muito satisfeito com o suporte que tive até aqui.....

  10. O IN especifica o valor selecionado, ou seja, o registro não é isso ?!?!

    Bom, ele não rolou e o 1º ficou na mesma, só funciona com 1 selecionado....

    Analisando ...

    Ele sempre vai passar pelo :

    if i = 0 then sWhe := sWhe + 'Where (CodPart = :P' + IntToStr(i) +')'

    Depois o problema é quando ele vai acumular né?!?!

    Tá cruel....estou dando trabalho.... wink.gif

    Uma dúvida.....O dbGrid vai aceitar mais de 2 códigos ??? Será que o erro é porque ele não está aceitando dois registros.

  11. if i = 0 then
      sWhe := sWhe + 'Where CodPart = :P' + IntToStr(i)
    else
      sWhe := sWhe + ' or CodPart = :P' + IntToStr(i);
    end;
    Entendi seu tratamento, fiz os testes e notei que quando eu seleciono apenas 1 ele com certeza entra no if i = 0, se eu clico em gerar e não seleciono nenhum aparecem todos no dbGrid e se são mais de 1 código jogados na lista2, ele entra no else....aparece o ShowMessage :
    Select * From dbCadAt.db Where CodPart = :P0 or CodPart = :P1
    em seguida gera o erro.... Acho que o or pode estar estranho....tentei jogar and em seu lugar, não deu certo !!! mas não deu erro.... O Resultado do ShowMessage com apenas 1 selecionado é :
    Select * From dbCadAt.db Where CodPart = :P0

  12. Cara, para criar um programa em DELPHI...(vá até a loja de softwares mais próxima)* e compre o DELPHI 7...Com ele instalado no seu PC você poderá criar Aplicações .EXE e este sim poderão ser executados em outras máquinas sem a necessidade de um compilador na mesma....lembrando que se você trabalhar com banco de dados aí a coisa é bem diferente....

    Acho que a melhor forma de você começar a usar o DELPHI é instalando o programa, assim você criar seu projetos podendo compilar no próprio micro... wink.gif

    --------------------------------------------

    Editado! Sem incentivos a pirataria né!

    --------------------------------------------

    * -> By CorpoSemAlma

    --------------------------------------------

×
×
  • Criar Novo...