Vous êtes sur la page 1sur 30

http://www.cynics-soft.

com

Rapid Application Development


With Visual Studio
Unleash The True Power of Visual Studio

Kok Choon
6/11/2008
Rapid Application Development with Visual Studio™

Important Information:
You may distribute this book to anyone without modifying the content, all links
and information must be remain in its’ original. Thank you for your attention!

7B

“Rapid Application Development with Visual Studio ™” is a worldwide-


protected publication of © Kok Choon and www.cynics-soft.com.

ALL RIGHTS RESERVED


No part of this course (content) may be reproduced or transmitted in any form whatsoever, electronic, or
mechanical, including photocopying, recording, or by any informational storage or retrieval system without
expressed written, dated and signed permission from the author.

DISCLAIMER AND / OR LEGAL NOTICES


The information presented herein represents the views of the author as of the date of publication. Because
of the rate with which conditions change, the author reserves the rights to alter and update his opinions
based on the new conditions.

This course is for informational purposes only and the author does not accept any responsibilities for any
liabilities resulting from the use of this information.

While every attempt has been made to verify the information provided here, the author and his referrals
cannot assume any responsibility for errors, inaccuracies or omissions. Any slights of people or
organizations are unintentional.

© Kok Choon, All Rights Reserved Worldwide. http://www.cynics-soft.com 2|Page


Rapid Application Development with Visual Studio™

Contents
A Word from the Author… ......................................................................................................................... 4
Before Start… ............................................................................................................................................ 6
Create the Project and Data Sources ........................................................................................................ 6
Draw controls to forms instead of coding................................................................................................. 13
Unleash the Power of Dataset Designer .................................................................................................. 16
Hierarchical Update with Visual Studio 2008 ........................................................................................... 23
Useful Resources .................................................................................................................................... 30

© Kok Choon, All Rights Reserved Worldwide. http://www.cynics-soft.com 3|Page


Rapid Application Development with Visual Studio™

A Word from the Author…

Dear Valued Reader,

Welcome to Rapid Application Development with Visual Studio™!


This book is design to assist you in developing application with Visual Studio RAD technology.

Many developers still using conventional coding method introduced in VB 6, while these methods are
effective in the old days, but the new and powerful Visual Studio 2005 and 2008 provides even more
efficient programming tools – The RAD Dataset designer and components.

Conventional programmer will code their way to the end of the project, but new Visual Studio 2005 and
2008 allows developer to “drag and draw” their application from start till the end! They call it Rapid
Application Development. Programmer from Borland Delphi in the old days already familiar with RAD
programming, but until Microsoft replaced them with the powerful Dataset Designer, Form Designer and
other visual tools, most of them switch to Visual Studio, and I am one of the Delphi developers.

From my experience with Visual Studio 2005, you can write code 500% faster than another conventional
programmer with the help of visual inheritance, form designer and dataset designer. Some developer still
relied on code generation tools such as CodeSmith to generate Insert, Update and Delete stored
procedure for SQL server, and certainly data access code in Visual Studio!

The biggest problem for RAD programming not common between Visual Studio 2005 developers is lack of
documentation and tutorial… and VS2008 has improved this weakness. Now you can find lots of video
tutorial and web demos showing you how to code your software in RAD style; I predict the RAD
programming will be become very popular in the next 3 years.

RAD will work very well because its’ utility has become to mature through the time, and developer can
lower the development cost and deliver the project faster. If you don’t believe me, try it yourself, compare
the “coding style” and “drawing style”, definitely you will agree with me that: Let the tools code for you
always the fastest way.

For your information: Visual Studio 2008 added many cool features, you can now do 3-tier programming
easier than before! and the Microsoft Synchronization framework for ADO.Net brings RAD into offline
application; You can use the software offline and upload any pending updates that you make during offline
into the server by batch, very cool feature! And the best part, you can do that RAD all the way…

© Kok Choon, All Rights Reserved Worldwide. http://www.cynics-soft.com 4|Page


Rapid Application Development with Visual Studio™

hope this book can bring the new age programming into your existing skills, we can expect to see more
tools coming from Microsoft in the near future.

While all efforts are done to make this book perfect, inevitably there might be technical mistakes or editing
errors, please feel free to contact the author at kkchoon@cynics-soft.com for comment and questions, I
will try to revise the book and answer your question as soon as possible.

