コード例 #1
0
ファイル: EngineImportTypeVm.cs プロジェクト: unicloud/FRP
        /// <summary>
        ///     获取发动机引进方式趋势图的数据源集合
        /// </summary>
        /// <returns></returns>
        private void CreateFleetImportTypeTrendCollection()
        {
            var importTypeCollection = new List<FleetImportTypeTrend>();
            var amountCollection = new List<FleetImportTypeTrend>();

            #region 发动机引进方式XML文件的读写

            var xmlConfig =
                XmlConfigs.FirstOrDefault(p => p.ConfigType.Equals("发动机引进方式", StringComparison.OrdinalIgnoreCase));

            var colorSetting =
                XmlSettings.FirstOrDefault(p => p.SettingType.Equals("颜色配置", StringComparison.OrdinalIgnoreCase));
            if (colorSetting != null &&
                XElement.Parse(colorSetting.SettingContent)
                    .Descendants("Type")
                    .Any(p => p.Attribute("TypeName").Value.Equals("运力变化", StringComparison.OrdinalIgnoreCase)))
            {
                var engineColor =
                    XElement.Parse(colorSetting.SettingContent)
                        .Descendants("Type")
                        .FirstOrDefault(
                            p => p.Attribute("TypeName").Value.Equals("运力变化", StringComparison.OrdinalIgnoreCase));

                if (engineColor != null)
                {
                    var firstOrDefault =
                        engineColor.Descendants("Item")
                            .FirstOrDefault(
                                p => p.Attribute("Name").Value.Equals("发动机数", StringComparison.OrdinalIgnoreCase));
                    if (firstOrDefault != null)
                        EngineColor = firstOrDefault.Attribute("Color").Value;
                }
                else
                {
                    EngineColor = Commonmethod.GetRandomColor();
                }
            }

            XElement importColor = null;
            if (colorSetting != null &&
                XElement.Parse(colorSetting.SettingContent)
                    .Descendants("Type")
                    .Any(p => p.Attribute("TypeName").Value.Equals("引进方式", StringComparison.OrdinalIgnoreCase)))
            {
                importColor =
                    XElement.Parse(colorSetting.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"))
                        {
                            if (type.Attribute("TypeName").Value.Equals("发动机引进方式", StringComparison.OrdinalIgnoreCase))
                            {
                                var currentAmount = type.Attribute("Amount").Value;
                                //发动机总数柱状集合
                                var engineAmount = new FleetImportTypeTrend
                                {
                                    DateTime = currentTime,
                                    Amount = Convert.ToInt32(currentAmount),
                                    Color = EngineColor
                                };
                                amountCollection.Add(engineAmount);

                                foreach (var item in type.Descendants("Item"))
                                {
                                    //发动机引进方式折线集合
                                    var fleetImportTypeTrend = new FleetImportTypeTrend
                                    {
                                        ImportType = item.Attribute("Name").Value,
                                        DateTime = currentTime,
                                        AirNum = Convert.ToInt32(item.Value),
                                        Amount = Convert.ToInt32(currentAmount)
                                    };
                                    if (importColor != null)
                                    {
                                        var firstOrDefault =
                                            importColor.Descendants("Item")
                                                .FirstOrDefault(
                                                    p =>
                                                        p.Attribute("Name")
                                                            .Value.Equals(fleetImportTypeTrend.ImportType,
                                                                StringComparison.OrdinalIgnoreCase));
                                        if (firstOrDefault !=
                                            null)
                                            fleetImportTypeTrend.Color = firstOrDefault.Attribute("Color").Value;
                                    }
                                    importTypeCollection.Add(fleetImportTypeTrend);
                                }
                            }
                        }
                    }
                }
            }

            #endregion

            SelectedTime = "所选时间";
            ZoomInitialize();
            if (importTypeCollection.Any() && amountCollection.Any())
            {
                FleetImportTypeTrendCollection = importTypeCollection;
                EngineAmountCollection = amountCollection;
            }
        }
コード例 #2
0
        /// <summary>
        /// 获取引进方式趋势图的数据源集合
        /// </summary>
        /// <returns></returns>
        private void CreateFleetImportTypeTrendCollection()
        {
            List<FleetImportTypeTrend> ImportTypeCollection = new List<FleetImportTypeTrend>();
            List<FleetImportTypeTrend> AmountCollection = new List<FleetImportTypeTrend>();

            #region 引进方式XML文件的读写
            var xmlconfig = this.ViewXmlConfig.FirstOrDefault(p => p.ConfigType == "引进方式");

            XElement aircraftcolor = null;
            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 == "运力变化");

                if (aircraftcolor != null)
                {
                    this.AircraftColor = aircraftcolor.Descendants("Item").FirstOrDefault(p => p.Attribute("Name").Value == "飞机数").Attribute("Color").Value;
                }
                else
                {
                    this.AircraftColor = commonmethod.GetRandomColor();
                }
            }

            XElement importcolor = null;
            if (colorconfig != null && colorconfig.XmlContent.Descendants("Type").Any(p => p.Attribute("TypeName").Value == "引进方式"))
            {
                importcolor = 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;
                            }
                        }

                        foreach (XElement type in datetime.Descendants("Type"))
                        {
                            if (type.Attribute("TypeName").Value == "引进方式")
                            {
                                string CurrentAmount = type.Attribute("Amount").Value;

                                //飞机总数柱状集合
                                FleetImportTypeTrend aircraftamount = new FleetImportTypeTrend();
                                aircraftamount.DateTime = CurrentTime;
                                aircraftamount.Amount = Convert.ToInt32(CurrentAmount);
                                aircraftamount.Color = this.AircraftColor;
                                AmountCollection.Add(aircraftamount);

                                foreach (XElement item in type.Descendants("Item"))
                                {
                                    //引进方式折线集合
                                    FleetImportTypeTrend fleetimporttypetrend = new FleetImportTypeTrend();
                                    fleetimporttypetrend.ImportType = item.Attribute("Name").Value;
                                    fleetimporttypetrend.DateTime = CurrentTime;
                                    fleetimporttypetrend.AirNum = Convert.ToInt32(item.Value);
                                    fleetimporttypetrend.Amount = Convert.ToInt32(CurrentAmount);
                                    if (importcolor != null)
                                    {
                                        fleetimporttypetrend.Color = importcolor.Descendants("Item")
                                            .FirstOrDefault(p => p.Attribute("Name").Value == fleetimporttypetrend.ImportType).Attribute("Color").Value;
                                    }
                                    ImportTypeCollection.Add(fleetimporttypetrend);
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            SelectedTime = "所选时间";
            FleetImportTypeCollection = null;
            AircraftCollection = null;
            this.Zoom = new Size(1, 1);

            if (ImportTypeCollection.Count() > 0 && AmountCollection.Count() > 0)
            {
                FleetImportTypeTrendCollection = ImportTypeCollection;
                AircraftAmountCollection = AmountCollection;
            }
        }