protected string DisplayDaysOnJob(Northwind.EmployeesRow employee) { // Make sure HiredDate is not null... if so, return "Unknown" if (employee.IsHireDateNull()) { return("Unknown"); } else { // Returns the number of days between the current // date/time and hiredDate TimeSpan ts = DateTime.Now.Subtract(employee.HireDate); return(ts.Days.ToString("#,##0")); } }
protected void Employees_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { // Determine the Manager of the Employee record being bound to this DataListItem Northwind.EmployeesRow employee = (Northwind.EmployeesRow)((System.Data.DataRowView)e.Item.DataItem).Row; // Read in the information for the currently "logged on" user, if needed if (currentlyLoggedOnUser == null && Convert.ToInt32(LoggedOnAs.SelectedValue) > 0) { EmployeesBLL employeeAPI = new EmployeesBLL(); currentlyLoggedOnUser = employeeAPI.GetEmployeeByEmployeeID(Convert.ToInt32(LoggedOnAs.SelectedValue))[0]; } // See if this user has access to edit the employee bool canEditEmployee = false; if (currentlyLoggedOnUser != null) { // We've got an authenticated user... see if they have no manager... if (currentlyLoggedOnUser.IsReportsToNull()) canEditEmployee = true; else { // ok, this person has a manager... see if they are editing themselves if (currentlyLoggedOnUser.EmployeeID == employee.EmployeeID) canEditEmployee = true; // see if this person manages the employee else if (!employee.IsReportsToNull() && employee.ReportsTo == currentlyLoggedOnUser.EmployeeID) canEditEmployee = true; } } // Referrence the Edit button and set its Visible property accordingly Button editButton = (Button)e.Item.FindControl("EditButton"); editButton.Visible = canEditEmployee; } }