Esempio n. 1
0
        string HasActiveFunction(string country, string functionName)
        {
            CountryConfigFacade ccf = CountryAdministrator.GetCountryConfigFacade(country);
            string faulty           = string.Empty;

            foreach (CountryConfig.SystemRow system in GetPublicSystems(country))
            {
                foreach (CountryConfig.PolicyRow pol in system.GetPolicyRows())
                {
                    if (pol.Private != DefPar.Value.YES &&
                        pol.Switch == DefPar.Value.ON)
                    {
                        foreach (CountryConfig.FunctionRow fun in pol.GetFunctionRows())
                        {
                            if (fun.Name == functionName &&
                                fun.Private != DefPar.Value.YES &&
                                fun.Switch == DefPar.Value.ON)
                            {
                                faulty += system.Name + ", "; break;
                            }
                        }
                    }
                }
            }
            return(faulty);
        }
Esempio n. 2
0
        static void GetCountryInfo_BackgroundEventHandler(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

            if (backgroundWorker.CancellationPending)
            {
                e.Result = null; e.Cancel = true; return;
            }   //user pressed Cancel button: stop the process and allow progress indicator to set dialog result to Cancel

            try // this is just to read the country- and data-XML-files, not to do anything with them or store the ConfigFacades
            {   // the CountryAdministrator will keept them in memory and thus quick-access by the RVTable-derived classes is possible
                List <string> countries       = e.Argument as List <string>;
                List <int>    faultyCountries = new List <int>();
                for (int i = 0; i < countries.Count; ++i)
                {
                    if (CountryAdministrator.GetCountryConfigFacade(countries[i]) == null ||
                        CountryAdministrator.GetDataConfigFacade(countries[i]) == null)
                    {
                        faultyCountries.Add(i);
                    }
                    backgroundWorker.ReportProgress(Convert.ToInt32((i + 1.0) / (countries.Count * 1.0) * 100.0));
                }
                for (int f = faultyCountries.Count - 1; f >= 0; --f)
                {
                    countries.RemoveAt(f);
                }
                e.Result = countries;
            }
            catch (Exception exception) { e.Result = exception.Message; backgroundWorker.ReportProgress(100); }
        }
        private void lstCountries_SelectedIndexChanged(object sender = null, EventArgs e = null)
        {
            if (radShowYears.Checked)
            {
                return;
            }

            Cursor = Cursors.WaitCursor;
            try
            {
                lstSystems.Items.Clear();
                foreach (string c in lstCountries.SelectedItems)
                {
                    if (!ccSystems.ContainsKey(c))
                    {
                        ccSystems.Add(c, (from s in CountryAdministrator.GetCountryConfigFacade(c).GetSystemRowsOrdered() select s.Name).ToList());
                    }
                    foreach (string s in ccSystems[c])
                    {
                        lstSystems.Items.Add(s);
                    }
                }
            }
            catch (Exception exception) { UserInfoHandler.ShowError(exception.Message); }
            Cursor = Cursors.Default;
        }
        private static void SetPrivate_BackgroundEventHandler(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker; if (backgroundWorker.CancellationPending)
            {
                e.Cancel = true; return;
            }
            Tuple <string, bool> settings = e.Argument as Tuple <string, bool>; string extName = settings.Item1; bool set = settings.Item2;

            try
            {
                List <Country> countries = CountryAdministrator.GetCountries();
                for (int i = 0; i < countries.Count; ++i)
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        e.Cancel = true; return;
                    }
                    Country country = countries[i]; CountryConfigFacade ccf = country.GetCountryConfigFacade();
                    ExtensionSetPrivateAction action = new ExtensionSetPrivateAction(extName, countries[i]._shortName, set);
                    action.PerformAction();
                    if (!action.ActionIsCanceled()) // happens if extension has no content
                    {
                        country.WriteXML(); country.SetCountryConfigFacade(null); country.SetDataConfigFacade(null);
                    }
                    backgroundWorker.ReportProgress(Convert.ToInt32((i + 1.0) / (countries.Count * 1.0) * 100.0));
                }
                if (backgroundWorker.CancellationPending)
                {
                    e.Cancel = true; return;
                }
            }
            catch (Exception exception) { UserInfoHandler.ShowException(exception); e.Cancel = true; }
        }
Esempio n. 5
0
        internal static List <AddOnSystemInfo> GetAddOnSystemInfo(string addOnShortName)
        {
            List <AddOnSystemInfo> addOnSystemInfoList = new List <AddOnSystemInfo>();

            CountryConfigFacade countryConfigFacade = CountryAdministrator.GetCountryConfigFacade(addOnShortName);

            foreach (CountryConfig.SystemRow addOnSystemRow in countryConfigFacade.GetSystemRows())
            {
                AddOnSystemInfo addOnSystemInfo = new AddOnSystemInfo(addOnShortName, addOnSystemRow.Name);

                //assess supported/excluded systems from func_AddOn_Applic
                List <CountryConfig.FunctionRow> functionAddOnApplic = countryConfigFacade.GetFunctionRowsBySystemIDAndFunctionName(addOnSystemRow.ID, DefFun.AddOn_Applic);
                if (functionAddOnApplic.Count <= 0)
                {
                    continue; //no AddOn_Applic found - system is in fact not available
                }
                foreach (CountryConfig.ParameterRow parameterRow in functionAddOnApplic.First().GetParameterRows())
                {
                    if (parameterRow.Name.ToLower().StartsWith(DefPar.AddOn_Applic.Sys.ToLower()))
                    {
                        addOnSystemInfo._supportedSystems.Add(parameterRow.Value.ToLower());
                    }
                    if (parameterRow.Name.ToLower().StartsWith(DefPar.AddOn_Applic.SysNA.ToLower()))
                    {
                        addOnSystemInfo._notSupportedSystems.Add(parameterRow.Value.ToLower());
                    }
                }

                addOnSystemInfoList.Add(addOnSystemInfo);
            }

            return(addOnSystemInfoList);
        }
