码迷,mamicode.com
首页 > 其他好文 > 详细

类 映射 遍历大全

时间:2014-11-07 18:24:42      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:io   ar   os   sp   for   on   art   cti   bs   

                foreach (T_GL_AnalysisCalculation item in AnalysisCalculationList)
                {
                    foreach (System.Reflection.PropertyInfo p in item.GetType().GetProperties())
                    {
                        var Key = p.Name;
                        var Value = p.GetValue(item, null);


                        #region 行业最优
                        if (Key == "Reporttype" && Value.ToString() == "Max")
                        {
                            foreach (System.Reflection.PropertyInfo pYear in item.GetType().GetProperties())
                            {
                                var KeyYear = pYear.Name;
                                var ValueYear = pYear.GetValue(item, null);
                                if (KeyYear == "Year" && ValueYear.ToString() == "1")
                                {
                                    foreach (System.Reflection.PropertyInfo pYearValue in item.GetType().GetProperties())
                                    {
                                        var KeyYearName = pYearValue.Name;
                                        var KeyYearValue = pYearValue.GetValue(item, null);
                                        if (KeyYearName.Length > 5 && KeyYearName.Substring(Key.Length - 5).Replace("_", ".") == code.ToString())
                                        {
                                            entiey.ValueMax1 = Convert.ToDecimal(KeyYearValue);
                                        }
                                    }
                                }
                                if (KeyYear == "Year" && ValueYear.ToString() == "3")
                                {
                                    foreach (System.Reflection.PropertyInfo pYearValue in item.GetType().GetProperties())
                                    {
                                        var KeyYearName = pYearValue.Name;
                                        var KeyYearValue = pYearValue.GetValue(item, null);
                                        if (KeyYearName.Length > 5 && KeyYearName.Substring(Key.Length - 5).Replace("_", ".") == code.ToString())
                                        {
                                            entiey.ValueMax3 = Convert.ToDecimal(KeyYearValue);
                                        }
                                    }
                                }
                                if (KeyYear == "Year" && ValueYear.ToString() == "5")
                                {
                                    foreach (System.Reflection.PropertyInfo pYearValue in item.GetType().GetProperties())
                                    {
                                        var KeyYearName = pYearValue.Name;
                                        var KeyYearValue = pYearValue.GetValue(item, null);
                                        if (KeyYearName.Length > 5 && KeyYearName.Substring(Key.Length - 5).Replace("_", ".") == code.ToString())
                                        {
                                            entiey.ValueMax5 = Convert.ToDecimal(KeyYearValue);
                                        }
                                    }
                                }
                                if (KeyYear == "Year" && ValueYear.ToString() == "10")
                                {
                                    foreach (System.Reflection.PropertyInfo pYearValue in item.GetType().GetProperties())
                                    {
                                        var KeyYearName = pYearValue.Name;
                                        var KeyYearValue = pYearValue.GetValue(item, null);
                                        if (KeyYearName.Length > 5 && KeyYearName.Substring(Key.Length - 5).Replace("_", ".") == code.ToString())
                                        {
                                            entiey.ValueMax10 = Convert.ToDecimal(KeyYearValue);
                                        }
                                    }
                                }
                            }
                        }

                        #endregion

                        #region 行业平均
                        if (Key == "Reporttype" && Value.ToString() == "Average")
                        {
                            foreach (System.Reflection.PropertyInfo pYear in item.GetType().GetProperties())
                            {
                                var KeyYear = pYear.Name;
                                var ValueYear = pYear.GetValue(item, null);
                                if (KeyYear == "Year" && ValueYear.ToString() == "1")
                                {
                                    foreach (System.Reflection.PropertyInfo pYearValue in item.GetType().GetProperties())
                                    {
                                        var KeyYearName = pYearValue.Name;
                                        var KeyYearValue = pYearValue.GetValue(item, null);
                                        if (KeyYearName.Length > 5 && KeyYearName.Substring(Key.Length - 5).Replace("_", ".") == code.ToString())
                                        {
                                            entiey.ValueAverage1 = Convert.ToDecimal(KeyYearValue);
                                        }
                                    }
                                }
                                if (KeyYear == "Year" && ValueYear.ToString() == "3")
                                {
                                    foreach (System.Reflection.PropertyInfo pYearValue in item.GetType().GetProperties())
                                    {
                                        var KeyYearName = pYearValue.Name;
                                        var KeyYearValue = pYearValue.GetValue(item, null);
                                        if (KeyYearName.Length > 5 && KeyYearName.Substring(Key.Length - 5).Replace("_", ".") == code.ToString())
                                        {
                                            entiey.ValueAverage3 = Convert.ToDecimal(KeyYearValue);
                                        }
                                    }
                                }
                                if (KeyYear == "Year" && ValueYear.ToString() == "5")
                                {
                                    foreach (System.Reflection.PropertyInfo pYearValue in item.GetType().GetProperties())
                                    {
                                        var KeyYearName = pYearValue.Name;
                                        var KeyYearValue = pYearValue.GetValue(item, null);
                                        if (KeyYearName.Length > 5 && KeyYearName.Substring(Key.Length - 5).Replace("_", ".") == code.ToString())
                                        {
                                            entiey.ValueAverage5 = Convert.ToDecimal(KeyYearValue);
                                        }
                                    }
                                }
                                if (KeyYear == "Year" && ValueYear.ToString() == "10")
                                {
                                    foreach (System.Reflection.PropertyInfo pYearValue in item.GetType().GetProperties())
                                    {
                                        var KeyYearName = pYearValue.Name;
                                        var KeyYearValue = pYearValue.GetValue(item, null);
                                        if (KeyYearName.Length > 5 && KeyYearName.Substring(Key.Length - 5).Replace("_", ".") == code.ToString())
                                        {
                                            entiey.ValueAverage10 = Convert.ToDecimal(KeyYearValue);
                                        }
                                    }
                                }
                            }
                        }


                        #endregion

                        #region 行业最差
                        if (Key == "Reporttype" && Value.ToString() == "Min")
                        {
                            foreach (System.Reflection.PropertyInfo pYear in item.GetType().GetProperties())
                            {
                                var KeyYear = pYear.Name;
                                var ValueYear = pYear.GetValue(item, null);
                                if (KeyYear == "Year" && ValueYear.ToString() == "1")
                                {
                                    foreach (System.Reflection.PropertyInfo pYearValue in item.GetType().GetProperties())
                                    {
                                        var KeyYearName = pYearValue.Name;
                                        var KeyYearValue = pYearValue.GetValue(item, null);
                                        if (KeyYearName.Length > 5 && KeyYearName.Substring(Key.Length - 5).Replace("_", ".") == code.ToString())
                                        {
                                            entiey.ValueMin1 = Convert.ToDecimal(KeyYearValue);
                                        }
                                    }
                                }
                                if (KeyYear == "Year" && ValueYear.ToString() == "3")
                                {
                                    foreach (System.Reflection.PropertyInfo pYearValue in item.GetType().GetProperties())
                                    {
                                        var KeyYearName = pYearValue.Name;
                                        var KeyYearValue = pYearValue.GetValue(item, null);
                                        if (KeyYearName.Length > 5 && KeyYearName.Substring(Key.Length - 5).Replace("_", ".") == code.ToString())
                                        {
                                            entiey.ValueMin3 = Convert.ToDecimal(KeyYearValue);
                                        }
                                    }
                                }
                                if (KeyYear == "Year" && ValueYear.ToString() == "5")
                                {
                                    foreach (System.Reflection.PropertyInfo pYearValue in item.GetType().GetProperties())
                                    {
                                        var KeyYearName = pYearValue.Name;
                                        var KeyYearValue = pYearValue.GetValue(item, null);
                                        if (KeyYearName.Length > 5 && KeyYearName.Substring(Key.Length - 5).Replace("_", ".") == code.ToString())
                                        {
                                            entiey.ValueMin5 = Convert.ToDecimal(KeyYearValue);
                                        }
                                    }
                                }
                                if (KeyYear == "Year" && ValueYear.ToString() == "10")
                                {
                                    foreach (System.Reflection.PropertyInfo pYearValue in item.GetType().GetProperties())
                                    {
                                        var KeyYearName = pYearValue.Name;
                                        var KeyYearValue = pYearValue.GetValue(item, null);
                                        if (KeyYearName.Length > 5 && KeyYearName.Substring(Key.Length - 5).Replace("_", ".") == code.ToString())
                                        {
                                            entiey.ValueMin10 = Convert.ToDecimal(KeyYearValue);
                                        }
                                    }
                                }
                            }
                        }


                        #endregion

                    }
                }

 

 

 


                foreach (System.Reflection.PropertyInfo p in entiey.GetType().GetProperties())
                {
                    var Key = p.Name;
                    var Value = p.GetValue(entiey, null);
                    if (Key.Substring(0, 1) == "Q")
                    {


                        foreach (var item in AnalysisCalculationQAllList)
                        {
                            if (item.Reporttype == quarter + Key.Substring(1, Key.Length - 1))
                            {
                                foreach (System.Reflection.PropertyInfo I in item.GetType().GetProperties())
                                {
                                    var itemKey = I.Name;
                                    var itemValue = I.GetValue(item, null);
                                    if (code.ToString() == itemKey.Replace("_", "."))
                                    {
                                        p.SetValue(entiey, itemValue, null);
                                    }
                                }
                            }
                        }
                    }
                }

类 映射 遍历大全

标签:io   ar   os   sp   for   on   art   cti   bs   

原文地址:http://www.cnblogs.com/520cc/p/4081642.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!