Skip to content

Commit

Permalink
Auto increment of employee id feature added.
Browse files Browse the repository at this point in the history
  • Loading branch information
kiranshahi committed Oct 3, 2023
1 parent adaf379 commit 7184edc
Show file tree
Hide file tree
Showing 7 changed files with 410 additions and 369 deletions.
24 changes: 12 additions & 12 deletions EmployeeManagementSystem.Data/Employee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ public Employee()
{
}

public Employee(string id, string fullName, string address, string contact, string email, string designation, string department, string dateOfJoin,
public Employee(int id, string fullName, string address, string contact, string email, string designation, string department, string dateOfJoin,
string wageRate, string workedHour)
{
this.EmployeeID = id;
this.FullName = fullName;
this.Address = address;
this.Contact = contact;
this.Email = email;
this.Designation = designation;
this.Department = department;
this.DateOfJoin = string.IsNullOrEmpty(dateOfJoin) ? DateTime.Now.ToShortDateString() : dateOfJoin;
this.WageRate = wageRate;
this.WorkedHour = workedHour;
EmployeeID = id;
FullName = fullName;
Address = address;
Contact = contact;
Email = email;
Designation = designation;
Department = department;
DateOfJoin = string.IsNullOrEmpty(dateOfJoin) ? DateTime.Now.ToShortDateString() : dateOfJoin;
WageRate = wageRate;
WorkedHour = workedHour;
}

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public string EmployeeID { get; set; }
public int EmployeeID { get; set; }
public string FullName { get; set; }
public string Address { get; set; }
public string Contact { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion EmployeeManagementSystem.Data/EmployeeManagementContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public EmployeeManagementContext()

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=kirans;Database=EmployeeManagement;Trusted_Connection=True;TrustServerCertificate=True;");
optionsBuilder.UseSqlServer(@"Server=localhost;Database=EmployeeManagement;Trusted_Connection=True;TrustServerCertificate=True;");
}
}
}
645 changes: 334 additions & 311 deletions EmployeeManagementSystem/AddEmployee.Designer.cs

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions EmployeeManagementSystem/AddEmployee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public partial class AddEmployee : Form
//Delegate has been added
public delegate void IdentityHandler(object sender, IdentityEventArgs e);


//Event of the delegate type has been added. i.e. Object of delegate created
public event IdentityHandler IdentityUpdated;

public AddEmployee()
public AddEmployee(int nextEmployeID)
{
InitializeComponent();
comboBoxDepartment.Items.Add("Administrative");
Expand All @@ -35,6 +35,10 @@ public AddEmployee()
comboBoxDepartment.Items.Add("Marketing");
comboBoxDepartment.Items.Add("IT");
comboBoxDepartment.SelectedIndex = 0;
if (nextEmployeID != 0)
{
txtIdNo.Text = nextEmployeID.ToString();
}
}

//This method will set the values on controls received from the selected row.
Expand Down Expand Up @@ -82,7 +86,7 @@ private void LblClose_Click(object sender, EventArgs e)

private async void BtnSave_Click(object sender, EventArgs e)
{
var id = txtIdNo.Text;
var id = int.TryParse(txtIdNo.Text, out int EmployeeNo);
var name = txtFullName.Text;
var address = txtAddress.Text;
var contactNo = txtContact.Text;
Expand All @@ -95,13 +99,13 @@ private async void BtnSave_Click(object sender, EventArgs e)

using (var context = new EmployeeManagementContext())
{
var emp = new Employee(id, name, address, contactNo, email, desigination, department, dateOfJoin, wageRate, hourWorked);
var emp = new Employee(EmployeeNo, name, address, contactNo, email, desigination, department, dateOfJoin, wageRate, hourWorked);
context.Employees.Add(emp);
await context.SaveChangesAsync();
}

//instance event args and value has been passed
var args = new IdentityEventArgs(id, name, address, contactNo, email, desigination, department, dateOfJoin, wageRate, hourWorked);
var args = new IdentityEventArgs(EmployeeNo, name, address, contactNo, email, desigination, department, dateOfJoin, wageRate, hourWorked);

//Event has be raised with update arguments of delegate
IdentityUpdated?.Invoke(this, args);
Expand Down
50 changes: 25 additions & 25 deletions EmployeeManagementSystem/AddEmployee.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down
20 changes: 17 additions & 3 deletions EmployeeManagementSystem/EmployeeDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void OnMouseUp(object sender, MouseEventArgs e)

private void AddEmployee_Click(object sender, EventArgs e)
{
var addEmp = new AddEmployee();
var addEmp = new AddEmployee(GetHighestEmployeeID() + 1);
addEmp.IdentityUpdated += SaveRecord;
addEmp.ShowDialog();
}
Expand Down Expand Up @@ -118,7 +118,7 @@ private void BtnEdit_Click(object sender, EventArgs e)
var hourWorked = Convert.ToString(dataGridView.Rows[row].Cells[9].Value);


var addEmp = new AddEmployee();
var addEmp = new AddEmployee(0);
addEmp.LoadData(id, name, address, contact, email, desigination, department, dateOfJoin, wageRate, hourWorked);
addEmp.IdentityUpdated += UpdateRecord;
addEmp.ShowDialog();
Expand Down Expand Up @@ -262,7 +262,8 @@ public async void ImportEmployeeFromCsv()
{
using var context = new EmployeeManagementContext();
dataGridView.Rows.Add(value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8], value[9]);
var emp = new Employee(value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8], value[9]);
bool isParsable = int.TryParse(value[0], out int employeeNo);
var emp = new Employee(isParsable ? employeeNo : 0, value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8], value[9]);
context.Employees.Add(emp);
try
{
Expand Down Expand Up @@ -310,5 +311,18 @@ public void GetEmployees()
}
}
}
public int GetHighestEmployeeID()
{
int highestEmployeeID = 0;
foreach (DataGridViewRow item in dataGridView.Rows)
{
bool isParsable = int.TryParse(Convert.ToString(item.Cells[0].Value), out int employeeID);
if (isParsable)
{
highestEmployeeID = employeeID > highestEmployeeID ? employeeID : highestEmployeeID;
}
}
return highestEmployeeID;
}
}
}
24 changes: 12 additions & 12 deletions EmployeeManagementSystem/IdentityEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ namespace EmployeeManagementSystem
*******/
public class IdentityEventArgs : EventArgs
{
public IdentityEventArgs(string id, string fullName, string address, string contact, string email,
public IdentityEventArgs(int id, string fullName, string address, string contact, string email,
string designation, string department,string dateOfJoin, string wageRate, string workedHour)
{
this.Id = id;
this.FullName = fullName;
this.Address = address;
this.Contact = contact;
this.Email = email;
this.Designation = designation;
this.Department = department;
this.DateOfJoin = dateOfJoin;
this.WageRate = wageRate;
this.WorkedHour = workedHour;
Id = id;
FullName = fullName;
Address = address;
Contact = contact;
Email = email;
Designation = designation;
Department = department;
DateOfJoin = dateOfJoin;
WageRate = wageRate;
WorkedHour = workedHour;
}

public string Id { get; }
public int Id { get; }
public string FullName { get; }
public string Address { get; }
public string Contact { get; }
Expand Down

0 comments on commit 7184edc

Please sign in to comment.