Esempio n. 6
0
        void btnOK_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(txtProjectPath.Text))
            {
                UserInfoHandler.ShowInfo("Please indicate a valid 'Project Path' for storing the new project."); return;
            }

            if (txtProjectName.Text == string.Empty)
            {
                UserInfoHandler.ShowInfo("Please indicate a 'Project Name'."); return;
            }

            if (chkProjectOnDisk.Checked && !CountryAdministrator.ContainsEuromodFileStructure(txtBasePath.Text))
            {
                UserInfoHandler.ShowInfo($"Please indicate a folder containting the {DefGeneral.BRAND_TITLE} file structure as 'Project on Disk' (or check 'No Base Project')."); return;
            }

            if (chkProjectOnVC.Checked && cmbBaseProjects.SelectedIndex < 0)
            {
                UserInfoHandler.ShowInfo("Please select a Base Project from the list 'Project on VC' (or check 'No Base Project')."); return;
            }

            if (chkProjectOnVC.Checked && cmbSelectVersion.SelectedIndex < 0)
            {
                UserInfoHandler.ShowError("Please select a Version. If no version is available, this project cannot be selected as Base Project."); return;
            }

            DialogResult = DialogResult.OK;
            Close();
        }
        internal override void PerformAction()
        {
            CountryConfig countryConfig = CountryAdministrator.GetCountryConfigFacade(cc).GetCountryConfig();

            ExtensionAndGroupMenuManager.GetSelectionPolFunPar(cc, out selectedPolRows, out selectedFunRows, out List <CountryConfig.ParameterRow> parRows);
            string extensionID = (from e in ExtensionAndGroupManager.GetExtensions(cc) where e.Name == extensionName select e.ID).FirstOrDefault(); if (extensionID == null)
            {
                return;
            }

            List <CountryConfig.Extension_PolicyRow>    delPolicyRows    = new List <CountryConfig.Extension_PolicyRow>();
            List <CountryConfig.Extension_FunctionRow>  delFunctionRows  = new List <CountryConfig.Extension_FunctionRow>();
            List <CountryConfig.Extension_ParameterRow> delParameterRows = new List <CountryConfig.Extension_ParameterRow>();

            foreach (CountryConfig.PolicyRow policyRow in selectedPolRows)
            {
                selectedFunRows.AddRange(policyRow.GetFunctionRows()); // to make sure that all functions of the policy are removed as well - note: the AddContent-function
                // does not remove a single function if its parent-policy is added (later)
                foreach (CountryConfig.Extension_PolicyRow del in from pe in countryConfig.Extension_Policy where pe.ExtensionID == extensionID& pe.PolicyID == policyRow.ID select pe)
                {
                    if (!delPolicyRows.Contains(del))
                    {
                        delPolicyRows.Add(del);                               // theoretically (but stupidly) this can be 2 (off and on)
                    }
                }
            }
            foreach (CountryConfig.FunctionRow functionRow in selectedFunRows)
            {
                parRows.AddRange(functionRow.GetParameterRows()); // see above
                foreach (CountryConfig.Extension_FunctionRow del in from fe in countryConfig.Extension_Function where fe.ExtensionID == extensionID& fe.FunctionID == functionRow.ID select fe)
                {
                    if (!delFunctionRows.Contains(del))
                    {
                        delFunctionRows.Add(del);
                    }
                }
            }
            foreach (CountryConfig.ParameterRow parameterRow in parRows)
            {
                foreach (CountryConfig.Extension_ParameterRow del in from pe in countryConfig.Extension_Parameter where pe.ExtensionID == extensionID& pe.ParameterID == parameterRow.ID select pe)
                {
                    if (!delParameterRows.Contains(del))
                    {
                        delParameterRows.Add(del);
                    }
                }
            }
            for (int i = delPolicyRows.Count - 1; i >= 0; --i)
            {
                delPolicyRows[i].Delete();
            }
            for (int i = delFunctionRows.Count - 1; i >= 0; --i)
            {
                delFunctionRows[i].Delete();
            }
            for (int i = delParameterRows.Count - 1; i >= 0; --i)
            {
                delParameterRows[i].Delete();
            }
        }
