Employee Management System
Home Page
{
AddEmployee AddEmployee = new AddEmployee();
AddEmployee.ShowDialog();
}
private void button2_Click(object sender, EventArgs e)
{
ViewEmployee ViewEmployee = new ViewEmployee();
ViewEmployee.ShowDialog();
}
private void button3_Click(object sender, EventArgs e)
{
Salary Salary = new Salary();
Salary.ShowDialog();
}
Add Employee Page
private void PopulateGrid()
{
string Query = "SELECT * FROM EmployeeDet";
SqlConnection Conn = new SqlConnection(StrConn);
Conn.Open();
SqlDataAdapter Adapter = new SqlDataAdapter(Query,Conn);
SqlCommandBuilder Builder = new SqlCommandBuilder(Adapter);
DataSet ds = new DataSet();
Adapter.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
Conn.Close();
}
private void BtnClear_Click(object sender, EventArgs e)
{
TxtEmployeeID.Text = "";
TxtName.Text = "";
TxtAddress.Text = "";
CmbGender.Text = "Male";
CmbQualification.Text = "";
TxtEmail.Text = "B.Sc.";
TxtPhone.Text = "";
}
private void BtnAdd_Click(object sender, EventArgs e)
{
String Query = "INSERT INTO EmployeeDet " +
"(EmpID,EmpName,Address,Gender,Qualification,Email,Phone) Values" +
" ('" + TxtEmployeeID.Text + "','" + TxtName.Text + "','" + TxtAddress.Text +
"','" + CmbGender.Text + "','" + CmbQualification.Text + "','" + TxtEmail.Text +
"','" + TxtPhone.Text + "')";
SqlConnection Conn = new SqlConnection(StrConn);
Conn.Open();
SqlCommand Cmd = new SqlCommand(Query,Conn);
Cmd.ExecuteNonQuery();
Conn.Close();
PopulateGrid();
MessageBox.Show("Add Sucess");
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
TxtEmployeeID.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
TxtName.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
TxtAddress.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
CmbGender.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
CmbQualification.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
TxtEmail.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
TxtPhone.Text = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString();
}
private void BtnUpdate_Click(object sender, EventArgs e)
{
String Query = "UPDATE EmployeeDet SET EmpName='" + TxtName.Text + "',Address='" +
TxtAddress.Text + "',Gender='" + CmbGender.Text + "',Qualification='" + CmbQualification.Text +
"',Email='" + TxtEmail.Text + "',Phone='" + TxtPhone.Text + "'" +
" WHERE EmpId='" + TxtEmployeeID.Text + "'";
SqlConnection Conn = new SqlConnection(StrConn);
Conn.Open();
SqlCommand Cmd = new SqlCommand(Query, Conn);
Cmd.ExecuteNonQuery();
Conn.Close();
PopulateGrid();
MessageBox.Show("Update Sucess");
}
private void BtnDelete_Click(object sender, EventArgs e)
{
String Query = "DELETE FROM EmployeeDet WHERE EmpID='" + TxtEmployeeID.Text + "'";
SqlConnection Conn = new SqlConnection(StrConn);
Conn.Open();
SqlCommand Cmd = new SqlCommand(Query, Conn);
Cmd.ExecuteNonQuery();
Conn.Close();
PopulateGrid();
MessageBox.Show("Deleted Sucess");
}
View Employee Page
private void BtnView_Click(object sender, EventArgs e)
{
string Query = "SELECT * FROM EmployeeDet WHERE EmpId='" + TxtEmployeeID.Text + "'";
SqlConnection Conn = new SqlConnection(StrConn);
Conn.Open();
SqlCommand Cmd = new SqlCommand(Query, Conn);
SqlDataReader dr = Cmd.ExecuteReader();
while (dr.Read())
{
TxtName.Text = dr["EmpName"].ToString();
TxtAddress.Text = dr["Address"].ToString();
CmbGender.Text = dr["Gender"].ToString();
CmbQualification.Text = dr["Qualification"].ToString();
TxtEmail.Text = dr["Email"].ToString();
TxtPhone.Text = dr["Phone"].ToString();
}
}
private void BtnPrint_Click(object sender, EventArgs e)
{
if (printPreviewDialog1.ShowDialog()==DialogResult.OK)
{
printDocument1.Print();
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString("Employee Details", new Font("Times New Roman",
25, FontStyle.Bold), Brushes.Red, new Point(100, 200));
e.Graphics.DrawString("Employee Name : " + TxtName.Text, new Font("Times New Roman",
25, FontStyle.Bold), Brushes.Blue, new Point(10, 250));
e.Graphics.DrawString("Address : " + TxtAddress.Text, new Font("Times New Roman",
25, FontStyle.Bold), Brushes.Blue, new Point(10, 300));
e.Graphics.DrawString("Gender : " + CmbGender.Text, new Font("Times New Roman",
25, FontStyle.Bold), Brushes.Blue, new Point(10, 350));
e.Graphics.DrawString("Qualification : " + CmbQualification.Text, new Font("Times New Roman",
25, FontStyle.Bold), Brushes.Blue, new Point(10, 400));
e.Graphics.DrawString("Email : " + TxtEmail.Text, new Font("Times New Roman",
25, FontStyle.Bold), Brushes.Blue, new Point(10, 450));
e.Graphics.DrawString("Phone : " + TxtPhone.Text, new Font("Times New Roman",
25, FontStyle.Bold), Brushes.Blue, new Point(10, 500));
}
Salary
private void BtnView_Click(object sender, EventArgs e)
{
string Query = "SELECT * FROM EmployeeDet WHERE EmpId='" + TxtEmployeeID.Text + "'";
SqlConnection Conn = new SqlConnection(StrConn);
Conn.Open();
SqlCommand Cmd = new SqlCommand(Query, Conn);
SqlDataReader dr = Cmd.ExecuteReader();
while (dr.Read())
{
TxtName.Text = dr["EmpName"].ToString();
TxtAddress.Text = dr["Address"].ToString();
if (CmbDesignation.Text=="Manager")
{
TxtSalary.Text = Convert.ToString(1500 * Convert.ToInt32(TxtWorkingDays.Text));
}
else
if (CmbDesignation.Text == "Team Leader")
{
TxtSalary.Text = Convert.ToString(1250 * Convert.ToInt32(TxtWorkingDays.Text));
}
else
if (CmbDesignation.Text == "Developer")
{
TxtSalary.Text = Convert.ToString(1000 * Convert.ToInt32(TxtWorkingDays.Text));
}
else
if(CmbDesignation.Text == "Trainee")
{
TxtSalary.Text = Convert.ToString(800 * Convert.ToInt32(TxtWorkingDays.Text));
}
}
}
private void BtnPrint_Click(object sender, EventArgs e)
{
if (printPreviewDialog1.ShowDialog() == DialogResult.OK)
{
printDocument1.Print();
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString("Salary Slip", new Font("Times New Roman",
25, FontStyle.Bold), Brushes.Red, new Point(100, 200));
e.Graphics.DrawString("Employee Name : " + TxtName.Text, new Font("Times New Roman",
25, FontStyle.Bold), Brushes.Blue, new Point(10, 250));
e.Graphics.DrawString("Address : " + TxtAddress.Text, new Font("Times New Roman",
25, FontStyle.Bold), Brushes.Blue, new Point(10, 300));
e.Graphics.DrawString("Designation : " + CmbDesignation.Text, new Font("Times New Roman",
25, FontStyle.Bold), Brushes.Blue, new Point(10, 350));
e.Graphics.DrawString("Working Days : " + TxtWorkingDays.Text, new Font("Times New Roman",
25, FontStyle.Bold), Brushes.Blue, new Point(10, 400));
e.Graphics.DrawString("Salary : " + TxtSalary.Text, new Font("Times New Roman",
35, FontStyle.Bold), Brushes.Blue, new Point(10, 450));
}

Comments
Post a Comment