private void selectEmployeeComboBox_SelectedIndexChanged(object sender, EventArgs e) { EmployeeManager anEmployeeManager = new EmployeeManager(); Employee anEmployee = new Employee(); anEmployee.Email = anEmployeeManager.Get((int)selectEmployeeComboBox.SelectedValue).Email; anEmployee.Contact = anEmployeeManager.Get((int)selectEmployeeComboBox.SelectedValue).Contact; emailTextBox.Text = anEmployee.Email; contactTextBox.Text = anEmployee.Contact; employeeId = (int)selectEmployeeComboBox.SelectedValue; }
private void saveButton_Click(object sender, System.EventArgs e) { Employee anEmployee = new Employee(); anEmployee.Name = nameTextBox.Text; anEmployee.Email = emailTextBox.Text; anEmployee.Contact = contactTextBox.Text; anEmployee.JoiningDate = joiningDateDateTimePicker.Value; anEmployee.DepartmentId = (int) departmentComboBox.SelectedValue; EmployeeManager anEmployeeManager = new EmployeeManager(); string msg = anEmployeeManager.Save(anEmployee); MessageBox.Show(msg); }
public string Save(Employee anEmployee) { string query = "INSERT INTO t_employee(name, email, contact, department_id, joiningdate)" + " VALUES ('" + anEmployee.Name + "','" + anEmployee.Email + "','" + anEmployee.Contact + "'," + anEmployee.DepartmentId + ",'" + anEmployee.JoiningDate + "')"; SqlConnection sqlConnection = new SqlConnection(connectionString); sqlConnection.Open(); SqlCommand sqlCommand = new SqlCommand(query, sqlConnection); sqlCommand.ExecuteNonQuery(); sqlConnection.Close(); return "Employee saved"; }
public Employee Get(int employeeId) { string query = "SELECT * FROM t_employee WHERE id = '" + employeeId + "'"; SqlConnection sqlConnection = new SqlConnection(connectionString); sqlConnection.Open(); SqlCommand sqlCommand = new SqlCommand(query, sqlConnection); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); if (sqlDataReader.HasRows) { sqlDataReader.Read(); Employee aEmployee = new Employee(); aEmployee.Name = sqlDataReader[1].ToString(); aEmployee.Email = sqlDataReader[2].ToString(); aEmployee.Contact = sqlDataReader[3].ToString(); aEmployee.DepartmentId = Convert.ToInt32(sqlDataReader[4]); aEmployee.JoiningDate = Convert.ToDateTime(sqlDataReader[5]); sqlConnection.Close(); return aEmployee; } sqlConnection.Close(); return null; }
public string Save(Employee anEmployee) { return anEmployeeGateway.Save(anEmployee); }
public List<Employee> GetAllEmployees(int theDeaprtmentId) { string query = "SELECT * FROM t_employee WHERE department_id = '"+ theDeaprtmentId + "'"; SqlConnection sqlConnection = new SqlConnection(connectionString); sqlConnection.Open(); SqlCommand sqlCommand = new SqlCommand(query, sqlConnection); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); List<Employee> employees = new List<Employee>(); while (sqlDataReader.Read()) { Employee aEmployee = new Employee(); aEmployee.Id = Convert.ToInt32(sqlDataReader[0]); aEmployee.Name = sqlDataReader[1].ToString(); aEmployee.Email = sqlDataReader[2].ToString(); aEmployee.Contact = sqlDataReader[3].ToString(); aEmployee.DepartmentId = Convert.ToInt32(sqlDataReader[4]); aEmployee.JoiningDate = Convert.ToDateTime(sqlDataReader[5]); employees.Add(aEmployee); } sqlConnection.Close(); return employees; }