Esempio n. 8
0
        void InitSwitchTable()
        {
            dgvSwitches.Rows.Clear();
            dgvSwitches.Columns.Clear();

            //add systems as columns
            foreach (CountryConfig.SystemRow systemRow in CountryAdministrator.GetCountryConfigFacade(_countryShortName).GetSystemRows())
            {
                DataGridViewComboBoxColumn dgvColumn = CreateSystemColumn("col" + systemRow.Name, systemRow.Name); //create the combo-boxes with values on, off and n/a
                if (systemRow.Private == DefPar.Value.YES)
                {
                    dgvColumn.HeaderCell.Style.ForeColor = _privateColor;
                }
                dgvColumn.Tag = systemRow;
            }

            //add datasets as rows
            foreach (DataConfig.DataBaseRow dataBaseRow in from db in _dataConfig.DataBase select db)
            {
                int             rowIndex = dgvSwitches.Rows.Add();
                DataGridViewRow dgvRow   = dgvSwitches.Rows[rowIndex];
                dgvRow.HeaderCell.Value = dataBaseRow.Name;
                dgvRow.Tag = dataBaseRow.ID;
                if (dataBaseRow.Private == DefPar.Value.YES)
                {
                    dgvRow.HeaderCell.Style.ForeColor          = _privateColor;
                    dgvRow.HeaderCell.Style.SelectionForeColor = _privateColor;
                }
            }
        }
        internal static Dictionary <string, string> GetSystemAssignement(EM_UI_MainForm copyCountryMainForm,
                                                                         EM_UI_MainForm pasteCountryMainForm,
                                                                         List <string> pasteCountryHiddenSystems)
        {
            Dictionary <string, string> pasteSystemsNamesAndIDs = new Dictionary <string, string>();
            Dictionary <string, string> copySystemNamesAndIDs   = new Dictionary <string, string>();

            foreach (CountryConfig.SystemRow systemRow in CountryAdministrator.GetCountryConfigFacade(pasteCountryMainForm.GetCountryShortName()).GetSystemRows())
            {
                if (!pasteCountryHiddenSystems.Contains(systemRow.ID))
                {
                    pasteSystemsNamesAndIDs.Add(systemRow.Name, systemRow.ID);
                }
            }

            foreach (CountryConfig.SystemRow systemRow in CountryAdministrator.GetCountryConfigFacade(copyCountryMainForm.GetCountryShortName()).GetSystemRows())
            {
                copySystemNamesAndIDs.Add(systemRow.Name, systemRow.ID);
            }

            AssignSystemsForm assignSystemsForm = new AssignSystemsForm(pasteCountryMainForm.GetCountryShortName(), pasteSystemsNamesAndIDs,
                                                                        copyCountryMainForm.GetCountryShortName(), copySystemNamesAndIDs);

            if (assignSystemsForm.ShowDialog() == DialogResult.Cancel)
            {
                return(null);
            }
            return(assignSystemsForm.GetSystemAssignment());
        }
Esempio n. 10
0
        internal static List <ExtensionOrGroup> GetLookGroupDrawInfo(string cc, TreeListNode node)
        {
            if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null)
            {
                return(new List <ExtensionOrGroup>());
            }
            BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag;

            List <string> lookGroupIds = (from lgPol in GetCountryConfig(cc).LookGroup_Policy where lgPol.PolicyID == nodeTag.GetDefaultPolicyRow().ID select lgPol.LookGroupID).ToList();

            if (nodeTag.GetDefaultFunctionRow() != null)
            {
                lookGroupIds.AddRange((from lgFun in GetCountryConfig(cc).LookGroup_Function where lgFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID select lgFun.LookGroupID));
            }
            if (nodeTag.GetDefaultParameterRow() != null)
            {
                lookGroupIds.AddRange((from lgPar in GetCountryConfig(cc).LookGroup_Parameter where lgPar.ParameterID == nodeTag.GetDefaultParameterRow().ID select lgPar.LookGroupID));
            }

            List <ExtensionOrGroup> lookGroups = new List <ExtensionOrGroup>();

            foreach (CountryConfig.LookGroupRow lg in GetCountryConfig(cc).LookGroup)
            {
                if (lookGroupIds.Contains(lg.ID))
                {
                    lookGroups.Add(new ExtensionOrGroup(lg));
                }
            }
            return(lookGroups);
        }
        internal override void PerformValidation(List <string> countries, bool showProblemsOnly)
        {
            base.PerformValidation(countries, showProblemsOnly);
            string noHICP = string.Empty, notDollarF = string.Empty, emptyFactors = string.Empty, zeroFactors = string.Empty,
                   noYearForSystem = string.Empty, noYearForData = string.Empty, noIncomeYear = string.Empty;

            foreach (string country in countries)
            {
                CountryConfigFacade ccf = CountryAdministrator.GetCountryConfigFacade(country);
                DataConfigFacade    dcf = CountryAdministrator.GetDataConfigFacade(country);

                List <CountryConfig.UpratingIndexRow> indices       = (from ui in ccf.GetUpratingIndices() select ui).ToList();
                List <CountryConfig.SystemRow>        publicSystems = GetPublicSystems(country);
                List <DataConfig.DataBaseRow>         datasets      = (from d in dcf.GetDataBaseRows() where d.Private != DefPar.Value.YES select d).ToList();

                List <string> indexYears = ccf.GetAllUpratingIndexYears();

                RegisterProblems(country, NotDollarF(indices), ref notDollarF);
                RegisterProblems(country, NoYearForSystem(publicSystems, indexYears), ref noYearForSystem);
                RegisterProblems(country, NoYearForData(datasets, indexYears), ref noYearForData);
                RegisterProblems(country, NoIncomeYear(datasets), ref noIncomeYear);
                RegisterProblems(country, EmptyFactors(ccf, indices, false), ref emptyFactors);
                RegisterProblems(country, EmptyFactors(ccf, indices, true), ref zeroFactors);
            }
            AddDataGridRow("Factors not starting with $f_", notDollarF);
            AddDataGridRow("Systems for which factor-table does not provide year", noYearForSystem);
            AddDataGridRow("Databases for which factor-table does not provide year", noYearForData);
            AddDataGridRow("Databases with undefined income year", noIncomeYear);
            AddDataGridRow("Factors with empty values", emptyFactors);
            AddDataGridRow("Factors with zero values (warning)", zeroFactors);
        }
        internal CountryConfig.SystemRow PerformAddOnGeneration(string newSystemName, string countryShortName, string addOnShortName,
                                                                string baseSystemName, string addOnSystemName)
        {
            //get the county's and add-on's data
            CountryConfigFacade baseCountryConfigFacade = CountryAdministrator.GetCountryConfigFacade(countryShortName);

            _addOnCountryConfigFacade = CountryAdministrator.GetCountryConfigFacade(addOnShortName);

            //get the base-system and the add-on-system
            CountryConfig.SystemRow baseSystemRow = baseCountryConfigFacade.GetSystemRowByName(baseSystemName);
            _addOnSystemRow = _addOnCountryConfigFacade.GetSystemRowByName(addOnSystemName);

            //add-on-system will be stored in an CountryConfig generated for the purpose of storing it
            _mergeCountryConfigFacade = new CountryConfigFacade(countryShortName);

            //generate a copy of the base-system, by keeping all ids except the system id identically: otherwise the id-references (e.g. in ChangeParam, AddOn_Par, etc. would not work)
            _mergeSystemRow = CountryConfigFacade.CopySystemRowToAnotherCountry(baseSystemRow, _addOnSystemRow.Name,
                                                                                _mergeCountryConfigFacade.GetCountryConfig(), true);
            _mergeSystemRow.Name = newSystemName;

            //add policies following instructions in AddOn_Pol-functions
            AddPolicies();

            //add functions following instructions in AddOn_Func-functions
            AddFunctions();

            //add parameters following instructions in AddOn_Par-functions
            AddParameters();

            //replace e.g. yse_uk_#2 respectively yse_uk_#2.4 by the actual id of this function respectively parameter
            ReplaceSymbolicIDsInChangeParam();

            return(_errorMessages == string.Empty ? _mergeSystemRow : null);
        }