Thanks for your generous support, look forward to your feedback!

Warmest Regards,

CYNICS SOFTWARE
www.cynics-soft.com

© Kok Choon, All Rights Reserved Worldwide. http://www.cynics-soft.com 5|Page


Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

B
Before Sta
art…
You need to download
d the Northwindd sample dattabase from Microsoft website
w or go
o to the end of
o this
bo
ook, and follow the resources links to
t create the
e sample Noorthwind DB before proceeed.

Unless you allready installed the Northwind datab


base, you ca
an skip this step.
s

C
Create the
e Project and Data
a Sources
s

Crea
ate new projject, select Windows
W
and then Windoows Forms Application,
A
save
e the projectt as RADDemo.

Fiigure 1

You
u should be able
a to see the
t
Form
m1.vb.

Fiigure 2

© Kok Choon, All Rightss Reserved Worldwide.


W h
http://www.c
cynics-soft.co
om 6|Page
Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

Now
w, go to the menu,
m selecct “Data” ->
“Sho
ow Data Sou urces” or use e the
shortcut key “Sh
hift+Alt+D”.

Fiigure 3

You
ur should see e the “Data Sources”
S
panel, click on “Ad
“ New Datta
Sou
urce…”.

Fiigure 4

© Kok Choon, All Rightss Reserved Worldwide. http://www.ccynics-soft.co


om 7|Page
Rapid Application Development with Visual Studio™

Then select Database and click Next.

Figure5

© Kok Choon, All Rights Reserved Worldwide. http://www.cynics-soft.com 8|Page


Rapid Application Development with Visual Studio™

Select your server name, click refresh


to drop down. If you don’t see it, just
key in your pc-name\sqlexpress.

In the “Select or enter a database


name:”, select Northwind.

Figure 6

© Kok Choon, All Rights Reserved Worldwide. http://www.cynics-soft.com 9|Page


Rapid Application Development with Visual Studio™

Select the correct connection and


then press “Next”.

Figure 7

Use the default connection name or


enter your own.

Figure 8

© Kok Choon, All Rights Reserved Worldwide. http://www.cynics-soft.com 10 | P a g e


Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

Fromm here, you can select the


t tables
and procedure need.
n In thiss example,
just select:
1. Custome ers
2. Employe ees
3. Order Details
4 Orders
4.
5. Productss

Fiigure 9

You u can see Vissual Studio created


c
the NorthWindD Dataset for you,
y all
objeect access are here, you u can drop
dowwn each table e and fields, select the
f the table and
conttrol to bind for
field
ds…

Fiigure 10

© Kok Choon, All Rights Reserved Worldwide. htttp://www.cyynics-soft.com


m 11 | P a g e
Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

w, select Ord
Now ders, EmployyeeID.

Clicck the drop down


d combo and
seleect “Combob box” to be asssign to
Emp ployee ID.

** Also
A change CustomerID
D to
“Combobox”.

Fiigure 11

© Kok Choon, All Rights R


Reserved Worldwide. htttp://www.cyynics-soft.com
m 12
2|Page
Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

D
Draw conttrols to fo
orms inste
ead of co
oding
In
n this section
n, you will lea
arn how to drag
d and dro
op the contro
ols from Data
a Sources in
nto the Winddows Form
Designer. Vissual Studio has
h powerful tools in the Data Sourcces Panel, yoou can assig
gn all controlls to the
Fiields.

Afte
er that, selecct Orders andd change
the DataGridVie ew to Detailss.

Thiss will allow Orders


O to dro
op into the
form
m with contro ols assign in the fields.

Fiigure 12

© Kok Choon, All Rights Reserved


R W
Worldwide. htttp://www.cyynics-soft.com
m 13 | P a g e
Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

Now
w drag and drop
d Orders from
aSources into the form.
Data

ou do not see Customer ID and


If yo
Emp ployee ID wiith combobo ox control,
go back
b to Figure 11 and re
edo as
instrructed.

Fiigure 13

Afte
er Drag the Orders
O table, you
should assign Customer
C ID and
Empployee ID coontrols to rettrieve data
from
m which table
e.

g Customer table from the Data


Drag
Sou
urces into Cu
ustomer ID combobox.
c

Drag
g Employee table from the
t Data
Sou
urces into Em
mployee ID combobox.
c

