Cfi023 Sistema Cadastro Completo

Download Cfi023 Sistema Cadastro Completo

Post on 19-Oct-2015

29 views

Category:

Documents

0 download

TRANSCRIPT

  • unit Unit4; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, DBCtrls, Grids, DBGrids, StdCtrls, Mask, DB, Buttons,maskutils; type TForm4 = class(TForm) DBGrid1: TDBGrid; DataSource1: TDataSource; Panel3: TPanel; Label5: TLabel; Edit1: TEdit; Label6: TLabel; BtnConsultar: TButton; Panel4: TPanel; BTNGravar: TBitBtn; BTNInserir: TBitBtn; BTNCancelar: TBitBtn; BTNSair: TBitBtn; BTNExcluir: TBitBtn; Panel1: TPanel; btnPrimeiro: TBitBtn; btnAnterior: TBitBtn; btnProximo: TBitBtn; btnUltimo: TBitBtn; BTNAlterar: TBitBtn; Label1: TLabel; Panel2: TPanel; Label2: TLabel; Label3: TLabel; Label4: TLabel; edtCodigo: TEdit; edtNome: TEdit; edtPreco: TEdit; procedure sairClick( ); procedure cancelarClick( ); procedure deletarClick( ); procedure inserirClick( ); procedure Button1Click( ); procedure BTNInserirClick( ); procedure FormShow( ); procedure BTNCancelarClick( ); procedure BTNGravarClick( ); procedure BTNSairClick( ); procedure BTNExcluirClick( );

    procedure btnPrimeiroClick( ); procedure btnAnteriorClick( ); procedure btnProximoClick( ); procedure btnUltimoClick( ); procedure BTNAlterarClick( ); procedure edtPrecoChange( ); procedure edtPrecoKeyPress( ; ); procedure edtPrecoKeyDown( ); procedure edtCodigoChange( ); procedure edtNomeExit( ); procedure edtPrecoExit( ); procedure edtNomeKeyPress();

  • private { Private declarations } public procedure tratabotoes; procedure atualizaedits; procedure tratabotoes2; { Public declarations } end; var Form4: TForm4; v1, v2:String; //PRIMEIRO DECLARE ESSAS DUASVARIAVEIS GLOBAIS implementation uses Unit2, Unit1; {$R *.dfm} Function FormatarBanco(Valor:String; Quant:Integer):String; begin case Length(Valor) of 0:result:=''; 1:result:=' 0,0'+Valor; 2:result:=' 0,'+Valor; 3:result:=FormatMaskText(' 0,00;0', Valor); 4:result:=FormatMaskText(' 00,00;0', Valor); 5:result:=FormatMaskText(' 000,00;0', Valor); 6:result:=FormatMaskText(' 0.000,00;0', Valor); 7:result:=FormatMaskText(' 00.000,00;0', Valor); 8:result:=FormatMaskText(' 000.000,00;0', Valor); end; end; procedure Tform4.atualizaedits; var valor:string; begin edtCodigo.text:=dm.sdUm.fieldbyname('codprduto').asstring; edtNome.text:=dm.sdUm.fieldbyname('NOME').asstring; valor:=(dm.sdUm.fieldbyname('preco').asstring); v1:=''; v2:=valor; edtPreco.text:=FormatarBanco(v2, Length(v2)); label2.caption:=inttostr(dm.sdUm.recno)+'/'+inttostr(dm.sdUm.recordcount); btninserir.SetFocus; end; procedure TForm4.tratabotoes; begin BTnInserir.enabled:=not BtnInserir.enabled; BtnAlterar.enabled:=not BtnAlterar.enabled;

    BtnExcluir.enabled:=not BtnExcluir.enabled; BtnGravar.enabled:=not BtnGravar.enabled; BtnCancelar.enabled:=not BtnCancelar.enabled; end; // trata dos botoes de navegacao procedure TForm4.tratabotoes2; begin // se est no primeiro registro (recno=1) if dm.sdUm.recno=1 then begin btnPrimeiro.enabled:=false; btnAnterior.enabled:=false; end else begin btnPrimeiro.enabled:=true; btnAnterior.enabled:=true; end; // se esta no ultimo registro, recno=recordcount if ((dm.sdUm.RecordCount=dm.sdUm.recno) and (dm.sdUm.RecordCount>1)) then begin btnUltimo.enabled:=false; btnProximo.enabled:=false; end else begin btnUltimo.enabled:=true; btnProximo.enabled:=true; end; end; procedure TForm4.cancelarClick(Sender: TObject); begin dm.sdUm.Cancel; tratabotoes; end; procedure TForm4.deletarClick(Sender: TObject); begin if dm.sdUm.RecordCount < 1 then begin ShowMessage('Nao existe registro na tabela!'); Exit; end else if MessageBox(0,'Deseja realmente excluir?','Excluindo ',mb_YesNo)=idYes then dm.sdUm.Delete; end;

  • procedure TForm4.inserirClick(Sender: TObject); begin dm.sdUm.last; dm.sdUm.Append; edtCodigo.SetFocus; tratabotoes; end; procedure TForm4.BTNSairClick(Sender: TObject); begin form4.close; end; procedure TForm4.BTNInserirClick(Sender: TObject); begin panel2.Visible:=true; panel1.Visible:=false; tratabotoes; edtCodigo.Clear; edtNome.Clear; // para limpar o edtPreco, tem que ser a rotina abaixo... v1:=''; v2:=v1; edtPreco.text:=FormatarBanco(v2, Length(v2)); edtcodigo.setfocus; dm.sdUm.append; panel1.Visible:=false; end; procedure TForm4.FormShow(Sender: TObject); begin dm.sdUm.Open; dm.sdUm.last; // atualizaedits; end; procedure TForm4.BTNCancelarClick(Sender: TObject); begin dm.sdUm.Cancel; showmessage('Voce cancelou a insercao'); dm.sdUm.Last; tratabotoes; panel2.Visible:=false; panel1.Visible:=true; end; procedure TForm4.BTNGravarClick(Sender: TObject); var valor, subtexto:string; j:integer; begin

    if ((edtCodigo.Text='') or (EdtNome.Text='') or (EdtPreco.Text='')) then begin Application.MessageBox('Campos Incompletos','Ateno',0); Exit; end else if dm.sdUm.state in [dsedit,dsinsert] then begin dm.sdUm.fieldbyname('codprduto').asinteger:=strtoint(edtCodigo.text); dm.sdUm.fieldbyname('NOME').asstring:=edtNome.text; // texto de codigo que extrai o valor numero do edtPreco // se for R$ 1.234,56 , extrai 1234,56 , excluindo o R$ e o . valor:=''; for j:=1 to (length(edtpreco.text)) do begin subtexto:=(copy(edtpreco.text,j,1)); if ((subtexto'.') and (subtexto' ')) then valor:=valor+subtexto; end; dm.sdUm.fieldbyname('PRECO').asstring:=valor; dm.sdUm.post; showmessage('Dados Gravados com sucesso'); end; tratabotoes; btnInserir.SetFocus; atualizaedits; panel2.Visible:=false; panel1.Visible:=true; end; procedure TForm4.BTNExcluirClick(Sender: TObject); begin if MessageBox(0,'Deseja realmente excluir?','Excluindo ',mb_YesNo)=idYes then begin dm.sdUm.Delete; dm.sdUm.last; atualizaedits; end; end; procedure TForm4.btnPrimeiroClick(Sender: TObject); begin dm.sdUm.First; //atualizaedits ; tratabotoes2; end; procedure TForm4.btnUltimoClick(Sender: TObject); begin

  • dm.sdUm.Last; // atualizaedits; tratabotoes2; end; procedure TForm4.btnProximoClick(Sender: TObject); begin dm.sdUm.Next; // atualizaedits; tratabotoes2; end; procedure TForm4.btnAnteriorClick(Sender: TObject); begin dm.sdUm.Prior; // atualizaedits; tratabotoes2; end; procedure TForm4.BTNAlterarClick(Sender: TObject); begin panel2.Visible:=true; panel1.Visible:=false; atualizaedits; dm.sdUm.Edit; EdtCodigo.SetFocus; tratabotoes; panel1.Visible:=false; end; procedure TForm4.edtPrecoChange(Sender: TObject); begin v2:=v1; edtPreco.text:=FormatarBanco(v2, Length(v2)); end; procedure TForm4.edtPrecoKeyPress(Sender: TObject; var Key: Char); begin // testa se o valor das teclas esta entre 0 e 9 if (key in ['0'..'9',#8,#13])then v1:= v1 + key else Key := #0; // se no est , nao aceita a tecla. end; procedure TForm4.edtPrecoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key=vk_delete then // se apertou delete - veja http://delphi.about.com/od/objectpascalide/l/blvkc.htm Begin edtPreco.clear; //delete apaga o edit para refazer

    v1:=''; end; end; procedure TForm4.edtCodigoChange(Sender: TObject); begin if length(edtCodigo.Text)>=4 then edtNome.SetFocus; end; procedure TForm4.edtNomeExit(Sender: TObject); begin if length(edtnome.Text)3 then begin dm.sdUm.Close; //QuotedStr acrescenta aspas em uma string. dm.sdUm.DataSet.CommandText:='select * from UM where UPPER(NOME) LIKE ' + Quotedstr('%' +Uppercase (edtConsulta.Text) + '%'); dm.sdUm.Active:=TRUE; dm.sdUm.REFRESH; end; end; procedure TForm4.btnLimparClick(Sender: TObject); begin edtConsulta.Clear; dm.sdUm.Close; //mostra todos os itens dm.sdUm.DataSet.CommandText:='select * from UM '; dm.sdUm.Active:=TRUE; dm.sdUm.REFRESH; end; end.

Recommended

View more >