Esempio n. 13
0
        private void btnCheckPath_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            bool   hasInsertedPath = true;
            string selectedPath    = String.Empty;
            string insertedPath    = txtImportFolder.Text;

            if (insertedPath == null || insertedPath == "")
            {
                Tools.UserInfoHandler.ShowError("Please insert or select a folder.");
                this.Cursor = Cursors.Default;
                return;
            }

            if (CountryAdministrator.ConsiderOldAddOnFileStructure(_fromAddOn))
            {
                _importCountry = ImportExportAdministrator.GetImportAddOn_OldStyle(out selectedPath, hasInsertedPath, insertedPath);
            }
            else
            {
                _importCountry = ImportExportAdministrator.GetImportCountry(out selectedPath, _fromAddOn, hasInsertedPath, insertedPath);
            }
            if (_importCountry == null)
            {
                this.Cursor = Cursors.Default;
                return;
            }


            displayCountrySystems();
            this.Cursor = Cursors.Default;
        }
Esempio n. 14
0
        internal override void PerformAction()
        {
            ExtensionAndGroupMenuManager.GetSelectionPolFunPar(cc, out List <CountryConfig.PolicyRow> polRows, out List <CountryConfig.FunctionRow> funRows, out List <CountryConfig.ParameterRow> parRows);
            CountryConfig countryConfig = CountryAdministrator.GetCountryConfigFacade(cc).GetCountryConfig();

            CountryConfig.LookGroupRow groupRow = (from lg in countryConfig.LookGroup where lg.Name.ToLower() == groupName.ToLower() select lg).First();

            foreach (CountryConfig.PolicyRow policyRow in polRows)
            {
                if (!(from pg in countryConfig.LookGroup_Policy where pg.PolicyID == policyRow.ID && pg.LookGroupID == groupRow.ID select pg).Any())
                {
                    countryConfig.LookGroup_Policy.AddLookGroup_PolicyRow(groupRow, policyRow); // make sure to not add twice (and thus crash)
                }
            }
            foreach (CountryConfig.FunctionRow functionRow in funRows)
            {
                if (!(from fg in countryConfig.LookGroup_Function where fg.FunctionID == functionRow.ID && fg.LookGroupID == groupRow.ID select fg).Any())
                {
                    countryConfig.LookGroup_Function.AddLookGroup_FunctionRow(groupRow, functionRow);
                }
            }
            foreach (CountryConfig.ParameterRow parameterRow in parRows)
            {
                if (!(from pg in countryConfig.LookGroup_Parameter where pg.ParameterID == parameterRow.ID && pg.LookGroupID == groupRow.ID select pg).Any())
                {
                    countryConfig.LookGroup_Parameter.AddLookGroup_ParameterRow(groupRow, parameterRow);
                }
            }
        }
        void btnOK_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(txtCountryFolder.Text))
            {
                UserInfoHandler.ShowError("Import Country Folder does not exist.");
                return;
            }

            if (Directory.Exists(EMPath.Folder_Countries(EM_AppContext.FolderEuromodFiles) + txtShortName.Text))
            {
                UserInfoHandler.ShowError("Country folder '" + txtShortName.Text + "' already exists at '" + EMPath.Folder_Countries(EM_AppContext.FolderEuromodFiles) + "'.");
                return;
            }

            if (txtFlag.Text != string.Empty && !CountryAdministrator.IsValidFlagFilePath(txtFlag.Text))
            {
                return;
            }

            //out-commented as it does not really make sense to not allow for longer country-short-names
            //if (txtShortName.Text.Length != 2)
            //{
            //    if (UserInfoHandler.GetInfo("Short Name is supposed to have two characters. Do you want to correct?", MessageBoxButtons.YesNo) == DialogResult.Yes)
            //        return;
            //}

            DialogResult = DialogResult.OK;
            Close();
        }
