コード例 #1
0
        private AddConsultationDTO ParseConsultation(IRow row, Type type, Dictionary <string, int> propertyIndex)
        {
            StringBuilder      errMsg       = new StringBuilder();
            var                constructor  = type.GetConstructor(new Type[] { });
            AddConsultationDTO consultation = (AddConsultationDTO)constructor.Invoke(new object[] { });

            foreach (var entry in propertyIndex)
            {
                string content = null;
                var    cell    = row.GetCell(entry.Value);
                if (cell != null)
                {
                    if (cell.CellType == CellType.String)
                    {
                        content = cell.StringCellValue;
                    }
                    else if (cell.CellType == CellType.Numeric)
                    {
                        content = cell.NumericCellValue.ToString();
                    }
                }

                if (content == null || content.IsNullOrWhiteSpace())
                {
                    continue;
                }

                var property = type.GetProperty(entry.Key);
                if (property.PropertyType.FullName.Contains("System.Int32"))
                {
                    int value = 0;
                    if (Int32.TryParse(content, out value))
                    {
                        property.SetValue(consultation, value);
                    }
                }
                else if (property.PropertyType.FullName.Contains("System.Double"))
                {
                    double value = 0;
                    if (Double.TryParse(content, out value))
                    {
                        property.SetValue(consultation, value);
                    }
                }
                else
                {
                    property.SetValue(consultation, content.Trim());
                }
            }
            return(consultation);
        }
コード例 #2
0
 public static Consultation TypeConverter(AddConsultationDTO addDTO)
 {
     if (addDTO is AddApplicationConsultationDTO)
     {
         AddApplicationConsultationDTO dto = (AddApplicationConsultationDTO)addDTO;
         return(new ApplicationConsultation()
         {
             ConsultationId = Guid.NewGuid().ToString(),
             ApplicationId = dto.ApplicationId,
             Period = dto.Period,
             Budget = dto.TotalBudget,
             CurrentYearBudget = dto.CurrentBudget,
             DelegateType = (DelegateType)Enum.Parse(typeof(DelegateType), dto.DelegateType),
             Result = (ApplicationConsultationResult)Enum.Parse(typeof(ApplicationConsultationResult), dto.Result, true)
         });
     }
     else if (addDTO is AddProjectConsultationDTO)
     {
         AddProjectConsultationDTO dto = (AddProjectConsultationDTO)addDTO;
         return(new ProjectConsultation()
         {
             ConsultationId = Guid.NewGuid().ToString(),
             ProjectId = dto.ProjectId,
             Period = dto.Period,
             Budget = dto.TotalBudget,
             CurrentYearBudget = dto.CurrentBudget,
             DelegateType = (DelegateType)Enum.Parse(typeof(DelegateType), dto.DelegateType),
             Result = (ProjectConsultationResult)Enum.Parse(typeof(ProjectConsultationResult), dto.Result, true),
             ArrivalBudget = 0
         });
     }
     else
     {
         throw new Exception("参数类型错误");
     }
 }