Welcome

Welcome, thanks to look my blog

Thursday 17 April 2014

membuat kode otomatis

      

procedure TForm1.KodeOtomatis;
  var
  Kode,Nourut : string;
  i : integer;
begin
  //Format Kode : Tahun+PJ(maksudnya untuk penjualan)+TahunBulanTanggal-
  //Jadi Misal : 13PJ20130823-Nourut
  Kode :=FormatDateTime('MMyy', TDTTanggal.Date);
  With ADOQuery1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('Select max(left(Nofaktur,4)) from tpenjualan ' +
              'Where  right(Nofaktur,4) = ' + QuotedStr(Kode) + ';');
      {SQL.Add('Select Max(right(Nofaktur,4)) from tpenjualan ' +
              'Where left(Nofaktur,4) = ' + QuotedStr(Kode) + ';');  }
      Open;
    end;

  if ADOQuery1.Fields[0].AsString = '' then
    Nourut := '0001'
  else
  if ADOQuery1.Fields[0].AsString = '9999' then
    MessageDlg('Data Hari Ini Sudah over Besok aza lagi ya !!',mtError,[mbOK],0)
  else
    Nourut := IntToStr(ADOQuery1.Fields[0].AsInteger + 1);

  if length(Nourut) < 4 then
  begin
    for i := length(Nourut) to 3 do
      Nourut := '0' + Nourut;
  end;
   EdKode.Text := NoUrut + Kode;
  //EdKode.Text := Kode + NoUrut;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if Button1.Caption='Tambah' then
begin
  EdKode.Text:='';
  Button1.Caption:='Simpan';
  Button2.Caption:='Batal';
End    Else
Begin
  Button1.Caption:='Tambah';
  Button2.Caption:='Keluar';
  KodeOtomatis;
  AdoQuery1.Close;
  AdoQuery1.SQL.Clear;
  AdoQuery1.SQL.Add('insert into tpenjualan values ("'+EdKode.Text+'","'+FormatDateTime('dd-MM-yyyy', TDTTanggal.Date)+'")');


  AdoQuery1.ExecSQL;
  FormShow(sender)
End;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if Button2.Caption='Batal' then
Begin
  EdKode.Text:='';
  TDTTanggal.Date:=now;
  Button1.Caption:='Tambah';
  Button2.Caption:='Keluar';
End else
Close
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  AdoQuery2.Close;
  AdoQuery2.SQL.Clear;
  AdoQuery2.SQL.Add('select*from tpenjualan order by NoFaktur');
  AdoQuery2.Open;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
TDTTanggal.DateTime:=Now;
end;

end.


No comments:

Post a Comment