Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 3 - Looking at the Details for an Invoicing Ap...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DELPHI-KYLIX

Looking at the Details for an Invoicing Application in Delphi
By: Chris Neeman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2007-07-16

    Table of Contents:
  • Looking at the Details for an Invoicing Application in Delphi
  • Settings Unit
  • New Invoice Form and Code
  • Invoice Management Code and Output
  • Client Management Code
  • Final output and Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Looking at the Details for an Invoicing Application in Delphi - New Invoice Form and Code


    (Page 3 of 6 )

    The new invoice form presents the user with a input form. You select a client from the dropdown box and then enter the amount for which you are invoicing. The total amount including the VAT will automatically be calculated and added to the total amount field of the form. Below is a listing of the code that makes all this happen:

    unit newinv;

    interface

    uses

      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

      Dialogs, Grids, DBGrids, DB, StdCtrls, Buttons, RpDefine, RpCon, RpConDS,

      RpRave, DBCtrls,math, ADODB;

    type

      TForm2 = class(TForm)

        StaticText4: TStaticText;

        StaticText6: TStaticText;

        edAmount: TEdit;

        btnInsert: TBitBtn;

        BitBtn2: TBitBtn;

        edTotal: TEdit;

        StaticText7: TStaticText;

        GroupBox1: TGroupBox;

        StaticText1: TStaticText;

        StaticText3: TStaticText;

        qclients: TADOQuery;

        cb1: TComboBox;

        Memo1: TMemo;

        procedure BitBtn2Click(Sender: TObject);

        procedure btnInsertClick(Sender: TObject);

        procedure edAmountChange(Sender: TObject);

        procedure edTotalClick(Sender: TObject);

        procedure FormCreate(Sender: TObject);

        procedure FormShow(Sender: TObject);

        procedure Memo1Click(Sender: TObject);

      private

        { Private declarations }

      public

        { Public declarations }

      end;

    var

      Form2: TForm2;

      tot:real;

    implementation

     uses invmain;

    {$R *.dfm}

    procedure TForm2.BitBtn2Click(Sender: TObject);

    begin

    edit1.clear;

    edit2.Clear;

    edit3.clear;

    edit4.Clear;

    edit6.Clear;

    close;

    end;

    procedure TForm2.btnInsertClick(Sender: TObject);

    var

    dt,d:tdatetime;

    begin

    dt:=now;

    shortDateFormat := 'dd-mm-yyyy';

    //if not (edamount.Text = '') and not (edtotal.Text='') and not (memo1.Text ='') then begin

    if form1.ado1.active then form1.ado1.active:=false;

    form1.ado1.TableName:='invoices';

    form1.ado1.active:=true;

    with form1.ado1 do

    begin

    Screen.Cursor := crHourGlass;

    Insert;

    FieldByName('invname').Text:= cb1.Text;

    FieldByName('invdate').AsDateTime:=date;

    FieldByName('status').text:='pending';

    FieldByName('amount').AsCurrency:=strtofloat(edAmount.Text);

    FieldByName('total').AsCurrency:=strtofloat(edTotal.Text);

    FieldByName('notes').AsString:=memo1.Lines.Text;

    post;

    //form1.ado1.Active:=false;

    // form1.ado1.Active:=true;

    Screen.Cursor := crDefault;

      {end

      else

      begin

      messagedlg('Please fill in ALL the fields.',mtwarning,[mbOk], 0);

      end; }

    end;

     

    end;

    procedure TForm2.edAmountChange(Sender: TObject);

    begin

    tot:= strtofloat(edAmount.Text);

    end;

    procedure TForm2.edTotalClick(Sender: TObject);

    var

    am:real;

    begin

    edtotal.Clear;

    if tot > 0 then

    begin

    am:= (form1.vat / 100) * tot;

    tot:=tot + am;

    tot:=RoundTo(tot,-2);

    edTotal.Text:=floattostr(tot);

    end;

    end;

    procedure TForm2.FormCreate(Sender: TObject);

    begin

    qclients.ConnectionString:=form1.con;

    qclients.Close;

    qclients.SQL.Text:='Select name from clients';

    qclients.Open;

    while not qclients.EOF do

    begin

      cb1.Items.Add(qclients.FieldByName('name').AsString);

      qclients.Next;

    end;

    end;

    procedure TForm2.FormShow(Sender: TObject);

    begin

    tot:=0.0;

    memo1.SelStart := 0;

        memo1.Perform(EM_SCROLLCARET, 0, 0);

      memo1.SetFocus;

    end;

    procedure TForm2.Memo1Click(Sender: TObject);

    begin

    memo1.SelStart := 0;

        memo1.Perform(EM_SCROLLCARET, 0, 0);

      memo1.SetFocus;

    end;

    end.

    Once you click on the "Create New Invoice" button, the invoice information is inserted into the invoices table. The following code does that job:

    dt:=now;

    shortDateFormat := 'dd-mm-yyyy';

    //if not (edamount.Text = '') and not (edtotal.Text='') and not (memo1.Text ='') then begin

    if form1.ado1.active then form1.ado1.active:=false;

    form1.ado1.TableName:='invoices';

    form1.ado1.active:=true;

    with form1.ado1 do

    begin

    Screen.Cursor := crHourGlass;

    Insert;

    FieldByName('invname').Text:= cb1.Text;

    FieldByName('invdate').AsDateTime:=date;

    FieldByName('status').text:='pending';

    FieldByName('amount').AsCurrency:=strtofloat(edAmount.Text);

    FieldByName('total').AsCurrency:=strtofloat(edTotal.Text);

    FieldByName('notes').AsString:=memo1.Lines.Text;

    post;

    //form1.ado1.Active:=false;

    // form1.ado1.Active:=true;

    Screen.Cursor := crDefault;

    The code itself is pretty straightforward. It opens up the table and calls the insert procedure. Then it simply inserts the newly-created values in the column fields of the invoice table and posts them to the database.

    More Delphi-Kylix Articles
    More By Chris Neeman


     

    DELPHI-KYLIX ARTICLES

    - Finishing the Client for an Internet Access ...
    - The Client for an Internet Access Control Ap...
    - User Management for an Internet Access Contr...
    - Important Procedures for an Internet Access ...
    - Server Code for an Internet Access Control A...
    - Constructing the Interface for an Internet A...
    - Building a Server Application for an Interne...
    - Building an Internet Access Control Applicat...
    - Client Dataset: Working with Data Packets an...
    - Using the Client Dataset in an N-Tiered Appl...
    - Using the Client Dataset in Two-Tiered Clien...
    - Using the Client Dataset in File-Based Archi...
    - Demystifying the Client Dataset
    - Working with INI Files in Delphi
    - Creating Data Link (UDL) Files in Delphi






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT