Example #1
0
        internal static List <string> getListComponents(EM_System sys, EM_IncomeList il, bool isShort)
        {
            List <string> comp = new List <string>();

            foreach (EM_ILComponent com in il.components)
            {
                if (sys.incomelists.ContainsKey(com.name))
                {
                    comp.AddRange(getListComponents(sys, sys.incomelists[com.name], isShort));
                }
                else
                {
                    comp.Add((com.addit ? "+" : "-") + " " + (isShort ? com.name.Replace("\n", "") : com.description.Replace("- ", ": ").Replace(" -", " :").Replace("\n", "")));
                }
            }
            return(comp);
        }
Example #2
0
        internal static List <EM_ILComponent> expandListComponents(EM_System sys, EM_IncomeList il, bool add)
        {
            List <EM_ILComponent> comp = new List <EM_ILComponent>();

            foreach (EM_ILComponent com in il.components)
            {
                if (sys.incomelists.ContainsKey(com.name))
                {
                    comp.AddRange(expandListComponents(sys, sys.incomelists[com.name], !(com.addit ^ add)));
                }
                else
                {
                    EM_ILComponent c = new EM_ILComponent()
                    {
                        description = com.description,
                        name        = com.name,
                        addit       = !(com.addit ^ add)
                    };
                    comp.Add(c);
                }
            }

            return(comp);
        }