Fiigure 14

© Kok Choon, All Rights Reserved Worldwide. htttp://www.cyynics-soft.com


m 14
4|Page
Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

Go to
t source vie ew, you should be
e to see the loading code
able e
auto
omatic generated.

Fiigure 15

Noww, hit F5 to compile


c and run, you
should see the combobox
c e
extract
data
a from maste er tables corrrectly!

u see how much time you can


You
e with RAD tools…!
save

Fiigure 16

© Kok Choon, All Rights R


Reserved Worldwide. htttp://www.cyynics-soft.com
m 15 | P a g e
Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

U
Unleash th
he Powerr of Datas
set Design
ner
Dataset Desig gner is the most
m powerfuul tools availlable in Visu
ual Studio 20
005 and 2008; many devvelopers
diidn’t even kn
now their exiistence or im
mportance.

Th
he only reasson develope
er do not use
e them are, they do not know how to
o customize
e it !

w double clicck the


Now
NortthWindDataset in the so
olution
explorer.

s is Datasett Designer, the most


This
imp
portant core
e for Databaase
prog
gramming!

Fiigure 17

Seee the Orders Table, now click on


the OrdersTableeAdapter.

TabbleAdapter iss the commu unication


interface betwee en dataset and
a your
dataabase, it con
ntains all the
e code
needed to selecct, insert, delete and
edit your table.

All codes
c generrated by the tools, you
can then configuure the toolss’
generated sourcce.

Fiigure 18

© Kok Choon, All Rights Reserved


R W
Worldwide. htttp://www.cyynics-soft.com
m 16
6|Page
Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

Afte
er Click on th
he
“Ord
dersTableAd dapter” in pre
evious
step
p, now look ata your Prop perties
Pannel, you will notice
n all 4 commands
c
generated for yo ou.

Fiigure 19

© Kok Choon, All Rights Reserved Worldwide. htttp://www.cyynics-soft.com


m 17 | P a g e
Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

The
e standard coommand sett might not
get what you waant; I will shoow you
how e it with filter.
w to configure

Now
w select OrdersTableAda apter
again, right clickk and select “Add
Que
ery”.

Fiigure 20

his screen, select


In th s the de
efault –
“Usee SQL State ements”, then click
“Nexxt”.

Fiigure 21

© Kok Choon, All Rights Reserved Worldwide. htttp://www.cyynics-soft.com


m 18 | P a g e
Rapid Application Development with Visual Studio™

Also select the default option that


return rows…Click “Next”.

Figure 22

Now in this screen, you can add your


own filter statement.

Add “WHERE OrderID Between


@STARTID AND @ENDID” at the
end of “From Orders”.

Click Next Button.

Figure 23

© Kok Choon, All Rights Reserved Worldwide. http://www.cynics-soft.com 19 | P a g e


Rapid Application Development with Visual Studio™

You can change the Method Name to


anything you want. In this demo, just
leave it as default.

Click “Next” button.

Figure 24

Click “Next” button again.

Figure 25

© Kok Choon, All Rights Reserved Worldwide. http://www.cynics-soft.com 20 | P a g e


Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

The
e FillBy and Get
G DataBy Method is
generated.

Fiigure 26

Noww, go to yourr form and add a new


buttton.

Fiigure 27

© Kok Choon, All Rights Reserved Worldwide. htttp://www.cyynics-soft.com


m 21 | P a g e
Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

Fiigure 28

Double click on
o the button
n and switch
h to code vie
ew automaticcally. Add the fillby meth
hod in the click event:

M
Me.OrdersTa bleAdapter.F
Fillby(Me.No
orthwindData
aset.Orders, STARTID, ENDID)

Please note that the STA ARTID can be e replace byy “0000” or anything.
a If you
y add two more editbo
ox, you can
acctually pass in the editbo
ox.text into the
t method directly.
d

Affter complete, hit F5 to compile


c and run.

© Kok Choon, All Rights Reserved


R W
Worldwide. htttp://www.cyynics-soft.com
m 22
2|Page
Rapid Application Development with Visual Studio™

Hierarchical Update with Visual Studio 2008


In this chapter, you will learn how to create Master details with hierarchical update. In VS2008, Microsoft
has included a powerful component called TableAdapterManager, which bring RAD to full support of
Hierarchical update!

