Home arrow Delphi-Kylix arrow Page 3 - Looking at the Details for an Invoicing Application in Delphi
DELPHI-KYLIX

Looking at the Details for an Invoicing Application in Delphi


In the previous article we discussed the requirements and purpose of the invoicing application that we are creating. We also listed the main application code. In this part of the article we are going to look at how to connect the database that we created earlier to the application code. We will also look at some of the code in detail.

Author Info:
By: Chris Neeman
Rating: 5 stars5 stars5 stars5 stars5 stars / 4
July 16, 2007
TABLE OF CONTENTS:
  1. · Looking at the Details for an Invoicing Application in Delphi
  2. · Settings Unit
  3. · New Invoice Form and Code
  4. · Invoice Management Code and Output
  5. · Client Management Code
  6. · Final output and Conclusion

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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.


blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- 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...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials