private void ValidateWorkTimeDataRow(WorkTimeDataRow row, PropertyInfo[] propertiesInfo) { foreach (var property in propertiesInfo) { var valueObject = property.GetValue(row); if (IsConvertibleToNotNullOrEmptyObject(valueObject)) { ValidateField(row, property, valueObject); } else { AddError("Value is empty or consists only white-space characters.", row.RowNumber, property.Name); } } }
private void ValidateField(WorkTimeDataRow row, PropertyInfo property, object objectValue) { var propertyName = property.Name; switch (propertyName) { case "ProjectName": string projectName = Convert.ToString(objectValue); projectName = projectName.Trim(); if (acceptedProject.Contains(projectName) == false) { AddError(string.Format("ProjectName is not accepted.Just accept{0}", string.Join(",", acceptedProject)), row.RowNumber, "ProjectName"); } break; case "Hour": try { int hour = Convert.ToInt32(objectValue); if (hour > 8) { AddError("Hour cannot be greater than 8", row.RowNumber, "Hour"); } } catch { AddError("Hour is not a number", row.RowNumber, "Hour"); } break; //case "Time": // DateTime time; // string valueDate = Convert.ToString(objectValue); // if(!DateTime.TryParse(valueDate, out time)) // { // AddError("Invalid time", row.RowNumber, "Time"); // } // break; } }