예제 #1
0
        /// <summary>
        /// 获取平均机龄趋势图的数据源集合
        /// </summary>
        /// <returns></returns>
        private void CreateFleetAgeTrendCollection()
        {
            List<FleetAgeTrend> collection = new List<FleetAgeTrend>();

            #region 平均机龄XML文件的读写
            var xmlconfig = this.ViewXmlConfig.FirstOrDefault(p => p.ConfigType == "机龄分析");

            string aircraftcolor = string.Empty;
            XmlConfig colorconfig = this.ViewXmlConfig.FirstOrDefault(p => p.ConfigType == "颜色配置");
            if (colorconfig != null && colorconfig.XmlContent.Descendants("Type").Any(p => p.Attribute("TypeName").Value == "运力变化"))
            {
                aircraftcolor = colorconfig.XmlContent.Descendants("Type").FirstOrDefault(p => p.Attribute("TypeName").Value == "运力变化")
                    .Descendants("Item").FirstOrDefault(p => p.Attribute("Name").Value == "飞机数").Attribute("Color").Value;
            }

            XElement regionalcolor = null;
            if (colorconfig != null && colorconfig.XmlContent.Descendants("Type").Any(p => p.Attribute("TypeName").Value == "座级"))
            {
                regionalcolor = colorconfig.XmlContent.Descendants("Type").FirstOrDefault(p => p.Attribute("TypeName").Value == "座级");
            }
            XElement typecolor = null;
            if (colorconfig != null && colorconfig.XmlContent.Descendants("Type").Any(p => p.Attribute("TypeName").Value == "机型"))
            {
                typecolor = colorconfig.XmlContent.Descendants("Type").FirstOrDefault(p => p.Attribute("TypeName").Value == "机型");
            }
            XElement airlinescolor = null;
            if (colorconfig != null && colorconfig.XmlContent.Descendants("Type").Any(p => p.Attribute("TypeName").Value == "航空公司"))
            {
                airlinescolor = colorconfig.XmlContent.Descendants("Type").FirstOrDefault(p => p.Attribute("TypeName").Value == "航空公司");
            }

            if (xmlconfig != null)
            {
                XElement xelement = xmlconfig.XmlContent;
                if (xelement != null)
                {
                    foreach (XElement datetime in xelement.Descendants("DateTime"))
                    {
                        string CurrentTime = Convert.ToDateTime(datetime.Attribute("EndOfMonth").Value).ToString("yyyy/M");

                        //早于开始时间时执行下一个
                        if (Convert.ToDateTime(CurrentTime) < StartDate)
                        {
                            continue;
                        }
                        //晚于结束时间时跳出循环
                        if (Convert.ToDateTime(CurrentTime) > EndDate)
                        {
                            break;
                        }

                        if (SelectedIndex == 1)//按半年统计
                        {
                            if (Convert.ToDateTime(CurrentTime).Month != 6 && Convert.ToDateTime(CurrentTime).Month != 12)
                            {
                                continue;
                            }
                        }
                        else if (SelectedIndex == 2)//按年份统计
                        {
                            if (Convert.ToDateTime(CurrentTime).Month != 12)
                            {
                                continue;
                            }
                        }
                        if (AgeSelectedIndex == 0)
                        {
                            XElement RegionalNode = datetime.Descendants("Type").FirstOrDefault(p => p.Attribute("TypeName").Value == "座级");
                            if (RegionalNode != null)
                            {
                                FleetAgeTrend alltrend = new FleetAgeTrend();//折线图的总数对象
                                alltrend.AircraftType = "所有飞机";
                                alltrend.AverageAge = Math.Round(Convert.ToDouble(RegionalNode.Attribute("Amount").Value), 4);
                                alltrend.DateTime = CurrentTime;
                                if (!string.IsNullOrEmpty(aircraftcolor))
                                {
                                    alltrend.Color = aircraftcolor;
                                }
                                //添加进相应的数据源集合
                                collection.Add(alltrend);

                                foreach (XElement item in RegionalNode.Descendants("Item"))
                                {
                                    FleetAgeTrend fleetagetrend = new FleetAgeTrend();//折线图的总数对象
                                    fleetagetrend.AircraftType = item.Attribute("Name").Value;
                                    fleetagetrend.AverageAge = Math.Round(Convert.ToDouble(item.Value), 4);
                                    fleetagetrend.DateTime = CurrentTime;
                                    if (regionalcolor != null)
                                    {
                                        fleetagetrend.Color = regionalcolor.Descendants("Item")
                                            .FirstOrDefault(p => p.Attribute("Name").Value == fleetagetrend.AircraftType).Attribute("Color").Value;
                                    }
                                    //添加进相应的数据源集合
                                    collection.Add(fleetagetrend);
                                }
                            }
                        }
                        else if (AgeSelectedIndex == 1)
                        {
                            XElement TypeNode = datetime.Descendants("Type").FirstOrDefault(p => p.Attribute("TypeName").Value == "机型");
                            if (TypeNode != null)
                            {
                                FleetAgeTrend alltrend = new FleetAgeTrend();//折线图的总数对象
                                alltrend.AircraftType = "所有飞机";
                                alltrend.AverageAge = Math.Round(Convert.ToDouble(TypeNode.Attribute("Amount").Value), 4);
                                alltrend.DateTime = CurrentTime;
                                if (!string.IsNullOrEmpty(aircraftcolor))
                                {
                                    alltrend.Color = aircraftcolor;
                                }
                                //添加进相应的数据源集合
                                collection.Add(alltrend);

                                foreach (XElement item in TypeNode.Descendants("Item"))
                                {
                                    FleetAgeTrend fleetagetrend = new FleetAgeTrend();//折线图的总数对象
                                    fleetagetrend.AircraftType = item.Attribute("Name").Value;
                                    fleetagetrend.AverageAge = Math.Round(Convert.ToDouble(item.Value), 4);
                                    fleetagetrend.DateTime = CurrentTime;
                                    if (typecolor != null)
                                    {
                                        fleetagetrend.Color = typecolor.Descendants("Item")
                                            .FirstOrDefault(p => p.Attribute("Name").Value == fleetagetrend.AircraftType).Attribute("Color").Value;
                                    }
                                    //添加进相应的数据源集合
                                    collection.Add(fleetagetrend);
                                }
                            }
                        }
                        else if (AgeSelectedIndex == 2)
                        {
                            XElement AirlinesNode = datetime.Descendants("Type").FirstOrDefault(p => p.Attribute("TypeName").Value == "航空公司");
                            if (AirlinesNode != null)
                            {
                                FleetAgeTrend alltrend = new FleetAgeTrend();//折线图的总数对象
                                alltrend.AircraftType = "所有飞机";
                                alltrend.AverageAge = Math.Round(Convert.ToDouble(AirlinesNode.Attribute("Amount").Value), 4);
                                alltrend.DateTime = CurrentTime;
                                if (!string.IsNullOrEmpty(aircraftcolor))
                                {
                                    alltrend.Color = aircraftcolor;
                                }
                                //添加进相应的数据源集合
                                collection.Add(alltrend);

                                foreach (XElement item in AirlinesNode.Descendants("Item"))
                                {
                                    FleetAgeTrend fleetagetrend = new FleetAgeTrend();//折线图的总数对象
                                    fleetagetrend.AircraftType = item.Attribute("Name").Value;
                                    fleetagetrend.AverageAge = Math.Round(Convert.ToDouble(item.Value), 4);
                                    fleetagetrend.DateTime = CurrentTime;
                                    if (airlinescolor != null)
                                    {
                                        fleetagetrend.Color = airlinescolor.Descendants("Item")
                                            .FirstOrDefault(p => p.Attribute("Name").Value == fleetagetrend.AircraftType).Attribute("Color").Value;
                                    }
                                    //添加进相应的数据源集合
                                    collection.Add(fleetagetrend);
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            SelectedType = string.Empty;
            SelectedTime = "所选时间";
            //对界面数据集合进行重新初始化
            FleetAgeCollection = null;
            AircraftByAgeDic = new Dictionary<string, List<Aircraft>>();
            AircraftCollection = null;

            FleetAgeTrendCollection = collection;
        }
예제 #2
0
파일: FleetAgeVm.cs 프로젝트: unicloud/FRP
        /// <summary>
        ///     获取平均机龄趋势图的数据源集合
        /// </summary>
        /// <returns></returns>
        private void CreateFleetAgeTrendCollection()
        {
            var collection = new List<FleetAgeTrend>();

            #region 平均机龄XML文件的读写

            var xmlConfig =
                XmlConfigs.FirstOrDefault(p => p.ConfigType.Equals("机龄分析", StringComparison.OrdinalIgnoreCase));
            var aircraftColor = string.Empty;
            var colorConfig =
                XmlSettings.FirstOrDefault(p => p.SettingType.Equals("颜色配置", StringComparison.OrdinalIgnoreCase));
            if (colorConfig != null &&
                XElement.Parse(colorConfig.SettingContent)
                    .Descendants("Type")
                    .Any(p => p.Attribute("TypeName").Value.Equals("运力变化", StringComparison.OrdinalIgnoreCase)))
            {
                var firstOrDefault =
                    XElement.Parse(colorConfig.SettingContent)
                        .Descendants("Type")
                        .FirstOrDefault(
                            p => p.Attribute("TypeName").Value.Equals("运力变化", StringComparison.OrdinalIgnoreCase));
                if (firstOrDefault != null)
                {
                    var orDefault =
                        firstOrDefault.Descendants("Item")
                            .FirstOrDefault(
                                p => p.Attribute("Name").Value.Equals("飞机数", StringComparison.OrdinalIgnoreCase));
                    if (orDefault != null)
                        aircraftColor = orDefault.Attribute("Color").Value;
                }
            }

            XElement typeColor = null;
            if (colorConfig != null &&
                XElement.Parse(colorConfig.SettingContent)
                    .Descendants("Type")
                    .Any(p => p.Attribute("TypeName").Value.Equals("机型", StringComparison.OrdinalIgnoreCase)))
            {
                typeColor =
                    XElement.Parse(colorConfig.SettingContent)
                        .Descendants("Type")
                        .FirstOrDefault(
                            p => p.Attribute("TypeName").Value.Equals("机型", StringComparison.OrdinalIgnoreCase));
            }

            if (xmlConfig != null)
            {
                var xelement = XElement.Parse(xmlConfig.ConfigContent);
                if (xelement != null)
                {
                    foreach (var datetime in xelement.Descendants("DateTime"))
                    {
                        var currentTime =
                            Convert.ToDateTime(datetime.Attribute("EndOfMonth").Value).ToString("yyyy/M");

                        //早于开始时间时执行下一个
                        if (Convert.ToDateTime(currentTime) < StartDate)
                        {
                            continue;
                        }
                        //晚于结束时间时跳出循环
                        if (Convert.ToDateTime(currentTime) > EndDate)
                        {
                            break;
                        }

                        if (SelectedIndex == 1) //按半年统计
                        {
                            if (Convert.ToDateTime(currentTime).Month != 6 &&
                                Convert.ToDateTime(currentTime).Month != 12)
                            {
                                continue;
                            }
                        }
                        else if (SelectedIndex == 2) //按年份统计
                        {
                            if (Convert.ToDateTime(currentTime).Month != 12)
                            {
                                continue;
                            }
                        }

                        foreach (var type in datetime.Descendants("Type"))
                        {
                            var fleetageTrend = new FleetAgeTrend
                            {
                                AircraftType = type.Attribute("TypeName").Value,
                                AverageAge = Math.Round(Convert.ToDouble(type.Attribute("Amount").Value), 4),
                                DateTime = currentTime
                            }; //折线图的总数对象
                            if (fleetageTrend.AircraftType.Equals("所有机型", StringComparison.OrdinalIgnoreCase))
                            {
                                if (!string.IsNullOrEmpty(aircraftColor))
                                {
                                    fleetageTrend.Color = aircraftColor;
                                }
                            }
                            else
                            {
                                if (typeColor != null)
                                {
                                    var firstOrDefault = typeColor.Descendants("Item").FirstOrDefault(
                                        p =>
                                            p.Attribute("Name")
                                                .Value.Equals(fleetageTrend.AircraftType,
                                                    StringComparison.OrdinalIgnoreCase));
                                    if (firstOrDefault != null)
                                        fleetageTrend.Color = firstOrDefault.Attribute("Color").Value;
                                }
                            }
                            //添加进相应的数据源集合
                            collection.Add(fleetageTrend);
                        }
                    }
                }
            }

            #endregion

            _selectedType = string.Empty;
            SelectedTime = "所选时间";
            //对界面数据集合进行重新初始化
            FleetAgeCollection = null;
            aircraftByAgeDic = new Dictionary<string, List<AircraftDTO>>();
            AircraftCollection = null;
            FleetAgeTrendCollection = collection;
        }