@@ -22,11 +22,11 @@ public partial class AddEmployee : Form
22
22
//Delegate has been added
23
23
public delegate void IdentityHandler ( object sender , IdentityEventArgs e ) ;
24
24
25
-
25
+
26
26
//Event of the delegate type has been added. i.e. Object of delegate created
27
27
public event IdentityHandler IdentityUpdated ;
28
28
29
- public AddEmployee ( )
29
+ public AddEmployee ( int nextEmployeID )
30
30
{
31
31
InitializeComponent ( ) ;
32
32
comboBoxDepartment . Items . Add ( "Administrative" ) ;
@@ -35,6 +35,10 @@ public AddEmployee()
35
35
comboBoxDepartment . Items . Add ( "Marketing" ) ;
36
36
comboBoxDepartment . Items . Add ( "IT" ) ;
37
37
comboBoxDepartment . SelectedIndex = 0 ;
38
+ if ( nextEmployeID != 0 )
39
+ {
40
+ txtIdNo . Text = nextEmployeID . ToString ( ) ;
41
+ }
38
42
}
39
43
40
44
//This method will set the values on controls received from the selected row.
@@ -82,7 +86,7 @@ private void LblClose_Click(object sender, EventArgs e)
82
86
83
87
private async void BtnSave_Click ( object sender , EventArgs e )
84
88
{
85
- var id = txtIdNo . Text ;
89
+ var id = int . TryParse ( txtIdNo . Text , out int EmployeeNo ) ;
86
90
var name = txtFullName . Text ;
87
91
var address = txtAddress . Text ;
88
92
var contactNo = txtContact . Text ;
@@ -95,13 +99,13 @@ private async void BtnSave_Click(object sender, EventArgs e)
95
99
96
100
using ( var context = new EmployeeManagementContext ( ) )
97
101
{
98
- var emp = new Employee ( id , name , address , contactNo , email , desigination , department , dateOfJoin , wageRate , hourWorked ) ;
102
+ var emp = new Employee ( EmployeeNo , name , address , contactNo , email , desigination , department , dateOfJoin , wageRate , hourWorked ) ;
99
103
context . Employees . Add ( emp ) ;
100
104
await context . SaveChangesAsync ( ) ;
101
105
}
102
106
103
107
//instance event args and value has been passed
104
- var args = new IdentityEventArgs ( id , name , address , contactNo , email , desigination , department , dateOfJoin , wageRate , hourWorked ) ;
108
+ var args = new IdentityEventArgs ( EmployeeNo , name , address , contactNo , email , desigination , department , dateOfJoin , wageRate , hourWorked ) ;
105
109
106
110
//Event has be raised with update arguments of delegate
107
111
IdentityUpdated ? . Invoke ( this , args ) ;
0 commit comments