Tutorial 5 Completing the Inventory Application Introducing Programming

Similar documents
Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic

Classes in C# namespace classtest { public class myclass { public myclass() { } } }

Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects

Flag Quiz Application

User-Defined Controls

Inheriting Windows Forms with Visual C#.NET

This is the start of the server code

Web Services in.net (2)

1. Windows Forms 2. Event-Handling Model 3. Basic Event Handling 4. Control Properties and Layout 5. Labels, TextBoxes and Buttons 6.

CSC 330 Object-Oriented Programming. Encapsulation

ListBox. Class ListBoxTest. Allows users to add and remove items from ListBox Uses event handlers to add to, remove from, and clear list

Lampiran B. Program pengendali

Convertor Binar -> Zecimal Rosu Alin, Calculatoare, An2 Mod de Functionare: Am creat un program, in Windows Form Application, care converteste un

CIS 3260 Intro. to Programming with C#

namespace Tst_Form { private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components;

CALCULATOR APPLICATION

IBSDK Quick Start Tutorial for C# 2010

Polymorphism. Polymorphism. CSC 330 Object Oriented Programming. What is Polymorphism? Why polymorphism? Class-Object to Base-Class.

IT 374 C# and Applications/ IT695 C# Data Structures

and event handlers Murach's C# 2012, C6 2013, Mike Murach & Associates, Inc. Slide 1

Arrays. Arrays: Declaration and Instantiation. Array: An Array of Simple Values

In order to create your proxy classes, we have provided a WSDL file. This can be located at the following URL:

Operatii pop si push-stiva

An array can hold values of any type. The entire collection shares a single name

Blank Form. Industrial Programming. Discussion. First Form Code. Lecture 8: C# GUI Development

Sub To Srt Converter. This is the source code of this program. It is made in C# with.net 2.0.

Professional ASP.NET Web Services : Asynchronous Programming

Web Services in.net (7)

You can call the project anything you like I will be calling this one project slide show.

Visual Basic 2008 Anne Boehm

First start a new Windows Form Application from C# and name it Interest Calculator. We need 3 text boxes. 4 labels. 1 button

Using the Xcode Debugger

Conventions in this tutorial

Visual Studio Windows Form Application #1 Basic Form Properties

CHAPTER 3. Writing Windows C# Programs. Objects in C#

Start Visual Studio and create a new windows form application under C# programming language. Call this project YouTube Alarm Clock.

Web Services in.net (6) cont d

Quick Guide for the ServoWorks.NET API 2010/7/13

Skill Area 336 Explain Essential Programming Concept. Programming Language 2 (PL2)

Experiment 5 : Creating a Windows application to interface with 7-Segment LED display

Objectives. Introduce static keyword examine syntax describe common uses

Konark - Writing a KONARK Sample Application

The Open Core Interface SDK has to be installed on your development computer. The SDK can be downloaded at:

Code Editor. The Code Editor is made up of the following areas: Toolbar. Editable Area Output Panel Status Bar Outline. Toolbar

Start Visual Studio, create a new project called Helicopter Game and press OK

To start we will be using visual studio Start a new C# windows form application project and name it motivational quotes viewer

6.170 Laboratory in Software Engineering Java Style Guide. Overview. Descriptive names. Consistent indentation and spacing. Page 1 of 5.

Hands-On Lab (MBL04) Lab Manual Incorporating COM Objects into Your.NET Compact Framework 2.0 Application

The Microsoft.NET Framework

#pragma comment(lib, "irrklang.lib") #include <windows.h> namespace SuperMetroidCraft {

Introduction to C# Applications Pearson Education, Inc. All rights reserved.

Getting started 7. Storing values 21. Creating variables 22 Reading input 24 Employing arrays 26 Casting data types 28 Fixing constants 30 Summary 32

Course 2D_WPF: 2D-Computer Graphics with C# + WPF Chapter C1a: The Intro Project Written in XAML and C#

Introduction to Microsoft.NET

XNA 4.0 RPG Tutorials. Part 11b. Game Editors

Tutorial 3 - Welcome Application

COPYRIGHTED MATERIAL. Visual Basic: The Language. Part 1

Representing Recursive Relationships Using REP++ TreeView

This is the empty form we will be working with in this game. Look under the properties window and find the following and change them.

Dr.Qadri Hamarsheh. Overview of ASP.NET. Advanced Programming Language (630501) Fall 2011/2012 Lectures Notes # 17. Data Binding.

Now find the button component in the tool box. [if toolbox isn't present click VIEW on the top and click toolbox]

The contents of this document are directly taken from the EPiServer SDK. Please see the SDK for further technical information about EPiServer.

C# and.net (1) cont d

Visual Studio.NET enables quick, drag-and-drop construction of form-based applications

Avoiding KeyStrokes in Windows Applications using C#

3 Welcome Application 41 Introduction to Visual Programming

Tutorial 2 - Welcome Application Introducing, the Visual Studio.NET IDE

LESSON B. The Toolbox Window

Microsoft Excel 2010 Handout

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Chapter 2: Introduction to C++

GUI Design and Event- Driven Programming

NAMESPACES IN C++ You can refer the Programming with ANSI C++ by Bhushan Trivedi for Understanding Namespaces Better(Chapter 14)

We are going to use some graphics and found a nice little batman running GIF, off course you can use any image you want for the project.

Visual Basic/C# Programming (330)

Visual C# Program: Simple Game 3

Lecture 18 Tao Wang 1

Visual Basic/C# Programming (330)

You will have mastered the material in this chapter when you can:

Before You Begin 1 Graphing Application 1 Introducing Computers, the Internet and Visual Basic.NET

It is necessary to follow all of the sections below in the presented order. Skipping steps may prevent subsequent sections from working correctly.

Word Select New in the left pane. 3. Select Blank document in the Available Templates pane. 4. Click the Create button.

C# Programming: From Problem Analysis to Program Design. Fourth Edition

Chapter 10 Introduction to Classes

UNIT-3. Prepared by R.VINODINI 1

Subject to Change Drawing Application 1 Introducing Computers, the Internet and C#

CST8152 Compilers Creating a C Language Console Project with Microsoft Visual Studio.Net 2010

Chapter 12. Tool Strips, Status Strips, and Splitters

HL7Spy 1.1 Getting Started

Savoy ActiveX Control User Guide

PS2 Random Walk Simulator

Create your own Meme Maker in C#

Dreamweaver Publishing and Editing Files. Outline

Chapter 8 Advanced GUI Features

Creating a new CDC policy using the Database Administration Console

Departme and. Computer. CS Intro to. Science with. Objectives: The main. for a problem. of Programming. Syntax Set of rules Similar to.

Visual C# Program: Temperature Conversion Program

SCP-MOD Quick Reference Guide: Discrete Orders Buyer

Event-based Programming

CIS 3260 Sample Final Exam Part II

Transcription:

1 Tutorial 5 Completing the Inventory Application Introducing Programming Outline 5.1 Test-Driving the Inventory Application 5.2 Introduction to C# Code 5.3 Inserting an Event Handler 5.4 Performing a Calculation and Displaying the Result 5.5 Using the Debugger: Syntax Errors 5.6 Wrap-Up

2 Objectives In this tutorial, you will learn to: Add an event handler for a Button control. Insert code into an event handler. Access a property s value by using C# code. Use the assignment and multiplication operators.

5.1 Test-Driving the Inventory Application 3 Application Requirements A college bookstore receives cartons of textbooks. In each shipment, each carton contains the same number of textbooks. The inventory manager wants to use a computer to calculate the total number of textbooks arriving at the bookstore for each shipment, from the number of cartons and the number of textbooks in each carton. The inventory manager will enter the number of cartons received and the fixed number of textbooks in each carton for each shipment; then the application will calculate the total number of textbooks in a shipment.

4 5.1 Test-Driving the Inventory Application Figure 5.1 Inventory application with quantities entered. Input data into application Enter 3 in the Cartons per shipment: TextBox Enter 15 in the Items per carton: TextBox

5.1 Test-Driving the Inventory Application 5 Figure 5.2 application. Result of clicking the Calculate Total Button in the Inventory Result of calculation Click the Calculate Total Button Observe result of calculation in the descriptive Label

6 5.2 Introduction to C# Code The Options dialog Setting option for Visual Studio.NET environment

5.2 Introduction to C# Code 7 Figure 5.3 Options dialog. Text Editor folder icon

8 5.2 Introduction to C# Code Adding line numbers Select the Text Editor folder icon Select the General item Place a check in the CheckBox next to Line Numbers

5.2 Introduction to C# Code 9 Figure 5.4 General settings page for C# text editor. C# folder General item Line Numbers CheckBox (checked)

10 5.2 Introduction to C# Code Setting the tab Change the Indenting option Change the Tabs settings Insert spaces for each tab

5.2 Introduction to C# Code 11 Figure 5.5 Setting the Tabs options. Smart Indenting (selected) Tabs item Insert spaces (selected)

12 5.2 Introduction to C# Code Fonts and colors Change color used to display code Use Defaults Button resets values

5.2 Introduction to C# Code 13 Figure 5.6 Examining the Fonts and Colors page. Fonts and Colors item Use Defaults Button

14 5.2 Introduction to C# Code Renaming the Form Set Form s Name property to FrmInventory

15 5.2 Introduction to C# Code The code editor Code view using directive Allows access to classes within specified namespace Class declaration class keyword Identifier Braces around class body Case sensitivity C# keywords and identifiers are case sensitive Main method

5.2 Introduction to C# Code 16 Figure 5.7 application. IDE showing the uppermost portion of the code for the Inventory Inventory.cs tabbed window Using FCL namespaces Class is declared in the Inventory namespace Class declaration

5.2 Introduction to C# Code 17 Figure 5.8 application. IDE showing the lowermost portion of the code for the Inventory Main method

18 5.2 Introduction to C# Code Generated code Expanding the code Outlined code

5.2 Introduction to C# Code 19 Figure 5.9 Windows Form Designer generated code, when expanded. Expanded code

5.2 Introduction to C# Code 20 Figure 5.10 Ellipses indicating outlined code. Outlined code

21 5.2 Introduction to C# Code Generated code for a control Default properties The result of changes from design view

5.2 Introduction to C# Code 22 Figure 5.11 Code generated by the IDE for lblcartons (with the code setting the Text property highlighted). Click tab for design view Property values for lblcartons

23 5.3 Inserting an Event Handler Renaming the Form in code In comments above class declaration In Main method

5.3 Inserting an Event Handler 24 Figure 5.12 Renaming the Form above the class declaration.

5.3 Inserting an Event Handler 25 Figure 5.13 Renaming the Form in method Main and adding spacing.

26 5.3 Inserting an Event Handler Event handling Visual Studio.NET automatically inserts event handler when controls are double clicked Event handler naming convention

5.3 Inserting an Event Handler 27 Figure 5.14 Event handler btncalculate_click before you add your code. Empty event handler Asterisks indicate unsaved changes to application

28 5.3 Inserting an Event Handler Figure 5.15 Running application without functionality. Close box Examine the application Closing an application using the close box

29 5.3 Inserting an Event Handler Adding code to an event handler Comments in code Comments appear in green Use double slash characters Executable C# statement Ends with semicolon Accessing properties Member access operator (.)

5.3 Inserting an Event Handler 30 Figure 5.16 Adding code to the Calculate Total Button s event handler. Event handler Type this code

31 5.3 Inserting an Event Handler IntelliSense Display entire class members and their purposes Assignment operator Two operands Right to left

5.3 Inserting an Event Handler 32 Figure 5.17 IntelliSense activating while entering code. Selected member Intellisense Description of selected member

33 5.3 Inserting an Event Handler Figure 5.18 Running the application with an event handler. Result of clicking Calculate Total Button Run the application Enter input and examine the result

5.4 Performing a Calculation and Displaying the Result 34 Changing the event handler Add comments Break header over multiple lines Multiplication operator Int32.Parse method Call a method Return a value Convert.ToString method

5.4 Performing a Calculation and Displaying the Result 35 Figure 5.19 Using multiplication in the Inventory application. Modified Inventory application code

1 using System; 2 using System.Drawing; 3 using System.Collections; 4 using System.ComponentModel; 5 using System.Windows.Forms; 6 using System.Data; 7 8 namespace Inventory 9 { 10 /// <summary> 11 /// Summary description for FrmInventory. 12 /// </summary> 13 public class FrmInventory : System.Windows.Forms.Form 14 { 15 private System.Windows.Forms.Label lblcartons; 16 private System.Windows.Forms.Label lblitems; 17 private System.Windows.Forms.Label lbltotal; 18 private System.Windows.Forms.Label lbltotalresult; 19 private System.Windows.Forms.TextBox txtcartons; 20 private System.Windows.Forms.TextBox txtitems; 21 private System.Windows.Forms.Button btncalculate; 22 /// <summary> 23 /// Required designer variable. 24 /// </summary> 25 private System.ComponentModel.Container components = null; Renaming the Form Outline Inventory.cs (1 of 4) 36

26 27 public FrmInventory() 28 { 29 // 30 // Required for Windows Form Designer support 31 // 32 InitializeComponent(); 33 34 // 35 // TODO: Add any constructor code after InitializeComponent 36 // call 37 // 38 } 39 40 /// <summary> 41 /// Clean up any resources being used. 42 /// </summary> 43 protected override void Dispose( bool disposing ) 44 { 45 if( disposing ) 46 { 47 if (components!= null) 48 { 49 components.dispose(); 50 } Outline Inventory.cs (2 of 4) 37

51 } 52 base.dispose( disposing ); 53 } 54 55 // Windows Form Designer generated code 56 57 /// <summary> 58 /// The main entry point for the application. 59 /// </summary> 60 [STAThread] 61 static void Main() 62 { 63 Application.Run( new FrmInventory() ); 64 } 65 66 // handles Calculate Button's Click event 67 private void btncalculate_click( 68 object sender, System.EventArgs e ) 69 { 70 // multiply values input and display result in Label 71 lbltotalresult.text = Convert.ToString( 72 Int32.Parse( txtcartons.text ) * 73 Int32.Parse( txtitems.text ) ); 74 75 } // end method btncalculate_click Renaming the Form Adding a comment to your code Adding a comment to your code Outline Inventory.cs (3 of 4) Adding an event handler to your code 38

76 77 } // end class FrmInventory 78 } Adding a comment to your code Outline 39 Inventory.cs (4 of 4)

40 5.5 Using the Debugger: Syntax Errors Figure 5.21 Results of successful build in the Output window. Output window Shows result of compilation

41 5.5 Using the Debugger: Syntax Errors Figure 5.22 Task List lists syntax errors. The Task List Displays the build error Description of the error Line number corresponding to the error

42 5.5 Using the Debugger: Syntax Errors Identifying syntax error Real-time error checking Errors are underlined by a red jagged line Task List will display the errors

5.5 Using the Debugger: Syntax Errors 43 Figure 5.23 IDE with syntax errors. Jagged red underline indicates syntax error

5.5 Using the Debugger: Syntax Errors 44 Figure 5.24 Task List displaying the syntax error recognized in real time.

45 5.5 Using the Debugger: Syntax Errors Matching the syntax error in the code Double click an error in the Task List to highlight the code with the syntax error

5.5 Using the Debugger: Syntax Errors 46 Figure 5.25 Highlighting the portion of code where a syntax error occurs. Highlighted syntax error

47 5.5 Using the Debugger: Syntax Errors Identifying second syntax error Build > Build Solution compiles code Syntax error not found in real time

5.5 Using the Debugger: Syntax Errors 48 Figure 5.26 IDE with second syntax error. Jagged blue underline indicates compilation error Compilation error shown in task list