public void AddToDB(TextBox firstNa, TextBox lastNa, TextBox telnumber, TextBox email, TextBox street, TextBox city, TextBox county, TextBox postcode, ComboBox typeDept, ComboBox typeRole) { try { // Query to find matching staffid and password in DB var verQuery = from a in db.employees where a.FirstName == firstNa.Text && a.LastName == lastNa.Text select a; if (verQuery.Any()) { MessageBox.Show("Employee Already Exists In DB"); } else { // Create a new employee object employee addedEmployee = new employee { FirstName = firstNa.Text, LastName = lastNa.Text, Password = firstNa.Text, Telephone = telnumber.Text, EmailAddress = email.Text, Address = (street.Text + "-" + city.Text + "-" + county.Text + "-" + postcode.Text), DateJoined = DateTime.Today.Date, StaffID = IDcreation() }; Console.WriteLine(" today date is " + DateTime.Today.Date); // Create a new Department object department addedDept = new department { DeptName = typeDept.Text }; // Create a new role object and add the employee and department role addedRole = new role { RoleType = typeRole.Text, employee = addedEmployee, department = addedDept }; //Save changes to Database db.roles.InsertOnSubmit(addedRole); db.SubmitChanges(); MessageBox.Show("Employee Added To DB"); } } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } }
public void AddToDB(string firstNa, string lastNa, string telnumber, string email, string street, string city, string county, string postcode, string typeDept, string typeRole) { try { // Query to find matching staffid and password in DB var verQuery = from a in db.employees where a.FirstName == firstNa && a.LastName == lastNa select a; if (verQuery.Any()) { MessageBox.Show("Employee Already Exists In DB"); } else { // Create a new employee object employee addedEmployee = new employee { FirstName = firstNa, LastName = lastNa, Password = firstNa, Telephone = telnumber, EmailAddress = email, Address = (street + "-" + city + "-" + county + "-" + postcode), DateJoined = DateTime.Today.Date, StaffID = IDcreation() }; // Create a new Department object department addedDept = new department { DeptName = typeDept }; // Create a new role object and add the employee and department role addedRole = new role { RoleType = typeRole, employee = addedEmployee, department = addedDept }; //Save changes to Database db.roles.InsertOnSubmit(addedRole); db.SubmitChanges(); MessageBox.Show("Employee Details Added To Database."); } } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } }
partial void Deletedepartment(department instance);
partial void Updatedepartment(department instance);
partial void Insertdepartment(department instance);