1. My question) There is a button, a textbox and a datagridview on the form.
When the button is clicked, the id, name, surname and salary of the personnel belonging to the company written in the textbox1
It is requested to transfer the information to datagridview1.
Using object-oriented programming techniques the required class (with methods) and from that class
I need to encode the object to be created.
As my second question) I need to send a message on the screen of the total salary of all the personnel transferred to the datagirdview1 of the question I wrote above, I would be glad if you could help me. Thank you from now
Public Class frmPersonnel
Class Personnel
Private _id As Integer
Private _name As String
Private _surname As String
Private _salary As Double
Public Property ID() As Integer
Get
Return _id
End Get
Set(ByVal value As Integer)
_id = value
End Set
End Property
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property Surname() As String
Get
Return _surname
End Get
Set(ByVal value As String)
_surname = value
End Set
End Property
Public Property Salary() As Double
Get
Return _salary
End Get
Set(ByVal value As Double)
_salary = value
End Set
End Property
End Class
Private personnels As New List(Of Personnel)
'1,Mary,Clark,4565
'2,Peter,Smith,1000
''' <summary>
''' Add button
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim values() As String = txtInfo.Text.Split(",")
Dim newPersonnel As New Personnel()
newPersonnel.ID = Integer.Parse(values(0))
newPersonnel.Name = values(1)
newPersonnel.Surname = values(2)
newPersonnel.Salary = Double.Parse(values(3))
personnels.Add(newPersonnel)
dgvPersonnel.DataSource = Nothing
dgvPersonnel.DataSource = personnels
End Sub
''' <summary>
''' Display the total salary of all the personnel transferred to the datagirdview
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub btnDisplayTotalSalaryPersonnel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayTotalSalaryPersonnel.Click
Dim totalSalary As Double = 0
For i As Integer = 0 To personnels.Count - 1
totalSalary += personnels(i).Salary
Next
MessageBox.Show("The total salary of all the personnel: " + totalSalary.ToString())
End Sub
End Class
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmPersonnel
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.btnAdd = New System.Windows.Forms.Button()
Me.txtInfo = New System.Windows.Forms.TextBox()
Me.dgvPersonnel = New System.Windows.Forms.DataGridView()
Me.btnDisplayTotalSalaryPersonnel = New System.Windows.Forms.Button()
CType(Me.dgvPersonnel, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'btnAdd
'
Me.btnAdd.Location = New System.Drawing.Point(220, 38)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(223, 23)
Me.btnAdd.TabIndex = 0
Me.btnAdd.Text = "Add"
Me.btnAdd.UseVisualStyleBackColor = True
'
'txtInfo
'
Me.txtInfo.Location = New System.Drawing.Point(12, 12)
Me.txtInfo.Name = "txtInfo"
Me.txtInfo.Size = New System.Drawing.Size(431, 20)
Me.txtInfo.TabIndex = 1
'
'dgvPersonnel
'
Me.dgvPersonnel.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
Me.dgvPersonnel.Location = New System.Drawing.Point(12, 76)
Me.dgvPersonnel.Name = "dgvPersonnel"
Me.dgvPersonnel.Size = New System.Drawing.Size(431, 231)
Me.dgvPersonnel.TabIndex = 2
'
'btnDisplayTotalSalaryPersonnel
'
Me.btnDisplayTotalSalaryPersonnel.Location = New System.Drawing.Point(220, 313)
Me.btnDisplayTotalSalaryPersonnel.Name = "btnDisplayTotalSalaryPersonnel"
Me.btnDisplayTotalSalaryPersonnel.Size = New System.Drawing.Size(223, 23)
Me.btnDisplayTotalSalaryPersonnel.TabIndex = 0
Me.btnDisplayTotalSalaryPersonnel.Text = "Display the total salary of all the personnel"
Me.btnDisplayTotalSalaryPersonnel.UseVisualStyleBackColor = True
'
'frmPersonnel
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(470, 353)
Me.Controls.Add(Me.dgvPersonnel)
Me.Controls.Add(Me.txtInfo)
Me.Controls.Add(Me.btnDisplayTotalSalaryPersonnel)
Me.Controls.Add(Me.btnAdd)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "frmPersonnel"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Personnel"
CType(Me.dgvPersonnel, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents btnAdd As System.Windows.Forms.Button
Friend WithEvents txtInfo As System.Windows.Forms.TextBox
Friend WithEvents dgvPersonnel As System.Windows.Forms.DataGridView
Friend WithEvents btnDisplayTotalSalaryPersonnel As System.Windows.Forms.Button
End Class
Comments
Leave a comment