/// <summary> /// Method enables adding employee to the database. /// </summary> public void AddEmployee(object sender, DoWorkEventArgs e) { try { using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString())) { var cmd = new SqlCommand(@"insert into tblEmployee values (@FirstName, @LastName, @JMBG, @DateOfBirth, @Gender, @RegNum, @PhoneNumber, @LocId, @SectorID, @ManagerID);", conn); cmd.Parameters.AddWithValue("@FirstName", Employee.FirstName); cmd.Parameters.AddWithValue("@LastName", Employee.LastName); cmd.Parameters.AddWithValue("@JMBG", Employee.JMBG); cmd.Parameters.AddWithValue("@DateOfBirth", Employee.DateOfBirth); cmd.Parameters.AddWithValue("@Gender", Employee.Gender); cmd.Parameters.AddWithValue("@RegNum", Employee.RegistrationNumber); cmd.Parameters.AddWithValue("@PhoneNumber", Employee.PhoneNumber); cmd.Parameters.AddWithValue("@LocId", Employee.Location.Id); cmd.Parameters.AddWithValue("@SectorID", Employee.Sector.Id); cmd.Parameters.AddWithValue("@ManagerID", 1); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); } MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Employee successfully created.", "Notification"); LogActions.LogAddEmployee(Employee); } catch (Exception) { } }
/// <summary> /// Method enables adding employee to the database. /// </summary> public void AddEmployee() { Thread.Sleep(2000); using (var conn = new SqlConnection(ConnectionString)) { var cmd = new SqlCommand(@"insert into tblEmployee values (@Name, @Surname, @JMBG, @DateOfBirth, @Gender, @RegNum, @PhoneNumber, @LocId, @SectorID, @ManagerID);", conn); cmd.Parameters.AddWithValue("@Name", Employee.FirstName); cmd.Parameters.AddWithValue("@Surname", Employee.LastName); cmd.Parameters.AddWithValue("@JMBG", Employee.JMBG); cmd.Parameters.AddWithValue("@DateOfBirth", Employee.DateOfBirth); cmd.Parameters.AddWithValue("@Gender", Employee.Gender); cmd.Parameters.AddWithValue("@RegNum", Employee.RegistrationNumber); cmd.Parameters.AddWithValue("@PhoneNumber", Employee.PhoneNumber); cmd.Parameters.AddWithValue("@LocId", Employee.Location.Id); cmd.Parameters.AddWithValue("@SectorID", Employee.Sector.Id); cmd.Parameters.AddWithValue("@ManagerID", Employee.Manager.Id); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); } MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Employee successfully created.", "Notification"); LogActions.LogAddEmployee(Employee); }