Download presentation
Presentation is loading. Please wait.
Published byTerence McBride Modified over 7 years ago
1
Tutorial 14 – Shipping Time Application Using DateTimes and Timers
Outline 14.1 Test-Driving the Shipping Time Application DateTime Variables Building the Shipping Time Application: Design Elements Creating the Shipping Time Application: Inserting Code Wrap-Up
2
In this tutorial, you will learn to:
Objectives In this tutorial, you will learn to: Create and manipulate DateTime variables. Execute code at regular intervals using a Timer control. Retrieve DateTime input with a DateTimePicker control. Group controls using a GroupBox control.
3
14.1 Test-Driving the Shipping Time Application
4
14.1 Test-Driving the Shipping Time Application
Figure 14.1 Shipping Time application. DateTimePicker with up-down arrows GroupBoxes
5
14.2 DateTime Variables Keyword new DateTime variable
Calls a structure’s constructor Example: DateTime dtmDelivery = new DateTime( , 1, 1, 0, 0, 0 ) Constructors initialize class objects or structure values DateTime variable Stores information about a point in time Contains properties Year, Month, Day, Hour, Minute, and Second
6
14.2 DateTime Variables Figure 14.2 DateTime constructor arguments.
7
14.2 DateTime Variables Figure 14.3 DateTime methods that perform various calculations.
8
14.3 Building the Shipping Time Application: Design Elements
9
14.3 Building the Shipping Time Application: Design Elements
10
14.3 Building the Shipping Time Application: Design Elements
Figure 14.5 GroupBox controls on the Shipping Time Form. Newly created GroupBox displaying the text Drop Off GroupBoxes Add a second Groupbox to contain drop off time
11
14.3 Building the Shipping Time Application: Design Elements
Figure 14.6 Adding a Label to a GroupBox. Before clicking inside the GroupBox Place a label inside the GroupBox by clicking the Label tab in the Toolbox
12
14.3 Building the Shipping Time Application: Design Elements
Figure 14.7 DateTimePicker control on the Form. DateTimePicker control before modification (note that the appearance is similar to a ComboBox) Add a DateTimePicker to the application by clicking the DateTimePicker control in the Toolbox
13
14.3 Building the Shipping Time Application: Design Elements
Figure 14.8 Customized DateTimePicker control on the Form. Up-down arrows for DateTimePicker (note that the appearance is similar to a NumericUpDown control) Set ShowUpDown property to true
14
14.3 Building the Shipping Time Application: Design Elements
Figure 14.9 Timer control is displayed in the component tray. Component tray Timer control
15
14.3 Building the Shipping Time Application: Design Elements
Figure 14.10 Rearranging and commenting the control declarations.
16
14.4 Creating the Shipping Time Application: Inserting Code
Tick event handler DateTime property Now retrieves current time Format output hh:mm:ss tt
17
14.4 Creating the Shipping Time Application: Inserting Code
Figure 14.11 Inserting code for a Tick event. Printing the current time
18
14.4 Creating the Shipping Time Application: Inserting Code
Load event handler Date stored in dtmCurrentTime FrmShippingTime_Load event handler MinDate: earliest date allowed MaxDate: latest date allowed
19
14.4 Creating the Shipping Time Application: Inserting Code
Figure 14.12 Storing the current time. Storing the current time in dtmCurrentTime
20
14.4 Creating the Shipping Time Application: Inserting Code
MinDate property Earliest value user can enter Set to 12:00 AM MaxDate property Latest value user can enter Seafood must remain fresh, so value will be set to one day after MinDate
21
14.4 Creating the Shipping Time Application: Inserting Code
Figure 14.13 Setting the MinDate and MaxDate properties. Setting the range of drop-off times
22
14.4 Creating the Shipping Time Application: Inserting Code
Figure 14.14 Calling the DisplayDeliveryTime method. Displaying the delivery time
23
14.4 Creating the Shipping Time Application: Inserting Code
Need to allow user to select a date Application will calculate delivery time ValueChanged event handler
24
14.4 Creating the Shipping Time Application: Inserting Code
Figure 14.15 Inserting code in the ValueChanged event handler. Calculating and displaying the delivery time
25
14.4 Creating the Shipping Time Application: Inserting Code
Figure 14.16 Calling the DepartureTime method. Determining the departure time Calculating the travel time Displaying the delivery time
26
14.4 Creating the Shipping Time Application: Inserting Code
Figure 14.17 Inserting method DepartureTime into the application. Declaring variables
27
14.4 Creating the Shipping Time Application: Inserting Code
Figure 14.18 Determining the seafood shipment’s flight departure time. Using the hour value stored in the DateTimePicker to determine departure time Noon departure time Noon (the next day) departure time Midnight departure time
28
14.4 Creating the Shipping Time Application: Inserting Code
Figure 14.19 Returning the flight departure time. Returning the departure time
29
ShippingTime.cs (1 of 7)
30
ShippingTime.cs (2 of 7)
31
ShippingTime.cs (3 of 7)
32
ShippingTime.cs (4 of 7) Displaying the current time Setting the DateTimePicker’s minimum and maximum values
33
ShippingTime.cs (5 of 7) Calculating and displaying the delivery time in Las Vegas
34
ShippingTime.cs (6 of 7) Using a switch statement to determine departure time
35
ShippingTime.cs (7 of 7)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.