Esempio n. 16
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtImportFolder.Text == string.Empty)
            {
                UserInfoHandler.ShowError("Please select a version to compare with."); return;
            }

            Cursor = Cursors.WaitCursor;
            bool   hasInsertedPath = true;
            string insertedPath    = txtImportFolder.Text;
            string selectedPath    = String.Empty;

            if (CountryAdministrator.ConsiderOldAddOnFileStructure(_fromAddOn))
            {
                _importCountry = ImportExportAdministrator.GetImportAddOn_OldStyle(out selectedPath, hasInsertedPath, insertedPath);
            }
            else
            {
                _importCountry = ImportExportAdministrator.GetImportCountry(out selectedPath, _fromAddOn, hasInsertedPath, insertedPath);
            }
            if (_importCountry == null)
            {
                Cursor = Cursors.Default;
                return;
            }

            DialogResult = DialogResult.OK;
            Close();
        }
        private static void Migrate_BackgroundEventHandler(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

            try
            {
                List <Country> countries = CountryAdministrator.GetCountries();
                for (int i = 0; i < countries.Count; ++i)
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        e.Result = null; e.Cancel = true; return;
                    }

                    CountryConfigFacade ccf = countries[i].GetCountryConfigFacade(); if (ccf == null)
                    {
                        continue;
                    }
                    countries[i].WriteXML();

                    backgroundWorker.ReportProgress(Convert.ToInt32((i + 1.0) / (countries.Count * 1.0) * 100.0));
                }
            }
            catch (Exception exception) { e.Result = exception.Message; backgroundWorker.ReportProgress(100); }
        }
Esempio n. 18
0
        public static bool GetCAOInfo(out TSDictionary info, bool includeCountries = true, bool includeAddOns = true, bool openOnly = false)
        {
            info = new TSDictionary();

            try
            {
                List <Country> caos = new List <Country>();
                if (includeCountries)
                {
                    caos.AddRange(CountryAdministrator.GetCountries());
                }
                if (includeAddOns)
                {
                    caos.AddRange(CountryAdministrator.GetAddOns());
                }

                Dictionary <string, EM_UI_MainForm> openMainForms = new Dictionary <string, EM_UI_MainForm>();
                foreach (EM_UI_MainForm mf in EM_AppContext.Instance.GetOpenCountriesMainForms())
                {
                    openMainForms.Add(mf.GetCountryShortName().ToLower(), mf);
                }

                List <Form>   mainForms        = new List <Form>();
                List <string> shortNames       = new List <string>();
                List <string> longNames        = new List <string>();
                List <bool>   isAddOn          = new List <bool>();
                List <bool>   isOpen           = new List <bool>();
                List <string> mainXMLFileNames = new List <string>();
                List <string> dataXMLFileNames = new List <string>();
                List <string> filePaths        = new List <string>();
                foreach (Country cao in caos)
                {
                    bool open = openMainForms.ContainsKey(cao._shortName.ToLower());
                    if (openOnly && !open)
                    {
                        continue;
                    }
                    mainForms.Add(open ? openMainForms[cao._shortName.ToLower()] : null);
                    shortNames.Add(cao._shortName);
                    // long name is only availabel through CountryConfig (it doesn't seem appropriate to open the country just to get the long-name)
                    longNames.Add(open ? openMainForms[cao._shortName.ToLower()].GetCountryLongName() : cao._shortName);
                    isAddOn.Add(cao._isAddOn);
                    isOpen.Add(open);
                    mainXMLFileNames.Add(CountryAdministrator.GetCountryFileName(cao._shortName));
                    dataXMLFileNames.Add(cao._isAddOn ? string.Empty : CountryAdministrator.GetDataFileName(cao._shortName));
                    filePaths.Add(CountryAdministrator.GetCountryPath(cao._shortName));
                }
                info.SetItem(UISessionInfo.CAO_INFO_MainForms, mainForms);
                info.SetItem(UISessionInfo.CAO_INFO_ShortNames, shortNames);
                info.SetItem(UISessionInfo.CAO_INFO_LongNames, longNames);
                info.SetItem(UISessionInfo.CAO_INFO_IsAddOn, isAddOn);
                info.SetItem(UISessionInfo.CAO_INFO_IsOpen, isOpen);
                info.SetItem(UISessionInfo.CAO_INFO_MainXMLFileNames, mainXMLFileNames);
                info.SetItem(UISessionInfo.CAO_INFO_DataXMLFileNames, dataXMLFileNames);
                info.SetItem(UISessionInfo.CAO_INFO_FilePaths, filePaths);
                return(true);
            }
            catch { return(false); }
        }
        internal static bool RestoreCountry(EM_UI_MainForm mainForm, string backUpFolder = "")
        {
            bool reportSuccess = false;

            if (backUpFolder == string.Empty) //called via button in MainForm
            {
                FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
                folderBrowserDialog.SelectedPath = EMPath.Folder_BackUps(EM_AppContext.FolderEuromodFiles);
                folderBrowserDialog.Description  = "Please select the back-up folder";
                if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                {
                    return(true);
                }
                backUpFolder  = folderBrowserDialog.SelectedPath;
                reportSuccess = true;
            }
            else //called from a catch-branch, i.e. using just generated back-up in Temp/BackUp
            {
                backUpFolder = EMPath.Folder_BackUps(EM_AppContext.FolderEuromodFiles) + backUpFolder;
            }

            string countryShortName = mainForm.GetCountryShortName();
            bool   isAddOn          = CountryAdministrator.IsAddOn(countryShortName);

            try
            {
                //check if backUpFolder contains the necessary files and if the files actually contain a backup of the loaded country/add-on ...
                string errorMessage;
                if (!Country.DoesFolderContainValidXMLFiles(countryShortName, out errorMessage, backUpFolder, isAddOn,
                                                            true)) //check if countryShortName corresponds to country's short name as stored in the XML-file
                {
                    throw new System.ArgumentException(errorMessage);
                }

                //... if yes, copy files form backup-folder to Countries-folder
                if (!Country.CopyXMLFiles(countryShortName, out errorMessage, backUpFolder))
                {
                    throw new System.ArgumentException(errorMessage);
                }

                mainForm.ReloadCountry();

                if (reportSuccess) //report success only if called via button (and not if called by a failed function)
                {
                    UserInfoHandler.ShowSuccess("Successfully restored using back-up stored in" + Environment.NewLine + backUpFolder + ".");
                }

                return(true);
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowError("Restore failed because of the error stated below." + Environment.NewLine +
                                          "You may want to try a manual restore via the button in the ribbon 'Country Tools'." + Environment.NewLine + Environment.NewLine +
                                          exception.Message);
                return(false);
            }
        }
        internal ImportAddOnForm(List <string> BaseSystemNames)
        {
            InitializeComponent();
            _baseSystemNames = BaseSystemNames;

            foreach (Country addOn in CountryAdministrator.GetAddOns())
            {
                cmbAddOns.Items.Add(addOn._shortName);
            }
        }
        public ExtractProjectForm()
        {
            InitializeComponent();

            foreach (Country c in CountryAdministrator.GetCountries())
            {
                lstCountries.Items.Add(c._shortName);
            }
            FillInYears();
        }