Unfortunate this tutorial only applies to VS2008, VS2005 still requires a bit coding!

Now let’s resize and extend the


width of the form.

Figure 29

© Kok Choon, All Rights Reserved Worldwide. http://www.cynics-soft.com 23 | P a g e


Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

Now
w you need to t drag the Order
O
Deta
ails into the form.

But please take note, do no


ot drag
“Order Details””….

Insteead, click Orrders, and th


hen select
the field
f “Order Details”, whhich is a
o the detail table.
reprresentation of

Dragg the Order Details from


m the Order
table
e into the form.

Fiigure 30

u can see the


You e detail grid
succcessfully dro
opped on the e form.

If yo
ou select thee Order Deta
ails instead
of Orders,
O then Order Details, the
data w not be filter by the
a in the grid will
Orde erID…

Noww we have too link the pro


oduct ID
h the productt table. See Next
with
Figu
ure…

Fiigure 31

© Kok Choon, All Rights Reserved Worldwide. htttp://www.cyynics-soft.com


m 24
4|Page
Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

Fiigure 32

Click the smaall arrow at th


he top right of
o the grid, select
s edit co
olumn. You may
m right click on the grrid and
se
elect Edit co
olumn as welll.

Selecct the productID.

Fiigure 33

© Kok Choon, All Rights Reserved


R W
Worldwide. htttp://www.cyynics-soft.com
m 25 | P a g e
Rapid Application Development with Visual Studio™

Find ColumnType and change it to


DataGridViewComboboxColumn.

Figure 34

Next, select DataSource, drop down


and find:

Project Data Sources,


NorthWindDataset, Products.

This will bind Products table with the


ProductID column.

Figure 35

© Kok Choon, All Rights Reserved Worldwide. http://www.cynics-soft.com 26 | P a g e


Rapid Application Development with Visual Studio™

Next, Select DisplayMember, drop


down and select ProductName.

Figure 36

Next, select ValueMember, drop down


and select ProductID.

Click OK Button.

Figure 37

© Kok Choon, All Rights Reserved Worldwide. http://www.cynics-soft.com 27 | P a g e


Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

Fiigure 38

Now hit F5 co
ompile and run, if everything setup correct,
c you will
w see the Order Detaills grid follow
w Order
ta
able when na
avigating.

Thhe ProductID
D in the Grid
d should sho ow Product Name
N (DisplayName), and every tim
me you chang
ge the
prroduct name
e, the producctID will be updated
u acco
ordingly.

Fiigure 39

You should nootice below the form dessigner, is all the compon
nents repressentation icon, one of the
e new
co
omponent iss TableAdaptterManager,, this compo onent allows you to updaate multiple table
t at once
e!

© Kok Choon, All Rights Reserved


R W
Worldwide. htttp://www.cyynics-soft.com
m 28 | P a g e
Rapid Applicatiion Deve
elopmentt with Visual Stud
dio™

Switch to the Properties panel, you


should see all TableAdapter(s)) are
conneccted to Table
eAdapterMa anager.

Fiigure 40

Fiigure 41

Th
his statemennt: “Me.TableAdapterMa anager.Upda ateAll(Me.No orthwindData
aset)” will do
o all the upda
ate for
bo
oth tables, even
e you hav
ve 3 or 4 or many tabless, it will mana
age the update accordin ngly.

Because deleete and inserrt sequence are not the same, witho
out TableAda
apterManage
er, develope
er will need
o do more co
to oding…

Fo
or example, when you trry to delete an
a Order, yo
ou must first delete the OrderDetails
O s record with
h the same
O
OrderID entrie
es.

But when you etails, you must insert Orrder Record first before OrderDetailss can be
u want to insert OrderDe
nter into the table.
en

© Kok Choon, All Rights Reserved


R W
Worldwide. htttp://www.cyynics-soft.com
m 29 | P a g e
Rapid Application Development with Visual Studio™

Useful Resources
Cynics Software – The Leading Provider in Accounting, POS and Inventory Source Code, build upon
Rapid Application Development Tools from Visual Studio 2005 and 2008.

General Ledger Trial Source Code – Sample source code that demonstrates how we build our system
using RAD tools.

Rapid Application Development Source Code in this tutorial.

© Kok Choon, All Rights Reserved Worldwide. http://www.cynics-soft.com 30 | P a g e

Vous aimerez peut-être aussi