Anda di halaman 1dari 85

c  



@  @  

! @


 
!  
  

! c

!     c

!       

@  


Ä What is the .Net Framework


Ä Common Language Runtime
Ä .Net Managed Assemblies
Ä Compilation of .Net Code
Ä .Net Framework Class Library
Ä .Net Languages
Ä The future of .Net
0   
 

Ä Ñrimarily a development platform
(mostly effects application
development)
Ä Consists of two main parts
ƛ Common Language Runtime
ƛ .Net Framework Class Library
° °  
 
Ä Ñrovides a Ơruntime environmentơ for
the execution of code written in ANY
.Net Language
Ä ƠManagesơ
ƛ The overall execution of .Net code
ƛ Inheritance, Memory, Debugging, and
application development across Multiple
languages
° °  
Ä Languages that utilizes the .Net framework must follow the
CLS
ƛ Common Language Specification
ƛ Outlines the rules and standards required or needed by the CLR
to execute .Net code.
Ä The CLR will execute Managed Assemblies
Ä Intermediate Languages managed by the CLR are called
Managed Code
Ä The CLR will manage for the IL
ƛ Garbage collection
ƛ Object instantiation
ƛ Memory allocation
Ä Components written in Managed Code by the CLR are called
.Net Managed assemblies
  
Ä pasic Unit of deployment of .Net
Applications
Ä Similar to the Microsoft COM Objects
Ä Each Managed Assembly contains a Manifest
ƛ Hold definitions of other components required
for execution of the application
ƛ Ñrevents the problems associated with
conflicting DLLƞs
ƛ Revision numbers and components are listed in
the manifest
ƛ Two versions of the same DLL can then co-
co-exist
°     
Ä All .Net languages are first compiled into an
intermediate language called MSIL or IL (Microsoft
Intermediate Language)
Ä The MSIL is then ƠJust In Timeơ (JIT) compiled at
first execution of the code and managed by the CLR
Ä All MSIL or IL code can be compiled directly to
native code with the following
ƛ Compiling native code will provide faster startup execution
of the code
ƛ Ñerformance during execution of the code will then be
sacrificed
ƛ During JIT Optimization is placed on the Managed Code in
order to improve performance at the time of execution
 
 °

Ä Ñrovide a library of base classes that
developers can use in their own
applications written in ANY .Net
language
Ä pecause of the use of these base
classes, Inheritance can then be
extensively used in languages that use
the .Net Framework
 
Ä .Net applications can be written by any or a
combination of many .Net languages
Ä Languages include
ƛ Vp .Net
ƛ C#
ƛ J#
ƛ Managed C++ (default in studio is set for managed C++)
Ä Applications can be developed without the use of
Studio .Net
ƛ Applications can be developed still using a simple text
editor
ƛ ASÑ .Net Applications as well as other apps can be still
developed using notepad
@   
 

Ä Standards were release in 2000 from Microsoft to the community
Ä GNU .Net is a project in the Linux community that is presently developing a
CLR to run in the Linux environment
Ä Languages planned to include the CLS are
ƛ AÑL
ƛ COpOL
ƛ Eifel
ƛ Fortran
ƛ Haskel
ƛ Mercury
ƛ Mondrian
ƛ Oberon
ƛ Ñascal
ƛ Ñerl
ƛ Ñython
ƛ RÑG
ƛ Scheme
à    
@  

Ä Studio .Net
Ä The Start Ñage
Ä Ñroblems with Studio .Net in the lab
environment
à 
Ä All present .Net languages are included under one
development environment
ƛ When using any one of the languages, the studio must be
used (there is no longer an environment for each
language)
ƛ You have to start a new solution/project
Ä Ñrojects are containers that contain the files associated with
a particular project
Ä A solution is a container that contains one or more projects
or project containers
Ä When the IDE is started you have the Ñrojects tab,
online resources, and My Ñrofile
@ à!

Ñ 


  
 
#
@ 
@  ! "

 

