Exemplo n.º 1
0
        private List <SqlDataRecord> BuildSqlRecordList(CurrencyModel DataModel)
        {
            string  CurrencyCode;
            decimal CurrencyRate;

            PropertyInfo[] PublicProps;
            Type           ModelType;
            SqlDataRecord  Record;

            SqlMetaData[]        Columns;
            SqlMetaData          C_Code, C_Rate;
            List <SqlDataRecord> CurrencyTable = new List <SqlDataRecord>();

            C_Code  = new SqlMetaData("Code", SqlDbType.NVarChar, 5);
            C_Rate  = new SqlMetaData("Rate", SqlDbType.Decimal, 18, 2);
            Columns = new SqlMetaData[] { C_Code, C_Rate };

            ModelType   = typeof(CurrencyRateModel);
            PublicProps = ModelType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            foreach (PropertyInfo Property in PublicProps)
            {
                CurrencyCode = Property.Name.ToString();
                CurrencyRate = Convert.ToDecimal(Property.GetValue(DataModel.quotes).ToString());
                Record       = new SqlDataRecord(Columns);
                Record.SetValue(Record.GetOrdinal("Code"), CurrencyCode.Substring(3));
                Record.SetValue(Record.GetOrdinal("Rate"), Math.Round(CurrencyRate, 2));
                CurrencyTable.Add(Record);
            }
            Record = new SqlDataRecord(Columns);
            Record.SetValue(Record.GetOrdinal("Code"), DataModel.source);
            Record.SetValue(Record.GetOrdinal("Rate"), 1.00M);
            CurrencyTable.Add(Record);
            return(CurrencyTable);
        }