Esempio n. 22
0
        internal static List <ExtensionOrGroup> GetExtensionDrawInfo(string cc, TreeListNode node)
        {
            if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null)
            {
                return(new List <ExtensionOrGroup>());
            }
            BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag;

            Dictionary <string, LookDef.STYLE> extIdsAndStyles = new Dictionary <string, LookDef.STYLE>();

            foreach (CountryConfig.Extension_PolicyRow extPolRow in from ePol in GetCountryConfig(cc).Extension_Policy where ePol.PolicyID == nodeTag.GetDefaultPolicyRow().ID select ePol)
            {
                extIdsAndStyles.Add(extPolRow.ExtensionID, extPolRow.BaseOff ? LookDef.STYLE.EXTENSION_OFF : LookDef.STYLE.EXTENSION_ON);
            }
            if (nodeTag.GetDefaultFunctionRow() != null)
            {
                foreach (CountryConfig.Extension_FunctionRow extFunRow in from eFun in GetCountryConfig(cc).Extension_Function where eFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID select eFun)
                { // function-setting with regard to BaseOff overwrites policy-setting (in fact only BaseOff=true may overwrite BaseOff=false, but this is not the point to check for observing this rule)
                    if (extIdsAndStyles.ContainsKey(extFunRow.ExtensionID))
                    {
                        extIdsAndStyles[extFunRow.ExtensionID] = extFunRow.BaseOff ? LookDef.STYLE.EXTENSION_OFF : LookDef.STYLE.EXTENSION_ON;
                    }
                    else
                    {
                        extIdsAndStyles.Add(extFunRow.ExtensionID, extFunRow.BaseOff ? LookDef.STYLE.EXTENSION_OFF : LookDef.STYLE.EXTENSION_ON);
                    }
                }
            }
            if (nodeTag.GetDefaultParameterRow() != null)
            {
                foreach (CountryConfig.Extension_ParameterRow extParRow in from ePar in GetCountryConfig(cc).Extension_Parameter where ePar.ParameterID == nodeTag.GetDefaultParameterRow().ID select ePar)
                { // see overwriting rule above
                    if (extIdsAndStyles.ContainsKey(extParRow.ExtensionID))
                    {
                        extIdsAndStyles[extParRow.ExtensionID] = extParRow.BaseOff ? LookDef.STYLE.EXTENSION_OFF : LookDef.STYLE.EXTENSION_ON;
                    }
                    else
                    {
                        extIdsAndStyles.Add(extParRow.ExtensionID, extParRow.BaseOff ? LookDef.STYLE.EXTENSION_OFF : LookDef.STYLE.EXTENSION_ON);
                    }
                }
            }

            List <ExtensionOrGroup> extensions = new List <ExtensionOrGroup>();

            foreach (GlobLocExtensionRow e in GetExtensions(cc))
            {
                if (extIdsAndStyles.ContainsKey(e.ID))
                {
                    extensions.Add(new ExtensionOrGroup(e, extIdsAndStyles[e.ID]));
                }
            }
            return(extensions);
        }
