Ejemplo n.º 1
0
        public IClientRecord GetRecord(string companyId, string record)
        {
          
            var result = new SourceRecord();
            var t = typeof(SourceRecord);
            var properties = t.GetProperties().Where(c => c.GetCustomAttribute(typeof(FixedLengthAttribute)) != null);
            //int start,end;
            foreach (var propertyInfo in properties)
            {
                var fixedLengthAtr = propertyInfo.GetCustomAttribute<FixedLengthAttribute>();

                var val = record.Substring(fixedLengthAtr.Start, fixedLengthAtr.Length).Trim();
                //var propertyName = propertyInfo.Name;

                //start = fixedLengthAtr.Start;
                //end = start + fixedLengthAtr.Length;


                if (propertyInfo.PropertyType == typeof(string))
                {
                    propertyInfo.SetValue(result, val);
                }
                else if (propertyInfo.PropertyType == typeof(decimal))
                {
                    decimal decimalValue;
                    var stringValue = Regex.Replace(val, @"(\d+)(\d{2}$)", "$1.$2");
                    if (decimal.TryParse(stringValue, out decimalValue))
                    {
                        propertyInfo.SetValue(result, decimalValue);
                    }
                }
                else if (propertyInfo.PropertyType == typeof(DateTime))
                {
                    DateTime dateValue;
                    if (DateTime.TryParse(val, out dateValue))
                    {
                        propertyInfo.SetValue(result, dateValue);
                    }

                }
                else if (propertyInfo.PropertyType == typeof(int))
                {
                    int intValue;
                    if (int.TryParse(val, out intValue))
                    {
                        propertyInfo.SetValue(result, intValue);
                    }

                }
                else if (propertyInfo.PropertyType == typeof(decimal?))
                {
                    decimal decimalValue;
                    if (decimal.TryParse(val, out decimalValue))
                    {
                        propertyInfo.SetValue(result, decimalValue);
                    }

                }
                
                //var value = dr.GetValue(propertyInfo);
                //if (value != DBNull.Value)
                //{
                //    propertyInfo.SetValue(result, value);
                //}


            }
            result.HoursWorkedPerWeek = 0;
            result.JwsCompanyId = companyId;


            return result;


            


        }
Ejemplo n.º 2
0
        public IClientRecord GetRecord(string companyId,IDataReader dr)
        {
            
            var result = new SourceRecord();
            var t = typeof(SourceRecord);
            var properties = t.GetProperties().Where(c => c.GetCustomAttribute(typeof(ColumnAttribute)) != null);
            foreach (var propertyInfo in properties)
            {
                var value = dr.GetValue(propertyInfo);

                if (value == DBNull.Value) continue;

                if (propertyInfo.PropertyType == typeof(int) && value is string)
                {
                    int convertedValue;
                    var isInt = int.TryParse(value.ToString(), out convertedValue);
                    if (isInt)
                    {
                        propertyInfo.SetValue(result, convertedValue);
                    }
                }
                else if (propertyInfo.PropertyType == typeof(decimal) && value is string)
                {
                    decimal convertedValue;
                    var isDecimal = decimal.TryParse(value.ToString(), out convertedValue);
                    if (isDecimal)
                    {
                        propertyInfo.SetValue(result, convertedValue);
                    }
                }
                else
                {
                    propertyInfo.SetValue(result, value);
                }
            }
            result.JwsCompanyId = companyId;
            
            return result;

        }