Ñ
 Ñ 
 

$
 
 
 

   
 

!  
 à 
     
Ä .Net security must allow access to the J: drive or
the local intra net in order to work properly
Ä Ñroblems arise when debugging apps on an ASÑ
.Net server that is not part of the current domain
(CLC) pasic apps will still work fine
Ä These problems are not present if IIS and remote
debugging tools are installed on the client machine
ƛ This solution is fine for students but is not practical for a
lab
ƛ Due to security holes of IIS you can have hundreds of
security risks on a given network.
ƛ In the Real world situation, all apps will be placed on a
server anyway
c " 

Ä General Features
Ä Additional Features of Vp .Net
Ä What has changed in Vp .Net
M
Ä It is an object oriented language
ƛ Students do better with this subject when they have a firm understanding of
objects
ƛ In the past Vp had objects but focus was not placed on them
ƛ Vp .Net use objects and inheritance with everything
Ä Uses exception handling extensively
ƛ New techniques are shown to the student for providing feedback from their
programs in order to help trouble shoot errors
ƛ Like with most OOÑ languages, exceptions that are not handled will cause
programs to abnormally end or exit
Ä Uses Ơgenericsơ with creating classes and Sub programs
ƛ Can use the top data type on inheritance of type Object
ƛ Used for late binding of data types and is quite useful when implementing stacks or
queues of any data type (.Net 2.0)
Ä Ñrovides a quick way to develop heavy duty applications in a windowing
environment
Ä It is a useful tool for developing event driven programs
   c"

Ä Can create both windows applications and web applications at
the click of a mouse button
Ä The interface between the Databases and applications
ƛ Are the same between web apps and windows apps
ƛ All data are transferred between the apps in XML format
regardless if it is a web application or a windows application
ƛ A copy of the data from the database is loaded into a data set.
ƛ Ñersistent connections between the application and the database
no longer exists
Ä Every form is a class and new forms now have to be
instantiated
Ä Vp .Net is still not case sensitive
0    c"
Ä Data Controls
ƛ pecause of the different way that the apps connect to the
database, there is no longer the support of data controls
in Vp .Net
ƛ Ñersistent connections with the database is no longer
present
Ä Object instantiation is now done differently
Ä Garbage collection for references that lose there
objects are done periodically not when the
reference lose its scope
Ä Ñeriodic changes throughout the language making
it vastly different from Vp 6.0 in order to make it
compliant to the .Net Framework and the CLS
@    
c"
Ä Data Types in Vp .Net
Ä Functions and Sub Ñrocedures
Ä Ñractice Examples
@ c"
Ä Data Types and possible values
ƛ Integer -> -2,147,483,648 (4 bytes)
ƛ Double -> floating point numbers with 14 digits of accuracy
(8
pytes)
ƛ Decimal -> decimal values ( 16 bytes replaced currency in 6.0)
ƛ Date -> the date (8 pytes)
ƛ pyte -> 0 to 255 (1 pyte)
ƛ Char -> Unicode character (2 pytes)
ƛ poolean ->True or false value (2 pytes)
ƛ Single -> floating point number with 6 digits of accuracy (4 bytes)
ƛ Short -> 2 byte integer
ƛ Long -> 8 byte integer
ƛ String -> an arrangement of alpha-
alpha-numeric characters varies in
length
ƛ Object -> any data type 4 bytes
 à
 #!   
c" 
Ä Functions and sub procedures must either have a sub or
function keyword in the function or sub procedure heading
Ä They can be either public or private (following the same
conventions in OOÑ languages such as C++ or Java)
Ä All parameters are passed by value by default in Vp .Net
Ä Ñarameters of any data type may be passed by reference
Ä All Objects and arrays are passed by reference not value
Ä All events are handled by a sub procedure in Vp .Net
Ä Functions return a value and Sub Ñrocedures do Not
! $  %
Ä You can use the text book given to you to
get the basics needed in programming Vp
starting on page 477
Ä Getting familiar with Vp .Net
ƛ Write a program that will take text from one text
box and place that text in another text box with
a click of a button
ƛ Take a look at the attributes of each control
Ä A control can be a button text box etc.
Ä Each control should contain names that follow Vp
specifications i.e. txtpox1 txtpox2 btnMove
Ä Each name as always should be meaningfull
! $ &

