/// <summary> /// Changes department being displayed /// </summary> /// <param name="newDept">New department to display"</param> /// <returns>DataTable containing information on department's measurements, goals, and values</returns> public DataTable ChangeDepartment(string newDept) { foreach (var dept in repo.Departments) { if (dept.ViewModel.DepartmentName == newDept) { CurrentDept = dept; break; } } if (CurrentDept == null) { CurrentDept = new DDepartment(); CurrentDept.ViewModel.DepartmentName = "Department"; CurrentDept.ViewModel.DepartmentId = -1; CurrentDept.ViewModel.AdGroupId = null; } return GetData(); }
private DMeasurement stringToMeas(DDepartment dept, string measName) { foreach (var meas in dept.Measurements) { if (measName == meas.Model.NM || measName == meas.ViewModel.NameMeasurement) { return meas; } } return null; }
/// <summary> /// Calculates department's score weight based on all the weighted goals of all its measurements /// </summary> /// <param name="dept">Department to retrieve score weight</param> /// <param name="optionalStart">Inclusive start date to consider datapoints, if blank will be one year before end</param> /// <param name="optionalEnd">Inclusive end date to consider datapoints, if blank will be today</param> /// <returns>Number between 0 and 100, or null if no valid goals</returns> private Decimal? GetDeptScoreWeight(DDepartment dept, DateTime? optionalStart = null, DateTime? optionalEnd = null) { DateTime end = optionalEnd.GetValueOrDefault(DateTime.Today); DateTime start = optionalStart.GetValueOrDefault(end.AddYears(-1)); bool validWeight = false; decimal? sumWeights = 0; foreach (var meas in dept.Measurements) { var measScoreWeight = GetMeasScoreWeight(meas); if (measScoreWeight != null) { validWeight = true; sumWeights += measScoreWeight; } } if (!validWeight) return null; return sumWeights; }
/// <summary> /// Creates a new instance of the DMeasurement class /// </summary> /// <param name="parent">DDepartment hosting this DMeasurement</param> /// <param name="model">Model providng data for this DMeasurement</param> public DMeasurement(DDepartment parent, Measurement model) { this.Parent = parent; this.db = parent.db; this.Model = model; ViewModel = new BasicMeasurementData(); ViewModel.DeptId = model.Department_ID; ViewModel.HasGoal = model.Has_Goal_IN; ViewModel.MeasurementID = model.Measurement_ID; ViewModel.NameMeasurement = model.NM; }