Example #3
0
        private void readCountrySystemInfo(string euromod_path)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            Plugin.chkData   = new DataTable();
            Plugin.countries = new List <EM_Country>();

            string countries_path = Path.Combine(euromod_path, "XMLParam", "Countries");

            if (!Directory.Exists(countries_path))
            {
                return;
            }

            // First get all the country folders and the respective country XMLs
            string[]      countryFolderPaths = Directory.GetDirectories(countries_path);
            List <string> countryXMLPaths    = new List <string>();

            foreach (string cfp in countryFolderPaths)
            {
                string tmp_path = Path.Combine(cfp, Path.GetFileName(cfp)) + ".xml";
                if (File.Exists(tmp_path))
                {
                    countryXMLPaths.Add(tmp_path);
                    countryShortNames.Add(Path.GetFileName(cfp).ToUpper());
                }
            }

            List <string> years = new List <string>();

            // Then read the different years in each XML
            foreach (string xmlPath in countryXMLPaths)
            {
                EM_Country country             = new EM_Country();
                Dictionary <string, bool> dict = new Dictionary <string, bool>();

                using (XmlReader xmlReader = XmlReader.Create(xmlPath, new XmlReaderSettings()
                {
                    ConformanceLevel = ConformanceLevel.Fragment
                }))
                {
                    xmlReader.ReadToDescendant("Country");
                    using (XmlReader countryReader = xmlReader.ReadSubtree())
                    {
                        countryReader.ReadToDescendant("Name");
                        country.name = countryReader.ReadElementContentAsString();
                        countryReader.ReadToNextSibling("ShortName");
                        country.shortname = countryReader.ReadElementContentAsString().ToUpper();
                        while (countryReader.ReadToNextSibling("System"))
                        {
                            using (XmlReader systemReader = countryReader.ReadSubtree())
                            {
                                EM_System system = new EM_System();
                                systemReader.ReadToDescendant("Name");
                                system.name = systemReader.ReadElementContentAsString().ToUpper();
                                systemReader.ReadToNextSibling("Year");
                                system.year = systemReader.ReadElementContentAsString();
                                if (system.year != "" && !dict.ContainsKey(system.year))
                                {
                                    dict.Add(system.year, true);
                                    if (!years.Contains(system.year))
                                    {
                                        years.Add(system.year);
                                    }
                                    while (systemReader.ReadToNextSibling("Policy"))
                                    {
                                        using (XmlReader policyReader = systemReader.ReadSubtree())
                                        {
                                            policyReader.ReadToDescendant("Name");
                                            string policyName = policyReader.ReadElementContentAsString();
                                            policyReader.ReadToNextSibling("Switch");
                                            if (policyReader.ReadElementContentAsString().ToUpper() == "ON")
                                            {
                                                while (policyReader.ReadToNextSibling("Function"))
                                                {
                                                    using (XmlReader functionReader = policyReader.ReadSubtree())
                                                    {
                                                        functionReader.ReadToDescendant("Name");
                                                        if (functionReader.ReadElementContentAsString().ToUpper() == "DEFIL")
                                                        {
                                                            EM_IncomeList il = new EM_IncomeList()
                                                            {
                                                                policy = policyName
                                                            };
                                                            functionReader.ReadToNextSibling("Comment");
                                                            il.description = functionReader.ReadElementContentAsString();
                                                            functionReader.ReadToNextSibling("Switch");
                                                            if (functionReader.ReadElementContentAsString().ToUpper() == "ON")
                                                            {
                                                                while (functionReader.ReadToNextSibling("Parameter"))
                                                                {
                                                                    if (il.name == "ils_pen")
                                                                    {
                                                                        // il.name = "ils_pen";
                                                                    }
                                                                    using (XmlReader parameterReader = functionReader.ReadSubtree())
                                                                    {
                                                                        parameterReader.ReadToDescendant("Name");
                                                                        string parName = functionReader.ReadElementContentAsString();
                                                                        if (parName.ToUpper() == "NAME")
                                                                        {
                                                                            parameterReader.ReadToNextSibling("Value");
                                                                            il.name = functionReader.ReadElementContentAsString();
                                                                        }
                                                                        else
                                                                        {
                                                                            parameterReader.ReadToNextSibling("Comment");
                                                                            string comment = parameterReader.ReadElementContentAsString();
                                                                            parameterReader.ReadToNextSibling("Value");
                                                                            string addIt = parameterReader.ReadElementContentAsString();
                                                                            if (addIt == "+" || addIt == "-")
                                                                            {
                                                                                EM_ILComponent comp = new EM_ILComponent()
                                                                                {
                                                                                    name = parName, addit = addIt == "+", description = comment
                                                                                };
                                                                                il.components.Add(comp);
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                if (il.name == string.Empty)
                                                                {
                                                                    throw new Exception("incomelist without name!");
                                                                }
                                                                if (!system.incomelists.ContainsKey(il.name))
                                                                {
                                                                    system.incomelists.Add(il.name, il);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    country.systems.Add(system.year, system);
                                }
                            }
                        }
                        comboExists.Add(country.shortname, dict);
                    }
                }
                Plugin.countries.Add(country);
            }
            years.Sort();

            string msg = sw.ElapsedMilliseconds + "ms taken for xml parsing";

            sw.Restart();

            foreach (string x in years)
            {
                Plugin.chkData.Columns.Add(x, typeof(bool));
                columnsCheckBoxState.Add(false);
            }
            foreach (string x in countryShortNames)
            {
                object[] r = new object[years.Count];
                for (int i = 0; i < years.Count; i++)
                {
                    r[i] = false;
                }
                Plugin.chkData.Rows.Add(r);
                rowsCheckBoxState.Add(false);
            }
            gridSelector.DataSource = Plugin.chkData;

            gridView1.CustomDrawColumnHeader += gridView1_CustomDrawColumnHeader;
            gridView1.ColumnPanelRowHeight    = columnHeaderHeight;
            gridView1.RowHeight = 30;
            foreach (DevExpress.XtraGrid.Columns.GridColumn c in gridView1.Columns)
            {
                c.Width = rowHeaderWidth;
            }
            gridView1.CustomDrawRowIndicator += gridView1_CustomDrawRowIndicator;
            gridView1.IndicatorWidth          = rowHeaderWidth;
            sw.Stop();
            msg += Environment.NewLine + sw.ElapsedMilliseconds + "ms taken for grid";
            if (timing)
            {
                MessageBox.Show(msg);
            }
        }