public List<Employee> GetAllEmloyee() { SqlConnection connection=new SqlConnection(connectionString); string query = "SELECT * FROM tbl_EmployeeInfo "; SqlCommand command=new SqlCommand(query,connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); List<Employee>employeeList=new List<Employee>(); while (reader.Read()) { Employee employee=new Employee(); employee.Id = int.Parse(reader["Id"].ToString()); employee.Name = reader["Name"].ToString(); employee.Email = reader["Email"].ToString(); employee.Address = reader["Address"].ToString(); employee.ADesignation.Id =int.Parse(reader["DesignationId"].ToString()); employeeList.Add(employee); } reader.Close(); connection.Close(); return employeeList; }
public void FillListBox(Employee employee) { nameTextBox.Text = employee.Name; emailTextBox.Text = employee.Email; addressTextBox.Text = employee.Address; designationComboBox.SelectedValue = employee.ADesignation.Id; }
public string Update(Employee employee) { if (employee.Name == String.Empty) { return "Please enter the employee name."; } else if (employee.Email == string.Empty) { return "Please enter the Email name."; } else if (employee.Address == string.Empty) { return "Please enter the Address name."; } else { if (gateway.Update(employee) > 0) { return "Updated Succesfully."; } else { return "Update Failed."; } } }
public string Save(Employee employee) { if (employee.Name==String.Empty) { return "Please enter the employee name."; } else if(employee.Email==string.Empty) { return "Please enter the Email name."; } else if (gateway.IsEmailExist(employee.Email)) { return "Sorry! Your email name already exist."; } else if (employee.Address == string.Empty) { return "Please enter the Address name."; } else { if (gateway.Save(employee)>0) { return "Insert successfully."; } else { return "Saved Failed!"; } } }
public int Save(Employee employee) { SqlConnection connection = new SqlConnection(connectionString); string query = "INSERT INTO tbl_EmployeeInfo Values('"+employee.Name+"','"+employee.Email+"','"+employee.Address+"','"+employee.ADesignation.Id+"')"; SqlCommand command=new SqlCommand(query,connection); int rowsEffected=command.ExecuteNonQuery(); return rowsEffected; }
private void saveEmployeeButton_Click(object sender, EventArgs e) { Employee employee=new Employee(); employee.Name = nameTextBox.Text; employee.Email = emailTextBox.Text; employee.Address = addressTextBox.Text; employee.ADesignation = (Designation) designationComboBox.SelectedItem; if (saveEmployeeButton.Text != @"Update") { MessageBox.Show(employeeManager.Save(employee)); } else { MessageBox.Show(employeeManager.Update(employee)); } }
public List<Employee> SearchByName(string name) { List<Employee> employees = new List<Employee>(); SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT Name,Email FROM tbl_EmployeeInfo WHERE Name LIKE '"+name+"%' ORDER BY Name"; SqlCommand command = new SqlCommand(query,connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Employee anEmployee=new Employee(); anEmployee.Name = reader["Name"].ToString(); anEmployee.Email = reader["Email"].ToString(); employees.Add(anEmployee); } reader.Close(); connection.Close(); return employees; }
public int Update(Employee employee) { SqlConnection connection = new SqlConnection(connectionString); string query = "UPDATE tbl_EmployeeInfo SET Name='"+employee.Name+"',Email='"+employee.Email+"',Address='"+employee.Address+"',DesignationId='"+employee.ADesignation.Id+"'WHERE Email='"+employee.Email+"'"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); int rowsEffected = command.ExecuteNonQuery(); connection.Close(); return rowsEffected; }
public void GetSelectedEmployee(Employee employee) { saveEmployeeButton.Text = @"Update"; FillListBox(employee); employeeId=employee.Id; }