Ä Using Functions in Vp .Net


ƛ Use the text boxes from the previous example
ƛ Add a text box
ƛ Ñrovide a function that adds the values of text
box 1 and text box 2
ƛ Ñlace the answer in text box3
ƛ Use variables of type double and use the CDbl()
function to convert the string value of the text
box to a double page 485 in your text
  

Ä The If Statement
Ä The Select Case Statement
Ä The Do While and Loop While loops
Ä The For Loop
@ à 
Ä Every If statement must contain a then and an end if
Ä Example:
ƛ If Num1 < 2 Then
Messagepox.show(ƠThe value is less than 2ơ)
End If
ƛ If Num1 <> 4 then
Messagepox.Show(ƠThe value is not 4ơ)
End If
Ä The relational operators that can be used in Vp are
ƛ >
ƛ <
ƛ =
ƛ >=
ƛ <=
ƛ <> (Not equal to)
@ à° 

Ä The select case statement is a lot like the


switch statement in Java
Ä It can use ANY data type in Vp
Ä Example
Select Case Num1
Case 1 DoSomeThing()
Case 2 Do SomethingElse()
End Select
Ä Yes you can use strings as well
0  

Ä Do while loops evaluate the expression


first then executes the Loop pody
Ä Act much in the same as All While
loops in languages like C++ and Java
Ä Example
Do While Num1 < 10
Num1 += 1
Loop
0  
Ä The pody of the Loop is executed first then
the expression is evaluated
Ä The loop will execute at least once
Ä This is a lot like the do while loop in Java
and students get confused with this subtle
change
Ä Example
Do
Num1 += 1
Loop While Num1 < 10
' %
c

%


&
u    '


! u  ' 
! @

 
u#

! 
 #% 

!  
 # % 

! @

  
% 

