Engineering Informatics I
Demo
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 69
C#
UI element
• Menu: list of options that users can select to perform various actions
• Button: clickable element that triggers a specific action
• CheckedListBox: list box that allows multiple items to be selected
• ComboBox: drop-down list that allows users to select one item from
a list
• DataGridView: grid-like control that displays data in a tabular format
• DateTimePicker: control that allows users to select a date and time
• ListBox: list of items from which users can select one or multiple
items
• Panel: container that holds and groups other controls or elements
• TextBox: field that allows users to input text
• TreeView: hierarchical list that displays items in a tree structure
• TabControl: control that organizes multiple pages or panels into tabs
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 70
C#
UI Properties and Events
• Properties: used to modify the UI element
Property Types: Text, Enabled, BackColor, Visible
• Events: used to modify behaviour of the UI element
Event Types: Click, SelectedIndexChanged,
TextChanged, AfterSelect
• Type of events and properties can change due to UI
element type
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 71
C#
Hello World
• Program.cs: contains start method of your
program (Static void Main(): )
• Application.Run(new Form1());
creates new Form1 object
• Open Code: right click Form → View Code
→ Opens Code of the Form1 object
• Form1 : Form inherits from Form Class from
System.Windows.Forms → Allows to use Form Methods
• public Form1(): constructor method of Form1 class
is automatically called when Form1 object is created
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 72
C#
Hello World
1. Form_Load: event that is executed when Form is loaded
2. MessageBox.Show(): opens yes/no Box
• If „Nein“ is pressed → form is closed
• If „Ja“ is pressed → program proceeds
3. Button_Click: event that gets executed
when button it is assigned to is pressed 3
4. this.Close(): closes current form
1
• this.: references current class
2
Form1
MessageBox
Button
4
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 73
C#
Password-Login
• CheckBox: option that can be selected to display
the characters of the string 1
1. CheckBox_changed: is executed everytime the
state of the CheckBox is changend
checks for state of CheckBox and executes „if“ 2
2. LinkLabel_Click: is executed whenLink is clicked
3
3. TextBox.Text: gets text input from TextBox
4. if(condition): checks if right input is made 4
• „user“.Equals(username): condtion for username
5
• &&: connects two conditions
• if(true): login right Label TextBox
5. else: login wrong
CheckBox LinkLabel
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 74
C#
Calculator
• Number TextBox: input field to numbers to be calculated Number TextBox
• Operator Buttons: current mathematical operator defined
Current Equation
by button pressed (+, -, *, /)
• Equal Button: executes the current stored equation Operator Clear
Buttons Buttons
• Equation Label: stores the current equation as a string to
display
Equals
Buttons
1. Class variables: variables are declared at the class level
and are used throughout the form
• result: stores the result of calculation, is 0 at the beginning
• num1: stores fist number of equation (can be the result)
1
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 75
C#
Calculator
• btnOperator_Click: when operator button is pressed,
assigns operator character and executed calculate method
1. calcOperator: gets operator character assigned
1
2. calculate(): calling the calculate method 2
3. if(condition): checks if TextBox is empty and
2
result is not null if true → num1 = result
3
4. else: is executed if conidtions arent met
5. try/ catch: try to convert inputField text into int 4
if execption is thrown execute catch
6. equation string is generated and assigned 5
to label
7. input.Text is set to empty string and is selected
6
7
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 76
C#
Calculator
1. try/catch: trys to converts input from TextBox for the
second number into integer if exception is thrown num2 is 1
set null
2. if(num2 != null): num2 is not null execute code block 2
3. switch: depending which character is assigned to 3
4
calcOperator corresponding case is executed
4. case: executes mathematical operation according to case
5. try/catch(DivideByZeroException): if divided by 0 an
exception is thrown and exspicially handeld in catch
5
6. Updates the equation with calculated result by adding
num2 and result to string
7. TextBox.Text: clears input text and sets courser to
6
TextBox
7
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 77
C#
OpenFileDialog & SaveFileDialog
• openFileDialog: UI element that allows users to
browse the file system and select a file to open
• Button_Click: Event assigned to OpenButton
1. DialogResult: stores the result of opened Dialog
when file is selected DialogResult.OK is returned
2. .FileName: returns filepath from FileDialog
3. if(): check if returned DialogResult is .OK and
filename string is not empty
4. StreamReader: object is created and filename
1
is passed to the constructor
2
5. ReadToEnd(): is used to read out all of the
3
information and afterwards instance is close 4
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 78
C#
OpenFileDialog & SaveFileDialog
• saveFileDialog: allows the user to specify a
location, name, and extension for saving a file
• Button_Click is assigned to SaveButton
1. SaveDialog is opend, DialogResult is passed to
variable, filename is retrieved and filename and
result are checked
2. StreamWriter: object is created and filename is
passed to the constructor
append: false → file is overwritten
append: true → information is added 1
3. sw.Write: information from textBox is written via
the StreamWrite to a file 2
StreamWriter is closed
3
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 79
C#
PDF_Export
1. Drawing.Image variable is decleared that later
represent the image
Combo
• Image class is from the System.Drawing namespace Box
2. Form1(): constructor which is called when object
is created and calls fillComboBox method
3. List<strings>: of type string is created and 1
multiple strings are added
4. .Datasource: of the ComboBox is set to the list 2
• .Datasource: is used when information is static
(doesnt change during runtime)
• .DataBindings: is used when Information of the
3
DataBinding is dynamic (changes during runtime)
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 80
C#
PDF_Export
• ComboBox_SelectedIndexChanged:
Image UI
event that is triggered on index change element
1. ComboBox.Text: is assigned to variable
1
2. switch/ case: depending on the text
value a picture from the resources is
assigned to the Image pImage
2
• Resources folder: need to be named
correctly and images need to be added
3. Case „Load Picture“: File is loaded
4. .Image: image UI element gets pImage 3
assigned
4
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 81
C#
PDF_Export
1. Document: object doc is created
2. PdfWrite.GetInstance: returns PDFWrite
object that writes to doc object to a file
• Document doc object to write information to
• FileStream: with path to target location
1
• FileMode.Create: creates or overwrites file 2
at target location 3
3. doc.Open(): opens the document 4
4. Paragraph: object from namespace 5
iTextSharp is created and Text passed
6
5. iTextSharp.Image: is created and pImage is
passed to the constructor
6. Document is closed
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 82
C#
PDF_Export
• To use „using iTextSharp.text“ (and other libraries) package needs to be imported via
NuGet
• Right click on project → Manage NuGet Packages
• Browse Package, Select and install
• Afterwards using „namespace“ can be used in code
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 83
C#
Excel_Export
1. LoadGridData(): method is called from LoadEvent
and sets up DataGridView on Load
2. DataTable: object „dt“ is created DataGridView
3. dt.Columns.Add: creates columns and sets their
column name & data type 1
4. DataRow: empty row object is created 2
• values are assigned to attributes (columns)
3
• row is added to Datatable
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 84
C#
Excel_Export
• Implementation of employee class
1. public variables: are declared 1
2. public employee: class constructor which
is called when class is instantiated
• Create List of type employee and add 2
instances to DataTable
3. List<employee>: creates list of employee 3
4. new employee: new class object is
created with attributes & added to the list 4
5. foreach: iteration through list 5
6. adds employee information to datatable
6
7. .DataSource: gets DataTable assigned
7
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 85
C#
Excel_Export
• Export DataGridView to Excel
1. if(): check if DataGridView is empty 1
2. Excel.Application: object is created 2
to interact with Excel Application
More Information at Interop.Excel 3
3. for-loop: iterating through first row of
DataGridView to write header text to 4
first row of excel document
4. Nested for-loops: iterating through
columns and rows to get access to 5
the value of each cell
5. if(value!=null): write value from
DataGridView to cell in the excel
document at the same location
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 86
C#
Multiple Forms
• Add additional Windows Form to
project
• Button opens second form and
passes text to Form2
Button
Label
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 87
C#
Multiple Forms
1. Main(): method that opens Form1 1
2. Button_Click: Form2 object is created and text
from TextBox is passed to constructor of Form2
2
3. Form2 constructor: is executed when Form2
object is created
• passes inputText to class variable textpassed
3
• executes addExcelMark method
4. addExcelMark(): method that adds „!“ to the end 5
of a string and returns string to same variable
5. Return value: data type of return value is defined
as string therefore textpassed must be a string
4
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 88
C#
Multiple Forms
• menuStrip UI element: that can be added to
a form to create a menu with sub-buttons Menu Strip
• openFileDialog element: is added to Form
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 89
C#
Tab pages
• Form1: only one Windows Form element is
created that contains multiple tab windows add
new
• Tabs: allow to organize one form element
Tabs
according to diffrent topics
• New tabs can be created manually in the
design view
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 90
C#
String editing
• Button delets the selected item from the list
1. .SelectedIndex: get the currently selected index 1
2
of the list UI element
3
2. .RemoveAt(): delets the item at a certain index
3. catch(): if no item is selected try block would
throw an exception and catch block is executed
1
• Button delets the last character of the string 2
1. textBox.Text: gets the current text of the
TextBox Delete Delete last
selected character
2. str.Substring: returns the string from startIndex item
to endIndex
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 91
C#
String
• Button delets the selected item from the list
1. Convert.ToChar: converts first character
of string to character data type 1
2. .Split: splits given string to substrings at
2
3
given character and returns array
3. foreach: add strings in array to listBox
Item by iterating over the array
Split string at
character
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 92
C#
String editing
• Button compares two strings from
textBox elements
1
1. .Equals: determines if both strings
have the same value then returns true
or false
• Button adds text from second TextBox
to the text of the first TextBox
1
1. string.Concat(): adds value of the
second string to the first string and
Compare two
returns the concated string strings
Add two strings
together
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 93
C#
Demo 1
1. Select Room and Light-Type and
provide spacial information
2. Based on given information number of 2
lamps are calculated and information is
summarized
3. Presents details for current light-type
4
4. Exports current
project information
1
3
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 94
C#
Demo 1
• Starting information for ComboBox, List, TreeView, etc.
can be set in editor
• Properties → Items → three dots
→ enter starting information
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 95
C#
Demo 1
1. Light Form: new object of Light (Form) is created
and LightBulbType is passed as string to 1
constructor and Form object is opened
2. Light constructor: passes given string to class 2
variable lightbulbtype
3. TextBox: displays lightbulbtype string
technical information is hardcoded 3
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 96
C#
Demo 1
1. SelectedIndexChanged Event: gets
1
selected item and parses it to string
depending on Index (room type) luminosity
value is selected
2. TextChanged Event: calls
flaecheBerechnen
2
3. calcArea(): if TextBoxes are not empty try
to parse string to double, multiply with each
other and round to third decimal place
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 97
C#
Demo 1
1. if, else if: checks if both ComboBox has
no item selected (SelectedIndex ==-1) 1
2. if, else if: determining which LightType is
selected and setting value accordingly
3. Amount: calculation the needed amount
of lightbulbs with mathematical equation
4. Price: calculation the price with equation 2
3,4
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 98
C#
Demo 1
1. SaveFileDialog: open SaveFileDialog and
getting string of FilePath
2. if(): DialogResult.OK and string is not
empty start export
3. StreamWriter: object generated and text
from TextBox is exported
1
2
3
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 99
C#
Demo 2
1. Displays room 1. Input fields for room information
2. Opens Room Form to add new 2. Saves room to list, if room already exists
room MessageBox to overwrite room is displayed
3. Displays detailed information of 3. Delete the currently
selected room selected room
1
1
2 3
2
2 2
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 100
C#
Demo 2
• class Room: represents room objects
1. class variables: describing the 1
properties of the room
set private to deny outside access
2. get/ set: to access private variables 2
3. Room constructor: initializes class
variables when Room is instantiated
4. CalcArea: calculates the room area with
the given class variables 3
5. Child Class Sanitaryroom: inherits from
the class room
5 4
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 101
C#
Demo 2
1. Room list class: class that contains
dictionaries and can be passed through forms 1
2. room list: object is instantiated
3. Form NewRoom: is called and roomlist object 2
is passed.
3
• Objects (classes) are reference data types:
multiple variables point to the same object
• Int, bool, float are value data types:
each variable holds its own copy of the data
4. this.Owner: establish an ownership 4
relationship between two forms. 5
5. raumliste: reference to roomlist object is
passed to class variable
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 102
C#
Demo 2
1. Room: new room object is created
2. switch(): depending of text of the selected item in ComboBox a case
block is executed
3. case block: new object of the specific room type which inherits from
class “Room” is created and initialized with values from the form fields
4. raumhinzufuegen(): adds room object
with string as key to Dictionary 1
5. Default: if no type is selected
2
MessageBox is shown
3
4
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 103
C#
Demo 2
1. raumhinzufuegen(): method has string and variable of type „Raum“ as input parameter
• String: gets value from TextBox.Text and functions as key in the dictionary
• Raum: gets value from created room object and represent the value in the dictionary
2. try: key values must be unique in dictionary, if not an exception will be thrown
3. MessageBox YesNo: asking the user whether they want to overwrite the existing room
with the new one
4. if(): result is Yes, existing value of
key “name” is replaced
1
2
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 104
C#
Demo 2
1. lbraeume.SelectedValue.ToString(): gets the
selected value of listbox as string and removes 1
the value from dictionary by using key „Name“ 3
2. raumeakualisieren(): sets the DataSource of
ListBox item to the list of values from the 2
dictionary
3. try/catch(): if no item is selected exception
would be thrown
4
4. flaecheberechnen(): method that is called
when text of TextBox changes
calculates area of the room 4
by getting values from TextBoxes
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 105
C#
Demo 2
1. NewRoom.ShowDialog(): after dialog is 1 2
closed updateNodes() method is called
2. updateNodes(): clears all Nodes of TreeView
item and calls loadNodes() method 3
3. loadNodes(): creates a new Node in the 4
TreeView for each Room in roomlist dictionary
5
4. Tvroom_AfterSelect: event that is called if
TreeView Node is selected
6
5. .TryGetValue: trys to get a object of Room by
referencing the key and returns true if room
is found
6. Room attributs are assigned to TextBox
Information
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 106
C#
Demo 3
• Demo 3 contains two projects: IIB_Class.sln and IIB_GUI.sln
• IIB_Class.sln: contains reusable classes and methods that can
be referenced and used in other projects.
• IIB_GUI.sln: contains the graphical interface that the user can
interact with
• More information can be found in project properties
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 107
C#
Demo 3
• Use class library (.dll) in GUI project 1
1. Open IIB_Class.sln and build solution 1
2. .dll file will be created in the bin/Debug directory
2
enable „Show all Files“
• Open IIB_GUI.sln
3. Right click references/ Add References/ Browse 2
4. Search for .dll in \IIB_Class\IIB_Class\bin\Debug project directory
5. Added Reference should be shown in References
3
5
3
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 108
C#
Demo 3
• Add light: open FormLamp to fill
out the details and add the lamp
• Edit: opens FormLamp to edit the
detailed information of the
currently selected item
• Delete: delets the currently
selected item
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 109
C#
Demo 3
• Add building: Opens FormBuilding to
add a building node to the TreeView Item
• Add floor: Opens FormFloor to add a
floor Node to a building Node
building node needs to be selected
• Add room: Opens FormRoom to add a
room Node to a floor Node
floor node needs to be selected
• Detailed information can be added in the
according Form
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 110
C#
Demo 3
• Display the cost: calculates the
costs of the lightbulbs for the
currently selected node in the
TreeView
• Room selected: calculates the cost
of all lightbulbs in the room
• Floor selected: calculates the cost
of all lightbulbs in all rooms in that
floor
• Building selected: calculates the
cost of all lightbulbs in that building
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 111
C#
Demo 3 – IIB_Class
• Interface Calculation: define a contract that classes
inherites from the interface must follow.
• CalculateCost(): Every class that inherites from
Calculation must implement the CalculateCost()
method which returns a float
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 112
C#
Demo 3 – IIB_Class
1
1. [Serializable]: indicates that instances of this 2
class can be serialized (can be saved in file)
2. : Calculation: Building class inherits from
interface Calculation 3
3. Private Attributes & get/ set: stores building
information and can be accessed by get/set
4. Constructor: allows to create object of Building
class with or without initializing properties 4
5. BindingList<Floor>: list with additional
functionality that implements the aggregation
5
relationship between building and floor
6. CalculateCost(): implementation of the
CalculateCost method according to the interface 6
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 113
C#
Demo 3 – IIB_Class
1. Class Floor: has the same structure as class
building with [Serializable], private class
variables, constructor and a BindingList to
realise aggregation relationship between Floor 1
and Room
2. CalculateCost(): iterates through all Room
objects in BindingList<Room> raeume and calls
calculateCost method and adds return value to
sum of the current floor
2
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 114
C#
Demo 3 – IIB_Class
1. Class Room: contains private
variables and get & set methods
2. berechneFlaeche(): calculates the
area of the current room and
returns double value
3. CalculateCost(): calculates the sum
of the prices of the lamps on the
room level.
• Basis for calculation of cost on Floor and
Building level
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 115
C#
Demo 3 – IIB_GUI
1. using IIB_Class: IIB_Class library now can be
used from GUI project
2. FormStart(Project): gets project passed which
contains List<Building> and List<Lampe>
represents current project that is used
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 116
C#
Demo 3 – IIB_GUI
• add light and edit Button
1. AddLight_Button: opens FormLamp
rest of the code starting at if statement
is executed after closing FormLamp
2. FormLamp_Load: fills the input fields 3 1
of FormLamp with information from current lamp
3. AddLight(): FormLamp is called with empty
constructor, therefore new Lamp object is created 4
4. EditLight(): FormLamp is called with selected Lamp
object in ListBox and object is passed to current lamp 2
• Depending on Button diffrent constructor is called and
either new Lamp is created or current Lamp will be 2
edited
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 117
C#
Demo 3 – IIB_GUI
1. if(form.speichern): depending on outcome of
2
FormLamp Dialog code block is executed or not
2. btnCancel: closes FormLamp but „speichern“
variable stays false, therefore if is not executed
3. btnOK: aktuelleEingabeHolen() is executed,
3
„speichern“ variable is set to true, FormLamp is
closed and if is executed
4
4. aktuelleEingabeHolen(): gets information from input
fields at passed values to aktuelleLamp object
5. if(form.speichern): lamp object is added to the list,
added lamp object is selected 1
Datasource is updated
5
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 118
C#
Demo 3 – IIB_GUI
• Delete Lamp button 1
1. if(!ChooseLampChecking()): method checks if 2
3
SelectedItem equals null and returns true or false
2. if(false): return will intercept current method 4
3. if(true): selected item of type Lamp is get from
ListBox
5
4. foreach: iterates through floors in building,
afterwards rooms in floors, 6
5. if(): selected Lamp equal Lamp of room, lamp of
room is set to null
6. Selected Lamp is removed from _lamp list 1
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 119
C#
Demo 3 – IIB_GUI
• Edit Button allows you to edit item attributes
1. Constructor:
2. FormLoad():
3. Add():
4. Cancel
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 120
C#
Demo 3 – IIB_GUI
• RoomAdd 1
1. CheckIfChoose(): checks if selected TreeView Node 2
is null then returns true or false. Return value is 3
inverted due to „!"
4
2. getSelectedObjectTreeView(): creates Array of
type Object and assigns SelectedNode.Tag to first
element in Array
3. if(): selected Node is not null and is of Type Floor
create new FormRoom and show Dialog. Method will
continue after closing FormRoom 2
4. if(): „speichern“ value is set to true in FormRoom,
Room object will be added to BindingList<Room> of
1
the Floor object
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 121
C#
Demo 3 – IIB_GUI
• anzeigenTreeView: updates TreeView with current
objects of building, floor and room
1. for(_gebaeude): iterates through each building in the
_gebaeude list
2. Nodes.Add: new tree node is created for each building
building object is stored in the Tag property of the node
3. for(Floor): iterates through each
floor in the current building
4. Nodes[i].Nodes.Add: new tree node is 1
created for each floor, and it becomes 2
a child node of the current building 3
node
4
5
5. for(Room): same process as for floor
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 122
C#
Demo 3 – IIB_GUI
• Item Edit
1. getSelectedObjectTreeView: retrieves the object 1
that is stored in the Tag property of the Node
2
2. if(Object is Data type): checks if the data type of
the retrieved object is either Room, Building or
Floor and opens the respective Form
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 123
C#
Demo 3 – IIB_GUI
• Display Cost Button: Displays the cost of the
lamps on the currently selected level
1. Calculation: returned currently selected object is
1
cast to calculation interface
2
2. CalculateCost(): method of the object type is
called depending on the object type multiple
iterations of the CalculateCost method are
executed
30.10.2024 | Engineering Informatics I (INF I) Tutorial 1-2 | Laura Valderrama Niño, M.Sc. | 124