private void SetPatientMeasurementProperty(PatientMeasurement measurement, PulmonaryFunctionTestResovler resolver, string propertyName, string propertyValue, IRow row, int cellCursor) { Type type = measurement.GetType(); PropertyInfo propertyInfo = type.GetProperty(propertyName); DateTime dateRowValue; try { if (propertyInfo != null && propertyInfo.PropertyType == typeof(DateTime)) { dateRowValue = row.GetCell(cellCursor).DateCellValue; propertyInfo.SetValue(measurement, dateRowValue); } else if (propertyInfo.PropertyType == typeof(int?) || propertyInfo.PropertyType == typeof(int)) { int propertyIntValue = Int32.Parse(propertyValue); propertyInfo.SetValue(measurement, propertyIntValue); } else if (propertyInfo.PropertyType == typeof(DateTime) || propertyInfo.PropertyType == typeof(DateTime?)) { propertyInfo. SetValue(measurement, Convert.ChangeType(propertyValue, typeof(DateTime)), null); } else if (propertyInfo.PropertyType == typeof(Decimal) || propertyInfo.PropertyType == typeof(Decimal?)) { decimal propertyDecValue = (decimal)Convert.ChangeType(propertyValue, typeof(Decimal)); var propertyDecMultValue = propertyDecValue * 100; if (propertyName == "Height") { resolver.Height = propertyDecValue; } propertyInfo.SetValue(measurement, propertyDecMultValue, null); } else { propertyInfo. SetValue(measurement, Convert.ChangeType(propertyValue, propertyInfo.PropertyType), null); } } catch (InvalidOperationException ex) { propertyInfo.SetValue(measurement, null); } }
private void ReadCell(Patient patient, IRow row, int cellIndex, PatientMeasurement newWeightHeight) { string header = _headers.ElementAt(cellIndex); string propertyValue = row.GetCell(cellIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString(); string newObjectFields = (string)_dictonary[header]; if (newObjectFields != null) { string[] fields = newObjectFields.Split("|"); foreach (string field in fields) { var klassAndField = field.Split("."); var propertyName = klassAndField[1]; switch (klassAndField[0]) { case "PatientMeasurement": try { Type type = newWeightHeight.GetType(); PropertyInfo propertyInfo = type.GetProperty(propertyName); if (propertyName == "DateTaken") { DateTime qDate = DateTime.ParseExact(propertyValue, "dd-MMM-yyyy", CultureInfo.InvariantCulture); propertyInfo.SetValue(newWeightHeight, qDate); } else if (propertyName == "Height") { newWeightHeight.Height = Convert.ToDecimal(propertyValue); } else if (propertyName == "Weight") { newWeightHeight.Weight = Convert.ToDecimal(propertyValue); } } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(propertyValue); Console.WriteLine(klassAndField[1]); } break; } } } }