! (
 " #
   à " 

Ä Differences between MS SQL and


Access
Ä Advantages of MS SQL
Ä Quirky things with SQL
Ä Connecting to the database with the
manager

à
à 
Ä SQL More Ñowerful than MS Access
ƛ Larger data types are available
ƛ Connection over a network provide
access to multiple clients
ƛ plob data type available
Ä A client is required to connect to the
SQL Database
 àà

Ä Can handle multiple users at one time


Ä Ideal for web sites and web
applications
Ä Contain the pLOp (pinary Large
Object) which enables a user to store
images in a database
Ä Larger numeric values can be stored in
each field
    
 à

Ä No Auto Number Data Type in MS SQL


Ä Auto number is an integer data type
Ä Identity is set to yes
Ä And the seed is set to one
Ä This gives you the option to set the
starting number and the increment
you want the auto number to have
 

Ä Connecting to the database


Ä Getting through the confusion of
locating databases
Ä Defining the different containers in the
Manager
°     "à

Ä Start the Enterprise Manager

Ä Right Click SQL Server group


°     "à
Ä Click on SQL Server
Registration
Ä Click next
Ä In the text box
labeled Available
Servers type
Sigma.vbnet.matcm
p.ncc.edu
Ä Click Add then next
°     "à

Ä Click on SQL Server login


Ä Username is the first six letters of your
last name and your first initial
Ä Ñassword is vbnet
Ä Click next and click next again
Ä Click Finish
Ä Click close on the next dialog box
M     
  
Ä MS SQL Enterprise Manager will display ALL
of the databases located on the server
Ä Access to each database is controlled by the
DpMS
Ä ALL tables are displayed in each database
Ä This includes tables that are used by the
DpMS
@ °   à

Ä Each container
has a specific
role
Ä Student
Databases are
in the
databases
container
°  

Ä Every students
database is displayed
Ä Only the database that
the student has
permissions for can be
opened
Ä Click on the database
container with your
username
à 
  
°   

Ä Creating tables
Ä Ñroperties of the data types
Ä Entering and Displaying Data in
database Tables
° @

Ä Right click on the table container


Ä Click new table
Ä This is a lot like the Access interface
with different data types.
Ä At this points explore the interface and
notice the differences
!     

Ä Each Data Field has a length property


Ä This sometimes causes a problem with
students who make this field too small
Ä Each data Field can also allow null values
Ä After defining each column and setting all
the properties set the primary key by right
clicking on the field that is to be the key
   

Ä Right Click the table
Ä Click Open Table
Ä Click Return All Rows
Ä From here you can view and enter
new data into the table
! $ %
Ä Creating a Table in Vp .Net
Ä Create a table of customers in a hardware store
Ä Columns will include
ƛ Customer ID
ƛ First Name
ƛ Last Name
ƛ Address
ƛ Zip Code
Ä Fill the table with data
Ä Display that data
°    

 c"  
Ä The Data Ñrovider
Ä The Data Set
Ä The use of the wizard
@  

Ä Needed to connect to every DpMS


Ä Must Use the Adapter that represents
the DpMS you are going to use
Ä We are going to use the
SQLDataAdapter Object
Ä Holds the information on how to
@  !  

Ä Manipulates data through the use of SQL


statements or commands
Ä Hold connection information to the
Database
Ä Contain two Major components
ƛ Data Adapter Object ƛ updates data in the
dataset
ƛ Connection Object ƛ maintains the connection
@  à

Ä Holds data returned from a procedure


or Query performed by the data
adapter
Ä Ñrovides a local ƠCopyơ of the data
from the table on the local machine
Ä Ñrevents persistent connections with
the database and reduces network
traffic
@   
(

Ä Give Demo on using the wizard


@  à

Ä Generating the data set object


Ä The use of the onload event handler
Ä pinding controls
Ä Creating navigation for a database
M   à
')
Ä Once the Data Adapter and the
connection object is created click on
Data in the menu
Ä Click generate dataset
Ä Give a name to the dataset
Ä Click OK
@     
*
Ä Double click the form
Ä Ñlace the fill method in the Load event
handler
Ä This will fill the dataset object with the
data from the table when the form
loads
Ä Example
SQLDataAdapter1.Fill(MyDataSet1)
"  °  

Ä Once you create a data set you can then


bind the controls of the form to fields or
columns of the database table
Ä This is done with in the pindings property in
the text box properties sheet
Ä Under the bindings property click text and
then the field you wish to bind to the text
box
°    

Ä Managed by the pindingManagerpase Object
Ä This object contains the Ñosition Ñroperty the holds
the current position of the record in the dataset
Ä This is done by adding one to the position attribute
of the object
Ä Methods of this object includes
ƛ Addnew()
ƛ EndCurrentEdit()
ƛ CancelCurrentEdit() -> provides a role back feature
ƛ RemoveAt() -> deletes current row at given position
$ * 
   
Ä Use try catch block much the same in Java
Ä Can help trouble shoot connections to databases
Ä Very important to use when filling the dataset
Ä Example
Try
SqlDataAdapter1.Fill(DataSet11)
Catch $
$As
As $ 
Messagepox.Show("Error will dataset fill")
End Try
! $ &
Ä Connecting a form to your Hardware customers
Ä Create a form with text fields for each column
ƛ Create the data Adapter and Data Connection with the use
of the wizard
ƛ Create the data set object
ƛ Create the onload event handler to fill the data set
ƛ pind your controls
ƛ pe sure to use exception handling for filling the data set
ƛ Create a Next button to navigate to the next record in the
database
' &
c

%)


*
@  
! ! # #+
 
! ,



     
! 
u 
 c

! u

!  
 #
! u%-u % 
 
 
.
!       c

! /,    


   
 
Ä When Adding records
ƛ The Ñosition of the dataset should be set to the
end
ƛ The text boxes should be cleared
Ä The AddNew() Method accomplishes all this
in one method call
Ä The AddNew() Method is part of the
pindingManagerpase Object
Ä When changes are being made, a cancel
button should be provided to ƠRoll packơ
changes made to the data set
 
Ä When Navigating the database the Text
boxes should be disabled to prevent
changes
Ä There should be an edit button that
ƛ Disables the navigation button
ƛ Enables the text boxes for editing
ƛ Ñrovide a cancel button that ƠRoles packơ the
changes that are made by calling the
CancelCurrentEdit() method of the
pindingManagerpase Object
§  
 
Ä This is done by
ƛ Ending the current edit by calling EndCurrentEdit() in the
pindingManagerpase class
ƛ Updating the Dp with Update() in the data adapter
ƛ Cause the dataset to reflect the changes by calling the
AcceptChanges() method in the data set
Ä Deleting the records
ƛ First Ask the user if they are sure they want to delete
ƛ Use the RemoveAt() method of the pindingManagerpase
object
ƛ Update the database with the Update() method
ƛ Have the dataset reflect the change by calling the
AcceptChanges() method of the dataset object
! $ %

Ä With the Example finished yesterday


ƛ Add an Add putton
ƛ Add an Edit putton
ƛ Ñrovide a Save and a delete feature
ƛ Use exception handling for everything
°  
c"
Ä Creating classes in Vp .Net
Ä The constructor and Sub procedures in
Vp .Net
Ä The use of Modules
° ° c"

Ä Classes can be added to a project by
ƛ Right clicking the project container
ƛ Click add
ƛ Click add class
Ä As in Most OOÑ Languages Vp classes have
ƛ Ñublic and private attributes
ƛ Ñublic and private Methods (called functions or
sub procedures)
ƛ Constructors and Destructors (destructors are
not really needed in Vp because of garbage
collection)
 

Ä Modules can also be added to a


project to provide a place for ƠGlobalơ
Methods and Identifiers
Ä These Identifiers and methods can be
either public or private
Ä Ñublic Identifiers and methods can be
accessed from all of the forms and
classes in the Vp project
! $ 

Ä For this Example


ƛ Create an Auto Class
ƛ An Auto will have
Ä Three Attributes
Ä Three Methods

Ä Two constructors

ƛ Try instantiating the method in the form




Ä When adding menus to a form you can


type in the choice right into the menu
object
Ä Click event handlers can then be
added for each menu choice in the
same manner as the button
    

Ä Colors are important


ƛ They should be contrast in color
ƛ Ease to read
ƛ Easy on the eyes for long periods of viewing
Ä Should provide easy navigation
Ä Should provide a way to enter the data
easily with just using the keyboard
   
 
Ä When creating a form in Vp .Net you are creating a
class
Ä Every class in vb must be instantiated before it is
used
Ä This is accomplished by using the new keyword
Ä When the instance of the form is created, the form
can then be visible by calling the forms show
method
Ä Closing a form does not exit the program. To exit
the program the End method should be called
! $ +

Ä Create a Form that will be a switch


board
ƛ Add a form to yesterdays example
ƛ Ñlace a button that will open the
customer form
ƛ Ñlace a button that will exit the program
" § 
°  
Ä So far we have seen the benefits of bound controls
Ä These are ok if you intend to use the same SQL
query for the whole application
Ä Once controls are bound to a data set, changes to
the query in the data adapter can not be
accomplished
Ä Unbounded controls give you the power to create
new data adapters with new queries.
Ä Values can then be placed into the query to find
specific records in a database
 +
c

%


0
@  
! ! Ñ
   
! ! Ñ
% 
  
! /
  
!  +
  
! 
 #"
 

! %
 
    # #c


! "  
 

à! 
  
 ,