Esempio n. 23
0
        internal UpdatingProgressForm()
        {
            InitializeComponent();

            txtFolder.Text = EM_AppContext.FolderOutput;

            foreach (Country country in CountryAdministrator.GetCountries())
            {
                lstCountries.Items.Add(country._shortName);
            }
        }
        private Dictionary <string, Dictionary <string, ILInfo> > AssessILInfo(string country, bool core)
        {
            Dictionary <string, Dictionary <string, ILInfo> > ilInfos = new Dictionary <string, Dictionary <string, ILInfo> >();
            CountryConfigFacade ccf = CountryAdministrator.GetCountryConfigFacade(country);

            foreach (CountryConfig.SystemRow system in GetPublicSystems(country))
            {
                // UDB (aka non-core) ILS are kept in a separate policy
                CountryConfig.PolicyRow ilPol = ccf.GetPolicyRowByName(system.ID, core ? DefPol.SPECIAL_POL_ILSDEF : DefPol.SPECIAL_POL_ILSUDBDEF);
                if (ilPol == null || ilPol.Switch != DefPar.Value.ON || ilPol.Private == DefPar.Value.YES)
                {
                    continue;
                }
                foreach (CountryConfig.FunctionRow ilFunc in ccf.GetFunctionRowsByPolicyIDAndFunctionName(ilPol.ID, DefFun.DefIl))
                {
                    if (ilFunc.Switch != DefPar.Value.ON || ilFunc.Private == DefPar.Value.YES)
                    {
                        continue;
                    }
                    ILInfo ilInfo = new ILInfo()
                    {
                        LabelEmpty = ilFunc.Comment == string.Empty
                    };
                    string ilName = string.Empty;

                    foreach (CountryConfig.ParameterRow ilPar in ilFunc.GetParameterRows())
                    {
                        if (ilPar.Name.ToLower() == DefPar.DefIl.Name.ToLower())
                        {
                            ilName = ilPar.Value.ToLower(); continue;
                        }
                        if (ilPar.Value == DefPar.Value.NA || ilPar.Private == DefPar.Value.YES)
                        {
                            continue;
                        }
                        ilInfo.Components.Add(ilPar);
                    }
                    if (ilName == string.Empty)
                    {
                        continue;                         // rather unlikely
                    }
                    if (!ilInfos.ContainsKey(ilName))
                    {
                        ilInfos.Add(ilName, new Dictionary <string, ILInfo>());
                    }
                    if (!ilInfos[ilName].ContainsKey(system.Name.ToLower())) // this is a security-request: ilName should be unique per system
                    {
                        ilInfos[ilName].Add(system.Name.ToLower(), ilInfo);
                    }
                }
            }
            return(ilInfos);
        }
        static void GetCountryExchangeRates_BackgroundEventHandler(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

            try
            {
                List <ExchangeRate> exRates   = new List <ExchangeRate>();
                List <Country>      countries = CountryAdministrator.GetCountries();
                for (int i = 0; i < countries.Count; ++i)
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        e.Result = null; e.Cancel = true; return;
                    }

                    CountryConfigFacade ccf = countries[i].GetCountryConfigFacade(); if (ccf == null)
                    {
                        continue;
                    }
                    Dictionary <double, string> sysRates = new Dictionary <double, string>();
                    foreach (CountryConfig.SystemRow system in ccf.GetSystemRows())
                    {
                        if (system.IsExchangeRateEuroNull())
                        {
                            continue;                                  // rather unlikely
                        }
                        double rate; if (!double.TryParse(system.ExchangeRateEuro, out rate))
                        {
                            continue;                                                                   // also rather unlikely
                        }
                        if (sysRates.ContainsKey(rate))
                        {
                            sysRates[rate] = ExchangeRate.AddToValidFor(sysRates[rate], system.Name);
                        }
                        else
                        {
                            sysRates.Add(rate, system.Name.ToLower());
                        }
                    }
                    foreach (var sr in sysRates)
                    {
                        ExchangeRate exRatesCY = new ExchangeRate()
                        {
                            Country = countries[i]._shortName, June30 = sr.Key, ValidFor = sr.Value
                        };
                        exRates.Add(exRatesCY);
                    }
                    backgroundWorker.ReportProgress(Convert.ToInt32((i + 1.0) / (countries.Count * 1.0) * 100.0));
                }
                e.Result = exRates;
            }
            catch (Exception exception) { e.Result = exception.Message; backgroundWorker.ReportProgress(100); }
        }
        internal override void PerformAction()
        {
            ExtensionAndGroupMenuManager.GetSelectionPolFunPar(cc, out List <CountryConfig.PolicyRow> polRows, out List <CountryConfig.FunctionRow> funRows, out List <CountryConfig.ParameterRow> parRows);
            CountryConfig countryConfig = CountryAdministrator.GetCountryConfigFacade(cc).GetCountryConfig();

            CountryConfig.LookGroupRow groupRow = (from lg in countryConfig.LookGroup where lg.Name.ToLower() == groupName.ToLower() select lg).First();

            List <CountryConfig.LookGroup_PolicyRow>    delPolicyRows    = new List <CountryConfig.LookGroup_PolicyRow>();
            List <CountryConfig.LookGroup_FunctionRow>  delFunctionRows  = new List <CountryConfig.LookGroup_FunctionRow>();
            List <CountryConfig.LookGroup_ParameterRow> delParameterRows = new List <CountryConfig.LookGroup_ParameterRow>();

            foreach (CountryConfig.PolicyRow policyRow in polRows)
            {
                funRows.AddRange(policyRow.GetFunctionRows()); // to make sure that all functions of the policy are removed as well - note: the AddContent-function
                                                               // does not remove a single function if its parent-policy is added (later)
                var del = from pg in countryConfig.LookGroup_Policy where pg.LookGroupID == groupRow.ID && pg.PolicyID == policyRow.ID select pg;
                if (del.Any() && !delPolicyRows.Contains(del.First()))
                {
                    delPolicyRows.Add(del.First());
                }
            }
            foreach (CountryConfig.FunctionRow functionRow in funRows)
            {
                parRows.AddRange(functionRow.GetParameterRows()); // see above
                var del = from fg in countryConfig.LookGroup_Function where fg.LookGroupID == groupRow.ID && fg.FunctionID == functionRow.ID select fg;
                if (del.Any() && !delFunctionRows.Contains(del.First()))
                {
                    delFunctionRows.Add(del.First());
                }
            }
            foreach (CountryConfig.ParameterRow parameterRow in parRows)
            {
                var del = from pg in countryConfig.LookGroup_Parameter where pg.LookGroupID == groupRow.ID && pg.ParameterID == parameterRow.ID select pg;
                if (del.Any() && !delParameterRows.Contains(del.First()))
                {
                    delParameterRows.Add(del.First());
                }
            }

            for (int i = delPolicyRows.Count - 1; i >= 0; --i)
            {
                delPolicyRows[i].Delete();
            }
            for (int i = delFunctionRows.Count - 1; i >= 0; --i)
            {
                delFunctionRows[i].Delete();
            }
            for (int i = delParameterRows.Count - 1; i >= 0; --i)
            {
                delParameterRows[i].Delete();
            }
        }
        internal static void UpdateCountryFiles(Dictionary <string, List <Tuple <string, string> > > changesCountryFiles, Form showWaitCursorForm = null)
        {
            try
            {
                if (showWaitCursorForm == null)
                {
                    showWaitCursorForm = EM_AppContext.Instance.GetActiveCountryMainForm();
                }
                showWaitCursorForm.Cursor = Cursors.WaitCursor;
                bool showOpenWarning = true;
                foreach (var ccChange in changesCountryFiles)
                {
                    string         country    = ccChange.Key;
                    EM_UI_MainForm ccMainForm = EM_AppContext.Instance.GetCountryMainForm(country);
                    if (ccMainForm != null)
                    {
                        if (showOpenWarning)
                        {
                            switch (UserInfoHandler.GetInfo(country.ToUpper() + " is open." + Environment.NewLine +
                                                            "Updating exchange rates requires a reset of the undo-functionality." + Environment.NewLine +
                                                            "That means you will not be able to undo any of your changes so far." + Environment.NewLine + Environment.NewLine +
                                                            "Do you still want to update exchange rates of " + country.ToUpper() + "?" + Environment.NewLine + Environment.NewLine +
                                                            "(Press Cancel to not be requested with respect to further open countries.)", MessageBoxButtons.YesNoCancel))
                            {
                            case DialogResult.No: continue;

                            case DialogResult.Cancel: showOpenWarning = false; break;
                            }
                        }
                        ccMainForm.GetUndoManager().Commit(); ccMainForm.GetUndoManager().Reset();
                    }
                    CountryConfigFacade ccf = CountryAdministrator.GetCountryConfigFacade(country);
                    foreach (var change in ccChange.Value)
                    {
                        ccf.GetSystemRowByName(change.Item1).ExchangeRateEuro = change.Item2;
                    }

                    if (ccMainForm != null)
                    {
                        ccMainForm.GetUndoManager().Commit(); ccMainForm.GetUndoManager().Reset(); ccMainForm.WriteXml();
                    }
                    else
                    {
                        CountryAdministrator.WriteXML(country);
                    }
                }
            }
            catch (Exception)
            {
            }
            finally { showWaitCursorForm.Cursor = Cursors.Default; }
        }
Esempio n. 28
0
        internal SaveParameterFilesAsTextForm()
        {
            InitializeComponent();

            txtFolder.Text = EM_AppContext.FolderOutput;

            foreach (Country country in CountryAdministrator.GetCountries())
            {
                lvCountries.Items.Add(country._shortName);
            }

            CheckCountries(true);
        }
        internal static void SaveDirectXMLAction(EM_UI_MainForm mainForm)
        {
            string countryShortName = mainForm.GetCountryShortName();

            CountryAdministrator.GetCountryConfigFacade(countryShortName).GetCountryConfig().AcceptChanges();
            if (!CountryAdministrator.IsAddOn(countryShortName))
            {
                CountryAdministrator.GetDataConfigFacade(countryShortName).GetDataConfig().AcceptChanges();
            }
            mainForm.GetUndoManager().Reset();       //reset undo-manager with the drawback that actions up until now cannot be undone
            lock (EM_UI_MainForm._performActionLock) //to not get into conflict with auto-saving
            {
                CountryAdministrator.WriteXML(countryShortName);
            }
        }
        internal void SaveTable()
        {
            List <Tuple <string, string, string> > indTaxes = new List <Tuple <string, string, string> >();

            foreach (DataGridViewRow row in table.Rows)
            {
                if (row.Cells[colName.Name].Value == null || string.IsNullOrEmpty(row.Cells[colName.Name].Value.ToString()))
                {
                    continue;                                                                                                          //probably an empty row
                }
                string name       = row.Cells[colName.Name].Value == null ? string.Empty : row.Cells[colName.Name].Value.ToString();
                string comment    = row.Cells[colComment.Name].Value == null ? string.Empty : row.Cells[colComment.Name].Value.ToString();
                string yearValues = string.Empty;
                foreach (DataGridViewColumn yearColumn in GetYearColumnsAsDisplayed())
                {
                    if (row.Cells[yearColumn.Index].Value != null)
                    {
                        yearValues += yearColumn.HeaderText + separatorYear + row.Cells[yearColumn.Index].Value.ToString();
                    }
                    yearValues += separator;
                }
                indTaxes.Add(new Tuple <string, string, string>(name, comment, yearValues.TrimEnd(new char[] { separator })));
            }

            CountryConfig countryConfig = CountryAdministrator.GetCountryConfigFacade(mainForm.GetCountryShortName()).GetCountryConfig();

            foreach (var indTax in indTaxes)
            {
                List <CountryConfig.IndirectTaxRow> its = (from it in countryConfig.IndirectTax where it.Name.ToLower() == indTax.Item1.ToLower() select it).ToList();
                if (its.Count == 0)
                {
                    countryConfig.IndirectTax.AddIndirectTaxRow(Guid.NewGuid().ToString(), indTax.Item1, indTax.Item2, indTax.Item3);
                }
                else
                {
                    its[0].Name = indTax.Item1; its[0].Comment = indTax.Item2; its[0].YearValues = indTax.Item3;
                }
            }
            List <string> itNames = (from i in indTaxes select i.Item1.ToLower()).ToList();

            for (int i = countryConfig.IndirectTax.Count - 1; i >= 0; --i)
            {
                if (!itNames.Contains(countryConfig.IndirectTax[i].Name.ToLower()))
                {
                    countryConfig.IndirectTax.ElementAt(i).Delete();
                }
            }
        }